Initializing the EEPROM Space in PSoC® 1 – KBA92309

Version: **

 

Question: How do you initialize the EEPROM space in PSoC® 1?

 

Answer:

To initialize the E2PROM space in PSoC 1:

In the following example, the name of the E2PROM user module is “E2PROM_1”. The E2PROM occupies 128 bytes of flash in block numbers 126 and 127 in a device with 8K of flash. The first two bytes of the E2PROM have to be initialized with a revision number that is a 16-bit integer, the next 96 bytes have to be filled with ‘0’, and the next 8 bytes have to be filled with the integers ‘0’ through ‘7’.

  1.   Modify the custom.lkp file  

       Open the custom.lkp file in the project folder. If the project does not contain a custom.lkp file, create a file named custom.lkp. Add the following line at the bottom of the file:

     

       -b<E2PROM_USER_MODULE_NAME>_AREA:<E2PROM_START_ADDRESS>.<E2PROM_END_ADDRESS>
      

     

       For our example the following text should be added into the custom.lkp file:

     

       -bE2PROM_1_AREA:0x1F80.0x1FFF

  2.   Modify the E2PROM User Module:  

       - Lock the E2PROM_1 User Module (Right-click the User Module and select Lock).

     

       - Open the E2PROM_1.asm file and comment the following code line:

     

       ORG E2PROM_1_START_ADDR

  3.   Initialize the E2PROM flash space.  

       - Assembly language

     

       FW_VERSION: equ 1010h

     

       RESERVED_SPACE: equ 60h

     

       AREA E2PROM_1_AREA (ROM,ABS,CON))

     

       DW FW_VERSION ; the first two locations in block

     

       BLK RESERVED_SPACE; skip 96 bytes

     

       DB 0, 1, 2, 3, 4, 5, 6, 7; the array starts at the 98th byte of the E2PROM flash block

     

       - C language

     

       #define FW_VERSION 0x1010

      #define RESERVED_SPACE 0x60
     

       #pragma lit_abs_address: E2PROM_1_START_ADDR
       __flash WORD Version = FW_VERSION;
       __flash BYTE EmptyArray[RESERVED_SPACE] = {0};
       __flash BYTE InitData[] = {0, 1, 2, 3, 4, 5, 6, 7};
       #pragma end_abs_address