2020-05-16 04:57 AM
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é
2024-06-21 08:15 AM - edited 2024-06-21 08:19 AM
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
try BFB2 0
2024-12-13 07:29 AM
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.
#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){}
}
}