Skip to main content
Visitor II
October 31, 2022
Question

Need help entering bootloader mode and USB DFU via user code

  • October 31, 2022
  • 2 replies
  • 5008 views

I have code that's meant to put an STM32L552xx microcontroller into bootloader mode after reset, so I can connect it to CubeProgrammer afterwards. I tested the code and while it does appear to be doing something, it isn't showing up in the device manager in any sort of update mode, nor can CubeProgrammer find it under the USB tab.

I'm still looking into causes, but I wanted to check to make sure that this wasn't a simple case of me misunderstanding the instructions from AN2606, table 2 (I'm using Bootloader Pattern 12, trustzone disabled and boot0 pin pulled low).

0693W00000VOX0fQAH.pngCode for starting the bootloader from user code is below:

void prepareForUpdate()
{
	uint32_t boot_addr = 0x017F200;
	FLASH_OBProgramInitTypeDef ob_cfg;
	HAL_FLASHEx_OBGetConfig(&ob_cfg);
 
	ob_cfg.OptionType = OPTIONBYTE_USER;
	ob_cfg.USERType = OB_USER_nSWBOOT0;
	ob_cfg.USERConfig = OB_nBOOT0_SET;
	ob_cfg.BootAddrConfig = OB_BOOTADDR_NS0;
	ob_cfg.BootAddr = boot_addr;
 
	HAL_FLASH_Unlock();
	HAL_FLASH_OB_Unlock();
	HAL_FLASHEx_OBProgram(&ob_cfg);
	HAL_FLASH_OB_Launch();
}

When I execute the code, the microcontroller resets but does not appear to enter bootloader mode. I can execute all other code in the project before and after reset, so it isn't outright breaking anything that I can see. I can confirm it can detect the usb, since that's how I tell it to execute other parts of the code. I should also note that I haven't the USB_DEVICE in CUBEMX configured as a Communication Device Class and haven't configured it for DFU or as a composite device. I don't believe that this is the problem, but I'm not writing it off entirely.

I'm going to keep testing and researching for more information to narrow the problem down, but I figured I'd check in to make sure this isn't a simple case of bad code from misunderstanding.

Thanks in advance!

    This topic has been closed for replies.

    2 replies

    Graduate II
    November 1, 2022

    Try describe  I can execute all other code in the project before and after reset,

    And some changes to OB need POR (power reset) , too some errata and eception exist for bootloaders versions...

    ESpra.1Author
    Visitor II
    November 1, 2022

    There's other code in the project for controlling stepper, DC and servo motors, and communicating with sensors via I2C, which I control by sending characters over USB Virtual Com Port. Before and after running prepareForUpdate(), that side of the code still works the same.

    Also, yes, I have tried turning it off and on again (I'm not griping, just making a bad joke).

    I'll see if I can dig up more helpful information. Anything else from me that might be helpful?

    Graduate II
    November 1, 2022

    Maybe i dont ask right. describe how you execute code not what code.

    Your prepare func reconfigure MCU to start system bootloader always.

    If this is writed into OB your MCU never can start app code self.

    Visitor II
    November 23, 2023

     

    use this ,its work )) 

    void JumpToBootloader(void) {
    void (*SysMemBootJump)(void);
    volatile uint32_t addr = 0x0BF90000; // ADDRES FOR SYSTEM BOOTLOADER
    HAL_RCC_DeInit();
    SysTick->CTRL = 0;
    SysTick->LOAD = 0;
    SysTick->VAL = 0;
    __disable_irq();

    SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
    __set_MSP(*(uint32_t *)addr);
    SysMemBootJump();
    /**
    * Step: Connect USB<->UART converter to dedicated USART pins and test
    * and test with bootloader works with STM32 Flash Loader Demonstrator software
    */
    }