Skip to main content
LYS
Associate II
January 20, 2021
Solved

How to Jump Bootloader(UART1) from Application for STM32F103

  • January 20, 2021
  • 2 replies
  • 2410 views

I am new to STM32F103

and My goal is to Update Firmware using Bootloader.

but I do not want to use Hardware way as Pin BOOT0.

I want to enter bootloader mode using Backup Register.

here is my code

============================

if (BKP->DR1 != 0) //DR != 0 means, that boot request has been sent

 {

 uint32_t *stack_ptr = (uint32_t *)FW_ADDR;

  __disable_irq(); // Good idea when messing with MSP/VTOR

 #if 1

  LL_RCC_DeInit();

 #elif 0

  HAL_DeInit();

 #else

  //__HAL_RCC_AHB1_FORCE_RESET();

  //__HAL_RCC_AHB1_RELEASE_RESET();

 #endif

  SysTick->CTRL=0;

  SysTick->LOAD=0;

  SysTick->VAL=0;

  __set_PRIMASK(1);

  SCB->VTOR = FW_ADDR;

 #if 0

  __set_MSP(*(volatile uint32_t *)FW_ADDR);

 #else

   __set_MSP(0x20001000); // Use value found at 0x1FFF0000

 #endif

  __set_CONTROL(0);

  // Call the reset handler (the construct below is 'pointer to a pointer to a function that takes no arguments and returns void')

  void (*SysMemBootJump)(void) = (void *)*(volatile uint32_t *)(FW_ADDR + 4);

  SysMemBootJump();  // Call it as if it were a C function

 }

====================================

But "Flash Loader Demonstrator" says

"Cannot get available commands,..."

If someone has the solution, please share it with me.

Thank you.

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

Thank you for the reply.

I got the answer from STMicroelectronics

It is impossible to jump the system Bootloader(0x1FFFF000).

Because STM32F1 series does not support the memory remap function.

2 replies

Uwe Bonnes
Chief
January 20, 2021

There have been many threads with good advice on this subject. Search these threads!

LYS
LYSAuthor
Associate II
January 21, 2021

I already found some threads but failed.

and there is not much about STM32F1 series.

If you have any threads that could help me, please let me know.

Uwe Bonnes
Chief
January 21, 2021

Best way to enter the bootloader is code that just after boot checks for the bootloader condition. No IRQs, no PLL setup and nothing more that could interfere. If things do nor work as expected, single step in the debugger to see what is going wrong.

LYS
LYSAuthorBest answer
Associate II
January 22, 2021

Thank you for the reply.

I got the answer from STMicroelectronics

It is impossible to jump the system Bootloader(0x1FFFF000).

Because STM32F1 series does not support the memory remap function.

October 17, 2024

It is very much possible on stm32f1xxx. You don't need remap, just set VTOR appropriatly.

 

#define BOOT_ADDR	0x1FFFF000	// MCU boot code base address

void JumpToBootloader(void)
{
	/* Disable all interrupts */
	__disable_irq();

	/* Set the clock to the default state */
	LL_RCC_DeInit();

	/* Disable Systick timer */
	SysTick->CTRL = 0;
	SysTick->LOAD = 0;
	SysTick->VAL = 0;

	/* Clear Interrupt Enable Register & Interrupt Pending Register */
	for (uint8_t i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++)
	{
		NVIC->ICER[i]=0xFFFFFFFF;
		NVIC->ICPR[i]=0xFFFFFFFF;
	}

	/* Re-enable all interrupts */
	__enable_irq();

	void (*SysMemBootJump)(void);
	SysMemBootJump = (void*) (*((uint32_t*) (BOOT_ADDR + 4)));

	/* Set Vector table */
	SCB->VTOR = BOOT_ADDR;

	/* Wait for all operations complete */
	__DSB();
	__ISB();

	/* Set the Master Stack Pointer */
	__set_MSP(*(uint32_t*) BOOT_ADDR);

	// Jump to app firmware
	SysMemBootJump();
}