• AVR Freaks

Hot!Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML

Page: < 12 Showing page 2 of 2
Author
DuaneH
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2009/10/15 11:49:22
  • Location: Sandy, UT
  • Status: offline
Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/15 15:26:32 (permalink)
0
Another idea you might try: Whenever I encounter an issue like this, it almost always comes from an overrun of some sort - a variable being too large, an string longer than it's allocation, code that is re-entrant, ....  If that is the case, then you should be able to stop the program at 1 minute (before it crashes, but long enough to see if something is growing) and examine the stack pointer (WREG15) and compare it with its initial value.  Then look at any variables that can grow (strings, especially, since you are outputting to a UART), to see if you have the possibility of running past the end of one.  If you find a string that is suspicious, increase its allocation size and see if the problem changes.

duaneh
#21
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3333
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/15 15:42:40 (permalink)
0
Cryptic, we have not seen any code.
post edited by Gort2015 - 2019/10/15 15:49:01

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#22
user2x
Super Member
  • Total Posts : 352
  • Reward points : 0
  • Joined: 2011/02/10 20:43:36
  • Location: 0
  • Status: offline
Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/15 15:49:29 (permalink)
0
Gort2015
Cryptic, we have not seen any code.



Which code would you like to see? Here are the exception handlers:

/******************************************************************************/

inline void INT_Dumpregs(void)
{
INT_PutString("\r\nCORCON 0x");
INT_PutHexShort(CORCON);
INT_PutString("\r\nINTCON1 0x");
INT_PutHexShort(INTCON1);
INT_PutString("\r\nINTCON2 0x");
INT_PutHexShort(INTCON2);
INT_PutString("\r\nINTCON3 0x");
INT_PutString("\r\nINTTREG 0x");
}
/******************************************************************************/
inline void INT_InitUart(void)
{
IEC1bits.U2TXIE = 0;
U2MODE = 0x00;
U2MODEbits.BRGH = 1; //38400 Baud
U2BRG = 12; //0.16% error
IFS1bits.U2TXIF = 0;
U2MODEbits.UARTEN = 1;
U2STAbits.UTXEN = 1; //transmit pin
}

/******************************************************************************/
void __attribute__((interrupt, no_auto_psv))_OscillatorFail(void)
{
volatile uint16_t here;
INT_InitUart();
INT_PutString("\r\nTRAP:OSCFAIL");
INT_Dumpregs();
INTCON1bits.OSCFAIL=0;
while(1)
here++;
}

void __attribute__((interrupt, no_auto_psv))_AddressError(void)
{
volatile uint16_t here;
INT_InitUart();
INT_PutString("\r\nTRAP:ADDRESS ERROR");
INT_Dumpregs();
INTCON1bits.ADDRERR=0;
while(1)
here++;
}
void __attribute__((interrupt, no_auto_psv))_StackError(void)
{
volatile uint16_t here;
INT_InitUart();
INT_PutString("\r\nTRAP:STACK ERROR");
INT_Dumpregs();
INTCON1bits.STKERR=0;
while(1)
here++;
}
void __attribute__((interrupt, no_auto_psv))_MathError(void)
{
volatile uint16_t here;
INT_InitUart();
INT_PutString("\r\nTRAP:MATH ERROR");
INT_Dumpregs();
INTCON1bits.MATHERR=0;
while(1)
here++;
}
void __attribute__((interrupt(auto_psv))) _DefaultInterrupt(void)
{
volatile uint16_t here;
INT_InitUart();
INT_PutString("\r\nDEFAULt INTERRUPT");
INT_Dumpregs();
while(1)
here++;
}
 

 
 
 
 
#23
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3333
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/15 16:59:12 (permalink)
0
user2x
I am just wondering...
 
Is it possible that the TRAPR reset occurs before I can get the registers dumped in the Trap Handlers ?
 
If that is happening, then how can I find out what happened? 
 

Did you try the default int.?
You may have an interrupt enabled but you have no int. handler.
 
Inside the irq vector table, unused ints. will be set to default.
Default just warm resets.
 
comment out the dump routine.
 
 
 

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#24
dan1138
Super Member
  • Total Posts : 3285
  • Reward points : 0
  • Joined: 2007/02/21 23:04:16
  • Location: 0
  • Status: offline
Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/15 17:29:29 (permalink)
5 (1)
Is it possible that your code is switching to the alternate interrupt vector table?
 
Under the worst case debug situation you may need to declare an individual interrupt handler for every possible interrupt source available.
 
Use this code for each instance:
void __attribute__((interrupt, no_auto_psv))/* replace this comment with name of interrupt */(void) 
{
    __asm__ volatile (".pword 0xDA4000"); /* undocumented opcode to invoke the ICD if it is connected */
    __asm__ volatile ("nop")
}

 
You will need to populate BOTH the primary and alternate interrupt vector tables. This means two of these handlers for each interrupt source.
 
You have one of those "unfindable" kinds of bugs.
 
Another note is that your stack error trap handler will fail if the stack limit is too near the end of the stack space.
 
Please consider re-initializing the stack pointer and stack limit before making function calls from a stack fault trap handler.
#25
user2x
Super Member
  • Total Posts : 352
  • Reward points : 0
  • Joined: 2011/02/10 20:43:36
  • Location: 0
  • Status: offline
Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/16 13:25:17 (permalink)
0
4 days into it and I think I found the I found the problem. 
 
Hidden in this code, there is functionality to write some parameters to Flash.
The Flash in this chip has a different size and config to the original chip and so it appears that a part of the code or constants gets erased when the parameters are erased / written.
 
Why does that result in a TRAPR reset though?
 
A cunning problem!
 
 
#26
NKurzman
A Guy on the Net
  • Total Posts : 18034
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/16 14:54:38 (permalink)
0
Why does erasing code cause weird things to happen?  I guess it would depend on what you erased.
#27
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3333
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/16 15:15:43 (permalink)
5 (1)
Overwrite of a pointer to $FFFF. CPU executes this as NOPR.
 
post edited by Gort2015 - 2019/10/16 15:17:41

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#28
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5