cancel
Showing results for 
Search instead for 
Did you mean: 

FLASH freertos hard fault

Recep
Associate II

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, &sector_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 ?

4 REPLIES 4

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.

https://github.com/STMicroelectronics/STM32CubeH5/blob/main/Projects/NUCLEO-H563ZI/Examples/FLASH/FLASH_EraseProgram/Src/main.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

thanks for reply,

 

error still goes on, neither write or erase, it goes hardfault or NMI handler

Do a register dump / disassembly of what actually faults, need something actionable here.

https://github.com/cturvey/RandomNinjaChef/blob/main/KeilHardFault.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..