1 Reply Latest reply on Aug 6, 2019 4:23 AM by GeonaP_26

    PSoC 5LP Flash/ECC memory address clarification.


      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));

        • 1. Re: PSoC 5LP Flash/ECC memory address clarification.

          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,

                  /* Compare a row from flash with the rowPattern */
                  for (i = 0u; i < (CY_FLASH_SIZEOF_ROW+CY_FLASH_SIZEOF_ECC_ROW); i++)
                          source = (*((uint8 *) (CYDEV_FLS_BASE + CY_TEST_FLASH_ADDR + i)));
                          source = (*((uint8 *) (CYDEV_ECC_BASE + CY_TEST_FLASH_ROW* 32 +  (i - CY_FLASH_SIZEOF_ROW))));
                      /* Define destination value */
                      destination = rowPattern[i];
                      /* Check if source and destination values are equal */
                      if ( source != destination)