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.

CC2541 Flash write into information memory.

Other Parts Discussed in Thread: CC2541

Hi, I'm trying to store some data into the information page of the flash memory on CC2541. (I do not want to use DMA.)

My current code (which is not working...) is as follow:

EA = 0;                                 /* disable interrupts */
while (FCTL & 0x80);                    /* poll FCTL.BUSY and wait until flash controller is ready */
    FADDRH = 0x7E; //((addr >> 8) & 0x00FF);
    FADDRL = 0; //addr & 0x00FF;
FCTL |= 0x01;                           /* set FCTL.ERASE bit to start page erase */
while (FCTL & 0x80);                    /* optional: wait until flash write has completed (~20 ms) */
EA = 1;                                 /* enable interrupts */

while (FCTL & 0x80);
    FADDRH = 0x7E; //((addr >> 8) & 0x00FF);
    FADDRL = 0; //addr & 0x00FF;
    FCTL |= 0x02;
    FWDATA = 0x63;                       //random number for testing. but it always fails to write into the flash. FFFF is always returned.
    
while (FCTL & 0x80); 

//the codes below are dummy codes to make sure the complile will not optimise. hhh=1; jjj= *abcde; if (*abcde >30 && hhh>jjj) { P1DIR = 0; }

  • Hi, Based on the User guide, you should be writing 4 times to FWDATA, it looks like you are only writing once to it.

    As per the User Guide:
    "...
    3. Write four times to FWDATA within 20 μs (since the last time FCTL.FULL became 0, if not first
    iteration). LSB is written first. (FCTL.FULL goes high after the last byte.)
    4. Wait until FCTL.FULL goes low. (The flash controller has started programming the 4 bytes written in
    step 3 and is ready to buffer the next 4 bytes).
    ...
  • Hi,

    Thanks for reply. I have tried writing 4 times of same value, as well as writing 4 different values. Both did not work. The value I read out from the flash is still FFFF.

  • This is read-only memory. From the user's guide:

    "The flash information page (2 KB) is mapped into the address range (0x7800–0x7FFF). This is a read-only
    area and contains various information about the device."

    You should use the NV pages to store memory in flash, i.e. osal_snv_write(), osal_snv_read()
  • Hi, Thank you for reply.

    I'm actually following the userguide, where it says:

    6.2.1 Flash-Write Procedure
    The flash-write sequence algorithm is as follows:
    1. Set FADDRH:FADDRL to the start address. (This is the 16 MSBs of the 18-bit byte address).
    2. Set FCTL.WRITE to 1. This starts the write-sequence state machine.
    3. Write four times to FWDATA within 20 μs (since the last time FCTL.FULL became 0, if not first
    iteration). LSB is written first. (FCTL.FULL goes high after the last byte.)
    4. Wait until FCTL.FULL goes low. (The flash controller has started programming the 4 bytes written in
    step 3 and is ready to buffer the next 4 bytes).
    5. Optional status check step:
    • If the 4 bytes were not written fast enough in step 3, the operation has timed out and FCTL.BUSY
    (and FCTL.WRITE) are 0 at this stage.
    • If the 4 bytes could not be written to the flash due to the page being locked, FCTL.BUSY (and
    FCTL.WRITE) are 0 and FCTL.ABORT is 1.
    6. If this was the last 4 bytes then quit, otherwise go to step 3.
    The write operation is performed using one of two methods:
    • Using DMA transfer (preferred method)
    • Using CPU, running code from SRAM

    And I'm trying the snv_wrtie code now. I use the following codes

    uint8 Flash_Data[4];
    uint8 Flash_Data1[4];
    Flash_Data[0] = 0x53;
    Flash_Data[1] = 0x4D;
    Flash_Data[2] = 0x49;
    Flash_Data[3] = 0x54;
    VOID osal_snv_read( 0x7804, sizeof( uint32 ), Flash_Data1 );
     VOID osal_snv_write( 0x7804, 4 , Flash_Data );
     VOID osal_snv_read( 0x7804, sizeof( uint32 ), Flash_Data1 );

    After wrting, I can read the correct values. but when I comment the wrtie code and run the codes again, I can only read 0. Is there a way to keep the values in the flash?

  • You should not be passing the address to the osal_snv functions. They work using "NVID's" Please see Section 6.9 (Simple NV) of the software developer's guide included with the 1.4.1 installer.