cancel
Showing results for 
Search instead for 
Did you mean: 

Jump To Application From

NASI
Senior

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.

19 REPLIES 19

show me this bit from your code0693W00000Y7yZGQAZ.png

we dont need to firmware by ourselves, lets talk
NASI
Senior

Here:

0693W00000Y7ybMQAR.png

looks alright, is the systick ticking at all?

Take a look at "uwTick" variable in your live expressions while debugging

we dont need to firmware by ourselves, lets talk
NASI
Senior

Yes the variable is ticking

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.

we dont need to firmware by ourselves, lets talk
NASI
Senior

Now the second line SET_BIT(RCC->CR, RCC_CR_HSION) jumps to fault handler.

NASI
Senior

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.

0693W00000Y85TtQAJ.png 

NASI
Senior

I have fixed the issue and the bootloader works fine.

Congratulations, do you mind explaining how for the next person that has a similar problem?

we dont need to firmware by ourselves, lets talk
NASI
Senior

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.