cancel
Showing results for 
Search instead for 
Did you mean: 

Writing 32-bit Data to Flash Memory on STM32G474

Savan_Sutariya
Associate II

I'm working with an STM32G474 microcontroller and need guidance on how to write 32-bit data to flash memory. Could someone provide me with a proper procedure or example code that demonstrates how to accomplish this task efficiently and correctly? Any insights or best practices would be greatly appreciated.

@STTwo-32 @SofLit 

2 REPLIES 2
MHAMR.1
ST Employee

Hello Savan,

I suggest beginning with the FLASH_EraseProgram example found in the STM32 Cube Firmware package at "STM32Cube_FW_G4_Vxxx\Projects\NUCLEO-G474RE\Examples\FLASH". This example outlines the correct procedures for erasing and writing to the Flash memory.

B.R.

Mohamed

>>Any insights or best practices would be greatly appreciated.

Don't use memory that your application is physically residing in. Perhaps shrink the memory seen by the Linker via the Linker Script, so you can have a unused portion at the top-of-memory to use.

Erase prior to usage.

You can only write to an erased location once, but can write across the whole sector before needing to erase. You can journal data/configuration items byte writing new content to the next available slot, and then finding the latest when you want to recover it.

Write on 4-byte aligned addresses, perhaps look if the Flash write-line is wider, say 8 or 16-bytes wide. I don't recall on the G4, but it will be discussed in the Reference Manual, and the example appears to directly support 4-byte / 32-bit word writes.

STM32Cube_FW_G4_V1.5.1\Projects\NUCLEO-G474RE\Examples\FLASH\FLASH_EraseProgram\Src\main.c

 

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