EEROM QUESTION  ABOUT MC9S12XET256

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

EEROM QUESTION  ABOUT MC9S12XET256

1,013 Views
zhangshweng
Contributor I

I  meet the quetion about eerom  in my project . By manual  what I would do is first write commnd 0x0f ( Full Partition D-Flash) , follow write command 0x13 (Enable EEPROM Emulation);  but ding I run  this program  phenomenon is  that by  BDM  adjut   my progam  result is ok ,   Partition for EEE is valid . but I run my program fo Full Partition in the normal mode ( get off BDM) . result is unvalid for  Partition. dflash  status still is blank (no progamed) ; why is this  ? thanks for  reply my quetion

Labels (1)
0 Kudos
Reply
2 Replies

707 Views
Martin35804
NXP Employee
NXP Employee

Hi,

In my opinion, the best way is to copy the initial data to Emulated EEPROM during the first startup of MCU. The procedure should be:

- After reset, we should check if the partition is set or not.

- If the partition is not set (that means this is first startup of MCU) then execute the Partition D-Flash command, enable emulation and then copy initial data to Emulated EEPROM (to Buffer RAM). These initial data should be stored somewhere in P-Flash memory. Do not use D-Flash for this purpose. D-Flash memory must be kept in erased state. Partition command will not work if D-Flash is not fully erased.

- If the partition has been already set then skip the partition command and skip the copying of initial data. Just enable the emulation.

Another way is to do all necessary steps by BDM/programmer device. It depends if your BDM device can execute a script or command file or something like that. After programming of the flash it would have to set the partition, enable emulation and then copy the initial data into Buffer RAM. But I still think that the first way is better.

If the emulation is enabled prior to writes to buffer RAM then the memory controller will program the data into D-Flash „immediately“ (D-Flash is slow, of course). This will save small amount of time.

Data are stored successfully in D-Flash if the ETAG register goes to „0“ and MGBUSY flag is „0“. This is a copy-paste from AN3490:

„The ETAG register holds the count of pending EEE data (new data in the EEE RAM not yet read by the memory controller). Writes to the EEE RAM automatically increment ETAG so a non-zero count always shows there is EEE data pending. The ETAG count is decremented when the memory controller reads the data from the EEE RAM, not after a record for the data has been programmed to the EEE NVM, so an ETAG count of zero alone does not indicate that all new EEE data has been programmed to the EEE NVM.

The MGBUSY flag is set during any memory controller activity. Monitoring the ETAG for a zero count

jointly with monitoring the MGBUSY flag has cleared indicates when all pending EEE data is programmed and all CCOB commands have completed.“

Code example:

while((ETAG > 0) || (MGBUSY == 1)){           /* wait for EEE to to finish */

}

In special mode (when the BDM is connected) you can do whatever you want. You can keep the original partition and just enabled Emulation and write new data into Buffer RAM. Or you can use „Full partition D-Flash command“ to set new partition (and delete whole D-Flash), enable emulation, store data...

It’s not necessary to check the written data by yourself. Also it’s very complicated because data are stored in records (address and data) and there’s implemented something like circle buffer, so we don’t know where the current data are stored.

Emulated EEPROM includes control mechanism. The only thing we need to do is check the appropriate error flags which can trigger an interrupt if needed.

See the description of FERCNFG and FERSTAT registers. There’s Erase error flag, Program error flag…

AN3490 – Overview of the MC9S12XE Emulated EEPROM:

http://www.freescale.com/files/microcontrollers/doc/app_note/AN3490.pdf

1. Emulated EEPROM:

Let’s suppose that we have written some data into Buffer RAM.

Now the ETAG register shows the number of pending words in the Buffer RAM to be programmed. All tagged words have been programmed into D-Flash once the ETAG register is 0 and the MGBUSY flag in FSTAT register is also 0. (MGBUSY flag signalize the activity of memory controller).

2. Direct access to D-Flash:

When writing into D-Flash memory through “Program D-Flash command” then the end of operation is signalized by bit CCIF (Command Complete Interrupt Flag) in FSTAT register.

0 Kudos
Reply

707 Views
kbatke
Contributor II

Very good explanation by Martin35804

To summarize...

The Flash Module command "Full Partition D-Flash" can only be executed if the MCU is in a special mode.

(see chip modes and MODC/MODB/MODA in your device manual).

When using the debugger (BDM) you are in a special mode and so the Full Partition command works.

When not using the debugger you are (probably) not in a special mode so the Full Partition command does NOT work.

0 Kudos
Reply