September 8, 2019

Convoy S2+ firmware - Using AVRdude with ArduinoISP

Now that we have my old Arduino Duemilanove programmed with ArduinoISP, the question is, "how do we use it to send a hex file to a device?".

Here are a bunch of links that may or may not be relevant.

Strangely enough, this is where various tutorials all seem to fall apart. The usual scheme is to use avrdude. One might thing that we find a command line that uses usbasp and then substitue "arduinoISP" for "usbasp" and we would be off to the races, but we are getting ahead of ourselves.

Get avrdude

First thing though, we need avrdude itself. This is available as a Fedora package, so this is easy:
su
dnf install avrdude
This gives me version 6.3-15 for Fedora 30.

Make avrdude talk to our arduino ISP

We don't actually need to connect this to a target ATTiny13A at this stage. When I plug in my arduinoISP, I see:
Sep  8 15:05:23 trona kernel: usb 2-1.8: new full-speed USB device number 11 using ehci-pci
Sep  8 15:05:23 trona kernel: usb 2-1.8: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
Sep  8 15:05:23 trona kernel: usb 2-1.8: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Sep  8 15:05:23 trona kernel: usb 2-1.8: Product: FT232R USB UART
Sep  8 15:05:23 trona kernel: usb 2-1.8: Manufacturer: FTDI
Sep  8 15:05:23 trona kernel: usb 2-1.8: SerialNumber: A6008bvC
Sep  8 15:05:23 trona kernel: ftdi_sio 2-1.8:1.0: FTDI USB Serial Device converter detected
Sep  8 15:05:23 trona kernel: usb 2-1.8: Detected FT232RL
Sep  8 15:05:23 trona kernel: usb 2-1.8: FTDI USB Serial Device converter now attached to ttyUSB0
Note two things. This gets set up as /dev/ttyUSB0 and since it uses an onboard FTDI chip for USB, we see the vendor and product code for this device (0403 and 6001).

There is a file /etc/avrdude/avrdude.conf that contains lines for a variety of programmers. The arduino GUI has its own avrdude.conf file. This gets copied to a variety of places, but the original copy seems to be at /opt/arduino/arduino-1.8.9/hardware/tools/avr/etc/avrdude.conf.

The standard file in /etc/avrdude has no entry named "arduinoisp". The file that is bundled with the arduino GUI has the following:

programmer
  id    = "arduinoisp";
  desc  = "Arduino ISP Programmer";
  type  = "usbtiny";
  connection_type = usb;
  usbvid     = 0x2341;
  usbpid     = 0x0049;
;
Note though that the vendor and product ID are wrong (whatever arduino this was intended for must have had a more modern AVR chip with embedded USB that allowed the vendor and product ID to be changed. Or something of the sort. What I did is to put a version of the above with the vendor and product ID's I expect into /etc/avrdude/avrdude.conf as follows. I also changed the programmer ID to "bulldog" just because I could.
programmer
  id    = "bulldog";
  desc  = "Arduino ISP Programmer (bulldog)";
  type  = "usbtiny";
  connection_type = usb;
  usbvid     = 0x0403;
  usbpid     = 0x6001;
;
Now I type "avrdude -c xyz" to get a list of known programmers, and I see:
  blaster          = Altera ByteBlaster
  bsd              = Brian Dean's Programmer, http://www.bsdhome.com/avrdude/
  bulldog          = Arduino ISP Programmer (bulldog)
  buspirate        = The Bus Pirate
This is some kind of progress, perhaps. Now let's try the following command and see what happens:
avrdude -p attiny13 -c bulldog
The above yielded little excitement, so I tried this:
avrdude -p attiny13 -P /dev/ttyUSB0 -c avrisp -b 19200 -U flash:w:release.hex
This yielded a lot of excitement. All of the LED's flash and I get a variety of errors. So I have avrdude talking to the arduino ISP, but with no actual ATtiny13 chip connected we can only expect errors. The surprise is that we don't need to use "bulldog" or even "arduinoisp" as the programmer type.

Before we go further, some comments about the arguments. -U says to do a "memory operation" which can be a list to be done in order. "flash:w:filename" says to write to flash from the filename specified. Change w to r and you read. Use "v" to verify. Consider the following command with this in mind:

avrdude -p attiny13 -c usbasp -U flash:w:main.hex:i -F -P usb
Here the "-F" says to ignore an invalid signature check. No telling about "-P usb", but the :i after the filename likely indicates Intel hex format. The following line would read out the flash. The :r says to save it as raw binary.
avrdude -p attiny13 -P usb -c avrisp -U flash:r:flash.bin:r

The bottom line

An afternoon spent fooling with this and no luck yet. So I jumped onto Ebay to see if I can find the "USBasp" programmer. And they sell for about $2.00! So I ordered two. They will cost me $5 each with shipping rolled in. I just have to wait a week.

And check this out -- somebody has done what I thought of and used the STM32 "blue pill" to work up an AVR programmer:


Feedback? Questions? Drop me a line!

Tom's Light Info / tom@mmto.org