2026-03-16 9:08 AM - last edited on 2026-03-17 1:10 AM by Gyessine
Hello,
As part of a new project, I'd like to use DFU mode for programming my STM32F303VET6.
I have a button that controls BOOT0. If the button is pressed during the microcontroller reset, there's no problem; I successfully enter DFU mode and can reprogram without any issues.
I'd like to be able to perform this step without any physical intervention on the board, but rather by creating a 'jump' from my application to the internal ST Bootloader.
My board is connected to the PC via a CDC connection. Using HyperTerminal, I send a command that calls a JumptoBootloader function.
My function is as follows:
void JumpToBootloader(void)
{
// 1. Stop USB peripheral
RCC->APB1ENR &= ~RCC_APB1ENR_USBEN; // Disable USB clock
RCC->APB1RSTR |= RCC_APB1RSTR_USBRST; // Reset USB
RCC->APB1RSTR &= ~RCC_APB1RSTR_USBRST;
// 2. Put USB pins (PA11/PA12) in analog mode
RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
GPIOA->MODER |= (3U << (11 * 2)) | (3U << (12 * 2)); // Analog mode
// 3. Disable all interrupts
__disable_irq();
for (int i = 0; i < 8; i++)
NVIC->ICER[i] = 0xFFFFFFFF;
// 4. Stop SysTick
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
// 5. Reset clock configuration
HAL_RCC_DeInit();
__DSB();
// 6. Set MSP to bootloader's initial stack pointer
uint32_t bootloader_addr = 0x1FFF0000; // System Memory for STM32F303
uint32_t msp = *(volatile uint32_t *)bootloader_addr;
__set_MSP(msp);
// 7. Optional: set vector table offset
SCB->VTOR = bootloader_addr;
// 8. Jump to bootloader reset handler
void (*bootloader)(void);
bootloader = (void (*)(void)) (*(volatile uint32_t *)(bootloader_addr + 4));
bootloader();
}
Unfortunately, I can't debug it. All I know is that the card seems to be malfunctioning; the USB connection is no longer recognized, and no device is visible in Windows Device Manager after unplugging and replugging the USB cable.
Do you have any ideas?
Solved! Go to Solution.
2026-03-16 9:44 AM
Interrupts need to be enabled.
Don't jump from within an interrupt.
Here is working jump to bootloader code:
How to jump to system bootloader from application ... - STMicroelectronics Community
2026-03-16 9:44 AM
Interrupts need to be enabled.
Don't jump from within an interrupt.
Here is working jump to bootloader code:
How to jump to system bootloader from application ... - STMicroelectronics Community