| name | zephyr-devicetree |
| description | Comprehensive Zephyr Devicetree expertise including overlays, bindings, C API macros, pin control, clocks, interrupts, DMA, and address translation. Use this skill when you need to: (1) Understand or create .dts/.dtsi/.overlay files, (2) Write or debug devicetree bindings (.yaml), (3) Use DT_* macros in C/C++ code, (4) Configure pin control, clocks, interrupts, or DMA in devicetree, (5) Resolve devicetree-related build errors, (6) Understand address translation and memory regions. |
Zephyr Devicetree Skill
Expert guidance on Zephyr's devicetree system for hardware description, driver integration, and build-time code generation.
Table of Contents
- Core Concepts
- Common Workflows
- Hardware Configuration
- Advanced Topics
- Troubleshooting
Core Concepts
Understanding Devicetree Structure
Devicetree is a tree of nodes and properties. Zephyr uses bindings to validate nodes and generate C macros.
Key Files in a Build
After building, check these for debugging:
build/zephyr/zephyr.dts — Final merged devicetree
build/zephyr/include/generated/devicetree_generated.h — Generated macros
Common Workflows
1. Modifying Hardware via Overlays
Overlays customize hardware without modifying base Zephyr files.
- Override properties, add nodes, enable/disable devices: See overlays.md
2. Writing Custom Bindings
Bindings define the schema for devicetree nodes.
3. Accessing Devicetree from C Code
Zephyr provides compile-time macros to access devicetree data.
- Basic macros (node IDs, properties, registers): See macros.md
- Advanced macros (iteration, strings, bus helpers): See advanced-macros.md
Hardware Configuration
Pin Control (Pinctrl)
Configure pin multiplexing and electrical properties.
Clocks
Configure clock providers and consumers.
Interrupts
Configure interrupt controllers and consumers with multi-level support.
DMA
Configure DMA controllers and channel assignments.
Advanced Topics
Address Translation
Understanding #address-cells, #size-cells, and ranges for complex SoC hierarchies.
Advanced Binding Features
Child bindings, enums, const, specifier-cells, and binding inheritance.
Advanced C Macros
Iteration macros, string helpers, and bus-specific conveniences.
Troubleshooting
For common errors and debugging techniques:
Quick Reference
| Error | Likely Cause | Fix |
|---|
| "binding for ... not found" | Missing or mismatched compatible | Check binding exists and compatible matches |
DEVICE_DT_GET() returns NULL | Node disabled | Add status = "okay"; |
__device_dts_ord_N linker error | Driver not enabled | Enable driver in Kconfig |
| Property type mismatch | Binding expects different type | Check binding's type: field |
Practical Examples
See examples.md for complete working examples:
- GPIO LED (Blinky)
- I2C Sensor
- SPI Flash with Partitions
- PWM Buzzer
- UART with Pin Control
- ADC Channel Configuration
- CAN Bus Setup
- Timer/Counter Configuration