2019-09-08 04:09 PM
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
2019-09-08 05:08 PM
With a valid app in FLASH the loader bounces back to it.
2019-09-09 06:50 AM
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
2019-09-09 07:06 AM
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.