2015-07-31 04:01 PM
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-fault2015-08-04 04:49 AM
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.
2015-08-04 11:58 AM
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.2015-08-04 12:37 PM
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.2015-08-04 12:46 PM
If you think that testing 2 different faults will be enough to test you're handler, it's ok with me.
2015-08-13 03:02 PM
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.