mirror of
https://github.com/hathach/tinyusb.git
synced 2025-10-29 03:25:41 +00:00
3.6 KiB
3.6 KiB
Agent Handbook
Shared TinyUSB Ground Rules
- Keep TinyUSB memory-safe: avoid dynamic allocation, defer ISR work to task context, and follow C99 with two-space indentation/no tabs.
- Match file organization: core stack under
src, MCU/BSP support inhw/{mcu,bsp}, examples underexamples/{device,host,dual}, docs indocs, tests undertest/{unit-test,fuzz,hil}. - Use descriptive snake_case for helpers, reserve
tud_/tuh_for public APIs,TU_for macros, and keep headers self-contained with#if CFG_TUSB_MCUguards where needed. - Prefer
.clang-formatfor C/C++ formatting, runpre-commit run --all-filesbefore submitting, and document board/HIL coverage when applicable. - Commit in imperative mood, keep changes scoped, and supply PRs with linked issues plus test/build evidence.
Build and Test Cheatsheet
- Fetch dependencies once with
python3 tools/get_deps.py [FAMILY]; assets land inlib/andhw/mcu/. - CMake (preferred):
cmake -G Ninja -DBOARD=<board> -DCMAKE_BUILD_TYPE={MinSizeRel|Debug}inside an examplebuild/dir, thenninjaorcmake --build .. - Make (alt):
make BOARD=<board> [DEBUG=1] [LOG=2 LOGGER=rtt] allfrom the example root; adduf2,flash-openocd, orflash-jlinktargets as needed. - Bulk builds:
python3 tools/build.py -b <board>to sweep all examples; expect occasional non-critical objcopy warnings. - Unit tests:
cd test/unit-test && ceedling test:all(or a specifictest_<module>), honor Unity/CMock fixtures undertest/support. - Docs:
pip install -r docs/requirements.txtthensphinx-build -b html . _buildfromdocs/.
Validation Checklist
pre-commit run --all-filesafter edits (install withpip install pre-commit && pre-commit install).- Build at least one representative example (e.g.,
examples/device/cdc_msc) via CMake+Ninja or Make. - Run unit tests relevant to touched modules; add fuzz/HIL coverage when modifying parsers or protocol state machines.
Copilot Agent Notes (.github/copilot-instructions.md)
- Treat this handbook as authoritative before searching or executing speculative shell commands; unexpected conflicts justify additional probing.
- Respect build timing guidance: allow ≥5 minutes for single example builds and ≥30 minutes for bulk runs; never cancel dependency fetches or builds mid-flight.
- Support optional switches:
-DRHPORT_DEVICE[_SPEED], logging toggles (LOG=2,LOGGER=rtt), and board selection helpers fromtools/get_deps.py. - Flashing shortcuts:
ninja <target>-jlink|openocd|uf2ormake BOARD=<board> flash-{jlink,openocd}; list Ninja targets withninja -t targets. - Keep Ceedling installed (
sudo gem install ceedling) and available for per-test or full suite runs triggered fromtest/unit-test.
Claude Agent Notes (CLAUDE.md)
- Default to CMake+Ninja for builds, but align with Make workflows when users rely on legacy scripts; provide DEBUG/LOG/LOGGER knobs consistently.
- Highlight dependency helpers (
tools/get_deps.py rp2040) and reference core locations:src/,hw/,examples/,test/. - Run
clang-formaton all touched files to ensure consistent formatting. - Use
TU_ASSERTfor all fallible calls to enforce runtime checks. - Ensure header comments retain the MIT license notice.
- Add descriptive comments for non-trivial code paths to aid maintainability.
- Release flow primer: bump
tools/make_release.pyversion, run the script (updatessrc/tusb_option.h,repository.yml,library.json), refreshdocs/info/changelog.rst, then tag. - Testing reminders: Ceedling full or targeted runs, specify board/OS context, and ensure logging of manual hardware outcomes when available.