Skip to main content
SKarl.3
Associate II
April 14, 2023
Solved

STM32L4: How to program MCU on-board flash from binary stored in external FLASH?

  • April 14, 2023
  • 1 reply
  • 1466 views

I have a design that uses and STM32L4 series MCU. The device will be hard to physically access, but has a serial connection to the 'outside' world on UART 4. The board also has a 4 Mbit flash connected to the MCU via (bit-banged) SPI.

When I need to update the FW in the MCU I'd like be able to send the binary file down the serial connection, store it in the external SPI flash, verify the download is good, and then copy flash the MCU FLASH so that the next boot up will be with the new FW.

Can someone please first verify if this is possible, and second point me to some resources on how to implement it?

Thanks!

This topic has been closed for replies.
Best answer by Tesla DeLorean

Yes, you can stage data in external memory, and subsequently pull that and write internal memory.

Would generally recommend making a small loader at the front of the internal flash which you never erase, it contains enough code to check the new app code, and then write it slightly deeper into internal flash. How much deeper depends on how tight the implementation is, but suspect the loader would take 16KB or less.

Things to have are some means to determining image size, and also a checksum or CRC for integrity checking.

STM32Cube_FW_L4_V1.17.2\Projects\NUCLEO-L432KC\Examples\FLASH\FLASH_EraseProgram

Seem to recall having posted L4 and L5 flashing code to the forum in recent weeks. Block sizes on the flash are relatively small and manageable.

1 reply

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
April 14, 2023

Yes, you can stage data in external memory, and subsequently pull that and write internal memory.

Would generally recommend making a small loader at the front of the internal flash which you never erase, it contains enough code to check the new app code, and then write it slightly deeper into internal flash. How much deeper depends on how tight the implementation is, but suspect the loader would take 16KB or less.

Things to have are some means to determining image size, and also a checksum or CRC for integrity checking.

STM32Cube_FW_L4_V1.17.2\Projects\NUCLEO-L432KC\Examples\FLASH\FLASH_EraseProgram

Seem to recall having posted L4 and L5 flashing code to the forum in recent weeks. Block sizes on the flash are relatively small and manageable.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..