AN1502
APPLICATION NOTE
EMULATED DATA EEPRO M WITH ST7 HDFLASH MEMORY
by Microcontroller Division Applications
INTRODUCTION
When the data EEPROM is not available in a ST7 device, it can be emulated by the HDFlash
memory with some re strictions. This App lication Note descri bes how to emulate thi s feature
with a ST72F521 device and the restrictions this emulation implies.
Data EEPROM can be emulated in all HDFlash devices.
AS HDFlash is a dual voltage FLASH memory, the 12-volt programming voltage must be
provided on the application board (a pull-down on ICPSEL on the application board is
advised).
For more i nforma tio n con cerning S T7 pr ogra mmi ng, a .z ip file is include d wi th th e c omp lete
corresponding code for the ST72F521, visit our web site at www.st.com.
AN1502/0202 1/7
1
EMULATED DATA EEPROM WITH ST7 HD FL ASH MEMORY
1 PRINCIPLE
Two different implementations can be distinguished:
■ Assuming that it is possible to limit the data EEPROM byte values to 00h..FEh (as FFh is the
default HDFlash erased value), the principle of thi s emulation is to reserve n bytes in the
HDFlash for each emulated data EEPROM byte whic h has to be cycled n times. With this
solution FFh value can not be used.
As shown in Figure 1., a “ptr” pointer gives the access to the emulated data EEPROM byte.
– For a read operation, from “ptr” address, read the first data byte not equal to FFh to get the
current value.
– For a write operation, from “ptr” address, look for the last data byte equal to FFh and then
write the new value at this location using the HDFlash “Byte programming” Embedded
Command (same as IAP method).
Figure 1. HDFlash Emulated Data EEPROM (value in 00h..FEh)
current value
INITIAL STATE
mthSTATE
■ Assuming no limitation for the data EEPROM byte values (00h..FFh), each byte value will
⇒
⇒
ptr
ptr
FFh FFh ... FFh FFh ... FFh val1
initial value
FFh FFh ... FFh valm ... val2 val1
current value
need 2 byte locations. The first one will determine if it is the current value (example: 00h =
current value, FFh = not yet used v alue) and the seco nd one will contain the c urrent byte
value. So the principle of this emulation is to reserve 2xn bytes in the HDFlash for each
emulated data EEPROM byte whi ch has to be cycled n times.
As shown in Figure 2., a “ptr” pointer gives the access to the emulated data EEPROM byte.
– For a read operation, from “ptr” addr ess, r ead the first data byte not equal to FFh (equal to
00h), the current value is the next adjacent byte.
– For a write operation, from “ptr” address, look for the last data byte equal to FFh and then
write the new value at this location and 00h in the previous location using the HDFlash
“Byte programming” Embedded Command (same as IAP method).
In both methods, the progr ammi ng is addr ess decr easing, wh ich means tha t when cu.0rrent
value is found, the next byte to be programmed is the previous one (refer to diagrams).
In the case of the ST72F521R9 (biggest product) for instance, that means that if sectors 2 and
1 are empty (FFh ), the first pro grammed byte will be at the las t address of the sec tor 1
(EFFFh), because F000h is the first address of the sector 0 containing the user program (this
sector is write protected in user mode).
2/7
2
EMULATED DATA EEPROM WITH ST7 HDFLASH MEMORY
Figure 2. HDFlash Emulated Data EEPROM (value in 00h..FFh)
ptr
INITIAL STATE
⇒
... FFh
current value
FFh 00h val1FFh FFhFFh FFhFFh FFh
initial value
mthSTATE
⇒
ptr
FFh ... 00h valm ...
FFh FFh 00h val2 00h val1
current value
2 RESTRICTIONS
■ Only a few data EEPROM bytes with a limited number of write/erase cycles can be emulated
(these characteristics are directly linked to the needed memory space in HDFlash)
■ Emulated data EEPROM must be located in sector 1 or 2 as sector 0 is write protected in
USER mode.
– To use the Embedded Commands the RASS protection must be disabled. So the protec-
tion against unintentional access to the HDFlash control register is no longer available. Unintentional programming is only guaranteed by the low probability of accidentally executing
an Embedded Command with V
at 12 volts.
PP
3 ADVANTAGE
■ The HDFlash emulated data EEPRO M method can keep the data byte value history.
3/7