Skip to main content
Explorer
January 15, 2025
Solved

stm32g0b0ce flash page erase issue

  • January 15, 2025
  • 1 reply
  • 820 views

Hello folks

 

I am using the first bank for the firmware and the second bank to save a bunch of parameters.

 

When the fw receives a command via uart, it updates the parameters erasing first and then writing groups of 8 bytes.

 

When I try to erase the first page of the second bank (0x08040000):

 FLASH_EraseInitTypeDef eitd;
 eitd.TypeErase = FLASH_TYPEERASE_PAGES;
 eitd.Banks = FLASH_BANK_2;
 eitd.Page = 0;
 eitd.NbPages = 1;
	unsigned int page_error;
	
 HAL_FLASH_Unlock();
 const HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&eitd, &page_error);
 HAL_FLASH_Lock();

the operation fails.

 

I red this, so I added some breakpoint with __BKPT(0) instruction:  

 

HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
{
 uint32_t error;
 uint32_t tickstart = HAL_GetTick();

 /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
 Even if the FLASH operation fails, the BUSY flag will be reset and an error
 flag will be set */

#if defined(FLASH_DBANK_SUPPORT)
 error = (FLASH_SR_BSY1 | FLASH_SR_BSY2);
#else
 error = FLASH_SR_BSY1;
#endif /* FLASH_DBANK_SUPPORT */

 while ((FLASH->SR & error) != 0x00U)
 {
 if(Timeout != HAL_MAX_DELAY)
 {
 if ((HAL_GetTick() - tickstart) >= Timeout)
 {
 	 __BKPT(0);
 return HAL_TIMEOUT;
 }
 }
 }

 /* check flash errors */
 error = (FLASH->SR & FLASH_SR_ERRORS);

 /* Clear SR register */
 FLASH->SR = FLASH_SR_CLEAR;

 if (error != 0x00U)
 {
 /*Save the error code*/
 pFlash.ErrorCode = error;
 __BKPT(0);
 return HAL_ERROR;
 }

 /* Wait for control register to be written */
 while ((FLASH->SR & FLASH_SR_CFGBSY) != 0x00U)
 {
 if(Timeout != HAL_MAX_DELAY)
 {
 if ((HAL_GetTick() - tickstart) >= Timeout)
 {
 	 __BKPT(0);
 return HAL_TIMEOUT;
 }
 }
 }

 return HAL_OK;
}

 

It stops at line 38 with error 0xE0: PGSERR + SIZERR + PGAERR !

 

What happens? How can I erase the page?

Thank you

 

 

 

    This topic has been closed for replies.
    Best answer by max65

    The problem was a null pointer dereferencing that happens regularly

    1 reply

    ST Employee
    January 15, 2025

    Hello @max65

    There are some ongoing updates on the STM32G0 512K reference manual, that you probably should be aware of: 

    Please Check these two related posts: 

     

    max65Author
    Explorer
    January 15, 2025

    Thank you @Sarra.S for your quick replay!

     

    I am using RM0454 Rev 5, November 2020 and I am aware of the documentation issues.

     

    I am working with an existing code that feeds HAL_FLASHEx_Erase with the correct parameters (see first fragment of code)

     

    In my opinion, the code should work, can you be more specific about the impact of the two threads on my code?

     

    Thank you

    max65AuthorAnswer
    Explorer
    January 22, 2025

    The problem was a null pointer dereferencing that happens regularly