cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G473CBT freezes jumping to bootloader

StefanH
Associate III

I have a custom board using the STM32G473CBT6 MCU. BOOT0 is pulled-down by a 100k resistor and is used as GPIO (output) at runtime. The firmware is generated by CubeMX, with the addition of a C++ file for the 'user' application. The board works fine, but is unable to jump to the bootloader from the main program. I use this function which works well with other boards:

void __attribute__ ((optimize(0))) enter_bootloader() {
    HAL_Delay(500); // Wait a bit for the last USB packets to be sent.
    CDC_deInit();
 
    GPIO_InitTypeDef GPIO_InitStruct;
    GPIO_InitStruct.Pin = USB_FWUPD_GPIO_DN | USB_FWUPD_GPIO_DP;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
    HAL_GPIO_Init(USB_FWUPD_GPIO_PORT, &GPIO_InitStruct);
    USB_FWUPD_GPIO_PORT->BSRR = (USB_FWUPD_GPIO_DN | USB_FWUPD_GPIO_DP) << 16U
    HAL_Delay(2000);
 
    HAL_RCC_DeInit();
    HAL_DeInit();
 
    SysTick->CTRL = 0;
    SysTick->LOAD = 0;
    SysTick->VAL = 0;
// #ifndef PLATFORM_STM32_FAMILY_G4
    __disable_irq();
// #endif
 
    __HAL_RCC_SYSCFG_CLK_ENABLE();
    __DSB();
    __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
    __DSB();
    __ISB();
    SCB->VTOR = 0;
 
    __set_MSP(*((uint32_t*) 0x1FFF0000));
    ((void (*)(void)) *((uint32_t*) 0x1FFF0004))();
 
    for (;;);
}

I left out the macros with board specifics, but the function works for F4,F7, L4, L0 & G0 MCUs.

Using SWD I can step through the function fine, it just freezes at line 32, the jump.

Tried not disabling the IRQs as suggested in this forum, no differences. Also tried setting the option byte to ignore the BOOT0 pin, no effect either. Flipping the default boot mode to DFU in the option bytes does make DFU show up on the PC, but obviously isn't workable.

Is there something G4 specific that needs changing in the above function? Or should I look elsewhere for the issue?

2 REPLIES 2
TDK
Guru

> Using SWD I can step through the function fine, it just freezes at line 32, the jump.

Are you stepping through in assembly mode? Hit play, then hit pause and see where execution is at. Could be stuck in another interrupt that you didn't disable. In any case, the CPU is somewhere in code, doing something, even if it's in a hard fault handler.

> Tried not disabling the IRQs as suggested in this forum, no differences.

The DFU bootloader uses interrupts. Disabling them will prevent it from working.

If you feel a post has answered your question, please click "Accept as Solution".
Piranha
Chief II

Forget this broken junk and implement a decent approach going through a reset:

https://community.st.com/s/question/0D50X0000AFpTmUSQV/using-nvicsystemreset-in-bootloaderapplication-jumps