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 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:
SLDCSandSSTCSread and write the control and status registers (TPISR,TPIPCR,TPIIR).SLDandSSTload and store a data-space byte through the pointer register;SSTPRsets the pointer, and the+forms step it forward.SINandSOUTread and write the I/O space.SKEYsends the 64-bit key that opens the NVM interface.
Entry
- RESET low, and it stays low for the whole session.
- Idle bits. TPIDATA is held high while TPICLK runs for at least 16 cycles. This resets the TPI's frame logic.
- Guard time. The programmer writes
TPIPCRto set the guard time between a frame the chip receives and the one it sends back. The pod sets it before the first read. - Read `TPIIR`. The identification register reads
0x80on a TPI. Anything else means nothing is listening on the wires, which is the first thing to check when the wiring is wrong. - Send the key.
SKEYfollowed by the 64-bit NVM key opens the non-volatile memory interface. - Wait for `NVMEN`. The programmer polls
TPISRuntil theNVMENbit is set. From now on the NVM controller answers.
The data-space memory map
Over TPI, everything lives in one data space, read and written through the pointer:
| Address | What it is |
|---|---|
0x0000 | I/O registers and SRAM; the NVM controller's NVMCSR is at 0x32 and NVMCMD at 0x33 |
0x3F00 | NVM lock bits |
0x3F40 | Configuration bits |
0x3FC0 | Signature: 1E 90 0B is the ATtiny104 |
0x4000 to 0x43FF | Flash, 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:
| Command | Value | Does |
|---|---|---|
| Chip erase | 0x10 | Erases the flash |
| Section erase | 0x14 | Erases the code section |
| Page erase | 0x18 | Erases one page (ATtiny102 and 104) |
| Word write | 0x1D | Writes 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:
- clears
NVMEN, which closes the NVM interface, - releases RESET, and
- 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,.elfor.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 detectand the SDK's detect identify a chip on the wires through the sametpimethod. - 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 Nano | Signal |
|---|---|---|
| LA4 | TPIC | TPICLK (PA0) |
| LA3 | TPID | TPIDATA (PA1) |
| pin 22, the reset pin | RST | RESET (PA2) |
| pin 17, +3.3 V | VCC (target row, pin 1) | target supply |
| GND | GND (target row, pin 14) | ground |
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.stderrclk 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.hexFrom 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.