cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 Hard Fault Error

eric5709
Associate II
Posted on March 02, 2016 at 16:40

Hi all,

The issue that I am having is that I having is last night I was programming and found that my code suddenly stopped functioning completely. After running in debug mode I found that the code immediately enters a hard fault. I tried removing and commenting out many lines of code to try to figure out what could have caused this issue. Attached is a picture of what I am seeing in debug mode, I have tried to set break points at many locations but cannot get to any of them.

It appears that this hard fault is occurring during the USB Initialization. The part that confuses me is that I have had the USB transmitting and receiving flawlessly prior to last night. Changes that were made were adding a timer (STM32CubeMX regenerated the code) and I believe that is it. The USB port is just sending the sensor data to the computer so via virtual com port for analyzing. 

Additional Information:

- Source code file WAS generated using STM32CubeMX

- USB port was configured as a CDC in device mode

Thanks for any help!

#stm32
6 REPLIES 6
Posted on March 02, 2016 at 18:33

Ok, but you need to look at the instructions that are faulting, and the registers and memory being referenced. Consider a better Hard Fault Handler (Joseph Yiu) that decomposes the failure. Or options within IAR to do a similar job.

With the Cortex-M0 the thing that catches most people is the alignment of 32-bit accesses. Other than that you need to check for accesses outside usable ranges, you'd want to double check the ranges provided to the linker, and review the .MAP file.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
eric5709
Associate II
Posted on March 02, 2016 at 23:19

I was able to find that it had to do with the osxMotionFX MEMs Fusion library that I am trying to incorporate into my project. When these lines are removed the code works fine, any chance you have experience with this library? I have added the .a library file with several header files. When making a call to this library is when the hard fault occurs. I am referencing the BLUEMICROSYSTEM1.

Posted on March 03, 2016 at 01:08

Sorry, I'm not.

The problem with pulling in a library targeting the Cortex-M4, is that the Cortex-M0 supports a significantly smaller subset of Thumb-II instructions. Illegal instructions, or unaligned memory accesses will cause faults.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
eric5709
Associate II
Posted on March 04, 2016 at 18:21

Yeah I saw that the example code was for the an M4 however the documentation says that its portable across all STM32 devices (correct me if I'm mistaken) and the ST rep had told me the same thing. Either way I think I'm just switching Micros as my school project is time restricted and this will just be quicker.

Thanks!

Posted on March 04, 2016 at 18:31

I think I'll go with the processor's determination about what it will/will not execute. You could examine the fault instructions and be sure, and then push that feedback to your ST Rep.

I don't work for ST in any capacity, and the forum is not heavily populated with ST staff or FAEs, while some might be lurking.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
AvaTar
Lead
Posted on March 04, 2016 at 19:43

>...however the documentation says that its portable across all STM32 devices...

 

This is perhaps meant to be valid for the source code, with conditional compilation. A build for the M3/M4 is certainly not portable to the M0.

>...and the ST rep had told me the same thing.

Maybe on this occasion you learnt something about salesmen.