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

14 REPLIES 14
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

Posted on April 26, 2017 at 20:54

Very helpful!  I've been dealing with HardFault's for days now.   This was the key.

Thank you!

- SteveK

Posted on October 19, 2017 at 13:32

Hi.

I use this code, but have HardFault ((

Please show your code!

Posted on October 20, 2017 at 02:28

Hi Alexsandr,

Here's the code I used for the ST32L052.

Steve

-------------------------------------------------------------

void upgradeFirmware(void)

{

  void (*JumpToBootloader)(void);

  uint32_t msp;

 

  // Disable all IRQs

  HAL_NVIC_DisableIRQ(SysTick_IRQn);

  HAL_NVIC_DisableIRQ(USART1_IRQn);

  HAL_NVIC_DisableIRQ(DMA1_Channel1_IRQn);

  __disable_irq();

 

  // Disable used PLL

  HAL_RCC_DeInit();

  SysTick->CTRL = 0;   // Reset the Systick Timer

  SysTick->LOAD = 0;

  SysTick->VAL  = 0;

 

  // Set the main stack pointer

  msp = 0x1FF00000;

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

  // goto the bootloader, we won't be coming back from here...  

  *(__IO uint32_t *)FWUG_MAGIC_NUMBER_ADDR = 0x12348765;   // Set the magic number for when we reboot after unlocking sectors

  __set_MSP(msp);

  JumpToBootloader();

  while (1);

}

------------------------------------------

It works, thanks.