Program Bootloader of Digispark ATTiny85 with A ISP Programmer Mar 8th 2021 Words: 1.3k

Background

After run micronucleus -run ./upgrade-t85_default.hex on my Chinese clone of Digispark, I successfully break the bootloader so the USB programming interface is no longer available for me.

My kernel log shows the following errors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
08.03.2021 22:54:17:742	kernel	usb 1-4: new low-speed USB device number 64 using xhci_hcd
08.03.2021 22:54:17:865 kernel usb 1-4: device descriptor read/64, error -71
08.03.2021 22:54:18:095 kernel usb 1-4: device descriptor read/64, error -71
08.03.2021 22:54:18:325 kernel usb 1-4: new low-speed USB device number 65 using xhci_hcd
08.03.2021 22:54:18:449 kernel usb 1-4: device descriptor read/64, error -71
08.03.2021 22:54:18:679 kernel usb 1-4: device descriptor read/64, error -71
08.03.2021 22:54:18:789 kernel usb usb1-port4: attempt power cycle
08.03.2021 22:54:19:442 kernel usb 1-4: new low-speed USB device number 66 using xhci_hcd
08.03.2021 22:54:19:442 kernel usb 1-4: Device not responding to setup address.
08.03.2021 22:54:19:649 kernel usb 1-4: Device not responding to setup address.
08.03.2021 22:54:19:855 kernel usb 1-4: device not accepting address 66, error -71
08.03.2021 22:54:19:982 kernel usb 1-4: new low-speed USB device number 67 using xhci_hcd
08.03.2021 22:54:19:982 kernel usb 1-4: Device not responding to setup address.
08.03.2021 22:54:20:189 kernel usb 1-4: Device not responding to setup address.
08.03.2021 22:54:20:395 kernel usb 1-4: device not accepting address 67, error -71
08.03.2021 22:54:20:396 kernel usb usb1-port4: unable to enumerate USB device
08.03.2021 22:54:50:095 kernel usb 1-4: new low-speed USB device number 68 using xhci_hcd
08.03.2021 22:54:50:219 kernel usb 1-4: device descriptor read/64, error -71
08.03.2021 22:54:50:449 kernel usb 1-4: device descriptor read/64, error -71
08.03.2021 22:54:50:679 kernel usb 1-4: new low-speed USB device number 69 using xhci_hcd
08.03.2021 22:54:50:802 kernel usb 1-4: device descriptor read/64, error -71
08.03.2021 22:54:51:035 kernel usb 1-4: device descriptor read/64, error -71

Solution

Luckily this Digispark I own does not disable the RESET pin(PB5) as the Genuine Digispark does, therefore I still can use the ISP to flash a new bootloader into the ATtiny85.

Tools required

Latest micronucleus command line tool and the ATtiny85 bootloader firmware release from GitHub - Micronucleus

avrdude executable, installed with Ardiono IDE on Linux.

A USB-ISP kit, in this case a USBasp.

Steps

Connetion:

USBasp Digispark
MOSI MOSI (PB0)
MISO MISO (PB1)
SCLK SCLK (PB2)
RESET RESET (PB5)

Run the following command:

1
avrdude -cusbasp -pattiny85 -e -v -b19200 -Uflash:w:/<path>/t85_default.hex

To solve the USB permission problem, either use the sudo or create a udev rule.

I did not modify the default fuse setting, but here’s a fuse code calculator for ATtiny85 if of any use.

The default code for my Digispark (PB5 as RESET) is E:FE, H:DF, L:F1

To set the fuse, use the following command:

1
avrdude -cusbasp -pattiny85 -e -v -Ulfuse:w:0xf1:m -Uhfuse:w:0xdf:m -Uefuse:w:0xfe:m -Uflash:w:/<path>/t85_default.hex

An example of output(with verbose flag):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
avrdude: Version 6.3, compiled on Jul  7 2020 at 19:38:43
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is "/etc/avrdude.conf"
User configuration file is "/root/.avrduderc"
User configuration file does not exist or is not a regular file, skipping

Using Port : usb
Using Programmer : usbasp
Overriding Baud Rate : 19200
AVR Part : ATtiny85
Chip Erase delay : 4500 us
PAGEL : P00
BS2 : P00
RESET disposition : possible i/o
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :

Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 6 4 0 no 512 4 0 4000 4500 0xff 0xff
flash 65 6 32 0 yes 8192 64 128 4500 4500 0xff 0xff
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00

Programmer Type : usbasp
Description : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
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 = 0x1e930b (probably t85)
avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FE
avrdude: erasing chip
avrdude: auto set sck period (because given equals null)
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "/home/foo/Downloads/t85_default.hex"
avrdude: input file /home/foo/Downloads/t85_default.hex auto detected as Intel Hex
avrdude: writing flash (8166 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 8166 bytes of flash written
avrdude: verifying flash memory against /home/foo/Downloads/t85_default.hex:
avrdude: load data flash data from input file /home/foo/Downloads/t85_default.hex:
avrdude: input file /home/foo/Downloads/t85_default.hex auto detected as Intel Hex
avrdude: input file /home/foo/Downloads/t85_default.hex contains 8166 bytes
avrdude: reading on-chip flash data:

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

avrdude: verifying ...
avrdude: 8166 bytes of flash verified

avrdude: safemode: hfuse reads as DF
avrdude: safemode: efuse reads as FE
avrdude: safemode: Fuses OK (E:FE, H:DF, L:F1)

avrdude done. Thank you.

Unplug and plug in the Digispark again, and now the device is recognized correctly.

1
2
3
4
5
6
08.03.2021 23:05:02:612	kernel	usb 1-4: new low-speed USB device number 77 using xhci_hcd
08.03.2021 23:05:02:751 vmware-usbarbitrator USBGL: kevent: adding USB device 1-4
08.03.2021 23:05:02:752 kernel usb 1-4: New USB device found, idVendor=16d0, idProduct=0753, bcdDevice= 2.05
08.03.2021 23:05:02:753 kernel usb 1-4: New USB device strings: Mfr=0, Product=0, SerialNumber=0
08.03.2021 23:05:02:770 mtp-probe checking bus 1, device 77: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-4"
08.03.2021 23:05:03:347 mtp-probe checking bus 1, device 77: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-4"

Reference

Using and reviving Digispark clones

Configuring the Digispark ATTINY85 board for Arduino IDE and upgrading the bootloader