cancel
Showing results for 
Search instead for 
Did you mean: 

How to write dirctly to a Flash memory address?

RChar.2
Associate II

Hi,

I'm working on Stm32CUBE IDE with STM32LO71RB. I would like to write a version number when I am flashing my device at EEPROM Flash memory address 0x08080000. I've tried HAL_FLASH_Program(), but I have to execute it at each reset. I would like to do the same as an One-time programmable memory but it's not availlable in STM32 cortex M0+.

Is there any other possibilities to write directly in EEPROM memory?

best,

1 ACCEPTED SOLUTION

Accepted Solutions
Uwe Bonnes
Principal III

You can only write flash once unless you erase i n between. But erase erases full sectors, that's the difference to EEPROM

View solution in original post

4 REPLIES 4
Uwe Bonnes
Principal III

Look for EEPROM emulation. B.t.w. I think 0x08080000 is no good place, it is in the middle of the code space. Move it to top of flash.

RChar.2
Associate II

Thank you for youyr answer, I already use HAL_flash and Hal_flash-ex for the eeprom emulation. Thanks for the tips but I did'nt find my answer in the doc or maybe is not the good formulation.

I know that in microchiop environment it is possible to write directly in assembly to the memory at the flashing moment.

asm("\
    PSECT   absdata,delta=2,abs\n\
    ORG 1000h\n\
    dw  1111h\n\
");  

Currently, I've have that:

void main (void)
{
 
//HAL _init ... 
  HAL_FLASH_Unlock();
  if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, ADDR , data)  != HAL_OK)
     Error_Handler();
  HAL_FLASH_Lock();
 
while(1){
 
} 
 
}

For me, if I restart the code, the write EEPROM operation will be execute another time and the variable "data" is stored twice, in the Flash Code and in the EEPROM.

I would like to find a way to execute it only once.

Tel me if my reasoning doesn't work?

Uwe Bonnes
Principal III

You can only write flash once unless you erase i n between. But erase erases full sectors, that's the difference to EEPROM

RChar.2
Associate II

ok thanks, I understand it better.

So if y want to write to the flash, I have to modify my linker and use __atribute__ to allocate memory to my data like it said on this topic ?

https://stackoverflow.com/questions/28503808/allocating-memory-in-flash-for-user-data-stm32f4-hal