Back to resources
Chip programming
Firmware
HIL

Programming the ATtiny104 over TPI with a BenchPod

How the BenchPod programs an ATtiny104 over Microchip's three-wire TPI: the 12-bit frame, the entry sequence and NVM key, the data-space memory map, word writes and page erase, starting the new program, wiring on an Xplained Nano and bench results.

Edward Viaene · November 25, 2026 · 9 min read

The ATtiny104 is a tiny 14-pin AVR with 1 KB of flash and 32 bytes of SRAM. It has no SWD port and no bootloader. Its programming port is TPI, the Tiny Programming Interface that Microchip uses on the small ATtiny4, 5, 9, 10, 20, 40, 102 and 104 parts. TPI takes three wires: a clock, a bidirectional data line and RESET. On an Xplained Nano the on-board debugger drives them; elsewhere it takes an Atmel-ICE, a mEDBG or a similar programmer.

A BenchPod can drive it directly from three of its pins, as one of its pin programmers. This article is part of a series, one per chip we have run on real hardware: the overview of how the BenchPod flashes microcontrollers lists them all. It covers how TPI works, how a programmer enters it and writes the flash, the data-space memory map, the wiring on an ATtiny104 Xplained Nano, what we measured, and how the new program gets started. Support for the chip, including the automatic start of the program, ships in firmware 4.0.6.

TPI in one paragraph

TPI uses three pins, which share their pads with port pins:

  • TPICLK (PA0) is the clock. The programmer drives it.
  • TPIDATA (PA1) is the data line, in both directions. Host and chip take turns on it.
  • RESET (PA2) is held low for the whole session. It is what switches the pins over from port pins to the programming interface.

Everything moves in 12-bit frames. The chip only answers when it is asked, so the protocol is a strict request and reply.

The 12-bit frame

A TPI frame: twelve TPICLK cycles carrying a start bit, eight data bits LSB first, an even parity bit and two stop bits, with TPIDATA changing while TPICLK is low and sampled on the rising edge
A TPI frame: twelve TPICLK cycles carrying a start bit, eight data bits LSB first, an even parity bit and two stop bits, with TPIDATA changing while TPICLK is low and sampled on the rising edge

A frame is start bit (0), eight data bits LSB first, an even parity bit, two stop bits (1). The sender changes TPIDATA while TPICLK is low and the receiver samples it on the rising edge. The parity bit makes the number of 1s in the data bits plus the parity bit even, and a frame that fails the parity or stop-bit check sets an error flag, after which the programmer starts over.

Three kinds of frames carry the whole protocol: a one-byte instruction, a data byte that follows it, and, for a read, a turnaround in which the host releases TPIDATA and the chip sends the frame back. The instructions are the TPI's own small set:

  • SLDCS and SSTCS read and write the control and status registers (TPISR, TPIPCR, TPIIR).
  • SLD and SST load and store a data-space byte through the pointer register; SSTPR sets the pointer, and the + forms step it forward.
  • SIN and SOUT read and write the I/O space.
  • SKEY sends the 64-bit key that opens the NVM interface.

Entry

The entry sequence: RESET low, at least 16 idle bits with TPIDATA high, guard time in TPIPCR, TPIIR read as 0x80, the NVM key sent with SKEY and NVMEN set in TPISR; and the exit: NVMEN cleared, RESET released and a short reset pulse with no clock
The entry sequence: RESET low, at least 16 idle bits with TPIDATA high, guard time in TPIPCR, TPIIR read as 0x80, the NVM key sent with SKEY and NVMEN set in TPISR; and the exit: NVMEN cleared, RESET released and a short reset pulse with no clock
  1. RESET low, and it stays low for the whole session.
  2. Idle bits. TPIDATA is held high while TPICLK runs for at least 16 cycles. This resets the TPI's frame logic.
  3. Guard time. The programmer writes TPIPCR to set the guard time between a frame the chip receives and the one it sends back. The pod sets it before the first read.
  4. Read `TPIIR`. The identification register reads 0x80 on a TPI. Anything else means nothing is listening on the wires, which is the first thing to check when the wiring is wrong.
  5. Send the key. SKEY followed by the 64-bit NVM key opens the non-volatile memory interface.
  6. Wait for `NVMEN`. The programmer polls TPISR until the NVMEN bit is set. From now on the NVM controller answers.

The data-space memory map

The ATtiny104 data space seen over TPI: I/O registers and SRAM at the bottom, NVM lock bits at 0x3F00, configuration bits at 0x3F40, signature at 0x3FC0 and flash mapped at 0x4000
The ATtiny104 data space seen over TPI: I/O registers and SRAM at the bottom, NVM lock bits at 0x3F00, configuration bits at 0x3F40, signature at 0x3FC0 and flash mapped at 0x4000

Over TPI, everything lives in one data space, read and written through the pointer:

AddressWhat it is
0x0000I/O registers and SRAM; the NVM controller's NVMCSR is at 0x32 and NVMCMD at 0x33
0x3F00NVM lock bits
0x3F40Configuration bits
0x3FC0Signature: 1E 90 0B is the ATtiny104
0x4000 to 0x43FFFlash, 1 KB

The signature read is how the pod identifies the chip: 1E 90 0B is the ATtiny104.

Erasing and writing

The NVM controller takes a command in NVMCMD and runs it when the data is written. The commands the pod uses:

CommandValueDoes
Chip erase0x10Erases the flash
Section erase0x14Erases the code section
Page erase0x18Erases one page (ATtiny102 and 104)
Word write0x1DWrites one 16-bit word

After each command the programmer polls the NVMBSY bit in NVMCSR until the controller is done. A word write goes like this: set the pointer to the word's address in flash space, write 0x1D to NVMCMD, store the low byte and then the high byte through the pointer (the second store starts the write), and poll NVMBSY. The pod writes the whole image this way and then reads it back through the same pointer to verify it.

Chip erase and page erase both work on the ATtiny104. Page erase only touches the pages the image covers, which keeps the rest of the flash as it was, for example a bootloader or stored data; the other chips of the TPI family erase their whole code section instead.

Starting the program

A chip in TPI mode is held in reset, and a reset that ends with the TPI still enabled would leave the chip waiting for frames. At the end of a session that wrote the chip and should run it, the pod:

  1. clears NVMEN, which closes the NVM interface,
  2. releases RESET, and
  3. gives one more short reset pulse without clocking TPICLK, so the TPI stays disabled and the new program starts from the reset vector.

That last pulse is what makes the programmed code run on its own, with no power cycle and no press on a button.

How the pod runs it

  • The host (the Python SDK, the CLI or the MCP server) reads the .hex, .elf or .bin, asks the pod for the chip's signature, looks it up in its device table, stages the image in the pod's memory and polls the job. benchpod detect and the SDK's detect identify a chip on the wires through the same tpi method.
  • The pod's MCU runs the entry, the frame handling and the write-then-verify loop.
  • The FPGA produces the clock and the data timing on the pins, at the target's I/O voltage, and samples TPIDATA on the rising edge of TPICLK.

The programming speed is a few hundred bytes per second, which suits a chip with 1 KB of flash.

3.3 V is enough for this one

The ATtiny102 and ATtiny104 can be programmed at 1.8 V to 5.5 V, so the pod's 1.8 V and 3.3 V I/O works directly. The older ATtiny4, 5, 9, 10, 20 and 40 need 5 V during programming; with those, the target has to run from 5 V and the pod's lines go through a level shifter, since its I/O is 1.8 or 3.3 V.

Wiring an ATtiny104 Xplained Nano

The on-board debugger header of the Xplained Nano follows Microchip's standard pinout: pin 1 RST, pin 2 TPID, pin 3 TPIC, pin 5 VREG, pin 9 GND and pin 10 VUSB. RST, TPID and TPIC reach PA2, PA1 and PA0 through 0 ohm resistors. The target row has VCC (pin 1) and GND (pin 14).

Pod (J1)Xplained NanoSignal
LA4TPICTPICLK (PA0)
LA3TPIDTPIDATA (PA1)
pin 22, the reset pinRSTRESET (PA2)
pin 17, +3.3 VVCC (target row, pin 1)target supply
GNDGND (target row, pin 14)ground
The pod's J1 header wired to the ATtiny104 Xplained Nano: LA4 to TPIC, LA3 to TPID, the reset pin to RST, +3.3 V to VCC and GND to GND
The pod's J1 header wired to the ATtiny104 Xplained Nano: LA4 to TPIC, LA3 to TPID, the reset pin to RST, +3.3 V to VCC and GND to GND

The board's own debugger and the chip share the supply, so leave the board's USB unplugged and power it from the pod. The user LED is on PA5 and the user button on PB1. On a custom board the same three pins plus VCC and GND go to a 6-pin TPI header.

Bench results

We ran the ATtiny104 Xplained Nano at 3.3 V with the wiring above:

  • The pod read the signature `1E 90 0B` and identified the chip, with and without a device name.
  • A full 1 KB flash write and verify took 3.8 s, about 270 bytes per second, and repeated with the same result.
  • A 32-byte blink program took 0.3 s and the LED started blinking on its own when the session ended.
  • Both chip erase and page erase were verified.

Using it

From Python, with the pytest package:

from embeddedci.benchpod import BenchPod

with BenchPod("192.168.1.50", la_voltage=3.3) as bp:
    # Only enter TPI and read the signature: a wiring check, nothing is written.
    print(bp.flash(target="attiny-tpi", clk=4, data=3, nreset=True, dry_run=True).stdout)

    r = bp.flash(target="attiny-tpi", device="ATtiny104", clk=4, data=3,
                 nreset=True, file="blink.hex", erase="page")
    assert r.ok, r.stderr

clk is the LA pin on TPICLK, data the one on TPIDATA, and nreset=True says RESET is on the pod's own reset pin (J1 pin 22). device is optional: without it the SDK identifies the chip from its signature, and with it a different chip on the pins is an error before anything is erased. erase is "chip" by default, "page" erases only the pages written.

From the command line:

benchpod flash --target attiny-tpi --clk 4 --data 3 --reset nrst --info
benchpod flash --target attiny-tpi --device ATtiny104 --clk 4 --data 3 --reset nrst --erase page --file blink.hex

From an AI agent, the MCP server's flash tool takes the same arguments with target="attiny-tpi".

TPI works on real chips with the pin-programmer image installed with benchpod install-blobs; the automatic start of the program after the write ships in firmware 4.0.6. The same attiny-tpi target covers the rest of the family (the 5 V parts need the level shifting described above); the pin programmers page lists the other protocols. Every chip and method we have verified on real hardware is in How the BenchPod flashes microcontrollers.