This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F5437A: Observing erase failure showing values other than FF after erasing a bank

Part Number: MSP430F5437A

Hi,

We are using MSP4305437A where we write a set of logs in the main memory bank 30000-3fff. I am trying to write and erase a set of logs into this location within an ISR routine. Everytime the interrupt comes I write few bytes into this bank 30000 and then erase it and again repeat the same. I am using the code below for erase and write. This interrupt comes every 16ms when I am writing and erasing the logs. I run this code for several hours and after that when I try to read the data in the location 30000-3fff, I expect it to be all FF's since I erase it, but I see that it holds data other than FF like BF, F7 etc in some of the locations.

I am wondering if the erase is failing since I have been writing and erasing so many number of times or is there anything wrong in the way I am trying to do the erase and write. 

Also all the code is being executed from the flash memory- 0x5C00 to 0xFFFF

Flash erase:

//Disable interrupt

//Disable watchdog

flashPtr = (unsigned char*)0x30000;      //flashPtr is of time unsigned char *

//wait while busy is set in FCTL3
FCTL3 = FWKEY; 
FCTL1 = FWKEY+MERAS_L;

*flashPtr = 0;

// wait while busy is set in FCTL3

FCTL1 = FWKEY; // Lock flash
FCTL3 = FWKEY+LOCK_L;

//enable interrupts

Regards

Lakshmi

  • If you really are erasing the same memory once every 16ms then you will reach the minimum flash endurance in about 160 seconds. Typical is ten times that so your failure is consistent with that.

    I have to wonder why you feel the need to erase memory so often. Are you really getting data at the rate of 4KB/16ms?  And where does it go?

  • HI David,

    Thanks for the response. No, we dont have the need to erase and write so often. In the actual scenario(in field), the erase and write is comparatively very low. But I wanted to try this in my local test environment. 

    The reason to do this was, in the field we are seeing some corruption while we read the data from the same location(30000). We see 0's in these locations sometimes, and when I went through some of the flash related TI documents it said that we would see a trail of 0's if we are overwriting into a location. And one reason for overwrite could be if erase failed, to test if erase is really happening correctly I tried the above test. I also doubted the erase routine since in the erratasheet for MSP4305437A it was mentioned that "Concurrent flash read during bank erase fails" and we are using bank erase while the code is running from the flash. I have added our flash and write routines as well below for reference.

    1. Flash Bank Erase

    //Disable interrupt

    //Disable watchdog

    flashPtr = 0x30000;

    //wait while busy is set in FCTL3
    FCTL3 = FWKEY; 
    FCTL1 = FWKEY+MERAS;

    *flashPtr = 0;

    // wait while busy is set in FCTL3

    FCTL1 = FWKEY; // Lock flash
    FCTL3 = FWKEY+LOCK;

    //enable interrupts

    2. Flash Erase and write

    INT32U *flashPtr_L;
    INT32U flashBuffer[128];

    //Disable interrupt

    //Disable watchdog

    flashPtr_L = (INT32U *)0x30000;

    while( BIT( FCTL3,BUSY) ); 
    FCTL3 = FWKEY; 
    FCTL1 = FWKEY+ERASE;

    *(CH8U*)flashPtr_L=0;

    // wait while busy is set in FCTL3

    FCTL1 = FWKEY+BLKWRT;

    memcpy(flashPtr_L, flashBuffer, 512);  //flashbuffer has the data to be written to flash

    // wait while busy is set in FCTL3

    FCTL1 = FWKEY;
    FCTL3 = FWKEY+LOCK;

    //Enable interrupts

    Regards

    Lakshmi

  • The problem described in the errata would not result in a failure to erase (either block or segment). That says that attempts to read flash while doing a bank erase will fail. (For some value of fail.) The workaround is to execute from RAM. So if you want to use the bank erase you will have to move some code into RAM. Otherwise you risk unexpected operation of the program when that flash read fails.

    You show two code fragments. The first is a bank erase and will run into the errata problem. Even if you wait till the erase finishes since that requires fetching instructions from flash.

    The second (segment erase) automatically pauses CPU execution (flash reads return 0x3fff which causes a loop in place) then resumes once complete. This should operate normally since there is no errata for that.

    I would be wary of "flashPtr_L = (INT32U *)0x30000;" Since if sizeof(int) is 16 (the norm on MSP430) then you will cast 0 into a pointer. I am paranoid enough to include the L at the end of the constant even if I am sure that the compiler is using 32 bit integers by default.

**Attention** This is a public forum