Computing stuff tied to the physical world

Re-flashing an LPC810 on the RPi

Now that we have a way to talk to the LPC810 directly from the I2C header pins on the Raspberry Pi, it’d be nice to also be able to upload to it. Let’s see what options we have.

On the Raspberry Pi models A and A+, there is only one USB connector. Uploading to our µC via an FTDI adapter is definitely possible, but will require an extra USB hub if we also want to keep the WiFi dongle connected.

The “dmsg” command in Linux reports the kernel message log. Here are the last few lines once the FTDI interface has been plugged in, showing that it all works out of the box:

[..] usb 1-1.2: Product: FT232R USB UART
[..] usb 1-1.2: Manufacturer: FTDI
[..] usb 1-1.2: SerialNumber: AH01A0ME
[..] usbcore: registered new interface driver usbserial
[..] usbcore: registered new interface driver usbserial_generic
[..] usbserial: USB Serial support registered for generic
[..] usbcore: registered new interface driver ftdi_sio
[..] usbserial: USB Serial support registered for FTDI USB Serial Device
[..] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[..] usb 1-1.2: Detected FT232RL
<snip>
[..] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB0

In short: no need to install drivers as in Windows or Mac OSX – Linux knows about FTDI.

But there’s another way which doesn’t go through USB and doesn’t need an FTDI interface. There’s a “serial console” on the Raspberry Pi, which is available as the system console for kernel messages and low-level receovery. This device is available as “/dev/ttyAMA0”, and best of all: it has the right 3.3V signal levels and it’s available on header pins 6/8/10.

First step is to disable the system console, so we can re-use this serial connection:

  • launch the configuration utility: sudo raspi-config
  • go to the “Advanced Options” menu and select “Serial”
  • disable the login shell, i.e. choose “No”
  • exit the configuration utility

We now have access to the serial port, and can hook up our own hardware:

DSC 4906

The adapter board converts the Raspberry Pi’s pins to an FTDI-compatible 6-pin header. The second little board is the same as before with an LPC810, a red LED, and a 0.1 µF cap.

Does it work? Sure – if we put some code on the LPC810 such as the primes example, which generates serial output, we can hook it up and use the following command to see it:

screen /dev/ttyAMA0 115200

But wait, to be able to actually reset the LPC810 and put it into ISP mode, we also need the equivalent of the DTR and RTS pins. Luckilly, the Raspberry Pi has some “General purpose I/O pins” (GPIO) freely available. The above adapter has two extra wires connected:

  • GPIO pin 17 is connected as DTR / reset, FTDI header pin 6
  • GPIO pin 4 is connected as RTS / bootloader, FTDI header pin 2

These pins can be controlled from Linux. Here is an example using plain shell commands:

    cd /sys/class/gpio
    RTS=4; echo $RTS >export; echo out >gpio$RTS/direction
    DTR=17; echo $DTR >export; echo out >gpio$DTR/direction
    echo 0 >gpio$RTS/value
    echo 1 >gpio$DTR/value
    echo 0 >gpio$DTR/value
    echo 1 >gpio$DTR/value
    echo 1 >gpio$RTS/value

This requests access to the two pins, sets them up as outputs, and then sets their values in such a way that an attached LPC810 will enter ISP “bootload” mode (keep in mind that both signals are inverted: “1” is inactive, “0” is active).

The µC is now waiting for upload commands, which could be sent using this command:

    lpc21isp -bin firmware.bin /dev/ttyAMA0 115200 0

… ehm, except that the default Raspbian version of Linux as installed on a Raspberry Pi does not have “lpc21isp”. One solution is to download the source code from GitHub and compile it. But as it turns out, the upload protocol is quite simple and we might as well implement a complete solution for it which also does all the necessary GPIO toggling.

This will be presented in a future article…

[Back to article index]