AN-1452
APPLICATION NOTEOne Technology Way • P.O. Box 9106 • Norwood, MA 02062-9106, U.S.A. • Tel: 781.329.4700 • Fax: 781.461.3113 • www.analog.com

ADuCM3027/ADuCM3029 Flash EEPROM Emulation
INTRODUCTION
Nonvolatile data storage is a necessity in many embedded
systems. Data, such as bootup configuration, calibration
constants, and network related information, is normally stored
on an electronically erasable programmable read only memory(EEPROM) device. The advantage of using the EEPROM to store
this data is that a single byte on an EEPROM device can be
rewritten or updated without affecting the contents in the otherlocations.
The ADuCM3027/ADuCM3029 are ultra low power
microcontroller units (MCUs) with integrated flash memory.
The ADuCM3027/ADuCM3029 include 512 kB of embedded
flash memory with a 72-bit wide data bus that provides two
32-bit words of data and one corresponding 8-bit error
correction code (ECC) byte per access. The ECC check is enabled
by default for the user space on the ADuCM3027/ADuCM3029
and provides assurance that the flash initialization function works
as expected. The ECC check is enabled for the entire user spacein the flash of the ADuCM3027/ADuCM3029. If there are ECC
errors reported during any read operation, the ECC engine
automatically corrects 1-bit errors and only reports on detection of
2-bit errors. When a read occurs on the flash, appropriate flags
are set in the status register of ADuCM3027/ADuCM3029. If
interrupts are generated, the source address of the ECC error

causing an interrupt is available in the FLCC0_ECC_ADDR
register for the interrupt service routine (ISR) to read.
Emulation of the EEPROM on the integrated flash reduces thebill of material (BOM) cost by omitting the EEPROM in thedesign. Therefore, the software complexity is also reduced.

BACKGROUND
Flash memory is typically organized as an array of pages. A
single page in the ADuCM3027 is 2 kB. The contents of thepage must be erased before writing data. The erase operation isuniversal to the page, whereas the read or write can be
performed on a single addressable location (byte or word).
The challenges of performing the read or write on a single
addressable location are as follows:••

Byte wide data read and write operations.
The ability to erase or update data at any location while
retaining data at other locations because flash memory
erase operates on an entire page.

This application note describes the software using the
ADuCM3027/ADuCM3029 devices and the built in flash
memory to emulate EEPROM, as shown in Figure 1.

FLASH
INTERFACE
CORE

15618-001

EEPROM

ADuCM3027/
ADuCM3029

Figure 1. ADuCM3027/ADuCM3029 Internal Flash and EEPROM System Overview

Rev. A | Page 1 of 9

AN-1452

Application Note

TABLE OF CONTENTS
Introduction ...................................................................................... 1

EEPROM ........................................................................................3

Background ....................................................................................... 1

Flash ................................................................................................5

Revision History ............................................................................... 2

Limitations .........................................................................................7

Working Principle............................................................................. 3

Conclusion..........................................................................................8

REVISION HISTORY
6/2018—Rev. 0 to Rev. A
Changes to Introduction .................................................................. 1
Changes Figure 2, Initialize EEPROM Section, and Write
EEPROM Section.............................................................................. 3
Change to Read EEPROM Section and Figure 3 .......................... 4
Changes to Figure 4, Figure 5, and Flash Section......................... 5
Change to Limitations Section........................................................ 7
Changes to Conclusion Section, Table 1, Table 2, Table 3, andTable 4 ................................................................................................ 8
Changes to Table 5, Table 6, and Table 7 ....................................... 9
3/2017—Revision 0: Initial Version

Rev. A | Page 2 of 9

Application Note

AN-1452

WORKING PRINCIPLE
USER CODE

write_eeprom8(addr, data)

read_eeprom8(addr)

erase_eeprom8()

pack_lower_data()

find_current_sector()move2nextsector()

EEPROM DRIVER pack_upper_data()

update_tag()move2nextpage()

FLASH FUNCTIONS
read_flash(addr)

erase_flash(page_number)

15618-002

write_flash(addr, data)

Figure 2. ADuCM3027/ADuCM3029 Flash EEPROM Emulation Software Structure

EEPROM emulation requires a dedicated portion of the flash
memory. Most EEPROMs can update one byte in one write
command. However, flash memory devices are equipped withmultibyte, a writing capability, and update the data accordingly,
only if erase sequences are followed between two write
operations. To emulate a byte writable and readable EEPROM
in the flash memory, it is necessary to follow a read, modify,
write sequence, which is similar to EEPROM operation.
The procedure presented in this section uses two flash pages
that can be extended to more than two pages, which are thendivided into sectors consisting of a sector tag. This sector tag
provides information about the current sector under process
and number of data bytes written onto that sector. Note that thelast location in every sector is reserved for the sector tag, which
has a size that is equal to the data bus size of the flash memory.
The sector size and the number of sectors in a flash page
depends on the size of the emulated EEPROM.

EEPROM
EEPROM writing and reading functions involve the processingof the application code input, such as EEPROM data and address
information. The EEPROM application programming interface(API) handles processing and presenting the data and address
information per the requirements of the flash interface.

details regarding the init_eeprom(uint16_t eeprom_size, uint8_t
word_length) function.

Write EEPROM
Figure 3 shows the EEPROM write operation flowchart. The
EEPROM write operation procedure is as follows:
1.

2.

3.

4.

Initialize EEPROM
The initialize EEPROM operation defines the size of the
EEPROM and word length of the data in an EEPROM to beemulated. The maximum size of the emulated EEPROM is 2 kB(one flash page) because two flash pages are reserved for
EEPROM emulation in this application software to keep theintegrity of the data. This limit can be increased if the same
application software is extended from reserving two flash pages toreserving four flash pages. Users have a configurable word length
ranging from 8-bits to a maximum of 64-bits. See Table 1 for

5.

Find the current sector by using the find_current_sector()function call. This search is based on the sector tag and thecorresponding sector tag value; the value returned is thecurrent sector start address (which is a physical location on
the flash memory).
Convert the EEPROM address to the flash address with thehelp of the current sector start address. Because the
ADuCM3027/ADuCM3029 flash memory has a 72-bit
wide data bus and the emulated EEPROM has an 8-bit
wide data bus, the software determines the number ofshifts required using the EEPROM address.
Read the data at the obtained flash address and if the datais equal to 0xFF, then the data to be written is first packed into
two 32-bit data (pack_lower_data() and pack_upper_data())
and a 64-bit wide data is prepared to be written onto flash
memory.
Execute a write command on the flash controller by callingthe write_flash() function. The input parameters for thisfunction are the flash memory address, the least significant
bit (LSB) data packet, and the most significant bit (MSB)
data packet.
After the write operation to the flash memory is complete,
the sector tag of the current sector is updated by calling the
update_tag() function.

If data is already present at the obtained flash address, the dataread function does not return 0xFF. In this case, the data before
and after the obtained flash address is moved to the next or
adjacent sector by calling the move2nextsector() function. The
EEPROM data, which is converted to LSB and MSB data

Rev. A | Page 3 of 9

AN-1452

Application Note

packets, is written at the new flash address on the next sector.
Thus, every time a write is issued at an already written locationof the EEPROM, the data is moved to the next sector with thelocation containing modified data.

POWER-ON RESETINITIALIZE SYSTEM

If the new sector resides on the next page, a flash page erasecommand is issued by calling erase_flash(page_number) to theprevious page after the data is moved. All the address registers
are updated by the move2nextpage() function.

INITIALIZE FLASH FOR
EEPROM EMULATIONAPPLICATION CODE

See Table 2 for details regarding the write_eeprom(uint16_t
addr_eeprom, uint8_t data_eeprom) function.

write_eeprom(addr, data)

Read EEPROM
Figure 4 shows the EEPROM read operation flowchart. The
EEPROM read operation procedure is as follows:

2.

3.
4.

Read the EEPROM value stored at the address location bycalling the read_eeprom(addr) function.
In an EEPROM read request from the application code, thesoftware first determines the current sector, which consistsof the latest data. A flash address is obtained using the
EEPROM address and current sector start address.
Execute a read command by calling the read_flash()function with the obtained flash address.
Process the 64-bit wide data received from the flash
address. The bits of this address are then masked, rightshifted, and provided to the application code.

See Table 3 for details regarding the read_eeprom(uint16_t
addr_eeprom) function.

CONVERT EERPOMADDRESS TO
FLASH ADDRESSREAD THE CURRENT DATAAT FLASH ADDRESSIS DATA =
0xFF?

YES

MOVE TO NEXT SECTOR
IN THE FLASH

pack_lower_data()

pack_upper_data()NO

MOVE THE DATA FROM STARTADDRESS OF THE CURRENTSECTOR TO THE FLASH ADDRESSOF THE NEXT SECTOR

write_flash()

UPDATE THE DATA AT FLASHADDRESS IN THE NEXT SECTOR

update_tag()

update_tag()

MOVE THE REMAINING DATAAFTER FLASH ADDRESS FROMCURRENT SECTOR TO THE
NEXT SECTORYESIS NEW
SECTORON NEXTPAGE?

NOERASE PREVIOUS PAGE

move2nextpage()

Figure 3. EEPROM Write OperationRev. A | Page 4 of 9

15618-003

1.

find_current_sector()

Application Note

AN-1452
Erase EEPROM

POWER-ON RESET

Figure 5 shows the EEPROM erase operation flowchart. The
EEPROM erase operation is as follows:
1.

INITIALIZE SYSTEM

Erase the entire EEPROM space allotted in the flash
memory by calling the erase_eeprom() function.
POWER-ON RESETINITIALIZE FLASHFOR EEPROM EMULATIONINITIALIZE SYSTEMAPPLICATION CODE

read_eeprom(addr)
INITIALIZE FLASH FOR
EEPROM EMULATIONAPPLICATION CODE

find_current_sector()

erase_eeprom()

ERASE ALL THE PAGES IN THE
ALLOTED FLASH MEMORYREAD THE CURRENT DATAAT FLASH ADDRESS

15618-005

CONVERT EEPROM ADDRESSTO FLASH ADDRESS

Figure 5. EEPROM Erase Operation

All the pages in the flash memory dedicated to EEPROM
emulation are erased. Therefore, exercise caution while using
this operation in the application code.

PROCESS 64-BIT DATA TO RECEIVE
THE REQUIRED EEPROM DATA

See Table 4 for details regarding the erase_eeprom() function.

Figure 4. EEPROM Read Operation

15618-004

FLASH
RETURN VALUE

The ADuCM3027/ADuCM3029 processors include 128 kB and
256 kB of embedded flash memory, which are available foraccess through the flash controller. The embedded flash
memory has a 72-bit wide data bus, providing two 32-bit wordsof data and one corresponding 8-bit ECC byte per access. The
memory is organized in pages of 2 kB each, plus 256 bytes
reserved for the ECC. ECC is, by default, enabled on the entire
user space of flash in the ADuCM3027/ADuCM3029. A write
to a location of flash updates the data as well as the ECC byte onthat location. Because flash memory cannot change the bit value
from Logic 0 to Logic 1 without an erase procedure, only one
write operation is allowed. Therefore, ECC bytes update just
one time. The next write to the same location without an erase
procedure leads to ECC error generation.

Flash Write
The flash memory operates by setting bits to 1 when erased, andselectively clearing bits to 0 when writing (programming) data.
No write operation is capable of setting any bit to 1 from 0. For
this reason, generalized write accesses must be prefixed by anerase operation.
Rev. A | Page 5 of 9

AN-1452

Application Note

A keyhole write is an indirect write operation in which the user
code programs memory mapped registers with target addressand data values, then commands the flash controller to perform awrite operation in the background. The flash controller supports
write access to the flash memory only through keyhole writes.
This constraint on write access enables the flash controller toguarantee that writes occur properly as atomic double word
(64-bit data) operations.

Flash Erase
When there is a page change during an EEPROM write, a pageerase command is asserted on the previous page by calling theerase_flash(page) function. Before a page erase, data movement
occurs as explained in the Write EEPROM section.
See Table 6 for details regarding the erase_flash(uint8_t PAGE)
function.

Flash Read

LSB and MSB data packets that are created using EEPROM data
are provided to keyhole data registers. After the assertion of awrite command, the flash controller initiates a 64-bit data dual
word write to the given flash address.

Flash memory is available to be read only after an automatic
initialization process. Reading the flash memory returns a 64-bit
data double word.

Note that word (32-bit), half word (16-bit), and byte (8-bit)
writes are not supported.

Flash address information is provided to the flash controller,
which returns read data. This data is further processed by the
EEPROM interface to achieve the EEPROM value.

See Table 5 for details regarding the write_flash(uint32_t addr,
uint32_t lower_data, uint32_t upper_data) function.

See Table 7 for details regarding the read_flash(uint32_t addr)
function.

Rev. A | Page 6 of 9

Application Note

AN-1452

LIMITATIONSIn real EEPROMs, if one location is updated, only one erase
cycle is counted, followed by a write operation to that particularaddress while other locations remain unchanged.
In this emulated EEPROM, updating one location causes
movement of data from the current sector to the next sector
that consumes the EEPROM size number of write cycles.
Therefore, every time a location is updated, data is moved to thenext sector and, if that sector resides on the next page, a pageerase occurs. This behavior decreases the effective endurance ofthe flash memory.

To overcome these limitations,••Rev. A | Page 7 of 9

Use caution when selecting the EEPROM size for
emulation. A small EEPROM size decreases the write
cycles during data movement, which indirectly increases
the endurance of the flash memory.
Avoid unnecessary writes to the EEPROM. By doing so, theeffective endurance of the flash memory increases. For
example, the system must issue writes only during a power
fail sequence. A RAM buffer can be used for storing thedata during normal operations. Note that the software
handles some of the unnecessary writes to the emulated
EEPROM. For example, if the data to be written is 0xFF andthe current data at that particular location is 0xFF, no write
is issued to the flash memory.

AN-1452

Application Note

CONCLUSION
The application note intends to match the physical difference
between the EEPROM and the flash memory using the
ADuCM3027/ADuCM3029. This emulated EEPROM is similar
to a real EEPROM that overcomes the problems related to, forexample, silicon area, input and output bus resources, andmanufacturing costs.
This application note provides the user with a large EEPROM
size (from 8 bytes to 2 kB (one page)) because this application
software reserves two flash pages for EEPROM emulation. If thesoftware is extended to four flash pages, the maximum EEPROM
size is 4 kB with a configurable word length of 8 bits to 64 bits.
Because there is a trade-off between the size of the emulated
EEPROM and the endurance of the flash memory, select theappropriate size to enhance the hardware efficiency. In addition
to this approach, the software handles some of the unnecessary
writes to the ADuCM3027/ADuCM3029 flash device, which
effectively increases the endurance.

Table 1. Initialize EEPROM Function Description—init_eeprom(uint16_t eeprom_size, uint8_t word_length)
Parameter
eeprom_size

Description
Size of the EEPROM to emulate.

word_length

Length of the data word to be written in the emulated EEPROM.
Valid values are 8, 16, 32 or 64.

Return ValueNo error. Write complete.
Error. The given address is out of the available EEPROM
memory space.
No error. Write complete.
Error. The given address is out of the available EEPROM
memory space.

Table 2. Write EEPROM Function Description—write_eeprom(uint16_t addr_eeprom, uint8_t data_eeprom)1
Parameter
addr_eeprom

Description
Logical address in the EEPROM space where data is written.

data_eeprom

Data written to the EEPROM space, pointed by addr_eeprom.

1

Return ValueNo error. Write complete.
Error. The given address is out of the available EEPROM
memory space.
No error. Write complete.
Error. The given address is out of the available EEPROM
memory space.

This function writes data to the EEPROM.

Table 3. Read EEPROM Function Description—read_eeprom(uint16_t addr_eeprom)1
Parameter
addr_eeprom
1

Description
Logical address in the EEPROM space where data is read.

Return Value
Value. The 8-bit data is returned to the application code.
Error. The given address is out of available EEPROM memory space.

This function reads data from the EEPROM.

Table 4. Erase EEPROM Function Description—erase_eeprom()1Parameter
Not applicable
1

Return ValueNo error. Erase complete.
Error. The flash controller is busy and cannot perform the erase action.

This function erases the EEPROM memory space. All the data is lost if this function is called.

Rev. A | Page 8 of 9

Application Note

AN-1452

Table 5. Write Flash Function Description—write_flash(uint32_t addr, uint32_t lower_data, uint32_t upper_data)1
Parameter
addr

Description
The address in the flash memory space allotted
for the EEPROM emulation.

lower_data

The lower 32 bits of the double word.

upper_data

The highest 32 bits of the double word.

1

Return ValueNo error. Write complete.
Error. The given address is out of the available EEPROM memory space.
Not applicable.
No error. Write s complete.
Error. The given address is out of the available EEPROM memory space.
Not applicable.
No error. Write complete.
Error. The given address is out of the available EEPROM memory space.
Not applicable.

This function receives the translated EEPROM address and data from the write_eeprom() function and issues a write command to the flash controller.

Table 6. Erase Flash Function Description—erase_flash(uint8_t PAGE)1
ParameterPage
1

Description
The page number of the allotted flash memory space.

Return ValueNo error. Page wise erase complete.
Error. The given page value is out of the allotted flash memory space.

This function performs a page wise erase in the allotted flash memory space.

Table 7. Read Flash Function Description—read_flash(uint32_t addr)1
Parameter
addr

1

Description
The address in the flash memory space allottedfor EEPROM emulation.

Return Value
Read data. The data available at the desired address is returned to thefunction.
Error. The translated address is out of the allotted flash memory space.

This function receives the translated EEPROM address from the read_eeprom() function and issues a read command to the flash controller.

©2017–2018 Analog Devices, Inc. All rights reserved. Trademarks andregistered trademarks are the property of their respective owners.
AN15618-0-6/18(A)Rev. A | Page 9 of 9