Solved
HAL_FLASHEx_Erase() returns OK but no flash is erased on STM32G030C8Tx
Using STM32G030C8Tx and I'm having a difficult time trying to erase flash. The function returns with no error, and stepping through appears to work. But the flash is not erased (viewing through CubeIDE memory explorer, and writes fail with `FLASH_SR_PGSERR`). Here's the code:
#define APP_START_PAGE (10) // Corresponds to 0x0800_4800, each page is 2kb
#define NUMBER_OF_PAGES_TO_ERASE (22)
uint32_t PageError;
FLASH_EraseInitTypeDef flashErase_handle;
static uint8_t execute_flash_erase(void)
{
HAL_StatusTypeDef status = HAL_OK;
PageError = 0;
// Configure the flash erase handle with the provided parameters
flashErase_handle.TypeErase = FLASH_TYPEERASE_PAGES;
flashErase_handle.Page = APP_START_PAGE;
flashErase_handle.NbPages = NUMBER_OF_PAGES_TO_ERASE;
flashErase_handle.Banks = FLASH_BANK_1;
if (HAL_FLASH_Unlock() == HAL_OK)
{
status = HAL_FLASHEx_Erase(&flashErase_handle, &PageError);
}
else
{
status = HAL_ERROR;
}
HAL_FLASH_Lock();
return status;
}
