cancel
Showing results for 
Search instead for 
Did you mean: 

How to Jump Bootloader(UART1) from Application for STM32F103

LYS
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

5 REPLIES 5
Uwe Bonnes
Principal III

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

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
Principal III

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.

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.

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();
}