PSoC 5LP Flash/ECC memory address clarification.

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

cross mob
AnSa_1225656
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

Form the https://www.cypress.com/file/274561/download  information, it is unclear how to calculate the array ID and row for a flash write when using ECC to store data.

I assumed that like th efollowing would work, but when I read back the data from address it is offset by 128 bytes.  What am I doing wrong?

bool saveToFlash(void *address, uint8 *rowData, const int size)

{

  uint32 flsAddr = (uint32)address - CYDEV_FLASH_BASE;

  uint8 arrayId = ( uint8 )(flsAddr / (CYDEV_FLS_SECTOR_SIZE + CYDEV_ECC_SECTOR_SIZE));

  uint16 rowNum = ( uint16 )((flsAddr % (CYDEV_FLS_SECTOR_SIZE + CYDEV_ECC_SECTOR_SIZE)) / (CYDEV_FLS_ROW_SIZE + CYDEV_ECC_ROW_SIZE));

  CyWriteRowFull(arrayID, rowNum, rowData, (CYDEV_FLS_ROW_SIZE + CYDEV_ECC_ROW_SIZE));

0 Likes
1 Solution
GeonaP_26
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 50 solutions authored

Please refer to PSoC® 3, PSoC 4, and PSoC 5LP Flash Memory Organization and Array ID Parameter - KBA84740

Note that array ID calculation is same for CyWriteRowFull and CyWriteRowData. You can also refer to the code example available in PSoC Creator, File > CodeExample > Flash_Example.

The catch is flash address space and ECC bytes are not continuous. I have attached PSoC 5LP address map for you reference. CyWriteRowFull takes care of the addresses. However, user needs to take care of addresses while reading back the content. Eg: in CY8C58LP device, flash and ECC row sizes are 256 and 32 bytes continuously. The number of flash rows and ECC rows are same, i.e., 1024.

Go through to the attached code snippet to verify ECC address content in the mentioned code example,

pastedImage_1.png

        /* Compare a row from flash with the rowPattern */

        for (i = 0u; i < (CY_FLASH_SIZEOF_ROW+CY_FLASH_SIZEOF_ECC_ROW); i++)

        {

            if(i<CY_FLASH_SIZEOF_ROW)

            {

                source = (*((uint8 *) (CYDEV_FLS_BASE + CY_TEST_FLASH_ADDR + i)));

            }

            else

            {

                source = (*((uint8 *) (CYDEV_ECC_BASE + CY_TEST_FLASH_ROW* 32 +  (i - CY_FLASH_SIZEOF_ROW))));

            }

           

            /* Define destination value */

            destination = rowPattern;

            /* Check if source and destination values are equal */

            if ( source != destination)

            {

                result++;

            }

        }

View solution in original post

0 Likes
1 Reply
GeonaP_26
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 50 solutions authored

Please refer to PSoC® 3, PSoC 4, and PSoC 5LP Flash Memory Organization and Array ID Parameter - KBA84740

Note that array ID calculation is same for CyWriteRowFull and CyWriteRowData. You can also refer to the code example available in PSoC Creator, File > CodeExample > Flash_Example.

The catch is flash address space and ECC bytes are not continuous. I have attached PSoC 5LP address map for you reference. CyWriteRowFull takes care of the addresses. However, user needs to take care of addresses while reading back the content. Eg: in CY8C58LP device, flash and ECC row sizes are 256 and 32 bytes continuously. The number of flash rows and ECC rows are same, i.e., 1024.

Go through to the attached code snippet to verify ECC address content in the mentioned code example,

pastedImage_1.png

        /* Compare a row from flash with the rowPattern */

        for (i = 0u; i < (CY_FLASH_SIZEOF_ROW+CY_FLASH_SIZEOF_ECC_ROW); i++)

        {

            if(i<CY_FLASH_SIZEOF_ROW)

            {

                source = (*((uint8 *) (CYDEV_FLS_BASE + CY_TEST_FLASH_ADDR + i)));

            }

            else

            {

                source = (*((uint8 *) (CYDEV_ECC_BASE + CY_TEST_FLASH_ROW* 32 +  (i - CY_FLASH_SIZEOF_ROW))));

            }

           

            /* Define destination value */

            destination = rowPattern;

            /* Check if source and destination values are equal */

            if ( source != destination)

            {

                result++;

            }

        }

0 Likes