Flash writing breaking after one write + influenced by breakpoints

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a program where 3 Flash pages are being written (4 if you include the userpage) in sequence, because the data doesn't fit in one page.

When I start the MCU and run it, everything seems to be written correctly to flash.

But if I want to clear and overwrite it, the program fails to do so.

There is no error showing up, no exception, nothing that would indicate a failure. The data is simply not re-written in flash (checked with atmel studio debugger).

I'm also fully aware, that with a write operation, only ones can be turned to zeroes and not the other way around. (I'm always calling the clearing command to restore the 0xff .... state.)

 

After a restart it works again for exacly 1 page written. The passed address is correct I verified that, I'm not violating reserved flash or something like that.

 

Any ideas why it's failing? What could I do?

 

A hint may be, that, when I put a breakpoint somewhere before the write command, it fails completely and doesn't even write once (race condition?).

 

This is the relevant code:

Own code:

void writeNormalFlashPage(uint32_t*data, uint16_t wordcount, uint32_t destinationAddr)
{
    flashc_clear_page_buffer();
    uint32_t *psrc, *pdest ;
    uint8_t timeout = 0;
    volatile uint32_t dAC = destinationAddr;
    
    psrc = (void*) (&(data[0]));
    pdest = (void*) destinationAddr ;
    while (wordcount--)
    {
        *pdest++ = *psrc++ ;
    }
    
    dAC = destinationAddr;
    while(!flashc_erase_page(dAC/512,true) && timeout < 250)
    {
        timeout++;
    }
    
    if(timeout >= 250)
    {
        return;
    }
    
    flashc_write_page(dAC/512);        // transfer all data from page buffer to flash
    while(!flashc_is_ready());
}

 

void KMS_FLASH_saveSettingsFileToFlash(uint32_t*settingsFile, uint16_t fileLen)
{
    // userpage
    WriteUserPageFlash(settingsFile, 7);
    
    // FSlot1
    writeNormalFlashPage(&(settingsFile[7]), 72, FLASH_FilterSlot0);
    
    // FSlot2
    writeNormalFlashPage(settingsFile + 79, 72, FLASH_FilterSlot1);    // + 79
    
    // FSlot3
    writeNormalFlashPage(settingsFile + 151, 72, FLASH_FilterSlot2); // + 151
    
}

 

ASF:

void flashc_write_page(int page_number)
{
    flashc_issue_command(AVR32_FLASHC_FCMD_CMD_WP, page_number);
}

 

 

[insert smart signature here]

Last Edited: Mon. Apr 24, 2017 - 03:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There might be a side-effect problem in your WriteUserPageFlash(,)
"After a restart it works again for exacly 1 page written." Does that "1 page" refer to the user-page ? or to whatever the FLASH_FilterSlot0 page-number is ?


flashc_erase_page(,) performs a flashc_issue_command(,) which will wait until the command has completed, therefore there should not be any need to have retries on the erase-page operation.
If flashc_erase_page(,) fails you can check why it failed with flashc_is_lock_error() and flashc_is_programming_error()

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What kind of side-effect problem are you thinking of?

 

The flashc_erase_page is returning a bool and has the option to check if the command was successful, thats what I'm using, just to be sure.

But nevertheless, flashc_erase_page(,) never fails (I concluded that, because the timer variable is never touched).

 

UPDATE: I did a small test and I wrote something wrong before: The function KMS_FLASH_saveSettingsFileToFlash(,) is calling writeNormalFlashPage multiple times and each is executed successfully! But when I call KMS_FLASH_saveSettingsFileToFlash(,) a second time, it doesn't do anything, although data has changed.

 

Also, all methods cease to function if a breakpoint is hit anywhere prior to the Flash function calls.

 

Im trying to find out what diffrences are being made to the flash registers between two writes.

[insert smart signature here]

Last Edited: Tue. Apr 25, 2017 - 10:48 AM