2025-01-31 02:45 PM - last edited on 2025-02-01 01:10 AM by STOne-32
Hi, I am working on STM32C071
I wrote code to jump to ST bootloader from my application.
The code seems to work well, after jump to ST bootloader, I can connect to ST Bootloader by USB, using STM32CubeProgrammer. I can read flash data, option byte....
But if I do erase flash or change anything, STM32CubeProgrammer throws a failed message and exit STM bootloader mode.
Below is my jump function:
void (*SysMemBootJump)(void);
void JumpToBootloader(void){
SysMemBootJump = (void (*)(void)) (*((uint32_t *) ((0x1FFF0000 + 4))));
/* Set the clock to the default state */
HAL_RCC_DeInit();
/* Disable Systick timer */
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
volatile uint32_t msp = *(__IO uint32_t*)(0x1FFF0000);
__HAL_RCC_USB_CLK_DISABLE();
/* Disable all interrupts */
__disable_irq();
__set_MSP(msp);
SysMemBootJump();
}
Below is failed message:
The error is "verify flash protection" but there is no flash protect. Because I can hold BOOT pin, hit reset pin then enter STM Bootloader again, and erase as well.
2025-02-01 06:39 AM
Interrupts should be enabled for USB DFU bootloader. It's possibly they added to code enable them in the C0 bootloader, but it's not there on other families.
See here for example working jump to bootloader code:
How to jump to system bootloader from application ... - STMicroelectronics Community
2025-02-01 10:12 AM - edited 2025-02-01 10:13 AM
Hi, thank you for your reply,
I tried enable interrupt but still don't work.
My code is from your link actually, and it does work to jump ST bootloader. Problem is after jump to bootloader, all thing I can do just read, can't change for write to flash.
Here is an update with enable interrupt, share to me if any recommend
void (*SysMemBootJump)(void);
void JumpToBootloader(void){
SysMemBootJump = (void (*)(void)) (*((uint32_t *) ((0x1FFF0000 + 4))));
/* Disable all interrupts */
__disable_irq();
/* Set the clock to the default state */
HAL_RCC_DeInit();
/* Disable Systick timer */
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
volatile uint32_t msp = *(__IO uint32_t*)(0x1FFF0000);
__HAL_RCC_USB_CLK_DISABLE();
for (int i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++)
{
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}
/* Disable all interrupts */
__enable_irq();
__set_MSP(msp);
SysMemBootJump();
}