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.

question about reading MSP430F5418A internal flash



Hi all,

I'm currently working on 5418a. Now I wanna write some data to flash and read them from flash to do some verification. I write a long word 0x12345678 at address 0x1800

which is the information segment D. I'm sure that the long word is written into the flash, because I can see it in the memory window. Do I have to set 5418a in read mode to

read the data? As I know, the default mode of flash is read mode. So could you tell me how to read data from flash?

Thanks

Best regards,

Nick

 

  • Unless the flash controller is actively writing to flash, you can read all flash content by just reading it like any other memory location. For reading, there is no difference between flash or ram or hardware registers (except that the CPU cannot fetch a program instruction from hardware registers - it will cause a reset due to illegal instruction fetch exception)

    So any way that allows you to read from memory address 0x1800 will return the content of the flash at 0x1800.

  • Hi Gross,

    Thanks for your instant reply. Now I can read the flash correctly.

    But I have one more question, which is, I know that before writing flash I need to erase it. Owing to I write a long word in the information memory segment D, so I need to

    erase this segment before using it. Right? There are four information memory segments in 5418a. Before erasing this segment, erase bit in FCTL1 should be set. From the

    code example, I know that I need a dummy write to erase this segment. After this instruction has been executed, all the information memory segments have been erased?

    Or only one segment has been erased? If one segment has been erased, what value should I write to the flash if I wanna erase other segments?

    My codes are as follows:

    FCTL3 = FWKEY;                            // Clear Lock bit

     FCTL1 = FWKEY+ERASE;                      // Set Erase bit  

    *gpudFlash_ptrD = 0;                      // Dummy write to erase information memory segment

    FCTL1 = FWKEY+BLKWRT;                     // Enable long-word write  

    *gpudFlash_ptrD = udEdtionNum;            // Write specific value to Flash

     FCTL1 = FWKEY;                            // Clear WRT bit  

    FCTL3 = FWKEY+LOCK;                       // Set LOCK bit 

    The value of  gpudFlash_ptrD is 0x1800, which is the address of  information memory segment D. For example, if I wanna erase  information memory segment C or B or A,

    what value should I write to the flash for the dummy write cycle?

    Thanks a lot

    Best regards,

    Nick

  • Nick Carter said:
    I know that before writing flash I need to erase it. Owing to I write a long word in the information memory segment D, so I need to erase this segment before using it. Right?

    Yes and no. You need to erase the whole segment, if you want to write a '1' bit where there is currently a '0' bit. However, you may erase the segment (so it is all bits 1) and then write on byte to is, then another byte or word. You can even overwrite a byte, so it is e.g. written 0x80 first time, and then 0x00 (no change from any bit from 0 to 1 required).

    But there is a limit on how long programming voltage may be applied to a 64 byte block or else bits may turn form 1 to 0 by themselves through leakage currents.
    On older MSPs, this limit was so short that a maximum of ~50 individual write operations was possible (whcih did not necessarily have to happen all at the same time) before the whoel segment (in case of main flash with 8 64byte blocks, for info memory with one block) had to be erased.

    On newer MSPs this has relaxed a bit. But whiel it is now enough to write the whoel block byt eby byte without exceeding the limit, there's still a tight limit for the number of total writes between two erases.

    Nick Carter said:
    Or only one segment has been erased? If one segment has been erased, what value should I write to the flash if I wanna erase other segments?

    if hte flash controller is in erase mode, any write (the value itself is a don't care) causes the whole segment that belongs to this address to be erased. In case of the info memory, it is just one of the INFO segments (64 or 128 bytes, depending on MSP), in case of main flash it is 512 bytes.
    You need to write somewhere into the segment syou want to erase and the whole segment at this address gets set back to 0xff.

    Nick Carter said:
    For example, if I wanna erase  information memory segment C or B or A, what value should I write to the flash for the dummy write cycle?

    gpudFlash_ptrD is a pointer. The value you need to assing to it must be somewhere in the address range of the segment you want to erase. (0x1800 to 0x183f for INFOD, I think).

    If you assign a value to *gpudFlash_ptrD (note the '*' before it), it gets written to the address this pointer ponts to. The value itself is unimportant for the erase. The fact that you write trigers the erase (the flash controller picks the address from the write instruction), the value itself is ignored.

  • Hi Gross,

    Thank you for your specific and instant reply. Now I understand better on how to reading and writing the flash.

    Thanks

    Best regards,

    Nick

**Attention** This is a public forum