I'm using a stm32g070 and i'm trying to erase and program a data into the Flash. This is my code:
/* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
/* Fill EraseInit structure*/
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.Page = 62u;
EraseInitStruct.NbPages = 1;
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_PROGERR | FLASH_FLAG_WRPERR | \ FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_PGSERR);
//Clear the page
if (HAL_FLASHEx_Erase(&EraseInitStruct, &PAGEError) != HAL_OK) {
/*Error occurred while page erase.*/
return HAL_FLASH_GetError ();
}
This code return the valor 96 in the HAL_FLASH_GetError() that correspond to 0b0110 0000, bit 5 (PGA ERR) and bit 6 (SIZ ERR) according to the Reference Manual 0454 (From STM32G070). Can anybody help me?
I try to understand why these errors are occurring and whether this is related to problems with the HAL layer.
I would suggest bare metal approach.
It is from another STM but having the same 64bits at the time programming procedure (it calculates 8 bits ECC so you need always to write 64 bits). Some error bits might not exist in your micro so check. The rest should work as expected.