Easy R8C/M16C/M32C/R32C Flash Programming DJ Delorie September 15, 2009 Note: This document is formatted with the free Liberation fonts1 and the freely redistributable Timing Diagram font2. If you don't have those installed, this document may not render properly. The home page of this document is http://people.redhat.com/dj/m32c/ Copyright © 2008, 2009 DJ Delorie
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).
Auto-Baud In mode 2, the first thing you do is teach the bootloader what baud rate to use, since the bootloader doesn't know how fast the chip's clock is. Wait 3mS or so for the chip to come out of reset, then send 16 NUL bytes spaced 20 mS or more (I use 40 mS) apart. These bytes should be sent at 9600 baud, 8 bits, no parity, one stop bit. Different chips require different delays between bytes, but this should be long enough to work with them all.
(0xFB), the response is eight bytes, intended to be human readable: Tx __{FB}______________________________ Rx ________{56)45)52)2E)31)2E)34)38}___ In the above example, the version string is "VER.1.48". The chips I've seen all follow this pattern (with various digits, of course), so my utility checks for each character to be the right type (specific letters, any digits, etc). Status The next command to know is how to check the status of the bootloader.
this: Tx __{48)12)CMD)78)56)34}____ Unlock To unlock the chip, we need to know the flash locking code that was last programmed into it. Most development tools use either all zeros or all ones (0xff) for the default key, so if you don't know the right key you can try those.
Erase All Erasing everything is easy. It's not as fast or as optimal as just erasing the blocks you need, but it's universal. Since this command takes a while to run, special precautions will be taken to properly clear and read the status. Tx __{50}_{A7)D0}____{70}____________________{70}____________ Rx _________________________{TIMEOUT}____________{SRD1)SRD2}_ After you issue the format command (0xA7, 0xD0), set up a 1 second timeout on receive and start asking for status.
Console In my utilities, I have a command line option to maintain the connection to the serial port at this point, acting like a mini terminal emulator. At the very least, if your utility prints any received data to your screen, you can use the serial port on the chip as a "debug" stream.
GNU Free Documentation License Version 1.2, November 2002 Copyright (C) 2000,2001,2002 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 0.
Document means that it remains a section "Entitled XYZ" according to this definition. The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License. 2.
parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard. You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity.
any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation.