2019-03-04 06:19 PM
I follow the AN4657, use the following piece of code, my IAP can jump to APP when boot up, and APP can jump to IAP.
BUT, after jump back to IAP from APP, it will NOT jump to APP successfully.
why same code, sometime it works but other time it doesn't work?
----------------The code -------------
typedef void (*pFunction)(void);
pFunction JumpToApplication;
uint32_t JumpAddress;
#define APPLICATION_ADDRESS (uint32_t)0x08080000 (In APP, it is 0x08000000)
...........
JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
JumpToApplication = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
JumpToApplication();
------------------------------------
2019-03-04 06:45 PM
So get a debugger out, output some diagnostic information, and try to better understand the nature of the problem. The description here doesn't really convey any information that could pin point a cause.
Make sure you set the vector table address properly, ie SCB->VTOR = &__Vectors;
Make sure you don't transfer under interrupts context, ie from IRQ Handler or Callback proxy
If using an RTOS make sure you understand the ramifications of System vs User mode.
2019-03-06 03:40 PM
Here I have described much better way of doing this:
2019-03-06 05:37 PM
Right now, I just use soft reset in my application so when in IAP again , It can jump successfully to APP. this seems meets my need.
BTW, I found that in my APP, if I jump to IAP in USBD code stack such as in MSC_BOT_DataOut() in usbd_msc_bot.c, it works! BUT, if I try to jump in main() , it won't work UNLESS I call HAL_NVIC_DisableIRQ(OTG_FS_IRQn); HAL_NVIC_DisableIRQ(UART5_IRQn);
So it seems interrupt context, it can jump, no need to disable some interrupt. but in main(), we have to disable the corresponding interrupt. Unfortunately when I try to do the same in my IAP code, it doesn't work if it is jumped back from APP.
2019-03-22 01:26 AM
OK, I revisited this issue. I found out the solution: call HAL_DeInit() before jump back to IAP in APP.
2019-07-24 05:23 AM
This helped in my issue as well. I had issues with getting my application started from bootloader. The bootloader must call HAL_Deinit() for the application to start. Here's my startup code in bootloader (almost identical to UM1709 STM32Cube Ethernet IAP example). MCU is F7, F746 specifically.
/* Check if valid stack address (RAM address) then jump to user application */
if (((*(volatile uint32_t*)USER_FLASH_FIRST_PAGE_ADDRESS) & 0x2FF00000 ) == 0x20000000)
{
HAL_UART_Transmit(&huart3,(uint8_t*)"Application entry\n\r",18,10);
HAL_DeInit(); /* This is necessary for the application to start */
/** Jump to user application */
JumpAddress = *(volatile uint32_t*) (USER_FLASH_FIRST_PAGE_ADDRESS + 4);
JumpToApplication = (pFunction) JumpAddress;
/** Initialize user application's Stack Pointer */
__set_MSP(*(volatile uint32_t*) USER_FLASH_FIRST_PAGE_ADDRESS);
JumpToApplication();
}