I have an application running on a STM32F401RE that has the feature to enter the STM32 System bootloader to reprogram the application flash. Entry to the bootloader is working and the code is flashed using dfutil. However, in order to run the code I have to press reset on my MCU. Once reset is pressed the application runs as expected.
This is the code that jumps to the bootloader:
void platform_request_boot(void)
{
const uint32_t application_address = 0x1fff0000;
register uint32_t jump_address = 0;
register uint32_t addr = 0;
register irq_function_t jump_to_application;
/* We start here */
cm_disable_interrupts();
uint32_t value = UINT32_MAX;
NVIC_ICER(0) = value;
NVIC_ICER(1) = value;
NVIC_ICER(2) = value;
NVIC_ICPR(0) = value;
NVIC_ICPR(1) = value;
NVIC_ICPR(2) = value;
STK_CSR = 0;
/* Reset the RCC clock configuration to the default reset state ------------*/
RCC_CR |= (uint32_t)0x00000081;
/* Reset CFGR register */
RCC_CFGR = 0x00000000;
/* Disable all interrupts */
RCC_CIR = 0x00000000;
FLASH_ACR = 0;
__asm__ volatile("isb");
__asm__ volatile("dsb");
cm_enable_interrupts();
addr = *((uint32_t *)application_address);
jump_address = *((uint32_t *)(application_address + 4));
jump_to_application = (irq_function_t)jump_address;
/*
set up the stack for the bootloader
*/
__asm__("mov sp,%[v]" : : [v] "r"(addr));
jump_to_application();
}
My research has not revealed a solution to this, I would appreciate some help.