2023-01-11 05:37 AM
Hello,
I am working on a custom bootloader for STM32F105 which it is possible to write a bin file into the flash via CAN bus(CAN2).
My issue is that the part of bootloader to jump to application doesn't work.
Here is the jump function code:
#define MAIN_PROGRAM_START_ADDRESS 0x08002000
void JumpToApplication(void)
{
JumpAddress = *(__IO uint32_t*)(MAIN_PROGRAM_START_ADDRESS + 4);
Jump_To_Application = (pFunction) JumpAddress;
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOD_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOA_CLK_DISABLE();
HAL_RCC_DeInit();
HAL_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
/**
* Step: Disable all interrupts
*/
__disable_irq();
__set_MSP(*(volatile uint32_t*) MAIN_PROGRAM_START_ADDRESS);
Jump_To_Application();
}
Function HAL_RCC_DeInit() jumps directly to HardFault_Handler(). I am using an external crystal ocsilator 8MHz.
Without calling HAL_RCC_DeInit(), the Jump_To_Application() jumps directly to HardFault_Handler().
Any idea?
Thank you.
2023-01-11 06:24 AM
show me this bit from your code
2023-01-11 06:28 AM
Here:
2023-01-11 06:30 AM
looks alright, is the systick ticking at all?
Take a look at "uwTick" variable in your live expressions while debugging
2023-01-11 06:32 AM
Yes the variable is ticking
2023-01-11 06:35 AM
Thats weird because
>>The first line "tickstart = HAL_GetTick();" jumps to fault handler
HAL_GetTick just returns that variable
__weak uint32_t HAL_GetTick(void)
{
return uwTick;
}
If i were you i would start all over again fresh CubeMX project, only the XTAL and make sure hal_delay is working , keep adding stuff untill it breaks again.
2023-01-11 07:05 AM
Now the second line SET_BIT(RCC->CR, RCC_CR_HSION) jumps to fault handler.
2023-01-12 05:36 AM
I made .ioc file for bootloader as the same as .ioc file for the application, and HAL_RCC_deinit() didn't jump to hard fault.
But the last line of the jump function Jump_To_Application() jumps now to hard fault interrupt.
2023-01-13 04:16 AM
I have fixed the issue and the bootloader works fine.
2023-01-13 04:47 AM
Congratulations, do you mind explaining how for the next person that has a similar problem?
2023-01-13 04:55 AM
As I mentioned I fixed the hard fault issue by using the same ioc file for bootloader as application (just initialization) and then I found that I didn't program data correctly on the flash.
Now I am able to jump to application, but after I make a power cycle (reset) on PCB, the application doesn't start anymore. So, I am still working on it.