Перейти к основному содержимому
Hardware Interfaces & Logic Captures: UART, SPI, I2C & JTAG
Урок 2 из 9

Hardware Interfaces & Logic Captures: UART, SPI, I2C & JTAG

Identify UART, SPI, I2C, and JTAG/SWD buses on embedded boards, calculate UART baud rates from pulse widths, decode logic captures with sigrok, and harden debug interfaces.

Продвинутый 30 мин IoT и встраиваемые
Этого урока пока нет на выбранном языке — показана версия на другом языке. Перевод готовится.
Только в разрешённой среде — Описанные здесь приёмы применяются только в учебных лабораториях и в системах, которые принадлежат вам или на которые есть письменное разрешение.

Цели обучения

  • Distinguish UART, SPI, I2C, and JTAG/SWD by wire count, clocking, and addressing model
  • Estimate UART baud rate from a logic-analyzer waveform and open a serial console with minicom
  • Decode SPI and I2C protocol captures using sigrok-cli and Saleae Logic
  • Explain how exposed debug and flash buses undermine firmware confidentiality and how to lock them down

Рекомендуется заранее: IoT Architecture, Embedded Linux & Microcontroller Basics

#Why this matters

Before an embedded device sends a network packet, its chips exchange boot logs, calibration values, and firmware images over board-level buses. Engineers leave UART headers for boot logs, wire external flash over SPI, attach sensors via I2C, and program silicon over JTAG or SWD. In a hardware assessment or CTF challenge, capturing and decoding these signals often reveals bootloaders, root shells, and unencrypted secrets.

#Comparing board-level buses

Each hardware bus trades wire count, speed, and addressing differently. Recognizing the physical wiring narrows down which protocol decoder to run.

Bus Typical wires Clocking Addressing / selection Typical role
UART TX, RX, GND Async (shared baud rate) Point-to-point Bootloader and OS consoles
SPI SCLK, MOSI, MISO, CS, GND Sync (SCLK) Active-low CS per chip NOR flash, displays, radios
I2C SDA, SCL, GND (+ pull-ups) Sync (SCL) 7-bit or 10-bit address Sensors, RTCs, EEPROMs
JTAG / SWD TCK, TMS, TDI, TDO (or SWDIO/SWCLK) Sync test clock TAP state machine CPU halt, flash programming
  1. Probe GND and VCCConfirm 3.3V or 1.8V logic
  2. Capture with analyzerSample >= 4x bit rate
  3. Identify bus patternAsync = UART; CS+CLK = SPI; 9th-clock ACK = I2C
  4. Decode protocolRun sigrok-cli or Saleae Logic

#UART: asynchronous framing and serial consoles

UART has no clock wire. Both ends must share the same baud rate, data width, parity, and stop bits (most commonly 115200 8N1: 115200 bps, 8 data bits, no parity, 1 stop bit).

At idle, TX sits high (1). Each frame starts with a low start bit (0), sends 8 data bits least-significant bit (LSB) first, and finishes with a high stop bit (1). To determine an unknown baud rate in Saleae Logic or PulseView, measure the narrowest single-bit pulse T:

  • T around 8.68 microseconds (1 / 0.00000868) = 115200 bps.
  • T around 104 microseconds (1 / 0.00010417) = 9600 bps.
  • T around 17.36 microseconds = 57600 bps.

Sample at least 4 to 10 times faster than the bit rate so edges align cleanly.

Decoding a captured UART boot log with sigrok-cli
$ sigrok-cli -i board_boot.sr -P uart:rx=D0:baudrate=115200:format=ascii
uart-1: "U-Boot 2022.04-lab (Oct 12 2025)\r\n"
uart-1: "Hit any key to stop autoboot:  2 \r\n"

When connecting live with a 3.3V USB-to-UART adapter, cross-wire TX and RX (Adapter RX -> Target TX, Adapter TX -> Target RX) and share GND. Open the console with minicom (disabling hardware flow control when RTS/CTS are unwired):

bash
minicom -D /dev/ttyUSB0 -b 115200 -o

#SPI and I2C: synchronous transfers

Unlike UART, SPI and I2C carry an explicit clock line driven by the controller, so small clock jitter does not break decoding.

#SPI flash and peripherals

SPI uses four main signals: SCLK (clock), MOSI (Controller Out, Peripheral In), MISO (Controller In, Peripheral Out), and an active-low Chip Select (CS# or SS). While CS# is pulled low, every clock cycle shifts one bit out on MOSI and simultaneously shifts one bit in on MISO.

Two configuration bits define the SPI mode:

  • CPOL (Clock Polarity): 0 means SCLK idles low; 1 means SCLK idles high.
  • CPHA (Clock Phase): 0 samples data on the leading clock edge; 1 samples on the trailing edge.

Most SPI NOR flash chips operate in Mode 0 (CPOL=0, CPHA=0) or Mode 3 (CPOL=1, CPHA=1). In a logic capture of an SPI flash boot, you commonly see MOSI send an opcode such as 0x9F (Read JEDEC ID) or 0x03 (Read Data) followed by a 24-bit address, while MISO returns the flash bytes.

#I2C open-drain communication

I2C uses only two signal wires, SDA (data) and SCL (clock), pulled high through resistors. Any device can pull a line low, creating a wired-AND bus.

I2C EEPROM read transaction (7-bit address 0x50)I2C EEPROM read transaction (7-bit address 0x50)ControllerEEPROMSTART + 0x50 (Write)ACK (9th clock low)Register offset 0x00ACKRepeated START + 0x50 (Read)ACK + Data byte 0x4B ('K')NACK + STOP

Notice the 9th clock pulse after every 8 bits: the receiver pulls SDA low for ACK (acknowledged) or leaves it high for NACK. When decoding an I2C capture in sigrok-cli, specify both scl and sda channels:

Decoding an I2C EEPROM read in sigrok-cli
$ sigrok-cli -i eeprom_read.sr -P i2c:scl=D0:sda=D1
i2c-1: Start
i2c-1: Address write: 50
i2c-1: Data write: 00
i2c-1: Start repeat
i2c-1: Address read: 50
i2c-1: Data read: 4B
i2c-1: Data read: 45
i2c-1: Data read: 59
i2c-1: Stop

The hex bytes 4B 45 59 decode to ASCII KEY. Be careful with address notation: datasheets sometimes write the 7-bit address 0x50 in 8-bit shifted form (0xA0 for write, 0xA1 for read), because the R/W bit occupies the least-significant bit on the wire.

#JTAG and SWD debug interfaces

JTAG (IEEE 1149.1) uses TCK, TMS, TDI, and TDO (plus optional TRST) to drive a Test Access Port (TAP) state machine. ARM microcontrollers often replace or supplement JTAG with two-pin SWD (SWDIO and SWCLK).

During manufacturing, engineers use JTAG or SWD to flash firmware and run boundary-scan checks. If left unlocked on a retail board, an attacker with a hardware debugger (and tools such as OpenOCD) can halt the CPU, read internal flash even when the network stack is locked down, or single-step cryptographic routines.

#Defending hardware interfaces and common mistakes

Common analysis mistakes in the lab:

  • Forgetting common ground (GND): Without a shared ground reference, signal thresholds float and decoders show random garbage.
  • Wrong SPI mode or UART baud rate: If decoded UART text shows unreadable symbols or framing errors, recalculate the shortest bit width. If SPI bytes appear shifted by one bit, toggle CPHA or CPOL.
  • Mixing up 7-bit and 8-bit I2C addresses: Protocol analyzers such as sigrok typically report the 7-bit address (0x50), while some device datasheets list 0xA0/0xA1.

Hardening recommendations for engineers:

  • Lock JTAG and SWD in silicon: Blow one-time programmable (OTP) eFuses or enable readout protection (RDP) before shipping production hardware.
  • Disable interactive boot consoles: Remove Hit any key to stop autoboot delays, disable root login on UART, and enforce cryptographic signature verification (Secure Boot).
  • Protect data at rest on external buses: Because SPI flash and I2C EEPROM traces are easy to tap with test clips, do not store unencrypted private keys or shared secrets in external memory.

#Summary

Board-level interfaces expose how embedded chips communicate before network security controls apply. UART carries asynchronous serial consoles whose baud rate equals the inverse of the shortest bit duration, SPI transfers high-speed full-duplex frames controlled by CS# and CPOL/CPHA mode, I2C coordinates multiple peripherals with 7-bit addresses and 9th-clock ACKs, and JTAG/SWD provide direct CPU debug access. Capturing these signals safely with sigrok or Saleae Logic reveals hidden consoles and external flash reads, underscoring why production devices must lock debug fuses, disable boot prompts, and protect secrets stored on external buses.

Проверка знаний

Войдите, чтобы проходить тест, завершать уроки и сохранять прогресс. Войти в систему

Практика: проверьте свои знания