2020-11-07 03:46 PM
I've read various articles/guides how to jump to bootloader form main program (without using boot0 pin and reset). All code that I've tried seems to fail...
My current approach is like this:
#define BOOTLOADER_ADDR 0x1FF00000U
void (*SysMemBootJump)(void);
void JumpToBootloader(void)
{
vTaskSuspendAll();
HAL_RCC_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
__disable_irq();
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(BOOTLOADER_ADDR + 4)));
__set_MSP (*((uint32_t*) BOOTLOADER_ADDR));
SysMemBootJump();
while(1);
}
Looks good but it doesn't work... however not completely....
When I use Boot0 pin and reset it STM32F767VIT goes to bootloader/DFU mode and DfuSe detects STM32F7 device correctly.
When runs code as above, it jumps somewhere, but DfuSe do not detect device to flash. After a while Windows reports unknown device - 43 error code (A request for the USB device descriptor failed). It seems that I'm close... but no clue how to fix it :unamused_face:
Edit:
I wonder if FreeRTOS is causing incorrect behaviour of bootloader. I've added "vTaskSuspendAll()" but this seems to be not enough.
Edit2:
To avoid FreeRTOS at this stage, I've called JumptoBootLoader() as first instruction in main() - nothing changes. Detected USB device is broken - 43 error code (A request for the USB device descriptor failed).
best regards
Mikolaj Tutak
2020-11-08 05:16 AM
2020-11-08 05:29 AM
Yes, this is one of the best I've found. My code is strictly based on this tutorial.
I wonder is FreeRTOS related issue? I've added vTaskSuspendAll(); in the beginning but without any change...
2020-11-08 06:08 AM
you miss or remove
//Remap by hand... {
#if defined(STM32F4)
SYSCFG->MEMRMP = 0x01;
#endif
#if defined(STM32F0)
SYSCFG->CFGR1 = 0x01;
#endif
//} ...or if you use HAL drivers
//__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); //Call HAL macro to do this for you
you use F7XX then i recommend use __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); //Call HAL macro to do this for you
2020-11-08 09:37 AM
I've tried "SYSCFG->MEMRMP = 0x01;" but it seems that this is not needed on STM32F7, anyway it doesn't changed anything (windows reports USB device with error code).
I could use "__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH()" but this is not included in my HAL firmware anywhere. If you have one for F767 please share, I will try it.
Edit:
The only existence of remap macro I've found is in "stm32_hal_legacy.h" header:
#define __HAL_REMAPMEMORY_SYSTEMFLASH __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH
But this doesn't help much...
2020-11-08 11:27 AM
Hmm you have right try coment out disabling irq from your code.
2020-11-08 11:52 AM
Oh yes! It works from non FreeRTOS (before osKernelInitialize()). From FreeRTOS it is restarting. Have to add something to disable FreeRTOS.
Current approach is (no disabling irq, no memory remap):
#define BOOTLOADER_ADDR ((bootloader_t *)0x1FF00000UL)
struct bootloader_t
{
uint32_t stackptr;
void (*jumpptr)(void);
} *bootloader = BOOTLOADER_ADDR;
void JumpToBootloader(void)
{
HAL_RCC_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
__set_MSP(bootloader->stackptr);
bootloader->jumpptr();
while(1);
}
2020-11-08 04:15 PM
OK above code works without FreeRTOS, however when called from FreeRTOS task it causes restart. I've tried adding:
Without luck.
2020-11-09 07:31 AM
For similar purpose i use IWDG or WWDG reset and in main detect it and start before RTOS what you need.
2020-11-09 07:52 AM
You mean that you set WDG flag and make reset and during startup you check the reason of reset and enter bootloader if needed? That sounds like idea worth to try.
Do you use IWDG/WWDG or just manually trigger it for purpose of doing something special before starting FreeRTOS scheduler? Could you share your code you are using trigger such request?