can't write to STM32G051G6U6 's flash: PGSERR
Hi community,
here my minimal code example:
int main(void) {
HAL_Init();
SystemClock_Config();
FLASH_EraseInitTypeDef s_eraseinit = {0};
uint32_t pe = 0;
s_eraseinit.TypeErase = FLASH_TYPEERASE_PAGES;
s_eraseinit.NbPages = 1;
s_eraseinit.Page = 1;
s_eraseinit.Banks = FLASH_BANK_1;
HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&s_eraseinit, &pe);
PRINT_INFO("HAL_FLASHEx_Erase status: %d, PageError: 0x%08X\n", status, pe);
status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, 0x8000808, 0xAAAAAAAAAAAAAAAAU);
uint64_t flash_content = (*(__IO uint64_t *)0x8000808);
PRINT_INFO("Flash content: 0x%08X, flash status: %d\n", (uint32_t)flash_content, status);
if (flash_content == 0xAAAAAAAAAAAAAAAAU) {
HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_SET);
} else {
HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_SET);
}
while (1) {
}
}Later on I want to use EEPROM emulation for storing some data to flash. But unfortunately it never really worked. So now I am trying to write into flash using the minimal example above but also this is failing. I am left quite clueless and lacking of ideas what to try next.
My output:
HAL_FLASHEx_Erase status: 0, ErrorCode: 0
HAL_FLASHEx_Erase status: 0, PageError: 0xFFFFFFFF
HAL_FLASH_Program status: 1, ErrorCode: 128
Flash content: 0xFFFFFFFF, flash status: 1I already understood that writing to flash fails with FLASH_SR_PGSERR. But since I am purely using the HAL library I don't think I really made a mistake with the programming sequence.
The errata does not contain anything like this neither.
Do you have any experience with that fault on that MCU?
