• AVR Freaks

Hot!PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long

Author
kylesams
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/08/16 13:35:24
  • Location: 0
  • Status: offline
2019/10/16 09:04:45 (permalink)
0

PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long

I am trying to execute code to erase a full page of flash memory in software. This process sometimes takes minutes to complete and continue to normal program operation! It seems like I am doing the right sequence of operations for unlocking and setting the NVM operation because the code will always evetually return to normal operation with no errors. Please let me know if there is anything wrong with my attached code snippets or if you have any suggestions. Thank you.
#1

16 Replies Related Threads

    jg_ee
    Super Member
    • Total Posts : 174
    • Reward points : 0
    • Joined: 2015/04/30 10:54:52
    • Location: Colorado
    • Status: offline
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 10:38:53 (permalink)
    0
    Your delay function is suspect to me, I would make sure that works like you think it should.
     
    I would also change all of the NVMCON register writes to atomic operations, since you are also using status bits in it as well and may encounter a RMW problem.
    #2
    kylesams
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2019/08/16 13:35:24
    • Location: 0
    • Status: offline
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 11:08:25 (permalink)
    0
    The erase page operation still works correctly even after removing my delay loop. It is just there as a precaution in case the LVD circuit detects an issue which there shouldn't be with my current setup.
     
    By changing them to atomic operations do you mean instead of setting all of the NVMCONbits individually, to set the NVMCON register with the appropriate value?
    #3
    NKurzman
    A Guy on the Net
    • Total Posts : 17939
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 11:08:34 (permalink)
    0
    1. It does not take Minutes.  It is milliseconds and listed in the Data Sheet.
    2. Depending on flash locations, the CPU can Stall.  No code will execute, but Timers will still run.
    #4
    kylesams
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2019/08/16 13:35:24
    • Location: 0
    • Status: offline
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 11:26:23 (permalink)
    0
    Well ok then I guess the CPU stalls for minutes. So do you have any idea how to force the CPU out of this stall? Will changing the flash location affect it?
    #5
    NorthGuy
    Super Member
    • Total Posts : 5754
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 11:56:26 (permalink)
    5 (1)
    No, CPU doesn't stall for minutes. I guess you're doing more writes/erases than you should, but it's impossible to figure out without looking at the code.
     
    #6
    kylesams
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2019/08/16 13:35:24
    • Location: 0
    • Status: offline
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 12:24:14 (permalink)
    0
    What code do you need to see exactly? At the beginning of the thread I attached my NVMOperation code and where I am calling it from
    #7
    NorthGuy
    Super Member
    • Total Posts : 5754
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 12:40:49 (permalink)
    0
    kylesams
    What code do you need to see exactly? At the beginning of the thread I attached my NVMOperation code and where I am calling it from



    If you do the NVM operation once, it takes several ms. If you do it many many times, it will take minutes. Just look at your code and see how many times you're calling it. Or put a counter inside your NVM operation routine and see how many times it is executed. Or pulse a LED within the NVM operation and count pulses with LA (you can also look at the duration of the pulses to see how long the CPU is actually stalled).
     
    In short, your theory that the CPU stalls for minutes during the NVM operation is incorrect. To find the reason for the delay, look elsewhere.
     
    #8
    NKurzman
    A Guy on the Net
    • Total Posts : 17939
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 12:43:54 (permalink)
    0
    It is not taking minutes, your code is. Focus on that.
     
    http://ww1.microchip.com/downloads/en/DeviceDoc/60001387c.pdf
    Self-Timed Page Erase Time  4.33 ms max.
    The Full chip is 17.3 millisec.
     
    I assume you are working from:
    http://ww1.microchip.com/downloads/en/DeviceDoc/60001121g.pdf
    #9
    kylesams
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2019/08/16 13:35:24
    • Location: 0
    • Status: offline
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 13:05:25 (permalink)
    0
    I am printing debug messages to a terminal and I can see that it is only performing 3 NVM operations and then gets hung up after returning from the function calling those 3 NVM operations
    #10
    NorthGuy
    Super Member
    • Total Posts : 5754
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 13:13:58 (permalink)
    5 (2)
    kylesams
    I am printing debug messages to a terminal and I can see that it is only performing 3 NVM operations and then gets hung up after returning from the function calling those 3 NVM operations



    It gets hung up after returning from the function calling those 3 NVM operations. See, has nothing to do with NVM operation stalls. You might have erased part of your program :)
    #11
    NKurzman
    A Guy on the Net
    • Total Posts : 17939
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 14:53:09 (permalink)
    0
    Have you insured that there is no code or constants in those pages in either their declarations, or the Linker script?
    #12
    Mysil
    Super Member
    • Total Posts : 3421
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/16 18:36:45 (permalink)
    5 (1)
    Hi,
    If you have timers running, either peripheral timers, or MIPS CP0  Count and Compare register (core timer)
    running, using interrupt service routines to process timer updates,
    Then during the time CPU is stalled during Flash erase and writing,
    timer updates could be missed such that program will hang until core timer run around 2^32 counter increments.
    e.g: a 1 millisecond interrupt timer could get confused this way.
    A PIC32MM running at 25 MHz might experience a 343 seconds hang in such a situation.
    The first interrupt after the stall might be processed normally, since the interrupt flag have already been set, but if the Compare register update value is already in the past ...
     
        Mysil
    #13
    kylesams
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2019/08/16 13:35:24
    • Location: 0
    • Status: offline
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/17 06:30:37 (permalink)
    0
    I believe you are correct in the fact that this is my issue. Any way to solve this timer issue to unhang the CPU?
     
    #14
    NKurzman
    A Guy on the Net
    • Total Posts : 17939
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/17 08:19:35 (permalink)
    0
    Stop Erasing Your Code.  either change the Linker script to hold the area OR
    create variables that use __attribute__
     
    for example:
    const uint8_t flashArea[FLASH_PAGE_SIZE] __attribute__ (((aligned (FLASH_PAGE_SIZE), address(PERSISTANT_MEMORY_BASE)));  
    #15
    Mysil
    Super Member
    • Total Posts : 3421
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/17 09:27:01 (permalink)
    0
    Hi,
    If core timer overrun is actually causing the problem,
    then either update Compare register from current Count value when Flash erase or update have been completed,
    Or in core timer ISR, check that next interrupt Compare value is in the future, something like:
            // All variables used for core timer calculations, should be unsigned 32 bit integer.
            unsigned int tInt, tNow;
     
            // Set the next interrupt time
            tInt = _CP0_GET_COMPARE();    // previous value of Compare register.
            tNow = _CP0_GET_COUNT();    // current value of Count register.

            // Make sure the next interrupt is in the future.
            if ( tNow - tInt < TICK_PERIOD)                // This is the normal case.
                _CP0_SET_COMPARE( tInt + TICK_PERIOD);
            else                                        // Set the next interrupt from the current time.
            {    _CP0_SET_COMPARE( tNow + TICK_PERIOD);    // If this happen often, tick timing will drag.
                Nop();            // Set a breakpoint here to check if this actually happen.
            }

    It may be possible to introduce some tolerance in the check calculation:
            if ( tNow - tInt < TICK_PERIOD - TOLERANCE)    

        Mysil
    #16
    kylesams
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2019/08/16 13:35:24
    • Location: 0
    • Status: offline
    Re: PIC32MM0256GPM048 RTSP Time to Erase a Page Too Long 2019/10/17 10:12:41 (permalink)
    0
    Thank you so much Mysil and everyone else for the input! That fixed it! 
    #17
    Jump to:
    © 2019 APG vNext Commercial Version 4.5