cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to write a Bootloader on STM32L4R5ZI MCU that gets data through the UART.

Shilpashree Madhu
Associate III

My question is I need to send the Application's binary file with CRC using Teraterm/Docklight.. so in the Bootloader project, I need to receive the Hex file of the application and verify the CRC of it, if it matches then it should be written to flash area.. how do I do?

7 REPLIES 7
KnarfB
Principal III

Search for existing bootloader projects for STM32, there are plenty of them like OpenBLT.

hth

KnarfB

Yeah, I saw some openbootloader projects but they are all difficult to understand, I want simple bootloader configuration for flashing application bin file using STM32 Cube Programmer how can i do it, please help me...

KnarfB
Principal III

STM32 MCUs have a "system memory boot" mode which is a built-in bootloader. STM32CubeProgrammer can talk to it. Just set the boot pins accordingly (see reference manual), connect chip to STM32CubeProgrammer via UART (see system memory boot app. note to find the correct pins), reset the chip. There is no need to write own code here. There are also tutorials on how to jump to system memory boot loader your from application code (without setting boot pins)

hth

KnarfB

Thank you..

MM..1
Chief II

System bootloader will work for you fine only when USART is on pins from AN2606 for your MCU.

Otherwise you need change schematics or use own bootloader.

Your idea with load and check one CRC work only if your fw size is less as RAM... Normal bootloader use blocks and crc on every block usw.

Hello @KnarfB​ Could you please share me the document which explains to enter into system memory bootloader without setting boot pins, since in our HW there are no provision to chnage the boot mode pins but wanted to implement the bootloader and the communication via UART. I'm using STM32F030CC uC, I have gone through the IAP and to execute this need to do the changes in boot pins and as the uC which I'm using belongs to Cortex-M0 there are no possibilities to reloacte the vector table.

On this Cortex own code relocates vectors to ram.

And start bootloader jump function is here mentioned many times but for you repeat

/**
 * Function to perform jump to system memory boot from user application
 *
 * Call function when you want to jump to system memory
 */
void JumpToBootloader(void) {
	void (*SysMemBootJump)(void);
 
	/**
	 * Step: Set system memory address. 
	 *       
	 *       For other families, check AN2606 document table 110 with descriptions of memory addresses 
	 */
	volatile uint32_t addr = 0x1FFFEC00; //0x1FFF0000;
 
	/**
	 * Step: Disable RCC, set it to default (after reset) settings
	 *       Internal clock, no PLL, etc.
	 */
#if defined(USE_HAL_DRIVER)
	HAL_RCC_DeInit();
#endif /* defined(USE_HAL_DRIVER) */
#if defined(USE_STDPERIPH_DRIVER)
	RCC_DeInit();
#endif /* defined(USE_STDPERIPH_DRIVER) */
	
	/**
	 * Step: Disable systick timer and reset it to default values
	 */
	SysTick->CTRL = 0;
	SysTick->LOAD = 0;
	SysTick->VAL = 0;
 
	/**
	 * Step: Disable all interrupts
	 */
	__disable_irq();
	
	/**
	 * Step: Remap system memory to address 0x0000 0000 in address space
	 *       For each family registers may be different. 
	 *       Check reference manual for each family.
	 *
	 *       For STM32F4xx, MEMRMP register in SYSCFG is used (bits[1:0])
	 *       For STM32F0xx, CFGR1 register in SYSCFG is used (bits[1:0])
	 *       For others, check family reference manual
	 */
	//Remap by hand... {
#if defined(STM32F4)
	SYSCFG->MEMRMP = 0x01;
#endif
//#if defined(STM32F0)
	SYSCFG->CFGR1 = 0x01;
//#endif
	//} ...or if you use HAL drivers
	//__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();	//Call HAL macro to do this for you
	
	/**
	 * Step: Set jump memory location for system memory
	 *       Use address with 4 bytes offset which specifies jump location where program starts
	 */
	SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
	GPIOA->ODR ^= LED_2;
 
/**
	 * Step: Set main stack pointer.
	 *       This step must be done last otherwise local variables in this function
	 *       don't have proper value since stack pointer is located on different position
	 *
	 *       Set direct address location which specifies stack pointer in SRAM location
	 */
	__set_MSP(*(uint32_t *)addr);
	/**
	 * Step: Actually call our function to jump to set location
	 *       This will start system memory execution
	 */
	SysMemBootJump();
	
	/**
	 * Step: Connect USB<->UART converter to dedicated USART pins and test
	 *       and test with bootloader works with STM32 Flash Loader Demonstrator software
	 */
}