cancel
Showing results for 
Search instead for 
Did you mean: 

Hardfault on IAP jump to APP

cable gu
Associate II

Hi guys,

I have use the stm32f105 to do a job on the IAP jump tp APP, and normally it works fine, but latest day, I have to disable the USB code on the APP code, then use the flash download demonstrator to download the APP, it runs OK, and then re-power on the device, APP run into hard fault at once.

And I have print the CFSR=0x8200, HFSR=0x40000000, BFAR=0x5548535f(this value seems not right). I can not use BFAR to find the error place. So any one could give some suggestion?

10 REPLIES 10
u_2man
Associate II

Hi..

Try to de-init RCC and SysTick before jump to application

  HAL_RCC_DeInit();

  SysTick->CTRL =0;

  SysTick ->LOAD =0;

  SysTick->VAL=0;

  JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4);

  JumpToApplication = (pFunction) JumpAddress;

  /* Initialize user application's Stack Pointer */

  //SCB->VTOR = APPLICATION_ADDRESS;

  __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

  JumpToApplication();

Usman

Hi Usman,

Thanks for giving the suggestion, and it still goes into the hard fault, and the test code as below:

if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)

{

//__disable_interrupt();

__set_PRIMASK(1);

HAL_RCC_DeInit();

  SysTick->CTRL =0;

  SysTick ->LOAD =0;

SysTick->VAL=0;

//HAL_DeInit();

/* Move the 4 bytes to APP address */

JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);

/* Point to the APP entry address */

Jump_To_Application = (pFunction) JumpAddress;

/* Reset the top of the stack point address */

__set_MSP(*(__IO uint32_t*) ApplicationAddress);

/* Jump to the reset function */

Jump_To_Application();

}

and now, I think the IAP code does not recycle the source, and the main in IAP is below:

int main(void)

{

HAL_Init();

/* Configure the system clock */

SystemClock_Config();

/* Initialize all configured peripherals */

MX_GPIO_Init();

JumpToApp();

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}

Maybe there is still some interrupt running?

u_2man
Associate II

Have you shift the interrupt vector on your application code?

Yes, I did the shift. And normally, the IAP and APP runs OK. This hard fault appear just when I disable the USB host function in APP. So it confused me.

/* #define VECT_TAB_SRAM */

#define VECT_TAB_OFFSET 0x00006000U /*!< Vector Table base offset field. 

Looks to be loading a pointer with the content of an ASCII string.

Really should be looking at LR and PC values and understanding the specific code that is faulting. Look at .MAP file or listing file.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Yes, I think so. Just disable the USB function and the code size reduced, so the map changed, this may related with the problem. And I am looking at the assemble code now, I hope there will be find something.

Make sure you have a couple of KB for the stack

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Yes, the hard fault happens at before the main() function, so I think the stack is no problem.

GNU tools?

Might also want to check startup code, and SystemInit() routines and call tree. Be especially conscious that statics may not yet be initialized when SystemInit() is called.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..