cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G070: TIM6 not working after jump from builtin bootloader to user code

klaus0x7C4
Associate

Hello,

i work with STM32G070KBT and i jump from my code to the buitin ST bootloader. Then i use SPI to upload my new code/binary and send the Go command. I receive an ACK but nothing happen. My code is not executet or stops working early.

If the bootloader starts after a full chips erase (done with STM32CubeProgrammer) the Go command works as expected.

My jump code looks like:

#define SYSTEM_MEMORY_ADDRESS 0x1FFF0000
 
void jump_to_bootloader()
// https://github.com/markusgritsch/SilF4ware/blob/master/SilF4ware/drv_reset.c
// https://stm32f4-discovery.net/2017/04/tutorial-jump-system-memory-software-stm32/
{
	HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);
	while (HAL_NVIC_GetPendingIRQ(EXTI4_15_IRQn)) {
		HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
		HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
		HAL_NVIC_ClearPendingIRQ(EXTI4_15_IRQn);
	}
	HAL_RCC_DeInit();  // disable reset and clock control
	HAL_DeInit();
 
	SysTick->CTRL = 0;  // disable systick timer
	SysTick->LOAD = 0;
	SysTick->VAL = 0;
 
	// remap system memory to address 0x00000000
	__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
 
	// set main stack pointer in SRAM location
	// 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_MSP(*(uint32_t *)SYSTEM_MEMORY_ADDRESS);
 
	// set jump memory location for system memory
	// use address with 4 bytes offset which specifies jump location where program starts
	void (*SysMemBootJump)(void);
	SysMemBootJump = (void (*)(void)) (*((uint32_t *)(SYSTEM_MEMORY_ADDRESS + 4)));
	// actually call our function to jump to set location and start system memory execution
	SysMemBootJump();
 
	// start firmware download over SPI
}

The project is create with STM32CubeMX and uses some GPIOs, the same SPI interface in slave mode the bootloader use and TIM6.

Have you some ideas what can i try to do?

Without a debugger, how can I tell if my code is even running? With debugger (ST-Link V2 via SWD interface) the bootloader is not working properly :-/

Regards

Klaus

1 REPLY 1
klaus0x7C4
Associate

I found out that my code hangs in this loop:

HAL_TIM_Base_Start(&htim6);
while (__HAL_TIM_GET_COUNTER(&htim6) < 10); // it is now an endless loop

The timer value is always zero.

I have added the following line to the jump method. But nothing has changed:

HAL_TIM_Base_DeInit(&htim6);

What can I do to initialise the timer correct after bootloaders Go command?