Skip to content

Instantly share code, notes, and snippets.

@Gemba
Last active March 19, 2023 16:18
Show Gist options
  • Save Gemba/621438f38fd0106393af2b3ab58c82b2 to your computer and use it in GitHub Desktop.
Save Gemba/621438f38fd0106393af2b3ab58c82b2 to your computer and use it in GitHub Desktop.
I2C-Tiny-USB Digispark Reboot Patch

I2C-Tiny-USB Digispark Reboot Patch

  • Tested with I2C-Tiny-USB commit 0a8fa3d. Verified working on Raspberry Pi 3+4. Further test on different devices appreciated.
  • Digispark used with RESETDSBL = 0 (see Notes below). Fuses: H:0x5d, L:0xe1, E:0xfe.
  • All USB devices directly connected to the Raspberry Pi.
  • Apply with patch -l < ....

Notes

  1. The Digispark bootloader has been altered to switch into programming mode when PB5 is set to Gnd (Fuse: RESETDSBL =0) insttead of waiting ~3 seconds in programming mode. This repo contains the files needed for the change. (In a nutshell: Enable this line, prepare the "trampolin" with the new bootloader, use an external programmer to set the fuses).
  2. For Raspberry Pi 4 only: If you use the I2C-Tiny-USB Digispark on a USB2 port and another USB2 device on a Pi USB3 port this patch does not work. I did not investigate the root cause. Just avoid such combination! All other combinations between Digispark/USB2/USB3 devices worked well and the I2C device showed up automagically after cold boot and warm boot of the Raspberry.

Configurations

Raspberry Pi 3B

Raspbian Debian Buster 10.6: Kernel 5.4.72-v7+

Raspberry Pi 4 (4GB)

Raspbian Debian Buster 10.8: Kernel 5.10.11-v7l+

Firmware:

# rpi-eeprom-update
BCM2711 detected
Dedicated VL805 EEPROM detected
Checking for updates in /lib/firmware/raspberrypi/bootloader/default
Use raspi-config to select either the default-production release or latest update.
BOOTLOADER: up-to-date
CURRENT: Thu  3 Sep 12:11:43 UTC 2020 (1599135103)
 LATEST: Thu  3 Sep 12:11:43 UTC 2020 (1599135103)
RELEASE: default
VL805: up-to-date
CURRENT: 000138a1
 LATEST: 000138a1
diff --git a/digispark/main.c b/digispark/main.c
index 034a06f..f8eb4e5 100644
--- a/digispark/main.c
+++ b/digispark/main.c
@@ -643,27 +643,22 @@ int main(void) {
// i2c_scan();
- usbDeviceDisconnect();
- for(i=0;i<20;i++){ /* 300 ms disconnect */
- _delay_ms(15);
+ cli();
+ usbInit();
+ i = 0;
+ while (--i) { /* fake USB disconnect for > 250 ms */
+ _delay_ms(30);
}
usbDeviceConnect();
- wdt_enable(WDTO_1S);
-
- usbInit();
sei();
pinMode(B,1,OUTPUT);
-
-
-
pinMode(B,5,INPUT);
internalPullup(B,5,DISABLE);
for(;;)
{
- wdt_reset();
usbPoll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment