dan-rodrigues / icestation-32

Compact FPGA game console
MIT License
152 stars 14 forks source link

Hang before reading flash and IPL #26

Open djkunkel opened 1 year ago

djkunkel commented 1 year ago

Hello! I'm trying this project out on an ICEbreaker v1.0e board with a WINBOND flash chip. I'm able to build and flash the bitstream and the bootloader using iceprog over usb, but when running it stops after printing STARTING NOW, never prints the name of the flashchip, and then hangs. If I enable BOOT_PROMPT it does flash the leds and wait for a button press.

I tried using the precompiled bitstream and program from (https://github.com/dan-rodrigues/super-miyamoto-sprint/releases/tag/0.2.0) using ice32-icebreaker-breakout-board.bit and prog-no-music.bin and I get the same effect.

ry755 commented 1 year ago

I seem to be running into the same issue with my iCEBreaker v1.0e. The main difference in my case is that I modified the hardware Verilog in order to support a plain VGA Pmod, but that shouldn't matter in this case considering you're running into the same issue.

ry755 commented 1 year ago

After doing some debugging I have figured out that it is in fact initializing the flash and attempting to load the program. It appears to be making it to the effective end of boot.S where it jumps to the RAM base address. My only guess as to what's going wrong is that maybe the data it's loading from flash is incorrect somehow? Not sure.

edit: I was wrong, it turns out it is actually making it to the user software's start.S! By playing around with setting the status LEDs at various stages of start.S I was able to figure that out. Now the question is, why is it failing to run the actual main() function?

edit 2: The behavior I'm seeing is really weird. It behaves differently depending on (seemingly) the size of the code? Adding or removing unrelated code (code that toggles LEDs, etc) makes it behave differently. This is really hard to debug since it works perfectly in the simulator :( I have also tried various different RISC-V toolchains, just in case there was some issue with the one I was originally using.

ry755 commented 1 year ago

Aha I figured it out! On line 307 of hardware/icebreaker/ics32_top_icebreaker.v, change RESET_DURATION_EXPONENT from 24 to 2. 2 is the value that the simulator uses. Honestly I mostly found this out just by messing around with various settings because I was out of other ideas :p

djkunkel commented 1 year ago

This is fantastic news @ry755. I have two versions of the 1.0e, one with a Q part number in the winbond chip and one without. One works as is, and the other fails in the way I described. The one with the Q works. There seems to be code to enable the QSPI mode of the chip, so it seems like it should work on both. I will give your change a try and see if it fixes it for me.

ry755 commented 1 year ago

Hmm, I just discovered that power cycling the board breaks it again until you reset it by reflashing one of the software demos. Also, RESET_DURATION_EXPONENT values only up to 21 work on my board, setting it to any value higher than that it doesn't make it past "STARTING NOW" in either situation.