cancel
Showing results for 
Search instead for 
Did you mean: 

I want to know why it stops with HardFault_Handler.

koeda
Associate

Hello

It may stop with the interrupt routine of HardFault_Handler.

MCU: STM32F446VCTx

Tools: CubeMX

IDE: IAR Embedded Workbench IDE

This routine is in stm32f4xx_it.c.

void HardFault_Handler(void)
{
  /* USER CODE BEGIN HardFault_IRQn 0 */
 
  /* USER CODE END HardFault_IRQn 0 */
  while (1)
  {
  }
  /* USER CODE BEGIN HardFault_IRQn 1 */
 
  /* USER CODE END HardFault_IRQn 1 */
}
 
 

Currently the status of the following registers is confirmed.

CFSR: Settable Fault Status Register INVSTATE bit is 1.

BFAR: The bus fault address register is 0xE000EDF8.

Registers above seem to be involved.

If you have detailed information, please explain the comment.

Attention, I am Japanese. This content is based on Google translation.

2 REPLIES 2

Check you have adequate heap and stack to accommodate what you are doing.

Try to identify the instructions that are faulting, a while(1) loop is not very helpful for that.

In Keil I have this

HardFault_Handler\
                PROC
                EXPORT  HardFault_Handler          [WEAK]
 
                TST     lr, #4          ; Determine correct stack
                ITE     EQ
                MRSEQ   R0, MSP         ; Read MSP (Main)
                MRSNE   R0, PSP         ; Read PSP (Process)
 
                MOV     R1, R4          ; Registers R4-R6, as parameters 2-4 of the function called
                MOV     R2, R5
                MOV     R3, R6          ;  sourcer32@gmail.com
 
                EXTERN  hard_fault_handler_c
                B       hard_fault_handler_c
                ENDP
void hard_fault_handler_c(unsigned int * hardfault_args, unsigned int r4, unsigned int r5, unsigned int r6)
{
  printf ("\n[Hard Fault]\n"); // After Joseph Yiu
 
  printf ("r0 = %08X, r1 = %08X, r2 = %08X, r3 = %08X\n",
    hardfault_args[0], hardfault_args[1], hardfault_args[2], hardfault_args[3]);
  printf ("r4 = %08X, r5 = %08X, r6 = %08X, sp = %08X\n",
    r4, r5, r6, (unsigned int)&hardfault_args[8]);
  printf ("r12= %08X, lr = %08X, pc = %08X, psr= %08X\n",
    hardfault_args[4], hardfault_args[5], hardfault_args[6], hardfault_args[7]);
 
  printf ("bfar=%08X, cfsr=%08X, hfsr=%08X, dfsr=%08X, afsr=%08X\n",
    *((volatile unsigned int *)(0xE000ED38)),
    *((volatile unsigned int *)(0xE000ED28)),
    *((volatile unsigned int *)(0xE000ED2C)),
    *((volatile unsigned int *)(0xE000ED30)),
    *((volatile unsigned int *)(0xE000ED3C)) );
 
  while(1);
}

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

Thank you for reply.

I'll give it a try.