【问题标题】:DFU bootloader immediately jumping to application in STM32F405RGDFU 引导加载程序立即跳转到 STM32F405RG 中的应用程序
【发布时间】: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


    【解决方案1】:

    查看应用笔记 AN2606,Rev.55,第 28 章 STM32F40xxx/41xxx 设备引导加载程序,第 127 页,可以看到第一步称为“系统复位”。 DFU 并非设计为从您的应用程序中执行,而是在系统重置后根据引导加载程序选择进行调用。在您进入应用程序的主要功能之前,已经执行了几个步骤来准备设备。对于 DFU,这些步骤可能会有所不同。从意外的系统状态调用 DFU 可能会导致未定义的行为。

    进入 DFU 的最佳方法是将 BOOT0 引脚锁存为高电平,然后通过软件复位或 IWDG 执行系统复位。

    HSE 可能会出现另一个潜在问题,它必须由外部提供,但是由于您声明 DFU 最终确实有效,这似乎不太可能。

    【讨论】:

      猜你喜欢
      • 2017-11-03
      • 1970-01-01
      • 2015-04-02
      • 2020-04-29
      • 2020-07-10
      • 1970-01-01
      • 2014-10-24
      • 2019-12-26
      • 1970-01-01
      相关资源
      最近更新 更多