cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_FLASHEx_Erase() returns OK but no flash is erased on STM32G030C8Tx

shane mattner
Associate III

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;
}

 

1 ACCEPTED SOLUTION

Accepted Solutions

PAGE 10 is at 0x08005000

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3
shane mattner
Associate III

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);
    }

 

 

PAGE 10 is at 0x08005000

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I'm glad it was just a silly hex error on my part.  Thank you!