Hi, I'm trying to store some information in flash, I'm attaching the program. The problem arises when I use HAL_FLASH_Program function. Inside the FLASH_WaitLastOperation function (called by HAL_FLASH_Program), the PGSERR+PGAERR bits are set after the write operation. Do you have any ideas about this.?
Thanks in advance
// From datasheet rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf pag. 95
#define ADDR_FLASH_PAGE_127 ((uint32_t)0x0807F800) // Bank 2
void _qSaveConfig() {
HAL_FLASH_Unlock();
uint32_t page = _qGetPage(ADDR_FLASH_PAGE_127);
FLASH_PageErase(page, FLASH_BANK_2);
HAL_FLASH_Lock();
/* Check FLASH operation error flags */
uint32_t e = HAL_FLASH_GetError();
if (e != 0u) {
qDebugFatalError("Errore in scrittura flash", e);
}
HAL_FLASH_Unlock();
// afesConfig == configuration to save
uint32_t sizeDataToWrite = sizeof(afesConfig);
uint64_t dataToWrite[sizeDataToWrite];
memcpy(dataToWrite, afesConfig, sizeDataToWrite);
// Scrivi i dati nella memoria flash a blocchi di 8 byte
for (uint32_t i = 0; i < sizeDataToWrite; i += 8) {
HAL_StatusTypeDef e = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD,
ADDR_FLASH_PAGE_127 + i, sizeDataToWrite);
if (e != HAL_OK) {
uint32_t ee = HAL_FLASH_GetError();
qDebugFatalError("Errore in scrittura flash", ee);
}
}
HAL_FLASH_Lock();
}
Error 0xA0=0b10100000
PGSERR+PGAERR
From datasheet rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf pag.133
line 696 of stm32g4xx_hal_flash.c
error = (FLASH->SR & FLASH_FLAG_SR_ERRORS);
if (error != 0u)
{
/* Save the error code */
pFlash.ErrorCode |= error;
/* Clear error programming flags */
__HAL_FLASH_CLEAR_FLAG(error);
return HAL_ERROR;
}