Skip to content
Skills Library
Programming · Analysis

peripheral-offload

/peripheral-offload

Decide whether firmware work belongs in software, an on-chip peripheral (DMA, RMT, PCNT, MCPWM, PIO, ADC monitor, glitch filter, ULP) or external silicon, and verify the chip has it before designing around it. Use when about to write an ISR, a polling loop, a bit-bang or a busy-wait, when a control loop shows jitter or overruns, or when weighing an offload proposal (including one from another model).

Licence
MIT
Last repository change
13.11.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
1
Deprecation

No signals detected. Repository changed on 13.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Decide whether firmware work belongs in software, an on-chip peripheral (DMA, RMT, PCNT, MCPWM, PIO, ADC monitor, glitch filter, ULP) or external silicon, and verify the chip has it before designing around it. Use when about to write an ISR, a polling loop, a bit-bang or a busy-wait, when a control loop shows jitter or overruns, or when weighing an offload proposal (including one from another model).

Arguments

/peripheral-offload [task, e.g. 'wheel encoders on robocar' or a proposal to evaluate]
Original author description

Decide whether firmware work belongs in software, an on-chip peripheral (DMA, RMT, PCNT, MCPWM, PIO, ADC monitor, glitch filter, ULP) or external silicon, and verify the chip has it before designing around it. Use when about to write an ISR, a polling loop, a bit-bang or a busy-wait, when a control loop shows jitter or overruns, or when weighing an offload proposal (including one from another model).

How it works

  1. 1. Measure the cost before offloading anything
  2. 2. Pick the tier
  3. 3. Verify the chip has the peripheral, at the IDF version in use
  4. 4. Check the offload against the actual board
  5. 5. Make a failed offload loud
  6. 6. Evaluating an offload proposal
  7. Worked examples in this repo
Original SKILL.md headings · 123 lines, 1,104 words
SKILL.md preview
---
name: peripheral-offload
description: Decide whether firmware work belongs in software, an on-chip peripheral (DMA, RMT, PCNT, MCPWM, PIO, ADC monitor, glitch filter, ULP) or external silicon, and verify the chip has it before designing around it. Use when about to write an ISR, a polling loop, a bit-bang or a busy-wait, when a control loop shows jitter or overruns, or when weighing an offload proposal (including one from another model).
user-invocable: true
argument-hint: "[task, e.g. 'wheel encoders on robocar' or a proposal to evaluate]"
allowed-tools: Bash, Read, Grep, Glob, WebFetch
---

# Peripheral Offload: Software, On-Chip Hardware, or External Silicon

Moving work from a CPU loop into a peripheral removes interrupt jitter and frees
the core, but each offload adds a driver, a register-width constraint and a
failure mode that can be silent. This skill is the decision procedure and the
checks that keep an offload proposal honest.

## 1. Measure the cost before offloading anything

An offload is justified by a number, not by the category of task. Get one of:

- **Rate × per-event cost.** 25 000 context switches per second is a problem;
  one CRC over 100 bytes at parameter save is not.
- **Jitter or overrun on the loop that matters.** The robocar executor runs at
  30 Hz and guards the overrun case (`reactive_controller.c`, the
  `xTaskDelayUntil() == pdFALSE` branch); `freertos-task-gotchas.md` §1 is what
  an unguarded overrun does.
- **A latency bound a test pins.** `REACTIVE_REFLEX_WORST_CASE_MS` in
  `test_reflex_latency.c` is the obstacle-to-brake budget; an offload that does
  not move it is not a latency fix.

No number means no offload yet. Leave the software path, add the measurement.

## 2. Pick the tier

| Task | Software | On-chip | External |
|---|---|---|---|
| Buffer movement (I2S, SPI, UART, ADC) | per-byte copy | DMA, descriptor ring | — |
| Step / pulse generation | timer ISR toggling | PIO, RMT TX, MCPWM, timer + DMA | motion controller (TMC5160) |
| Quadrature / pulse count | GPIO edge ISR | PCNT, timer encoder mode, PIO | counter IC (LS7366R) |
| Pulse-width capture | edge ISR + timestamp | RMT RX, MCPWM capture, input capture | — |
| Non-standard serial timing | bit-bang | PIO, RMT, LCD_CAM, FlexIO | — |
| Debounce / glitch reject | poll + timer | GPIO glitch filter | RC + Schmitt (74HC14) |
| Threshold watch | ADC read + compare | ADC monitor / analog watchdog, comparator | window comparator |
| Event → action without ISR | ISR reads A, writes B | ETM, PPI, EVSYS, DMAMUX | discrete logic |
| Periodic sensing while asleep | wake main core | ULP FSM / RISC-V, LP core | sensor with interrupt pin |
| CRC / hash / crypto | table or bitwise loop | CRC unit, DMA sniffer, AES/SHA | — |
| Many PWM channels | LEDC/MCPWM per pin | — | PCA9685 over I2C |

Prefer the lowest tier that meets the measured need. External silicon costs
board area, a BOM line (`part-sourcing.md`) and a bus transaction per update.

## 3. Verify the chip has the peripheral, at the IDF version in use

Peripheral sets differ inside one family, and recalled capability lists are
wrong often enough to matter. ESP32-S3 has **no ETM** (that is C6, H2 and P4);
it has a fixed pin glitch filter but not the configurable one; it has no CRC
peripheral (use `esp_rom_crc32_le()`). Read the capability header for the exact
target and the IDF release the container pins (`docker-compose.yml`):

```sh
curl -sSfL https://raw.githubusercontent.com/espressif/esp-idf/release/v5.4/components/soc/esp32s3/include/soc/soc_caps.h -o /tmp/soc_caps.h
grep -nE "SOC_(ETM|PCNT|MCPWM|RMT|GDMA|ULP|RISCV_COPROC|ANA_CMPR|GPIO_.*GLITCH|ADC_MONITOR|SIMD)" /tmp/soc_caps.h
```

A macro that is absent means the peripheral is absent. For RP2040/RP2350,
STM32 and nRF, read the datasheet's peripheral chapter, not a summary.

Then read the driver's register-width limits in the IDF source before choosing
values: `esp-idf-rmt-rx.md` records three RMT RX limits (even `mem_block_symbols`
≥ 48, an 8-bit glitch filter on the source clock, a 15-bit idle threshold) that
each fail a different call.

## 4. Check the offload against the actual board

An on-chip peripheral only helps if the signal reaches a pin it can use.

- **Is the signal on an MCU pin at all?** robocar drives every motor
  and servo line through the PCA9685 (I2C), so MCPWM fault inputs, timer DMA and
  ETM cannot touch them; only `MOTOR_STBY_PIN` (GPIO1) is direct.
- **Are pins free?** Read the generated pin table in the project's `WIRING.md`
  (`hardware.toml` is the source, ADR-021). robocar has D3 (GPIO4) and
  D7 (GPIO44) spare; everything else goes through the MCP23017.
- **Does the bus already belong to someone?** A ULP polling an I2C bus the
  main core drives at 30 Hz needs arbitration the firmware does not have.
- **Does the device ever sleep?** ULP offload pays only if the main cores power
  down. A robot holding WiFi, a camera and TLS sessions never does.

## 5. Make a failed offload loud

A driver that falls back to a software path on peripheral init failure keeps
working, degraded, and hides the error (`esp-idf-rmt-rx.md`). For each offload:

- Log the init result at WARN or ERROR with the `esp_err_to_name()` text.
- Expose it in the self-report or a status command, as the robocar's
  `*_is_initialized()` accessors do.
- Re-arm on timeout where the peripheral can wedge (RMT RX does).
- Keep a host test on the logic around it (shared-core pattern, `testing.md`).

## 6. Evaluating an offload proposal

Proposals written from an indexed or summarised view of the repo describe a
design that may be gone. Check every premise against `main` before weighing the
idea:

1. **Does the named file, function or bus exist?** `rg -n "<symbol>" packages/<proj>`.
2. **Is the "current bottleneck" the current code?** Comments often describe
   the bug a constant fixed (`TTS_PCM_BATCH_BYTES` in `gemini_tts.c` records
   the 25 000 yields/s it removed).
3. **Is the hardware it assumes fitted?** `hardware.toml` and `WIRING.md` list
   what is wired; a sensor or encoder that is not there makes the proposal moot.
4. **Did the repo already reject it, with a reason?** Search the subsystem doc
   and the module header (`voice_fx_core.h` rejects a band-limit).
5. **Does the chip have it?** §3.

Report each point as confirmed, moot (premise false) or open (needs a
measurement), with the file and line that decided it.

## Worked examples in this repo

| Offload | Where | Note |
|---|---|---|
| PIO step generation | `packages/robotics/balancebot/src/stepper.pio` | `pull noblock` holds the last rate; the CPU only pushes a period per control tick |
| External PWM | robocar PCA9685 (`motor_controller.c`) | frees MCU pins and timers; costs an I2C write per change |
| I2S TX DMA with silence preload | `audio_player.c` `preload_silence()` | `auto_clear` zeroes on underrun, not at enable |
| Producer batching into a DMA consumer | `gemini_tts.c` `TTS_PCM_BATCH_BYTES` | software fix for a scheduling cost; no new peripheral |
| I2C rangefinders instead of echo timing | robocar `ultrasonic.c` (#782, #790) | moved pulse capture into the sensor module |

Counter-example: balancebot's bitwise `crc32_calc()` runs once per parameter
save over one small parameter record (`PARAM_V3_SIZE`). The RP2350 DMA CRC sniffer would save nothing
measurable, and the bitwise loop is host-testable as-is.

Versions

The database has no other skills named peripheral-offload.

Database snapshot: 13.11.2026 · package version 418133a2d431 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90esp32-chip-revision-audit
    Use when designing, reviewing, debugging or validating chip revision audit for ESP32 firmware; apply target-specific constraints, failure analysis and measurable verification before release.
  • 100driver-review
    Review and implement hardware driver code — DMA safety, interrupt correctness, timing constraints, peripheral register usage, channel drivers, and peripheral mock implementations. Use when writing, modifying, or reviewing LED drivers, SPI/I2S/RMT/UART/PARLIO/LCD_CAM peripherals,…
  • 100embedded-peripheral-bringup
    Use when bringing up embedded GPIO, UART, SPI, I2C, PWM, ADC, timers, DMA, interrupts, or board-level peripheral functionality
  • 90REPLACE-with-skill-name
    Firmware development for the <VENDOR> <BOARD NAME> (<MCU PART NUMBER>) — its <peripheral>, <peripheral>, <peripheral>, and the <SDK/HAL> + <build system> setup around them. Use when working on this board or any <compatible siblings>: project setup, <config file>, clock…
  • 100embedded-firmware
    Embedded firmware and device drivers — BSP development, peripheral driver implementation (UART, SPI, I2C, GPIO, DMA, Timer), RTOS integration (FreeRTOS, Zephyr), and system validation. Use when writing chip bring-up firmware, implementing HAL drivers, porting an RTOS, or…
  • 90esp32-peripheral-instance-budget
    Use when designing, reviewing, debugging or validating peripheral instance budget for ESP32 firmware; apply target-specific constraints, failure analysis and measurable verification before release.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.