View previous topic :: View next topic |
Author |
Message |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
Use #INT_ADDRERR with PIC24 to locate code errors |
Posted: Wed Oct 22, 2008 2:40 am |
|
|
Hello,
PIC24 has an address error trap interrupt, that is triggered when accessing nonexisting memory or word data at an odd address. By default, the trap is unhandled, causing a reset with the TRAPR bit set in RCON.
The address error trap is usually indicating a user coding error (e. g. a bad pointer operation) or one of the various PCD bugs still present.
Installing a dummy #INT_ADDRERR avoids the reset on address error, but the code still behaves incorrect. By saving the return address in the trap interrupt, the existence and location of address errors can easily be monitored.
Code: | unsigned int32 trapaddr = 0;
#INT_ADDRERR
void ae_isr(void)
{
#asm
mov w15,w0
sub #36,w0
mov [w0++],w1
mov w1,trapaddr
mov [w0],w1
and #0x7f, w1
mov w1,trapaddr+2
#endasm
} |
The 36 return address offset is empirically based on the default behaviour of PCD V4.081. Apparently, the compiler is always saving all WREGs in interrupt functions, thus the offset should be constant, but may be different with other compiler versions.
Regards,
Frank |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Thu Oct 15, 2009 1:52 am |
|
|
Hey FvM,
I've been using this while debugging the TCP/IP Stack and I'm finding stuff that looks legit causing traps...
Have you seen this? (I can post some code if you like)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Oct 15, 2009 7:10 am |
|
|
Besides the said address error, also stack error and possibly arithmetic error (div zero) is likely to happen.
http://www.ccsinfo.com/forum/viewtopic.php?t=40083
Either accessing nonexisting memory addresses or word accesses to odd addresses can cause an address error trap. Programming errors in user code, particularly with pointers but also still existing PCD bugs are ways to produce them.
I didn't yet use the TCP/IP stack. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Fri Oct 16, 2009 12:32 am |
|
|
I've been halting on some of the errors with my ICD3 and checking trapaddr as well as the interrupt register. And it's one right now has been a stick copying one WREG to another. (weird)
I haven't dug deep enough yet -- I found some other PCD bugs assigning INT8's (duh) -- which I'll report at some point...
But anyway... I can email you the stack if you'd like to see.
PM me your email if you'd like.
I don't know how many peeps have 16bit tcpip working yet... but I'm getting there... _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|