imx8qm LSM9DS1九轴驱动调试

本文档详细介绍了STMems传感器在Android系统的HAL层和Linux内核层的驱动代码,包括设备节点创建、数据读取以及编译指令。在实际运行中遇到权限问题,通过修改selinux策略解决了打开/dev/iio:device*的权限问题。然而,尽管设备成功加载,应用程序仍无法读取数据,可能的原因是注入模式不可用。此外,还记录了一个磁力计异常导致系统断电的问题,解决办法是调整中断引脚配置。
摘要由CSDN通过智能技术生成

HAL代码:

https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_IIO

https://www.st.com/content/st_com/zh/products/embedded-software/mems-and-sensors-software/drivers-for-mems/androidhal-iio.html

 

kernel层代码:

https://github.com/STMicroelectronics/STMems_Linux_IIO_drivers/tree/linux-4.14.y-gh

 

增加uevent节点如下:

/sys/bus/iio/devices/iio:device0

/sys/bus/iio/devices/iio:device1

读取数据。

 

HAL层参考文档:

STMicroelectronics\SensorHAL_IIO\Documentation

 

编译指令:

mm sensors-defconfig

"make sensors-defconfig" Set to default configuration "make sensors-menuconfig" Text based color menus, radiolists & dialogs. "make sensors-cleanconf" Delete hal_config, hal_config.old and configuration.h files.

 

如何进入menuconfig:

source env.sh

export PLATFORM_VERSION=9

make sensors-menuconfig

 

过滤打印信息:

logcat -s SensorHAL

 

生成路径:

out/target/product/mek_8q/obj_arm/SHARED_LIBRARIES/sensors.imx8_intermediates/sensors.imx8.so.toc

out\target\product\mek_8q\vendor\lib64\hw\sensors.imx8.so

 

/dev下文件打不开

打印如下,怀疑是selinux权限问题:

01-01 00:00:13.326  2349  2349 D SensorHAL: 3 IIO devices available into /sys/bus/iio/devices/ folder.
01-01 00:00:13.326  2349  2349 D SensorHAL: "lsm9ds1_gyro": IIO device found and supported. Wake-up sensor: no
01-01 00:00:13.328  2349  2349 D SensorHAL: "lsm9ds1_magn": IIO device found and supported. Wake-up sensor: no
01-01 00:00:13.330  2349  2349 D SensorHAL: "lsm9ds1_accel": IIO device found and supported. Wake-up sensor: no
01-01 00:00:13.341  2349  2349 E SensorHAL: LSM9DS1 Gyroscope Sensor: Failed to open iio char device (/dev/iio:device1).
01-01 00:00:13.341  2349  2349 E SensorHAL: "lsm9ds1_gyro": failed to create HW sensor class.
01-01 00:00:13.341  2349  2349 E SensorHAL: LSM9DS1 Magnetometer Sensor: Failed to open iio char device (/dev/iio:device2).
01-01 00:00:13.341  2349  2349 E SensorHAL: "lsm9ds1_magn": failed to create HW sensor class.
01-01 00:00:13.341  2349  2349 E SensorHAL: LSM9DS1 Accelerometer Sensor: Failed to open iio char device (/dev/iio:device0).
01-01 00:00:13.341  2349  2349 E SensorHAL: "lsm9ds1_accel": failed to create HW sensor class.
01-01 00:00:13.341  2349  2349 D SensorHAL: 0 sensors available and ready.

关闭hal层进程。

selinux报错:

[  530.748281] init: Service 'vendor.sensors-hal-1-0' (pid 3731) received signal 15
[  530.755847] init: Sending signal 9 to service 'vendor.sensors-hal-1-0' (pid 3731) process group...
[  530.765260] libprocessgroup: Successfully killed process cgroup uid 1000 pid 3731 in 0ms
[  530.774552] init: starting service 'vendor.sensors-hal-1-0'...
[  530.820472] type=1400 audit(156635
1060.028:2718): avc: denied { call } for pid=2253 comm="surfaceflinger" scontext=u:r:surfaceflinger:s0 tcontext=u:r:mediacodec:s0 tclass=binder permissive=1 b/77924251
[  530.838455] type=1400 audit(1566351086.288:2719): avc: denied { read } for pid=4549 comm="android.hardwar" name="iio:device1" dev="tmpfs" ino=16734 scontext=u:r:hal_sensors_default:s0 tcontext=u:object_r:iio_device:s0 tclass=chr_file permissive=1
[  530.860517] type=1400 audit(1566351086.288:2719): avc: denied { read } for pid=4549 comm="android.hardwar" name="iio:device1" dev="tmpfs" ino=16734 scontext=u:r:hal_sensors_default:s0 tcontext=u:object_r:iio_device:s0 tclass=chr_file permissive=1
[  530.882399] type=1400 audit(1566351086.288:2720): avc: denied { open } for pid=4549 comm="android.hardwar" path="/dev/iio:device1" dev="tmpfs" ino=16734 scontext=u:r:hal_sensors_default:s0 tcontext=u:object_r:iio_device:s0 tclass=chr_file permissive=1
[  530.904925] type=1400 audit(1566351086.288:2720): avc: denied { open } for pid=4549 comm="android.hardwar" path="/dev/iio:device1" dev="tmpfs" ino=16734 scontext=u:r:hal_sensors_default:s0 tcontext=u:object_r:iio_device:s0 tclass=chr_file permissive=1
[  530.927244] type=1400 audit(1566351086.288:2721): avc: denied { ioctl } for pid=4549 comm="android.hardwar" path="/dev/iio:device1" dev="tmpfs" ino=16734 ioctlcmd=0x6990 scontext=u:r:hal_sensors_default:s0 tcontext=u:object_r:iio_device:s0 tclass=chr_file permissive=1

增加权限如下:

+++ b/android9.0.0/device/fsl/imx8q/sepolicy/hal_sensors_default.te
+allow hal_sensors_default iio_device:chr_file { ioctl read open };

 

设备加载了,但是app还是读不到数据:

01-01 00:00:12.893  2380  2380 D SensorHAL: "lsm9ds1_magn": IIO device found and supported. Wake-up sensor: no
01-01 00:00:12.894  2380  2380 D SensorHAL: "lsm9ds1_accel": IIO device found and supported. Wake-up sensor: no
01-01 00:00:12.895  2377  2377 I android.hardware.light@2.0-service: Registration complete for android.hardware.light@2.0::ILight/default.
01-01 00:00:12.895  2380  2380 D SensorHAL: "LSM9DS1 Gyroscope Sensor": injection mode not available.
01-01 00:00:12.896  2380  2380 D SensorHAL: "LSM9DS1 Gyroscope Sensor": created HW class instance, handle: 1 (sensor type: 4).
01-01 00:00:12.896  2380  2380 D SensorHAL: "LSM9DS1 Magnetometer Sensor": injection mode not available.
01-01 00:00:12.896  2380  2380 D SensorHAL: "LSM9DS1 Magnetometer Sensor": created HW class instance, handle: 2 (sensor type: 2).
01-01 00:00:12.896  2379  2379 I android.hardware.power@1.0-service: Registration complete for android.hardware.power@1.0::IPower/default.
01-01 00:00:12.896  2380  2380 D SensorHAL: "LSM9DS1 Accelerometer Sensor": injection mode not available.
01-01 00:00:12.896  2380  2380 D SensorHAL: "LSM9DS1 Accelerometer Sensor": created HW class instance, handle: 3 (sensor type: 1).
01-01 00:00:12.896  2380  2380 D SensorHAL: 3 sensors available and ready.

增加calibration权限错误:

must be associated with the "coredomain" attribute because they are executed

 

解决方案:

typeattribute STSensors coredomain;

 

 

磁力计读取数据异常,导致整机断电:

08-21 09:39:08.682 2379 2379 E SensorHAL: LSM9DS1 Magnetometer Sensor: Failed to write hw fifo watermark.

原因:中断被拉高后,一直无法拉低,将该输入引脚SPDIF0_RX改为pull-down,改成DRDY_M引脚后正常。

引脚配置:

		pinctrl_hog: hoggrp {
			fsl,pins = <
                SC_P_SPDIF0_RX_LSIO_GPIO2_IO14          0x18000040 //magn irq  pull-down
			>;
		};

 

读取状态寄存器:

加速度计:i2cget -f -y 2 0x6a 0x17

磁力计:i2cget -f -y 2 0x1c 0x27

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值