I've recently encountered problems with HardFault_Handler. I'm using ATSAM4S connected via JTAG. I've two boards based on same ATSAM4S model chip with same package, there is little differences in this two board schematics; just some changes in some pin connection(like LEDs) and a MCU position on the board.
The first one board, that I'll call board_1, have no problems, code runs perfectly without any errors or fault handlers triggered. The board_2, with exactly the same code, with just GPIO pinout adapted, trigger HardFault_Handler very frequently at different code points. I've checked that HardFault_Handler not depend on which point of code, some times it's called by a I2C istruction, some times by a variable set or a function call. Also I've found that uploading a very simple code on board_2, like a LED blink, and running it whitout debugger connected, code runs with problems; sometimes at random MCU reboots, sometimes freeze and after some times recovers or sometimes freeze without recover.
I can't find out if the problem can be:
- PCB or schematics board fault;
- MCU is flawed;
- MCU was damaged during reflow;
Since MCU seems to programs without problems, and runs code(with problems), what it can be? Any supposition are appreciated and I'll check. I prefer to try to solve this problem(or be sure that is a MCU fault) before assembly another board.