USBtiny is a writer/reader for in-system programming (ISP) or in-circuit serial programming (ICSP) for AVR. Although there is no drivers for Windows 10 nor 11, we can still use USBtiny with Linux. My USBtiny is HP-AUSB-ISP.
I could write some programs into some boards through a 6-pin cable/connector:
- led.c into Arduino NANO with ATmega168P
- Klipper into ET-4000 V2 with ATmega1284P, a 3D Printer main board.
Original location of this MEMO is https://gist.github.com/t-nissie/a9c81376cf0898c0ec0b453d5a385d33 .
I had to install some packages with apt(1) command. My Ubuntu is 22.04 LTS.
$ sudo apt install gcc-avr avr-libc binutils-avr avrdude
After I connected USBtiny to my Linux box with a USB cable, I got some system log messages.
$ sudo dmesg -e
:
[ 3/23 04:41] usb 1-3: new low-speed USB device number 25 using xhci_hcd
[ +0.155004] usb 1-3: New USB device found, idVendor=1781, idProduct=0c9f, bcdDevice= 1.04
[ +0.000050] usb 1-3: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ +0.000021] usb 1-3: Product: USBtiny
:
Compile led.c
. Flash led.elf.hex
to the board with avrdude(1)
command.
led.c
and Makefile
are in this Gist.
After the flashing, verification will be done by avrdude(1)
.
$ make
avr-gcc -g -Wall -O2 -mmcu=atmega168 -c -o led.o led.c
avr-gcc -g -Wall -O2 -mmcu=atmega168 -Wl,-Map,led.map -o led.elf led.o
avr-objcopy -j .text -j .data -O ihex led.elf led.elf.hex
$ sudo avrdude -c usbtiny -p atmega168p -U flash:w:led.elf.hex
Do not forget sudo
for avrdude(1)
, or you will get a verification error.
klipper.elf.hex can be written into ET-4000 V2 as:
$ sudo avrdude -c usbtiny -p atmega1284p -U flash:w:out/klipper.elf.hex:i
Connection can be checked with et4000v2initialtest.cfg as printer.cfg.
serial
should be changed for your system.
[include mainsail.cfg]
[mcu]
serial: /dev/ttyUSB1
[virtual_sdcard]
path: /home/pi/printer_data/gcodes
on_error_gcode: CANCEL_PRINT
[printer]
kinematics: none
max_velocity: 1000
max_accel: 1000
avrdude(1)
gives an error of avrdude: verification error, first mismatch at byte 0x0006
after writing and reading.
$ sudo avrdude -p atmega168p -c usbtiny -D -U flash:w:demo.elf.hex
:
Writing | ################################################## | 100% 0.58s
:
Reading | ################################################## | 100% 0.34s
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0006
0x06 != 0x46
avrdude: verification error; content mismatch
There may be some reasons:
- You forgot
sudo
beforeavrdude(1)
. - Power supply is not enough. Disconnect servos, motors, etc.
avrdude(1)
is too old. See Appendix below.
You may encounter link errors like:
/usr/lib/avr/bin/ld: address 0x800931 of out/klipper.elf section `.bss' is not within region `data'
In this case reinstallations of gcc-avr avr-libc and binutils-avr may solve the problem. See https://gist.github.com/t-nissie/81bc471cd543e92d5cd1c3d36474c8b1
If you want to install the latest avrdude(1)
, you need some packages for development.
$ sudo apt remove avrdude
$ sudo apt install cmake flex bison libelf-dev libusb-dev libhidapi-dev libftdi1-dev libreadline-dev libserialport-dev ninja-build
$ tar xf avrdude-7.3.tar.gz
$ cd avrdude-7.3.tar.gz
$ ./build.sh
$ sudo cmake --build build_linux --target install