Programming the Arduino Uno and Nano under PCBSD 9.1

This post describes the small patch required to the FreeBSD Port of avrdude 5.11 to enable programming of the Arduino Uno R3 directly from a PCBSD 9.1 desktop.

At the time of writing, the Arduino IDE version 1.0.3 is available as a PCBSD “PBI“. This PBI bundles avrdude version 5.11, which does the low-level programming for a wide variety of Arduino devices. As supplied, the Arduino IDE had no problem programming my Nano over the USB-serial interface. However, it refused to program my Uno R3 — I would get the following error each time:

avrdude: stk500_getsync(): not in sync: resp=0x00

Turns out to be a problem with avrdude sending a too-short reset signal to the Uno over the USB-serial connection. Bob Frazier noted the solution (extending part of the reset signal from 50ms to 250ms) in early January 2012. This is  fixed  in avrdude’s main development branch, but hasn’t (yet) been incorporated into the FreeBSD Port for avrdude 5.11.

The trick is to build avrdude from Ports (with patch applied), install the new avrdude executable into its usual (non-PBI) location, delete the PBI’s own version of avrdude and symlink in the newly built Ports version.

First, fetch and unpack the avrdude Port’s source files:

  [gja@gjadesktop] /usr/ports/devel/avrdude# make fetch
  ===>  License GPLv2 accepted by the user
  => avrdude-5.11.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
  => Attempting to fetch http://nongnu.askapache.com/avrdude/avrdude-5.11.tar.gz
  avrdude-5.11.tar.gz                           100% of  536 kB  148 kBps
  [gja@gjadesktop] /usr/ports/devel/avrdude#
  [gja@gjadesktop] /usr/ports/devel/avrdude# make extract
  ===>  License GPLv2 accepted by the user
  ===>  Extracting for avrdude-5.11
  => SHA256 Checksum OK for avrdude-5.11.tar.gz.
  [gja@gjadesktop] /usr/ports/devel/avrdude#

Install the patch in a form that the Port will automagically apply during ‘make build’:

  [gja@gjadesktop] /usr/ports/devel/avrdude# mkdir files
  [gja@gjadesktop] /usr/ports/devel/avrdude# cd files
  [gja@gjadesktop] /usr/ports/devel/avrdude/files# fetch http://www.mrp3.com/patch-arduino.c.20120102.txt
  patch-arduino.c.20120102.txt                  100% of  442  B   64 kBps
  [gja@gjadesktop] /usr/ports/devel/avrdude/files# mv patch-arduino.c.20120102.txt patch-arduino.c
  [gja@gjadesktop] /usr/ports/devel/avrdude/files# cd ../

Build & install the new avrdude:

  [gja@gjadesktop] /usr/ports/devel/avrdude# make build
  ===>  Patching for avrdude-5.11
  ===>  Applying FreeBSD patches for avrdude-5.11
  ===>  Configuring for avrdude-5.11
  checking build system type... amd64-portbld-freebsd9.1
  checking host system type... amd64-portbld-freebsd9.1
  checking target system type... amd64-portbld-freebsd9.1
	  [...various build-related messages...]
  cc -Wall -Wno-pointer-sign -O2 -pipe -I/usr/local/include -fno-strict-aliasing   -L/usr/local/lib -o avrdude avrdude-main.o avrdude-term.o ./libavrdude.a -lusb -lusb -lftdi -lusb  -lm -lreadline -lncurses -ltermcap
  [gja@gjadesktop] /usr/ports/devel/avrdude#
  [gja@gjadesktop] /usr/ports/devel/avrdude# make install
  ===>  Installing for avrdude-5.11
  ===>   Generating temporary packing list
  ===>  Checking if devel/avrdude already installed
  make  install-recursive
  test -z "/usr/local/bin" || ./install-sh -c -d "/usr/local/bin"
    install  -s -o root -g wheel -m 555 avrdude '/usr/local/bin'
  Backing up avrdude.conf in /usr/local/etc
  test -z "/usr/local/etc" || ./install-sh -c -d "/usr/local/etc"
  install  -o root -g wheel -m 444 avrdude.conf '/usr/local/etc'
  test -z "/usr/local/man/man1" || ./install-sh -c -d "/usr/local/man/man1"
  install  -o root -g wheel -m 444 avrdude.1 '/usr/local/man/man1'
  ===>   Compressing manual pages for avrdude-5.11
  ===>   Registering installation for avrdude-5.11
  [gja@gjadesktop] /usr/ports/devel/avrdude#

Replace the PBI’s version of avrdude:

  [gja@gjadesktop]/usr/ports/devel/avrdude# cd /usr/pbi/arduino-amd64/
  [gja@gjadesktop] /usr/pbi/arduino-amd64# mv bin/avrdude bin/avrdude-pbi-orig
  [gja@gjadesktop] /usr/pbi/arduino-amd64# ln -s /usr/local/bin/avrdude bin/avrdude

(This, of course, is a nasty hack that violates the normally self-contained nature of a PBI. Hopefully a future update of the Arduino IDE PBI will include a suitably patched avrdude.)

But in any case, I can now program my Uno R3.

The patch itself is rather small, altering one line of code:

  [gja@gjadesktop] /usr/ports/devel/avrdude# diff work/avrdude-5.11/arduino{.c,.c.orig}
  96c96
  <   usleep(250*1000); // increased from 50msec to 250msec - BBB
  ---
  >   usleep(50*1000);
  [gja@gjadesktop] /usr/ports/devel/avrdude#

Fun times ahead!

Advertisements

One comment

  1. Thank you. I’ve been searching for this article since I switched out my old PC-BSD machine for a new one.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: