PSoC 4 Em_EEPROM Write in Deep Sleep Mode

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

cross mob
user_2581831
Level 2
Level 2
10 sign-ins 5 questions asked First solution authored

Hi,

I'm trying to write a data to Em_EEPROM in Deep Sleep Mode, but when the data is written to the EEPROM after CySysPmDeepSleep() function is called, the program fails to read the written data to the EEPROM when the  CPU is re-powered again. But there's no problem when reading data from EEPROM when the data is written in NOT Deep-Sleep Mode. I'm using Debug without Programming option on PSoC Creator interface to watch the EEPROM data. 

According to the EM_EEPROM Component Datasheet,

cy_en_em_eeprom_status_t Cy_Em_EEPROM_Write (uint32 addr, void *eepromData,
uint32 size, cy_stc_eeprom_context_t *context)
This function takes the logical EEPROM address and converts it to the actual physical
address and writes data there. If wear leveling is implemented, the writing process will use
the wear leveling techniques. This is a blocking function and it does not return until the
write operation is completed. The user firmware should not enter Hibernate mode until
write is completed. The write operation is allowed in Sleep and Deep-Sleep modes.
During the flash operation, the device should not be reset, including the XRES pin, a
software reset, and watchdog reset sources. Also, low-voltage detect circuits should be
configured to generate an interrupt instead of a reset. Otherwise, portions of flash may
undergo unexpected changes.

It says that the write operation is allowed in Sleep and Deep-Sleep modes. But I've encountered a problem about that.

Here's the code block that I've written.

//----------Main  Program--------------------//

switch(powerModeStatus)
{
case PM_CPU_DEEP_SLEEP:
powerModeStatus = NO_OPERATION;
CySysWdtDisable();
CapSense_Sleep();
RTCTimer_Sleep();
CySysPmDeepSleep();
WriteEEPROM();
break;

case EXIT_LOW_POWER_MODE:
RTCTimer_Wakeup();
CapSense_Wakeup();
CapSense_Start();
CapSense_ScanAllWidgets();
CapSense_CSDCalibrateWidget(CapSense_BTN1_WDGT_ID,70);
CapSense_CSDCalibrateWidget(CapSense_BTN2_WDGT_ID,70);
CapSense_CSDCalibrateWidget(CapSense_BTN3_WDGT_ID,70);
CapSense_CSDCalibrateWidget(CapSense_BTN4_WDGT_ID,70);
CapSense_CSDCalibrateWidget(CapSense_BTN5_WDGT_ID,70);
CySysWdtEnable();
programStatus = PROGRAM_START;
break;

case NO_OPERATION:
/* CY_NOP */
break;
}

//--------------------------------------------------------------------Interrupt Handler------------------------------------------------------------------//

portInterruptTrigger = ZeroCrossPort_ClearInterrupt();
if(portInterruptTrigger == 1)
{
zeroCrossCounter = 0;
powerModeStatus = EXIT_LOW_POWER_MODE;
ZeroCrossRisingEdgeFlag = 1;
}

//------------------------------------------------------------------------RtcTimer-----------------------------------------------------------------------------//

void ZeroCrossControl()
{
zeroCrossCounter++;
if(zeroCrossCounter == MAX_DELAY_50HZ)
{

programStatus = PROGRAM_SLEEP;

powerModeStatus = PM_CPU_DEEP_SLEEP;
}

I'm using Em_EEPROM_Write (inside WriteEEPROM() function) and Em_EEPROM_Read functions when reading and write data to the EEPROM.

I call the Em_EEPROM_Read() function before the starting the main code to read the stored variable. 

I'll be appreciated if you illuminate me,

Thanks.

0 Likes
1 Solution
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi,

Technically we cannot write to flash/Em_eeprom in deep sleep. Reasons –

  1. Flash operation needs high speed clock (usually IMO or higher)
  2. Flash operation needs higher load core voltage regulators (usually in mA) – the ones in deep sleep are not meant for larger loads.
  3. Flash write operation usually involves a CPU or co-processor or a controller that performs the operation – M0/M0+ in PSoC 4/6

 

Technically even for giving the flash write command we need to be awake. And in PSoC 4, the flash writes are blocking. Even if it is non-blocking, we cannot or rather should not enter deep sleep.

We are not sure why the component datasheet mentions like that, we will check with the internal team and correct it accordingly.

Regards

 

Alakananda

View solution in original post

0 Likes
5 Replies
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi,

Can you please let us know if you are writing in deep sleep?

As we see you are writing after wake up.

Also if you have the debugger attached then the system wont enter deep sleep, can you please check this at your end.

Can you also do UART prints and check at your end.

Regards

Alakananda
0 Likes

Hi,

It seems correct that I'm doing a mistake when to write data to the EEPROM as you said and according to my test result.

My goal is to write data to the EEPROM when the CPU is in Deep Sleep Mode. So I basicly call the Em_EEPROM_Write function after CySysPmDeepSleep() function. But It seems that after CySysPmDeepSleep() function is called, Em_EEPROM_Write function is not executed. But according to the EEPROM component datasheet for Em_EEPROM_Write function, The write operation is allowed in Sleep and Deep-Sleep modes. That makes me confused actually.

I'll be appreciated if you illuminate me,

Thanks.

 

0 Likes
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi,

In debug mode, PSoC will not go to deepsleep.

As we can see in your code,

If you call EEPROM_Write after the CPU wakes up, can you let us know how you are writing when the device is in sleep?
When you do this,
CySysPmDeepSleep();
WriteEEPROM();
You are coming out of deep sleep and writing.
 
Can you do like this and check if it works
WriteEEPROM();
CySysPmDeepSleep()
 
Regards
 
Alakananda
0 Likes
user_2581831
Level 2
Level 2
10 sign-ins 5 questions asked First solution authored

Hi,

It works fine when doing this,

WriteEEPROM();
CySysPmDeepSleep()
 
But the thing that I don't understand and couldn't implement is that writing data when the CPU is in sleep mode. In the above code, the program calls the EEPROM function before CySysPmDeepSleep() function is executed. So, according to the my understanding,  the data is  written to the EEPROM when the CPU is not in sleep mode because  the sleep mode function is called after writing process is completed. I want to implement writing process when the CPU is in sleep mode. 
 
Regards.
 
 
 
 
0 Likes
Alakananda_BG
Moderator
Moderator
Moderator
50 likes received 250 sign-ins 250 replies posted

Hi,

Technically we cannot write to flash/Em_eeprom in deep sleep. Reasons –

  1. Flash operation needs high speed clock (usually IMO or higher)
  2. Flash operation needs higher load core voltage regulators (usually in mA) – the ones in deep sleep are not meant for larger loads.
  3. Flash write operation usually involves a CPU or co-processor or a controller that performs the operation – M0/M0+ in PSoC 4/6

 

Technically even for giving the flash write command we need to be awake. And in PSoC 4, the flash writes are blocking. Even if it is non-blocking, we cannot or rather should not enter deep sleep.

We are not sure why the component datasheet mentions like that, we will check with the internal team and correct it accordingly.

Regards

 

Alakananda
0 Likes