cancel
Showing results for 
Search instead for 
Did you mean: 

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

dango.11
Associate II

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!!

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

5 REPLIES 5

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

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

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.

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

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.

Hi!

Thanks for the help!

My application is related to a brushless motor control ,i control its current and i wanted to implement a mode so i can change the intensity depending on the use but that if i turn off and on the microproccesor, that value is retained.

I will be trying the eeprom cause even though this mode will not be used many times,i don´t wanna waste the flash cycles.