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

    Technical Moderator
    March 17, 2023

    Hi MWoło.2 (Community Member)

    According to https://www.kernel.org/doc/Documentation/devicetree/bindings/iio/iio-bindings.txt

    It seems that you may have missed the #io-channel-cells = <1>; property in the ADC node.

    from : linux-5.15.67/arch/arm/boot/dts/stm32mp151.dtsi

            adc: adc@48003000 {

                compatible = "st,stm32mp1-adc-core";

                reg = <0x48003000 0x400>;

    ...

                adc1: adc@0 {

                    compatible = "st,stm32mp1-adc";

                    #io-channel-cells = <1>;

    ...

    Regards,

    Olivier

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

    Hi OlivierK,

    thanks for the hint, unfortunately, it doesn't work. It is curious to that my configuration works for the DK2 board, in DK2 I see iio devices. The difference between my custom and dk2 is that dk2 not uses cube mx.

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

    In my opinion, the system doesn't bind adc driver with iio. How to force the system to bind adc with iio?

    Technical Moderator
    March 17, 2023

    Hi MWoło.2 (Community Member)

    Regarding the bindings, you can use CubeMx and generate MP15-DK2 dts and compare with your settings. Normally if the IIO is enabled in the kernel I don't see why it shouldn't work.

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

    OK,

    let's compare

    after issue

    grep -H "" /sys/bus/iio/devices/*/name | grep adc 

    I get on my board

    grep: /sys/bus/iio/devices/*/name: No such file or directory

    and on disco

    /sys/bus/iio/devices/iio:device0/name:48003000.adc:adc@0

    What do the above means? If I get "No such file ...." it means not configured something in the kernel config or missing something in dts?

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

    The configuration of both board

    0693W00000aJDsSQAW.png0693W00000aJDrKQAW.pngI can't find only the U-Boot drivers

    0693W00000aJDusQAG.pngDo U-Boot configuration (dts+driver) significant?

    Technical Moderator
    March 17, 2023

    Hi MWoło.2 (Community Member)

    What about the diff between CubeMX DTS generation for the MP15-DK2 vs your board?

    Graduate
    March 17, 2023

    Hi,

    you can try something like this

    &adc1 {
    	st,min-sample-time-nsecs = <10000000>;
     
    	st,adc-channels = <9 19>;
    	assigned-resolution-bits = <12>;
    	status = "okay";
    };

    This works for me on STe4.1.

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

    ok I try, thanks

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

    Unfortunately, the result is the same. But I have an additional question. After writing my new image to sd card or in my case emmc what I should do after the first login? Maybe here is the problem, maybe additional configuration is needed?