Delay needed before executing newly written code
I am using a STM32F401 MCU and STM32 HAL library. I am writing a bootloader that will update an application that is located into a different sector. The sequence is this:
/* Unlock the flash */
HAL_FLASH_Unlock();
/* Erase the sector that will hold the application */
HAL_FLASHEx_Erase();
/* Write each word into the new sector */
for(uint32_t word)
HAL_FLASH_Program(word);
/* Lock the flash */
HAL_FLASH_Lock();
/* Add a delay; why? */
HAL_Delay(200);
/* Jump to application code */
jump();
The flash is erased and written successfully. However I have discovered that I need to add a delay of arround 200ms after I lock the flash memory and before jumping into the new application. Otherwise the MCU hangs.
Is there another solution then adding this delay or can somebody point me out to some documentation about this issue?
Thanks!
