• AVR Freaks

Hot!PIC32MZ not saving state correctly in interrupts?

Author
aostler
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2015/11/05 13:08:20
  • Location: 0
  • Status: offline
2020/06/25 07:20:34 (permalink)
0

PIC32MZ not saving state correctly in interrupts?

I have a product using PIC32MZ2048EFH144-250I/PH.
 
Mostly it runs fine. On some specific units though, it crashes frequently. I have traced this down to what looks to be a corruption of the main register set during an interrupt.
 
Specifically, I can observe the code doing a LH into v0 (which should always result in sign-extension of the upper halfword), and then a few instructions later v0 has an impossible value (e.g. 0x00034567) which could not result from sign-extension of a halfword.
 
If I disable interrupts around this section of code this does not occur.
 
I'm using shadow register sets for the interrupts and have set up PRISS correctly.
 
As I say, it's only on a few specific units that this happens.
 
Any ideas?
 
Thanks.
 
 
#1

8 Replies Related Threads

    wdy
    Starting Member
    • Total Posts : 28
    • Reward points : 0
    • Joined: 2016/10/05 06:32:30
    • Location: 0
    • Status: offline
    Re: PIC32MZ not saving state correctly in interrupts? 2020/06/25 14:42:02 (permalink)
    0
    Double check that interrupt function definitions match PRISS, just in case. Then check the compiler prologues/epilogues, again just in case. I don't use Microchip's GCC, hence this very general suggestion.
     
    Verify the priorities. What could interrupt the function you're describing, by design? Allocate a simple global variable, where the function under question stores zero right after the prologue, and any possible preempting function puts some unique ID there. Once corruption is suspected, check which ID is present. Finding zero is also helpful.
     
    On the hardware side, I'd try lowering the frequency and checking whether the problem still persists, esp. if you're playing in the 200+ MHz region. Could be a power supply bypassing issue, among many things.
    #2
    RISC
    Super Member
    • Total Posts : 5775
    • Reward points : 0
    • Status: offline
    Re: PIC32MZ not saving state correctly in interrupts? 2020/06/25 16:33:35 (permalink)
    0
    Hi,
    Have you implemented an error exception handler ?
    MIPS architecture has builtin Coprocessor 0 registers (cause, EPC) which will enable you to go back to the C line which caused the exception and also let you know the cause ( unaligned access, pointer issues,...)
    Regards
     

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #3
    aostler
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2015/11/05 13:08:20
    • Location: 0
    • Status: offline
    Re: PIC32MZ not saving state correctly in interrupts? 2020/06/26 02:19:22 (permalink)
    0
    I know which interrupt is causing the issue, since it's the only one active, and disabling that one specific interrupt (it's an SPI RX) also avoids the problem.
     
    #4
    aostler
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2015/11/05 13:08:20
    • Location: 0
    • Status: offline
    Re: PIC32MZ not saving state correctly in interrupts? 2020/06/26 02:21:53 (permalink)
    4 (1)
    Yes, the default Harmony error handler catches the error, which is how I was able to identify the location of the crash and set a breakpoint there.
     
    The crash is happening because a variable which should be limited to the size of a half-word is ending up holding a non-halfword value.
     
    #5
    moser
    Super Member
    • Total Posts : 581
    • Reward points : 0
    • Joined: 2015/06/16 02:53:47
    • Location: Germany
    • Status: offline
    Re: PIC32MZ not saving state correctly in interrupts? 2020/06/26 03:32:55 (permalink)
    0
    Maybe you should show us your declaration of the interrupt handler. Also the code parts which configure the interrupts.
     
    Make sure, the priority in the declaration and the interrupt setup matches and is correct.
     
    You wrote, that you have only one interrupt. Because of this you don't have nesting interrupts. Otherwise, you should also verify, you don't use the same shadow set twice.
     
     
    PS: Added note about "code parts which configure the interrupts."
    post edited by moser - 2020/06/26 03:34:46
    #6
    aostler
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2015/11/05 13:08:20
    • Location: 0
    • Status: offline
    Re: PIC32MZ not saving state correctly in interrupts? 2020/06/26 03:45:47 (permalink)
    0
    void __ISR(_SPI6_RX_VECTOR, ipl7srs) SPI6RXInterruptHandler(void)
     
    PLIB_INT_VectorPrioritySet( INT_ID_0, INT_VECTOR_SPI6_RX, INT_PRIORITY_LEVEL7 );
    PLIB_INT_VectorSubPrioritySet( INT_ID_0, INT_VECTOR_SPI6_RX, INT_SUBPRIORITY_LEVEL0 );
    PLIB_INT_SourceEnable( INT_ID_0, INT_SOURCE_SPI_6_RECEIVE );
     
     
    #7
    moser
    Super Member
    • Total Posts : 581
    • Reward points : 0
    • Joined: 2015/06/16 02:53:47
    • Location: Germany
    • Status: offline
    Re: PIC32MZ not saving state correctly in interrupts? 2020/06/26 05:53:58 (permalink)
    4 (1)
    Hmm, I have no idea. As far as I understood the prologue for interrupt priority 7 might be bit different and shorter (because it can't get interrupted). But this should not cause any problems.
     
    Did you check, whether the problem still exists, if you don't use the shadow register set (IPL7SOFT) or if you use the automatic (IPL7AUTO)?
     
    #8
    aostler
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2015/11/05 13:08:20
    • Location: 0
    • Status: offline
    Re: PIC32MZ not saving state correctly in interrupts? 2020/06/26 06:30:37 (permalink)
    4 (1)
    There's still a problem with IPL7SOFT. I didn't yet try IPL7AUTO.
     
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5