• AVR Freaks

Hot!Programming flash memory gives random write errors

Author
henkebenke
Senior Member
  • Total Posts : 72
  • Reward points : 0
  • Joined: 2008/09/27 23:55:51
  • Location: 0
  • Status: offline
2020/08/05 07:47:50 (permalink)
0

Programming flash memory gives random write errors

Hi, I'm trying to program flash on a PIC32 MZ device. I'm using the row programming option.
 
        while (NVM_IsBusy());
        NVM_RowWrite((int*) block, 0x9d050000, 2048 );
        while (NVM_IsBusy());
        delay_code_us(15000); // To be sure, 15 ms delay
        if (memcmp( block, (char*) 0x9d050000, 2048));
            return -1;
 memcmp reports unsuccessful writing. When I dump the flash, I find that at the end of the row,
 there are usually around ten or twenty words that are set to zero. They are grouped together
 in sections of five to ten words.
 If the operation would have failed, the words would have been 0xffffffff.
 It's a pic32mz0512efe100 device. The code is not write protected. No interrupts involved.
 And the WRERR bit is set to zero.
 This must be a simple task. The NVM functions ( generated by Harmony ) should do their jobs.
 Thanks
#1

5 Replies Related Threads

    optimus_jack
    Senior Member
    • Total Posts : 102
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: Programming flash memory gives random write errors 2020/08/05 09:09:24 (permalink)
    0
    HI,
    Please make sure before performing Write operation that region of memory is in erased state. You can erase that region before writing using the erase API's
    post edited by optimus_jack - 2020/08/05 09:10:58
    #2
    henkebenke
    Senior Member
    • Total Posts : 72
    • Reward points : 0
    • Joined: 2008/09/27 23:55:51
    • Location: 0
    • Status: offline
    Re: Programming flash memory gives random write errors 2020/08/05 23:14:23 (permalink)
    0
    OK, I forgot to tell that I certainly did erase the locations before attempting to write.
     
    I tried to use QuadwordWrite() instead, and then it seems to work properly.  Does anyone know if the row-programming is considered less stable?
     
     
    #3
    optimus_jack
    Senior Member
    • Total Posts : 102
    • Reward points : 0
    • Joined: 2017/02/16 03:02:47
    • Location: 0
    • Status: offline
    Re: Programming flash memory gives random write errors 2020/08/05 23:52:51 (permalink)
    0
    I don't see a reason why Row write should not work.
     
    1. Try to place your buffer (block) in coherent space from where you are writing. __attribute__((coherent))
    2. Can you try to read from non cacheable space 0xBd050000 instead of 0x9d050000
     
    if (memcmp( block, (char*)KVA0_TO_KVA1(0x9d050000), 2048));
          return -1;
    post edited by optimus_jack - 2020/08/05 23:55:04
    #4
    henkebenke
    Senior Member
    • Total Posts : 72
    • Reward points : 0
    • Joined: 2008/09/27 23:55:51
    • Location: 0
    • Status: offline
    Re: Programming flash memory gives random write errors 2020/08/08 01:09:36 (permalink)
    4 (1)
    OK, I never quite got it what the kseg1 means - is it two separate memories, or what. But I think the kseg1 is just an image of the kseg0, but the CPU cant use the cache to reach the data on kseg1. Am I right?
     
    This seems to be the most plausible explanation. The cache somehow missed some data.
     
    One more thing.  The source ram ( in row programming ) should be placed in kseg1 for max safety. But is there any point to program the kseg1? It shouldn't, since we are programming, not reading.
     
    But it must be the source ram that caused the mishap, not the validation afterwards, because I checked it by uploading the flash image to Mplabx. But I will definitely stick to quad programming - it seems most safe.
     
    Thanks.
     
     
    #5
    Mysil
    Super Member
    • Total Posts : 3712
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Programming flash memory gives random write errors 2020/08/08 05:16:44 (permalink)
    0
    Hi,
    kseg0 and kseg1 are Not two separate memory areas,
    they are Two different ways of accessing the same memory.
    However, the flash programming hardware use neither kseg0 nor kseg1 addressing:
    the flash programming peripheral use Physical memory addressing.
    There exists functions for Virtual to Physical address translations.
     
    When flash programming is completed, then Cache contents may be invalid,
    so take care to read uncached memory when trying to verify updated flash.
     
        Mysil
    #6
    Jump to:
    © 2020 APG vNext Commercial Version 4.5