cancel
Showing results for 
Search instead for 
Did you mean: 

Bootloader HardFault Error Peripheral

Hi world!
Associate III

Hi guys,

I'm using a bootloader. I am using 2 UART channels in the bootloader program. At the same time, I use these uart channels in the program I will install. But they don't work. The program enters the HardFault Error interrupt. When sending data to the uart channel when debugging, the program is corrupted and enters the HardFault Error interrupt.

What can I do?

Thanks..

17 REPLIES 17

>>What can I do?

Instrument the Hard Fault Handler so you understand how/why it got there, and learn how to debug gross errors?

Most likely source of errors insufficient stack size, and errant pointers or memory access.

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

> What can I do?

Provide more information.

Like code for the UART initialization and the interrupt handlers.

Or you can step though your code in a debugger, and identify where the hardfault happens.

Perhaps inproper peripheral settings remain from the bootloader code. Or the interrupt vectors / settings are messed up.

Hi world!
Associate III

Sorry ..

I able to blink led with bootloader. But if i use uart etc. program is go to HardFault_Handler.

MCU: Stm32f0

This my jumpping function:

      void (*JumpToApp)(void);
 
      __set_CONTROL(0);
      SysTick->CTRL = 0;
      SysTick->LOAD = 0;
      SysTick->VAL = 0;
 
      __disable_irq();
      
      __DSB();
      __ISB();
 
      SYSCFG->CFGR1 = 0x01;
      
      uint32_t msp_value = *(__IO uint32_t *)UserStartAdress;
      uint32_t JumpAppAddr = *(__IO uint32_t *) (UserStartAdress+4);
      
      JumpToApp = (void (*) (void))JumpAppAddr;
      __set_MSP(*(__IO uint32_t *)UserStartAdress);
            
      JumpToApp();

And this in my user application program for vector configuration, RemapTable():

  #define APPLICATION_ADDRESS     (uint32_t)0x08003000
  
  __IO uint32_t *VectorTable = (__IO uint32_t *)0x20000000;
  
  uint32_t Index = 0;
  for(Index = 0; Index < 48; Index++) {
    VectorTable[Index] = *(__IO uint32_t*)((uint32_t)APPLICATION_ADDRESS + (Index << 2));
  } 
  __HAL_RCC_USART1_FORCE_RESET();
  __HAL_RCC_USART2_FORCE_RESET();
  __HAL_RCC_USART1_RELEASE_RESET();
  __HAL_RCC_USART2_RELEASE_RESET();
  __HAL_RCC_APB2_FORCE_RESET();
  __HAL_RCC_AHB_FORCE_RESET();
  __HAL_RCC_SYSCFG_CLK_ENABLE();
  __HAL_RCC_AHB_RELEASE_RESET();
  __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
  __HAL_SYSCFG_REMAPMEMORY_SRAM();
  
  __enable_irq();

And finally this my main function:

  RemapTable();
 
  HAL_Init();
 
  SystemClock_Config();
 
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_TIM6_Init();
  MX_NVIC_Init();
  
  PORTA_ODR.Led = 1; //Led is okey, ON
  
  xfprintf(UART, "\n/*** Boot ***/\n\n"); // This not work, go hardfault error interrupt

Hi world!
Associate III

Any ideas?

AvaTar
Lead

> xfprintf(UART, "\n/*** Boot ***/\n\n"); // This not work, go hardfault error interrupt

I'm not doing Cube code.

What is xprintf() supposed to do, and where/how is it implemented ?

Hardfaults on printf()-like functions tend to be stack related, i.e. insufficient stack size.

Hi world!
Associate III

Yes, my problem is insufficient stack size.

I wrote my relocation code and jump code.

Where I am wrong?

My brain is blocked :)

AvaTar
Lead

Stack size is a parameter you feed into the project settings.

The toolchain reserves said chunk of memory for the stack, and feeds the pointer to that chunk to the appropriate place in the vector table, where the MCU fetches it at startup. I assume you know the stack grows downward.

Consult the map file for your project.

BTW, mentioning the toolchain would be helpful.

Hi world!
Associate III

What can i do?

Hi world!
Associate III

This general problem. But no enought information.