【发布时间】:2022-09-29 00:16:04
【问题描述】:
我试图通过 STM32F405RG 上的软件立即跳转到 DFU 引导加载程序,但它正在执行软件复位并抛出 RCC_FLAG_SFTRST 标志。程序继续重复执行跳转到引导加载程序的代码,并最终在几秒钟后停留在引导加载程序模式。如果中断被禁用,我第一次尝试进入引导加载程序模式就成功了。但是,我无法在 DFU 模式下上传代码,因为它需要启用中断。我不确定是什么导致引导加载程序跳回应用程序,并希望在这方面获得帮助。下面是跳转到bootloader的代码,在main下Init_HAL()之后立即调用。
void JumpToBootloader(void) {
void (*SysMemBootJump)(void);
volatile uint32_t addr = 0x1FFF0000;
HAL_RCC_DeInit();
HAL_DeInit();
/**
* Step: Disable systick timer and reset it to default values
*/
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/**
* Step: Interrupts are not disabled since they are needed for DFU mode
*/
// __disable_irq();
/**
* Step: Remap system memory to address 0x0000 0000 in address space
* For each family registers may be different.
* Check reference manual for each family.
*
* For STM32F4xx, MEMRMP register in SYSCFG is used (bits[1:0])
* For STM32F0xx, CFGR1 register in SYSCFG is used (bits[1:0])
* For others, check family reference manual
*/
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); //Call HAL macro to do this for you
/**
* Step: Set jump memory location for system memory
* Use address with 4 bytes offset which specifies jump location where program starts
*/
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
/**
* Step: Set main stack pointer.
* This step must be done last otherwise local variables in this function
* don\'t have proper value since stack pointer is located on different position
*
* Set direct address location which specifies stack pointer in SRAM location
*/
__set_MSP(*(uint32_t *)addr);
/**
* Step: Actually call our function to jump to set location
* This will start system memory execution
*/
SysMemBootJump();
}
标签: c++ stm32 microcontroller bootloader stm32f4