cancel
Showing results for 
Search instead for 
Did you mean: 

Unexpected EEPROM memory erase

TKova.1
Associate

Hi

I develop my own bootloader for STM32L152VC. The bootloader works, but I found something wierd.

When the device is turned on and there is no need to write the flash the program jumps to the application and everythings works properly.

When I write the flash and the program jumps to the application the entire EEPROM is erased. As I noticed it clearly depends on the HAL_FLASH_Unock() and HAL_FLASH_Lock() functions. Unlock clears two bits of the FLASH_PECR register, PELOCK and PRGLOCK. The lock function only sets the PRGLOCK. In the reference manual I found this: "To lock the FLASH_PECR and the data EEPROM again, the software only needs to set the PELOCK bit in FLASH_PECR" If I manually set the PELOCK, the EEPROM content will be preserved. Without setting PELOCK the EEPROM content will be cleared during the jump. According the debugger: at the last command of the bootloader the EEPROM is correct, at the first command of the application the EEPROM is blank.

The question is why did I lose the eeprom content? When will it be deleted?

Thanks.

SET_BIT(FLASH->PECR, FLASH_PECR_PELOCK);
            
const volatile vector_t *vector_p  = (vector_t*) APPLICATION_START_ADDR;
__disable_interrupt();                              // 1. Disable interrupts
__set_SP( vector_p->stack_addr );                   // 2. Configure stack pointer
SCB->VTOR = APPLICATION_START_ADDR;                 // 3. Configure VTOR
vector_p->func_p();                                 // 4. Jump to application

1 REPLY 1
TDK
Guru

It doesn't make sense the EEPROM would be erased without accessing it. Perhaps there is something in your startup code which erases it. Having it locked would prevent this.

If you feel a post has answered your question, please click "Accept as Solution".