2025-04-17 3:43 AM - last edited on 2025-04-17 3:49 AM by Andrew Neil
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.
Solved! Go to Solution.
2025-04-17 7:16 PM - edited 2025-04-17 7:17 PM
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.
2025-04-17 5:49 AM
Does the code execute successfully? Return all HAL_OK status codes?
How are you checking the memory at 0x803F800?
2025-04-17 7:16 PM - edited 2025-04-17 7:17 PM
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.