
Easy R8C/M16C/M32C/R32C Flash Programming
This document will provide a basic understanding of how the R8C/M16C/M32C/R32C family of
microprocessors can be programmed with new flash contents. To make things easier, we'll refer to any
of these chips as "the chip" unless we're talking about a specific one. We refer to the machine
providing the programming signals as "the host" regardless of how these signals are generated (serial
port, USB, something else).
The simplest method to program from a host is the asynchronous serial mode, often called "serial mode
2". This mode lets you use a standard serial port, such as is found on most PCs, and two jumpers. One
jumper is for nRESET, and the other is for the MODE or CNVss pin (different chips call them different
things, we'll use MODE in this document). In addition, each chip may have other pins which must be
pulled high or low for this mode; check the chip's hardware manual for details. Usually a high-valued
resistor is sufficient for these pins. The serial pins on the chip are TTL logic, not RS-232 logic. You'll
need a converter to connect to a standard serial port, or use a TTL-level USB-to-serial cable like
FTDI's TTL-232R (5 volts) or TTL-232R-3V3 (3.3 volts). You can also connect the pins to the UART
pins of some other MCU chip such as another M32C. You just need two serial pins (Tx and Rx), and
two GPIO pins (nRESET and MODE).
For example, in one of my projects, I have five R8C chips connected to an XScale chip which can
program them as well as communicate with them. The five R8C RX lines are all tied together, and a
multiplexer chooses which of the five TX lines the XScale listens to. The MODE lines are all tied
together, and five XScale GPIO independently reset the R8Cs. The XScale can thus reset only the
relevant R8C chip and program it; the others will ignore their MODE and RX lines.
Each chip has two program memories. The main memory is the user flash memory that holds your
application, which is what we want to reprogram. There is a second smaller memory in each chip that
contains a small bootloader program. When you want to program a new application, you tell the chip
to boot from the second memory, and the bootloader there helps you download new data into the main
flash memory through a simple communications protocol.
Reset
The chip decides which memory to boot from (user flash or bootloader) by checking the MODE pin at
reset. If the MODE pin is high (it's normally pulled high with a resistor), the chip boots from user flash
and runs your software. If it's low, the bootloader runs instead, and you can download new contents
into the flash. For chips with CNVss, the functionality is the same but the logic is inverted:
Reset for programming Reset to Run
nRESET
====\/==
nRESET
====\/==
MODE
??\-----
MODE
??/=====
CNVss
??/=====
CNVss
??\-----
You would normally leave the MODE pin unchanged except just before a reset. Fortunately, the
timing is very loose on these - you can control these two pins with jumpers. On most eval boards, the
pins are pulled high (or low, for CNVss) with resistors, so what you do is put the MODE jumper in
place (which pulls MODE to ground), press the reset button, then run the host program which talks to
the bootloader. When the programming is done, remove the MODE jumper, press the reset button, and
your software runs.
Commentaires sur ces manuels