cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32L476RG] Jump to Bootloader from Software.

Lo�c Bouilly
Associate II
Posted on April 19, 2017 at 09:27

Hello,

I want to use DFU for update my program on the STM32L476RG. I use a personnal board. When I put BOOT0 to VCC, the Bootloader start and we can change the firmware but my system is on battery and I have no access to BOOT0 pin and RESET.

So I want to jump in bootloader directly from software for that I have search the start addresse of system memory of the MCU -> 0x1FFF0000. So this is my code :

#define USBD_DFU_APP_DEFAULT_ADD 0x1FFF0000
pFunction JumpToApplication;
uint32_t JumpAddress;
/***
 **** some code HERE 
***/
HAL_RCC_DeInit();
HAL_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
 
//_HAL_REMAPMEMORY_SYSTEMFLASH();
/* Jump to user application */
JumpAddress = *(__IO uint32_t*) (USBD_DFU_APP_DEFAULT_ADD + 4);
JumpToApplication = (pFunction) JumpAddress;
 
/**
* Step: Disable all interrupts
*/
__disable_irq();
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
 
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) USBD_DFU_APP_DEFAULT_ADD);
JumpToApplication(); �?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

When I use this code the system reset but not in DFU mode. What I have miss for do a good reset DFU ?

I have try theUSBD_DFU_APP_DEFAULT_ADD to 0x00000000 no change.

Thanks,

Loïc

1 ACCEPTED SOLUTION

Accepted Solutions
Lo�c Bouilly
Associate II
Posted on April 24, 2017 at 11:52

Thanks

and

!! Finally I find the solution for jump to bootloader !

Yes it's the barriers the solution.

This is my finally code, I hope it will help someone else :

typedef void (*pFunction)(void);pFunction JumpToApplication;uint32_t JumpAddress;HAL_RCC_DeInit();SysTick->CTRL = 0;SysTick->LOAD = 0;SysTick->VAL = 0;/** * Step: Disable all interrupts */__disable_irq();/* ARM Cortex-M Programming Guide to Memory Barrier Instructions.*/__DSB();__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();/* Remap is bot visible at once. Execute some unrelated command! */__DSB();__ISB();JumpToApplication = (void (*)(void)) (*((uint32_t *)(0x1FFF0000 + 4)));/* Initialize user application's Stack Pointer */__set_MSP(*(__IO uint32_t*) 0x1FFF0000);JumpToApplication();�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Thanks again !

Loïc

View solution in original post

14 REPLIES 14
Uwe Bonnes
Principal III
Posted on April 19, 2017 at 10:39

Probably you miss to set VTOR to point to system flash

Another way to enter system bootloader is early in the initialization to set SYSCFG_RMPR to system flash and do a vector reset. This saves you from knowing the the device specific flash values, like entry address, VTOR and such.

Posted on April 19, 2017 at 11:07

Thanks for your return. 

For the VTOR is SCB->VTOR to set to 0x1FFF0000 ? Because when I try this is still reset indefinitely. 

When you said 

SYSCFG_RMPR set is the SYSCFG->MEMRMP and MEM_MODE to 1 for set 0x0000

0000 to system flash ? I try this but the system still reset on User Flash. 

 
Posted on April 19, 2017 at 11:58

Here is what I do to enter the bootloader on f4_discovery:

void platform_init(void)

{

volatile uint32_t *magic = (uint32_t *) &_ebss;

if ((magic[0] == BOOTMAGIC0) && (magic[1] == BOOTMAGIC1)) {

    magic[0] = 0;

    magic[1] = 0;

    /*As we just come out of reset, no other deinit is needed!*/

    rcc_periph_clock_enable(RCC_SYSCFG);

    SYSCFG_MEMRM &= ~3;

   SYSCFG_MEMRM |= 1;

   SCB_AIRCR = SCB_AIRCR_VECTKEY | SCB_AIRCR_VECTRESET;

   while(1);

}
Posted on April 19, 2017 at 12:20

On an F303xC, I had to issue an system reset if RCC_CFGR was not at it's default value (0). Otherwiese the program missbehaved.

Posted on April 19, 2017 at 14:59

The RCC_CFGR is to 0, before jumping to System Memory. 

I don't have HSE but I have only LSE, it's not a problem for use bootloader ? 

martinj3456
Associate III
Posted on April 20, 2017 at 06:57

I guess, this post will help you with L476.

https://community.st.com/0D50X00009XkemvSAB

 

Enter DFU mode by commands like that:

*Bootloader_Ram_Key_Address = Bootloader_Key_Value; // Write a key to a RAM location to check at next reset

 NVIC_SystemReset();    // System reset
Lubos Medovarsky
Associate II
Posted on April 20, 2017 at 12:46

 ,

 ,

After much fiddling, follwing sequence gets me into the system bootloader just after reset:

 , void (*bootloader) (void),

 ,

 , uint32_t msp,

 ,

 , /* ARM Cortex-M Programming Guide to Memory Barrier Instructions.*/

 ,

 , __DSB(),

 ,

 , ♯ if (SYSCFG_CFGR1_MEM_MODE_0)

 ,

 ,/* Map system flash at address 0 so that our interrupts in bootloader get active */

 ,

 , SYSCFG->,CFGR1 = SYSCFG_CFGR1_MEM_MODE_0,

 ,

 , ♯ else

 ,

 , SYSCFG->,MEMRMP = SYSCFG_MEMRMP_MEM_MODE_0,

 ,

 , ♯ endif

 ,

 , /* Remap is bot visible at once. Execute some unrelated command! */

 ,

 , __DSB(),

 ,

 , __ISB(),

 ,

 , msp = *(uint32_t *)0,

 ,

 , bootloader = (void (*)(void))*(uint32_t *)4,

 ,

 , __set_MSP(msp),

 ,

 , /* Jump to bootloader */

 ,

 , bootloader(),

 ,

 , while(1),
Posted on April 20, 2017 at 15:25

Without the barriers it does not work on L4!