zephyr devicetree

news/2025/2/9 1:36:56 标签: 嵌入式硬件, mcu, 单片机

Syntax and structure — Zephyr Project Documentation 

Input files

There are four types of devicetree input files:

  • sources (.dts)

  • includes (.dtsi)

  • overlays (.overlay)

  • bindings (.yaml)

The devicetree files inside the zephyr directory look like this:

boards/<ARCH>/<BOARD>/<BOARD>.dts
dts/common/skeleton.dtsi
dts/<ARCH>/.../<SOC>.dtsi
dts/bindings/.../binding.yaml

Generally speaking, every supported board has a BOARD.dts file describing its hardware. For example, the reel_board has boards/phytec/reel_board/reel_board.dts.

BOARD.dts includes one or more .dtsi files. These .dtsi files describe the CPU or system-on-chip Zephyr runs on, perhaps by including other .dtsi files. They can also describe other common hardware features shared by multiple boards. In addition to these includes, BOARD.dts also describes the board’s specific hardware.

The dts/common directory contains skeleton.dtsi, a minimal include file for defining a complete devicetree. Architecture-specific subdirectories (dts/<ARCH>) contain .dtsi files for CPUs or SoCs which extend skeleton.dtsi.

The C preprocessor is run on all devicetree files to expand macro references, and includes are generally done with #include <filename> directives, even though DTS has a /include/ "<filename>" syntax.

BOARD.dts can be extended or modified using overlays. Overlays are also DTS files; the .overlay extension is just a convention which makes their purpose clear. Overlays adapt the base devicetree for different purposes:

  • Zephyr applications can use overlays to enable a peripheral that is disabled by default, select a sensor on the board for an application specific purpose, etc. Along with Configuration System (Kconfig), this makes it possible to reconfigure the kernel and device drivers without modifying source code.

  • Overlays are also used when defining Shields.

The build system automatically picks up .overlay files stored in certain locations. It is also possible to explicitly list the overlays to include, via the DTC_OVERLAY_FILE CMake variable. See Set devicetree overlays for details.

The build system combines BOARD.dts and any .overlay files by concatenating them, with the overlays put last. This relies on DTS syntax which allows merging overlapping definitions of nodes in the devicetree. See Example: FRDM-K64F and Hexiwear K64 for an example of how this works (in the context of .dtsi files, but the principle is the same for overlays). Putting the contents of the .overlay files last allows them to override BOARD.dts.

Devicetree bindings (which are YAML files) are essentially glue. They describe the contents of devicetree sources, includes, and overlays in a way that allows the build system to generate C macros usable by device drivers and applications. The dts/bindings directory contains bindings.

Scripts and tools

The following libraries and scripts, located in scripts/dts/, create output files from input files. Their sources have extensive documentation.

dtlib.py

A low-level DTS parsing library.

edtlib.py

A library layered on top of dtlib that uses bindings to interpret properties and give a higher-level view of the devicetree. Uses dtlib to do the DTS parsing.

gen_defines.py

A script that uses edtlib to generate C preprocessor macros from the devicetree and bindings.

In addition to these, the standard dtc (devicetree compiler) tool is run on the final devicetree if it is installed on your system. This is just to catch errors or warnings. The output is unused. Boards may need to pass dtc additional flags, e.g. for warning suppression. Board directories can contain a file named pre_dt_board.cmake which configures these extra flags, like this:

list(APPEND EXTRA_DTC_FLAGS "-Wno-simple_bus_reg")

Output files

These are created in your application’s build directory.

Warning

Don’t include the header files directly. Devicetree access from C/C++ explains what to do instead.

<build>/zephyr/zephyr.dts.pre

The preprocessed DTS source. This is an intermediate output file, which is input to gen_defines.py and used to create zephyr.dts and devicetree_generated.h.

<build>/zephyr/include/generated/zephyr/devicetree_generated.h

The generated macros and additional comments describing the devicetree. Included by devicetree.h.

<build>/zephyr/zephyr.dts

The final merged devicetree. This file is output by gen_defines.py. It is useful for debugging any issues. If the devicetree compiler dtc is installed, it is also run on this file, to catch any additional warnings or errors.

A devicetree on its own is only half the story for describing hardware, as it is a relatively unstructured format. Devicetree bindings provide the other half.

A devicetree binding declares requirements on the contents of nodes, and provides semantic information about the contents of valid nodes. Zephyr devicetree bindings are YAML files in a custom format (Zephyr does not use the dt-schema tools used by the Linux kernel).


http://www.niftyadmin.cn/n/5845437.html

相关文章

65.棋盘 C#例子 WPF例子

这是一个不具备任何功能的UI设计&#xff0c;使用矩形和边界和文字块。通过这些可以自由的创建不同显示效果的内容。 棋盘展示&#xff1a; 代码展示&#xff1a; <Window x:Class"棋盘设计.MainWindow"xmlns"http://schemas.microsoft.com/winfx/2006/xam…

02.07 TCP服务器与客户端的搭建

一.思维导图 二.使用动态协议包实现服务器与客户端 1. 协议包的结构定义 首先&#xff0c;是协议包的结构定义。在两段代码中&#xff0c;pack_t结构体都被用来表示协议包&#xff1a; typedef struct Pack {int size; // 记录整个协议包的实际大小enum Type type; …

STM32G474--Whetstone程序移植(单精度)笔记

1 准备基本工程代码 参考这篇笔记从我的仓库中选择合适的基本工程&#xff0c;进行程序移植。这里我用的是stm32g474的基本工程。 使用git clone一个指定文件或者目录 2 移植程序 2.1 修改Whetstone.c 主要修改原本变量定义的类型&#xff0c;以及函数接口全部更换为单精度…

Android修行手册-五种比较图片相似或相同

Unity3D特效百例案例项目实战源码Android-Unity实战问题汇总游戏脚本-辅助自动化Android控件全解手册再战Android系列Scratch编程案例软考全系列Unity3D学习专栏蓝桥系列ChatGPT和AIGC👉关于作者 专注于Android/Unity和各种游戏开发技巧,以及各种资源分享(网站、工具、素材…

【Leetcode 热题 100】136. 只出现一次的数字

问题背景 给你一个 非空 整数数组 n u m s nums nums&#xff0c;除了某个元素只出现一次以外&#xff0c;其余每个元素均出现两次。找出那个只出现了一次的元素。 你必须设计并实现线性时间复杂度的算法来解决此问题&#xff0c;且该算法只使用常量额外空间。 数据约束 1 ≤…

MCU应用踩坑笔记(ADC 中断 / 查询法)

问题描述 IC&#xff1a;SC92F7596,在使用过程中&#xff0c;发现一个问题&#xff0c;就是我们使用到了ADC功能&#xff0c;程序的代码如下&#xff1a; ADC采样周期200ms &#xff0c;采样个数&#xff1a;4 在使用过程中&#xff0c;因配置了ADC中断使能&#xff0c;在中断…

洛谷P8742 [蓝桥杯 2021 省 AB] 砝码称重(dp初始)

归纳蓝桥杯的这道题总结了一定对于dp的看法&#xff0c;虽然还没看到y总的动态规划&#xff0c;自己搜了搜上学期算法中学到的01背包问题。 首先动态规划问题最重要的是状态转移方程&#xff0c;将问题抽象成数学问题&#xff0c;列出方程就可以得解。 #include<cstdio> …

数据结构在 Web 开发中的重要性与应用

数据结构是 Web 开发的基石&#xff0c;直接关系到应用程序的效率、可扩展性和可维护性。 根据实际需求选择合适的数据结构&#xff0c;能够有效优化性能、简化代码&#xff0c;并提升用户体验。 本文将深入探讨 PHP 和 Laravel 中的常用数据结构&#xff0c;并结合实际案例&am…