AD9361 Driver-Generation Agent
Register tables are parsed from an RF transceiver datasheet, a language model writes C register drivers, and a simulated SPI bus checks whether their behaviour really matches the datasheet.
Sole designer and experimenter, coded with AI assistance
- Python
- pdfplumber
- BM25
- Ollama
- OpenAI-compatible API
- gcc 13.3
- Docker sandbox
- Simulated SPI
- Mutation testing
- FastAPI
Background
Register drivers for RF chips are long and fiddly; the AD9361 alone has hundreds of registers. When a language model writes a driver from the datasheet, the code nearly always compiles, but compiling is only the floor. Clobbering a neighbouring bit during a read-modify-write, or overwriting where a read must come first, is invisible to the compiler and to unit tests that only check the value written.
What the system does
- Parses the datasheet into registers, fields, bit ranges and access types
- Retrieves datasheet passages per task and has the model write C driver functions
- Runs behaviour tests on a simulated SPI bus and feeds the failures back to the model for repair
My work
- Datasheet parsing: read the summary tables and two-column text of UG-671, giving 344 registers and 809 fields (599 named) with 0 structural QA issues; compared register by register with ADI’s official no-OS driver, 475 of 560 field macros have exactly matching bit ranges.
- Behaviour checks: a simulated SPI bus tests whether neighbouring bits survive, illegal arguments are rejected, bus failures return an error and reads come before writes, about 34 scenarios per task. Code compiles and runs in a gcc 13.3 Docker sandbox with no network, a read-only file system, resource limits and a 5 s timeout.
- Loop: generate → compile → behaviour test → return diagnostics → repair, up to 3 rounds.
- Testing the tests: 11 classes of bug variant check the test suite, with 0 false alarms on correct implementations.
- Model comparison: qwen2.5-coder:7b (Q4) on local Ollama with a laptop RTX 5060, plus two cloud models, all at temperature 0.
Problems and fixes
The tests themselves can hide bugs. A full-byte overwrite behaves exactly like the correct code when every register starts at 0, so all 17 variants slipped through. Adding a 0xFF initial value caught all 17. Mutation testing forced this out; a pass rate alone would never have shown it.
Separating “the pipeline runs” from “the model can write”. A mock generator that writes wrong code on purpose and then repairs it from the diagnostics validates the loop first. Its numbers only show the loop works and are not counted as model results.
Results
- 14 held-out tasks: the local 7B passed behaviour on 9 at first and 10 after repair, and its 4 failures were all reserved-code and range checks; both cloud models reached 14/14 after repair.
- Each model ran once, with no variance estimate; the cloud models differ by a task or two, which is not enough to rank them.
Retrospective
- Only the simulated bus is used so far; nothing has run on real hardware.
- The next step is to use these behaviour tests as verifiable rewards for GRPO training of a 7B code model. That is a draft plan and has not started.