2023-12-22 08:02 AM
Hi
STM32H563ZI, I am using freertos and in first task I try to make flash write operation code;
Flash::Error Flash::flashErase(const uint8_t sectorNumber)
{
uint32_t sector_error = 0;
FLASH_EraseInitTypeDef erase;
erase.TypeErase = FLASH_TYPEERASE_SECTORS;
erase.Banks = FLASH_BANK_2;
erase.Sector = sectorNumber;
erase.NbSectors = SINGLE_SECTOR_SIZE;
xSemaphoreTake(FlashMutex, portMAX_DELAY);
HAL_FLASH_Unlock();
if (HAL_FLASHEx_Erase(&erase, §or_error) != HAL_OK)
{
HAL_FLASH_Lock();
xSemaphoreGive(FlashMutex);
return Error::kEraseFail;
}
HAL_FLASH_Lock();
xSemaphoreGive(FlashMutex);
return Error::kEraseSuccess;
}
but it goes hard fault
if I dont use HAL_FLASH_Unlock(); functions it is normal but it cant erase so it is ridiculous
how can I work this ?
2023-12-22 08:38 AM
Not sat down and tested this, but suspect you need to config the MPU, change the protection mode it's running in or watch you don't erase active code.
2023-12-22 08:39 AM
2023-12-22 09:32 AM
thanks for reply,
error still goes on, neither write or erase, it goes hardfault or NMI handler
2023-12-22 09:52 AM
Do a register dump / disassembly of what actually faults, need something actionable here.
https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c