Skip to main content
Visitor II
March 17, 2023
Solved

How to connect adc driver in dts with libiio - stm32mp1

  • March 17, 2023
  • 16 replies
  • 5571 views

Hi,

I try to connect ADC channels with libiio for my custom board based on the stm32mp157caa3. I followed the instructions from the link

https://wiki.st.com/stm32mpu/wiki/IIO_libiio

https://wiki.st.com/stm32mpu/wiki/ADC_device_tree_configuration#DT_configuration_examples

but without success. After issuing the console

iio_info

I get

Library version: 0.23 (git tag: 92d6a35)
Compiled with backends: local xml ip usb serial
IIO context created with local backend.
Backend version: 0.23 (git tag: 92d6a35)
Backend description string: Linux stm32mp1-connect-bridge 5.15.67 #1 SMP PREEMPT Thu Sep 8 10:32:54 UTC 2022 armv7l
IIO context has 2 attributes:
	local,kernel: 5.15.67
	uri: local:
IIO context has 0 devices:

The same is in

/sys/bus/iio/devices/

empty, with no devices.

Part of my dts looks

&adc{
	pinctrl-names = "default", "sleep";
	pinctrl-0 = <&adc_pins_mx>;
	pinctrl-1 = <&adc_sleep_pins_mx>;
	status = "okay";
 
	/* USER CODE BEGIN adc */
	vdda-supply = <&vdda>; /* Example to supply vdda pin by using a PMIC regulator */
	vref-supply = <&vrefbuf>; /* Example to use VREFBUF (It needs to be enabled as well) */
	adc1: adc@0 {
		assigned-resolution-bits = <12>;
		/* Single-ended channels */
		channel@0 {
			reg = <0>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@1 {
			reg = <1>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@2 {
			reg = <2>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@3 {
			reg = <3>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@5 {
			reg = <5>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@6 {
			reg = <6>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@9 {
			reg = <9>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@10 {
			reg = <10>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@12 {
			reg = <12>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@13 {
			reg = <13>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@15 {
			reg = <15>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
		channel@17 {
			reg = <17>;
			st,min-sample-time-ns = <10000>; /* 10µs sampling time */
		};
	};
	/* USER CODE END adc */
};

In the Kernel configuration, I also marked

Device Drivers --->
 
 <*> Industrial I/O support --->
 
 Analog to digital converters --->
 
 <*> STMicroelectronics STM32 adc core
 
 <*> STMicroelectronics STM32 adc

It must be something I missed.

Thanks in advance for the hints.

BR Michal

    This topic has been closed for replies.
    Best answer by MWoło.2

    After some break and rechecking everything I discover a correct dts configuration.

    First I used as reference AVDD(external) and according to this I have configurations like

    The Kernel

    &adc {
    	/* ANA0, ANA1 are dedicated pins and don't need pinctrl: only in6. */
    	pinctrl-names = "default", "sleep";
    	pinctrl-0 = <&adc_pins_mx>;
    	pinctrl-1 = <&adc_sleep_pins_mx>;
    	vdd-supply = <&vdd>;
    	vdda-supply = <&vdda>;
    	vref-supply = <&vdda>;
    	status = "okay";
    	adc1: adc@0 {
    		#address-cells = <1>;
    		#size-cells = <0>;
    		status = "okay";
    		channel@0 {
    			reg = <0>;
    			/* 16.5 ck_cycles sampling time */
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@1 {
    			reg = <1>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@3 {
    			reg = <3>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@5 {
    			reg = <5>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@6 {
    			reg = <6>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@9 {
    			reg = <9>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@10 {
    			reg = <10>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@13 {
    			reg = <13>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@15 {
    			reg = <15>;
    			st,min-sample-time-ns = <5000>;
    		};
    	};
    };

    The U-Boot

    &adc {
    	/* ANA0, ANA1 are dedicated pins and don't need pinctrl: only in6. */
    	pinctrl-names = "default", "sleep";
    	pinctrl-0 = <&adc_pins_mx>;
    	pinctrl-1 = <&adc_sleep_pins_mx>;
    	vdd-supply = <&vdd>;
    	vdda-supply = <&vdda>;
    	vref-supply = <&vdda>;
    	status = "okay";
    	adc1: adc@0 {
    		#address-cells = <1>;
    		#size-cells = <0>;
    		status = "okay";
    		channel@0 {
    			reg = <0>;
    			/* 16.5 ck_cycles sampling time */
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@1 {
    			reg = <1>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@3 {
    			reg = <3>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@5 {
    			reg = <5>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@6 {
    			reg = <6>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@9 {
    			reg = <9>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@10 {
    			reg = <10>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@13 {
    			reg = <13>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@15 {
    			reg = <15>;
    			st,min-sample-time-ns = <5000>;
    		};
    	};
    };

    Finally T-Fa

    &etzpc{
    	status = "okay";
    	st,decprot = <
     /*"Non Secured" peripherals*/
     DECPROT(STM32MP1_ETZPC_ADC_ID, DECPROT_NS_RW, DECPROT_UNLOCK)
     ...
    }
    and
    &rcc{
    ...
    CLK_ADC_PLL4R
    pll4:st,pll@3 {
    	compatible = "st,stm32mp1-pll";
    	reg = <3>;
    	cfg = < 3 98 5 6 5 PQR(1,1,1) >;
    };

    This works for me and maybe will be suitable for someone else.

    Thanks for any help

    Topic can be closed.

    16 replies

    MWoło.2Author
    Visitor II
    March 17, 2023

    When I issue lsmod I get

    Module Size Used by
    cfg80211 626688 0
    usb_f_rndis 24576 2
    u_ether 20480 1 usb_f_rndis
    libcomposite 49152 10 usb_f_rndis
    galcore 520192 0
    dwmac_stm32 16384 0
    stmmac_platform 20480 1 dwmac_stm32
    stm32_adc_core 20480 0
    spi_stm32 24576 0
    stm32_timers 16384 0
    sch_fq_codel 20480 3
    ip_tables 24576 0
    x_tables 24576 1 ip_tables
    ipv6 503808 42

     on dk board, I see something different

    stm32_adc 32768 0
    stm32_timer_trigger 20480 1 stm32_adc
    stm32_lptimer_trigger 16384 1 stm32_adc

    The above means that timers use adc.

    Where I should bind the timer with adc and how?

    Graduate
    March 17, 2023

    I have tried to unload the stm32_adc module and the adc devices were removed to. So try to execute modprobe stm32_adc. If this helps add a stm32-adc.conf to the /etc/modules-load.d/. This could help.

    MWoło.2Author
    Visitor II
    March 17, 2023

    Now I'm able to achieve this

    stm32_adc 32768 0
    stm32_timer_trigger 20480 1 stm32_adc
    stm32_lptimer_trigger 16384 1 stm32_adc

    but after going to "/sys/bus/iio/devices" still empty

    MWoło.2Author
    Visitor II
    March 17, 2023

    on disco I have

    root@stm32mp13-disco:/sys/bus/iio/devices# ls 
     
    iio:device0 

    on my board

    nothing

    MWoło.2Author
    Visitor II
    March 17, 2023

    I just see that I have a snapshot distro

    ST OpenSTLinux - Weston - (A Yocto Project Based Distro) 4.0.4-snapshot

    I try to repo sync and check.

    Graduate
    March 18, 2023

    Can you post dmesg, full device tree and check if there is anything interesting in /proc/device-tree/soc/adc@48003000/?

    MWoło.2Author
    Visitor II
    March 18, 2023

    Hi,

    .../sys/firmware/devicetree/base/soc/adc@48003000/adc@0# ls

    I have

    '#address-cells' compatible interrupt-parent reg
    '#io-channel-cells' dma-names interrupts status
    '#size-cells' dmas name

    MWoło.2AuthorAnswer
    Visitor II
    May 8, 2023

    After some break and rechecking everything I discover a correct dts configuration.

    First I used as reference AVDD(external) and according to this I have configurations like

    The Kernel

    &adc {
    	/* ANA0, ANA1 are dedicated pins and don't need pinctrl: only in6. */
    	pinctrl-names = "default", "sleep";
    	pinctrl-0 = <&adc_pins_mx>;
    	pinctrl-1 = <&adc_sleep_pins_mx>;
    	vdd-supply = <&vdd>;
    	vdda-supply = <&vdda>;
    	vref-supply = <&vdda>;
    	status = "okay";
    	adc1: adc@0 {
    		#address-cells = <1>;
    		#size-cells = <0>;
    		status = "okay";
    		channel@0 {
    			reg = <0>;
    			/* 16.5 ck_cycles sampling time */
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@1 {
    			reg = <1>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@3 {
    			reg = <3>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@5 {
    			reg = <5>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@6 {
    			reg = <6>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@9 {
    			reg = <9>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@10 {
    			reg = <10>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@13 {
    			reg = <13>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@15 {
    			reg = <15>;
    			st,min-sample-time-ns = <5000>;
    		};
    	};
    };

    The U-Boot

    &adc {
    	/* ANA0, ANA1 are dedicated pins and don't need pinctrl: only in6. */
    	pinctrl-names = "default", "sleep";
    	pinctrl-0 = <&adc_pins_mx>;
    	pinctrl-1 = <&adc_sleep_pins_mx>;
    	vdd-supply = <&vdd>;
    	vdda-supply = <&vdda>;
    	vref-supply = <&vdda>;
    	status = "okay";
    	adc1: adc@0 {
    		#address-cells = <1>;
    		#size-cells = <0>;
    		status = "okay";
    		channel@0 {
    			reg = <0>;
    			/* 16.5 ck_cycles sampling time */
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@1 {
    			reg = <1>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@3 {
    			reg = <3>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@5 {
    			reg = <5>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@6 {
    			reg = <6>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@9 {
    			reg = <9>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@10 {
    			reg = <10>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@13 {
    			reg = <13>;
    			st,min-sample-time-ns = <5000>;
    		};
    		channel@15 {
    			reg = <15>;
    			st,min-sample-time-ns = <5000>;
    		};
    	};
    };

    Finally T-Fa

    &etzpc{
    	status = "okay";
    	st,decprot = <
     /*"Non Secured" peripherals*/
     DECPROT(STM32MP1_ETZPC_ADC_ID, DECPROT_NS_RW, DECPROT_UNLOCK)
     ...
    }
    and
    &rcc{
    ...
    CLK_ADC_PLL4R
    pll4:st,pll@3 {
    	compatible = "st,stm32mp1-pll";
    	reg = <3>;
    	cfg = < 3 98 5 6 5 PQR(1,1,1) >;
    };

    This works for me and maybe will be suitable for someone else.

    Thanks for any help

    Topic can be closed.