Kjetil's Information Center: A Blog About My Projects

GR-SAKURA Shell

Renesas has more microcontroller reference boards. On another trip to Japan I picked up the GR-SAKURA board, which uses the Renesas RX63N microcontroller.

Like the GR-KURUMI, I have made a command shell interface for the GR-SAKURA as well, based on much of the same code, to control its LED and timer functions.

The shell is spawned as the UART on "SCI0", which has the RxD pin at P21 (aka IO0) and the TxD pin at P20 (aka IO1) on the board. The code and build environment also assumes that the pre-flashed USB mass-storage based bootloader is in use, so the binary may be transferred using that USB interface.

Get the source code here and follow this advice on how to setup the toolchain for compiling Renesas RX binaries. I have created custom C-runtime stubs and a linker script to work specifically with the pre-flashed bootloader. These are included in the source code tarball as well.

Here is a similar Python script that can be used to load script files remotely:

#!/usr/bin/python

import serial

class Sakura(object):
    def __init__(self, port):
        self.s = serial.Serial()
        self.s.port = port
        self.s.baudrate = 9600
        self.s.bytesize = serial.EIGHTBITS
        self.s.parity = serial.PARITY_NONE
        self.s.stopbits = serial.STOPBITS_ONE
        self.s.xonxoff = False
        self.s.rtscts = False
        self.s.dsrdtr = False

        self.s.open()
        self.s.flushInput()
        self.s.flushOutput()
    
    def __del__(self):
        self.s.close()

    def _command(self, cmd):
        print ">", cmd
        for char in cmd:
            self.s.write(char) # Write one character at a time...
            self.s.read(1)     # ...and read the echo.
        self.s.write("\r") # Finish command...
        self.s.read(10)    # ...and read the prompt.

    def script(self, filename):
        self._command("stop")
        self._command("d1 off")
        self._command("d2 off")
        self._command("d3 off")
        self._command("d4 off")
        self._command("clear")
        with open(filename) as fh:
            for line_no, line in enumerate(fh):
                self._command("%s %s" % (line_no, line.strip()))
        self._command("run")

if __name__ == "__main__":
    import sys
    s = Sakura("/dev/ttyUSB0")

    if len(sys.argv) > 1:
        s.script(sys.argv[1])
    else:
        print "Usage: %s <script file>" % (sys.argv[0])
          


One difference compared to the GR-KURUMI is that the LEDs on GR-SAKURA are all blue and named D1 to D4 instead. Here is a sample script:

d1 on
sleep 50
d1 off
sleep 50
d2 on
d3 on
sleep 100
d2 off
sleep 100
d3 off
sleep 500
d4 toggle
          


Topic: Open Source, by Kjetil @ 04/02-2018, Article Link