cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault_Handler exception problem

juanjo
Associate II
Posted on March 27, 2013 at 23:32

Hello all,

I will apreciate any help that can give me some light to understand what is happening.

The firmware has a loader, data flash and an application.

ROM memory mapping:

* Loader 0x0000h - 0x3FFFh

* EEPROM DATA 0x4000h - 0x4FFFh

* Aplication 0x5000h - 0x1FFFh

Due to some reason that I don't know HardFault exception happend.

As recomended in some post I implemented the Joseph Yiu code as follow:

startup_stm32f10x_md.s

;HardFault_Handler

;        B HardFault_Handler

HardFault_Handler

        TST LR, &sharp4

        ITE EQ

        MRSEQ R0, MSP

        MRSNE R0, PSP

        B HardFault_Handler

And implemented the Joseph Yiu code in the interrupts.c file (application NVIC region), I can post it if needed.

The problem happend when the applicaiton is running.

This is the output that I get when the exception happend (application NVIC):

-- DEBUG --   HardFault_Handler      

                                          [Hard fault handler - all numbers in hex]

-- DEBUG --   HardFault_Handler      R0 = 20000478

-- DEBUG --   HardFault_Handler      R1 = 8003b15

-- DEBUG --   HardFault_Handler      R2 = 800368d

-- DEBUG --   HardFault_Handler      R3 = 800369d

-- DEBUG --   HardFault_Handler      R12 = 80036ad

-- DEBUG --   HardFault_Handler      LR [R14] = 80036bd  subroutine call return address

-- DEBUG --   HardFault_Handler      PC [R15] = 80036cd  program counter

-- DEBUG --   HardFault_Handler      PSR = 0

-- DEBUG --   HardFault_Handler      BFAR = e000ed38

-- DEBUG --   HardFault_Handler      CFSR = 100

-- DEBUG --   HardFault_Handler      HFSR = 40000000

-- DEBUG --   HardFault_Handler      DFSR = 0

-- DEBUG --   HardFault_Handler      AFSR = 0

-- DEBUG --   HardFault_Handler      SCB_SHCSR = 0

Well the PC point directly to the UsageFault handler located in the loader NVIC

void UsageFault_Handler(void) {

UsageFault_Handler:

    0x80036cc: 0xb580         PUSH      {r7, lr}

    debugPrint(''LOADER - UsageFault Handler'');

    0x80036ce: 0xf20f 0x1130  ADR.W     r1, ?<Constant ''LOADER - UsageFault H...''> ; 0x44414f4c (1145130828)

    0x80036d2: 0xf20f 0x1018  ADR.W     r0, ??__FUNCTION___5    ; 0x67617355 (1734439765)

    0x80036d6: 0xf7fe 0xfd81  BL        debugPrintMsg           ; 0x80021dc

    while (1) {

??UsageFault_Handler_0:

    0x80036da: 0xe7fe         B.N       ??UsageFault_Handler_0  ; 0x80036da

And the values stored in R0(stack), R1, R2,R3 y R12 are Loader handlers interrupts as I can show bellow.

Reset_Handler           0x08003b15         Code  Wk  startup_stm32f10x_md_vl.o [1]

NMI_Handler             0x0800368d   0x10  Code  Gb  interrupciones.o [1]

HardFault_Handler       0x0800369d   0x10  Code  Gb  interrupciones.o [1]

When I try to execute some code for example debugPrint in this interrups I can't get data.

When I start the Micro, run loader and start the application correctly,

but it seems that when the application is running can't go back to the loader.

Any idea to understand what is happening and how to get the error source. I think that it happening someting in the code but run the loader NVIC exceptions and can't get the cause of the exception.

Thanks in advance.

#stm32-hardfault-exception
2 REPLIES 2
Posted on March 27, 2013 at 23:57

Looks like you're dumping the base of FLASH situated/mapped at ZERO, and not the stack. ie your vector table not register contents. SP == 0

Check you have adequate allocations for the main and process stacks.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
juanjo
Associate II
Posted on March 28, 2013 at 12:36

Thanks clive1 for your advice, you are completily right.

It was in the main allocation, due to write more data in a buffer than expected. But the exception happent several lines of code after (two functions) this make me think in other causes.

Thanks you very much.