Skip to main content
dango.11
Associate
December 20, 2022
Solved

How to retain a 32bit real value on FLASH Memory in STM32L041x6

Hi!

I am trying to store a real value in the flash memory of my STM32 but i am struggling to write it. Has anyone already done this in the same STM32L041x6 processor?

If so , how can i do it? also, is it possible to read it back?

Thanks in advance!!

This topic has been closed for replies.
RomainR.
RomainR.Best answer
ST Employee
December 20, 2022

Hello dango.1 (Community Member)

You can refer to the STM32Cube_FW_L0 example below:

\STM32Cube\Repository\STM32Cube_FW_L0_V1.12.1\Projects\NUCLEO-L031K6\Examples\FLASH\FLASH_EraseProgram.

It shows how to use Flash HAL function to first unlock the flash then erase a page and finally write a word.

However, you also have to check the flash erase/programming maximum cycle if it fits to your application ?

However, for user data, the STM32L041 (categorie 2) device embed 1 Kbyte of data EEPROM that is very suitable to store user data.

You can find the relative function to manage EEPROM located in stm32l0xx_hal_flash_ex.h / .c

Best regards,

Romain

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

5 replies

Tesla DeLorean
Guru
December 20, 2022

Imagine it is just 4-bytes of data, and use pointers, casting or union/struct​

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

Ideally create a flash data sector in the linker config file so the address is fixed while your code grows. Use pointers as Clive mentionned.

dango.11
dango.11Author
Associate
December 20, 2022

Thanks for the help! , do you know where could i find an example? I am really lost at this.

RomainR.
RomainR.Best answer
ST Employee
December 20, 2022

Hello dango.1 (Community Member)

You can refer to the STM32Cube_FW_L0 example below:

\STM32Cube\Repository\STM32Cube_FW_L0_V1.12.1\Projects\NUCLEO-L031K6\Examples\FLASH\FLASH_EraseProgram.

It shows how to use Flash HAL function to first unlock the flash then erase a page and finally write a word.

However, you also have to check the flash erase/programming maximum cycle if it fits to your application ?

However, for user data, the STM32L041 (categorie 2) device embed 1 Kbyte of data EEPROM that is very suitable to store user data.

You can find the relative function to manage EEPROM located in stm32l0xx_hal_flash_ex.h / .c

Best regards,

Romain

In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.