We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello all,
I'm new to the ARM platform and I'm having a problem discovering why my code is generating a Hard Fault.
My hardware is an mbed platform board with the NXP LPC1768 processor.
The code in question works when compiled using the mbed.org online compiler but creates a Hard Fault when compiled with the LPCXpresso compiler. I know it's probably a compiler switch or preprocessor definition that is wrong somewhere but I have no idea where to begin to look.
So, more detail on what is happening, the following assembly instruction is where the hard fault is generated:
ldr r3, [r7, #4]
If I understand the assembly properly, it is attempting to load a word into register r3 that is located in memory at the address stored in r7 + 4 bytes.
So, just before executing this instruction r7 contains 0x10007568. So it is attempting to load the word from memory location 0x1000756C which contains 0x00000000.
Being new to the architecture, I'm failing to discover why this is generating a hard fault.
Thanks in advance for any help anyone can provide!
Hi,
You're understanding of asm is correct, but a load from zero wouldn't normally generate the fault unless you've set up the MPU.
I'm guessing an uninitialised pointer is being derefeneced. You're getting a hard fault as that's the default, but you need to look at the Usage Fault Status Register (UFSR) to see the actual cause.
Are you writing in C or asm? If C you'd have to share a snippet of code.
Take a look at the following post as this should help give you further info about hard faults and how to track them down.
Sticky Bits » Blog Archive » Developing a Generic Hard Fault handler for ARM Cortex-M3/Cortex-M4
This might also help identifiy the problem.
I would check also the memory map with your compiler. If you're trying to access a memory location out of bounds, the processor will generate a MemFault exception. If MemFault handler is not set, the exception will be automatically 'promoted' to HardFault.
By default memory map for instructions/program (flash), starts at 0x00000000 (or 0x08000000 in some cases). I don't know much about your processor, however the address you're referring to looks a bit ... high.
Just an idea :)