cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L552CCT6 Unable to erase flash memory

karoyama2
Associate

I can't erase the flash in the STM32L552CCT6 with the code below. I wonder if my code is wrong. When I check the memory, the 2kB from the flash address 0x803F800 is not 0xFF. The reason it wasn't 0xFF originally seems to be because something other than 0xFF happened to be written during debugging.

Thank you.

 
uint32_t error;
uint8_t  ram[2048];

HAL_FLASH_Unlock();

FLASH_EraseInitTypeDef flash;
flash.NbPages   = 1;
flash.Page      = 127;
flash.TypeErase = FLASH_TYPEERASE_PAGES;
flash.Banks     = 1;
if (HAL_FLASHEx_Erase(&flash, &error) == HAL_OK)
{
  HAL_FLASH_Lock();
  if (error != 0xFFFFFFFF) return false;
  else
  {
    if (keepRamData == false) memset(ram, 0xFF, 2048);
    return true;
  }
}
HAL_FLASH_Lock();
return false;

Code formatting applied - please see How to insert source code for future reference.

1 ACCEPTED SOLUTION

Accepted Solutions

I remembered that I wanted to use FLASH as EEPROM in the past. I used eeprom_emul.c to achieve this. I will try to code it again using this.
Thank you.

View solution in original post

2 REPLIES 2
TDK
Guru

Does the code execute successfully? Return all HAL_OK status codes?

How are you checking the memory at 0x803F800?

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

I remembered that I wanted to use FLASH as EEPROM in the past. I used eeprom_emul.c to achieve this. I will try to code it again using this.
Thank you.