Showing results for 
Search instead for 
Did you mean: 

Hard Fault in STM32CubeMX Generated Code

Associate II
Posted on August 05, 2016 at 06:07

This is an STM32CubeMX 4.16.0 generated project. The  STM32CubeMX project file is attached. The processor is an STM32F373VCT6

I have a Hard Fault. Below is the call stack and register contents when the Hard Fault happened. It happens in STM32CubeMX generated code. I have suspicion it has something to do with TIM6, which is used to serve as the hardware ticker timer for FREERTOS. TIM6 was selected in an earlier version of STM32CubeMX. I no longer see where the hardware ticker timer is selected for FREERTOS. I only see that TIM6 is grayed out in Pinout tab.

This function is where it happened:



  NVIC->ISER[(((uint32_t)(int32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)(int32_t)IRQn) & 0x1FUL));


Any help in fixing this would be appreciated.

HardFault_Handler() at Segger_HardFaultHandler.c:293 0x8006578    

<signal handler called>() at 0xfffffff1    

HAL_TIM_IRQHandler() at stm32f3xx_hal_tim.c:2,812 0x800d902    

TIM6_DAC1_IRQHandler() at stm32f3xx_it.c:255 0x801ae24    

<signal handler called>() at 0xfffffff9    

NVIC_EnableIRQ() at core_cm4.h:1,628 0x8017da0    

HAL_NVIC_EnableIRQ() at stm32f3xx_hal_cortex.c:237 0x8017da0    

HAL_InitTick() at stm32f3xx_hal_timebase_TIM.c:74 0x801aee0    

HAL_Init() at stm32f3xx_hal.c:165 0x8019de0    

main() at main.c:244 0x801b588    

HardFaultRegs.SavedRegs    struct {...}    {...}    

    r0    volatile unsigned int    0x20006ea8    

    r1    volatile unsigned int    0x0    

    r2    volatile unsigned int    0xfffffff7    

    r3    volatile unsigned int    0x0    

    r12    volatile unsigned int    0x0    

    lr    volatile unsigned int    0x801ae25    

    pc    volatile unsigned int    0x800d902    

    psr    union {...}    {...}    

        byte    volatile unsigned int    0x21000046    

        bits    struct {...}    {...}    

            IPSR    unsigned int    0x46    

            EPSR    unsigned int    0x10000    

            APSR    unsigned int    0x4    

Posted on August 05, 2016 at 16:50

And which interrupt is it enabling there? It something is pending, off it will go.

Start by looking at that, make sure the right name exists in the vector tables, and that it linked in properly.

Also look at the stack allocation, in Keil that would be in the startup_stm32fxxx.s file, make sure that is adequate.

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