“ADC Linux driver”的版本间的差异

来自百问网嵌入式Linux wiki
 
 
(未显示2个用户的12个中间版本)
第1行: 第1行:
[[Category:Linux_Operating_System]][[Category:Analog]][[Category:IIO]]
+
== Article purpose ==
 +
本文介绍了用于ADC <ref name="ADC internal peripheral">[[ADC internal peripheral]]</ref>内部外围设备的Linux<sup>&reg;</sup>驱动程序:
 +
* 驱动程序支持哪些ADC功能
 +
* 如何配置,使用和调试驱动程序
 +
* 驱动程序的结构是什么,以及在哪里可以找到源代码。
 +
 
 +
== Short description ==
 +
ADC Linux<sup>&reg;</sup>驱动程序(内核空间)基于 [[IIO overview|IIO]] 框架。
 +
它支持两种模式:
 +
# '''IIO直接模式''':在通道上单次捕获(使用中断)
 +
# '''IIO触发缓冲模式''':在一个或多个通道上捕获(最好使用DMA)。<br/>它使用IIO中提供的硬件触发器。 请参阅[[TIM Linux driver]] and [[LPTIM Linux driver]].
 +
 
 +
== Configuration ==
 +
=== Kernel configuration ===
 +
使用Linux Menuconfig工具在内核配置中激活ADC <ref name="ADC internal peripheral"/> Linux<sup>&reg;</sup> 驱动程序: [[Menuconfig or how to configure kernel]] (同时启用CONFIG_STM32_ADC_CORE和CONFIG_STM32_ADC).
 +
<pre>
 +
Device Drivers  --->
 +
  <*> Industrial I/O support  --->
 +
      Analog to digital converters  --->
 +
        <*> STMicroelectronics STM32 adc core
 +
        <*>  STMicroelectronics STM32 adc
 +
</pre>
 +
 
 +
=== Device tree ===
 +
在配置ADC Linux内核驱动程序时,请参考[[ADC device tree configuration]] 文章。
 +
 
 +
== How to use ==
 +
在“'''IIO直接模式'''”中,可以直接从'''sysfs'''读取转换结果 (请参阅
 +
[[How to use the IIO user space interface#How to do a simple ADC conversion using the sysfs interface|How to do a simple ADC conversion using the sysfs interface]]).
 +
 
 +
在“'''IIO触发缓冲区模式'''”中,必须先使用'''sysfs'''执行配置。 然后,使用“字符设备”(/ dev / iio:deviceX)读取数据 (请参阅[[How to use the IIO user space interface#Convert one or more channels using triggered buffer mode|Convert one or more channels using triggered buffer mode]]).
 +
 
 +
== How to trace and debug ==
 +
请参阅[[IIO_overview#How_to_trace_with_dynamic_debug|How to trace with dynamic debug]] ,以了解如何在驱动程序和框架中“启用调试日志”。
 +
请参阅 [[IIO_overview#How_to_debug_with_debugfs|How to debug with debugfs]],以了解如何“''访问ADC寄存器”。
 +
 
 +
ADC对其他关键资源具有系统范围的依赖性:
 +
* 可以禁用'''运行时电源管理''',例如,可以通过“ power / control” sysfs条目将其强制为'''on'''。
 +
{{Board$}} cd /sys/devices/platform/soc/48003000.adc/48003000.adc:adc@0
 +
{{Board$}} cat power/autosuspend_delay_ms
 +
2000
 +
{{Board$}} cat power/control
 +
auto                                    # kernel is allowed to automatically suspend the ADC device after autosuspend_delay_ms
 +
{{Board$}} {{highlight|echo on > power/control}}        # force the kernel to resume the ADC device (e.g. keep clocks and regulators enabled)
 +
{{Info| 禁用运行时电源管理可能很有用,以便通过任何方式转储寄存器或检查时钟和调节器的使用情况(请参见下面的示例)。}}
 +
 
 +
* 可以通过阅读“ clk_summary”来验证'''clock'''<ref name="Clock overview">[[Clock overview]]</ref> 的使用情况:
 +
{{Board$}} {{highlight|cat /sys/kernel/debug/clk/clk_summary}} | grep adc
 +
          adc12_k                    1        1        0    24000000          0 0
 +
                  adc12              1        1        0  196607910          0 0
 +
 
 +
* '''regulator'''<ref name="Regulator overview">[[Regulator overview]]</ref> 树和用法可以通过以下方式进行验证(例如,使用计数,开路计数或调节器参考电压):
 +
{{Board$}} {{highlight|cat /sys/kernel/debug/regulator/regulator_summary}}
 +
  regulator                      use open bypass voltage current    min    max
 +
-------------------------------------------------------------------------------
 +
    v3v3                          4    5      0  3300mV    0mA  3300mV  3300mV
 +
        vdda                      1    2      0  2900mV    0mA  2900mV  2900mV
 +
          40017000.dac                                              0mV    0mV
 +
          48003000.adc                                              0mV    0mV
 +
 
 +
* '''pinctrl'''<ref name="Pinctrl_overview">[[Pinctrl overview]]</ref> 可以通过阅读“ pinmux-pins”来验证用法:
 +
{{Board$}} cd /sys/kernel/debug/pinctrl/soc\:pin-controller@50002000/
 +
{{Board$}} {{highlight|cat pinmux-pins}} | grep adc
 +
pin 92 (PF12): device 48003000.adc function {{highlight|analog}} group PF12  # check pin is assigned to ADC and is configured as "analog"
 +
 
 +
* 可以通过阅读'''interrupts'''来验证“ interrupts”:
 +
{{Board$}} {{highlight|cat /proc/interrupts}}
 +
            CPU0      CPU1
 +
  56:          2          0    dummy  0 Edge      48003000.adc:adc@0
 +
 
 +
== Source code location ==
 +
ADC源代码包括:
 +
* {{CodeSource | Linux kernel | drivers/iio/adc/stm32-adc-core.c | stm32-adc-core driver}}来处理诸如时钟(选择,预分频器),用作参考电压的[[Regulator overview|regulator]] 等通用资源,中断和通用寄存器。
 +
* {{CodeSource | Linux kernel | drivers/iio/adc/stm32-adc.c | stm32-adc driver}} 来处理每个ADC可用的资源,例如通道配置和缓冲区处理。
 +
 
 +
==References==
 +
<references />

2020年11月9日 (一) 11:28的最新版本

Article purpose

本文介绍了用于ADC [1]内部外围设备的Linux®驱动程序:

  • 驱动程序支持哪些ADC功能
  • 如何配置,使用和调试驱动程序
  • 驱动程序的结构是什么,以及在哪里可以找到源代码。

Short description

ADC Linux®驱动程序(内核空间)基于 IIO 框架。 它支持两种模式:

  1. IIO直接模式:在通道上单次捕获(使用中断)
  2. IIO触发缓冲模式:在一个或多个通道上捕获(最好使用DMA)。
    它使用IIO中提供的硬件触发器。 请参阅TIM Linux driver and LPTIM Linux driver.

Configuration

Kernel configuration

使用Linux Menuconfig工具在内核配置中激活ADC [1] Linux® 驱动程序: Menuconfig or how to configure kernel (同时启用CONFIG_STM32_ADC_CORE和CONFIG_STM32_ADC).

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

Device tree

在配置ADC Linux内核驱动程序时,请参考ADC device tree configuration 文章。

How to use

在“IIO直接模式”中,可以直接从sysfs读取转换结果 (请参阅 How to do a simple ADC conversion using the sysfs interface).

在“IIO触发缓冲区模式”中,必须先使用sysfs执行配置。 然后,使用“字符设备”(/ dev / iio:deviceX)读取数据 (请参阅Convert one or more channels using triggered buffer mode).

How to trace and debug

请参阅How to trace with dynamic debug ,以了解如何在驱动程序和框架中“启用调试日志”。 请参阅 How to debug with debugfs,以了解如何“访问ADC寄存器”。

ADC对其他关键资源具有系统范围的依赖性:

  • 可以禁用运行时电源管理,例如,可以通过“ power / control” sysfs条目将其强制为on
Board $> cd /sys/devices/platform/soc/48003000.adc/48003000.adc:adc@0
Board $> cat power/autosuspend_delay_ms
2000
Board $> cat power/control
auto                                     # kernel is allowed to automatically suspend the ADC device after autosuspend_delay_ms
Board $> echo on > power/control         # force the kernel to resume the ADC device (e.g. keep clocks and regulators enabled)
Info.png 禁用运行时电源管理可能很有用,以便通过任何方式转储寄存器或检查时钟和调节器的使用情况(请参见下面的示例)。
  • 可以通过阅读“ clk_summary”来验证clock[2] 的使用情况:
Board $> cat /sys/kernel/debug/clk/clk_summary | grep adc
         adc12_k                     1        1        0    24000000          0 0
                  adc12              1        1        0   196607910          0 0
  • regulator[3] 树和用法可以通过以下方式进行验证(例如,使用计数,开路计数或调节器参考电压):
Board $> cat /sys/kernel/debug/regulator/regulator_summary
 regulator                      use open bypass voltage current     min     max
-------------------------------------------------------------------------------
    v3v3                          4    5      0  3300mV     0mA  3300mV  3300mV
       vdda                       1    2      0  2900mV     0mA  2900mV  2900mV 
          40017000.dac                                              0mV     0mV
          48003000.adc                                              0mV     0mV
  • pinctrl[4] 可以通过阅读“ pinmux-pins”来验证用法:
Board $> cd /sys/kernel/debug/pinctrl/soc\:pin-controller@50002000/
Board $> cat pinmux-pins | grep adc
pin 92 (PF12): device 48003000.adc function analog group PF12   # check pin is assigned to ADC and is configured as "analog"
  • 可以通过阅读interrupts来验证“ interrupts”:
Board $> cat /proc/interrupts
           CPU0       CPU1
 56:          2          0     dummy   0 Edge      48003000.adc:adc@0

Source code location

ADC源代码包括: