VisionSOM-STM32MP1 sensors demo
From SomLabs Wiki
VisionSOM-STM32MP1 sensors demo
Contents
The SoMLabs sensors demo application for VisionSOM-STM32MP1 module and VisionCB-STM32MP1-STD board is the example of simple signal measurement and data presentation in a graphical user interface. The application reads the acceleration data from the LSM6DS3 sensor connected to the I2C bus and the analogue signal samples collected by the on-chip ADC. The results are presented on the Qt interface built with the QML and QtCharts libraries.
Hardware configuration
ADC
The ADC needs to be enabled in the device tree since it is not configured in the default system images for VisionSOM-STM32MP1. Moreover, the timer 2 is enabled and used later for the ADS triggering. The following files in the mx directory need to be modified:
- kernel/stm32mp157a-visionsom-dsi-mx.dts
&pinctrl { u-boot,dm-pre-reloc; adc_pins_mx: adc_mx-0 { pins { pinmux = <STM32_PINMUX('B', 1, ANALOG)>; /* ADC1_INP5 */ }; }; adc_sleep_pins_mx: adc_sleep_mx-0 { pins { pinmux = <STM32_PINMUX('B', 1, ANALOG)>; /* ADC1_INP5 */ }; };
&adc{ pinctrl-names = "default", "sleep"; pinctrl-0 = <&adc_pins_mx>; pinctrl-1 = <&adc_sleep_pins_mx>; status = "okay"; /* USER CODE BEGIN adc */ vref-supply = <&vdd>; status = "okay"; adc1: adc@0 { st,adc-channels = <5>; st,min-sample-time-nsecs = <10000>; status = "okay"; }; /* USER CODE END adc */ };
&timers2{ status = "okay"; /* USER CODE BEGIN timers2 */ /delete-property/dmas; /delete-property/dma-names; pwm { status = "okay"; }; timer@1 { status = "okay"; }; /* USER CODE END timers2 */ };
- u-boot/stm32mp157a-visionsom-dsi-mx.dts
&pinctrl { u-boot,dm-pre-reloc; adc_pins_mx: adc_mx-0 { pins { pinmux = <STM32_PINMUX('B', 1, ANALOG)>; /* ADC1_INP5 */ }; }; adc_sleep_pins_mx: adc_sleep_mx-0 { pins { pinmux = <STM32_PINMUX('B', 1, ANALOG)>; /* ADC1_INP5 */ }; };
&adc{ pinctrl-names = "default", "sleep"; pinctrl-0 = <&adc_pins_mx>; pinctrl-1 = <&adc_sleep_pins_mx>; status = "okay"; /* USER CODE BEGIN adc */ vref-supply = <&vdd>; status = "okay"; adc1: adc@0 { st,adc-channels = <5>; st,min-sample-time-nsecs = <10000>; status = "okay"; }; /* USER CODE END adc */ };
&timers2{ status = "okay"; /* USER CODE BEGIN timers2 */ trigger@0 { status = "okay"; }; /* USER CODE END timers2 */ };
- u-boot/stm32mp157a-visionsom-dsi-mx-u-boot.dtsi
CLK_ADC_PLL4R
pll4:st,pll@3 { cfg = < 3 98 5 7 7 PQR(1,1,1) >; };
- tf-a/stm32mp157a-visionsom-dsi-mx.dts
CLK_ADC_PLL4R
pll4:st,pll@3 { cfg = < 3 98 5 7 7 PQR(1,1,1) >; };
&etzpc{ st,decprot = < DECPROT(STM32MP1_ETZPC_ADC_ID, DECPROT_NS_RW, DECPROT_UNLOCK) DECPROT(STM32MP1_ETZPC_TIM2_ID, DECPROT_NS_RW, DECPROT_UNLOCK)
LSM6DS3
The LSM6DS3 sensor is connected to the I2C4 bus which is already configured for the touchscreen. However a new subsection needs to be added to the &i2c4 device in order to register correct driver.
- kernel/stm32mp157a-visionsom-dsi-mx.dts
lsm6ds3@6a { compatible = "st,lsm6ds3"; reg = <0x6a>; };
Finally, the driver needs to be compiled with the kernel (or as a module) in the kernel configuration file:
- stm32mp157a_visionsom_mx_defconfig
CONFIG_IIO_ST_SENSORS_I2C=m CONFIG_IIO_ST_SENSORS_SPI=m CONFIG_IIO_ST_SENSORS_CORE=m CONFIG_IIO_ST_LSM6DSX=m CONFIG_IIO_ST_LSM6DSX_I2C=m CONFIG_IIO_ST_LSM6DSX_SPI=m
ADC configuration
The ADC is configured within the application using the iio subsystem. The following values are written to the configuration files in order to obtain the 1kHz sampling frequency on channel 5 with 128 samples watermark:
echo 1000 > /sys/bus/iio/devices/trigger0/sampling_frequency echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage5_en echo tim2_trgo > /sys/bus/iio/devices/iio:device0/trigger/current_trigger echo 128 > /sys/bus/iio/devices/iio:device0/buffer/watermark echo 256 > /sys/bus/iio/devices/iio:device0/buffer/length echo 1 > /sys/bus/iio/devices/iio:device0/buffer/enable
The raw ADS readings are obtained from the file: /dev/iio:device0
LSM6DS3 configuration
The LSM6DS3 sensor is ready to use after system boot. The application configures the sampling frequency:
echo 416 > /sys/bus/iio/devices/iio:device0/sampling_frequency
The sensor raw readings can be obtained from the files:
- /sys/bus/iio/devices/iio:device0/in_accel_x_raw
- /sys/bus/iio/devices/iio:device0/in_accel_y_raw
- /sys/bus/iio/devices/iio:device0/in_accel_z_raw
Application binary
The application compiled binary is available for download: VisionSOM-STM32MP1_sensors_demo.zip