Question on PSoC4 Emulated EEPROM

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

cross mob
Doorknob
Level 4
Level 4
First solution authored 50 replies posted 25 replies posted

I have been trying to save some basic start up values (2) in a product I am developing.  There seems to be no clear simple explanation of how EEPROM works in PSoC4 or how it is used simply save a few bits of data into EEPROM and recall them again.   Every thing i have found involves a UART and error checking which for a rookie like my self is totally confusing.  I have several questions i was hoping some one could explain.  In the only example posted on Cypress site for PSoC4 Emulated EEPROM is CE195313.

1. The first question in regards to CE195313 is what does the following line of code mean, and what does it actually do?

2. Why is the variable eepromReturnValue utilized on the left side of equals, and then no were in the code is it actually utilized.  It is used several times in the C code its just not clear to me its purpose.

    UART_PutString("EmEEPROM demo \n\r");

      

    /*Read 15 bytes out of EEPROM memory*/

    eepromReturnValue = Em_EEPROM_Read(LOGICAL_EEPROM_START, eepromArray, LOGICAL_EEPROM_SIZE);

    if(eepromReturnValue != CY_EM_EEPROM_SUCCESS)

    {

        HandleError();

    }

3. In CE195313 there is also a line of code again utilizing the same variable but in this case as i understand it it only write a couple bits in EEPROM.  My question again why is the same variable "eepromReturnValue is used and also what is the purpose of and & sign in the statement of code &eepromArray[RESET_COUNT_LOCATION], RESET_COUNT_SIZE).  I have high lighted green below the code straight from the example.

        /*Only update the two count values in the EEPROM*/

        eepromReturnValue = Em_EEPROM_Write(RESET_COUNT_LOCATION, &eepromArray[RESET_COUNT_LOCATION], RESET_COUNT_SIZE);

        if(eepromReturnValue != CY_EM_EEPROM_SUCCESS)

        {

            HandleError();

        }

4. In my application I was able to save my EEPROM values as desired but I did not use the variable eepromReturnValue.  Why does this work when I do not use eepromReturnValue.  What am I not understanding.   I am storing a LED Color setting and and a Mode setting in EEPROM for recall at start up. Both of these section of code work properly i just don't understand why.

     Note: Color is 1 and LED_Color is either a 1 or 2 in value. Note i am saving the LED_Color number into EEPROM.

            if (Mode_mV > 1600)

                {

                CyDelay(100);   

                while(ADC_Calibrate());                               

                Mode_mV = ADC_ReadResult_mVolts(ADC_Ch5_Mode);

                ++LED_Color;

                eepromArray[Color]=LED_Color;

                Em_EEPROM_Write(Color,&eepromArray[Color],2);

                    if(LED_Color > Max_Colors)

                    {

                        LED_Color=1;

                        eepromArray[Color]=LED_Color;

                        Em_EEPROM_Write(Color,&eepromArray[Color],2);

                    }//End If 

**********************************************************************************************

Note: Mode is 0 and Mode_Number ranges between 1 and 10

if (Mode_mV < 3700)

                {

                CyDelay(100);   

                while(ADC_Calibrate());                               

                Mode_mV = ADC_ReadResult_mVolts(ADC_Ch5_Mode);

                ++Mode_Number;

                eepromArray[Mode]=Mode_Number;

                Em_EEPROM_Write(Mode,&eepromArray[Mode],2);

                    if(Mode_Number > Max_Modes)

                    {

                        Mode_Number=1;

                        eepromArray[Mode]=Mode_Number;

                        Em_EEPROM_Write(Mode,&eepromArray[Mode],2);

                    }//End If

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

The variable "eepromReturnValue" is used to check if the function succeeded or not,

To avoid using corrupted value(s) when reading fails and/or retry writing when writing fails.

So if you don't mind/care about error case, which I suppose does not happen often,

you can just ignore or not use this variable.

But Cypress suggest to check the return value(s) of the EEPROM related functions

to make the application reliable.

moto

P.S. We can enter an intersection without seeing the traffic light,

but seeing it is usually a good habit 😉

View solution in original post

0 Likes
3 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

The variable "eepromReturnValue" is used to check if the function succeeded or not,

To avoid using corrupted value(s) when reading fails and/or retry writing when writing fails.

So if you don't mind/care about error case, which I suppose does not happen often,

you can just ignore or not use this variable.

But Cypress suggest to check the return value(s) of the EEPROM related functions

to make the application reliable.

moto

P.S. We can enter an intersection without seeing the traffic light,

but seeing it is usually a good habit 😉

0 Likes

Thank you Moto,

For clearing this up for me as to is function...  Can you explain the seocnd part of my question as to why & funtion is used on the eepromArray?  (&eepromArray[RESET_COUNT_LOCATION], RESET_COUNT_SIZE);)

Thanks

Scott

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Scott-san,

I'm sorry for forgetting about the second part.

May be naming of eepromArray[] and array[] are confusing.

They are just memory buffers in the application program

and Em_EEPROM has its own FLASH ROM area named "Em_EEPROM_em_EepromStorage[]".

The author is writing array[] data to Em_EEPROM and

read out data is stored in eepromArray[].

About the contents/location of "Em_EEPROM_em_EepromStorage[]",

please read a discussion below?

Re: Emulated EEPROM what does ..._Write() function exactly do?

In the CE195313,

the author allocated  RESET_COUNT_SIZE(=2) bytes from eepromArray[RESET_COUNT_LOCATION(=13)]

to keep track of number of  reset and stores the data to EEPROM as a set of 2 bytes data into Em_EEPROM.

So eepromArray[13] and eepromArray[14] are used to store 16bit "reset counter" .

To provide memory address of eepromArray[13] to Em_EEPROM_Write function,

"&eepromArray[13]", which is "&eepromArray[RESET_COUNT_LOCATION]" is used.

(I wonder if I can make it clear...)

Best Regards,

13-Nov-2019

Motoo Tanaka

0 Likes