Emulated EEPROM requires actual initialization.

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

cross mob
VlYe_281166
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

Spent a lot of time trying to understand where is the BUG.
The reason is, if you do not really fill EEPROM array with definite values, it does not work, returning CYRET_BAD_PARAM.
Say, if you declare EEPROM array as 
    static const uint8 CYCODE eepromArray[8];
you will not be able to perform EEPROM_Write.

   

You have to fill it with any values.
    static const uint8 CYCODE eepromArray[8]= {0, 0, 0, 0, 0, 0, 0, 0};

   

then it will work.

   


IMHO, it MUST be mentioned in the manual. 

   

Tested only with PSoC 4.

   

Example to test:

   

int main()
{
    uint8 t[8]={1,2,3,4,5,6,7,8};       
    cystatus status;   
    static const uint8 CYCODE eepromArray[8]= {8, 7, 6, 5, 4, 3, 2, 0};
    static const uint8 CYCODE eepromArray1[8]= {0, 0, 0, 0, 0, 0, 0, 0};
    static const uint8 CYCODE eepromArray2[8];

   

    Em_EEPROM_Start();
          
    status = Em_EEPROM_Write(t, eepromArray,8u);              // OK
    if (CYRET_SUCCESS != status){
        SW_Tx_UART_PutString("Em EEPROM error\n\r");   
    }   
    status = Em_EEPROM_Write(t, eepromArray1,8u);           // OK
    if (CYRET_SUCCESS != status){
        SW_Tx_UART_PutString("Em1 EEPROM error\n\r");   
    }     
    status = Em_EEPROM_Write(t, eepromArray2,8u);       
    if (CYRET_SUCCESS != status){
        SW_Tx_UART_PutString("Em2 EEPROM error\n\r");   // you'll get this error 
    }       
    while(1);
}

0 Likes
1 Solution
MiKO_283856
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

Hello Kabron,

   

 

   

If you read carefully the corresponding component datasheet (V1.10A) page 4 of the pdf document:

   

"In order to force the compiler to locate data in Flash, variables/arrays should be declared as “static const (CYCODE for PSoC 3)” and initialized with some value at the same time. Reads from Flash are recommended to be done using “(volatile)” type qualifier to prevent the compiler from optimizing reads from static variables. For details on component usage please refer to Emulated EEPROM example project."

   

So Cypress has already answered your request 🙂

   

 

   

Happy New Year,

   

Michel

View solution in original post

0 Likes
4 Replies
MiKO_283856
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

Hello Kabron,

   

 

   

If you read carefully the corresponding component datasheet (V1.10A) page 4 of the pdf document:

   

"In order to force the compiler to locate data in Flash, variables/arrays should be declared as “static const (CYCODE for PSoC 3)” and initialized with some value at the same time. Reads from Flash are recommended to be done using “(volatile)” type qualifier to prevent the compiler from optimizing reads from static variables. For details on component usage please refer to Emulated EEPROM example project."

   

So Cypress has already answered your request 🙂

   

 

   

Happy New Year,

   

Michel

0 Likes

Sorry, I was not attentive.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

There is another pitfall: Under some circumstances the compiler "remembers" that the values are "const" and when accessing the flash data. it inserts the known const value instead of actually reading the values. I used a memcpy() to overcome that.

   

 

   

Bob

0 Likes

Sure, I noticed it a couple of times.

0 Likes