GithubHelp home page GithubHelp logo

stmicroelectronics / st-mems-android-linux-drivers-iio Goto Github PK

View Code? Open in Web Editor NEW
21.0 11.0 1.0 1.61 MB

stm mems iio drivers for Android and Linux platforms.

License: GNU General Public License v2.0

Makefile 0.36% C 99.64%
iio mems sensors android kernel mems-sensors stmicroelectronics

st-mems-android-linux-drivers-iio's Introduction

Introduction

This repository contains STMicroelectronics MEMS IIO drivers for the following LTS Linux/Android kernels:

  • 4.9 (EOL)
  • 4.14
  • 4.19
  • 5.4
  • 5.10
  • 5.15
  • 6.1
  • 6.6 (WIP)

For EOL kernel the maintenance has been discontinued and is strongly discouraged from using it for new developments.

Source code integration

From your kernel source code directory add the git remote (i.e. stmems_iio_github) for this repository:

git remote add stmems_iio_github \
               https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio.git

Fetch the just added remote:

git fetch stmems_iio_github

There are now two ways to integrate the drivers code into the kernel target branch:

  • merge (suggested strategy)
  • rebase

merge

Merge the stmems_iio_github/master with your target kernel source branch (i.e branch linux-5.4.y):

git merge --allow-unrelated-histories \
          linux-5.4.y \
          stmems_iio_github/master

rebase

Rebase the stmems_iio_github/master on top of your target kernel source branch (i.e branch linux-5.4.y):

git rebase --no-fork-point \
           linux-5.4.y \
           stmems_iio_github/master

Note: older git versions (i.e.: 2.7.4) would require to use sligthly different options:

git merge --no-fork-point \
          linux-5.4.y \
          stmems_iio_github/master
git rebase -Xno-renames \
           --no-fork-point \
           linux-5.4.y \
           stmems_iio_github/master

Apply patches

Now that drivers code has been added to the target kernel branch, few patches needs to be added in order to:

  • add STM drivers into Kconfig & Makefile systems
  • patch IIO framework with custom events with custom events, channels and devices

Apply the patches available in the just added repository (i.e branch linux-5.4.y):

git am stm_iio_patches/5.4.y/*-stm-*.patch

Configuration

A folder named stm_iio_configs should now be available with the default configs for the supported drivers.

Modify target defconfig

Sensors defconfig can be appended to the board defconfig (i.e. if your current configuration file is arch/arm/configs/stm32_defconfig):

cat stm_iio_configs/lsm6dsm_defconfig >> arch/arm/configs/stm32_defconfig

Alternatively, it can be done at build time without altering the board config file, as follow.

Merge configuration

Driver config can be merged into current target pre-configured kernel using a script available in the kernel itself:

export ARCH=arm
export CROSS_COMPILE=arm-linux-gnu-
scripts/kconfig/merge_config.sh -n .config stm_iio_configs/lsm6dsm_defconfig

License

This software is distributed under the GNU General Public License v2.0

st-mems-android-linux-drivers-iio's People

Contributors

ciocca-d avatar mariotesi avatar matteo-dameno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

lucbeaufils

st-mems-android-linux-drivers-iio's Issues

ASM330LHH IIO driver on kernel 5.10

Hi,
I have ported the IIO driver to Kernel5.10 and it should be working fine. But I'm not sure how to read the sensor value from the application layer. I use "cat /sys/bus/iio/devices/iio:device0/in_anglvel_x_raw" to get this error: "The cat: '/ sys/bus/iio/devices/iio: device0 / in_anglvel_x_raw' : Remote I/O error".

If I use the "fread" function in c code to read xxx_raw files, I end up with zero values.

Is there a demo of application layer reading code? Can you provide it for my reference?

Slow when keep read value?

I got really slowy speed when read iio node, and some value event not correct.
Is any way I can fix it??
Here is my script and output.

echo "Hello iio test"
cat /sys/bus/iio/devices/iio\:device2/sampling_frequency 
while :
do
        cat /sys/bus/iio/devices/iio:device2/in_accel_x_raw >> /dev/kmsg
        cat /sys/bus/iio/devices/iio:device2/in_accel_y_raw >> /dev/kmsg
        cat /sys/bus/iio/devices/iio:device2/in_accel_z_raw >> /dev/kmsg
        cat /sys/bus/iio/devices/iio:device1/in_anglvel_x_raw >> /dev/kmsg
        cat /sys/bus/iio/devices/iio:device1/in_anglvel_y_raw >> /dev/kmsg
        cat /sys/bus/iio/devices/iio:device1/in_anglvel_z_raw >> /dev/kmsg
    sleep 0.01
done
root@iBox-500:~/kivyT# sh test.sh                                                                                                                                                                              
Hello iio test                                                                                                                                                                                                 
833.000000                                                                                                                                                                                                     
[ 1131.604427] 1548                                                                                                                                                                                            
[ 1131.616635] -368                                                                                                                                                                                            
[ 1131.628900] -16176                                                                                                                                                                                          
[ 1131.956560] 9                                                                                                                                                                                               
[ 1132.283833] -70                                                                                                                                                                                             
[ 1132.558214] -68                                                                                                                                                                                             
[ 1132.584233] 1486                                                                                                                                                                                            
[ 1132.596522] -408                                                                                                                                                                                            
[ 1132.608636] -16095                                                                                                                                                                                          
[ 1132.935723] 7                                                                                                                                                                                               
[ 1133.262978] -70                                                                                                                                                                                             
[ 1133.590466] -67                                                                                                                                                                                             
[ 1133.616815] 1444                                                                                                                                                                                            
[ 1133.628973] -423                                                                                                                                                                                            
[ 1133.641130] -16098                                                                                                                                                                                          
^C                                                                                                                                                                                                             
root@iBox-500:~/kivyT# 

Here is my DTS setting

LSM6DSRTR@6b {
// /sys/bus/iio/devices/iio:device1
// /sys/bus/iio/devices/iio:device2
compatible = "st,lsm6dsr";
reg = <0x6b>;
// interrupt-parent = <&gpio0>;
// interrupts = <0 IRQ_TYPE_EDGE_RISING>;
mount-matrix = "1", "0", "0",
				"0", "1", "0",
				"0", "0", "1";
};

Correct way to implement accel/gyro thresholds on lsm9ds1

Hi,
we're noticing an incredibly high number of raised IRQs (about one every 20ms) in android from the lsm9ds1 accelerometer. This situation causes a fixed 20% usage on the CPU. When testing the gyroscope, the situation is the same. What is the correct way to implement thresholds in the code so that a device in static position doesn't flood the kernel with IRQs? We've tried writing to the various THS registers, enabling FIFO THS on INT1, setting DUR and WAIT... everything to no success. The only thing we managed to reduce the CPU to about 2.5% is setting the Decimation to 8. The documentation doesn't really explain what values the registers expect and/or if there's a correct order to set them. Please help :)

Configuring a hrtimer-trigger or buffered-trigger for iio-device and ODR in driver lower than actual ODR

Hello, I have been having issues with configuring configuring a hrtimer-trigger or buffered-trigger for my iio-device. I am using a ISM330dlc (IMU) and it is connected to a rasberry pi cm4. As a driver I am using the LSM6DSX driver because my IMU is listed as configurable sensor in the Documentation. My problem is that when I load my device tree overlay (dtbo file) the /sys/bus/iio/devices/iio:deviceX/ directory appears but only these files appear.
284557304-52913afb-7326-4841-8317-0c6c70791489
In basically every documentation file, they say that a /sys/bus/iio/devices/iio:deviceX/trigger/ directory should appear and it doesn't matter what I do it doesn't appear. I have checked and the ISM330dlc supports triggers, even 2. Chatgpt has suggested I should change some parameters in the config.txt, but I have checked and every functionality I need.
284559182-2e54f9bb-2852-4d5a-a8cf-f66d86b5caf8
And as you can see everything is set to "m" or "y" so there shouldn't be a problem there.
I have also looked into my dts file:
284560141-6d68a484-2aba-4206-b582-7e0101bdc1ea
And chatgbt suggested I should do it in this fashion:
284560701-376df592-c917-43f3-bd45-cafaac2f757d

Unfortunately I haven't found anything regarding triggers under this Documentation path linux/Documentation/devicetree/bindings/iio/imu /st,lsm6dsx.yaml .

Also just a side question, is the buffered trigger a hardware trigger from the IMU because that is what I need besides the Hrtimer-trigger. What I really need, is to compare:
-polling the Data-ready register to see whether new data is ready which then serves me as an interrupt if the data is ready
-waiting for hardware interrupt when new data is ready
To compare them I need to know if there is any chance I can do this by using iio-devices or moreover iio-triggers.

And also my ODR can just be configured to 433Hz even though I know for a fact that my IMU can be configured to an ODR of even 1.6KHz. I only need it set to 833Hz but the issue remains. I am a newbie linux, the iio-framework and the device tree, so I would be extremely thankful if you could provide some backround information to your answer, if you think you might have a solution for me.
Thank you very much in advance.

lsm9ds1 (st_imu68) irq not triggered on data ready

Hi,
we're using an lsm9ds1 on an Android 10 board with kernel 5.4 and, while the in-kernel magnetormeter driver works correctly and the HAL receives the correct data when an irq is raised, the accel/gyro section doesn't seem to work in the same way. We tried the older driver and this new one to the same result. The triggers are setup correctly and the data readings from sysfs (eg: in_accel_x_raw) return sane values readings via i2c, but no irq is raised at all when the device is moved or rotated. We've tried setting the irq type in the dt as low/high/rising/falling (and related changes in the driver) to no visible results. When we force enable the data-ready irq via i2cset (eg: "i2cset -y -f 2 0x6a 0x0c 0x3" to enable both data-ready for accel/gyro on the 1st irq line), we see the interrupts coming in /proc/interrupts, but no data is received from the HAL (we're using the android hal provided here: https://github.com/STMicroelectronics/st-mems-android-linux-sensors-hal). No changes have been done to the driver itself and all sensors show up in Aida64, including the iNemo virtual sensors, but no data is received.
Any idea what could be going on or if we're missing something ? We've been fighting with this issue for the last week...

Edit: we also tried with the IIO HAL (https://github.com/STMicroelectronics/STMems_Android_Sensor_HAL_IIO) and the result is the same. Magnetometer works fine, accel / gyro are silent.

Updated driver AIS2IHTR to read temperature register

Hello,

I use an ais2h chip with spi on a project to have accelerometer and temperature sensors. I use a Linux-imx kernel 5.10 in a Yocto project.
I have no integration problem with the driver but the temperature reading doesn't seem to be implemented.
Do you plan to implement register reading for temperatures on this chip? Or their is a way to have it ?

Thanks

LSM6DSO iio errors

I have added your drivers to the current released tag of the Raspberry Pi kernel version 5.15.74 and compiled the modules for st_lsm6dsox. The module is loaded with the following overlay.

/dts-v1/;
/plugin/;
#include <dt-bindings/interrupt-controller/irq.h>

/ {
        compatible = "brcm,bcm2835";

        fragment@0 {
                target = <&i2c1>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";
                        clock-frequency = <400000>;

                        lsm6dso: lsm6dso@6a {
                                compatible = "st,lsm6dso";
                                reg = <0x6a>;
                                interrupt-parent = <&gpio>;
                                interrupts = <22 IRQ_TYPE_EDGE_FALLING>,
					     <27 IRQ_TYPE_EDGE_FALLING>;
				st,int-pin = <1>;
                        };
                };
        };

};

The following failures are then observed in dmesg

[ 8.657920] st_lsm6dsox: disagrees about version of symbol iio_push_event
[ 8.657955] st_lsm6dsox: Unknown symbol iio_push_event (err -22)
[ 8.657981] st_lsm6dsox: disagrees about version of symbol iio_push_to_buffers
[ 8.657994] st_lsm6dsox: Unknown symbol iio_push_to_buffers (err -22)
[ 8.658021] st_lsm6dsox: disagrees about version of symbol iio_device_release_direct_mode
[ 8.658033] st_lsm6dsox: Unknown symbol iio_device_release_direct_mode (err -22)
[ 8.658073] st_lsm6dsox: disagrees about version of symbol devm_iio_kfifo_buffer_setup_ext
[ 8.658085] st_lsm6dsox: Unknown symbol devm_iio_kfifo_buffer_setup_ext (err -22)
[ 8.658117] st_lsm6dsox: disagrees about version of symbol iio_device_alloc
[ 8.658129] st_lsm6dsox: Unknown symbol iio_device_alloc (err -22)
[ 8.658153] st_lsm6dsox: disagrees about version of symbol iio_device_free
[ 8.658164] st_lsm6dsox: Unknown symbol iio_device_free (err -22)
[ 8.658206] st_lsm6dsox: disagrees about version of symbol iio_show_mount_matrix
[ 8.658217] st_lsm6dsox: Unknown symbol iio_show_mount_matrix (err -22)
[ 8.658235] st_lsm6dsox: disagrees about version of symbol iio_device_claim_direct_mode
[ 8.658246] st_lsm6dsox: Unknown symbol iio_device_claim_direct_mode (err -22)
[ 8.658284] st_lsm6dsox: disagrees about version of symbol __iio_device_register
[ 8.658296] st_lsm6dsox: Unknown symbol __iio_device_register (err -22)
[ 8.658330] st_lsm6dsox: disagrees about version of symbol __devm_iio_device_register
[ 8.658341] st_lsm6dsox: Unknown symbol __devm_iio_device_register (err -22)
[ 8.658372] st_lsm6dsox: disagrees about version of symbol devm_iio_device_alloc
[ 8.658383] st_lsm6dsox: Unknown symbol devm_iio_device_alloc (err -22)
[ 8.658399] st_lsm6dsox: disagrees about version of symbol iio_get_time_ns
[ 8.658410] st_lsm6dsox: Unknown symbol iio_get_time_ns (err -22)
[ 8.658426] st_lsm6dsox: disagrees about version of symbol iio_device_unregister
[ 8.658437] st_lsm6dsox: Unknown symbol iio_device_unregister (err -22)

compilation of st_lis2dw12_buffer.c with kernel 5.15 fails

I'm using the Kernel 5.15. and get the following error when I try to compile the driver for the LIS2DW12/IIS2DLPC:

st_lis2dw12_buffer.c:308:18: error: implicit declaration of function 'devm_iio_kfifo_allocate'; did you mean 'iio_kfifo_allocate'? [-Werror=implicit-function-declaration]

The function 'devm_iio_kfifo_allocate' was changed to a private function in kernel 5.13 and replaced by 'devm_iio_kfifo_buffer_setup' in header 'kfifo_buf.h'

Power up fail for lis2dux12/lis2duxs12

Hi,
I'm using LIS2DUX12 accelerometer on a custom PCB with SPI interface in a Linux environment and I was experiencing a failure during the probe of the device with error message [ 0.561627] st_lis2duxs12_spi spi0.0: unsupported whoami [ff]
Reading the datasheet documentation I found out that

When Vdd and Vdd_IO are set, the device enters a deep power-down state

So I read how to exit from a deep power-down state

If the SPI interface is used, the LIS2DUX12 can move from deep power-down to soft power-down by writing the
bit SOFT_PD of EN_DEVICE_CONFIG (3Eh) to 1

and took a look into the implementation of the function st_lis2duxs12_power_up_command(struct st_lis2duxs12_hw *hw) inside the file
st_lis2duxs12_core.c

To my surprise I found out that the code does not implement what's described in the documentation but instead was reading WHO_AM_I (0Fh) register.

regmap_read(hw->regmap, ST_LIS2DUXS12_WHOAMI_ADDR, &data);

To this SPI transaction the accelerometer does not respond and the MISO line stays high.

So, I tried to write EN_DEVICE_CONFIG (3Eh) to 1 instead and by doing so the probe returned with success!
I did this by putting the magic numer 0x3E as an argument to the regmap_write() function because there is no definition of that register address inside st_lis2duxs12.h file. Does this file, as well as others related to LIS2DUX12, need to be updated to reflect the latest changes with this device/documentation?

Thanks

Licensing

Hi all,

I can see many of the files in this repo are licensed under GPL v2. However, without mention of this in the README, in a licensing file, or on the page on the website for this software, I don't feel safe treating the entire project as GPL v2. Could you please clearly lay out licensing for this repo and software? Thanks

Support for sensor hub on LSM6DSM

I have a device with an LSM6DSM communicating with my host over SPI and would like to connect an LPS22HH on the downstream I2C pins.

Does this driver support that? I'm not seeing how to configure things to support a downstream device.

How to Stabilize Sensor Output and Achieve Target Frequency for asm330lhhxg1 and lsm6dsox?

Hi ,

I am currently working on porting two sensors, the asm330lhhxg1 and lsm6dsox, to my platform.
However, I have no idea how to stabilize the sensor data and achieve the frequency in Hz as specified in the hardware specifications. Despite searching and trying various tutorials, using the iio_generic_buffer tools yields no results.

# Enable Y-axis acceleration
echo 1 > /sys/bus/iio/devices/iio:device2/scan_elements/in_accel_y_en

# Enable X-axis acceleration
echo 1 > /sys/bus/iio/devices/iio:device2/scan_elements/in_accel_x_en

# Enable timestamp
echo 1 > /sys/bus/iio/devices/iio:device2/scan_elements/in_timestamp_en

# Enable Z-axis acceleration
echo 1 > /sys/bus/iio/devices/iio:device2/scan_elements/in_accel_z_en

# Attempt to enable buffer
echo 1 > /sys/bus/iio/devices/iio:device2/buffer/enable

# Run generic buffer utility
./iio_generic_buffer -a -g -n asm330lhhxg1_accel
# Output from incomplete command
  iio device number being used is 2
  trigger-less mode selected
  Auto-channels selected but some channels are already activated in sysfs
  Proceeding without activating any channels
##stuck here

#Here is my device tree configuration under `i2c0`:

&i2c0 {
   asm330lhhx-imu@0x6b {
        compatible = "st,asm330lhhxg1";
        reg = <0x6b>;
        interrupt-parent = <&gpio0>;
        interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
        /*vddio-supply = <&sensors_vddio>;*/
        /*vdd-supply = <&sensors_vdd>;*/
	    drive-open-drain;
        st,int-pin = <1>;
        st,mlc-int-pin = <2>;
        mount-matrix = "1", "0", "0",
                   "0", "1", "0",
                   "0", "0", "1";
        };
    }
#  ./iio_generic_buffer -a -n asm330lhhxg1_gyro -e -g
iio device number being used is 1
trigger-less mode selected
No channels are enabled, enabling all channels
Enabling: in_anglvel_z_en
Enabling: in_timestamp_en
Enabling: in_raw_en
Enabling: in_anglvel_y_en
Enabling: in_anglvel_x_en
nothing available
nothing available
Disabling: in_anglvel_z_en
Disabling: in_timestamp_en
Disabling: in_raw_en
Disabling: in_anglvel_y_en

Could you please provide any suggestions?

Thanks,
AlysonQ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.