2 Critical bugs in Emulated EEPROM component, negative effect on all users. DO NOT USE. | Cypress Semiconductor
2 Critical bugs in Emulated EEPROM component, negative effect on all users. DO NOT USE.
Just a quick heads up for everyone. (Are you listening Cypress?)
There are 2 serious bugs in the Emulated EEPROM component which make it not suitable for use in any application.
It has to do with the way the internal addresses within the flash arrays are calculated. The user has no control over these and a work around is only possible by editing the generated-source or modifying the supplied library source.
1. If the constant structure, variable or array you have defined just happens to live outside of flash array-0 then writing to it will corrupt other areas of flash. The data will get saved to the wrong flash array and could overwrite code, or configuration data.
2. If the data you are storing in flash just happens to occupy part of the last row of a flash array (again you have no control over this) then the last row will be written to the wrong flash array, which could damage code or configuration data.
I have raised tickets with Cypress for both of these issues. I have given them sample code which demonstrates the issues and I am sure a fix will be forth coming, but until then you canot use the Emulated EEPROM component.
If you are currently using this component and not suffering any bad effects, then it is only by chance - a small change to ANY part of your code could push your flash data into one of the affected areas and cause your code to behave in strange ways.
For those on PSoC 5 or PSoC 5LP here is a work around:
After you code is built and compiled, find the generated source for the Em_EEPROM_Write() method. [Its name will depend on what you names the component in the schematic, for example if your component is named 'FlashSave' then the method will be FlashSave_Write() ]
Then edit the four lines at approximately line 121 in the file and replace them with this:
rowNumber = dataAddress / CY_FLASH_SIZEOF_ROW;
arrayNumber = dataAddress / CY_FLASH_SIZEOF_ARRAY;
rowOffset = dataAddress - (CY_FLASH_SIZEOF_ROW * rowNumber);
readSrcIndex = 0u;
And then add this line immediately following the previous four:
rowNumber &= 0x000000ff;
This will allow the rowNumber and arrayNumber to be calculated properly for any address in flash.
I hope this helps.