I'm developing a custom a bootloader on STM32F411VE MCU which must download a .bin file from USB key and flash it into the application sectors of flash memory. Following the examples provided with cube libraries i managed to open correctly the file with the FAT FS system, but I'm having hard times understanding how to exit from the bootloader and jump to my app.

These are the scenarios: 1) Power on the board with no USB Key inserted; the code has no usb stop/deinit/disconnect call -->boot ends its function and jumps correctly to the application. If I plug the USB key during application-life the system reboots. Note that in my application I have no USB driver running 2) Power on with USB key inserted; the code has no usb stop/deinit/disconnect call --> boot fails when setting the MSP of the application:

__set_MSP((uint32_t)*APPLICATION_START_ADDRESS);


3) Power on with no USB Key inserted and USBH_Stop call before jumping to app --> boot fails when setting the MSP of the application

This is my Jump to app implementation. It worked optimally before inserting the USB Host driver

static void JumpToApplication(void)
{
void (*pmain_app)(void);
/* First, disable all IRQs */
__disable_irq();

pmain_app = (void (*)(void))*(APPLICATION_START_ADDRESS + 1);

pmain_app();
}


Thanks a lot for supporting me

• How do you know that it fails when setting the MSP? Can you step through the statement in instruction debug mode (in the disassembly window)? What is the value of the sp register before and after? Can you show the disassembled function? What optimization settings do you use? – berendi - protesting Jul 13 '19 at 20:57
• I can say that I'm using medium optimization, while I'm sorry but I'm not able to give you the other answers. Would you be so kind to guide me someway? I'd like to undersand better the cons and dangers related to code optimization – gdivella Jul 15 '19 at 8:02