Skip to main content
Visitor II
July 17, 2020
Solved

Android P can't get LSM6DSM HAL Accelerometer/Gyroscope data on iMX8MM board

  • July 17, 2020
  • 6 replies
  • 5096 views

I have follow the Integration of the LSM6DSM drivers from here : https://github.com/STMicroelectronics/STMems_Linux_IIO_drivers/blob/linux-4.4.y-gh/README.md & https://github.com/STMicroelectronics/STMems_Linux_IIO_drivers/tree/linux-4.14.y-gh/drivers/iio/imu/st_lsm6dsm

Now I am able to get data through sysfs devices :

grep "" /sys/bus/iio/devices/iio\:device*/name
/sys/bus/iio/devices/iio:device0/name:lsm6dsm_accel
/sys/bus/iio/devices/iio:device1/name:lsm6dsm_gyro
/sys/bus/iio/devices/iio:device2/name:lsm6dsm_sign_motion
/sys/bus/iio/devices/iio:device3/name:lsm6dsm_step_c
/sys/bus/iio/devices/iio:device4/name:lsm6dsm_step_d
/sys/bus/iio/devices/iio:device5/name:lsm6dsm_tilt
/sys/bus/iio/devices/iio:device6/name:lsm6dsm_wrist
/sys/bus/iio/devices/iio:device7/name:lsm6dsm_stap
/sys/bus/iio/devices/iio:device8/name:lsm6dsm_dtap

I have then follow the HAL integration into my AOSP folder : https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_IIO/blob/STMems_Android_Sensor_HAL_IIO/README.md & https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_IIO/blob/STMems_Android_Sensor_HAL_IIO/Documentation/README

I have not used the Factory Calibration since I am missing access to the library in lib folder

Nothing show up in my Android, no sensor :

adb shell dumpsys sensorservice
No Sensors on the device
devInitCheck : -19

I see the library on my imx8 board at /system/vendor/lib/hw/sensor.imx8.so

Do I need extra libraries ? (SENSOR_FUSION, GEOMAG_FUSION, GBIAS, MAGCALIB, ACC_CALIB)

I am fine with NDA signing :

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.

Do I need to initialize anything else ?

Any clue would be really appreciated !

Thank you very much

Aurelien BOUIN

    This topic has been closed for replies.
    Best answer by AurelienBOUIN

    Hey @DevM​,

    Inside the android_*_defconfig, you need to have selected the lsm9ds1, as an example for the lsmd6dsm i had to add :

    CONFIG_ST_HAL_LSM6DSM_ENABLED=y
    CONFIG_ST_HAL_ACCEL_ENABLED=y
    CONFIG_ST_HAL_MAGN_ENABLED=y
    CONFIG_ST_HAL_GYRO_ENABLED=y
    CONFIG_ST_HAL_MAGN_UNCALIB_DISABLED=y
    CONFIG_ST_HAL_GYRO_UNCALIB_DISABLED=y
    CONFIG_ST_HAL_ACCEL_UNCALIB_DISABLED=y
    CONFIG_ST_HAL_SIGN_MOTION_ENABLED=y
    CONFIG_ST_HAL_TAP_ENABLED=y
    CONFIG_ST_HAL_TAP_TAP_ENABLED=y
    CONFIG_ST_HAL_STEP_DETECTOR_ENABLED=y
    CONFIG_ST_HAL_STEP_COUNTER_ENABLED=y
    CONFIG_ST_HAL_TILT_ENABLED=y

    To be sure to recompile the ST iio library you need to delete those files before launching the AOSP make :

    rm wherever/libsensors_stmicro/android_data_config
    rm wherever/libsensors_stmicro/configuration.h
    rm wherever/libsensors_stmicro/hal_config

    I hope it will help you,

    Best regards,

    Aurelien BOUIN

    6 replies

    ST Employee
    July 17, 2020

    Hi @AurelienBOUIN​ , since I'm not an expert on this topic, I add a couple of tags (Linux and Android) for more help. If you simply want to read LSM6DSM registers, I think you are using the right linux drivers... but did you already check (e.g. with an oscilloscope) if the communication between the application processor and the sensor on the MCIMX8M-EVK board is OK? And did you already ask for support on NXP forum, since it is a NXP board? Regards

    Visitor II
    July 17, 2020

    Thanks @Eleon BORLINI​ for your fast answer and your tags

    Yes I check that I2C communication is fine, easy to check with this command that retrieve the WHO_I_AM register :

    # i2cget -f -y 2 0x6a 0x0f
    0x6a

    I have not ask on NXP community since I2C is working fine and the dialog between the LSM6DSM and iMX8 is fine :

    while true; do cat /sys/bus/iio/devices/iio\:device0/in_accel_x_raw ; sleep 0.3; done 
    188
    190
    186
    184
    185
    196
    187
    188
    #Here i move the component
    77
    118
    180
    140
    3656
    3882
    3606
    -5
    -5

    Here the problem is in the HAL provided by ST

    May I get access to the libraries I was referring to ?

    Thanks again for any suggestions

    Best regards,

    Visitor II
    November 2, 2020

    Hi @AurelienBOUIN​ ​ 

    I am in the same situation as you. It's not the lsm6dsm i'm using lsm9ds1.

    grep "" /sys/bus/iio/devices/iio\:device*/name

    /sys/bus/iio/devices/iio:device0/name:lsm9ds1_magn

    /sys/bus/iio/devices/iio:device1/name:lsm9ds1_accel

    /sys/bus/iio/devices/iio:device2/name:lsm9ds1_gyro

    And i can read from the device

    /sys/bus/iio/devices/iio:device1 $ cat in_accel_x_raw

    -468

    Using the dumpsys sensorservice

    No Sensors on the device

    devInitCheck : 0

    I see the library on my board at /system/vendor/lib/hw/sensor.msm.so

    Did you manage to solve it? Thank you in advance!

    AurelienBOUINAuthorAnswer
    Visitor II
    November 3, 2020

    Hey @DevM​,

    Inside the android_*_defconfig, you need to have selected the lsm9ds1, as an example for the lsmd6dsm i had to add :

    CONFIG_ST_HAL_LSM6DSM_ENABLED=y
    CONFIG_ST_HAL_ACCEL_ENABLED=y
    CONFIG_ST_HAL_MAGN_ENABLED=y
    CONFIG_ST_HAL_GYRO_ENABLED=y
    CONFIG_ST_HAL_MAGN_UNCALIB_DISABLED=y
    CONFIG_ST_HAL_GYRO_UNCALIB_DISABLED=y
    CONFIG_ST_HAL_ACCEL_UNCALIB_DISABLED=y
    CONFIG_ST_HAL_SIGN_MOTION_ENABLED=y
    CONFIG_ST_HAL_TAP_ENABLED=y
    CONFIG_ST_HAL_TAP_TAP_ENABLED=y
    CONFIG_ST_HAL_STEP_DETECTOR_ENABLED=y
    CONFIG_ST_HAL_STEP_COUNTER_ENABLED=y
    CONFIG_ST_HAL_TILT_ENABLED=y

    To be sure to recompile the ST iio library you need to delete those files before launching the AOSP make :

    rm wherever/libsensors_stmicro/android_data_config
    rm wherever/libsensors_stmicro/configuration.h
    rm wherever/libsensors_stmicro/hal_config

    I hope it will help you,

    Best regards,

    Aurelien BOUIN

    Visitor II
    September 7, 2023

    Thankyou @AurelienBOUIN​,

    But after doing all the modification in my hal folder I am getting the error .
    Steps I have followed till now :

    - device/{vendor}/{product}/BoardConfig.mk (modification)
    - device/{vendor}/{product}/init.{board}.rc (modification)
    - device/{vendor}/{product}/sepolicy/file.te (modification)
    - device/{vendor}/{product}/sepolicy/file_contexts (modification)
    - device/{vendor}/{product}/sepolicy/STSensors.te (add)

    i got this references from this :https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_IIO/blob/STMems_Android_Sensor_HAL_IIO/Documentation/README

    As you have above mentioned for deleting the android_data_config , configuration.h and hal_config before compiling the ST iio hal folder and for compilation i gave "mm sensors-defconfig" in the root hal folder and i found the error log as:

    FAILED: sensors-defconfig
    /bin/bash -c "(\$(cp hardware/STMicroelectronics/STMems_Android_Sensor_HAL_IIO/src/android_R_defconfig hardware/STMicroelectronics/STMems_Android_Sensor_HAL_IIO/hal_con
    fig) ) && (hal_config hardware/STMicroelectronics/STMems_Android_Sensor_HAL_IIO/tools/mkconfig hardware/STMicroelectronics/STMems_Android_Sensor_HAL_IIO/ > hardware/STM
    icroelectronics/STMems_Android_Sensor_HAL_IIO/configuration.h )"
    /bin/bash: hal_config: command not found
    10:13:59 ninja failed with: exit status 1

    #### failed to build some targets (47 seconds) ####

    Please mark that i am using android version 11 and imx8mm board for my sensor integration.
    Waiting for your support.Please help me out .
    Thankyou in advance.

    Visitor II
    November 3, 2020

    Hey again @DevM​ ,

    As an example attached is my sepolicy for the lsm6dsm

    Best regards,

    Aurelien BOUIN

    Visitor II
    November 3, 2020

    Hi @AurelienBOUIN​ ,

    Thanks for your answers, in your board using the dumpsys sensorservice gives you some results right?

    I'm double checking my sepolicy, looks good to me ( i'm using STMems_Android_Sensor_HAL_IIO/Documentation/ueventd.example.rc as example ). About the defconfig file, i added some entries. But the result is the same.

    Visitor II
    November 3, 2020
    captina:/ #dumpsys sensorservice
    Sensor Device:
    Total 9 h/w sensors, 9 running:
    0x00000007) active-count = 1; sampling_period(ms) = {83.3}, selected = 83.33 ms; batching_period(ms) = {0.0}, selected = 0.00 ms
    0x00000009) active-count = 1; sampling_period(ms) = {1.0}, selected = 1.00 ms; batching_period(ms) = {0.0}, selected = 0.00 ms
    Sensor List:
    0x00000001) LSM6DSM Tilt Sensor | STMicroelectronics | ver: 1 | type: android.sensor.tilt_detector(22) | perm: n/a | flags: 0x00000007
    	special-trigger | maxDelay=0us | minDelay=0us | FIFO (max,reserved) = (1, 0) events | wakeUp | 
    0x00000002) HTS221 Temperature Sensor | STMicroelectronics | ver: 1 | type: android.sensor.ambient_temperature(13) | perm: n/a | flags: 0x00000002
    	on-change | minRate=1.00Hz | maxRate=13.00Hz | FIFO (max,reserved) = (1, 0) events | non-wakeUp | 
    0x00000003) LSM6DSM Step Counter Sensor | STMicroelectronics | ver: 1 | type: android.sensor.step_counter(19) | perm: n/a | flags: 0x00000002
    	on-change | maxDelay=0us | minDelay=0us | FIFO (max,reserved) = (1, 0) events | non-wakeUp | 
    0x00000004) LSM6DSM Gyroscope Sensor | STMicroelectronics | ver: 1 | type: android.sensor.gyroscope(4) | perm: n/a | flags: 0x00000000
    	continuous | minRate=12.00Hz | maxRate=833.33Hz | FIFO (max,reserved) = (682, 0) events | non-wakeUp | 
    0x00000005) LSM6DSM Step Detector Sensor | STMicroelectronics | ver: 1 | type: android.sensor.step_detector(18) | perm: n/a | flags: 0x00000006
    	special-trigger | maxDelay=0us | minDelay=0us | FIFO (max,reserved) = (1, 0) events | non-wakeUp | 
    0x00000006) LSM6DSM Significant Motion Sensor | STMicroelectronics | ver: 1 | type: android.sensor.significant_motion(17) | perm: n/a | flags: 0x00000005
    	one-shot | maxDelay=0us | minDelay=-1us | no batching | wakeUp | 
    0x00000007) LSM6DSM Accelerometer Sensor | STMicroelectronics | ver: 1 | type: android.sensor.accelerometer(1) | perm: n/a | flags: 0x00000000
    	continuous | minRate=12.00Hz | maxRate=833.33Hz | FIFO (max,reserved) = (682, 0) events | non-wakeUp | 
    0x00000008) HTS221 RHumidity Sensor | STMicroelectronics | ver: 1 | type: android.sensor.relative_humidity(12) | perm: n/a | flags: 0x00000002
    	on-change | minRate=1.00Hz | maxRate=13.00Hz | FIFO (max,reserved) = (1, 0) events | non-wakeUp | 
    0x00000009) Dynamic Sensor Manager | Google | ver: 1 | type: android.sensor.dynamic_sensor_meta(32) | perm: n/a | flags: 0x00000007
    	special-trigger | minRate=1000.00Hz | maxRate=1000.00Hz | no batching | wakeUp | 
    0x5f676172) Game Rotation Vector Sensor | AOSP | ver: 3 | type: android.sensor.game_rotation_vector(15) | perm: n/a | flags: 0x00000000
    	continuous | maxDelay=0us | maxRate=833.33Hz | no batching | non-wakeUp | 
    0x5f677276) Gravity Sensor | AOSP | ver: 3 | type: android.sensor.gravity(9) | perm: n/a | flags: 0x00000000
    	continuous | maxDelay=0us | maxRate=833.33Hz | no batching | non-wakeUp | 
    Fusion States:
    9-axis fusion disabled (0 clients), gyro-rate= 200.00Hz, q=< 0, 0, 0, 0 > (0), b=< 0, 0, 0 >
    game fusion(no mag) disabled (0 clients), gyro-rate= 200.00Hz, q=< 0, 0, 0, 0 > (0), b=< 0, 0, 0 >
    geomag fusion (no gyro) disabled (0 clients), gyro-rate= 200.00Hz, q=< 0, 0, 0, 0 > (0), b=< 0, 0, 0 >
    Recent Sensor events:
    LSM6DSM Accelerometer Sensor: last 50 events
    	 1 (ts=69865.678907170, wall=04:47:28.615) -0.17, 0.04, 9.83, 
    	 2 (ts=69865.758653108, wall=04:47:28.697) -0.17, 0.04, 9.83, 
    	 3 (ts=69865.838399045, wall=04:47:28.775) -0.17, 0.04, 9.82, 
    	 4 (ts=69865.918144983, wall=04:47:28.854) -0.17, 0.04, 9.83, 
    	 5 (ts=69865.997890918, wall=04:47:28.929) -0.16, 0.04, 9.83, 
    	 6 (ts=69866.077636857, wall=04:47:29.014) -0.17, 0.04, 9.83, 
    	 7 (ts=69866.157382796, wall=04:47:29.094) -0.17, 0.03, 9.83, 
    	 8 (ts=69866.237128733, wall=04:47:29.172) -0.17, 0.04, 9.83, 
    	 9 (ts=69866.316874669, wall=04:47:29.251) -0.16, 0.04, 9.83, 
    	10 (ts=69866.396620606, wall=04:47:29.329) -0.16, 0.04, 9.82, 
    	11 (ts=69866.476366545, wall=04:47:29.413) -0.17, 0.03, 9.82, 
    	12 (ts=69866.556112482, wall=04:47:29.492) -0.17, 0.04, 9.82, 
    	13 (ts=69866.635858419, wall=04:47:29.571) -0.17, 0.04, 9.83, 
    	14 (ts=69866.715604358, wall=04:47:29.653) -0.17, 0.04, 9.82, 
    	15 (ts=69866.795350296, wall=04:47:29.733) -0.17, 0.04, 9.83, 
    	16 (ts=69866.875096235, wall=04:47:29.812) -0.17, 0.04, 9.83, 
    	17 (ts=69866.954842173, wall=04:47:29.891) -0.17, 0.04, 9.82, 
    	18 (ts=69867.034588111, wall=04:47:29.971) -0.17, 0.04, 9.82, 
    	19 (ts=69867.114334049, wall=04:47:30.050) -0.17, 0.04, 9.83, 
    	20 (ts=69867.194079988, wall=04:47:30.131) -0.17, 0.04, 9.83, 
    	21 (ts=69867.273825926, wall=04:47:30.210) -0.17, 0.04, 9.83, 
    	22 (ts=69867.353571865, wall=04:47:30.290) -0.17, 0.04, 9.83, 
    	23 (ts=69867.433317804, wall=04:47:30.370) -0.17, 0.04, 9.83, 
    	24 (ts=69867.513063743, wall=04:47:30.450) -0.17, 0.04, 9.82, 
    	25 (ts=69867.592809682, wall=04:47:30.530) -0.17, 0.03, 9.83, 
    	26 (ts=69867.672555621, wall=04:47:30.609) -0.17, 0.04, 9.83, 
    	27 (ts=69867.752301560, wall=04:47:30.690) -0.17, 0.04, 9.82, 
    	28 (ts=69867.832047497, wall=04:47:30.769) -0.17, 0.04, 9.83, 
    	29 (ts=69867.911793436, wall=04:47:30.849) -0.17, 0.04, 9.83, 
    	30 (ts=69867.991539375, wall=04:47:30.929) -0.17, 0.04, 9.82, 
    	31 (ts=69868.071285313, wall=04:47:31.008) -0.17, 0.03, 9.83, 
    	32 (ts=69868.151031252, wall=04:47:31.088) -0.17, 0.04, 9.83, 
    	33 (ts=69868.230777191, wall=04:47:31.169) -0.17, 0.03, 9.83, 
    	34 (ts=69868.310523130, wall=04:47:31.248) -0.17, 0.04, 9.83, 
    	35 (ts=69868.390269069, wall=04:47:31.328) -0.17, 0.04, 9.82, 
    	36 (ts=69868.470015008, wall=04:47:31.407) -0.17, 0.04, 9.83, 
    	37 (ts=69868.549760947, wall=04:47:31.487) -0.17, 0.04, 9.83, 
    	38 (ts=69868.629506885, wall=04:47:31.566) -0.17, 0.04, 9.83, 
    	39 (ts=69868.709252825, wall=04:47:31.647) -0.17, 0.04, 9.83, 
    	40 (ts=69868.788998764, wall=04:47:31.726) -0.17, 0.04, 9.83, 
    	41 (ts=69868.868744704, wall=04:47:31.806) -0.17, 0.05, 9.83, 
    	42 (ts=69868.948490643, wall=04:47:31.886) -0.17, 0.03, 9.83, 
    	43 (ts=69869.028236582, wall=04:47:31.963) -0.17, 0.04, 9.83, 
    	44 (ts=69869.107982522, wall=04:47:32.045) -0.17, 0.04, 9.82, 
    	45 (ts=69869.187728462, wall=04:47:32.125) -0.17, 0.03, 9.82, 
    	46 (ts=69869.267474402, wall=04:47:32.205) -0.17, 0.04, 9.83, 
    	47 (ts=69869.347220341, wall=04:47:32.284) -0.17, 0.04, 9.84, 
    	48 (ts=69869.426966280, wall=04:47:32.363) -0.17, 0.04, 9.83, 
    	49 (ts=69869.506712220, wall=04:47:32.444) -0.17, 0.04, 9.83, 
    	50 (ts=69869.586458160, wall=04:47:32.525) -0.17, 0.03, 9.83, 
    Active sensors:
    LSM6DSM Accelerometer Sensor (handle=0x00000007, connections=1)
    Dynamic Sensor Manager (handle=0x00000009, connections=1)
    Socket Buffer size = 984 events
    WakeLock Status: not held 
    Mode : NORMAL
    2 active connections
    Connection Number: 0 
    	Operating Mode: NORMAL
    	 android.view.OrientationEventListener | WakeLockRefCount 0 | uid 10025 | cache size 0 | max cache size 0
    	 LSM6DSM Accelerometer Sensor 0x00000007 | status: active | pending flush events 0 
    Connection Number: 1 
    	Operating Mode: NORMAL
    	 com.android.server.SensorNotificationService | WakeLockRefCount 0 | uid 1000 | cache size 0 | max cache size 0
    	 Dynamic Sensor Manager 0x00000009 | status: active | pending flush events 0 
    0 direct connections
    Previous Registrations:
    09:24:25 + 0x00000007 pid= 4255 uid=10025 package=android.view.OrientationEventListener samplingPeriod=83333us batchingPeriod=0us
    09:23:28 - 0x00000007 pid= 3314 uid= 1000 package=com.android.server.policy.WindowOrientationListener
    09:23:16 + 0x00000007 pid= 3314 uid= 1000 package=com.android.server.policy.WindowOrientationListener samplingPeriod=66667us batchingPeriod=0us
    09:23:14 + 0x00000009 pid= 3314 uid= 1000 package=com.android.server.SensorNotificationService samplingPeriod=1000us batchingPeriod=0us