admin管理员组

文章数量:1194135

I have an identical function on an STM32g431 chip that jumps the chip into bootloader. This function successfully jumps to bootloader. The system only has SPI1 enabled, to handle the bootloader coms once in bootloader mode. I ensure that there is no weird artifacting of registers, by ensuring this code does not run in an interrupt (check for flag in main, then executes if true).

/**
 * @brief Function to reset STM32 into bootloader mode
 * @note This function will not return as it triggers a system reset
 * @note Flash start address for STM32G431: 0x08000000
 */
void jump_to_bootloader(void)
{
    #define conBootloadAddress 0x1FFF0000

    void (*SysMemBootJump)(void);


    /* 1. Disable all interrupts */
    __disable_irq();
    
    /* 2. Disable all peripheral clocks */
    HAL_SPI_DeInit(&hspi1);
    MX_GPIO_DeInit();
    
    /* 3. Disable PLL and reset to default clock */
    HAL_RCC_DeInit();  // This handles PLL disable

    
    /* 4. Clear ALL pending interrupts */
    HAL_NVIC_DisableIRQ(SPI1_IRQn);
    HAL_NVIC_ClearPendingIRQ(SPI1_IRQn);
    
    for (int i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++)
    {
        NVIC->ICER[i] = 0xFFFFFFFF;
        NVIC->ICPR[i] = 0xFFFFFFFF;
    }
    
    /* 5. Disable SysTick */
    SysTick->CTRL = 0;
    SysTick->LOAD = 0;
    SysTick->VAL = 0;

    /* 6. Re-enable interrupts (needed for bootloader) */
    __enable_irq();

    /* 7. Force system reset for clean bootloader entry */
    HAL_FLASH_OB_Launch();  // This triggers a system reset

    /* 8. Jump to bootloader */
    SysMemBootJump = (void (*)(void)) (*((uint32_t*) (conBootloadAddress + 4)));
    __set_MSP(*(uint32_t*) conBootloadAddress);
    SysMemBootJump();

    while (1);
}

This same code does nothing on the STM32G474
STM32 bootloader address

I tried running this code on the STM32G474, but it just goes back to program memory. the final while loop is also not reached.

Is there a special register setting that is different from the STM32G431?

本文标签: embeddedSTM32G474 jump to bootloader through internal function issueStack Overflow