Project

General

Profile

Actions

attiny-wdt

attiny-wdt is an OSHW + open source firmware project of turning an Attiny{4,5,9,10} microcontroller into a hardware watchdog that can be used to reset another CPU/SoC when it gets stuck.

The primary use case was to use it with Raspberry Pi devices. Those do have a built-in hardware watchdog themselves, but unfortuantelly it is not documented at the register-level and there is no option to enable it straight from the boot loader, so it is not really providing the kind of guarantees one would expect from a watchdog.

Operating Principle

The general idea is to use the Timer/Counter block of the ATTiny9 in the following way:
  • Clear the output OC0B on BOTTOM (counter == 0)
    • this generates a rising edge on the !RESET signal of the CPU we're guarding
  • Set the output OC0B when counter reaches OCR0B
    • this generates a falling edge on the !RESET signal of the CPU we're guarding
  • Wrap the counter once it reaches OCR0A
    • this determines the amount of time until a reset
  • Configure any falling edge on the INT0 pin to re-set the counter to zero
    • this is what the software on the CPU we're guarding nees to do to avoid the watchdog from expiring

Pinout

The board contains two connectors:

JP3

This header is used in two cases:
  1. programming phase: the firmware into the ATtiny9 (using the TPI protocol)
  2. normal use: To supply VCC to the watchdog and to connect its output with !RESET/GLOBAL_EN of the target
Number Name Description Programming Function
1 GLOBAL_EN open collector watchdog output; xpected to be connected to the !RESET of the CPU we're guarding (or GLOBAL_EN in case of Raspi) -
2 VCC 3.3V supply voltage powering the watchdog VCC
3 TPICLK - TPICLK
4 PB0 - TPIDATA
5 !RESET - !RESET
6 GND Ground GND

JP2

Number Name Description
1 GND Ground
2 PB2 Input; any falling edge re-sets the counter to zero. Connected to GPIO26 on Raspi
3 PB0/GPIO19 No function; RFU

Pictures

The pictures below show one of the first hand-soldered prototypes:

attiny_wdt_v2_top.jpg attiny_wdt_v2_bot.jpg

Firmware source code + Design Files

See https://gitea.osmocom.org/electronics/attiny-wdt

Flashing

You need
  • an attiny-wdt
  • a TPI-capable programmer for ATtiny9, such as the guloprog
  • a 2x3 to 1x5pin adapter cable (custo made) to connect the guloprog TPI Connector to attiny JP3
  • a Linux machine with avrdude (e.g. installed via apt install avrdude on Debian/Ubuntu). Tested with avrdude 6.3

Physical connection

full setup with usb cable, guloprog, 2x3-1x5 cable and attiny-wdt:

attiny_wdt_with_gulprog_cable.jpg

detailed view of 2x3 cable in guloprog

guloprog_with_cable.jpg

detailed view of 1x5 cable in attiny-wdt

attiny_with_cable.jpg

avrdude command for flashing

Assuming your firmware file is called attiny-wdt.hex, you can use the fa command like:

avrdude -p attiny9 -P usb -c usbasp -U flash:w:attiny-wdt.hex

The successful output looks like this:

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e9008 (probably t9)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "attiny-wdt.hex" 
avrdude: input file attiny-wdt.hex auto detected as Intel Hex
avrdude: writing flash (116 bytes):

Writing | ################################################## | 100% 0.41s

avrdude: 116 bytes of flash written
avrdude: verifying flash memory against attiny-wdt.hex:
avrdude: load data flash data from input file attiny-wdt.hex:
avrdude: input file attiny-wdt.hex auto detected as Intel Hex
avrdude: input file attiny-wdt.hex contains 116 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.04s

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

avrdude done.  Thank you.

LED test assembly.

This is a small helper that allows to test attiny-wdt without a Raspi target device. It will illuminate a yellow LED whenever the GLOBAL_EN (reset) is asserted.

attiny_wdt_led_test.jpg

Updated by laforge 3 months ago · 8 revisions

Add picture from clipboard (Maximum size: 48.8 MB)