cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L072CZ - Jumping in DFU bootloader via software

andre239955_stm1_stmicro
Associate III

Hello

I'm migrating my STM32F072 project to the STM32L072.

In my original project (F072) I can jump to the DFU bootloader by software via a function located before SystemInit.

I tried to convert this to be used by L072 by changing the address of bootloader program to 0x1ff00004 it's not working.

Is it due to the dual memory bank? Is there a way to get it working?

Thank-you

André

11 REPLIES 11

Jump on MCUs with detection firmware in flash not work or better say work , but default jump back to app if is detected in flash. One way is erase first memory sector before jump.

Second maybe as AN2606 pattern say 

MM1_0-1718982848005.png

try BFB2 0

This is my code, it worked fine on my L072.

It is imporant to erase the first 4 bytes of user flash, you can find in AN2606 Rev 64 (p.69).

I was helped by many posts, thanks all.

teru839_0-1734103053594.png

 

#define BOOTLOADER_MAGIC_ADDR 		              ((uint32_t*) ((uint32_t) 0x2000142c)) // ._user_heap_stack front addr
#define BOOTLOADER_MAGIC_TOKEN 		              0xDEADBEEF
#define BOOTLOADER_START_ADDR 		              0x1FF00000

// call this at any time to initiate a reboot into bootloader
void RebootToBootloader(){
    *BOOTLOADER_MAGIC_ADDR = BOOTLOADER_MAGIC_TOKEN;
    NVIC_SystemReset();
}

// call this in first line of main()
void bootloaderSwitcher(){
    uint32_t jumpaddr;
    FLASH_EraseInitTypeDef erase;
    uint32_t pageError = 0;

    if (*BOOTLOADER_MAGIC_ADDR == BOOTLOADER_MAGIC_TOKEN){
        *BOOTLOADER_MAGIC_ADDR = 0;

        // Avoid the empty check mechanism
        erase.TypeErase = FLASH_TYPEERASE_PAGES;
        erase.PageAddress = 0x08000000;
        erase.NbPages = 1;
        HAL_FLASH_Unlock();
        HAL_FLASHEx_Erase(&erase, &pageError);
        HAL_FLASH_Lock();

        void (*bootloader)(void) = 0;
        jumpaddr = *(__IO uint32_t*)(BOOTLOADER_START_ADDR + 4);
        bootloader = (void (*)(void)) jumpaddr;
        __set_MSP(*(__IO uint32_t*) BOOTLOADER_START_ADDR); 
        bootloader();
        while(1){}
    }
}