Helpful ReplyLockedException Error - How to find the cause

Page: 12 > Showing page 1 of 2
Author
Dr. Whom
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2012/12/28 13:33:02
  • Location: 0
  • Status: offline
2013/01/29 09:04:03 (permalink)
0

Exception Error - How to find the cause

Hello,
 
I am new to the PIC32 and keep getting exception errors
 
I am using the general exception handler
 
The code returned is
 
address = 0xA0000204,   _excep_code = 0x00000018 "Enumeration ?"
 
 
address = 0xA000020C,    _excep_addr = 0x00100C03
 
Sometimes the _excep_addr is 0x00000000 or 0x0001BBE4
 
 
Any help would be appreciated
#1
Dr. Whom
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2012/12/28 13:33:02
  • Location: 0
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/29 09:43:19 (permalink)
0
I modified the Exception Handler to :
 _excep_code=( _CP0_GET_CAUSE() & 0x0000007C ) >> 2;
 
And now I get an exception code of IBE (Bus Error)   Bus Error Exception Instruction Fetch
 
_excep_Addr is 0x0001BBE4
 
I only seem to get this error with I2C turned on for now
 
Are these BUS errors almost always a fault in the code (like addressing element of an array with -1 )?
 
 
 
#2
DarioG
leaving this planet
  • Total Posts : 53043
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: porcodioland
  • Status: online
Re:Exception Error - How to find the cause 2013/01/29 10:46:50 (permalink)
0
Hmm, I'd say "yes". Bad pointers causing unwanted bus accesses

Dario Greggio
--
how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

#3
schneiderj
Super Member
  • Total Posts : 497
  • Reward points : 0
  • Joined: 2008/01/19 07:46:49
  • Location: France, close to Paris
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/29 11:11:07 (permalink)
0
Dr. Whom
Are these BUS errors almost always a fault in the code (like addressing element of an array with -1 )?

Hello,
 
as Dario said... most of the time that the cause. You can have a look on my message : http://www.microchip.com/forums/m701816.aspx
I was thinking that I had a good control of the pointer and avoiding it to read/write to far : but that was wrong !
 
Jean-Marie
#4
Dr. Whom
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2012/12/28 13:33:02
  • Location: 0
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/29 11:17:17 (permalink)
0
Some more info
 
My Stack pointer is at 0xA001FF10 and my part has 0x1FFFF of RAM
Almost all of my RAM (I use 0x744) is full of Instructions which I assume are from the Stack. Does the stack really grow that big on the PIC32?
#5
andersm
Super Member
  • Total Posts : 2225
  • Reward points : 0
  • Joined: 2012/10/07 14:57:44
  • Location: 0
  • Status: online
Re:Exception Error - How to find the cause 2013/01/29 11:37:27 (permalink)
5 (1)
On the PIC32 the stack grows downwards. Stack space is consumed by local variables and registers saved across function calls and interrupt handlers. Code is not placed on the stack.
 
Check all your pointers and array handling, that's the source for the vast majority of errors.
#6
Dr. Whom
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2012/12/28 13:33:02
  • Location: 0
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/29 13:13:39 (permalink)
5 (1)
I am not using any arrays or pointers so not sure where the BUS error is being generated
 
I am using two switch statements in my I2C ISR and maybe this is causing my bus error. I will try to use function pointers.
 
 
#7
andersm
Super Member
  • Total Posts : 2225
  • Reward points : 0
  • Joined: 2012/10/07 14:57:44
  • Location: 0
  • Status: online
Re:Exception Error - How to find the cause 2013/01/29 16:04:10 (permalink)
5 (1)
Dr. WhomI am using two switch statements in my I2C ISR and maybe this is causing my bus error.

Why do you think that?
 
I will try to use function pointers.

Not likely to reduce the number of bugs. Why not just post the code? Create a reduced testcase if you don't want to post your whole project.
#8
friesen
Super Member
  • Total Posts : 1722
  • Reward points : 0
  • Joined: 2008/05/08 05:23:35
  • Location: Indiana, USA
  • Status: online
Re:Exception Error - How to find the cause 2013/01/30 05:59:45 (permalink)
0
Use the dissassembly listing to find your code corresponding to the address.

Erik Friesen
#9
Dr. Whom
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2012/12/28 13:33:02
  • Location: 0
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/30 06:21:06 (permalink)
0
The Exception Address is 0 which I cannot find in the assembly as it would be the first address in RAM (although I think it displays the virtual address)
 
Here is my code below
 
void vWriteI2CData( UINT8 u8SlaveAddress, UINT8 u8ValueOne , UINT8 u8ValueTwo )
{

    UINT8 u8Working = 0;

    //If there is not a Task already processing
    if( u8CurrentStep == eWRITE_BUS_AVAILABLE)
    {
        // Clear the Receive Buffer
        u8TransmitBuffer[0] = u8ValueOne;
        u8TransmitBuffer[1] = u8ValueTwo;

        //Setup the Task and Step
        u8CurrentTask = I2C_WRITE;
        u8CurrentStep = eSEND_WRITE_CODE;

        u8Working = u8SlaveAddress << 1;
        u8Working = u8Working | I2C_WRITE;
        //Format the Slave Address
        //I2C_FORMAT_7_BIT_ADDRESS( uSlaveAddress, u8SlaveAddress, I2C_WRITE );

        //Store the modified Address for sending
        u8OperationCode = u8Working; //uSlaveAddress.byte;

        //while( !I2CBusIsIdle(LOOP4_DAC_I2C_BUS) );
        IdleI2C5();
        I2CStart(LOOP4_DAC_I2C_BUS);
        //StartTransfer( FALSE );
    }
}
 
 
void __ISR(_I2C_5_VECTOR ,ipl6)I2C5_Loop4_Interrupt()
{

        //Handle BUS collision
    if( I2C5STATbits.BCL )
    {
        // Open and Enable I2C for Loop 4 for 100Khz SCK
        //OpenI2C5( ( I2C_OFF |  I2C_SLW_DIS  ) , 0xC2) ;
        // Enable the I2C bus
        I2C5CONbits.ON = 0;

        u8CurrentTask = eI2C_READ;
        u8CurrentStep = eREAD_BUS_AVAILABLE;

        // Open and Enable I2C for Loop 4 for 100Khz SCK
        //OpenI2C5( ( I2C_ON |  I2C_SLW_DIS  ) , 0xC2) ;
        //I2CEnable(LOOP4_DAC_I2C_BUS, TRUE);
        I2C5CONbits.ON = 1;
    }

    //boI2CStatusChange = TRUE;

    //Status = I2CGetStatus(LOOP4_DAC_I2C_BUS);
    if ( u8CurrentTask == eI2C_WRITE )
    {
        //if( u8CurrentStep < ( sizeof(WriteFunctions) / sizeof(*WriteFunctions) ) )
        //{
        //    WriteFunctions[u8CurrentStep]();
        //}

        switch( u8CurrentStep )
        {
            case eSEND_WRITE_CODE: //case 0
            {
                // If Start not completed
                if( !I2C5STATbits.S )
                {
                    u8CurrentTask = eI2C_WRITE;
                    u8CurrentStep = eWRITE_BUS_AVAILABLE;
                    break;
                }
                else
                {
                    u8CurrentStep++;
                    //If transmitter is ready to accept more data
                    if( !I2C5STATbits.TBF ) // I2CTransmitterIsReady(LOOP4_DAC_I2C_BUS) )
                    {
                        //I2CSendByte(LOOP4_DAC_I2C_BUS, u8OperationCode );
                        I2C5TRN = u8OperationCode;
                    }
                    else
                    {
                        u8CurrentTask = eI2C_WRITE;
                        u8CurrentStep = eWRITE_BUS_AVAILABLE;
                        break;
                    }

                }

                break;

            }
            case eCHECK_ACK_SEND_DATA1:
            {
                u8CurrentStep++;
                //if( !I2CTransmissionHasCompleted(LOOP4_DAC_I2C_BUS) )
                if( I2C5STATbits.TRSTAT )
                {
                        u8CurrentTask = eI2C_WRITE;
                        u8CurrentStep = eWRITE_BUS_AVAILABLE;
                        break;
                }

                if( I2C5STATbits.ACKSTAT ) //!I2CByteWasAcknowledged(LOOP4_DAC_I2C_BUS ))
                {
                        u8CurrentTask = eI2C_WRITE;
                        u8CurrentStep = eWRITE_BUS_AVAILABLE;
                        break;

                }

                if( !I2C5STATbits.TBF )  //if( I2CTransmitterIsReady(LOOP4_DAC_I2C_BUS) )
                {
                    //I2CSendByte(LOOP4_DAC_I2C_BUS, u8TransmitBuffer[0] );
                    I2C5TRN = u8TransmitBuffer[0];
                }
                else
                {
                        u8CurrentTask = eI2C_WRITE;
                        u8CurrentStep = eWRITE_BUS_AVAILABLE;
                        break;
                }
                break;

            }

            case eCHECK_ACK_SEND_DATA2:
            {
                u8CurrentStep++;
                //if( !I2CTransmissionHasCompleted(LOOP4_DAC_I2C_BUS) )
                if( I2C5STATbits.TRSTAT )
                {
                        u8CurrentTask = eI2C_WRITE;
                        u8CurrentStep = eWRITE_BUS_AVAILABLE;
                        break;
                }

                //if( !I2CByteWasAcknowledged(LOOP4_DAC_I2C_BUS ))
                if( I2C5STATbits.ACKSTAT )
                {
                        u8CurrentTask = eI2C_WRITE;
                        u8CurrentStep = eWRITE_BUS_AVAILABLE;
                        break;

                }

                if( !I2C5STATbits.TBF ) //if( I2CTransmitterIsReady(LOOP4_DAC_I2C_BUS) )
                {
                    //I2CSendByte(LOOP4_DAC_I2C_BUS, u8TransmitBuffer[1] );
                    I2C5TRN = u8TransmitBuffer[1];
                }
                else
                {
                        u8CurrentTask = eI2C_WRITE;
                        u8CurrentStep = eWRITE_BUS_AVAILABLE;
                        break;
                }
                break;

            }
             case eCHECK_ACK_SEND_STOP:
             {
                    u8CurrentStep++;
                    //if( !I2CTransmissionHasCompleted(LOOP4_DAC_I2C_BUS) )
                    if( I2C5STATbits.TRSTAT )
                    {
                            u8CurrentTask = eI2C_WRITE;
                            u8CurrentStep = eWRITE_BUS_AVAILABLE;
                            break;
                    }

                    //if( !I2CByteWasAcknowledged(LOOP4_DAC_I2C_BUS ))
                    if( I2C5STATbits.ACKSTAT )
                    {
                            u8CurrentTask = eI2C_WRITE;
                            u8CurrentStep = eWRITE_BUS_AVAILABLE;
                            break;

                    }
                    // Send the Stop signal
                    //IdleI2C5();
                    I2CStop(LOOP4_DAC_I2C_BUS);
                    //while( !I2CBusIsIdle(LOOP4_DAC_I2C_BUS) );
                    //I2C5CONSET = _I2CCON_PEN_MASK;
                    break;
                 }
             case eEND_WRITE:
             default:
             {
                u8CurrentTask = eI2C_WRITE;
                u8CurrentStep = eWRITE_BUS_AVAILABLE;
                break;
             }

        }
        
    }
    else
    {
        //READ TWO BYTES
        switch( u8CurrentStep )
        {
            case eSEND_READ_CODE: //case 0
            {
                // If Start not completed
                if( !I2C5STATbits.S )
                {
                    u8CurrentTask = eI2C_READ;
                    u8CurrentStep = eREAD_BUS_AVAILABLE;
                    break;
                }
                else
                {
                    u8CurrentStep++;
                    if( I2CTransmitterIsReady(LOOP4_DAC_I2C_BUS) )
                    {
                        I2CSendByte(LOOP4_DAC_I2C_BUS, u8OperationCode );

                    }
                    else
                    {
                        u8CurrentTask = eI2C_READ;
                        u8CurrentStep = eREAD_BUS_AVAILABLE;
                        break;
                    }

                }

                break;

            }
            // Send Write was sent -> Check ACK
            case eCHECK_ACK_ENABLE_RECEPTION: // case 1
            {
                u8CurrentStep++;
                if( !I2CTransmissionHasCompleted(LOOP4_DAC_I2C_BUS) )
                {
                        u8CurrentTask = eI2C_READ;
                        u8CurrentStep = eREAD_BUS_AVAILABLE;
                        break;
                }

                if( !I2CByteWasAcknowledged(LOOP4_DAC_I2C_BUS ))
                {
                        u8CurrentTask = eI2C_READ;
                        u8CurrentStep = eREAD_BUS_AVAILABLE;
                        break;

                }
                //Enable Receive
                I2C5CONbits.RCEN = 1;
                break;
                //No break...Go immediately to next case
            }
            // ACK CHECKED -> Read and Send ACK
            case eREAD_AND_SEND_ACK: // case 2
            {
                u8CurrentStep++;
                if( I2C5STATbits.RBF ) // I2CReceivedDataIsAvailable( LOOP4_DAC_I2C_BUS ) )
                {
                    u8ReceiveBuffer[u8BufferCount] = I2C5RCV;
                    I2CAcknowledgeByte(LOOP4_DAC_I2C_BUS, TRUE);
                    u8BufferCount++;
                }
                else
                {
                    u8CurrentTask = eI2C_READ;
                    u8CurrentStep = eREAD_BUS_AVAILABLE;
                    break;

                }

                break;
            }
            case eENABLE_RECEPTION:
            {
                u8CurrentStep++;
                if( !I2C5CONbits.ACKEN  )
                {
                    //Enable Receive
                    I2C5CONbits.RCEN = 1;
                }
                else
                {
                    u8CurrentTask = eI2C_READ;
                    u8CurrentStep = eREAD_BUS_AVAILABLE;
                    break;

                }

            }
            case eREAD_AND_SEND_NACK: //case 3
            {
                u8CurrentStep++;
                if( I2C5STATbits.RBF ) // I2CReceivedDataIsAvailable( LOOP4_DAC_I2C_BUS ) )
                {
                    u8ReceiveBuffer[u8BufferCount] = I2C5RCV;
                    I2CAcknowledgeByte(LOOP4_DAC_I2C_BUS, FALSE);
                    u8BufferCount++;
                }
                else
                {
                    u8CurrentTask = eI2C_READ;
                    u8CurrentStep = eREAD_BUS_AVAILABLE;
                    break;

                }
                break;
            }
            case eSEND_STOP:
            {
                u8CurrentStep++;
                // Send the Stop signal
                I2CStop(LOOP4_DAC_I2C_BUS);
                break;
            }
            case eEND_READ:
            default:
            {
                u8CurrentTask = eI2C_READ;
                u8CurrentStep = eREAD_BUS_AVAILABLE;
                break;
            }
        }
    }


    mI2C5ClearAllIntFlags();


}
 
#10
Dr. Whom
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2012/12/28 13:33:02
  • Location: 0
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/30 06:22:46 (permalink)
0
Here is my init
 
    //Open and Enable I2C for Loop 4 for 100Khz SCK
    OpenI2C5( ( I2C_ON |  I2C_SLW_DIS   ) , 0xC2) ;




    //
    mI2C5ClearAllIntFlags();
    mI2C5SetIntPriority(6);
    mI2C5SetIntEnable(0x05);

    u8CurrentTask = I2C_READ;
    u8CurrentStep = eREAD_BUS_AVAILABLE;
#11
friesen
Super Member
  • Total Posts : 1722
  • Reward points : 0
  • Joined: 2008/05/08 05:23:35
  • Location: Indiana, USA
  • Status: online
Re:Exception Error - How to find the cause 2013/01/30 06:49:19 (permalink)
0
That makes it a little harder, likely you could have an unitialized function pointer somewhere, which defaults to 0 probably.  In these cases you have to single step, or put breakpoints at your functions until you know which function it is, then single step to find.

Erik Friesen
#12
Dr. Whom
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2012/12/28 13:33:02
  • Location: 0
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/30 07:36:01 (permalink)
0
Thanks for the advice
 
I am not using any function pointers in my program
 
Sometime when I do get an Address in the exception it is for an Adel Address Error Exception (load or fetch)
 
It is always in the return (closing bracket)
 
Disassembly of the return from function
! }
0x9D0020F8: ADDU SP, S8, ZERO
-->>>> 0x9D0020FC: LW S8, 4(SP)
0x9D002100: ADDIU SP, SP, 8
0x9D002104: JR RA
0x9D002108: NOP
 
or
 
EXCEP_DBE
Exception address 0x9D002230
 
!void vI2Ctest( void )
!{
0x9D002208: ADDIU SP, SP, -24
0x9D00220C: SW RA, 20(SP)
0x9D002210: SW S8, 16(SP)
0x9D002214: ADDU S8, SP, ZERO
!    //vReadI2CData( CurrentPulse_DACAddress );
!    vWriteI2CData( CurrentPulse_DACAddress, 0x0A, 0x55  );
0x9D002218: ADDIU A0, ZERO, 14
0x9D00221C: ADDIU A1, ZERO, 10
0x9D002220: ADDIU A2, ZERO, 85
0x9D002224: JAL 0x9D002188
0x9D002228: NOP
!    return;
!}
0x9D00222C: ADDU SP, S8, ZERO
0x9D002230: LW RA, 20(SP)
0x9D002234: LW S8, 16(SP)
0x9D002238: ADDIU SP, SP, 24
0x9D00223C: JR RA
0x9D002240: NOP
 
I added the return just in case that was the problem
 
 
#13
friesen
Super Member
  • Total Posts : 1722
  • Reward points : 0
  • Joined: 2008/05/08 05:23:35
  • Location: Indiana, USA
  • Status: online
Re:Exception Error - How to find the cause 2013/01/30 07:46:02 (permalink)
0
What are the rest of the interrupts doing?  Have you auto psv'd, etc?

Erik Friesen
#14
rpg7
Super Member
  • Total Posts : 1334
  • Reward points : 0
  • Joined: 2003/11/07 12:47:35
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/30 07:46:55 (permalink) ☄ Helpful
0
Dr. Whom
The Exception Address is 0 which I cannot find in the assembly as it would be the first address in RAM (although I think it displays the virtual address)

 
Are you looking at EPC ?
 
2.12.32 ErrorEPC (CP0 Register 30, Select 0)The ErrorEPC register is a read/write register, similar to the EPC register, except that ErrorEPCis used on error exceptions. All bits of the ErrorEPC register are significant and must be writable.It is also used to store the program counter on Reset, Soft Reset, and non-maskable interrupt(NMI) exceptions 
#15
Dr. Whom
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2012/12/28 13:33:02
  • Location: 0
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/30 08:12:16 (permalink)
0
How do you set auto_psv or no_auto_psv?
 
I use
void __ISR(_I2C_5_VECTOR ,ipl6)I2C5_Loop4_Interrupt()
to declare my ISR function
 
#16
Dr. Whom
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2012/12/28 13:33:02
  • Location: 0
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/30 08:20:44 (permalink)
0
My ErrorEPC is 0xBFC024E0
 
This is an address in the Boot Flash
 
I have not modified the existing bootflash to my knowledge
 
So this means I am getting a BUS error inside the BOOTFLASH?
#17
friesen
Super Member
  • Total Posts : 1722
  • Reward points : 0
  • Joined: 2008/05/08 05:23:35
  • Location: Indiana, USA
  • Status: online
Re:Exception Error - How to find the cause 2013/01/30 08:32:05 (permalink)
0
I think it defaults to auto, so you should be ok, just wondered if you have any that were non auto, where w regs are getting corrupted from another isr.  If thats the case, your exception address will be meaningless, I think.

Erik Friesen
#18
Dr. Whom
Starting Member
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2012/12/28 13:33:02
  • Location: 0
  • Status: offline
Re:Exception Error - How to find the cause 2013/01/30 08:39:28 (permalink)
0
Is it normal for my entire RAM to be filled with opcodes (like my stack just went never ending ) and then when I try to debug again that some variable read was overwritten by an opcode and the CPU does the instruction instead of reading the variable which causes my exception
 
Even after I have initialized my RAM to all (0xDEADBEEF), it has since filled up with opcodes like from the stack. Total size of RAM is
 
The Disassembly is showing opcode
For example I get EPCError 0xA0001138 and it shows up in my execution code with opcode 8DAC0000 or LW T4, 0(T5) unless these are the instructions that are used to get the data
#19
andersm
Super Member
  • Total Posts : 2225
  • Reward points : 0
  • Joined: 2012/10/07 14:57:44
  • Location: 0
  • Status: online
Re:Exception Error - How to find the cause 2013/01/30 09:04:27 (permalink) ☄ Helpful
0
Dr. WhomI am not using any arrays or pointers so not sure where the BUS error is being generated

This is an array access:
u8ReceiveBuffer[u8BufferCount] = I2C5RCV;

The index is only ever increased, you never check to see if the end of the buffer is reached.
 
Is it normal for my entire RAM to be filled with opcodes

It's not.
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2017 APG vNext Commercial Version 4.5