stm32h7 CPU halts when I try to erase Flash sector 0 in Bank 1
I have a problem with erasing sector 0 in Bank 1 of a stm32h7 CPU. See my code snipped below...
When I run the code in the debugger, the CPU never returns from the call to HAL_FLASHEx_Erase. When I interrupt the programm the PC is set to 0xFFFFFFFE which I learned, means the CPU has stopped.
The code is called from BL_SBSFU bootloader and runs in a complete copy of the bootloader in RAM. The code seems to be correct, because when I try to erase sector 1 or bank 2 the code runs without an error and the sector is erased.
Only when I try to erase sector 0 the CPU stops.
The code runs completely in RAM and does not access the FLASH so I think there should be no problem in deleting sector 0.
Has anyone an idea why the CPU stops when I try to erase sector 0 ?
__disable_irq();
if (HAL_FLASH_Unlock() == HAL_OK)
{
FLASH_EraseInitTypeDef p_erase_init;
p_erase_init.TypeErase = FLASH_TYPEERASE_SECTORS;
p_erase_init.Banks = FLASH_BANK_1;
p_erase_init.Sector = 0;
p_erase_init.NbSectors = 1U;
p_erase_init.VoltageRange = FLASH_VOLTAGE_RANGE_3;
if (HAL_FLASHEx_Erase(&p_erase_init, &page_error) != HAL_OK)
{
ret = SFU_ERROR;
}
}
__enable_irq();
