cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect STM32 CubeMX Programmer from my application

Strooom
Associate III

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Strooom
Associate III

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.

View solution in original post

1 REPLY 1
Strooom
Associate III

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.