delorie.com/electronics/rx-stick/   search  
RX-Stick Projects and Info

If you can't change it, you don't own it.

Developing for the RX-Stick under Linux

Table of Contents
Building a GNU Toolchain
Flashing Tools
USB Permissions
R8C Programs
Programming the R8C/1B over USB
Programming the R8C/1B with an Adapter
Bypassing the R8C/1B
RX Programming

Getting the RX-Stick usable under Linux is a multi-step process...

Building a GNU Toolchain

To build a GNU toolchain (gcc, gas, ld, gdb, newlib), you'll need to download a bunch of tarballs from any GNU mirror, or check the latest versions out of their source code repositories. I usually check out the latest; some packages don't release often enough to get current support which you'll need.

Go to www.gnu.org and click the download link. You want sources, so find the links for downloading it via web/ftp, and get the latest versions of these (project pages appended, in case you want to check out the latest from source control):

GDB is not really needed, but it does include simulators for R8C and RX which might come in handy.

Wherever you're installing them to, make sure your $PATH includes that .../bin directory. In the examples below, that would be /opt/redhat/bin

export PATH=/opt/redhat/bin:$PATH

Each package is built and installed separately. Just use the same --prefix and they'll all get along. Never build in the source tree! Always use a separate build tree; this will not only work more reliably but it means you don't need separate R8C and RX source trees.

First, build binutils. Something like this:

mkdir $TOP/m32c-binutils ; cd $TOP/m32c-binutils
../binutils-X.Y/configure --prefix=/opt/redhat --target=m32c-elf
make
make install
Note that the instructions are the same for RX, just use rx-elf instead of m32c-elf. Note that the m32c target supports r8c, m16c, and m32c, so don't get confused by the different name.

Next build as much of gcc as you can (yes, it will fail, because you haven't built newlib yet):

mkdir $TOP/m32c-gcc ; cd $TOP/m32c-gcc
../gcc-X.Y/configure --prefix=/opt/redhat --target=m32c-elf --enable-languages=c --with-newlib
make -k
make -k install

Now that you have a working compiler, you can build newlib:

mkdir $TOP/m32c-newlib ; cd $TOP/m32c-newlib
../newlib-X.Y/configure --prefix=/opt/redhat --target=m32c-elf
make
make install

Now go back and build the rest of gcc:

cd $TOP/m32c-gcc
make
make install

If you want the debugger/simulator, you can build it now:

mkdir $TOP/m32c-gdb ; cd $TOP/m32c-gdb
../gdb-X.Y/configure --prefix=/opt/redhat --target=m32c-elf
make
make install

Flashing Tools

The R8C and RX chips both use a serial protocol for downloading new code into their flash memory. I've written a utility that implements this protocol. Unpack that tarball in an empty directory and run:

make serial
There's support for FTDI-based targets as well, but we won't need those, and they need extra libraries anyway.

The two programs you'll use for the RX-Stick are sflash to flash the R8C chip, and rxs to flash the RX chip.

If you use an FTDI-based serial cable to reprogram the R8C/1B using the four-pin connector and serial mode 3, you'll need to install libftdi-devel and build uflash as well.

Make sure these two files are in your $PATH.

USB Permissions

To run the flashing tools as a regular user, you'll need to arrange for the right permissions to be granted. There are a couple of ways to accomplish this:

R8C Programs

Each chip you program for needs "support files" that handle things like memory maps and startup. In addition, you need the application sources. Together, they are built into ELF images which you download into the chip.

For a starter, let's build a standard Hello,world application for the R8C simulator (you type the bold parts):

$ m32c-elf-gcc hello.c -o hello.elf -msim
$ m32c-elf-run hello.elf
Hello, world
$
If you try to run that on hardware, it won't work - the simulator is providing special hooks for printf and exit which the hardware doesn't have - that's what -msim is for. Besides, a chip doesn't "exit" :-)

For the R8C/1B on the Stick, you need specific support files. Here's a tarball of them along with the apps I'll mention later. Untar them in an empty directory, and if m32c-elf-gcc is in your $path, just type "make".

Programming the R8C/1B over USB

To use the CP2102 serial port to program the R8C/1B, you'll need to connect the R8C's clock input to the RX's clock circuit. A single wire will do. You want to carefully solder the wire between R8C pin 6 (clock input) to the "C2" side of the 12 MHz crystal (RX clock output). This is the side closest to the R8C.

In the Makefile, there's a line that starts with port=. Find that line, and edit it according to the serial device your stick shows up as.

Now for the actual programming. I suggest covering the V pin, like with tape or some bit of 20 gauge wire insulation, to prevent shorting Vcc to Gnd. To put the R8C into program mode, you need to short the M pin and the G pin, then momentarily short the R and G pins. This puts the R8C in serial mode 2. Note that you can remove the M-G short after you reset the chip, as long as you wait 0.3 seconds or more first. Once you'd done that, run:

make flash
This talks to the R8C/1B over the USB serial port to send down the new program. Once the program is downloaded, reset again without the M-G short to run your program.

The program that's downloaded by default is stick-mon which watches for a BREAK condition on the serial line, then reads a single byte at 9600 baud. If the LSB is set, the RX is reset into flashing mode, else it's reset into user mode. The monitor then sends back the same byte, but with bit 4 toggled (this converts upper to lower case, etc), and gives serial control to the RX. The red LED is ON in flash mode and OFF in user mode, and blinks when there's serial data sent back to the PC (the orange led blinks for received data).

If you want a completely manual setup, change the Makefile to flash the hands-off image instead. The blinky image just disconnects the RX and blinks both leds, as a demo.

Note that it is possible to ID-lock the R8C. This happens if programming is interrupted, or if you just don't remember the ID. It's possible your stick's R8C comes pre-locked. If this is the case, your only remedy is to replace the R8C chip with a new one.

Note that the proper way to remove it is to desolder it with a removal tool - first, add *more* solder to the pins to ensure a good thermal connection, then remove it. If you do not have the right tools, carefully cut the individual pins. If you are not careful, you will damage the delicate pcb traces they're soldered to. Don't just cut the whole row of pins (like I did) or you'll break the traces (like I did) and have to solder repair wires all over the place (like I did). Alternately, bypass it and manually jumper/reset the RX.

Programming the R8C/1B with an Adapter

It is possible to make an adapter to connect the four-pin header to an E8a connector or an FT232R-based serial port. TBD. Here's a hint: Get a TTL-232R-3.3V cable. Connect it's RXD to MODE, and a diode from RXD to TXD (mark towards TXD, so TXD can pull it down but not up). Use RTS for reset. Now write a bunch of software...

Note: if you are powering the stick through the V pin on the four-port header, note that the RED led will not work. That LED is powered by the +5 rail of the stick's USB connector.

Bypassing the R8C/1B

The R8C/1B on the RX-Stick controls the reset, mode, and serial gate (U9) to the RX. Unfortunately, it is pre-programmed with code that only works with HEW. So, to use the RX-Stick with anything *other* than the HEW debugger, you need to reprogram it or bypass it. If you don't want to replace or reprogram the R8C, you have two options:

You will also need to jumper the R and G pins of the four-pin connector next to the USB connector. These are the two closest to the edge. This holds the R8C in reset and floats all the lines. If you don't have a four-pin header, just solder a wire between those two holes.

For manual operation, you'll definitely need a reset switch, like the Omron B3FS-1000P.

RX Programming

The RX has a GCC and simulator just like the R8C:

$ rx-elf-gcc hello.c -o hello.elf -msim
$ rx-elf-run hello.elf
Hello, world

Like for the R8C, I have a sample program for you to build. That tarball includes the support files too. Make sure your MDE jumper is set to "little endian" - that's the two pins closest to the button (marked "L" for MDE and MD1). Extract it in an empty directory, edit the port line in the Makefile, and type:

make flash

If all goes well, it should "just work" and the RX-Stick demo should start up. Note: Press Ctrl-C twice to exit the terminal mode of the flashing tool.

Note that the -P rxstick command line option tells the flashing tool to talk with the R8C's stick-mon application. If you're using full-manual (jumpers and reset button), omit that parameter.


  webmaster     delorie software   privacy  
  Copyright © 2015     Updated Dec 2015