Skip to main content
Recep
Associate II
December 22, 2023
Question

FLASH freertos hard fault

  • December 22, 2023
  • 1 reply
  • 1561 views

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 ?

1 reply

Tesla DeLorean
Guru
December 22, 2023

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 VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
December 22, 2023
Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..