September 7, 2019

New firmware for one of my Convoy S2+ flashlights

A month has gone by since I wasted almost two days trying to program the ATTiny13A in my Convoy flashlight. I now have more tools, in particular several USBasp boards, and am in a mood to get to work on this again.

My new tools

I bought 25 of the surface mount chips from Digikey, since that was the price break. This reduces the cost to about 53 cents each! With shipping the lot cost me $20.

To enhance my learning and allow easy fiddling around on a breadboard, I bought the 10 dip package chips also. These are almost certainly counterfeit, but for what I want to do I don't care whether they are or not.

Ebay dongles

I am marking these E1 and E2 with my sharpie. He lists these as $2.41 with $4 shipping. I bought two, so they cost me $10 for the pair. He ships them with firmware that works right away with AVRdude, which I really appreciate. There are many versions of this dongle, with some variation in the pinout. The following diagram seems to apply to mine. You have 10 pins (but need at most 6). The four you ignore are the NC pin, a redundant ground, and the RxD and TxD. The dongle is based on an ATmega8A.

The 6 pin header shown on the right above is the "ISP" (in system programming) header that is found on many AVR products, including the Adafruit Atmega32u4 breakout I am going to use for initial testing.

The challenge now is to connect this to the Adafruit breakout. This is complicated by the fact that Adafruit did not feel compelled to mark pin 1, but by locating ground and Vcc we can sort this out. I tried them out by connecting them to an Adafruit Atmega32u4 Breakout Board that I had laying around. This board has a 6 pin ISP header that I connect to as follows:

ASP pin  1 to ISP pin 4  -- MOSI
ASP pin  2 to ISP pin 2  -- Vcc
ASP pin  5 to ISP pin 5  -- Reset
ASP pin  7 to ISP pin 3  -- Sclk
ASP pin  9 to ISP pin 1  -- MISO
ASP pin 10 to ISP pin 6  -- Gnd
This dongle has a jumper that selects 3.3 or 5 volts (silk screen on the bottom guides you). I set this to provide 3.3 volts. When I plug the dongle into my linux machine (with the breakout dangling on the cable) red LED's on the dongle and the breakout light up and I see the following messages:
Oct 16 12:31:34 trona kernel: usb 2-1.7: new low-speed USB device number 8 using ehci-pci
Oct 16 12:31:34 trona kernel: usb 2-1.7: New USB device found, idVendor=16c0, idProduct=05dc, bcdDevice= 1.02
Oct 16 12:31:34 trona kernel: usb 2-1.7: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Oct 16 12:31:34 trona kernel: usb 2-1.7: Product: USBasp
Oct 16 12:31:34 trona kernel: usb 2-1.7: Manufacturer: www.fischl.de
So, no attempt to connect a driver or act like this is a tty device. Now the thing to do is see if AVRdude will play nicely with it.
avrdude -p m32u4 -c usbasp

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)

avrdude: safemode: Fuses OK (E:C3, H:D0, L:FC)

avrdude done.  Thank you.
So, it does see a 32u4 chip. I am not sure how crucial the warning about setting sck and updating my usbasp firmware is. I get a little braver and try reading out the flash (in the 32u4):
avrdude -p m32u4 -c usbasp -U flash:r:flash.bin:r

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: reading flash memory:

Reading | ################################################## | 100% 20.10s

avrdude: writing output file "flash.bin"

avrdude: safemode: Fuses OK (E:C3, H:D0, L:FC)

avrdude done.  Thank you.
I am not sure why avrdude thanks me, but I appreciate polite firmware. This yields a 32448 byte file. This all seems to be working.

My second Ebay dongle is easy to test, I just transfer the cable, plug it in, and repeat the avrdude commands. It yields a binary file of the same size and with the same content.

Note that it is not necessary to run avrdude as root or to fiddle with any udev rules. It just works.

Dongle from AliExpress seller A

I mark this unit "C1" with my sharpie. This looks physically identical to my Ebay unit, with minor differences in the silkscreen. It gives the same USB information when plugged in, and works perfectly with AVRdude.

Dongle from AliExpress seller B

I mark this unit "C2" with my sharpie. This looks physically identical to my other units. However, when I plug it in, it does not identify itself in any way to USB, and of course AVRdude does not work with it.

So, this is why you buy multiple copies of a unit like this, especially when they are cheap. Even if you don't receive a dead unit like this, you can use one unit to update firmware in another (such as when AVRdude advises you to do so ....).

I had hoped this unit just had bad (or no) firmware, but it is simply dead. It will be discarded. I am glad I bought duplicate and backup units.


Feedback? Questions? Drop me a line!

Tom's Light Info / tom@mmto.org