Content originally posted in LPCWare by Pacman on Tue Sep 09 20:53:39 MST 2014
Did you find out what caused this ?
The difference is most likely that the code was optimized, so that none of the assignments you made were actually in the final binary, since they were unused variables.
Try building the code again.
Questions:
1: Which compiler do you use, GCC ?
2: Try turning optimizing off: -O0
3: Try disassembling your code. For instance if using a GNU toolchain: objdump -D file.elf
4: Try putting 'volatile" in front of all your local variables as well (yes, you can do that, and it will work - but it's only a good idea to do when making tests).
5: If using OpenOCD, you can halt the processor when it reaches the HardFault handler, then you can see the old value of PC and LR; they will point to the return-address, so you can disassemble using 'arm disassemble <address> <length>' and see where it failed.
6: Did you build your libraries for the Cortex-M4 with soft floating point support ? -if not, the HardFault is probably on a 32-bit ARM instruction, which was generated in the hope that the microcontroller would be able to run it. ;)