STM32F042G6 won't jump to bootloader

223 Views Asked by At

I have a piece of code which is supposed to turn a board into bootloader mode when it's powered on with a button (not on boot pins) pressed.

blah blah
int main(void)
{

    delay(1000);


#ifdef ENABLE_OVERCLOCK
clk_init();
#endif

#if defined(RX_SBUS_DSMX_BAYANG_SWITCH)
    switch_key();
    if(KEY ==0)
    {
            unsigned long time=0;
            while(KEY == 0)
            {
                if (time > 4000000)
                {//reboot to dfu if the key is continiously held on poweron
                    __enable_irq();
                    RCC_DeInit();
                    SysTick->CTRL = SysTick->LOAD = SysTick->VAL = 0;
                    SYSCFG->CFGR1 = 0x01;
                    const uint32_t p = (*((uint32_t *) 0x1FFFC400));
                    __set_MSP(p);
                    void (*SysMemBootJump)(void);
                    SysMemBootJump = (void (*)(void)) (*((uint32_t *) 0x1FFFC404));
                    SysMemBootJump();
                    while(1);
                }
                ++time;
            }
blah blah

...and so on. However the uC hangs and doesn't get detected with usb when this code is run. What am i doing wrong?

1

There are 1 best solutions below

0
On

An option byte BOOT_SEL must be set to 0 on STM32F042, otherwise it won't let jump to the bootloader. Be careful, this setting doesn't let the bootloader start on boot0 pin.