Hi Eric,
I would like to apologize, but I didn’t read your code carefully.
Possible issue in my previous reply doesn’t have any direct connection with your code. Please ignore it.
According your reading address 0x107F00, D-Flash part for EEEPROM is correctly formatted.
I looked again on you code and I discover that you used driver which emulated EEPROM by software.
This is quite strange solution due to fact, that S12XE family already has emulated EEPROM solved on hardware side. So, finally you have two independent emulated EEPROMs.
In fact, your code divided 32kB of D-Flash into two parts (DFPART=0x40, ERPART=0x08). So, upper 16kB of D-Flash is used for hardware EEEPROM and lower 16kB you used for software EEEPROM.
Function IEE1_Partition() partitioned D-Flash into two part during first run and it also enable hardware EEEPROM after every reset (when we call IEE1_Init).
Issue1: Function IEE1_Partition() use Full Partition D-Flash command (0x0F). This function erases whole D-flash and partition that. Unfortunately this command cannot be used in normal mode (it works only in special mode). So, correctly you should during first run erase D-Flash by command loop with Erase D-Flash Sector command (0x12) and call Partition D-Flash command (0x20).
Note: I would like to recommend also add testing address 0x107F00 for check whether D-flash part dedicated for hardware EEEPROM was formatted correctly.
Unfortunately I am not sure what could be reason for software EEEPROM failure on your side. It may be some software issue or you simply reach maximum number of write cycles into D-flash. Could you please estimate how many times you called sauv_config() function until first issue? Also information about amount of stored bytes could help to estimate whether reach maximum number of write cycles into D-flash.
Anyway, I would like to recommend use built-in hardware emulation of EEPROM. You can simply write and modify your data into Buffer RAM (0x13F800- 0x13FFFF in your case) and all these changes will be applied to nonvolatile memory on background without any CPU or XGATE intervention.
In attachment you can find short description of hardware emulated EEPROM at S12XE, and example codes.
Note: If we want wait until data are stored into D-Flash (for example prior reset), we could use command like: while((ETAG > 0) || (FSTAT_MGBUSY == 1)); //we can wait till data are stored to D-Flash
I hope it helps you.
Have a great day,
RadekS
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------