cancel
Showing results for 
Search instead for 
Did you mean: 

Hardfault Handler in STM32

akshayamk
Associate II
Posted on February 17, 2016 at 02:06

Hello!

I am using a custom made STM32F302RE board.

At the start of CAN initialisation, I wrote  __HAL_CAN_DISABLE_IT(&hcan, CAN_IT_BOF); to disable all interrupts before initialising CAN.

However, the codes go to hardfault handler after this. Why is that so? How do I rectify or solve this?

Thanks!
7 REPLIES 7
Posted on February 17, 2016 at 04:27

Somewhat indicative that the structure contains some junk or a broken pointer. Check that it is initialized.

Look at the instructions that are faulting, and the registers.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
akshayamk
Associate II
Posted on February 17, 2016 at 09:39

Hi Clive,

I use the can pointer and have already verified that it is not broken. I am using the same set of codes for STMF302R8 custom made board and they work without going to handler but have issues on the STM32F302RE board.

Amel NASRI
ST Employee
Posted on February 18, 2016 at 12:45

Hi mk.shasha,

May be a basic question: is the same project used as it is for both STM32F302RE and STM32F302R8?

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on February 18, 2016 at 15:06

Ok, but it is a structure containing pointers to other structures, and regions of memory. Something in the chain is touching memory in a way that the processor objects too.

In Faulting the processor provides a host of context information for you to identify exactly what it is objecting too. Understand why it is angry, and work backward from there.

For different processor models make sure the linker script reflects the sizes of the FLASH/SRAM accurately, and the stack/heap placement/size are valid.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
akshayamk
Associate II
Posted on February 25, 2016 at 08:14

Hi Mayla,

I am not using the same project but the CAN codes for both firmware is very similar.

akshayamk
Associate II
Posted on February 25, 2016 at 08:16

Hi Clive,

Thanks a lot for your reply. I have verified and amended my heap and stack sizes/placements and also Flash memory address. However, I am still getting hardfault handler. I noticed that this error appears when trying to disable interrupts in CAN_IER register, in particular. But I am still not able to solve it. Any more suggestions?/

Posted on February 25, 2016 at 22:21

Do you have a Joseph Yiu model Hard Fault handler, he's covered this in his books, here and on other ARM Forums. This can print out data to a terminal, and you can add other code to automate the reporting of your own system state. This can be easier than mining through the debugger, and stack frame data.

This would provide you with some register/fault statistics, examining those and the structures they point to you should be able to determine the nature of the fault.

Based on the data you've reported so far, I'm inclined to think that the handle (and structure behind it) have been overwritten in some fashion. This could be from some errant pointer, memcpy's or background DMA.

You should perhaps sanity check the code being used for the CAN_IER operation, ie make sure the pointer isn't NULL, and points to a valid range in RAM, and then iterate into the structure and check pointers in there. Ideally you want to be able to identify the condition that is going to precipitate the Hard Fault, and catch it before it happens. Once you've done that you  need to work your way back through your code applying this test until you can contain/confine where the damage is occurring.

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