Back to resources
Chip programming
Firmware
HIL

Flashing a Teensy 4.1 over USB with a BenchPod

How the BenchPod flashes a Teensy 4.1 through its HalfKay loader: the HID report format, the sequence from the program button to the running program, the i.MX RT1062 boot image, and bench results.

Edward Viaene · November 23, 2026 · 10 min read

The Teensy 4.1 is a small board built around the NXP i.MX RT1062, a 600 MHz Cortex-M7 that runs its program from an 8 MB QSPI flash chip. It has no debug header to speak of. You program it over its own USB port, through a loader called HalfKay: press the program button, the board shows up as a USB HID device, and the host sends the image in fixed-size reports. On a desk, the Teensy Loader app or teensy_loader_cli does that.

A BenchPod can do the same job as the USB host. The pod enumerates the Teensy, sends the image in HalfKay reports and starts the new program, from a test script, the CLI or an AI agent. 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 the HalfKay protocol, the sequence from the button to a running program, the boot image the i.MX RT1062 expects, how the pod runs it, the wiring, and what we measured.

HalfKay in one paragraph

HalfKay is a plain HID device with vendor ID 16C0 and product ID 0478. It needs no driver on any operating system, and it has no bulk endpoints and no commands to read anything back. The host writes with one kind of request: a HID SET_REPORT on endpoint 0 (bmRequestType 0x21, bRequest 0x09, wValue 0x0200 for an output report). Each report carries one block of the image behind a small header that says where it goes. That is the whole protocol: write blocks, then send one special report that reboots the board.

The report format

A HalfKay report: a 64-byte header whose first three bytes hold the address, then one 1024-byte block. The first block erases the flash, all-0xFF blocks are skipped, and a report with the address FF FF FF boots the board.
A HalfKay report: a 64-byte header whose first three bytes hold the address, then one 1024-byte block. The first block erases the flash, all-0xFF blocks are skipped, and a report with the address FF FF FF boots the board.
  • Header. 64 bytes. Bytes 0 to 2 hold the address of the block, little-endian; bytes 3 to 63 are zero.
  • Block. 1024 bytes on the Teensy 3.x and 4.x boards, 512 on the Teensy LC. A report is therefore 1088 bytes on a Teensy 4.1. The last block of an image is padded with 0xFF.
  • Address. The offset from the start of flash, not the address the CPU sees. On a Teensy 4.x the flash is mapped at 0x60000000, so an image linked there starts at loader address 0, and 0x60001000 is sent as 001000.
  • The first block erases. Before it writes block 0, the loader erases the flash. That request takes far longer than the others, and the loader does not take it until the erase is done. A host keeps trying for a long time on that one block.
  • Blocks of `0xFF` are skipped. Erased flash already reads 0xFF, so a block that is all 0xFF does not need to be sent. The first block is always sent, because it is the one that starts the erase.
  • The boot report. A report whose address bytes are FF FF FF and whose other bytes are zero tells the loader to leave and start the program.

A 4256-byte image at address 0 takes five data reports (the last one padded) and the boot report.

From the button to a running program

The sequence: the program button starts HalfKay (red LED on), the board enumerates as 16C0:0478, the first block erases and is written, the other blocks follow, the boot report starts the new program.
The sequence: the program button starts HalfKay (red LED on), the board enumerates as 16C0:0478, the first block erases and is written, the other blocks follow, the boot report starts the new program.
  1. Start the loader. Press the program button. A small bootloader chip on the Teensy takes over the i.MX RT1062 and starts HalfKay, and the red LED next to the button lights. Whatever program ran before is gone from the bus.
  2. Enumerate. The board appears as 16C0:0478, a full-speed HID device. The host checks those IDs before it sends anything.
  3. First block. The host sends block 0. The loader erases the flash, then writes the block; until the erase is done, the request is not taken, and the host retries.
  4. The other blocks, in address order, skipping any that are all 0xFF. Each one is written as it arrives, and the next request waits until the loader is ready.
  5. Boot. The FF FF FF report. HalfKay leaves the bus, the red LED goes out, and the i.MX RT1062 boots the new image from flash.

There is no verify step. HalfKay has no way to read the flash back, so neither the Teensy Loader nor the pod can compare what was written with the file. The proof that a flash worked is the new program running.

The boot image the i.MX RT1062 expects

The loader writes bytes; it is the chip's boot ROM that decides whether they are a program. On reset, the i.MX RT1062 ROM reads the start of the QSPI flash and expects three structures before any code:

The start of a Teensy 4.x image: the FlexSPI configuration block at 0x60000000, the image vector table at 0x60001000, the boot data at 0x60001020, then the program.
The start of a Teensy 4.x image: the FlexSPI configuration block at 0x60000000, the image vector table at 0x60001000, the boot data at 0x60001020, then the program.
AddressLoader addressWhat it is
0x60000000000000FlexSPI configuration block (tag FCFB): how the ROM talks to the flash chip, its read command, clock and size
0x60001000001000Image vector table (IVT), 32 bytes: header 0x432000D1, the entry point, a pointer to the boot data and to itself
0x60001020001020Boot data, 12 bytes: the image's start (0x60000000), its length, and a plugin flag (0)
afterThe program: startup code first

The Teensyduino core and its linker script put these in place for every sketch. A bare-metal image has to carry them itself, which is why even a minimal LED blinker is a little over 4 KB: the gap between the configuration block and the IVT is padding.

How the pod runs it

Who does what: the host reads the file and stages the image in the pod, the pod's MCU is the USB host and sends the HalfKay reports, the Teensy's own USB cable goes to the pod's USB host port, and its 5 V comes from a supply on the rig.
Who does what: the host reads the file and stages the image in the pod, the pod's MCU is the USB host and sends the HalfKay reports, the Teensy's own USB cable goes to the pod's USB host port, and its 5 V comes from a supply on the rig.
  • The host (the Python SDK, the CLI or the MCP server) reads a .hex or .bin file. A Teensyduino .hex carries addresses from 0x60000000 up; the host turns it into a binary and subtracts 0x60000000, so it starts at loader address 0. A .bin starts at address 0 unless you say otherwise. The host uploads the image into the pod's memory and starts the job. It picks the teensy mode by itself when the device on the port is 16C0:0478.
  • The pod's MCU is the USB host. It checks the device IDs, then sends the reports from the staged image in the background, and reports progress in blocks. The phases it reports are start, write, leave and done. When a report is not taken, it tries again every 10 ms: for up to 45 seconds on the first block, which carries the erase, and up to 5 seconds on every other block. Blocks of 0xFF are skipped, never the first.
  • The board runs nothing of yours during the flash: HalfKay is all that is awake on the USB side.

Once the image is in the pod, the USB side does not depend on the network: the whole write runs between the pod and the board.

Wiring a Teensy 4.1

The Teensy's own USB cable goes into a USB-A breakout on the pod's USB-C connector (port usb_c), as the USB docs page describes. That carries D+, D- and GND.

The Teensy also needs 5 V on VBUS. On our rig it comes from the rig's 5 V supply. While the pod hosts a board, its own USB console and USB network are off, so reach the pod over the LAN or the cloud.

To start HalfKay, press the program button. The pod flashes a board that is already in its loader; it does not press the button for you. Teensyduino also documents a software way in for a sketch that has USB serial: set the serial port to 134 baud and the sketch reboots into HalfKay. A sketch built with a non-serial USB type takes a HID feature report instead. The pod does not send either today, and a program with no USB at all, such as a bare-metal image, can only be started into the loader with the button.

Bench results

We ran this on a Teensy 4.1 on the pod's USB host port, wired as above, with the pod reached over the LAN:

  • Before flashing, the board ran its factory blink program and enumerated as 16C0:0486 ("Teensyduino RawHID"), full speed, with its descriptors read in 219 ms. That program has no USB serial port, so the program button started HalfKay, and the red LED came on.
  • usb_flash in teensy mode at address 0, with a 4256-byte bare-metal image (configuration block, IVT, boot data, and a loop that toggles pin 13, the LED, through GPIO2 bit 3): flashed 4256 bytes in 0.3 s.
  • After the write the pod sent the boot report. HalfKay left the bus and the program ran: nothing enumerated any more, because the program has no USB, and the LED blinked.
  • To show the running program was the one we wrote, we flashed two builds, the second with a delay three times shorter. The first blinked about 1 s on and 1 s off; after the second flash the LED blinked visibly about three times faster.

Things to know

  • There is no read-back. HalfKay cannot read flash, so a flash is checked by what the board does afterward: a boot message on a UART, a pin toggling, a USB device appearing.
  • The first block is slow, and that is normal. It carries the erase of the flash. A host that gives up after a normal block timeout fails on block 0.
  • Loader addresses start at 0. A .hex linked at 0x60000000 has to be rebased; sending the CPU address would land outside the flash.
  • The boot image structures are required. Without the FlexSPI configuration block and the IVT at their addresses, the loader writes the image and the board then does nothing at all.
  • Code in flash runs slowly with the cache off. A bare-metal program runs straight from the QSPI flash, and the i.MX RT1062 leaves its caches off unless the startup code turns them on. A busy-wait loop then runs far slower than its cycle count suggests, so calibrate delays on the board, or turn the caches on. The Teensyduino startup code does that, and copies the code that needs speed into the chip's fast internal RAM.
  • `leave=False` keeps the board in HalfKay. The pod then skips the boot report, and the board stays in its loader with the red LED on.

Using it

Flashing over USB needs firmware 4.0.3 or later: USB host mode and usb_flash arrived in that release.

From Python, with the pytest package:

from embeddedci.benchpod import BenchPod

with BenchPod("192.168.1.50") as bp:
    # Teensy in HalfKay (program button pressed), on the pod's USB host port.
    r = bp.usb_flash("build/blink.hex")
    print(r.mode, r.reason)

The SDK starts host mode, waits for the device, and picks teensy from the board that enumerated. A .bin starts at address 0: bp.usb_flash("blink.bin"). A failure raises an error that carries the pod's result.

From the command line:

benchpod usb-flash blink.hex
benchpod usb-flash blink.bin

The CLI needs a direct link to the pod, its network address, not the cloud; over embeddedci.com use the SDK or the MCP server. From an AI agent, the MCP server's usb_flash tool takes the file, and an optional address and leave.

Underneath all three is one JSON command, after the image is staged with load_bin ("psram": true) into the pod's memory:

{"cmd": "usb_host", "enabled": true, "port": "usb_c", "timeout_s": 120}
{"cmd": "usb_flash", "mode": "teensy", "address": 0, "len": 4256}
{"cmd": "usb_flash"}

block sets the block size, 1024 by default and 512 for a Teensy LC. The last command reads the state: the phase, blocks done out of the total, and at the end ok or the reason it failed. abort stops a running flash. The reference is in the API docs, and the USB page lists which modes are tested on real hardware. Every chip and method we have verified is in How the BenchPod flashes microcontrollers.