BrunoLevy / learn-fpga

Learning FPGA, yosys, nextpnr, and RISC-V
BSD 3-Clause "New" or "Revised" License
2.53k stars 242 forks source link

WIP: Icesugar support #49

Open piso77 opened 2 years ago

piso77 commented 2 years ago

The Icesugar board is a close relative (clone?) of the Icebreaker board: iCE40UP5K, 12Mhz clock, 3 PMODS (well, technically four if you solder one header), 8MB SPI flash, etc and while it was already mentioned in FemtoRV, the target didn't build.

This pull request is a WIP (aka builds but don't run) and reviews/comments/ pointers are welcome: i went with the FEMTORV32_QUARK (since GRACILIS didn't fit, werird since sugar and breaker share the same exact fpga chip - BTW, is FEMTO good enough to run code from flash?) and had to execute code from SPI flash (since firmware.hex was ~45KB and blew past the available 12KB BRAM), on top of that SPI flash is only 8MB (vs 16MB in Icebreaker - see also NRV_RESET_ADDR) and i still have to figure out FemtoRV/FIRMWARE/CRT/spiflash*.ld blackmagic.

I already checked the pcf against the schematics (so that part should be correct), while i'm a bit worried about code execution from flash/linker script errors and wouldn't be surprised if i overlooked something there.

Let me know.

dkilfoyle commented 2 years ago

Hi. I stumbled across this comment in https://github.com/wuxx/icesugar/blob/master/src/basic/verilog/flash/top.v

//from ice40 ultraplus datasheet, the miso/mosi are inverted in the ice40 when in flash-prog mode

Invert the relevant pin definitions in BOARDS/icesugar.pcf to:

set_io spi_miso 17 set_io spi_mosi 14

...and it seems to work fine - firmware can be flashed at 0x20000 and Femtosoc will execute the program from flash.

PS: I'm compiling firmware on WSL2 and then executing icesprog in windows to do the uploading as WSL doesn't support USB devices on Windows host. To flash the firmware (eg hello.c) I use

icesprog -o 0x20000 hello.spiflash.bin

...because icesprog doesn't seem to support text offsets as used in the FIRMWARE/makefile.inc (iceprog -o 128k ....)

piso77 commented 2 years ago

Hi. I stumbled across this comment in https://github.com/wuxx/icesugar/blob/master/src/basic/verilog/flash/top.v

//from ice40 ultraplus datasheet, the miso/mosi are inverted in the ice40 when in flash-prog mode

Invert the relevant pin definitions in BOARDS/icesugar.pcf to:

set_io spi_miso 17 set_io spi_mosi 14

...and it seems to work fine - firmware can be flashed at 0x20000 and Femtosoc will execute the program from flash.

PS: I'm compiling firmware on WSL2 and then executing icesprog in windows to do the uploading as WSL doesn't support USB devices on Windows host. To flash the firmware (eg hello.c) I use

icesprog -o 0x20000 hello.spiflash.bin

...because icesprog doesn't seem to support text offsets as used in the FIRMWARE/makefile.inc (iceprog -o 128k ....)

Somehow i completely missed your comment - thanks, i'll give it a shot later today, or tomorrow.

piso77 commented 2 years ago

Indeed, after inverting spi MISO/MOSI, i successfully flashed hello world and see it execute from flash.