cancel
Showing results for 
Search instead for 
Did you mean: 

flash program single byte in stm32L031g6

Heo WooHyeok
Associate
Posted on November 20, 2017 at 08:00

I want to write 1byte variable to the internal flash memory. 

It works well when I write 4bytes variable like this.

if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, vari4) == HAL_OK)

{

   Address+=4;

}

but when I write 1 byte variable to the memory like this, it works only first time.

when I call HAL_FLASH_Program next time it doesn't work and goes to the Hardfault_handler

if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, Address, vari1) == HAL_OK)

{

 Address+=1;

}

Is it impossible to Program single byte data to internal flash memory in stm32l031g6?

2 REPLIES 2
Uwe Bonnes
Principal II
Posted on November 20, 2017 at 10:57

Read and understand the flash programming section of the reference manual.

In short : erased flash in L0 is set to 0, programming can only set it to '1'. If your second programming tries to set some bits from '1' to '0', things fail.

B.t.w. most other STM32 erase to '1'.

Posted on November 20, 2017 at 20:52

In most cases it is more complicated than that because ST uses additional bits for ECC, so you get a single shot at programming

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