cancel
Showing results for 
Search instead for 
Did you mean: 

How to save app settings to flash

Louie88
Associate III

I need to save a couple of bytes (a settings struct) to upper (last) page of the Bank1 flash. The settings are changed very rarely so lifetime of the flash is not an issue. The settings struct has a CSC member so when the settings are read from the flash during startup the settings would be applied only if the CSC of the settings struct is right.

I know that I have to unlock, then erase a full page (128kB) before saving the app settings. How can I do this using HAL_Flash_xxx calls? I also must lock out the last page of Bank1 from code space (Linker file?). Can anybody send an example? I am using STM32H7474I-DISCO discovery board. 

Thanks,

Louis

PS: Adding a small, external SPI/I2C NVRAM/Flash chip won't work. I have to solve saving/restoring settings within the discovery board.

 

1 REPLY 1
TDK
Guru

Here is an example which erases a flash page and then writes to it.

STM32CubeH7/Projects/STM32H735G-DK/Examples/FLASH/FLASH_EraseProgram/Src/main.c at a64bfcbb83adf21adce13cab48ee0dce47837ac1 · STMicroelectronics/STM32CubeH7

If you feel a post has answered your question, please click "Accept as Solution".