2020-11-08 11:55 PM
Hi!
I have been searching for days trying to find an answer to this question. Lots of people have similar questions but none of the answers have worked for me.
I am trying to get my STM32L071xx to jump to bootloader from application code. I need this to be able to update it when the device is installed.
I have code from an STM32F0 that i was hoping to just copy and change out the address, but sadly it wasnt that easy.
Here is the jum to bootloader function i am trying:
void jumpToBootloader(void)
{
void (*SysMemBootJump)(void);
volatile uint32_t addr = 0x1FF00000; // from AN2606
__disable_irq();
HAL_RCC_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
__set_MSP(*(uint32_t *)addr);
SysMemBootJump();
}
To simplify my testing i made a minimal CubeMX project where i blink an led a few times, and then attempt to jump to the bootloader. This project is attached.
As the code is now, it seems to exit jumpToBootloader() and then hang on a delay in the main loop, since interrupts are disabled.
As i have said, i have tried many different suggestions, but I have yet to try modifying the startup file. I really dont feel like that should be necessary?
As you can see from the project i build using Make and my arm-none-eabi-gcc is version 9.3.1 0200408.
Edit:
I am also getting som compiler warnings related to the __set_MSP() function:
arm-none-eabi-gcc -c -mcpu=cortex-m0plus -mthumb -DUSE_HAL_DRIVER -DSTM32L071xx -ICore/Inc -IDrivers/STM32L0xx_HAL_Driver/Inc -IDrivers/STM32L0xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32L0xx/Include -IDrivers/CMSIS/Include -Og -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/main.d" -Wa,-a,-ad,-alms=build/main.lst Core/Src/main.c -o build/main.o
In file included from Drivers/CMSIS/Device/ST/STM32L0xx/Include/stm32l071xx.h:114,
from Drivers/CMSIS/Device/ST/STM32L0xx/Include/stm32l0xx.h:151,
from Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_hal_def.h:30,
from Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_hal_rcc.h:29,
from Core/Inc/stm32l0xx_hal_conf.h:187,
from Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_hal.h:30,
from Core/Inc/main.h:31,
from Core/Src/main.c:21:
Drivers/CMSIS/Include/cmsis_gcc.h: In function 'jumpToBootloader':
Drivers/CMSIS/Include/core_cm0plus.h:93:28: warning: listing the stack pointer register 'sp' in a clobber list is deprecated [-Wdeprecated]
93 | #define __ASM __asm /*!< asm keyword for GNU Compiler */
| ^~~~~
Drivers/CMSIS/Include/cmsis_gcc.h:190:3: note: in expansion of macro '__ASM'
190 | __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
| ^~~~~
Drivers/CMSIS/Include/core_cm0plus.h:93:28: note: the value of the stack pointer after an 'asm' statement must be the same as it was before the statement
93 | #define __ASM __asm /*!< asm keyword for GNU Compiler */
| ^~~~~
Drivers/CMSIS/Include/cmsis_gcc.h:190:3: note: in expansion of macro '__ASM'
190 | __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
| ^~~~~
2020-11-10 02:02 AM
The address of the system memory is fine.
Please try to move line 18 (__set_MSP) before line 16 (SysMemBootJump).
/Peter
2020-11-10 02:57 AM
Sadly that gives the same result.
As I just added to the post, I am also getting a warning and notes from the compiler.
Maybe they can help someone understand what is going on?
2020-11-11 12:49 AM
Did you find a solution?
2020-11-11 12:54 AM
No, and I am getting desperate :l
Concidered a latching circuit to keep boot0 pin high when i perform a sw reset.
But that is a really crappy workaround :D
2020-11-13 04:00 AM
No idea?
This is very basic and crucial functionality, so it would be nice if an ST employee would help to fix it.
2020-11-13 04:05 AM
Another interisting thing is that in GDB i can't even read the bootloader ID. This also works fine on my STM32F07.
So could it me some memory protection issue?