cancel
Showing results for 
Search instead for 
Did you mean: 

I'm having trouble storing variable values ​​in FLASH memory. I am currently using the STU32F765VI MCU, I would like to know what address range I can use to store. What are the functions of the HAL library?

ALara.1
Associate

I am currently trying as follows:

HAL_FLASH_Unlock();

HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,0x40023BFD,10);

HAL_FLASH_Lock();

However, no data is recorded.

1 ACCEPTED SOLUTION

Accepted Solutions

Try picking an address that's in FLASH, and aligned on a 32-bit boundary

Typically 0x08000000..0x081FFFFF (2MB)

You can only write the value once after the memory has been erased. Try not to write/erase locations your code is executing from

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

View solution in original post

4 REPLIES 4

Try picking an address that's in FLASH, and aligned on a 32-bit boundary

Typically 0x08000000..0x081FFFFF (2MB)

You can only write the value once after the memory has been erased. Try not to write/erase locations your code is executing from

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

And how do I delete it, you know?

Peter BENSCH
ST Employee

Erasing Flash is only possible in chunks of the sector size of the specific device.

But usually it is not a good idea to store variables in Flash, as its endurance is limited to 10000 write cycles (over temperature range, see datasheet and search for Flash memory endurance).

It might be a better idea to either use devices providing EEPROM or EEPROM emulation software.

While providing the desired write cycles this approach consumes of course the amount of Flash being the number of emulated 'EEPROM blocks'. So for example, emulating a 1KB EEPROM with guaranteed 1Mio write cycles requires 1Mio/10k*1K=100K Flash.

Good luck!

/Peter

In order 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.

STM32Cube_FW_F7_V1.14.0\Projects\STM32746G-Discovery\Examples\FLASH\FLASH_EraseProgram\Src\main.c

 /* Unlock the Flash to enable the flash control register access *************/

 HAL_FLASH_Unlock();

 /* Fill EraseInit structure*/

 EraseInitStruct.TypeErase   = FLASH_TYPEERASE_SECTORS;

 EraseInitStruct.VoltageRange = FLASH_VOLTAGE_RANGE_3;

 EraseInitStruct.Sector    = FLASH_SECTOR_23; // 0x081E0000 as I recall

 EraseInitStruct.NbSectors   = 1;

 HAL_FLASHEx_Erase(&EraseInitStruct, &SECTORError) ;

 /* Lock the Flash to disable the flash control register access (recommended

   to protect the FLASH memory against possible unwanted operation) *********/

 HAL_FLASH_Lock();

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