2024-06-04 12:11 PM
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;
}
Solved! Go to Solution.
2024-06-04 12:33 PM
PAGE 10 is at 0x08005000
2024-06-04 12:22 PM
I found my older post where I found this problem, but there was no solution for this erase function not working. I also tried Flash_PageErase() and that did not work either this time:
if (HAL_FLASH_Unlock() == HAL_OK)
{
// status = HAL_FLASHEx_Erase(&flashErase_handle, &PageError);
FLASH_PageErase(FLASH_BANK_1, APP_START_PAGE);
}
2024-06-04 12:33 PM
PAGE 10 is at 0x08005000
2024-06-04 09:10 PM
I'm glad it was just a silly hex error on my part. Thank you!