• AVR Freaks

PIC32 exception handling

Senior Member
  • Total Posts : 122
  • Reward points : 0
  • Joined: 2008/08/12 13:04:59
  • Location: 0
  • Status: offline
2011/06/02 12:17:40 (permalink)

PIC32 exception handling

Getting a lot better with PIC32, but I have a real basic question. I am using FreeRTOS which has a general exception handler routine .  If I set a breakpoint in that general exception handler and it breaks there, how do I find out how it got there?   The call stack does not help. Makes sense, since the program just kinda vectors there......   Is there a method that I am not aware of other than stepping and "discovering"?
Trying to debug some USB stuff and things go real quick and single stepping changes the behavior of USB! :)

2 Replies Related Threads

    Senior Member
    • Total Posts : 169
    • Reward points : 0
    • Joined: 2010/02/01 09:11:45
    • Location: 0
    • Status: offline
    Re:PIC32 exception handling 2011/06/02 13:26:02 (permalink)
    4 (1)
    There's registers in Coprocessor 0 which can tell you a type of reason why the exception was triggered, and i think the EPC register in the Coprocessor holds the instruction that caused the exception, if not the EPC it's another register in Coprocessor 0.  Either way, just read up on Coprocessor 0 and you should find some answers.
    Super Member
    • Total Posts : 494
    • Reward points : 0
    • Joined: 2003/11/07 12:36:50
    • Status: offline
    Re:PIC32 exception handling 2011/06/09 08:25:37 (permalink)
    5 (2)
    Here's my general exception handler, adapted from code posted here by others.

    static enum {
         EXCEP_IRQ = 0,            // interrupt
         EXCEP_AdEL = 4,            // address error exception (load or ifetch)
         EXCEP_AdES,                // address error exception (store)
         EXCEP_IBE,                // bus error (ifetch)
         EXCEP_DBE,                // bus error (load/store)
         EXCEP_Sys,                // syscall
         EXCEP_Bp,                // breakpoint
         EXCEP_RI,                // reserved instruction
         EXCEP_CpU,                // coprocessor unusable
         EXCEP_Overflow,            // arithmetic overflow
         EXCEP_Trap,                // trap (possible divide by zero)
         EXCEP_IS1 = 16,            // implementation specfic 1
         EXCEP_CEU,                // CorExtend Unuseable
         EXCEP_C2E                // coprocessor 2
     } _excep_code;
     static unsigned int _epc_code;
     static unsigned int _excep_addr;
     void _general_exception_handler(void)
         asm volatile("mfc0 %0,$13" : "=r" (_excep_code));
         asm volatile("mfc0 %0,$14" : "=r" (_excep_addr));
         _excep_code = (_excep_code & 0x0000007C) >> 2;
         Uart1TxStringPolled("\r\nGeneral Exception ");
           case EXCEP_IRQ: Uart1TxStringPolled ("interrupt");break;
           case EXCEP_AdEL: Uart1TxStringPolled ("address error exception (load or ifetch)");break;
           case EXCEP_AdES: Uart1TxStringPolled ("address error exception (store)");break;
           case EXCEP_IBE: Uart1TxStringPolled ("bus error (ifetch)");break;
           case EXCEP_DBE: Uart1TxStringPolled ("bus error (load/store)");break;
           case EXCEP_Sys: Uart1TxStringPolled ("syscall");break;
           case EXCEP_Bp: Uart1TxStringPolled ("breakpoint");break;
           case EXCEP_RI: Uart1TxStringPolled ("reserved instruction");break;
           case EXCEP_CpU: Uart1TxStringPolled ("coprocessor unusable");break;
           case EXCEP_Overflow: Uart1TxStringPolled ("arithmetic overflow");break;
           case EXCEP_Trap: Uart1TxStringPolled ("trap (possible divide by zero)");break;
           case EXCEP_IS1: Uart1TxStringPolled ("implementation specfic 1");break;
           case EXCEP_CEU: Uart1TxStringPolled ("CorExtend Unuseable");break;
           case EXCEP_C2E: Uart1TxStringPolled ("coprocessor 2");break;
         Uart1TxStringPolled(" at 0x");
         while (1) {
             // Examine _excep_code to identify the type of exception
             // Examine _excep_addr to find the address that caused the exception


    Jump to:
    © 2019 APG vNext Commercial Version 4.5