Programming the MSP430 using docker
Docker is awesome. It's super handy for many things especially in the dev ops world but a personal favorite use case of mine would be creating disposable execution environments and workspaces. It's great to be able to quickly download preconfigured environments where I can get stuff done quickly and blow them away without a trace once I'm done. If you aren't already familiar, you can check out my in introductory slides to Docker for a quick overview[1].
A reader recently reached out with an idea of programming an MSP430 launchpad using a docker container based on a previous post I made on programming the launchpad[2]. I thought it was pretty interesting, so I decided to put together a quick guide on how to do just that.
It's worth mentioning that I'm doing this on an Ubuntu 14.04 system.
With the launchpad connected to my machine via USB, first we've got to figure out whether it's connected, we can do this using lsusb
.
$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 3.0 root hub
Bus 002 Device 002: ID 0451:f432 Texas Instruments, Inc. eZ430 Development Tool
Here my that my device is mounted on Bus 002 and Device 002
. We can now obtain its path using the find
command.
$ find /dev/bus
/dev/bus
/dev/bus/usb
/dev/bus/usb/002
/dev/bus/usb/002/002
/dev/bus/usb/002/001
/dev/bus/usb/001
/dev/bus/usb/001/001
At this point, we can assume that the correct path is /dev/bus/usb/002/002
. However, it never hurts to exercise a little caution and double check. We can obtain more information about the device using lsusb
$ lsusb -D /dev/bus/usb/002/002
Device: ID 0451:f432 Texas Instruments, Inc. eZ430 Development Tool
Couldn't open device, some information will be missing
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0451 Texas Instruments, Inc.
idProduct 0xf432 eZ430 Development Tool
bcdDevice 1.05
iManufacturer 1
iProduct 2
iSerial 3
bNumConfigurations 1
...
<[ Truncated for conciseness ]>
It looks like we've got the right device so we can press forward with putting a container together. I'm going to be using Ubuntu as the base image since it's pretty easy to install the MSP430 toolchain, but can just as easily use any base image you want.
We can run a new container using the run in interactive shell invoking bash. The key here is to include the path to the USB device using the device
flag.
docker run -t -i --device=/dev/bus/usb/002/002 ubuntu /bin/bash
At this point we should be able to see the device in the container, unfortunately, we cannot use the lsusb
command without the usbutils
package.
We can use this opportunity to update apt and install the toolchain.
apt-get update && apt-get install -y binutils-msp430 gcc-msp430 msp430-libc mspdebug usbutils
We can now view the USB device
root@63182d25a541:/# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 0451:f432 Texas Instruments, Inc. eZ430 Development Tool
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
And invoke mspdebug
root@63182d25a541:/# mspdebug rf2500
MSPDebug version 0.22 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2013 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Trying to open interface 1 on 002
Initializing FET...
FET protocol version is 30394216
Set Vcc: 3000 mV
Configured for Spy-Bi-Wire
Device ID: 0x2553
Code start address: 0xc000
Code size : 16384 byte = 16 kb
RAM start address: 0x200
RAM end address: 0x3ff
RAM size : 512 byte = 0 kb
Device: MSP430G2553/G2403
Number of breakpoints: 2
fet: FET returned NAK
warning: device does not support power profiling
Chip ID data: 25 53
While I focused on setting up the MSP430 toolchain, I do believe that the techniques should apply to any USB debugging toolchain.
Footnotes and references
Tahir, N. (2017). Essential docker - talk write up. [online] Another dev's two cents. Available at: /2016/10/18/essential-docker-talk-write-up/ [Accessed 15 Jan. 2017]. ↩︎
Tahir, N. (2017). Automate programming the MSP430 Launchpad on Linux using Expect. [online] Another dev's two cents. Available at: /2015/12/20/automate-programming-the-msp430-using-expect/ [Accessed 15 Jan. 2017]. ↩︎