From 29fc73eb1ff4295e17a93779d055bde8b5ab2b19 Mon Sep 17 00:00:00 2001 From: matt venn Date: Thu, 20 Sep 2018 16:56:30 +0200 Subject: [PATCH 1/7] init globals and bss in start.S --- examples/picosoc/firmware.c | 5 ----- examples/picosoc/start.S | 30 ++++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/examples/picosoc/firmware.c b/examples/picosoc/firmware.c index b36463f..cd7f9c6 100644 --- a/examples/picosoc/firmware.c +++ b/examples/picosoc/firmware.c @@ -25,11 +25,6 @@ uint32_t set_irq_mask(uint32_t mask); asm ( void main() { set_irq_mask(0xff); - // zero out .bss section - for (uint32_t *dest = &_sbss; dest < &_ebss;) { - *dest++ = 0; - } - // switch to dual IO mode reg_spictrl = (reg_spictrl & ~0x007F0000) | 0x00400000; diff --git a/examples/picosoc/start.S b/examples/picosoc/start.S index 7f2796d..38e4697 100644 --- a/examples/picosoc/start.S +++ b/examples/picosoc/start.S @@ -209,10 +209,36 @@ start: addi x30, zero, 0 addi x31, zero, 0 + # copy data section + la a0, _sidata # load _sidata to a0 + la a1, _sdata # load _sdata to a1 + la a2, _edata # load _edata to a2 + bge a1, a2, end_init_data # if _edata > _sdata jump to end + +loop_init_data: + lw a3, 0(a0) # load data at a0 to a3 + sw a3, 0(a1) # store data in a3 to a1 (_sdata) + addi a0, a0, 4 # add 4 to a0 + addi a1, a1, 4 # add 4 to a1 + blt a1, a2, loop_init_data # if a1 < a2 finish + +end_init_data: + + # zero-init bss section + la a0, _sbss + la a1, _ebss + bge a0, a1, end_init_bss + +loop_init_bss: + sw zero, 0(a0) + addi a0, a0, 4 + blt a0, a1, loop_init_bss + +end_init_bss: + call main - call main loop: - j loop + j loop From cabced9a53d0d78920a97b97bf665c505260cc36 Mon Sep 17 00:00:00 2001 From: matt venn Date: Sun, 4 Nov 2018 17:00:26 +0100 Subject: [PATCH 2/7] readme --- examples/picosoc/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/picosoc/README.md diff --git a/examples/picosoc/README.md b/examples/picosoc/README.md new file mode 100644 index 0000000..002912f --- /dev/null +++ b/examples/picosoc/README.md @@ -0,0 +1,21 @@ +# PicoSOC TinyFPGA example + +PicoSOC is an SOC - system on chip. It includes everything you need to +run a RiscV CPU on the TinyFPGA. + +The RiscV CPU is PicoRV32, made by Clifford Wolf. The original repo is here: + +https://github.com/cliffordwolf/picorv32 + +The SOC example that uses the PicoRV32 was originally made for the Lattice 8k evaluation +board. This example has been modified to work with the TinyFPGA by Luke from TinyFPGA. + +# Toolchain + +You can synthesise the demo with the [icestorm](http://www.clifford.at/icestorm/) toolchain. +A very convient way to install the toolchain is to use [APIO](https://github.com/FPGAwars/apio) +And then set your path to include the installed tools and copy the chipdb files: + + export PATH=$PATH:~/.apio/packages/toolchain-icestorm/bin/ + sudo cp -r ~/.apio/packages/toolchain-icestorm/share/icebox/ /usr/local/share/ + From e621d5405f5559a11cb7487e614fff07a3104a5c Mon Sep 17 00:00:00 2001 From: matt venn Date: Sun, 4 Nov 2018 17:01:11 +0100 Subject: [PATCH 3/7] blinky firmwrae --- examples/picosoc/firmware.bin | Bin 0 -> 524 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 examples/picosoc/firmware.bin diff --git a/examples/picosoc/firmware.bin b/examples/picosoc/firmware.bin new file mode 100755 index 0000000000000000000000000000000000000000..a4e488c3b1e9dd8ef1a4ba750afd6446381bfe3c GIT binary patch literal 524 zcmY+9%}X0W7>D0UGP~9Iv2jGvgKV>9l^%NN!9Wi(Nl^TtH)Ae-fT8{gJ*O^S%%Rj2 z$uaa#uxPF^CP6|7vd9vGw`kHd&u)gfC3{`Q;1eWplRm>T0fC zDppIia-(XWJGEB5-S~2GV}HB6b2`m#>(`ar4pxZv_bi<#70~EwnrK%B^W-~_8JwS_ zH_K5p7PDj9@lM>gdaxQ!93^6F_S$x`lT;QD7tN)UrG;f@d1s}&qO2dTn;Rz^3!Bd7 z&Q^EJo813Y68pP@M1d?3Wf}hAgMskFKm=eQI1GdW1EIn|Jb{7egMsLWfk0>$hyfUg zK^TZ37>HpQjC+}UzVBbQWT|F_Mx!53L;M53u2)>aCCh?T@|X;rQ;1)`K6WQ&SRMoS zR`3m1cGE1RG{SY#1iv4Cj1*Mz<>CeP-S5Zo&u@Q{S4UJyiTAlP!wk5n{r>5)8?|z0 R7QCk#=6CnD& Date: Sun, 4 Nov 2018 17:02:18 +0100 Subject: [PATCH 4/7] removed firmware.map --- examples/picosoc/firmware.map | 80 ----------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 examples/picosoc/firmware.map diff --git a/examples/picosoc/firmware.map b/examples/picosoc/firmware.map deleted file mode 100644 index 657ca3c..0000000 --- a/examples/picosoc/firmware.map +++ /dev/null @@ -1,80 +0,0 @@ - -Memory Configuration - -Name Origin Length Attributes -FLASH 0x0000000000050000 0x0000000000100000 xr -RAM 0x0000000000000000 0x0000000000002000 xrw -*default* 0x0000000000000000 0xffffffffffffffff - -Linker script and memory map - - -.text 0x0000000000050000 0x1dc - 0x0000000000050000 . = ALIGN (0x4) - *(.text) - .text 0x0000000000050000 0x16a /tmp/ccBvQ25N.o - .text 0x000000000005016a 0x72 /tmp/cchneX8U.o - 0x000000000005016a set_irq_mask - 0x0000000000050170 main - *(.text*) - *(.rodata) - *(.rodata*) - *(.srodata) - *(.srodata*) - *(.eh_frame) - *(.eh_frame*) - 0x00000000000501dc . = ALIGN (0x4) - 0x00000000000501dc _etext = . - 0x00000000000501dc _sidata = _etext - -.rela.dyn 0x00000000000501dc 0x0 - .rela.text 0x00000000000501dc 0x0 /tmp/ccBvQ25N.o - -.data 0x0000000000000000 0x14 load address 0x00000000000501dc - 0x0000000000000000 . = ALIGN (0x4) - 0x0000000000000000 _sdata = . - 0x0000000000000000 _ram_start = . - *(.data) - .data 0x0000000000000000 0x14 /tmp/ccBvQ25N.o - .data 0x0000000000000014 0x0 /tmp/cchneX8U.o - *(.data*) - *(.sdata) - *(.sdata*) - *(.init_array) - *(.init_array*) - 0x0000000000000014 . = ALIGN (0x4) - 0x0000000000000014 _edata = . - -.bss 0x0000000000000014 0x0 load address 0x00000000000501f0 - 0x0000000000000014 . = ALIGN (0x4) - 0x0000000000000014 _sbss = . - *(.bss) - .bss 0x0000000000000014 0x0 /tmp/ccBvQ25N.o - .bss 0x0000000000000014 0x0 /tmp/cchneX8U.o - *(.bss*) - *(.sbss) - *(.sbss*) - *(COMMON) - 0x0000000000000014 . = ALIGN (0x4) - 0x0000000000000014 _ebss = . - -.heap 0x0000000000000014 0x0 - 0x0000000000000014 . = ALIGN (0x4) - 0x0000000000000014 _heap_start = . -LOAD /tmp/ccBvQ25N.o -LOAD /tmp/cchneX8U.o -OUTPUT(firmware.elf elf32-littleriscv) - -.comment 0x0000000000000000 0x11 - .comment 0x0000000000000000 0x11 /tmp/cchneX8U.o - 0x12 (size before relaxing) - -Cross Reference Table - -Symbol File -_ebss /tmp/cchneX8U.o -_sbss /tmp/cchneX8U.o -debug /tmp/ccBvQ25N.o -main /tmp/cchneX8U.o - /tmp/ccBvQ25N.o -set_irq_mask /tmp/cchneX8U.o From fb98539be0a47a0eb43667897174fdf1bec74a54 Mon Sep 17 00:00:00 2001 From: matt venn Date: Sun, 4 Nov 2018 17:07:22 +0100 Subject: [PATCH 5/7] added elf for simulation --- examples/picosoc/firmware.elf | Bin 0 -> 9388 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 examples/picosoc/firmware.elf diff --git a/examples/picosoc/firmware.elf b/examples/picosoc/firmware.elf new file mode 100755 index 0000000000000000000000000000000000000000..ea7c87068f4c11313566b57d71a84d9390213965 GIT binary patch literal 9388 zcmeHNUuauZ82|1~Zn9e4(%tI(19F#07KdcB4m&DHnz-(-dysa0*><@}ZfS5y+T=2) z4_a6EVg=nIqsShL_@pmxvehT)y0(l`>IgHGG736S5FN8>9l|ny-%W0E6%?O*@qFRS z@B5weo$uWH%RLYGH)%4FA%O`1EU02u~AWit9~F{T?d4#EkL+>9}uphXbG;~4}_}^0O9I-AY9!5gm2=S z%C44L?U@2m7AXc1Am* z+y7n)yx77#c)xa=2PXyC_&X?77$5vz|L>>_kzELvkNtoD2d>Niw}c; z;Nq`?zvtrbfS+^m)8LNr{hb5hvk`0o%>U6}_$T0wUIFNLo)ha9fWDt2cK3hrC+?+r zCmG23UjaYGd_BO8m~R=_952(?;2*oLhqhVSp>3(uYdeQ}Uh0kJDN`8M2aR0%m|4(` zbh<#r{D7qochvEjI&QDy(^N2vrllV@Q}$3sGndvgxs0W!4a=Zo`TUTJHae5VqN~qg zG>|D|Uoi@1G(~zbV^`2k%RFI$a*|%Gx7lRSG=}t|Wfag|FtYV9Yh-eyn|2~!9N$yc zD85V-Exwwyj3m%1)Ns&=>^Y+Lm?+nda&3yH^4YAJvmo2Qw#Sgk&$)dLhMzq=pnPt| zG3R;Rj0SG5tr`Sc^S1(Ptb;9xc@1zL|Ca3 zV{L^afJHQ-+i1jA89fN+b;|dGt+M7lAbuE&_!iJHuEWN2H0~9#FGTblcht?v`vbR` BA<+N; literal 0 HcmV?d00001 From 56dfcf027a9df567ab5dda4ada8e3ec8e403f77f Mon Sep 17 00:00:00 2001 From: matt venn Date: Sun, 4 Nov 2018 17:15:35 +0100 Subject: [PATCH 6/7] edits --- examples/picosoc/README.md | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/examples/picosoc/README.md b/examples/picosoc/README.md index 002912f..fd3dc01 100644 --- a/examples/picosoc/README.md +++ b/examples/picosoc/README.md @@ -10,7 +10,7 @@ https://github.com/cliffordwolf/picorv32 The SOC example that uses the PicoRV32 was originally made for the Lattice 8k evaluation board. This example has been modified to work with the TinyFPGA by Luke from TinyFPGA. -# Toolchain +# FPGA Toolchain You can synthesise the demo with the [icestorm](http://www.clifford.at/icestorm/) toolchain. A very convient way to install the toolchain is to use [APIO](https://github.com/FPGAwars/apio) @@ -19,3 +19,36 @@ And then set your path to include the installed tools and copy the chipdb files: export PATH=$PATH:~/.apio/packages/toolchain-icestorm/bin/ sudo cp -r ~/.apio/packages/toolchain-icestorm/share/icebox/ /usr/local/share/ +You will also need tinyprog: + + pip install tinyprog + +For more info on the TinyFPGA tools and setup see the TinyFPGA page: https://tinyfpga.com/bx/guide.html + +At this point you should be able to run make upload to synthesise the hardware and program to the TinyFPGA. +I have precompiled the firmware.c and added the firmware.bin and hex files to the repo so you don't need GCC. + +If you just want to see the demos in the video, you can just switch to the serial branch + + git checkout serial + git checkout ws2812 + +Which should allow you to program the precompiled firmware or run the simulation without installing GCC. + +# GCC for firmware compilation + +As this is a RiscV CPU running on the FPGA, we really need the RiscV GCC tools to get the most out of it! +Fetching the repos and compiling took about 3 hours on my 4 year old T400 Lenovo laptop. Full instructions +here: https://github.com/cliffordwolf/picorv32#building-a-pure-rv32i-toolchain + +What I did was: + + sudo apt-get install autoconf automake autotools-dev curl libmpc-dev \ + libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo \ + gperf libtool patchutils bc zlib1g-dev git libexpat1-dev + git clone git@github.com:cliffordwolf/picorv32.git + cd picorv32/ + time make -j2 build-riscv32i-tools + export PATH=$PATH:/opt/riscv32i/bin/ + +Then make firmware.bin should work and you can then write your own c program or edit my demos. From 9a5c9cb9fc09344bf0535946a51b30e60cf99c4c Mon Sep 17 00:00:00 2001 From: matt venn Date: Sun, 4 Nov 2018 17:19:14 +0100 Subject: [PATCH 7/7] readme edits --- examples/picosoc/README.md | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/examples/picosoc/README.md b/examples/picosoc/README.md index fd3dc01..2f3e561 100644 --- a/examples/picosoc/README.md +++ b/examples/picosoc/README.md @@ -1,3 +1,15 @@ +# Video Notes + +Git repository https://github.com/mattvenn/TinyFPGA-BX/tree/master/examples/picosoc + +The README.md contains information on: + +* Information about installing the toolchains +* Electrical wiring for the demos +* Precompiled firmware binaries: + * master - starting point + * ws2812 - includes ws2812 driver and serial driver + # PicoSOC TinyFPGA example PicoSOC is an SOC - system on chip. It includes everything you need to @@ -14,10 +26,12 @@ board. This example has been modified to work with the TinyFPGA by Luke from Tin You can synthesise the demo with the [icestorm](http://www.clifford.at/icestorm/) toolchain. A very convient way to install the toolchain is to use [APIO](https://github.com/FPGAwars/apio) -And then set your path to include the installed tools and copy the chipdb files: +And then set your path to include the installed tools and copy the chipdb and yosys files: export PATH=$PATH:~/.apio/packages/toolchain-icestorm/bin/ sudo cp -r ~/.apio/packages/toolchain-icestorm/share/icebox/ /usr/local/share/ + sudo cp -r ~/.apio/packages/toolchain-icestorm/share/yosys /usr/local/share/ + You will also need tinyprog: @@ -28,9 +42,8 @@ For more info on the TinyFPGA tools and setup see the TinyFPGA page: https://tin At this point you should be able to run make upload to synthesise the hardware and program to the TinyFPGA. I have precompiled the firmware.c and added the firmware.bin and hex files to the repo so you don't need GCC. -If you just want to see the demos in the video, you can just switch to the serial branch +If you just want to see the demos in the video, you can switch to the ws2812 branch - git checkout serial git checkout ws2812 Which should allow you to program the precompiled firmware or run the simulation without installing GCC. @@ -46,9 +59,16 @@ What I did was: sudo apt-get install autoconf automake autotools-dev curl libmpc-dev \ libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo \ gperf libtool patchutils bc zlib1g-dev git libexpat1-dev + git clone git@github.com:cliffordwolf/picorv32.git cd picorv32/ time make -j2 build-riscv32i-tools export PATH=$PATH:/opt/riscv32i/bin/ Then make firmware.bin should work and you can then write your own c program or edit my demos. + +# Wiring for the demo + +* Serial TX is pin 1 +* Serial RX is pin 2 +* WS2812 data is pin 3