cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Bootloader from my code and vice versa-STM32L072

ashah.16
Associate II

Hi,

I am trying to call the bootloader from my application, on a STM32L072. I followed posts in ST Community and other resources, but failed to do it.

I tried the code given in different places as below:

void BootLoaderInit(void)

{

void (*SysMemBootJump)(void);

volatile uint32_t BootJumpAddr = 0x1FF00000;

__disable_irq();

  SysTick->CTRL = 0;

  SysTick->LOAD = 0;

  SysTick->VAL = 0;

HAL_RCC_DeInit();

/*

for (int i=0;i<5;i++)

   {

 NVIC->ICER[i]=0xFFFFFFFF;

 NVIC->ICPR[i]=0xFFFFFFFF;

   }

__enable_irq();

*/

SysMemBootJump = (void (*)(void)) (*((uint32_t *)(0x1FF00004)));

__set_MSP(*(uint32_t*)BootJumpAddr);

SysMemBootJump();

while(1);

}

Once this function is called, it CubeProgrammer does not recognize the bootloader as it detects when BOOT0 pin is high and I do reset. It seems the hardware setup is fine but I have no idea why the bootloader does not work. I tried USB-DFU and USART1.

So, can someone help me to find out the problem??

Assuming the I could resolve the issue, or use BOOT0 pin to do it, how could I return to my code once the programming ends. The CubeProgrammer does not run the code after the programming:

Thank you,

Amir

3 REPLIES 3

With a valid app in FLASH the loader bounces back to it.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

thanks for your reply,

I do have an app on the flash. I programmed with SWD and then re-programmed with bootloader, bootloader did not get back to flash.

In another try, I erased the flash, programmed with bootloader, again no return to flash. But when I reset and remove BOOT0 jumper, it runs from the flash.

So, any idea? and do you have any definition for the "valid app"?

Thanks

There was a similar topic on the L072 or L073 the other week. Basically the ROM returns control back to FLASH if you try to enter it in this fashion.

I'd need to dig into the loader some more, but my recollection is that is looking at the SP/PC pairs in the front of FLASH Bank1 and Bank2 base locations.

I think you're going to need to write your own DFU boot loader.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..