cancel
Showing results for 
Search instead for 
Did you mean: 

Android P can't get LSM9DS1 Magnetometer data

zjian.11
Associate
  1. LSM9DS1 IMU Linux Driver:https://github.com/STMicroelectronics/STMems_Linux_IIO_drivers/tree/linux-4.14.y-gh/drivers/iio/imu/st_imu68
  2. LSM9DS1 ​Magnetometer Linux Driver:https://github.com/STMicroelectronics/STMems_Linux_IIO_drivers/blob/linux-4.14.y-gh/drivers/iio/magnetometer/st_mag3d_i2c.c
  3. Android HAL Driver:https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_IIO
  4. Our Android P system can get LSM9DS1's Accelerometer/Gyroscope data, but can't get LSM9DS1's ​Magnetometer data. We have checked iio driver work correctly.
1 REPLY 1
Eleon BORLINI
ST Employee

Hi @zjia.938nfeng​ , after a check with our experts they told me you could face some issue because this component has no entry for the FIFO in the filesystem. You can try the following steps:

1.Try to launch this function from the linux command line (checking if the interrupt pin of the magnetometer has been well connected to the processor):

generic_buffer -n lsm9ds1_accel -ga -c 10

generic_buffer -n lsm9ds1_gyro -ga -c 10

generic_buffer -n lsm9ds1_magn -ga -c 10

2.You could send us the Android logcat for our check

You could btw try to add this code to the SensorHAL and check if it's working:

diff --git a/src/SensorHAL.cpp b/src/SensorHAL.cpp
index 4df9553..5b95523 100644
--- a/src/SensorHAL.cpp
+++ b/src/SensorHAL.cpp
@@ -1171,6 +1177,9 @@ static int st_hal_load_iio_devices_data(STSensorHAL_iio_devices_data *data)
                }
 
                data[index].hw_fifo_len = device_iio_utils::get_hw_fifo_length(data[index].iio_sysfs_path);
+               if (data[index].hw_fifo_len <= 0)
+                       data[index].hw_fifo_len = 1;
+
                data[index].sensor_type = ST_sensors_supported[n].android_sensor_type;
                data[index].dev_id = iio_devices[i].num;
 
diff --git a/src/utils.cpp b/src/utils.cpp
index 0075f2b..457f8f6 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -673,7 +672,19 @@ int device_iio_utils::set_hw_fifo_watermark(char *device_dir,
        ret = snprintf(tmp_filaname, DEVICE_IIO_MAX_FILENAME_LEN,
                       "%s/%s", device_dir, device_iio_hw_fifo_watermark);
 
-       return ret < 0 ? -ENOMEM : sysfs_write_int(tmp_filaname, watermark);
+       if (ret < 0)
+               return -ENOMEM;
+
+       ret = check_file(tmp_filaname);
+
+       if (!ret) {
+               ret = sysfs_write_int(tmp_filaname, watermark);
+       } else if (errno != ENOENT) {
+               /* permission error */
+               return ret;
+       }
+
+       return 0;
 }

If this still not work, please try this other code

diff --git a/src/utils.cpp b/src/utils.cpp
index 0075f2b..7ee7fb6 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -585,37 +584,37 @@ int device_iio_utils::get_hw_fifo_length(const char *device_dir)
        ret = snprintf(tmp_filaname, DEVICE_IIO_MAX_FILENAME_LEN,
                       "%s/%s", device_dir, device_iio_hw_fifo_length);
        if (ret < 0)
-               return -ENOMEM;
+               return 0;
 
        ret = sysfs_read_int(tmp_filaname, &len);
        if (ret < 0 || len <= 0)
-               return ret;
+               return 0;
 
        /* write "len * 2" -> <iio:devicex>/buffer/length */
        ret = snprintf(tmp_filaname, DEVICE_IIO_MAX_FILENAME_LEN,
                       "%s/%s", device_dir, device_iio_buffer_length);
        if (ret < 0)
-               return -ENOMEM;
+               return 0;
 
        ret = sysfs_write_int(tmp_filaname, 2 * len);
        if (ret < 0)
-               return ret;
+               return 0;
 
        /* write "1" -> <iio:devicex>/hwfifo_enabled */
        ret = snprintf(tmp_filaname, DEVICE_IIO_MAX_FILENAME_LEN,
                       "%s/%s", device_dir, device_iio_hw_fifo_enabled);
        if (ret < 0)
-               return -ENOMEM;
+               return 0;
 
        /* used for compatibility with old iio API */
        ret = check_file(tmp_filaname);
        if (ret < 0 && errno == ENOENT)
-               return len;
+               return 0;
 
        ret = sysfs_write_int(tmp_filaname, 1);
        if (ret < 0) {
                ALOGE("Failed to enable hw fifo: %s.", tmp_filaname);
-               return ret;
+               return 0;
        }
 
        return len;

Regards