Skip to main content
Graduate
September 5, 2024
Solved

STM32G0 bootloader usart loop

  • September 5, 2024
  • 2 replies
  • 1474 views

Hi,

I am using built-in usart bootloader on stm32g0. And I am also using the same usart for communication in my user app. I enabled the bootloader via boot option bits. When I start the debug session, I can see the flow stepping over through the program flow, going over HAL_Init()SystemClock_Config(),  MX_GPIO_Init() and MX_USART1_UART_Init(), and then the program flow comes to my first "HAL_UART_Receive(..." function. 

It is at this function that the program jumps to the Bootloader and the bootloader starts to respond to my uasrt commands. After I exit the bootloader, via the "Go command(I use address 0x08000000)", the program flow stops at breakpoint I have at "HAL_Init()" and then when I step over again, I see that as soon as I hit the "HAL_UART_Receive(..." function again, it goes back into bootloader.

 

So, my thinking now is that after I exit the bootloader, I should modify the boot bit (nBOOT0) in my user code, to disable it and then enabling it again via the uart command later, if i want to return to bootloader?

int main(void)
{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */
 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_USART1_UART_Init();
 //MX_ADC1_Init();
 /* USER CODE BEGIN 2 */
 char tmp[1]; //Dummy variable for next line HAL uart receive function.
 HAL_UART_Receive(&huart1, tmp, 1, 500);
 //cha...

 

 

 

 

    This topic has been closed for replies.
    Best answer by mƎALLEm

    RM0444 Rev 5 / Sections 2.5 Boot configuration and 3.4.2 FLASH option byte programming.

     

    2 replies

    Technical Moderator
    September 5, 2024

    Hello @KlemenPfce 

    If you configure the option bytes to Jump to the system memory and you didn't changed it to jump to the Flash memory (to run your application), indeed, the MCU keeps  running the system memory. So you need to restore the default option bytes boot config to jump to the Flash memory and, if needed, modify it again for system memory to execute bootloader program. Make sure you make a system reset after each change to let the MCU reading these new values at startup.

    Graduate
    September 5, 2024

    Yes, so I need to modify option bytes inside my code. But I cant find info on how to do it. Is there an AN or RM where this process is described?

    mƎALLEmAnswer
    Technical Moderator
    September 5, 2024

    RM0444 Rev 5 / Sections 2.5 Boot configuration and 3.4.2 FLASH option byte programming.

     

    Graduate II
    September 5, 2024

    If you're using a really low-pin count package, perhaps this thread is relevant.

    AKA "Life gets interesting when NRST and the UART share a pin".