GNU/Linux - U-Boot中的i2c命令

u-boot=> i2c

i2c - I2C sub-system

Usage:

i2c bus [muxtype:muxaddr:muxchannel] - show I2C bus info

i2c crc32 chip address[.0, .1, .2] count - compute CRC32 checksum

i2c dev [dev] - show or set current I2C bus

i2c loop chip address[.0, .1, .2] [# of objects] - looping read of device

i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device

i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)

i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)

i2c nm chip address[.0, .1, .2] - write to I2C device (constant address)

i2c probe [address] - test for and show device(s) on the I2C bus

i2c read chip address[.0, .1, .2] length memaddress - read to memory

i2c write memaddress chip address[.0, .1, .2] length [-s] - write memory

          to I2C; the -s option selects bulk write in a single transaction

i2c flags chip [flags] - set or get chip flags

i2c olen chip [offset_length] - set or get chip offset length

i2c reset - re-init the I2C Controller

i2c speed [speed] - show or set I2C bus speed

u-boot=> i2c speed

Current bus speed=400000

u-boot=> i2c bus

Bus 0:  i2c@44340000

Bus 1:  i2c@44350000  (active 1)

   25: pmic@25, offset len 1, flags 0

   34: gpio@34, offset len 1, flags 0

Bus 2:  i2c@42530000

   53: rtc@53, offset len 1, flags 0

u-boot=> i2c dev 1

Setting bus to 1

u-boot=> i2c crc32 0x25 0x1B.1 1

CRC32 for 0000001b ... 0000001b ==> abde5729

1,选择你要使用的i2c bus号码

// Where <bus> is the number of the bus to select:

# i2c dev <bus>

// Example - Select bus 0

# i2c dev 0

2,在当前的i2c bus上搜索设备

// Attempt to detect the addresses of all devices on the bus

# i2c probe

// Check if a device is present, where <chip> is the address of the I2C device

# i2c probe <chip>

// Example - Check if a device with address 0x50 is present

# i2c probe 0x50

3,地址说明

I2C 地址通常为 7 位,第 8 位表示 I2C 操作是读取(0)还是写入(1)。U-Boot 希望地址只有 7 位,在一个字节内正确排列。例如 0b0AAAAAAA,其中 A 是地址位。不同的集成电路数据手册以不同的方式指定 I2C 地址。有些可能会指定左对齐并附加读取位的地址。即 0bAAAAAAA0。在这种情况下,应将数据表地址右移一位,然后再将其用于 U-Boot I2C 命令。U-Boot 会自动设置地址字段中的读/写位。

I2C addresses are typically 7 bits with the 8th bit indicating if the I2C operation is a read (0) or a write (1). U-Boot expects the address as just 7 bits, right alined within a byte. I.e. 0b0AAAAAAA, where A is an address bit. Different IC datasheets specify the I2C address in different ways. Some may specify the address left aligned with the read bit appended. I.e. 0bAAAAAAA0. In these cases, the datasheet address should be right shifted by one bit before using it for the U-Boot I2C commands. U-Boot automatically sets the read/write bit in the address field.

4,从I2C设备读取寄存器值 Reading from an I2C device

您可以使用以下命令将内存转储到屏幕上:

You can dump memory to the screen using the following commands:

// <chip> is the address of the I2C IC.

// <register_address> is the register within the I2C device that you wish to read

// <address_length> is either 0, 1, or 2. 0 = no address, 1 = 8 bit address, 2 = 16 bit address.

// <length> is the number of bytes to read from the I2C device.

i2c md <chip> <register_address>[.<address_length>] <length>

// Example 1 - Read 0x100 bytes starting at register 0x00, from device with address 0x51. Address is 1 byte.

i2c md 0x51 0x00.1 0x100

// Example 2 - Read 0x1000 byte starting at register 0x0400, from device with address 0x34. Address is 2 bytes.

i2c md 0x34 0x0400.2 0x1000

// Example 3 - Read a single byte from device with address 0x60. Don't send register address word.

i2c md 0x60 0x00.0 0x1

您还可以使用以下命令直接从 I2C 设备读取数据到内存中:

You can also read from the I2C device directly into memory using the following command:

// <register_address>, <address_length>, and <length> are as per the i2c md command.

// <memory_address> is the address in the processors memory to copy the I2C data to.

i2c read <chip> <register_address>[.<address_length>] <length> <memory_address>

// Example: copy into memory location 0x40000000, 0x80 bytes starting at register

// address 0x10 of the I2C device with address 0x50.

i2c read 0x50 0x10 0x80 0x40000000

5,向I2C设备的寄存器写入数据 Writing to an I2C device

您可以使用以下命令直接写入 I2C 设备的寄存器:

You write to I2C device's registers directly using the following command:

// <chip> is the address of the I2C IC.

// <register_address> is the register within the I2C device that you wish to read

// <address_length> is either 0, 1, or 2. 0 = no address, 1 = 8 bit address, 2 = 16 bit address.

// <value> is the value to write to the register address.

// <length> is the number of bytes to write to the I2C device.

i2c mw <chip> <register_address>[.<address_length>] <value> <length>

// Example 1 - Write 0x1 byte with value 0xAA to register 0xE5 of the I2C

// device with address 0x28. Address is 1 byte.

i2c mw 0x28 0xE5.1 0xAA 0x1

参考:

Controlling I2C Devices from U-Boot

"/pkg/qct/software/llvm/release/arm/14.0.0/bin/clang" -g -Os -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -c -include AutoGen.h -mlittle-endian -fno-short-enums -save-temps -fverbose-asm -funsigned-char -ffunction-sections -fdata-sections -fno-builtin -Wno-address -fno-asynchronous-unwind-tables -target aarch64-linux-gnu -fcolor-diagnostics -fdiagnostics-format=vi -Wno-parentheses-equality -Wno-tautological-compare -Wno-tautological-constant-out-of-range-compare -Wno-empty-body -Wno-unknown-warning-option -Wno-unused-function -Wno-bitwise-op-parentheses -mcmodel=small -ffixed-x18 -mstrict-align -fstack-protector -Wno-nonportable-include-path -Wno-misleading-indentation -fno-common -mtune=cortex-a53 -I/home/chen-docker/bin/boot/boot_images/BuildLogs/QcomPkg/SocPkg/LeMans/AU/Include -include /home/chen-docker/bin/boot/boot_images/boot/QcomPkg/Include/Library/DebugLib.h -DQCOM_EDK2_PATCH -DDISABLE_DEP -DENABLE_XN -DENABLE_ASLR -DENABLE_DEP_64 -DENABLE_EXEC_CODE_READY_TO_BOOT -DENABLE_AUTO_PLAT -DMAX_DDR_REGIONS=6 -mstrict-align -mcpu=cortex-a53 -DPRODMODE -c -o /home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/./HiiLib.obj @/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/inc.lst /home/chen-docker/bin/boot/boot_images/edk2/MdeModulePkg/Library/UefiHiiLib/HiiLib.c /pkg/qct/software/llvm/release/arm/14.0.0/bin/clang: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory GNUmakefile:373: recipe for target '/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/HiiLib.obj' failed Building ... /home/chen-docker/bin/boot/boot_images/edk2/MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf [AARCH64] make: *** [/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib/OUTPUT/HiiLib.obj] Error 127 make: Nothing to be done for 'tbuild'. build.py... : error 7000: Failed to execute command make tbuild [/home/chen-docker/bin/boot/boot_images/Build/LeMansAU/Core/RELEASE_CLANG140LINUX/AARCH64/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib]错误在哪里?
07-20
根据错误消息,错误发生在执行 `/pkg/qct/software/llvm/release/arm/14.0.0/bin/clang` 命令时。具体错误是 `libtinfo.so.5: cannot open shared object file: No such file or directory`,也就是找不到共享库文件 `libtinfo.so.5`。 这个错误通常是由于缺少对应的共享库文件或库文件路径配置不正确导致的。你可以尝试以下几个解决方法: 1. 安装缺失的库文件:根据错误消息,缺失的库文件是 `libtinfo.so.5`。你可以尝试使用包管理器安装该库文件。例如,在基于 Debian/Ubuntu 的系统上,可以运行 `sudo apt-get install libtinfo5` 命令来安装该库文件。 2. 更新库文件路径:如果你已经安装了库文件,但仍然遇到该错误,可能是因为库文件路径配置不正确。你可以通过设置 LD_LIBRARY_PATH 环境变量来指定正确的库文件路径。例如,`export LD_LIBRARY_PATH=/path/to/lib`,将 `/path/to/lib` 替换为包含 `libtinfo.so.5` 的目录路径。 3. 检查编译环境:确保编译环境的依赖项和工具链已正确安装。你可能需要检查并安装所需的 LLVM、Clang 版本以及其他依赖项。 4. 更新构建脚本:如果以上解决方法都不起作用,你可能需要检查构建脚本的编译命令和相关配置,确保正确设置了库文件路径和其他编译选项。 请注意,根据具体情况,可能存在其他原因导致该错误。如果以上解决方法都不起作用,你可以提供更多关于你的项目和构建环境的信息,以便我能够提供更具体的建议。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值