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
