R31JP Development on Mac and Linux for 6.115

July 27, 2013

On my first day in MIT’s 6.115 (Microcomputer Project Lab), I was disappointed to see that developing for the R31JP requires using the Windows machines in the lab. The process for uploading code on a lab machine is to first assemble it with the as31 command line tool and save the resulting hex file, then open the serial monitor and choose the hex file. You also need a USB stick to keep your code when you are done for the day. What I really wanted was to develop from my laptop and make uploading a one step process, so that the time between making a change and testing it is less than 5 seconds rather than at least 30. One of the TA’s created an upload script when he took the class, available here, but I wanted a single script to assemble and upload code with no additional dependencies, so that uploading to the R31JP is a one-liner.

View the GitHub project here

Here are the steps to get setup:

  1. Buy a USB-Serial adapter. Here’s the one most people in 6.115 in Spring 2013 used:

    USB-Serial Adapter on Amazon

  2. Install drivers:

    Download from Prolific

  3. Install everything you need with homebrew. If you don’t have homebrew just run ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

First install python and pyserial with homebrew.

brew install python
echo "export PATH=/usr/local/bin:\$PATH" >> ~/.bash_profile
pip install pyserial

Next install r31jp.

brew tap nitsky/r31jp
brew install r31jp

Create an assembly file, and when you are ready to load it, just run

r31jp filename.asm

The r31jp script assembles the code with as31 and then waits for you to reset the R31JP in MON mode. It then uploads the code, and opens a serial console using screen. You can run the code by switching the board into RUN mode and hitting reset, or by entering the command G8000. The script takes one argument, the path to an 8051 assembly file, and has two options, -s to specify the serial port for the R31JP, and -b to choose the baud rate of MINMON. The default serial port is /dev/tty.usbserial which the Prolific driver chooses for Mac OS X, and the default baud rate is 9600.

Please file an issue on GitHub if you run into any trouble!

blog comments powered by Disqus