Skip to main content
MootSeeker
Associate
April 21, 2023
Solved

How to enter ST USART Bootloader from Code?

  • April 21, 2023
  • 3 replies
  • 2705 views

Im trying to jump to bootloader section from my Code. I'm trying to update the firmware over USART with the intergrated bootloader. In my application I'm using USART2 (PA2/PA3) on a STM32L431CCU6 Microcontroller running native FreeRTOS.

My Code to initialize should work:

	// Set Memory Boot Jump address
	SysMemBootJump = (void (*) (void)) (*((uint32_t *) 0x1FFF0004)); //device dependent parameter System Memory + 4
 
	// Set Display to Firmware Update Mode
	display_show( FW_UPDATE );
 
	taskENTER_CRITICAL( );
	{
//		vTaskSuspendAll( );
 
		// Turn off Peripherals
		HAL_TIM_Base_MspDeInit(&htim15);
		HAL_RTC_MspDeInit(&hrtc);
		HAL_UART_MspDeInit(&huart2);
		HAL_UART_MspDeInit(&huart1);
		HAL_SPI_MspDeInit(&hspi2);
		HAL_SPI_MspDeInit(&hspi1);
		HAL_CRC_MspDeInit(&hcrc);
 
		// Disable Interrupts
		__disable_irq();
 
		// Remap Memory
		__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
 
		// Reset Systick timer
		SysTick->CTRL = 0;		//reset the Systick Timer
		SysTick->LOAD = 0;
		SysTick->VAL = 0;
 
		__set_PRIMASK (1);
		__set_MSP(*((uint32_t *)0x1FFF0000U));	//expected stack pointer value is the value at adress 0x1FFF0000U
 
		SysMemBootJump();
 
		while( FOREVER );
	}
	taskEXIT_CRITICAL( );

When I try to debugg it, I reach until the jump command and then the debugger is showing nothing anymore. So it looks like it makes the jump.

When analysing the USART interface I see that the device is receiving the 0x7F Command but does not responce on this.

My boot options are all checked:


_legacyfs_online_stmicro_images_0693W00000biZdlQAE.pngThe Bootpin BOOT0 (PH3) is connected to GND via a 10k resistor.

Do I missed something, that the bootloader does not response?

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

I missed

HAL_DeInit();

before jumping to bootloader.

taskENTER_CRITICAL( );
	{
		vTaskSuspendAll( );
 
		// Turn off Peripherals
		HAL_TIM_Base_MspDeInit(&htim15);
		HAL_RTC_MspDeInit(&hrtc);
		HAL_UART_MspDeInit(&huart2);
		HAL_UART_MspDeInit(&huart1);
		HAL_SPI_MspDeInit(&hspi2);
		HAL_SPI_MspDeInit(&hspi1);
		HAL_CRC_MspDeInit(&hcrc);
 
		HAL_DeInit();
 
		// Reset Systick timer
		SysTick->CTRL = 0;		//reset the Systick Timer
		SysTick->LOAD = 0;
		SysTick->VAL = 0;
 
		// Remap Memory
		__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
 
		// Disable Interrupts
		__disable_irq();
 
 
		__set_PRIMASK (1);
		__set_MSP(*((uint32_t *)0x1FFF0000U));	//expected stack pointer value is the value at adress 0x1FFF0000U
 
 
		SysMemBootJump();
		while( FOREVER );
	}
	taskEXIT_CRITICAL( );

 Bootloader is now working.

3 replies

MM..1
Chief III
April 21, 2023

Your parity is set to Even ? 8 - E - 1

MootSeeker
Associate
April 21, 2023

Yes it is set to Even. I also tried None but that also not worked.

MM..1
Chief III
April 22, 2023

Switch in Cubeprogrammer connect to USART and try connect

And primary read AN2606 diagram about interface detection order and check if no other interface is detected .

MootSeeker
Associate
April 22, 2023

I already did that. It is also not working.


_legacyfs_online_stmicro_images_0693W00000bicqLQAQ.pngAccording to AN2606 USART is the first interface to check.

MM..1
Chief III
April 23, 2023

Interfaces is checked in loop. Quickest as you 7F if other is detected...

Check your connections...

MootSeeker
MootSeekerAuthorBest answer
Associate
April 24, 2023

I missed

HAL_DeInit();

before jumping to bootloader.

taskENTER_CRITICAL( );
	{
		vTaskSuspendAll( );
 
		// Turn off Peripherals
		HAL_TIM_Base_MspDeInit(&htim15);
		HAL_RTC_MspDeInit(&hrtc);
		HAL_UART_MspDeInit(&huart2);
		HAL_UART_MspDeInit(&huart1);
		HAL_SPI_MspDeInit(&hspi2);
		HAL_SPI_MspDeInit(&hspi1);
		HAL_CRC_MspDeInit(&hcrc);
 
		HAL_DeInit();
 
		// Reset Systick timer
		SysTick->CTRL = 0;		//reset the Systick Timer
		SysTick->LOAD = 0;
		SysTick->VAL = 0;
 
		// Remap Memory
		__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
 
		// Disable Interrupts
		__disable_irq();
 
 
		__set_PRIMASK (1);
		__set_MSP(*((uint32_t *)0x1FFF0000U));	//expected stack pointer value is the value at adress 0x1FFF0000U
 
 
		SysMemBootJump();
		while( FOREVER );
	}
	taskEXIT_CRITICAL( );

 Bootloader is now working.