Skip to main content
Associate II
Jan 15, 2025 8:51 AM UTC
Solved

stm32g0b0ce flash page erase issue

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.
max65Best answer
Associate II
Jan 22, 2025 7:00 AM UTC

The problem was a null pointer dereferencing that happens regularly

3 replies

ST Employee
Jan 15, 2025 9:34 AM UTC

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: 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
max65Author
Associate II
Jan 15, 2025 12:36 PM UTC

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

max65AuthorBest answer
Associate II
Jan 22, 2025 7:00 AM UTC

The problem was a null pointer dereferencing that happens regularly