Jump to bootloader STM32F103
Posted: Mon Feb 08, 2021 11:18 am
Hi All,
I am building a prototype controller board using the STM32F103C8 (Bluepill based board)with remote download & control capability (via serial modem). As an enhancement, I am trying to call the bootloader from the program so that I can set the controller in bootloader mode. That way I dont have to open the enclosure and change the BOOT 0 pin state.
During start-up, with in the first 5 or 10 seconds, if a sequence of character(s) is received at the serial port the "JumpToBootLoader" function will be called.
After looking around on internet, I found a tutorial at this link
https://stm32f4-discovery.net/2017/04/t ... are-stm32/
The function is defined as below
void JumpToBootloader(void) {
void (*SysMemBootJump)(void);
volatile uint32_t addr = 0x1FFFF000;
/**
* Step: Disable RCC, set it to default (after reset) settings
* Internal clock, no PLL, etc.
*/
#if defined(USE_HAL_DRIVER)
HAL_RCC_DeInit();
#endif /* defined(USE_HAL_DRIVER) */
#if defined(USE_STDPERIPH_DRIVER)
RCC_DeInit();
#endif /* defined(USE_STDPERIPH_DRIVER) */
/**
* Step: Disable systick timer and reset it to default values
*/
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/**
* Step: Disable all interrupts
*/
__disable_irq();
* Step: Set jump memory location for system memory
* Use address with 4 bytes offset which specifies jump location where program starts
*/
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
/**
* Step: Set main stack pointer.
* This step must be done last otherwise local variables in this function
* don't have proper value since stack pointer is located on different position
*
* Set direct address location which specifies stack pointer in SRAM location
*/
__set_MSP(*(uint32_t *)addr);
SysMemBootJump();
}
The function compiles without any error on Arduino STM32 Core 1.9.0 version. But when i run the code on the controller and the above function is called, the controller sends a garbage character to serial port and seems to go into an indeterminate state. Same Code runs normally if the JumpToBoootloader function is not called.
I have tried this routine on STM32Cube IDE and it works perfectly. The MCU goes into download state and I am able to program the MCU.
My knowledge about core HAL libraries and debugging STM32 on Arduino is very minimal. I would like to develop the code on Arduino due to vast collection of libraries and simplicity.
Is there a trick to getting this function to work in Arduino could anybody point me in the right direction.
Any help would be much appreciated.
Thanks in advance
I am building a prototype controller board using the STM32F103C8 (Bluepill based board)with remote download & control capability (via serial modem). As an enhancement, I am trying to call the bootloader from the program so that I can set the controller in bootloader mode. That way I dont have to open the enclosure and change the BOOT 0 pin state.
During start-up, with in the first 5 or 10 seconds, if a sequence of character(s) is received at the serial port the "JumpToBootLoader" function will be called.
After looking around on internet, I found a tutorial at this link
https://stm32f4-discovery.net/2017/04/t ... are-stm32/
The function is defined as below
void JumpToBootloader(void) {
void (*SysMemBootJump)(void);
volatile uint32_t addr = 0x1FFFF000;
/**
* Step: Disable RCC, set it to default (after reset) settings
* Internal clock, no PLL, etc.
*/
#if defined(USE_HAL_DRIVER)
HAL_RCC_DeInit();
#endif /* defined(USE_HAL_DRIVER) */
#if defined(USE_STDPERIPH_DRIVER)
RCC_DeInit();
#endif /* defined(USE_STDPERIPH_DRIVER) */
/**
* Step: Disable systick timer and reset it to default values
*/
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/**
* Step: Disable all interrupts
*/
__disable_irq();
* Step: Set jump memory location for system memory
* Use address with 4 bytes offset which specifies jump location where program starts
*/
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
/**
* Step: Set main stack pointer.
* This step must be done last otherwise local variables in this function
* don't have proper value since stack pointer is located on different position
*
* Set direct address location which specifies stack pointer in SRAM location
*/
__set_MSP(*(uint32_t *)addr);
SysMemBootJump();
}
The function compiles without any error on Arduino STM32 Core 1.9.0 version. But when i run the code on the controller and the above function is called, the controller sends a garbage character to serial port and seems to go into an indeterminate state. Same Code runs normally if the JumpToBoootloader function is not called.
I have tried this routine on STM32Cube IDE and it works perfectly. The MCU goes into download state and I am able to program the MCU.
My knowledge about core HAL libraries and debugging STM32 on Arduino is very minimal. I would like to develop the code on Arduino due to vast collection of libraries and simplicity.
Is there a trick to getting this function to work in Arduino could anybody point me in the right direction.
Any help would be much appreciated.
Thanks in advance