2025-02-19 9:54 PM
Dear Team,
We are integrating lsm303AGR accelerometer and magnetometer sensors on NXP's imx8 Android 10 platform.
https://github.com/STMicroelectronics/st-mems-android-linux-sensors-hal for HAL
https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio for linux 5.4 kernel
device registers as iio:device0 and iio:device1 x,y,z raw value we can see in cat sysfs files.
HAL finds 2 IIO devices but further
there is lack of implementation of loading bias and save bias functions in legacy
because of this the sensors app is not able to read the sensor data values . apps says there are 2 sensors from stm accel and magn but data is not able to read.
it is going into un-calibrated type.
kindly help us in fixing the issue.
2025-03-06 10:40 PM
your readme file on git-hub whatever it says we have followed it
https://github.com/STMicroelectronics/st-mems-android-linux-sensors-hal/blob/master/readme.org
android multi-hal (Android 11 and above)
Android multi-hal
adapter.android hidl 2.0 (Android 11 and above)
Android HIDL 2.0 adapter (full treble).
android aidl (Android 13 and above)
Android AIDL AIDL adapter (full treble).
android legacy (Android 10 and inferior)
Android legacy (pre full treble) adapter.
You should update this right!! how will we understand that we have to use HIDL2.0
Since we are using Android 10 and as per your readme we have used legacy HAL.
kindly update your readme which will help all.
anyways we will try HIDL2.0 and update here
2025-03-07 4:58 AM
We have tried with HIDL2.0 also but same behaviour... android apps are not recognising the sensors .. the same screen as attached here before.
Few findings are ************************ the device boot logcat looks like this
--------- beginning of main
--------- beginning of system
01-01 00:00:22.570 306 306 I stm-sensors: gyroscope rotation matrix: 1.000000,0.000000,0.000000;0.000000,1.000000,0.000000;0.000000,0.000000,1.000000
01-01 00:00:22.571 306 306 I stm-sensors: magnetometer rotation matrix: 1.000000,0.000000,0.000000;0.000000,1.000000,0.000000;0.000000,0.000000,1.000000
01-01 00:00:22.571 306 306 I stm-sensors: accelerometer rotation matrix: 1.000000,0.000000,0.000000;0.000000,1.000000,0.000000;0.000000,0.000000,1.000000
01-01 00:00:22.571 306 306 I stm-sensors: gyroscope placement: 0.000000, 0.000000, 0.000000
01-01 00:00:22.571 306 306 I stm-sensors: magnetometer placement: 0.000000, 0.000000, 0.000000
01-01 00:00:22.571 306 306 I stm-sensors: pressure placement: 0.000000, 0.000000, 0.000000
01-01 00:00:22.571 306 306 I stm-sensors: accelerometer placement: 0.000000, 0.000000, 0.000000
01-01 00:00:22.572 306 306 D stm-sensors: found 2 IIO devices available under /sys/bus/iio/devices
01-01 00:00:22.582 306 306 D stm-sensors: LSM303AGR Magnetometer Sensor: injection mode not available
01-01 00:00:22.583 306 306 I stm-sensors: magn calibration library: stm-magn-lib-mock
01-01 00:00:22.583 306 306 D stm-sensors: LSM303AGR Accelerometer Sensor: injection mode not available
01-01 00:00:22.583 306 306 I stm-sensors: accel calibration library: stm-accel-lib-mock
01-01 00:00:22.583 306 306 I stm-sensors: sensors fusion (6X) library: stm-sensors-fusion-6X-lib-mock
01-01 00:00:22.584 306 306 I stm-sensors: sensors fusion (9X) library: stm-sensors-fusion-9X-lib-mock
01-01 00:00:22.584 306 306 I stm-sensors: sensors fusion (6X) library: stm-sensors-fusion-6X-lib-mock
01-01 00:00:22.584 306 306 I stm-sensors: sensors fusion (9X) library: stm-sensors-fusion-9X-lib-mock
01-01 00:00:22.587 306 306 E stm-sensors: selftest functions cannot be loaded correctly
01-01 00:00:22.587 306 306 D stm-sensors: 4 sensors available and ready
01-01 00:00:22.588 306 306 I stm-sensors: timesync library: stm-timesync-lib-mock
01-01 00:00:22.588 306 306 D stm-sensors: onLoadDataRequest is entered
01-01 00:00:22.588 306 306 D stm-sensors: onLoadDataRequest: file is opened
01-01 00:00:22.588 306 306 W stm-sensors: failed to load accel bias
01-01 00:00:22.588 306 306 D stm-sensors: onLoadDataRequest is entered
01-01 00:00:22.588 306 306 D stm-sensors: onLoadDataRequest: file is opened
01-01 00:00:22.588 306 306 E stm-sensors: failed to load magn bias
03-07 10:17:31.795 306 306 D stm-sensors: LSM303AGR Accelerometer Sensor: changed pollrate to 14.999925Hz, timeout=0ms
03-07 10:17:31.795 306 306 D stm-sensors: LSM303AGR Accelerometer Sensor: power-on
when Opened the accelerometer from APP following log
03-07 10:18:02.955 306 534 E stm-sensors: received unrecognized event type 30
03-07 10:18:33.364 306 534 E stm-sensors: received unrecognized event type 30
* Where to add the following lines?
persist.vendor.stm.sensors.max-odr = 250 #max odr that can be used is 250Hz
persist.vendor.stm.sensors.rot-matrix-1.accel = "1,0,0,0,1,0,0,0,1" #accel rotation matrix
persist.vendor.stm.sensors.placement-1.accel = "10,20,30" #accel position in cm
persist.vendor.stm.sensors.max-range.accel = 70 #accel full-scale to support reading of at least 70m/s^2
persist.vendor.stm.sensors.max-range.magn = 2000 #magn full-scale to support reading of at least 2000uT
persist.vendor.stm.sensors.max-range.gyro = 8 #gyro full-scale to support reading of at least 8rad/s
we have /vendor/build.prop file. if I add these in this file is that OK?
* in Android.bp file of 2.0 refers to a file a directory
DHAL_PRIVATE_DATA_PATH=\"/data/vendor/stm-sensors-hal\
but this folder is not getting created...
I have removed all the SElinux permissions
androidboot.selinux=permissive device is in permissive=1 mode.
Kindly help
2025-03-12 6:39 AM
Hi @prasannakulkarni ,
The Android sensor hal reads the calibration offsets from files that are saved on the file system. For this to happen, you need to correctly configure the sepolicy and init.rc files in order to create the folders that will contain such calibration files, define their owners and access flags.
In our tests we generally use Android reference boards, which already have predefined folders where to save the sensor hal calibration data, typically these are defined by sepolicy rules files prepared by vendors (sepolicy file_contexts file):
/data/vendor/sensor(/.*)? u:object_r:sensor_vendor_data_file:s0
Of course in your case you might have chosen another place to save this persistent data, so it depends on how you have organized your file system, but in our configuration this SELinux rule assigns the security context u:object_r:sensor_vendor_data_file:s0 to all files and directories under /data/vendor/sensor.
In order to write to these files, the specified path (/data/vendor/sensor) must exist and be made accessible to the system user before sensorhal even starts. To do this you need to add a file init.sensorhal.rc containing the following instructions:
on post-fs-data
mkdir /data/vendor/sensor
chown root system /data/vendor/sensor
chmod 0770 /data/vendor/sensor
You also need to instruct the aosp build to copy this file to the vendor partition (typically from the device.mk file of the device):
PRODUCT_COPY_FILES += \
device/linaro/hikey/init.sensorhal.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.sensorhal.rc
Finally you need to define the variable HAL_PRIVATE_DATA_PATH in <sensorHal>/2.0/Android.bp in the following way:
"-DHAL_PRIVATE_DATA_PATH=\"/data/vendor/sensor\""
Of course the paths where to save the sensor data can be changed, this is just an example of implementation.
I hope this clarifies the procedure to follow.
Please see the aosp SELinux documentation page for debugging rules: https://source.android.com/docs/security/features/selinux/concepts and https://source.android.com/docs/security/features/selinux/validate
Please note that in order for the calibration data to be actually produced it is necessary to install the STMicroelectronics calibration libraries (MotionAC for accelerometer calibration and MotionMC for magnetometer calibration). The release of STM proprietary libraries is subject to signature of a License User Agreement (LUA); please contact an STMicroelectronics sales office and representatives for further information.
2025-03-13 3:02 AM
Hi @Federica Bossi ,
As I have mentioned in earlier post the device is in permissive mode.
it creates files in
#ls /data/vendor/stm-sensors-hal/
accel_bias_1.dat magn_bias_1.dat
following is the boot logcat and tried open sensor test apps but magnetometer is giving zero values only... drivers is giving RAW values but the HAL is unable to read
------------------------------------------------------------------------------------------------------------------------------------------------------------
01-01 00:00:12.322 310 310 I ServiceManagement: Registered android.hardware.sensors@2.0::ISensors/default (start delay of 686ms)
01-01 00:00:12.329 310 310 I ServiceManagement: Removing namespace from process name android.hardware.sensors@2.0-service.stmicroelectronics to sensors@2.0-service.stmicroelectronics.
01-01 00:00:13.284 293 293 I FslCameraHAL: enumSensorSet
01-01 00:00:20.632 463 540 D SystemServerInitThreadPool: Started executing StartSensorService
01-01 00:00:20.633 463 540 D SensorService: nuSensorService starting...
01-01 00:00:20.652 310 310 D stm-sensors: persist.vendor.stm.sensors.max-odr *************sensors available and ready
01-01 00:00:20.652 310 310 D stm-sensors: 250 *************sensors available and ready
01-01 00:00:20.652 310 310 I stm-sensors: gyroscope rotation matrix: 1.000000,0.000000,0.000000;0.000000,1.000000,0.000000;0.000000,0.000000,1.000000
01-01 00:00:20.652 310 310 I stm-sensors: magnetometer rotation matrix: 1.000000,0.000000,0.000000;0.000000,1.000000,0.000000;0.000000,0.000000,1.000000
01-01 00:00:20.653 310 310 I stm-sensors: accelerometer rotation matrix: 1.000000,0.000000,0.000000;0.000000,1.000000,0.000000;0.000000,0.000000,1.000000
01-01 00:00:20.653 310 310 I stm-sensors: gyroscope placement: 0.000000, 0.000000, 0.000000
01-01 00:00:20.653 310 310 I stm-sensors: magnetometer placement: 0.000000, 0.000000, 0.000000
01-01 00:00:20.653 310 310 I stm-sensors: pressure placement: 0.000000, 0.000000, 0.000000
01-01 00:00:20.653 310 310 I stm-sensors: accelerometer placement: 10.000000, 20.000000, 30.000000
01-01 00:00:20.653 310 310 D stm-sensors: found 2 IIO devices available under /sys/bus/iio/devices
01-01 00:00:20.661 310 310 D stm-sensors: LSM303AGR Magnetometer Sensor: injection mode not available
01-01 00:00:20.662 310 310 I stm-sensors: magn calibration library: stm-magn-lib-mock
01-01 00:00:20.662 310 310 D stm-sensors: LSM303AGR Accelerometer Sensor: injection mode not available
01-01 00:00:20.663 310 310 I stm-sensors: accel calibration library: stm-accel-lib-mock
01-01 00:00:20.663 310 310 I stm-sensors: sensors fusion (6X) library: stm-sensors-fusion-6X-lib-mock
01-01 00:00:20.663 310 310 I stm-sensors: sensors fusion (9X) library: stm-sensors-fusion-9X-lib-mock
01-01 00:00:20.665 310 310 E stm-sensors: selftest functions cannot be loaded correctly
01-01 00:00:20.666 310 310 D stm-sensors: 4 sensors available and ready
01-01 00:00:20.666 310 310 D stm-sensors: Old Status:0new Status:0
01-01 00:00:20.666 310 310 D stm-sensors: Before Trying to save bias
01-01 00:00:20.666 310 310 D stm-sensors: After Trying to save bias
01-01 00:00:20.666 310 310 I stm-sensors: timesync library: stm-timesync-lib-mock
01-01 00:00:20.667 310 310 D stm-sensors: onLoadDataRequest is entered
01-01 00:00:20.676 310 310 D stm-sensors: onLoadDataRequest: read successful
01-01 00:00:20.676 310 310 D stm-sensors: onLoadDataRequest is entered
01-01 00:00:20.678 310 310 D stm-sensors: onLoadDataRequest: read successful
01-01 00:00:20.680 463 540 I SensorService: Reported power 0.000000 not deemed sane, clamping to 0.001000
01-01 00:00:20.681 463 540 I SensorService: Reported power 0.000000 not deemed sane, clamping to 0.001000
01-01 00:00:20.681 463 540 I SensorService: Reported power 0.000000 not deemed sane, clamping to 0.001000
01-01 00:00:20.681 463 540 I SensorService: Reported power 0.000000 not deemed sane, clamping to 0.001000
01-01 00:00:20.686 463 550 D SensorService: new thread SensorEventAckReceiver
01-01 00:00:20.686 463 551 D SensorService: nuSensorService thread starting...
03-11 05:50:34.347 310 310 D stm-sensors: LSM303AGR Accelerometer Sensor: HWSensor changed pollrate to 14.999925Hz, timeout=0ms
03-11 05:50:34.348 310 310 D stm-sensors: LSM303AGR Accelerometer Sensor: power-on
03-11 05:50:34.357 310 310 D stm-sensors: Old Status:0new Status:1
03-11 05:50:34.357 310 310 D stm-sensors: Before Trying to save bias
03-11 05:50:34.357 310 310 D stm-sensors: After Trying to save bias
03-11 05:51:10.032 310 310 D stm-sensors: LSM303AGR Magnetometer Sensor: HWSensor changed pollrate to 14.999925Hz, timeout=0ms
03-11 05:51:10.033 310 310 D stm-sensors: LSM303AGR Magnetometer Sensor: power-on
03-11 05:52:24.783 310 310 D stm-sensors: LSM303AGR Magnetometer Sensor: power-off
03-11 05:52:24.790 310 310 D stm-sensors: onSaveDataRequest is entered
03-11 05:52:24.797 310 310 D stm-sensors: onSaveDataRequest: write successful
03-11 05:52:30.094 310 310 D stm-sensors: LSM303AGR Magnetometer Sensor: HWSensor changed pollrate to 10.000000Hz, timeout=0ms
03-11 05:52:30.094 310 310 D stm-sensors: LSM303AGR Magnetometer Sensor: power-on
03-11 05:52:42.649 310 310 D stm-sensors: LSM303AGR Magnetometer Sensor: power-off
03-11 05:52:42.652 310 310 D stm-sensors: onSaveDataRequest is entered
03-11 05:52:42.654 310 310 D stm-sensors: onSaveDataRequest: write successful
03-11 05:53:00.028 310 310 D stm-sensors: LSM303AGR Magnetometer Sensor: HWSensor changed pollrate to 10.000000Hz, timeout=0ms
03-11 05:53:00.028 310 310 D stm-sensors: LSM303AGR Magnetometer Sensor: power-on
03-11 05:53:03.094 310 310 D stm-sensors: LSM303AGR Magnetometer Sensor: power-off
03-11 05:53:03.103 310 310 D stm-sensors: onSaveDataRequest is entered
03-11 05:53:03.105 310 310 D stm-sensors: onSaveDataRequest: write successful
03-11 05:53:38.369 310 546 D stm-sensors: Im calling event type from here
03-11 05:53:38.369 310 546 D stm-sensors: LSM303AGR Accelerometer Sensor: write flush event to pipe
03-11 05:53:47.842 310 310 D stm-sensors: Old Status:1new Status:1
03-11 05:53:47.842 310 310 D stm-sensors: Before Trying to save bias
03-11 05:53:47.842 310 310 D stm-sensors: After Trying to save bias
2025-03-15 2:21 AM - edited 2025-03-15 2:22 AM
and One more doubt do we need to pass an interrupt for magnetometer also ?
For accelerometer we are passing but magnetometer it is giving so many interrupts in a minutes or so it will increase so fast almost sub millions of interrupts ... kindly guide on this point also
#cat /proc/interrupts
153: 208369 0 0 0 gpio-mxc 21 Level lsm303agr_magn
154: 1996 0 0 0 gpio-mxc 22 Level lsm303agr_accel
Does really an interrupts required for magnetometer??