Problem with HAL_FLASH_OB_Launch, STM32H7 swapping flash banks
Ok just trying to get the bank swapping working.
Loaded and flashed new firmware in to 0x08100000 all goes fine, all i need to do is to swap the flash banks.
Now the code below does do the bank swap fine, but it gets stuck at the HAL_FLASH_OB_Launch();
Does not hard fault, but does not get past it either, the cpu just seems to stop??
If i then press reset button on the board, the bank swap does complete and all is well,
I thought the HAL_FLASH_OB_Launch(); was supposed to reset the cpu?
If not why does it not get any further than that function?
I do have a workaround, by setting the watchdog timer, but would like to know whats going on?
Im using STM32Cube_FW_H7_V1.3.0
HAL_FLASH_OB_Unlock();
/* Get FLASH_WRP_SECTORS write protection status */
//OBInit.Banks = FLASH_BANK_1;
HAL_FLASHEx_OBGetConfig(&OBInit);
/* Check Swap Flash banks status */
if ((OBInit.USERConfig & OB_SWAP_BANK_ENABLE) == OB_SWAP_BANK_DISABLE)
{
/*Swap to bank2 */
/*Set OB SWAP_BANK_OPT to swap Bank2*/
printf("Swapping to bank2\r\n");
OBInit.OptionType = OPTIONBYTE_USER;
OBInit.USERType = OB_USER_SWAP_BANK;
OBInit.USERConfig = OB_SWAP_BANK_ENABLE;
HAL_FLASHEx_OBProgram(&OBInit);
printf("Launch\r\n");
/* Launch Option bytes loading */
HAL_FLASH_OB_Launch();
printf("DONE Restarting\r\n");
/*
as the CPU is executing from the Flash Bank1, and the I-Cache is enabled :
Instruction cache must be invalidated after bank switching to ensure that
CPU will fetch correct instructions from the flash.
*/
SCB_InvalidateICache();
HAL_NVIC_SystemReset();
}
else
{
/* Swap to bank1 */
/*Set OB SWAP_BANK_OPT to swap Bank1*/
printf("Swapping to bank1\r\n");
OBInit.OptionType = OPTIONBYTE_USER;
OBInit.USERType = OB_USER_SWAP_BANK;
OBInit.USERConfig = OB_SWAP_BANK_DISABLE;
HAL_FLASHEx_OBProgram(&OBInit);
printf("Launch\r\n");
/* Launch Option bytes loading */
HAL_FLASH_OB_Launch();
printf("DONE Restarting\r\n");
/*
as the CPU is executing from the Flash Bank1, and the I-Cache is enabled :
Instruction cache must be invalidated after bank switching to ensure that
CPU will fetch correct instructions from the flash.
*/
SCB_InvalidateICache();
HAL_NVIC_SystemReset();
}