stm32g0b0ce flash page erase issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-15 12:51 AM
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
Solved! Go to Solution.
- Labels:
-
Flash
-
STM32G0 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-21 11:00 PM
The problem was a null pointer dereferencing that happens regularly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-15 1:34 AM - edited ‎2025-01-15 1:35 AM
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:
- Solved: STM32G0 erasing bank2 - STMicroelectronics Community
- Issue with Flash Erase in Single Bank Mode on STM3... - STMicroelectronics Community
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-15 4:36 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-21 11:00 PM
The problem was a null pointer dereferencing that happens regularly
