cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 6 MCU

Len_CONSULTRON
Honored Contributor

I have used the Em_EEPROM on a PSoC6.

I'm trying to preload values from a struct into the Em_EEPROM at compile-time.

I've tried different methods such as "Use emulated EEPROM = No" and it isn't working.

Attached is a simple test program.

Any suggestions?

Len

Update: 01/14/2020.

Apparently when a Cy_Em_EEPROM_Read() is performed, it is pulling the data from the EEPROM image to copy into RAM from the EEPROM_addr+0x100 bytes.

Here are some code snippets as I stepped through the code from my trouble-shooting session:

cy_en_em_eeprom_status_t Cy_Em_EEPROM_Read(uint32_t addr,  void * eepromData,  uint32_t size, cy_stc_eeprom_context_t * context)

{
  // addr = 0, eepromData = pointer to the RAM copy of the struct   size=size of the struct

     ...  //  Next curRowOffset is computed.

     curRowOffset = CY_EM_EEPROM_EEPROM_DATA_LEN + (rdAddr % CY_EM_EEPROM_EEPROM_DATA_LEN);  //curRowOffset = 0x100 (256 bytes) because of CY_EM_EEPROM_EEPROM_DATA_LEN.

     ...  // later the EEPROM image is copied to the RAM location.

     /* Copy the data to the user buffer */

     (void)memcpy((void *)(eeData),   // eeData = eepromData.

              (void *)(startRowAddr + curRowOffset),     // startRowAddr = 0  curRowOffset = 0x100

             numBytesToRead);

     ...  //EEPROM data 0x100 bytes into the EEPROM allocation is copied into the RAM.

}

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Reply
1 Solution
GeonaP_26
Moderator
Moderator

The Emulated EEPROM component stores service specific information such as checksum, sequence number etc., in the Em_EEPROM header section. Since the Emulated EEPROM data storage section contains both data and header information, it is not straight forward to initialize and load values at the compile time. Instead, user can check whether it contains the valid data in firmware and update if necessary. CE195313 PSoC Emulated EEPROM implements this flow.

To load Emulated EEPROM content at compile time, you can use the Em_EEPROM middleware in the simple mode from GitHub. It does not contain header information and consumes lesser flash area. Please refer to the documentation here​ for more details.

View solution in original post

0 Likes
Reply
5 Replies
EmHo_296241
Contributor II

Hi,

The latest Emulated EEPROM data storage contains header and data. Header stores service information stored in the EM_EEPROM memory region. Hence, it is not straight forward to load the Emulated EEPROM data storage area at compile time. Go through https://www.cypress.com/documentation/code-examples/ce195313-psoc-emulated-eeprom for reference.

The latest Emulated EEPROM data storage contains header and data. Header stores service information stored in the EM_EEPROM memory region. Hence, it is not straight forward to load the Emulated EEPROM data storage area at compile time. Go through https://www.cypress.com/documentation/code-examples/ce195313-psoc-emulated-eeprom for reference.

0 Likes
Reply
Len_CONSULTRON
Honored Contributor

EmHo,

Thanks for the reply.  Your link is not correctly formed.  Here is the correct link for those interested.  https://www.cypress.com/documentation/code-examples/ce195313-psoc-emulated-eeprom

I agree with your assessment of the issue.  There is some header info in the raw FLASH space being used for emulated FLASH.

A future improvement to Em_EEPROM component:

  • Have a new return code from the Em_EEPROM_Init() function.  This new return code indicates the initialization was successful but the EEPROM is detected to be "blank".  Testing for the new return code would allow me to load the default values into EEPROM before executing the Application.
  • Have a new initialization function Em_EEPROM_Init_w_def( uint32 startAddress, const uint32 *default_vals).  The new argument "default_vals" allows the loading of the default values if the EEPROM is found to be "blank" during the initialization process.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Reply
Len_CONSULTRON
Honored Contributor

To all,

I have a potential solution to my question.  It appears to work "now".  Future component changes might make it invalid.

The solution is after the _Init() function, to perform a _NumWrites() function.  If the return from NumWrites() == 0, then the EEPROM is blank.

If the EEPROM blank, then perform a _Write() with the default data from a FLASH memory area.  This loads these values and increments the NumWrites count to 1.

Later after further program reset/restarts, the _NumWrites() >  0 and a forced load of default values does not occur.

Of course, if you need to modify the EEPROM due to application conditions, you can perform an Application _Write() and the NumWrites count > 1.

Attached is a simple example project with this code.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Reply
GeonaP_26
Moderator
Moderator

The Emulated EEPROM component stores service specific information such as checksum, sequence number etc., in the Em_EEPROM header section. Since the Emulated EEPROM data storage section contains both data and header information, it is not straight forward to initialize and load values at the compile time. Instead, user can check whether it contains the valid data in firmware and update if necessary. CE195313 PSoC Emulated EEPROM implements this flow.

To load Emulated EEPROM content at compile time, you can use the Em_EEPROM middleware in the simple mode from GitHub. It does not contain header information and consumes lesser flash area. Please refer to the documentation here​ for more details.

View solution in original post

0 Likes
Reply
Len_CONSULTRON
Honored Contributor

EmHo and GeonaM,

Thanks for replying.  It appears I have multiple choices depending on what suits my application.

I can use the Em_EEPROM in raw (simple) mode. Using this everything is managed by me..

I can use the Em_EEPROM with the benefits provided by the middleware layer that incorporates a CRC validation and allow for wear-leveling.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
Reply
Top labels