2017-04-19 12:27 AM
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
Solved! Go to Solution.
2017-04-24 02:52 AM
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
2017-04-19 01:39 AM
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.
2017-04-19 04:07 AM
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.
2017-04-19 04:58 AM
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);
}2017-04-19 05:20 AM
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.
2017-04-19 07:59 AM
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 ?
2017-04-19 09:57 PM
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 reset2017-04-20 04:54 AM
FYI:
https://stm32f4-discovery.net/2017/04/tutorial-jump-system-memory-software-stm32/
2017-04-20 05:46 AM
,
,
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),2017-04-20 08:25 AM
Without the barriers it does not work on L4!