From 5fbfbbd9526e297c14e8bf2ed01cde4d8bb0b7f9 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 18 Mar 2026 13:04:10 +0700 Subject: [PATCH 1/2] add AGENTS.md for repository guidance and conventions --- AGENTS.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..0bfc31be --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,81 @@ +# AGENTS.md + +This file provides guidance to AI coding agents when working with code in this repository. + +## Project Overview + +Adafruit nRF52 Arduino Board Support Package (BSP) — an Arduino core for Nordic nRF52 Bluetooth SoCs (nRF52832, nRF52833, nRF52840). Targets Adafruit Bluefruit boards. Combines the Arduino API with FreeRTOS, Nordic nrfx HAL, Nordic SoftDevice (BLE stack), and TinyUSB. + +**Default/preferred board:** `feather52840` (Adafruit Feather nRF52840 Express). Use this board when no specific board is specified. + +## Build Commands + +This is an Arduino BSP, not a standalone project. It builds via `arduino-cli`. + +**Build a single example:** +```bash +arduino-cli compile --warnings all --fqbn adafruit:nrf52:feather52840:softdevice=s140v6,debug=l0 path/to/sketch +``` + +**Build all examples for a board (CI script):** +```bash +python3 tools/build_all.py feather52840 +``` + +**Build all examples for all default boards:** +```bash +python3 tools/build_all.py +``` + +**Default CI boards:** `cluenrf52840`, `cplaynrf52840`, `feather52832`, `feather52840`, `feather52840sense`, `itsybitsy52840` + +**FQBN format:** `adafruit:nrf52:{variant}:softdevice={sd},debug=l0` +- SoftDevice selection: `s132v6` for nRF52832, `s140v7` for nRF52833, `s140v6` for nRF52840 + +**Skip markers for examples:** Place these files in an example directory to control CI: +- `.all.test.skip` — skip for all boards +- `.{variant}.test.skip` — skip for a specific board +- `.{variant}.test.only` — run only for that board + +## Architecture + +### Core (`cores/nRF5/`) +Arduino core implementation. Entry point is `main.cpp` which initializes hardware, creates FreeRTOS tasks (`loop_task` and `callback_task`), and starts the scheduler. Standard Arduino wiring functions (`wiring_digital.c`, `wiring_analog_nRF52.c`, etc.) wrap Nordic nrfx HAL calls. + +Key subsystems: +- **FreeRTOS** (`freertos/`) — all blocking Arduino functions use RTOS primitives internally +- **Nordic nrfx** (`nordic/nrfx/`) — hardware abstraction for peripherals (GPIO, UART, SPI, I2C, ADC, PWM, etc.) +- **SoftDevice API** (`nordic/softdevice/`) — Nordic BLE stack headers (S132 for 52832, S140 for 52840/52833) +- **Linker scripts** (`linker/`) — memory layout per chip, accounting for SoftDevice and bootloader regions + +### Variants (`variants/`) +Per-board pin definitions. Each variant has `variant.h` (pin macros, peripheral assignments) and `variant.cpp` (pin mapping array `g_ADigitalPinMap[]`, peripheral init). When adding a new board, create a new variant directory and add entries to `boards.txt`. + +### Libraries (`libraries/`) +- **Bluefruit52Lib** — BLE central/peripheral, services (UART, HID, MIDI, Battery, etc.), bonding +- **Adafruit_TinyUSB_Arduino** — USB device stack (CDC, HID, MSC, MIDI) — git submodule +- **Adafruit_LittleFS / InternalFileSytem** — flash filesystem +- **Adafruit_nRFCrypto** — CryptoCell CC310 wrapper (hash, HMAC, ECC) — git submodule +- **Wire, SPI, Servo, PDM, SoftwareSerial, RotaryEncoder** — peripheral drivers + +### Bootloader (`bootloader/`) +Precompiled UF2/hex/zip binaries per variant. Upload via UF2 drag-drop, serial DFU (`adafruit-nrfutil`), or J-Link (`nrfjprog`). + +### Build Configuration +- `platform.txt` — compiler flags, recipes, tool paths. Compiler: `arm-none-eabi-gcc`, optimization `-Ofast`, hard float ABI. +- `boards.txt` — board definitions (MCU, SoftDevice, memory sizes, USB VID/PID, debug options) +- `tools/build_all.py` — CI build orchestrator using `arduino-cli compile` with multiprocessing + +### Submodules +Some libraries (`Adafruit_TinyUSB_Arduino`, `Adafruit_nRFCrypto`) are git submodules. After cloning: +```bash +git submodule update --init +``` + +## Key Conventions + +- Compiler flags include `-Werror=return-type -Wall -Wextra` — all functions must have return statements +- C standard: `gnu11`, C++ standard: `gnu++11` with `-fno-rtti -fno-exceptions` +- Board variant names in `boards.txt` must match directory names in `variants/` +- FreeRTOS task priorities: `TASK_PRIO_LOWEST` (0) through `TASK_PRIO_HIGHEST` (4) +- `initVariant()` is a weak symbol — boards override it in `variant.cpp` for board-specific init From bc9acf2d02658ea37430d6c4c73480accbd5ae31 Mon Sep 17 00:00:00 2001 From: Ha Thach Date: Wed, 18 Mar 2026 13:51:26 +0700 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- AGENTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 0bfc31be..c054fa2b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -40,7 +40,7 @@ python3 tools/build_all.py ## Architecture ### Core (`cores/nRF5/`) -Arduino core implementation. Entry point is `main.cpp` which initializes hardware, creates FreeRTOS tasks (`loop_task` and `callback_task`), and starts the scheduler. Standard Arduino wiring functions (`wiring_digital.c`, `wiring_analog_nRF52.c`, etc.) wrap Nordic nrfx HAL calls. +Arduino core implementation. Entry point is `main.cpp` which initializes hardware, creates the main FreeRTOS task (`loop_task`), calls `ada_callback_init(...)` to set up the callback task (`adafruit_callback_task` in `cores/nRF5/utility/AdaCallback.c`), and starts the scheduler. Standard Arduino wiring functions (`wiring_digital.c`, `wiring_analog_nRF52.c`, etc.) wrap Nordic nrfx HAL calls. Key subsystems: - **FreeRTOS** (`freertos/`) — all blocking Arduino functions use RTOS primitives internally @@ -76,6 +76,6 @@ git submodule update --init - Compiler flags include `-Werror=return-type -Wall -Wextra` — all functions must have return statements - C standard: `gnu11`, C++ standard: `gnu++11` with `-fno-rtti -fno-exceptions` -- Board variant names in `boards.txt` must match directory names in `variants/` +- In `boards.txt`, each `*.build.variant` value must match a directory name under `variants/` (board IDs like `feather52840` may differ from the variant directory, e.g. `variants/feather_nrf52840_express`) - FreeRTOS task priorities: `TASK_PRIO_LOWEST` (0) through `TASK_PRIO_HIGHEST` (4) - `initVariant()` is a weak symbol — boards override it in `variant.cpp` for board-specific init