rustworks icon indicating copy to clipboard operation
rustworks copied to clipboard

Bootloader & flasher for QPI external flash

Open willemml opened this issue 3 years ago • 13 comments

Need to finish QSPI flash and then create a boot loader so RustWorks can be flashed to external flash. Potentially useful links:

  • flashAlgorithm docs: https://www.keil.com/pack/doc/CMSIS/Pack/html/flashAlgorithm.html
  • flashAlgorithm for RP2040: https://github.com/rp-rs/flash-algo

Todo:

  • [ ] Read external flash
  • [ ] Write external flash
  • [x] Flash algorithm implementation so that cargo flash can access external flash (done in willemml/rsworks-flash-algo)
  • [ ] Make probe-rs and cargo-embed use flash algorithm
  • [x] Enable writing external flash using dfu-util

willemml avatar Jun 26 '21 07:06 willemml

As of ab411664f85e reading external flash seems to work correctly, but writing to it and erasing it does not. Unsetting memory mapped mode no longer causes a crash.

willemml avatar Jul 05 '21 00:07 willemml

Note that external flash is actually supposed to be read as 32 bit integers, not individual bytes. This is shown (working) in a3d80abc002f.

willemml avatar Jul 05 '21 00:07 willemml

One issue I noticed in external_flash.rs is that you use self.qspi.cr.write instead of modify in send_command_full, which will some settings to their reset value.

rfuest avatar Jul 05 '21 17:07 rfuest

Hmm, I tried using modify instead of write for cr but now attempts to write memory cause the calculator to either crash or freeze (without reseting, so I am going to assume it is waiting for the abort).

willemml avatar Jul 05 '21 18:07 willemml

For reference, here are the changes I made:

self.qspi.cr.write(|w| w.abort().set_bit());

to

self.qspi.cr.modify(|_, w| w.abort().set_bit());

and then I also tried

self.qspi.cr.write(|r, w| unsafe { w.bits(r.bits()) }.abort().set_bit());

willemml avatar Jul 05 '21 18:07 willemml

Thanks to #8 all that is left is to create a bootloader that also allows flashing of the QPI external flash via tools such as probe-rs and dfu-util.

willemml avatar Jul 07 '21 06:07 willemml

There is a boot loader project called loadstone that looks interesting and is probably worth exploring...

EDIT: Might be worth waiting for loadstone to directly use embedded-hal to make porting it to stm32f730 easier if the loadstone route is taken. Will continue to explore alternative methods of using external flash for main program storage.

willemml avatar Jul 13 '21 18:07 willemml

Flash algo ~~attempt~~ (fixed by rfuest in willemml/rsworks-flash-algo#1): https://github.com/willemml/rsworks-flash-algo

willemml avatar Jul 15 '21 08:07 willemml

Do you still have the issue? I have worked on QSPI flash drivers, I can help if needed.

naveenprasathc avatar Jul 30 '21 13:07 naveenprasathc

Currently the only things left to do are to allow probe-run to use the flash also (so add a command line argument to take custom chip definition yaml, which needs to be done in the probe-run repo), add dfu support and a boot loader.

willemml avatar Jul 30 '21 18:07 willemml

@Npc15 if you have any tips (or want to help with) creating a dfu bootloader (or even just a bootloader in general for the QSPI flash) it would be greatly appreciated, my current blocker is moving the code off of internal flash and onto QSPI (the end goal being to have the bare minimum on the internal flash).

willemml avatar Aug 05 '21 05:08 willemml

@Npc15 if you have any tips (or want to help with) creating a dfu bootloader (or even just a bootloader in general for the QSPI flash) it would be greatly appreciated, my current blocker is moving the code off of internal flash and onto QSPI (the end goal being to have the bare minimum on the internal flash).

Ok sure, will give you an update soon

naveenprasathc avatar Aug 05 '21 19:08 naveenprasathc

As of 5a52fe6 DFU flashing of external flash works, booting not yet implemented.

willemml avatar May 15 '22 20:05 willemml