SAMD21 Hard Fault Exception Handling

basically miscellaneous, if it doesn't fit another sub-forum enter it here, we might even promote it to its own sub-forum
Post Reply
TodWulff
Posts: 58
Joined: Fri Oct 19, 2012 4:03 am
Location: The Mitten State - Shores of Lake Huron

SAMD21 Hard Fault Exception Handling

Post by TodWulff »

It seems that the AB FW for the SAMD21 might not handle Hard Faults as gracefully as has been observed on LPC wares.

I've tested it using the attached SAMD21_FaultRecovery_POC.bas on three SAMD21 devices - the uChip, the Prontoneer, and the Robotdyn. Using that file (with the standard SAMD21 library), when executed and option 1 selected, the code intentionally generates a Hard Fault due to a non-word aligned access. The device appears to hang hard and is a bit tough to get back when a user app does something like non-aligned access when it automatically runs. During testing they all present express the same behavior by presenting to hang, and then, when stop is clicked to try to get the device back into a responsive state, the USB serial port gives up the ghost and borks hard (at least on this Win10 x64 box).

I've identified and implemented what I perceive to be a viable work around, by adding an exception handler in the SAMD21.bas lib file. During preprocessing, this prepends the user app with the ISR routine and a call to the NVIC peripheral to instantiate said ISR as the Hard Fault exception handler, then continues on with the user app's code. I've attached a modified SAMD21.bas file here as well.

Please feel free to make edits as needed. One opportunity for improvement would be to have some ASM in the ISR to get the PC at the time of exception (it's on the stack somewhere, according to the ARM docs) and to display that, like what is done with HFEs on the LPC controllers.

-t
Attachments
SAMD21.bas
(48.83 KiB) Downloaded 12 times
SAMD21_FaultRecovery_POC.bas
(1.09 KiB) Downloaded 12 times



Post Reply