Closed henrygab closed 4 years ago
I mainly use ozone to troubleshoot as well. I don't remembered the last time I deal with hardfault on nrf52. However update everything to latest, don't forget to pull from submodule (tinyusbcore) as well.
Can you reproduce this outside of arduino? I've debugged hard faults with GDB but not Ozone. The system control block has helpful registers. I believe you can end up in hard fault if another fault occurs but it's not handled by something else.
See https://static.docs.arm.com/dui0553/b/DUI0553.pdf section 4-3. The NVIC can be helpful too which is section 4-2.
Hi @tannewt,
Can you help me understand what you mean by "outside of arduino"?
I flash the binary and start debugging using Ozone (w/Segger JLINK EDU).
This same problem has occurred in the past also, with the same steps to repro. (any breakpoint set when restart device == HardFault).
Based on your pointers, I've looked into the registers some, based on a 2019 guide, and the doc you pointed to.
Can you help me understand what you mean by "outside of arduino"?
I was thinking a plain C file built using gcc directly. This is my bias because I don't usually use the Arduino toolchain.
This doesn't sound like an issue with the actual code since the error is so early. Did you try powering the board off and unplugging? I've seen issue before where a reset doesn't reset everything.
@henrygab I got into this issue today as well, ozone must change something. I am not entirely sure, I think it is related to bootloader load etc .. https://forum.segger.com/index.php/Thread/6041-SOLVED-Ozone-Program-enters-inmediately-in-hardfault-handler-after-program-and-s/
One work around is using "attach to running" instead of "download and run" option.
@hathach -- THANK YOU! I had no idea that the bootloader's existing could cause this problem. With that site's help, here is a summary of a solution that works well:
BootloaderBaseAddress
.Open the .jdebug
file in a text editor
Add the following function at the head of the file, ensuring you change the noted line:
void AfterTargetDownloadOrReset(void) {
unsigned int SP;
unsigned int PC;
unsigned int VectorTableAddr;
unsigned int BootloaderBaseAddress = 0xF4000; // <<==== EDIT THIS VALUE TO MATCH YOUR BOOTLOADER
VectorTableAddr = Elf.GetBaseAddr();
if (VectorTableAddr == 0xFFFFFFFF) {
Util.Log("Project file error: failed to get program base");
} else {
SP = Target.ReadU32(BootloaderBaseAddress);
Target.SetReg("SP", SP);
PC = Target.ReadU32(BootloaderBaseAddress + 4);
Target.SetReg("PC", PC);
}
}
Replace the following two functions (which should exist in the file) with the following:
void AfterTargetReset (void) {
AfterTargetDownloadOrReset();
}
void AfterTargetDownload (void) {
AfterTargetDownloadOrReset();
}
Enjoy a stable debugging experience.
great thanks @henrygab for great sum up , ozone certainly changes in recent version probably trying to catch out-of-bound code and make hardfault debugging easier. happy debugging :+1:
I have no idea how to even begin debugging of a HardFault Exception. @hathach ... have you seen this behavior before? do you have any recommendations on how to determine a root cause? Any pointers to tracking down HardFault exception causes would be appreciated.
Describe the bug 100% repro -- having breakpoint enabled causes HardFault Exception at reboot
Set up (mandatory)
To Reproduce Steps to reproduce the behavior:
Debug
-->Start Debugging
-->Download and Reset Program
main()
function ... everything working wonderfullyloop()
(e.g., console commandBreak.SetOnSrc ("Blink.ino:34");
)main()
(e.g., pressF4
or console commandDebug.Reset()
)F5
) ... expect to hit breakpoint in loop(), but HardFault Exception occurs insteadDebug
-->Start Debugging
-->Attach to Running program
Expected Results Breakpoints should work across reboots of the board.
Actual Results Breakpoints cannot be set by debugger ... something about the board initialization (post-
main()
) appears to conflict?Serial Log There is no output ... perhaps the hardfault exception occurs too early?