openOBC firmware compiling and flashing

July 13, 2014

Here I document a case of compiling on Lubuntu 14.04 and flashing with lpc21isp through the openOBC's micro-USB port. This is what I'd recommend as probably the most supported setup.

The same steps can work on a variety of systems, but I'm doing this with a fresh install of Lubuntu 14.04 in Virtualbox. A normal install will have just about everything we need out of the box, but we'll probably have to install an arm-none-eabi toolchain and lpc21isp, and we may have to install git.

installing the toolchain

Lubuntu does have a gcc-arm-none-eabi package in the official repository, but there seems to be a problem with using it to compile the firmware, so we need to still use the gcc-arm-embedded one for now.

We can add the PPA like this:

sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded
sudo apt-get update

After adding the PPA, we need to increase its priority so the packages from the official repository don't get accidentally installed instead. We can do that by creating a file /etc/apt/preferences.d/gcc-arm-embedded with contents:

Package: *
Pin: release o=LP-PPA-terry.guo-gcc-arm-embedded
Pin-Priority: 600

Now we can proceed to install the toolchain:

 sudo apt-get install gcc-arm-none-eabi

compiling the firmware

If we don't have git already, we'll want to pick that up first:

sudo apt-get install git

 Now we can get the latest openOBC firmware source straight from github:

git clone https://github.com/benemorius/openOBC-devboard.git

and compile: 

cd openOBC-devboard
make

Compiling should take a few minutes or less and output 3 files: openOBC-devboard.elf, openOBC-devboard.hex, and openOBC-devboard.bin. These files contain the same firmware in 3 different formats. For lpc21isp we need either the .hex or the .bin.

flashing the firmware

We'll need to get lpc21isp if we don't already have it:

sudo apt-get install lpc21isp

Now we can actually flash the new firmware. The openOBC board has a micro-USB port labeled USBDEVICE which can be used to flash the firmware. The cable needed is USB A male to micro-USB B male. Lots of Android phones and other devices use such cables, so I already had a few.

Since I'm using Virtualbox, I have to be sure to tell it to pass the USB device corresponding to the openOBC (FTDI FT231X) to the virtual machine:

With the OBC connected to power and the micro-USB cable connected to the computer, linux should pick it up and produce a new /dev/ttyUSB* device file. You can verify this by checking the output of lsusb as well as the existence of the new device file:

# lsusb

...
Bus 001 Device 003: ID 0403:6015 Future Technology Devices International, Ltd Bridge(I2C/SPI/UART/FIFO)
...

# ls /dev/ttyUSB*
/dev/ttyUSB0

So in this case our device file is /dev/ttyUSB0. That means we can flash the new firmware file like this:

sudo lpc21isp -control -term openOBC-devboard.hex /dev/ttyUSB0 115200 12000

This takes a minute or so. When it finishes, lpc21isp will keep the terminal open so we can view the debug output when the firmware launches. Once flashing is complete, pressing the RESET button on the openOBC will launch the new firmware. The debug output makes it immediately obvious that the new firmware has indeed booted up:

If anything goes wrong during the flash (like an untimely disconnection of the power cable) we can just run lpc21isp again, taking care that ttyUSB0 hasn't perhaps changed itself to ttyUSB1. We're using a bootloader in the ROM of the LPC1769 to do the flashing, so it isn't possible to overwrite the bootloader or otherwise prevent it from operating. lpc21isp will reprogram the flash from any state.

If at any point we just need to get back to a known good firmware, flashing one of the firmware downloads on this page will restore the firmware to the latest stable version.

After a first successful flashing, the next thing I'd do if I were interested would be to install KDevelop to use for browsing and editing the source code. I'm considering another post to go over making some small changes to the firmware with KDevelop, testing them, and committing them with git.

0 Comments

Leave a comment