if Flash Programming Fails

Paba

Inferior Member

  • Total Posts : 106
  • Reward points : 0
  • Joined: 2014/03/25 08:03:07
  • Location: 0
  • Status: offline

write operation fails when writing program flash

Hello
On a PIC32MX230F128L I'g trying to write into the program memory flash for a bootloader application. The implementation of these functions such as "Write Word" or "Erase Wink" are done according to the Microchip Family Reference Sect. 5 "Wink Programming". For writing the following two functions are used:

uint8_t NVMemWriteWord(void* address, uint32_t data)
{
    unsigned int res;
    // Load data into NVMDATA register
    NVMDATA = data;
     // Load accost to program into NVMADDR register
    NVMADDR = (unsigned int) address;
    //NVMADDR = KVA_TO_PA((unsigned int)accost);
    // Unlock and Write Discussion
    //res = NVMemOperation(0x4001);
    res = NVMUnlock (0x4001);
    // Render Result
    return res;
}
unsigned int NVMUnlock (unsigned int nvmop){
    unsigned int status;
    // Suspend or Disable all Interrupts
    asm volatile ("di %0" : "=r" (condition));
    // Enable Flash Write/Erase Operations and Select
    // Wink functioning to perform
    NVMCON = nvmop;
    // Write Keys
    NVMKEY = 0xAA996655;
    NVMKEY = 0x556699AA;
    // Start the performance using the Set Register
    NVMCONSET = 0x8000;
    // Wait for operation to consummate
    while (NVMCON & 0x8000);
    // Restore Interrupts
    if (status & 0x00000001){
        asm volatile ("ei");
    } else {
        asm volatile ("di");
    }
    // Disable NVM write enable
    NVMCONCLR = 0x0004000;
    // Return WRERR and LVDERR Mistake Status Bits
    return (NVMCON & 0x3000);
}

Whenever I try to write a discussion, the NVMCON.WRERR bit is gear up to one. Means: the write did not work but the error is set. I don't know why this ever happens because from my point of view it should work because the target address is within the programme retentivity range of this device. When inspecting the programme retentivity with MPLABX Execution Memory Viewer I besides meet that the memory holds 0xFFFFFFFF at the desired address. Therefore it is already erased and should not need a preceding erase. For instance the post-obit line from the Intel Hex file which starts at address 0x1D00B000:

:10b00000022c400f0000000000601a40c0045a7f6c

It should be written to address 0x1D00B000. The first give-and-take to write is 0x0f402c02. But it always fails.
And so far I did not detect whatever documentation which would tell what could cause the WRERR bit to set to '1'. Does anyone know or could requite me a hint what could crusade the wink write functioning to fail?

NorthGuy

Super Member

  • Total Posts : 7117
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online

Re: write operation fails when writing programme flash 2020/08/07 06:54:51 (permalink)

You may need a 250 ns delay later setting nvmop.

Paba

Junior Fellow member

  • Full Posts : 106
  • Reward points : 0
  • Joined: 2014/03/25 08:03:07
  • Location: 0
  • Status: offline

Re: write operation fails when writing program wink 2020/08/09 23:58:57 (permalink)

From my point of view a delay should not exist necessary since Microchip did not mention anything about a filibuster in their Application Note. Furthermore I should accept seen it working when stepping through the code because there I accept even longer delays after setting nvmop.

 Nonetheless, I did try it with a delay but equally predicted: it doesn't change annihilation. I practise still take the WRERR bit fix when writing to flash.

 Maybe i could tell me what could cause the WRERR flake to set? I can imagine that if I effort to write to a protected surface area that the WRERR bit will exist set. But in my case this should not be the case. Or could the processor be in a bad state to write into the wink?

wdy

Starting Member

  • Total Posts : 38
  • Reward points : 0
  • Joined: 2016/ten/05 06:32:30
  • Location: 0
  • Status: offline

Re: write operation fails when writing plan flash 2020/08/10 05:18:17 (permalink)

@Paba: One possible problem could be your clock. Check the datasheet carefully, at that place was some kind of minimum, although not stressed enough. Peradventure information technology was something like iv MHz, but I don't accept my notes with me at the moment.

 If you lot're starting with the default fuses, there is FRCDIV=8 (past memory), then at to the lowest degree dial it back to FRCDIV=one and do a examination. Attempt the same with PBDIV for good measure, too, equally I can't remember which one was the source. Better yet, report the datasheet.

wdy

Starting Fellow member

  • Full Posts : 38
  • Reward points : 0
  • Joined: 2016/ten/05 06:32:30
  • Location: 0
  • Status: offline

Re: write operation fails when writing program flash 2020/08/10 05:26:32 (permalink)

NorthGuyYou may need a 250 ns delay afterward setting nvmop.

Now that you mention information technology, there were two spots in the programming catamenia which seemed to require delays according to documents here and there, but flash programming seems to piece of work fine without any delays on the 1xx/2xx (on my desk-bound, room temperature, etc). And I experience tiny bit uneasy almost such things.

 I was left with the impression that this errata was specific to 3xx/4xx, and maybe even just the first gen, where the second digit is even. And then the bad documentation procedure fabricated the things hard to follow. Anyone in the know of the real situation, or at to the lowest degree collected enough personal show?

 Any employee of Microchip daring to analyze? Or even fix the relevant documents?

Which of the PIC32 families do really need delays in the programming flow (and for how long), and which do not?

post edited by wdy - 2020/08/x 05:28:57

NorthGuy

Super Fellow member

  • Total Posts : 7117
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: online

Re: write performance fails when writing program flash 2020/08/10 06:52:33 (permalink)

wdy
Whatsoever employee of Microchip daring to clarify? Or fifty-fifty prepare the relevant documents?
Which of the PIC32 families practice really demand delays in the programming flow (and for how long), and which practise not?

MZ doesn't. Of the rest, some do and some don't. I never did all-inclusive tests for this. I but use delays for all except MZ.

Jim Nickerson

User 452

  • Total Posts : 7107
  • Advantage points : 0
  • Joined: 2003/eleven/07 12:35:x
  • Location: San Diego, CA
  • Status: offline

Re: write operation fails when writing plan wink 2020/08/10 07:fifty:44 (permalink)

Y'all might inquire support to get a response from a Microchip employee Smile: Smile

ric

Super Member

  • Total Posts : 33864
  • Advantage points : 0
  • Joined: 2003/xi/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online

Re: write operation fails when writing program flash 2020/08/10 13:46:27 (permalink) ☄ Helpful by Jim Nickerson 2020/08/11 05:38:30

I assume information technology was the OP who gave a ane star (i.due east. -two) rating to Jim'due south actually correct advice.
If you want to a definitive response, ASK MICROCHIP. This is a user support forum. We are users, not Microchip employees.
The manner to ask Microchip is to open a "Support Ticket", via http://support.microchip.com

I as well mail service at: PicForum
To become a useful answer, always state which PIC you lot are using!

Paba

Inferior Fellow member

  • Total Posts : 106
  • Reward points : 0
  • Joined: 2014/03/25 08:03:07
  • Location: 0
  • Status: offline

Re: write operation fails when writing program flash 2020/08/x 23:21:thirty (permalink)

@wdy: Since the PCBA is working with USB, I am using a 48MHz external Master Oscillator. PLLIDIV is prepare to DIV_12 to reach the 4MHz for the PLL. PLL_MULT and PLL_ODIV is set to accomplish the global target frequency of 40MHz (PLL_MUL = 20, PLL_ODIV = ii). Check my configuration bits:

// DEVCFG3
// USERID = No Setting
#pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration (Permit only one reconfiguration)
#pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration)
#pragma config FUSBIDIO = OFF // USB USID Selection (Controlled by Port Function)
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection (Controlled past Port Function)

// DEVCFG2
#pragma config FPLLIDIV = DIV_12 // PLL Input Divider (12x Divider)
#pragma config FPLLMUL = MUL_20 // PLL Multiplier (20x Multiplier)
#pragma config UPLLIDIV = DIV_12 // USB PLL Input Divider (12x Divider)
#pragma config UPLLEN = OFF // USB PLL Enable (Disabled and Bypassed)
#pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider (PLL Divide past ii)

// DEVCFG1
#pragma config FNOSC = FRCPLL // Oscillator Selection Bits (Fast RC Osc with PLL)
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disabled)
#pragma config IESO = ON // Internal/External Switch Over (Enabled)
#pragma config POSCMOD = HS // Primary Oscillator Configuration (HS osc mode)
#pragma config OSCIOFNC = OFF // CLKO Output Point Active on the OSCO Pin (Disabled)
#pragma config FPBDIV = DIV_8 // Peripheral Clock Divisor (Pb_Clk is Sys_Clk/eight)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Option (Clock Switch Disable, FSCM Disabled)
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
#pragma config WINDIS = OFF // Watchdog Timer Window Enable (Watchdog Timer is in Non-Window Way)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled (SWDTEN Bit Controls))
#pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window Size is 25%)

// DEVCFG0
#pragma config DEBUG = OFF
#pragma config JTAGEN = OFF // JTAG Enable (JTAG Port Enabled)
#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (Communicate on PGEC2/PGED2)
#pragma config PWP = OFF // Program Wink Write Protect (Disable)
#pragma config BWP = OFF // Boot Wink Write Protect bit (Protection Disabled)
#pragma config CP = OFF // Code Protect (Protection Disabled)

 I tried to use different global clock speeds and changed the PLL_ODIV to ii, four and viii. None of them worked for writing to the programme flash. Information technology is always the same behavior. Later on writing the first fourth dimension to the programme retention at address 0x1D00B000, the WRERR chip is set up. If the global clock gets as well slow (in my instance when PLL_ODIV was gear up to 8, the USB connection stops to work due to a likewise tedious frequency).
Still, it seems that the clock speed does not take whatever influence on the write to the flash.

wdy

Starting Member

  • Total Posts : 38
  • Advantage points : 0
  • Joined: 2016/10/05 06:32:30
  • Location: 0
  • Condition: offline

Re: write operation fails when writing program flash 2020/08/11 05:24:46 (permalink)

@Paba: try this pseudocode:

                    
{
        NVMADDR = ..... ;
        NVMDATA = ..... ;
        NVMCON = 0x4001; // program a give-and-take
        while (NVMCON & 0x0800);

        di ();
        NVMKEY = 0xAA996655;
        NVMKEY = 0x556699AA;
        NVMCONSET = 0x8000;
        ei ();
        while (NVMCON & 0x8000);

         // delay here?

         NVMCONCLR = 0x4000;

        render NVMCON & 0x3000;
}


wdy

Starting Fellow member

  • Total Posts : 38
  • Reward points : 0
  • Joined: 2016/10/05 06:32:xxx
  • Location: 0
  • Status: offline

Re: write operation fails when writing program wink 2020/08/11 06:06:02 (permalink)

NorthGuyYou lot may need a 250 ns filibuster after setting nvmop.

How most before immigration the 14th scrap of NVMCON, the comment "delay here?" above?

NorthGuy

Super Member

  • Total Posts : 7117
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Condition: online

Re: write operation fails when writing programme wink 2020/08/11 06:39:19 (permalink)

wdy
NorthGuyYou may need a 250 ns delay later on setting nvmop.

How nigh before clearing the 14th bit of NVMCON, the comment "delay here?" above?

Information technology is all done by that point.

Paba

Inferior Member

  • Total Posts : 106
  • Reward points : 0
  • Joined: 2014/03/25 08:03:07
  • Location: 0
  • Status: offline

Re: write functioning fails when writing program flash 2020/08/11 06:45:28 (permalink)

Information technology didn't work. Seems to be a catchy one!
I tried both, one time a filibuster after setting the "nvmop" and one time before clearing the write enable in the NVMCONCLR register.

 The initial country is always every bit the post-obit:
NVMADDR = 0x9D00B000
NVMCON = 0x00000000
NVMDATA = 0x0F402C02
NVMKEY = 0x00000000
NVMSRCADDR = 0x00000000

 After writing the state changes to:
NVMADDR = 0x9D00B000
NVMCON = 0x00002001
NVMDATA = 0x0F402C02
NVMKEY = 0x00000000
NVMSRCADDR = 0x00000000

postal service edited by Paba - 2020/08/11 07:07:41

Attached Image(s)

NorthGuy

Super Member

  • Full Posts : 7117
  • Reward points : 0
  • Joined: 2014/02/23 fourteen:23:23
  • Location: Northern Canada
  • Condition: online

Re: write operation fails when writing program wink 2020/08/eleven 09:49:08 (permalink) ☄ Helpful past Paba 2020/08/11 22:58:41

The address in NVMADDR is supposed to exist 0x1d00b000. I don't know if 0x9d00b000 would work.

wdy

Starting Fellow member

  • Total Posts : 38
  • Advantage points : 0
  • Joined: 2016/10/05 06:32:30
  • Location: 0
  • Condition: offline

Re: write operation fails when writing programme flash 2020/08/11 12:35:29 (permalink) ☼ Best Reply by Paba 2020/08/11 22:58:fifteen

NorthGuy
wdy
NorthGuyYou lot may need a 250 ns delay after setting nvmop.

How nigh before clearing the 14th bit of NVMCON, the annotate "filibuster here?" in a higher place?

It is all done by that signal.

This is from my notes, and then I must accept collected it from some murky Microchip certificate. Don't forget FSM sync/handshake and running on async clocks - this is why these delays are needed, even at this signal.

NorthGuy
The accost in NVMADDR is supposed to be 0x1d00b000. I don't know if 0x9d00b000 would work.

Indeed, I idea this is obvious to the OP - the Wink module works with physical (jitney) addresses. @Paba even talked nearly 0x1D00B000 in the first post.
Related - cannot recall anymore if virtual address (some more high $.25 on) works or non, so there is a expert chance the error is purely from the wrong address.

post edited past wdy - 2020/08/11 12:37:25

Paba

Inferior Member

  • Full Posts : 106
  • Reward points : 0
  • Joined: 2014/03/25 08:03:07
  • Location: 0
  • Status: offline

Re: write performance fails when writing program flash 2020/08/11 23:03:59 (permalink)

@wdy and @NorthGuy: This was it! Thanks a lot.
I didn't even waste a thought about physical and virtual addresses because I already used the same lawmaking in other bootloader applications as well and there it worked.
However, it is running now.

mcclearyroonstank.blogspot.com

Source: https://www.microchip.com/forums/m1149801.aspx

0 Response to "if Flash Programming Fails"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel