I am a new owner of a HiFive1 Rev B (technically the sparkfun Red-V) and I’m looking to fiddle around with reading and writing to the external qspi flash.
I wanted to check if anyone here has some experience with it. I’ve attempted to look around online but have been very unsuccessful and the Freedom-metal-sdk does not offer this functionality.
From what I can tell there are two possible avenues for me to be able to write to flash:
-
Unlikely, but maybe just writing to a memory space associated with the QSPI (0x20010000+0x6a120)? This depends on whether or not the QSPI interface is able to handle writes by default, which my understanding is that it’s a read-only interface (this implementation is at least). But if possible as far as I know all I would need to do is modify the linker script to designate a section of that memory space as writable.
-
Use the SPI0 peripheral. This one is the most likely the avenue I would need to take. My understanding is that if I enable SPI0 as a peripheral that will disable the QSPI interface. I have a few questions regarding this method:
2a. Double check my understanding here: I see from the datasheet that I need two steps when it comes to changing SPI0 between IO and memory-mapped mode:
- Change the ‘en’ bit of the fctrl register (0x10014000+0x60) - 1 for memory-mapped and 0 for IO
- Change the ‘dir’ bit of the fmt register (0x10014000+0x40) - 1 for memory-mapped and 0 for IO
Am I missing anything? Should I be saving+restoring the ffmt register as well?
2b. Before I make the change from memory-mapped to IO mode I need to ensure that the Flash SPI write function is fully within cache or ITIM. I see there’s an example in the Freedom SDK on how I can add a function into ITIM, but ideally I should add the function at runtime since ITIM can be cleared and the whole thing working relies on the function being in ITIM. Any resources on how I may be able to add functions into cache/ITIM at runtime?
2c. I will need to know the messaging protocol of the external flash in order to write to it. I suspect it’s relatively standard between flash manufacturers? I will take a look at the sparkfun red-v qpsi flash datasheet (IS25LP032D) but any knowledge on whether or not this part of the project would be portable between platforms?
2d. Anything else I may be missing? I have a feeling that the QSPI flash chip won’t automatically switch between SPI and QSPI mode, so some insight in that matter would be great since I don’t have any experience with QSPI flash chips!
Thank you for giving this a read! Hopefully I am on the right track for this project… but more ideally I hope someone else has done this work already haha