cancel
Showing results for 
Search instead for 
Did you mean: 

SPI External Flash Loader for STM32F407VE

MSing.8
Associate III

I am trying to create external flash loader for STM32F407VE.

The flash is w25q64jv - 8MB.

I tried to follow the tutorial but since this is QuadSPI and I think STM32F407VE does not support QuadSPI.

https://www.youtube.com/watch?v=XqCq0xtQmbI&list=PLnMKNibPkDnHIrq5BICcFhLsmJFI_ytvE&index=5

Are there any reference material that I can refer to create SPI based(Not QSPI) external flash loader?

Does STMCubeProgrammer comes with external flash loader to support STM32F407VE ?

4 REPLIES 4

>>Does STMCubeProgrammer comes with external flash loader to support STM32F407VE ?

Well it can use an External Loader you provide, there is an SPI_FLASH type, you'd likely create a faux address for memory so the linker/tools can build an image you can subsequently write to the memory.

You'd have to implement the Read, Write, Erase, Verify, functions in much the same way and form as one might for a QSPI, but accessing the memory using your BSP function.

I'd recommend testing your BSP code in application space before porting into an External Loader, as those are much more difficult to debug.

Perhaps search GitHub for examples.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andreas Bolsch
Lead II

If you're not bound to use CubeProg: There is a patch for OpenOCD,

https://review.openocd.org/c/openocd/+/4152

for SPI-Flash, SPI-EEPROMs and I2C-EEPROMs. And don't worry about speed, it's limited mainly by SWD clock rate and hardware programming speed of the memory chip ...

MSing.8
Associate III

Andreas, Thank you for the direction.

I explored the link a little bit.

I am open to explore further.

I have st-link v2 to talk to the STM32F407VE chip and the flash is connected to it. flash pins connected to stm32 are known.

Please share how to use openocd for the flashing. The last time i vaguely remember using it in Visual Studio Code through platformio.

Some guide or manual would help on how to flash using openocd.

Regards.

Oh, just realized that I pointed you to an outdated patch. The current one is https://review.openocd.org/c/openocd/+/4760

For the configuration: Take one of the sample configs, e.g.

tcl/board/cmspi_stm32f746g-disco.cfg

Of course, this must be adoped to F4 instead of F7, but that's rather straightforward.

The GPIO setting could be done manually or via the script contrib/cmspi_gpio/gpio_conf_stm32.pl

Something like ./contrib/cmspi_gpio/gpio_conf_stm32.pl -b 0x40020000 -c "PA04:PP:M, PA05:PP:V, PA06:INUP:V, PA07:INUP:V" would work for NCS on PA04, CLK on PA05, and MOSI and MISO on PA06 and PA07 respectively (details to be found in this script).

The first part goes after the "flash bank", the second part in "cmspi_init". As you need plain SPI only, all the stuff when $mode equals 1 can be discarded.

Your flash needs only 3-byte addresses, hence there in no additional set-up needed.

Regarding integration in an IDE I can't tell anything, I've always used OpenOCD stand-alone via telnet interface. With or without this special driver, you can even program flash from command line with something like (see chap. 13 of OpenOCD manual)

# program and verify using elf/hex/s19. verify and reset

# are optional parameters

openocd -f board/stm32f3discovery.cfg \

-c "program filename.elf verify reset exit"

The data to be programmed is automatically split into the ranges for the internal and external flash and sent to the appropriate flash, nothing to do about that manually.

But: 1) a 'fake' address range must be assigned to the external flash (in the sample script it's the 0x90000000 in the "flash bank" command) and compiler/linker must map the data for external flash to this range

2) use only elf-, hex- or s19-file for programming, never a bin-file, as the latter type can't span across gaps (between internal and external flash)