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

cross mob
SagginDragon
Level 2
Level 2
5 likes given 5 questions asked 5 replies posted

The saga continues lol. We've got our Em_EEPROM working, but I have a row addressing question regarding Cy_Em_EEPROM_Write(). It's recording single data points fine, but we're trying to keep a log of voltage readings.

This is what I've got right now. Every 500 loops, I'm storing an array of voltage readings from (currently) 2 ADC channels, but I want to keep the last 1000 readings, FIFO style. I'm a little confused on what to put for the first argument of Cy_Em_EEPROM_Write().

 

cy_stc_eeprom_context_t eepromContext;
cy_stc_eeprom_config_t eepromConfig =
{
	.eepromSize = DATA_SIZE,
	.simpleMode = SIMPLE_MODE,
	.wearLevelingFactor = WEAR_LEVELING,
	.redundantCopy = REDUNDANT_COPY,
	.blockingWrite = 1u,
	.userFlashStartAddr = (uint32_t)&(emEepromStorage[0u]),
};
unsigned short mVLength = 2;
uint32_t voltagemVolts[mVLength];
uint32_t mVSize = sizeof(voltagemVolts);
unsigned short cycleCount = 1; // counter for while loop cycles for logging
uint32_t FIFOCount = 0u; // counts # of values stored in memory

while(true) { // operation cycle
	// snip recording voltage into voltagemVolts	

	if (cycleCount == 500) {
		Cy_Em_EEPROM_Write(FIFOCount * mVSize, &voltagemVolts, mVSize, &eepromContext);
    		cycleCount = 0; // reset loop counter
    		if (FIFOCount == 1000)
    		{
    			FIFOCount = 0u; // reset to initial Em_EEPROM row
    		}
    		else FIFOCount++; // iterate FIFO counter
    	}

   	cycleCount++; // iterate loop counter
    }
}

 

Initially I just used FIFOCount by itself as the first argument, so it would advance one Em_EEPROM row each time it recorded, but then I started to wonder if I should make more room after iterating for the next datapoint, given that I'm writing an array of voltages. So I guessed and went, maybe I should give it the count of entries * the sizeof the array to ensure I'm advancing to the next recording row correctly. And then I started second-guessing myself and decided to get a second opinion.

0 Likes
1 Solution
Rohan136
Moderator
Moderator
Moderator
100 replies posted 25 solutions authored 10 likes received

Hi @SagginDragon ,

Changing address everytime you write data is a tedious task. Instead, store all 1000 values of voltage in another array and write all data the in a single go by calling  CY_Em_EEPROM_Write one time and give the logical address as 0.

Also, change the value of length of eeprom in linker script accordingly such that it has enough size for data and it is not overlapping with other sections of the flash.

 

Please let us know if you have more queries.

Regards,

Rohan

 

View solution in original post

4 Replies
Rohan136
Moderator
Moderator
Moderator
100 replies posted 25 solutions authored 10 likes received

Hi @SagginDragon ,

Changing address everytime you write data is a tedious task. Instead, store all 1000 values of voltage in another array and write all data the in a single go by calling  CY_Em_EEPROM_Write one time and give the logical address as 0.

Also, change the value of length of eeprom in linker script accordingly such that it has enough size for data and it is not overlapping with other sections of the flash.

 

Please let us know if you have more queries.

Regards,

Rohan

 

Yeah, you're right, that makes a lot more sense. Thanks.

0 Likes

Okay, wait a minute, how do I change the length value in the linker script?

0 Likes
Rohan136
Moderator
Moderator
Moderator
100 replies posted 25 solutions authored 10 likes received

Hi @SagginDragon ,

Search "em_eeprom" in linker script and observe if it's Length is greater than your data size. If not, change it accordingly.

P.S.: For PSOC 6, it's generally 32 KB. So no need to change the length.

 

Regards,

Rohan