cancel
Showing results for 
Search instead for 
Did you mean: 

How to enter ST USART Bootloader from Code?

MootSeeker
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
MootSeeker
Associate II

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.

View solution in original post

7 REPLIES 7
MM..1
Chief II

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

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

MM..1
Chief II

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 .

I already did that. It is also not working.


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

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

Check your connections...

What should I check?

the Connection (Usart) is working in normal use.

The other interfaces are not used, they don‘t have a changing signal on the pins.

Are the boot option bits set correct? Or do I have to change something before jumping to bootloader?

MootSeeker
Associate II

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.