cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411 embedded bootloader USB

butaforsky
Associate

Hello, i am trying to use system bootloader in STM32F411 for software update via USB. I use a freertos in my project.

Workflow is here: By sending a "BOOT" via Virtual Com Port USB, MCU executes folowing code:

 
Spoiler
USBD_Stop(&hUsbDeviceFS);
uint32_t i=0;
void (*SysMemBootJump)(void);


/* Set a vector addressed with STM32 Microcontrollers names */
/* Each vector position contains an address to the boot loader entry point */

    volatile uint32_t BootAddr[33];

    BootAddr[C0]     = 0x1FFF0000;
    BootAddr[F030x8] = 0x1FFFEC00;
    BootAddr[F030xC] = 0x1FFFD800;
    BootAddr[F03xx]  = 0x1FFFEC00;
    BootAddr[F05]    = 0x1FFFEC00;
    BootAddr[F07]    = 0x1FFFC800;
    BootAddr[F09]    = 0x1FFFD800;
    BootAddr[F10xx]  = 0x1FFFF000;
    BootAddr[F105]   = 0x1FFFB000;
    BootAddr[F107]   = 0x1FFFB000;
    BootAddr[F10XL]  = 0x1FFFE000;
    BootAddr[F2]     = 0x1FFF0000;
    BootAddr[F3]     = 0x1FFFD800;
    BootAddr[F4]     = 0x1FFF0000;
    BootAddr[F7]     = 0x1FF00000;
    BootAddr[G0]     = 0x1FFF0000;
    BootAddr[G4]     = 0x1FFF0000;
    BootAddr[H503]   = 0x0BF87000;
    BootAddr[H563]   = 0x0BF97000;
    BootAddr[H573]   = 0x0BF97000;
    BootAddr[H7x]    = 0x1FF09800;
    BootAddr[H7A]    = 0x1FF0A800;
    BootAddr[H7B]    = 0x1FF0A000;
    BootAddr[L0]     = 0x1FF00000;
    BootAddr[L1]     = 0x1FF00000;
    BootAddr[L4]     = 0x1FFF0000;
    BootAddr[L5]     = 0x0BF90000;
    BootAddr[WBA]    = 0x0BF88000;
    BootAddr[WBX]    = 0x1FFF0000;
    BootAddr[WL]     = 0x1FFF0000;
    BootAddr[U5]     = 0x0BF90000;

    /* Disable all interrupts */
    __disable_irq();

    /* Disable Systick timer */
    SysTick->CTRL = 0;

    /* Set the clock to the default state */
    HAL_RCC_DeInit();

    /* Clear Interrupt Enable Register & Interrupt Pending Register */
    for (i=0;i<5;i++)
    {
        NVIC->ICER[i]=0xFFFFFFFF;
        NVIC->ICPR[i]=0xFFFFFFFF;
    }


    SYSCFG->MEMRMP = 0x01;
    /* Re-enable all interrupts */
    __enable_irq();

    /* Set up the jump to boot loader address + 4 */
    SysMemBootJump = (void (*)(void)) (*((uint32_t *) ((BootAddr[MCU] + 4))));

    /* Set the main stack pointer to the boot loader stack */
    __set_MSP(*(uint32_t *)BootAddr[MCU]);

    /* Call the function to jump to boot loader location */
    SysMemBootJump();

    /* Jump is done successfully */
    while (1)
    {
        /* Code should never reach this loop */
    }
 

 and succesfully jumps into embedded bootloader, so I can read an mcu software with usb in dfu mode 

butaforsky_0-1723463328464.png

but I can't update a software using "Erasing and programming" tab and get errors "LIBUSB_NO_DEVICE" after erasing of previous software

14:49:48:159 : Download in Progress:
14:49:48:160 : Size : 408 Bytes
14:49:48:160 : Address : 0x08000000
14:49:48:161 : DFU status = 0 : OK
14:49:48:161 : DFU state = 5 : dfuDNLOAD-IDLE
14:49:48:161 : Status: 0, State: 5
14:49:48:161 : setting the address pointer to address: 0x08000000
14:49:48:198 : DFU status = 0 : OK
14:49:48:198 : DFU state = 4 : dfuDNBUSY
14:49:48:203 : DFU status = 0 : OK
14:49:48:204 : DFU state = 5 : dfuDNLOAD-IDLE
14:49:48:204 : sending packet nbr: 0
14:49:48:204 : downloading data
14:49:48:211 : DFU status = 0 : OK
14:49:48:211 : DFU state = 4 : dfuDNBUSY
14:49:48:212 : libusb get status error [-4] : LIBUSB_ERROR_NO_DEVICE

 

What should i fix in my code to flash a new .hex properly ? Thank you in advance

 

 

STM32CubeProgrammer 2.17

 

1 REPLY 1
STOne-32
ST Employee

Dear @butaforsky ,

is that possible to run the USB DFU system bootloader after a power off and power on while forcing the Boot pins by hardware and see if you have the same behavior ?

The goal is to check if the behavior is linked from the FreeRTOS application dynamic jump to system bootloader : such as using shared ressources like RAM or corrupting some buffers causing such issue .

let us know 

STOne-32