CYBLE-012011 SFLASH

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
HeGi_2497906
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

bob.marlowegyan

I need a simple set of commands to write a 32bit value to the SFLASH on my PROC-012011 module.  This is too store the users selected pairing code.  I need to be able to write, read and clear the 32 bit value, this is rather urgent, and the documentation is not clear.

Is there a simple SFLASH example for one 32 bit word?

0 Likes
1 Solution
KevinR_91
Employee
Employee
25 replies posted 10 likes received 10 replies posted

Herb,

Here is a routine I wrote a while back for a project, it uses the last user row of SFLASH to store data, should be easy to modify to 32bit value, my example shows 8bit and 16 bit variables being stored and read back from SFLASH.

/* Defines last ROW of SFlash */
#define CY_TEST_SFLASH_ROW       (CY_SFLASH_NUMBER_USERROWS - 1u)
/* Defines absolute address of ROW */
#define CY_TEST_SFLASH_ADDR      (CY_SFLASH_USERBASE + CY_TEST_SFLASH_ROW * CY_SFLASH_SIZEOF_USERROW)
/* FLAG indicating flash write occurred */
#define FLASH_WRITE_FLAG    0xAA

uint8 A;

uint8 B;

uint8 C;

uint8 D;

uint8 E;

uint8 F;

uint16 G;

void updateFlashValues(void)

{

        /***********************************************************************

        * Erases a row of SFlash and programs it with the rowPattern.

        * Comment line below and program the hex file into the target device

        * to check if SFlash dataRow is available after device reprogramming.

***********************************************************************/

        uint8 flashArray[CY_SFLASH_SIZEOF_USERROW];

       

        flashArray[0] = A;

        flashArray[1] = B;

        flashArray[2] = C;

        flashArray[3] = D;

        flashArray[4] = E;

        flashArray[5] = F;

        flashArray[6] = (uint8)G;

        flashArray[7] = (uint8)(G >> 8);

   

CySysSFlashWriteUserRow(CY_TEST_SFLASH_ROW, flashArray);       

      

}

void readFlashValues(void)

{

        /* Define source value */

        A = (*((uint8 *) (CY_TEST_SFLASH_ADDR)));

        B = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 1)));

        C = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 2)));

        D = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 3)));

        E = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 4)));

        F = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 5)));

        G = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 7))); 

        G = (G << 8 )|(*((uint8 *) (CY_TEST_SFLASH_ADDR + 6)));

}

View solution in original post

0 Likes
1 Reply
KevinR_91
Employee
Employee
25 replies posted 10 likes received 10 replies posted

Herb,

Here is a routine I wrote a while back for a project, it uses the last user row of SFLASH to store data, should be easy to modify to 32bit value, my example shows 8bit and 16 bit variables being stored and read back from SFLASH.

/* Defines last ROW of SFlash */
#define CY_TEST_SFLASH_ROW       (CY_SFLASH_NUMBER_USERROWS - 1u)
/* Defines absolute address of ROW */
#define CY_TEST_SFLASH_ADDR      (CY_SFLASH_USERBASE + CY_TEST_SFLASH_ROW * CY_SFLASH_SIZEOF_USERROW)
/* FLAG indicating flash write occurred */
#define FLASH_WRITE_FLAG    0xAA

uint8 A;

uint8 B;

uint8 C;

uint8 D;

uint8 E;

uint8 F;

uint16 G;

void updateFlashValues(void)

{

        /***********************************************************************

        * Erases a row of SFlash and programs it with the rowPattern.

        * Comment line below and program the hex file into the target device

        * to check if SFlash dataRow is available after device reprogramming.

***********************************************************************/

        uint8 flashArray[CY_SFLASH_SIZEOF_USERROW];

       

        flashArray[0] = A;

        flashArray[1] = B;

        flashArray[2] = C;

        flashArray[3] = D;

        flashArray[4] = E;

        flashArray[5] = F;

        flashArray[6] = (uint8)G;

        flashArray[7] = (uint8)(G >> 8);

   

CySysSFlashWriteUserRow(CY_TEST_SFLASH_ROW, flashArray);       

      

}

void readFlashValues(void)

{

        /* Define source value */

        A = (*((uint8 *) (CY_TEST_SFLASH_ADDR)));

        B = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 1)));

        C = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 2)));

        D = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 3)));

        E = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 4)));

        F = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 5)));

        G = (*((uint8 *) (CY_TEST_SFLASH_ADDR + 7))); 

        G = (G << 8 )|(*((uint8 *) (CY_TEST_SFLASH_ADDR + 6)));

}

0 Likes