I had an issue that turned out to be a bug in microchip's code:
sprintf(foo_str, "%f", NAN)
would (and will) throw a bus error exception... (bug in their "_fconvert" function) To debug/identify that I modified my exception handler to print out (product was already had an ASCII UART connection to its host) what the exception was, what the violating address was and then it will reset itself. The reset portion was hard to find, it is in one of the many Microchip docs for the PIC32MX. This replaces the Harmony (1.10) generated "_general_exception_handler()", not sure if it's compatible with Harmony 2.x
void _general_exception_handler ( void )
{
char fail_str[96];
/* Mask off Mask of the ExcCode Field from the Cause Register
Refer to the MIPs Software User's manual */
_excep_code = (_CP0_GET_CAUSE() & 0x0000007C) >> 2;
_excep_addr = _CP0_GET_EPC();
_cause_str = cause[_excep_code];
sprintf(fail_str, "ERROR,%s,cause=%d,addr=%x,",
_cause_str, _excep_code, _excep_addr);
//"send_my_string" copies the string to the ring buffer
send_my_string(fail_str);
//"tx_chars_from_ring_buffer" returns # of chars left in the ring buffer
while(tx_chars_from_ring_buffer());
//queue up another set of chars equal to the length of the UART FIFO
sprintf(fail_str, "\r\r\r\r\r\r\r\r\r\r");
send_my_string(fail_str);
while(tx_chars_from_ring_buffer());
#if (__DEBUG)
while (1)
{
SYS_DEBUG_BreakPoint();
}
#endif
/* The following code illustrates a software Reset */
// assume interrupts are disabled
// assume the DMA controller is suspended
// assume the device is locked
/* perform a system unlock sequence */
// starting critical sequence
SYSKEY = 0x00000000; //write invalid key to force lock
SYSKEY = 0xAA996655; //write key1 to SYSKEY
SYSKEY = 0x556699AA; //write key2 to SYSKEY
// OSCCON is now unlocked
/* set SWRST bit to arm reset */
RSWRSTSET = 1;
/* read RSWRST register to trigger reset */
_excep_code = RSWRST;
/* prevent any unwanted code execution until reset occurs*/
while(1);
}
I did have to play with it a bit to ensure that the message got thru the output FIFO before the reset was invoked...