Skip to content

Commit 48a149f

Browse files
authored
Merge pull request #393 from adafruit/add-agents-md
update AGENTS.md
2 parents 8023c1e + ac08632 commit 48a149f

2 files changed

Lines changed: 88 additions & 10 deletions

File tree

.github/workflows/githubci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
name: Build
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
push:
6-
repository_dispatch:
7+
branches: [ master ]
78
release:
89
types:
910
- created
1011

12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
1116
jobs:
1217
set-matrix:
1318
runs-on: ubuntu-latest

AGENTS.md

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,98 @@
11
# Agent Instructions
22

3+
This file provides guidance to AI agents when working with code in this repository.
4+
5+
## Project Overview
6+
7+
CDC/DFU/UF2 bootloader for Nordic nRF52 microcontrollers (nRF52832, nRF52833, nRF52840). Supports DFU over Serial, BLE OTA, and USB mass storage (UF2). Runs on 60+ boards.
8+
39
## Style
4-
- Follow the repo `.clang-format` when making changes.
10+
11+
Follow the repo `.clang-format` when making changes.
512

613
## Build / Verify
7-
- Prefer CMake for testing/verification.
8-
- Always build both boards during verification:
9-
- `feather_nrf52832`
10-
- `feather_nrf52840_express`
14+
15+
Default board: `feather_nrf52840_express`. Always verify changes against both boards:
16+
- `feather_nrf52840_express` (nRF52840)
17+
- `feather_nrf52832` (nRF52832)
1118

1219
### CMake (preferred)
1320
```bash
14-
cmake -S . -B cmake-build-feather_nrf52832 -DBOARD=feather_nrf52832
15-
cmake --build cmake-build-feather_nrf52832
16-
1721
cmake -S . -B cmake-build-feather_nrf52840_express -DBOARD=feather_nrf52840_express
1822
cmake --build cmake-build-feather_nrf52840_express
23+
24+
cmake -S . -B cmake-build-feather_nrf52832 -DBOARD=feather_nrf52832
25+
cmake --build cmake-build-feather_nrf52832
1926
```
2027

2128
### Make (alternate)
2229
```bash
23-
make BOARD=feather_nrf52832 all
2430
make BOARD=feather_nrf52840_express all
31+
make BOARD=feather_nrf52832 all
32+
```
33+
34+
### Flashing
35+
```bash
36+
make BOARD={board} flash # Flash via JLink
37+
make BOARD={board} flash-dfu # Flash via Serial/CDC DFU
38+
make BOARD={board} flash-sd # Flash SoftDevice only
2539
```
40+
41+
### Build all boards
42+
```bash
43+
python3 tools/build_all.py
44+
```
45+
46+
## Architecture
47+
48+
### MCU Variants and SoftDevices
49+
- **nrf52** (nRF52832): UART-only bootloader, default SoftDevice s132 v6.1.1
50+
- **nrf52833**: USB support, default SoftDevice s140 v7.3.0
51+
- **nrf52840**: Full USB + OTA, default SoftDevice s140 v6.1.1
52+
- Boards may override `SD_NAME`/`SD_VERSION` in their `board.mk`
53+
54+
### Key Source Structure
55+
- `src/main.c` — Bootloader entry point, DFU mode detection, LED/button init
56+
- `src/dfu_init.c` — DFU packet validation, CRC/signature verification
57+
- `src/dfu_ble_svc.c` — BLE DFU service
58+
- `src/flash_nrf5x.c` — Flash memory operations
59+
- `src/boards/boards.c` — Board abstraction (LED control, buttons, timing)
60+
- `src/usb/` — USB stack (nRF52833/nRF52840): CDC serial, MSC storage, UF2 handler
61+
- `src/usb/uf2/ghostfat.c` — Virtual FAT filesystem for UF2 drag-and-drop
62+
63+
### Board Definition System
64+
65+
Each board lives in `src/boards/{board_name}/` with:
66+
- `board.h` — Pin definitions, LED/button assignments, USB VID/PID, UF2 metadata
67+
- `board.mk` — Makefile variable `MCU_SUB_VARIANT` (nrf52, nrf52833, or nrf52840)
68+
- `board.cmake` — CMake variable `MCU_VARIANT`
69+
- `pinconfig.c` — CF2 bootloader configuration (flash/RAM size, UF2 family ID)
70+
71+
### Memory Layout (linker scripts in `linker/`)
72+
- Bootloader occupies ~38KB near end of flash (e.g., 0xF4000–0xFD800 on nRF52840)
73+
- No heap (`__HEAP_SIZE=0`), static allocation only
74+
- Special sections: double-reset detection word, bond info for OTA, MBR params, bootloader settings
75+
76+
### Submodules (`lib/`)
77+
- `tinyusb` — USB device stack
78+
- `nrfx` — Nordic HAL drivers
79+
- `uf2` — UF2 format tools
80+
- `tinycrypt` — Crypto (only when `SIGNED_FW=1`)
81+
- `sdk/`, `sdk11/` — Nordic SDK libraries
82+
- `softdevice/` — Precompiled Bluetooth stack binaries
83+
84+
### Compile-Time Feature Flags
85+
- `SIGNED_FW` — Require signed firmware (disables UF2 unless `FORCE_UF2=1`)
86+
- `DUALBANK_FW` — Dual-bank updates
87+
- `DEFAULT_TO_OTA_DFU` — Default to BLE OTA instead of serial DFU
88+
- `DEBUG` — Enable RTT debugging, larger bootloader region
89+
90+
## CI
91+
92+
GitHub Actions (`.github/workflows/githubci.yml`) builds all boards in parallel using a matrix generated from `src/boards/` directory names. On release, artifacts (zip, hex, uf2) are uploaded as release assets.
93+
94+
## Required Toolchain
95+
96+
- `arm-none-eabi-gcc` (tested with 12.3.1)
97+
- Python 3 with: `adafruit-nrfutil`, `intelhex`
98+
- `nrfjprog` (for JLink flashing)

0 commit comments

Comments
 (0)