我正在尝试使用 Zephyr 在 Seeed xiao sense 板上使用 LSM6DS3TR-C IMU。通过讨论,我发现示例的绑定仅在特定条件下有效,因此我从头开始制作设备树/绑定。
我从 Linux 内核档案中找到了 st,lsm6dsx.yaml 绑定。使用此 .yaml 文件时,当我在覆盖文件的兼容部分中使用绑定时,出现错误:“仅接受 i2c 节点”,如下所示:
&i2c0 {
compatible = "nordic,nrf-twim";
/* Cannot be used together with spi0. */
status = "okay";
pinctrl-0 = <&i2c0_default>;
pinctrl-1 = <&i2c0_sleep>;
pinctrl-names = "default", "sleep";
clock-frequency = <I2C_BITRATE_FAST>;
label = "I2C0";
imu@6a{
compatible = "st,lsm6dsx";
reg = <0x6a>;
label = "IMU";
vdd-supply=<®ulator_imu>;
vddio-supply=<®ulator_imu>;
st,pullups;
};
};
绑定文件内容如下:
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/iio/imu/st,lsm6dsx.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: STM 6-axis (acc + gyro) IMU Mems sensors
maintainers:
- Lorenzo Bianconi <[email protected]>
description:
Devices have both I2C and SPI interfaces.
properties:
compatible:
oneOf:
- enum:
- st,lsm6ds3
- st,lsm6ds3h
- st,lsm6dsl
- st,lsm6dsm
- st,ism330dlc
- st,lsm6dso
- st,asm330lhh
- st,lsm6dsox
- st,lsm6dsr
- st,lsm6ds3tr-c
- st,ism330dhcx
- st,lsm9ds1-imu
- st,lsm6ds0
- st,lsm6dsrx
- st,lsm6dst
- st,lsm6dsop
- st,lsm6dsv
- st,lsm6dso16is
- items:
- enum:
- st,asm330lhhx
- st,asm330lhhxg1
- const: st,lsm6dsr
- items:
- const: st,lsm6dstx
- const: st,lsm6dst
- items:
- const: st,lsm6dsv16x
- const: st,lsm6dsv
- items:
- const: st,ism330is
- const: st,lsm6dso16is
- items:
- const: st,asm330lhb
- const: st,asm330lhh
reg:
maxItems: 1
interrupts:
minItems: 1
maxItems: 2
description:
Supports up to 2 interrupt lines via the INT1 and INT2 pins.
vdd-supply:
description: if defined provides VDD power to the sensor.
vddio-supply:
description: if defined provides VDD IO power to the sensor.
st,drdy-int-pin:
$ref: /schemas/types.yaml#/definitions/uint32
description: |
The pin on the package that will be used to signal data ready
enum:
- 1
- 2
st,pullups:
type: boolean
description: enable/disable internal i2c controller pullup resistors.
st,disable-sensor-hub:
type: boolean
description:
Enable/disable internal i2c controller slave autoprobing at bootstrap.
Disable sensor-hub is useful if i2c controller clock/data lines are
connected through a pull-up with other chip lines (e.g. SDO/SA0).
drive-open-drain:
type: boolean
description:
The interrupt/data ready line will be configured as open drain, which
is useful if several sensors share the same interrupt line.
wakeup-source:
$ref: /schemas/types.yaml#/definitions/flag
mount-matrix:
description: an optional 3x3 mounting rotation matrix
required:
- compatible
- reg
allOf:
- $ref: /schemas/iio/iio.yaml#
- $ref: /schemas/spi/spi-peripheral-props.yaml#
unevaluatedProperties: false
examples:
- |
#include <dt-bindings/interrupt-controller/irq.h>
i2c {
#address-cells = <1>;
#size-cells = <0>;
imu@6b {
compatible = "st,lsm6dsm";
reg = <0x6b>;
interrupt-parent = <&gpio0>;
interrupts = <0 IRQ_TYPE_EDGE_RISING>;
};
};
...
参考文件的所有参考部分中没有 I2C 参考,但参考了使用与 i2c 的绑定。那么这个绑定与I2C兼容吗?根据我的研究,事实并非如此。
如果我要实现 I2C 版本,我将如何知道我需要哪些基本属性?
如果您认为有更好的方法来实现 LSM6DS3TR-C 操作,那么让我们对此进行讨论。
谢谢大家
虽然 Linux 和 Zephyr 都使用 devicetrees 和 yaml 绑定,但它们在实际使用方式上确实存在显着差异。值得注意的是,Zephyr 实际上将强制绑定作为构建映像的一部分,而 Linux 仅将它们用于文档。因此,获取 Linux devicetree 片段或绑定通常不起作用。
对于这个特定部分,Zephyr 中似乎已经存在支持,甚至对于您的主板也是如此:https://github.com/zephyrproject-rtos/zephyr/blob/main/boards%2Fseeed%2Fxiao_ble%2Fxiao_ble_nrf52840_sense.dts#L40
此处声明了 IMU 并使用
"st,lsm6dsl"
兼容驱动程序(该驱动程序也应与 LSM6DS3TR-C 配合使用。此处有一个绑定:https://github.com/zephyrproject-rtos/zephyr/ blob/main/dts%2Fbindings%2Fsensor%2Fst%2Clsm6dsl-i2c.yaml 因此,您只需确保 CONFIG_SENSOR
已设置,并且驱动程序应可通过传感器 API 使用。
请注意您遇到的确切错误,我相信这是绑定未声明
on-bus
属性的结果,该属性告诉绑定应该出现在特定总线上:https://docs.zephyrproject.org/最新/build/dts/bindings-syntax.html#on-bus 。同样,Zephyr 和 Linux 绑定不同,因此 Linux 似乎没有使用它。