M16C/62
A
PPLICATION
N
OTE
Virtual Flash EEPROM Driver for the M16C/62
1. Declaration
Mitsubishi Electric & Electronics USA does not guarantee the performance or use of this source-code.
The intended use of provided source-code is the sole responsible of the user. The files have been
successfully compiled using Mitsubishi's NC30 compiler. Before using this software review the source
and make any necessary changes to support your hardware and application.
2. Introduction
Mitsubishi's M16C/62 is a 16-bit MCU based on the M16C CPU core with 256k bytes of user flash. The
device can erase and program the on-chip flash memory under control of a user’s program with no
external programming devices required. This feature is called “CPU Rewrite Mode”.
This application note describes the usage of the accompanying program that allows the user to write to
the flash as if it were EEPROM.
3. Compatibility
The included virtual EEPROM driver is compatible with M16C/6x microcontrollers with page write (256
bytes) flash memory. It is NOT compatible with word write MCUs such as the M30220. The driver is
compatible with the above noted MCUs on any Starter Kit/evaluation system running under KD30 and the
ROM monitor. It CANNOT be evaluated or demonstrated on any emulator using RAM to emulate flash
(i.e. Mitsubishi’s PC4701, Nohau, or Ashling emulator systems).
4. Theory of operation
The C0000h and D0000h flash blocks (blocks 5 and 6) are used for the virtual EEPROM, with provisions
to switch to other blocks (see section 5 below). The D0000h is used as backup in case of a power failure
or a write error on the C0000h block. The size of the EEPROM is written to the top of both blocks. The
first call to writeEE() writes the word at the beginning of both blocks (at offset “tag”) with an “end of file”
written to the end of the EEPROM “record”. If writeEE() is called again with the same “tag”, then another
EEPROM “file” is created after the previous one and so on until the block (and the backup block) is filled.
At that point, the C0000h block is erased, the last EEPROM file in the D0000H block is copied to the start
of the C0000h block, then the D0000h block is erased and the EEPROM file is copied over to the start of
it as well. Then the process repeats. The most up-to-date data is determined as the last “end of file” in
the block.
For more detailed information on flash operations, read the application note references given at the end
of this document.
AN-DECE-MCU-31-A
February 2002
1