2 Replies Latest reply on Feb 24, 2019 7:49 PM by XiaoweiZ_71

    How can I use the flash or sflash of a PRoC?

    AdRa_4011776

      What happens is that I tried to use EmEEPROM with PRoC and it showed me that it was not compatible with PRoC. Then I would like to know how to use FLASH as emulated eeprom.

        • 1. Re: How can I use the flash or sflash of a PRoC?
          ScottA_91

          I'm not sure you'll get much help on this, given that this is explicitly not supported by PRoC (as such official Cypress support will not help you do this) and there are equivalent PSoC chips that do support EmEEPROM.

           

          There may be a way to use the APIs to write to flash, but without the component, you'll be guessing at the memory layout and could possibly overwrite something important.  It is definitely not recommended.

          • 2. Re: How can I use the flash or sflash of a PRoC?
            XiaoweiZ_71

            Use FLASH as emulated EEPROM is possible,  you can try follow way to do that:

             

            1. Define a constant array and locate this array in fixed address use linker script.

            2. Call API CySysFlashWriteRow() defined in cyboot-->CyFlash.c to realize program data into dedicate flash row. Below is an example:

             

            #if defined (__GNUC__)

            /* Requires custom linker flags to define the section. Add custom linker flags

            * by right-clicking on the project, select "Build Settings", then under:

            * ARM GCC -> Linker -> Command Line enter the desired custom flags.

            * Add the following text (remove quotation marks):

            * "-Wl,--section-start=.array_flash_loc=0x1a00"

            * Replace 0x1a00 with your own location. Make sure it's at the start of a row. */

            #define FLASH_LOCATION __attribute__ ((section(".array_flash_loc")))

             

            static const uint8 FLASH_LOCATION E2PROM_Arrow[16u]= \

            {   0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A};

            #elif defined(__ARMCC_VERSION)   

            const uint8 E2PROM_Arrow[16u] __attribute__((at(0x00001a00))) = \

            {   0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A,0x5A};

            #endif   

             

            static uint8  u8_flashRowDataSRAM[16u] = {0u};

             

            uint8 EEPROM_Save()

            {

            uint8 i;

            uint8 temp = 0xffu;

             

            CyGlobalIntEnable;

             

            for(i = 0u; i < 16u; i++)

            {

            u8_flashRowDataSRAM[i] = flashRowDataSRAM[i] + 1;

            }

            /* Configure the Flash Writes for the current IMO clock frequency(MHz),  */

            CySysFlashSetWaitCycles(48u);

             

            temp = CySysFlashWriteRow(FLASH_ROWS_NUMBER, u8_flashRowDataSRAM);

            return(temp);

            }

             

            The side effect of using FALSH row as emulated EEPROM is when you reprogram the silicon through SWD, the EEPROM part will be erased.

             

            Using SFLASH have no such issue, you can call CySysSFlashWriteUserRow() API to write data into SFLASH row, re-program silicon won't erase SFLASH region, but SFLASH have only 4 rows, and BLE module need to use part of it to store device address and other info.