cancel
Showing results for 
Search instead for 
Did you mean: 

Create a fault on purpose

harry_rostovtsev
Associate II
Posted on August 01, 2015 at 01:01

I would like to test all my hard fault and friends (MemManage, BusFault, UsageFault, etc) fault handlers.  Essentially, I'd like to log their occurence to an I2C EEPROM.  I have all the HardFault handling working (at least it prints out registers when I saw it crash early in dev) but I'd like to actually log them.  That part is easy (I hope). 

What would really want to do is have some tests that actually cause these faults.  I'm pretty sure I can cause a Hard Fault pretty easily (divide by zero or something equally dumb) but how do you cause the rest of the faults to occur on purpose?  Any advice?

I'm on STM32F4 using GCC 4.6.

#m4 #stm32 #hardfault #fpu-memmanage-hard-fault
5 REPLIES 5
stm32forum
Associate II
Posted on August 04, 2015 at 13:49

There are so many reasons for hardfaults, I suggest that you read chapter 12.2 of ''The definitive guide to Arm Cortex M4'' by Joseph Yiu.

Posted on August 04, 2015 at 20:58

I'm not sure that was the question.

For MemManage I'd expect you'd have to set up the protection unit (MPU) first, and then violate the settings configured.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
harry_rostovtsev
Associate II
Posted on August 04, 2015 at 21:37

I don't need to recreate all possible ways of causing a hard fault.  I just want to make sure I have a good test for my already existing hard fault handler.  I also want to test the other handlers as well.  So I just need to be able to cause those faults on demand/purpose.

Clive's suggestion of setting up the MPU and violating it is basically what I'm looking for.

stm32forum
Associate II
Posted on August 04, 2015 at 21:46

If you think that testing 2 different faults will be enough to test you're handler, it's ok with me.

harry_rostovtsev
Associate II
Posted on August 14, 2015 at 00:02

I'm not seeing a problem with testing a hard fault handler that way.  The handler works. I know because I've had hard faults for various reasons and it always jumps to the routine that successfully prints out the registers.  What I want to do now is to add the ability to write some of that info into my EEPROM.  Hence, I need a way to force a hard fault, memfault, and all their friends so I can test it.  That's all.  I don't see how different causes of hard fault are going to affect what I'm trying to do.  The only thing it will change is the contents of the registers, which is fine.