2020-11-08 03:57 PM
Hello,
I am trying to write to flash memory from the firmware itself
It looks like the Erase process hangs for 2 seconds or so but works, but the writing process seems to totally freeze the MCU. Below is the code I am using. Any idea ?
FLASH_EraseInitTypeDef flashErase;
flashErase.TypeErase = TYPEERASE_SECTORS;
flashErase.VoltageRange = FLASH_VOLTAGE_RANGE_3;
flashErase.Sector = FLASH_SECTOR_7;
flashErase.NbSectors = 1;
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
uint32_t sectorError;
if (HAL_FLASHEx_Erase(&flashErase, §orError) != HAL_OK) {
error = true;
}
if (HAL_FLASH_Program(TYPEPROGRAM_WORD, 0x08060000, 123) != HAL_OK) {
error = true;
}
HAL_FLASH_Lock();
2020-11-09 02:22 AM
Actually, an HARD FAULT is triggered instantly when trying to write in the flash, the micro controller doesn't hang