Computing stuff tied to the physical world

Uploading via a USB interface

Until now, we’ve always been uploading via the “lpc21isp” tool, which is easy to install in Linux (via apt-get) as well as Mac OSX (via brew). Here is an example upload session:

$ lpc21isp -control -bin firmware.bin /dev/tty.usbserial-* 115200 0
lpc21isp version 1.97
File firmware.bin:
    loaded...
    image size : 1464
Image size : 1464
Synchronizing (ESC to abort). OK
Read bootcode version: 4
13
Read part ID: LPC810M021FN8, 4 kiB FLASH / 1 kiB SRAM (0x00008100)
Will start programming at Sector 1 if possible, and conclude with Sector 0 to ensure that checksum is written last.
Erasing sector 0 first, to invalidate checksum. OK 
Sector 1: ...|.
Sector 0: ..|.|.|.
Download Finished... taking 1 seconds
Now launching the brand new code
$

While this works fine, there is a new “uploader” tool in the embello repository on GitHub:

$ uploader /dev/tty.usbserial-* firmware.bin 
found: 8100 - LPC810: 4 KB flash, 1 KB RAM, DIP8
hwuid: 4670031002841BAE0C5BD751061900F5
flash: 05C0 done, 1464 bytes
$

As you can see, it is somewhat less verbose, and also reports the µC’s unique hardware ID. This version has been implemented in the Go language and can also be found on GitHub. Note that it currently only supports the LPC8xx family of chips.

There’s a special case when it comes to re-flashing a chip which has disabled its RESET pin. With uploader, you have to add the “-w” flag to tell it to wait and retry indefinitely until it can reach the boot loader. Without RESET pin, the only way to accomplish this is a power cycle, e.g. unplug the board (but not the FTDI interface!) and plug it back in.

Note that plugging a board into an active FTDI interface should be a last resort, not a habit.

If you want to see the serial output coming from the uploaded firmware, add the “-s” flag:

$ uploader -s /dev/tty.usbserial-* firmware.bin                
found: 8100 - LPC810: 4 KB flash, 1 KB RAM, DIP8
hwuid: 4670031002841BAE0C5BD751061900F5
flash: 05C0 done, 1464 bytes
entering terminal mode, press <ESC> to quit:

DEV_ID = 00008100
GPREG0 = 00000000
GPREG1 = 00000000
GPREG2 = 00000000
GPREG3 = 00000000

… and then press ESCAPE key to exit serial mode again. Or you can include “-i 1”:

$ uploader -s -i 1 /dev/tty.usbserial-* firmware.bin                
found: 8100 - LPC810: 4 KB flash, 1 KB RAM, DIP8
[...]
GPREG3 = 00000000

idle timeout
$

With “-i N”, uploader will exit when nothing is happening on the serial port for N seconds. This can be very convenient if you have your editor environment set up to start “make” on a shortcut or mouse click, because then the shell resumes – ready to perform the next make.

For the time being, there is no binary release of uploader, so if you want to use it, you’ll have to install Go and build the utility yourself:

  • see the Go install page for x86-/amd64-based machines

  • to install Go on Linux ARM (i.e. Raspberry Pi or Odroid), see this README

  • once that is done, you can fetch, build, and install the uploader using this command:

    go get -u git.jeelabs.org/jcw/embello/tools/uploader
    

Add the “-u” flag if you want to update the utility (“go get -u …”). If Go has been properly set up, including the GOPATH and PATH environment variables, then you’ll be all set.

To check whether the uploader is able to access and identify an attached board, use:

$ uploader /dev/tty.usbserial-*
found: 8100 - LPC810: 4 KB flash, 1 KB RAM, DIP8
hwuid: 4670031002841BAE0C5BD751061900F5
$

Please replace the “/dev/…” path in all the above with where your USB FTDI interface is found on the system. On Linux, this will most likely be /dev/ttyUSB0 or ...USB1.

Coming next: the real reason why the “uploader” utility was created…

[Back to article index]