• AVR Freaks

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

Page: 12 > Showing page 1 of 2
Author
user2x
Super Member
  • Total Posts : 317
  • Reward points : 0
  • Joined: 2011/02/10 20:43:36
  • Location: 0
  • Status: offline
2019/10/14 14:10:01 (permalink)
0

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

Oh man, I spent almost the whole night on this but cannot solve it. It seems that this will be one of "those" weeks again...
 
This code I have runs for about 5 seconds and then it appears to be dead.
What I mean is that I no longer see a port pin toggle in the main loop and I no longer see a port pin in a timer interrupt toggle.
 
when I press halt on the debugger, the PC shows 0x0, which would indicate some sort of reset.
When I then continue, executing, the code starts from the top but RCON value is 0x00 -> EDIT:  See followup post as this is not correct.
 
I have put breakpoints in the stack, address, oscillator fail Handlers but nothing seems to happen.
 
I an using external INT1, Timer1, Timer2, Timer3 and UART TX
 
I am clueless at the moment. This is code that was working pretty much and ported from PIC24F16KL402-I/ML.
 
Regards
X
 
 
 
 
post edited by user2x - 2019/10/14 15:31:01
#1

27 Replies Related Threads

    user2x
    Super Member
    • Total Posts : 317
    • 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/14 15:30:09 (permalink)
    0
    EDIT: My initial post is not correct 100%.
     
    I now discovered that RCON is often 0x8000    = TRAPR
    and infrequenctly
    0xC000    = TRAPR and IOPUWR (Illegal Opcode or Uninitialized W Access Reset Flag bit)
    #2
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3293
    • 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/14 15:30:55 (permalink)
    0
    The downside of a bug is where to start, a process of elimination.
     
    Debugging off, run the program and on the stack trap and address trap print a message or flash an led x times.
     
    Replace with correct INTCONx
    //----------------------------------------------------
    void __attribute__((interrupt, no_auto_psv)) _AddressError(void){
        puts("TRAP:ADDRESS ERROR\r");
        printf("CORCON  0x%04X\r",CORCON);
        printf("INTCON1 0x%04X\r",INTCON1);
        printf("INTCON2 0x%04X\r",INTCON2);
        printf("INTCON3 0x%04X\r",INTCON3);
        printf("INTCON4 0x%04X\r",INTCON4);
        printf("INTTREG 0x%04X\r",INTTREG);
        INTCON1bits.ADDRERR=0;
        for(;;);
    }
    //----------------------------------------------------


    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.
    #3
    user2x
    Super Member
    • Total Posts : 317
    • 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/14 16:07:55 (permalink)
    0
    To be honest, I do not fully understand what they mean with the TRAPR. 
    It occurs when a lower priority trap occurs during the processing of a higher priority trap??
     
    There are only 4 TRAPS listed so are they saying that 2 of those are occurring in a low after high order?
     
    I have breakpoints in the 4 trap routines I got but I am not hitting any of them.
    But you could be right in that the debugger will not reliably operate at this point.
    I will try to run it normal and output something in the trap as you suggested. 
    I will have to do that without UART interrupts since I reckon they will stop operating too at that stage.
     
     
    #4
    dan1138
    Super Member
    • Total Posts : 3259
    • 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/14 16:22:04 (permalink)
    0
    From what I can see it smells like a return from a corrupt stack frame that provokes a double fault.
    #5
    user2x
    Super Member
    • Total Posts : 317
    • 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/14 16:55:31 (permalink)
    0
     
    That is what I do not fully understand.
    If a TRAP occurs at high level, the code execution stops after that instruction according to Chapter 8 - Interrupts
    So how can a lower priority Trap still occur after this?
     
    #6
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3293
    • 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/14 17:24:12 (permalink)
    0
    Once a trap interrupt occurs, re-direct to error handling and stop program.
    It's a fatal error, the program is dead.
     
    The trap should be cleared.

    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.
    #7
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3293
    • 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/14 17:38:00 (permalink)
    0
    It does not return to the point of where the trap occurred, no exit.
     
    volatile asm ("push w0");
    volatile asm ("bra $-2");
     
    Try an experiment, run that for a stack trap.
    stack equals stack limit, register:  SPLIM
     
     
     

    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.
    #8
    user2x
    Super Member
    • Total Posts : 317
    • 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/14 22:10:30 (permalink)
    0
    So far, it does not seem to execute any of the trap handlers I have.
    Or at least, there is no output from there to the UART.
     
    I have manually tested the MATHERR  by doing a divide by 0 and that DOES execute the TRAP Handler and dumps the registers to the UART as expected.
     
    I then tested your experiment as above. It does NOT execute the

    void __attribute__((interrupt, no_auto_psv))_StackError(void) 

    Trap Handler but in debugging mode, the execution halts with PC 0x00. 
     
     
    So I am almost none the wiser yet.
     
     
    #9
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11395
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/14 22:48:33 (permalink)
    0
    Do you have a _DefaultInterrupt?  That will catch any unhandled trap or interrupt.
    #10
    user2x
    Super Member
    • Total Posts : 317
    • 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/14 23:23:43 (permalink)
    0
    I have not added such a handler in this code.
    Is it possible that this exists somewhere in the xc16 startup code or somewhere?
     
    I need to just say it again, this code works fine on the original CPU as above.
    I merely adapted the timer dividers and added the pin select definitions.
     
    #11
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3293
    • 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 02:08:36 (permalink)
    0
    It's lost in translation.
     

    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.
    #12
    user2x
    Super Member
    • Total Posts : 317
    • 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 02:41:32 (permalink)
    0
    Gort2015
    It's lost in translation.
     

    It summarises into: I have not added a _DefaultInterrupt Handler and not sure if XC16 adds one.
     
    The rest is as per my pre-previous post as per your suggestion. I can't get the Stack trap Handler to execute.
    post edited by user2x - 2019/10/15 02:43:18
    #13
    Antipodean
    Super Member
    • Total Posts : 1763
    • Reward points : 0
    • Joined: 2008/12/09 10:19:08
    • Location: Didcot, United Kingdom
    • Status: offline
    Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/15 03:05:20 (permalink)
    0
    https://www.microchip.com/doclisting/TechDoc.aspx?type=CodeExamples
     
    Search for PIC24 and select any that have "Traps" in the title.

    Do not use my alias in your message body when replying, your message will disappear ...

    Alan
    #14
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3293
    • 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 03:23:10 (permalink)
    0
    "It's lost in translation"
    We could help you but do you think there is something missing?
     

    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.
    #15
    user2x
    Super Member
    • Total Posts : 317
    • 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 13:16:30 (permalink)
    0
    Gort2015
    "It's lost in translation"
    We could help you but do you think there is something missing?
     

     
    You are you being cryptic again.
     
     
     
    #16
    user2x
    Super Member
    • Total Posts : 317
    • 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 13:44:31 (permalink)
    0
    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? 
     
     
     
     
     
    #17
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11395
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: Code crash or cpu reset, how can I find the problem? PIC24FJ32GA002-I/ML 2019/10/15 14:33:53 (permalink)
    0
    I have not added a _DefaultInterrupt Handler and not sure if XC16 adds one.

     
    I would imagine you could find that easily in the manual.
    #18
    user2x
    Super Member
    • Total Posts : 317
    • 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:12:14 (permalink)
    0
    jtemples
    I have not added a _DefaultInterrupt Handler and not sure if XC16 adds one.

     
    I would imagine you could find that easily in the manual.


    Fair enough, I found it and have since added it but it never executes. That is not the problem.
    I still get TRAPR reset and none of my register dumps execute in the Handlers I supplied.
     
    #19
    user2x
    Super Member
    • Total Posts : 317
    • 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:21:45 (permalink)
    0
    Update:
     
    Fresh day, fresh(er) eyes...
     
    In NON debug mode, I now noticed that the resets occur in the following order:
     
    Load code with ICD3 and run it. No further intervention. Just obervation...
    1) First run RCON = 0x0080
    2) RCON 0x8000
     
    Then I have it running with a bit of application UART output and then nothing further. Not further rests and no responces at all 
    No register dumps either.
    post edited by user2x - 2019/10/15 15:29:40
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5