ADC device tree configuration

来自百问网嵌入式Linux wiki
Wiki讨论 | 贡献2020年11月9日 (一) 14:25的版本 →‎DT configuration

Article purpose

本文的目的是解释在将外围设备分配给Linux® OS时如何配置模数转换器(“ ADC”)[1]

  • 如何配置ADC外围设备
  • 如何配置board,例如 ADC参考电压调节器,通道,引脚和采样时间。

使用设备树机制执行配置[2].

ADC Linux driver 使用它在 IIO framework中注册相关信息,例如每个ADC的IIO设备,通道和电压标度。

如果外围设备已分配给另一个执行上下文,请参阅 How to assign an internal peripheral to a runtime context 文章,以获取有关外围设备分配和配置的准则。

DT bindings documentation

"STM32 ADC设备树绑定"[3] 描述所有必需和可选功能。

DT configuration

该硬件描述是STM32微处理器和电路板设备树文件的组合。 有关设备树文件分割的更多说明,请参见Device treeSTM32CubeMX可用于生成板卡设备树。 有关更多详细信息,请参考 How to configure the DT using STM32CubeMX

ADC common resources ADC common resources ADC common resources ADC private resources ADC private resources Regulator Pinctrl How to setup TIM or LPTIM triggers
ADC DT configuration

DT configuration (STM32 level)

ADC节点在stm32mp157c.dtsi中声明[4].

  • DT root node ('adc') describes the ADC hardware block parameters such as register areas, clocks and interrupts.
  • DT child nodes ('adc1' and 'adc2') describe ADC1 and ADC2 independently.
adc: adc@address {
	compatible = "st,stm32mp1-adc-core";
	...                                      /* common resources in 'adc' root node. */
	adc1: adc@0 {
		compatible = "st,stm32mp1-adc";
		...                              /* private resources in 'adc1' child node. */
	};
	adc2: adc@100 {
		compatible = "st,stm32mp1-adc";
		...                              /* private resources in 'adc2' child node. */
	};
};
Warning.png This device tree part is related to STM32 microprocessors. It must be kept as is, without being modified by the end-user.

DT configuration (board level)

Follow the sequences described in the below chapters to configure and enable the ADC on your board.

Common resources for all ADCs

The DT root node ('adc') must be filled in:

  • Enable the ADC block by setting status = "okay".
  • Configure the pins in use via pinctrl, through pinctrl-0 and pinctrl-names.
  • Configure the analog supply voltage regulator[5] by setting vdda-supply = <&your_vdda_regulator>.
  • Configure the analog reference voltage regulator[5] by setting vref-supply = <&your_vref_regulator>.
Info.png The ADC can use the internal VREFBUF[6] or any other external regulator[5] wired to VREF+ pin.

Resources dedicated to ADC1 and ADC2

The DT child nodes ('adc1' and/or 'adc2') must be filled in:

  • Enable 'adc1' and/or 'adc2' by setting status = "okay".
  • Enable single-ended channel(s) (<vinp...>) by setting st,adc-channels = <0 1 2...>.
  • Enable differential channel(s) pairs (<vinp vinn>, ...) by setting st,adc-diff-channels = <1 0>, <2 6>, ....
  • Set the minimum sampling time [7] for each or all channels by setting st,min-sample-time-nsecs = <10000> (optional).
  • Set the resolution by setting assigned-resolution-bits = <12> (optional).

DT configuration example

The example below shows how to configure ADC1:

  • Input pin: use Pinctrl device tree configuration to configure PF12 as analog input.
  • Analog supply: it is provided by one of the PMIC LDO regulators.
  • Voltage reference: it is provided by the VREFBUF internal regulator.
  • Input channel: configure ADC1_IN6 (e.g on PF12).
  • Sampling time: the minimum sampling time is 10 µs.
# part of pin-controller dt node
adc1_in6_pins_a: adc1-in6 {
	pins {
		pinmux = <STM32_PINMUX('F', 12, ANALOG)>; /* configure 'PF12' as ANALOG */
	};
};
&adc {
	/* ADC1 & ADC2 common resources */
	pinctrl-names = "default";
	pinctrl-0 = <&adc1_in6_pins_a>;              /* Use PF12 pin as ANALOG */
	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) */
	status = "okay";                             /* Enable ADC12 block */
	adc1: adc@0 {
		/* private resources for ADC1 */
		st,adc-channels = <6>;               /* ADC1 in6 channel is used */
		st,min-sample-time-nsecs = <10000>;  /* 10µs sampling time */
		status = "okay";                     /* Enable ADC1 */
	};
	adc2: adc@100 {
		/* private resources for ADC2 */
		...
	};
};

How to configure the DT using STM32CubeMX

The STM32CubeMX tool can be used to configure the STM32MPU device and get the corresponding platform configuration device tree files.
The STM32CubeMX may not support all the properties described in the above DT bindings documentation paragraph. If so, the tool inserts user sections in the generated device tree. These sections can then be edited to add some properties and they are preserved from one generation to another. Refer to STM32CubeMX user manual for further information.