Skip to main content
Strooom
Senior
June 5, 2023
Solved

How to detect STM32 CubeMX Programmer from my application

  • June 5, 2023
  • 1 reply
  • 1478 views

I am developing an application on the Seeed Lora-E5 module, which contains an STM32WLE5.

Currently I am programming the device via the SWD interface, but for future firmware updates I want to use the UART, (this UART is available externally through a USB-UART chip).

The problem now is how to make the device switch to the internal bootloader : unfortunately the Boot0 (PH3) PIN on the STM32WLE5 is NOT made available on the package of the Seeed Lora-E5 module, so I cannot use that pin..

From the AN3155 I see that the CubeMx Programmer is sending 0x7F to the UART, in order for the MCU to select the UART as programming interface.

So here is my idea : after reset, I could listen to the UART for eg. 30 seconds, and if in this time a 0x7F byte arrives, jump to the bootloader. (if the 30 seconds expire, the device starts in normal operation mode).

I am aware that the bootloader expects the MCU in the same state as after reset, so I will take that into account, be resetting already configured UART (and other modified peripherals)

Does this make sense ? Any comments ? Did anyone try this ?

Thank you!

This topic has been closed for replies.
Best answer by Strooom

As I got no immediate response, I decided to try it out, and it actually works.

Here is some demo code :

int main(void)
{
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_USART2_UART_Init();
 logging::detectDebugProbe();
 logging::snprintf("normal boot...\n");
 uint8_t data[1];
 HAL_StatusTypeDef result;
 while (1)
 {
 result = HAL_UART_Receive(&huart2, data, 1, 5);
 if (result == HAL_OK)
 {
 if (data[0] == 0x7F)
 {
 logging::snprintf("jmp..\n");
 HAL_UART_DeInit(&huart2);
 JumpToBootloader();
 }
 }
 }
}

the body of

JumpToBootloader();

can be found here :

How to jump to system bootloader from application code on STM32 microcontrollers

Mind the logging:: statements, this some SWO debug class I use to monitor what's going on. They are not needed for the mechanism to work.

1 reply

Strooom
StrooomAuthorBest answer
Senior
June 7, 2023

As I got no immediate response, I decided to try it out, and it actually works.

Here is some demo code :

int main(void)
{
 HAL_Init();
 SystemClock_Config();
 MX_GPIO_Init();
 MX_USART2_UART_Init();
 logging::detectDebugProbe();
 logging::snprintf("normal boot...\n");
 uint8_t data[1];
 HAL_StatusTypeDef result;
 while (1)
 {
 result = HAL_UART_Receive(&huart2, data, 1, 5);
 if (result == HAL_OK)
 {
 if (data[0] == 0x7F)
 {
 logging::snprintf("jmp..\n");
 HAL_UART_DeInit(&huart2);
 JumpToBootloader();
 }
 }
 }
}

the body of

JumpToBootloader();

can be found here :

How to jump to system bootloader from application code on STM32 microcontrollers

Mind the logging:: statements, this some SWO debug class I use to monitor what's going on. They are not needed for the mechanism to work.