2024-03-01 04:57 AM - edited 2024-03-01 05:12 AM
I'm using an STM32F446RE MCU on a custom board and I developed a custom bootloader. The bootloader starts at 0x8000000, while the application code starts at 0x8008000. Inside the bootloader I use timer 14 with interrupt and when I need to jump I use the following code:
HAL_CAN_DeactivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);
HAL_CAN_Stop(&hcan1);
HAL_CAN_DeInit(&hcan1);
HAL_TIM_Base_Stop_IT(&htim14); // Note this
HAL_TIM_Base_DeInit(&htim14); // Note this
HAL_RCC_DeInit();
HAL_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
uint32_t JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);
pFunction Jump_To_Application = (pFunction) JumpAddress;
SCB->VTOR = APPLICATION_ADDRESS;
__set_MSP(*(__IO uint32_t*) (APPLICATION_ADDRESS ));
Jump_To_Application();
Now inside the application code I need the same timer 14 and I also want to debug the application code. The debugger works perfectly until the execution reaches this line:
HAL_TIM_Base_Start_IT(&htim14)
At that point the debugger stucks and the program counter jumps from 0x8009a78 (which makes sense because it is in application code) to 0x80030e2 (which does not make sense because it is in the bootloader part). But if I run the application without debugging it, it seems to work without any issue.
It seems something related to timer 14, but as you can see I deinitialized the peripheral.
Solved! Go to Solution.
2024-03-01 07:34 AM
2024-03-01 07:34 AM
Resolved by adding:
SCB->VTOR = 0x8008000;
in system_stm32f4xx.c