Registered User mNo edit summary |
Registered User mNo edit summary Tag: 2017 source edit |
||
(24 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
<noinclude>{{ApplicableFor | |||
|MPUs list=STM32MP13x, STM32MP15x | |||
|MPUs checklist=STM32MP13x, STM32MP15x, STM32MP25x | |||
}} | |||
</noinclude> | |||
== Article purpose == | == Article purpose == | ||
The purpose of this article is to explain how to configure the [[DFSDM_internal_peripheral|DFSDM internal peripheral]] when the peripheral is assigned to Linux<sup>®</sup> OS''', and in particular: | The purpose of this article is to explain how to configure the [[DFSDM_internal_peripheral|DFSDM internal peripheral]] when the peripheral is assigned to Linux<sup>®</sup> OS''', and in particular: | ||
Line 7: | Line 12: | ||
It is used by the [[DFSDM Linux driver]] which registers the relevant information in [[IIO overview|IIO]] and [[ALSA overview|ALSA]] frameworks. | It is used by the [[DFSDM Linux driver]] which registers the relevant information in [[IIO overview|IIO]] and [[ALSA overview|ALSA]] frameworks. | ||
If the peripheral is assigned to another execution context, refer to [[How to assign an internal peripheral to | If the peripheral is assigned to another execution context, refer to [[How to assign an internal peripheral to an execution context]] article for guidelines on peripheral assignment and configuration. | ||
== DT bindings documentation == | == DT bindings documentation == | ||
The DFSDM maybe used as various functions: ADC and DMIC (for audio). | The DFSDM maybe used as various functions: ADC and DMIC (for audio). | ||
Each one is represented by a separate '''compatible string''', documented | Each one is represented by a separate '''compatible string''', documented in ''STM32 DFSDM device tree bindings''<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.yaml}}, STM32 DFSDM device tree bindings</ref>. | ||
The external analog frontend (e.g. sigma-delta modulator) is documented | The external analog frontend (e.g. sigma-delta modulator) is documented in ''Device-Tree bindings for sigma delta modulator''<ref name="sd-modulator">{{CodeSource | Linux kernel | Documentation/devicetree/bindings/iio/adc/sigma-delta-modulator.yaml}}, Generic Device-Tree bindings for sigma delta modulator</ref> | ||
== DT configuration == | == DT configuration == | ||
Line 26: | Line 28: | ||
===DT configuration (STM32 level) === | ===DT configuration (STM32 level) === | ||
DFSDM nodes are declared in stm32mp151.dtsi<ref name="stm32mp151.dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp151.dtsi}}, STM32MP151 device tree file</ref>. | DFSDM nodes are declared in stm32mp151.dtsi<ref name="stm32mp151.dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp151.dtsi}}, STM32MP151 device tree file</ref> for {{MicroprocessorDevice | device=15}}, and stm32mp131.dtsi<ref name="stm32mp131.dtsi">{{CodeSource | Linux kernel | arch/arm/boot/dts/stm32mp131.dtsi}}, STM32MP131 device tree file</ref> for {{MicroprocessorDevice | device=13}}. | ||
* DT root node ('dfsdm') describes the ADC hardware block parameters such as registers area, clocks. | * DT root node ('dfsdm') describes the ADC hardware block parameters such as registers area, clocks. | ||
Line 48: | Line 50: | ||
Configure the 'dfsdm' '''DT root node''': | Configure the 'dfsdm' '''DT root node''': | ||
* Enable the DT root node for the DFSDM, by setting '''status = "okay"'''. | * Enable the DT root node for the DFSDM, by setting '''status = "okay"'''. | ||
* Configure the pins in use via [[Pinctrl overview|pinctrl]], by setting '''pinctrl-0''', '''pinctrl-1''' and '''pinctrl-names'''. | * [[Pinctrl device tree configuration|Configure the pins]] in use via [[Pinctrl overview|pinctrl]], by setting '''pinctrl-0''', '''pinctrl-1''' and '''pinctrl-names'''. | ||
* Configure the SPI clock output frequency, by setting '''spi-max-frequency''' (optional: only for SPI master mode). | * Configure the SPI clock output frequency, by setting '''spi-max-frequency''' (optional: only for SPI master mode). | ||
* Configure the audio clock to be used, by setting '''clocks''' and '''clock-names''' (optional: to use more accurate clock for audio). | * Configure the audio clock to be used, by setting '''clocks''' and '''clock-names''' (optional: to use more accurate clock for audio). | ||
{ | |||
&dfsdm { | |||
pinctrl-names = "default", "sleep"; | |||
pinctrl-0 = <&dfsdm_clkout_pins_a &dfsdm_data1_pins_a>; /* default pins */ | |||
pinctrl-1 = <&dfsdm_clkout_sleep_pins_a &dfsdm_data1_sleep_pins_a>; /* sleep pins for low-power mode */ | |||
spi-max-frequency = <2048000>; /* desired maximum clock rate */ | |||
clocks = <&rcc DFSDM_K>, {{highlight|<&rcc ADFSDM_K>}}; | |||
clock-names = "dfsdm", {{highlight|"audio"}}; | |||
status = "okay"; | |||
}; | |||
==== Private resources for each DFSDM filter ==== | ==== Private resources for each DFSDM filter ==== | ||
Line 72: | Line 83: | ||
=== DT configuration examples === | === DT configuration examples === | ||
==== DFSDM ADC DT configuration example ==== | |||
The example below shows how to configure the DFSDM ADC channel 1, assigned to DFSDM filter 0: | The example below shows how to configure the DFSDM ADC channel 1, assigned to DFSDM filter 0: | ||
* Add sd-modulator<ref name="sd-modulator"/> in the board dts file. | * Add sd-modulator<ref name="sd-modulator"/> in the board dts file. | ||
{{highlight|sd_adc1}}: adc-1 { | {{highlight|sd_adc1}}: adc-1 { | ||
Line 109: | Line 94: | ||
* Configure and enable DFSDM, configure {{highlight|channel 1}} to use SPI (rising edge), associate it to {{highlight|filter0}}. | * Configure and enable DFSDM, configure {{highlight|channel 1}} to use SPI (rising edge), associate it to {{highlight|filter0}}. | ||
&dfsdm { | &dfsdm { | ||
/* Also configure [[DFSDM_device_tree_configuration#Common_resources_for_all_DFSDM_filters|common resources for all DFSDM filters]] */ | |||
{{highlight|dfsdm0: filter@0}} { | {{highlight|dfsdm0: filter@0}} { | ||
st,adc-channels = <{{highlight|1}}>; /* Assign channel 1 to this filter */ | st,adc-channels = <{{highlight|1}}>; /* Assign channel 1 to this filter */ | ||
Line 124: | Line 105: | ||
}; | }; | ||
}; | }; | ||
==== DFSDM audio DT configuration example ==== | |||
In this example two microphones are multiplexed on the same DFSDM input line. One microphone is sampled on the SPI clock rising edges, and the other on the SPI clock falling edges. By convention the rising edge corresponds to the left channel and the falling edge to the right channel. | |||
The '''st,adc-channel-types''' property allows to select either the left or the right channel on the input data line. | |||
A channel y is connected to both the input lines DATAy and DATAy+1. For each channel, an input selector allows to select either the data from DATAy or DATAy+1 input line. The '''st,adc-alt-channel''' DT property is used to configure this channel input selector. Refer to the DFSDM "Serial channel transceivers" chapter of the [[STM32MP15 resources#Reference manuals|STM32MP15 reference manuals]] for more details on the channel input selection. | |||
* st,adc-alt-channel <nowiki>= <0></nowiki> the '''channel x''' is fed by the input line '''DATAx''' | |||
* st,adc-alt-channel <nowiki>= <1></nowiki> the channel y is fed by the input line DATAy+1. If y=x-1, the '''channel x-1''' is fed by the input line '''DATAx''' | |||
The following device tree sample is an extraction of the [[Soundcard_configuration#Static_configuration_2|STM32MP15 evaluation board device tree]], highlighting the channels configuration for multiplexed data on input line. In this exemple the '''input line DATA1''' provides the left audio samples to the '''channel 1''' and the right audio samples to the '''channel 0'''. | |||
&dfsdm { | |||
/* Also configure [[DFSDM_device_tree_configuration#Common_resources_for_all_DFSDM_filters|common resources for all DFSDM filters]] */ | |||
dfsdm1: filter@1 { | |||
st,adc-channels = <0>; /* Use {{highlight|channel 0}} fed by mic U2 signal wired to {{highlight|input 1}} */ | |||
st,adc-alt-channel = <1>; /* {{highlight|Connect channel 0 to next input (input 1)}} */ | |||
st,adc-channel-types = "SPI_F"; /* mic U2 signal available on {{highlight|input 1 Falling edge (Right channel) }} */ | |||
}; | |||
dfsdm3: filter@3 { | |||
st,adc-channels = <1>; /* Use {{highlight|channel 1}} fed by mic U4 signal wired to {{highlight|input 1}} */ | |||
st,adc-alt-channel = <0>; /* Optional as set to 0 by default */ | |||
st,adc-channel-types = "SPI_R"; /* mic U4 signal available on {{highlight|input 1 Rising edge (Left channel) }} */ | |||
}; | |||
}; | |||
Refer to [[Soundcard_configuration#Static_configuration_2|STM32MP15 evaluation board device tree]] for the full DFSDM audio device tree configuration example. | |||
==How to configure the DT using STM32CubeMX== | ==How to configure the DT using STM32CubeMX== | ||
The [[STM32CubeMX]] tool can be used to configure the STM32MPU device and get the corresponding [[Device_tree# | The [[STM32CubeMX]] tool can be used to configure the STM32MPU device and get the corresponding [[Device_tree#STM32_MPU|platform configuration device tree]] files.<br /> | ||
The STM32CubeMX may not support all the properties described in the above [[#DT bindings documentation|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. | The STM32CubeMX may not support all the properties described in the above [[#DT bindings documentation|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. | ||
Revision as of 14:09, 5 June 2024
1. Article purpose[edit | edit source]
The purpose of this article is to explain how to configure the DFSDM internal peripheral when the peripheral is assigned to Linux® OS, and in particular:
- How to configure the DFSDM peripheral to enable filters and associated channels
- How to configure the board, e.g. serial interface input/output pins
The configuration is performed using the device tree mechanism.
It is used by the DFSDM Linux driver which registers the relevant information in IIO and ALSA frameworks.
If the peripheral is assigned to another execution context, refer to How to assign an internal peripheral to an execution context article for guidelines on peripheral assignment and configuration.
2. DT bindings documentation[edit | edit source]
The DFSDM maybe used as various functions: ADC and DMIC (for audio).
Each one is represented by a separate compatible string, documented in STM32 DFSDM device tree bindings[1].
The external analog frontend (e.g. sigma-delta modulator) is documented in Device-Tree bindings for sigma delta modulator[2]
3. DT configuration[edit | edit source]
This hardware description is a combination of STM32 microprocessor and board device tree files. See Device tree for more explanations on device tree file split.
The STM32CubeMX can be used to generate the board device tree. Refer to How to configure the DT using STM32CubeMX for more details.
3.1. DT configuration (STM32 level)[edit | edit source]
DFSDM nodes are declared in stm32mp151.dtsi[3] for STM32MP15x lines , and stm32mp131.dtsi[4] for STM32MP13x lines .
- DT root node ('dfsdm') describes the ADC hardware block parameters such as registers area, clocks.
- DT child nodes ('dfsdm0', 'dfsdm1', ...) describe each filter independently: compatible string, interrupts, DMAs.
/* common resources in 'dfsdm' root node. */ dfsdm0: filter@0 { compatible = "st,stm32-dfsdm-adc"; /* can either be st,stm32-dfsdm-(adc or dmic) */ ... /* private resources in 'dfsdm0' child node. */ } dfsdm1: filter@1 { ... }dfsdm: dfsdm@4400d000 { compatible = "st,stm32mp1-dfsdm"; ...
This device tree part is related to STM32 microprocessors. It should be kept as is, without being modified by the end-user. |
3.2. DT configuration (board level)[edit | edit source]
Follow the sequences described in the below chapters to configure and enable the DFSDM on your board.
3.2.1. Common resources for all DFSDM filters[edit | edit source]
Configure the 'dfsdm' DT root node:
- Enable the DT root node for the DFSDM, by setting status = "okay".
- Configure the pins in use via pinctrl, by setting pinctrl-0, pinctrl-1 and pinctrl-names.
- Configure the SPI clock output frequency, by setting spi-max-frequency (optional: only for SPI master mode).
- Configure the audio clock to be used, by setting clocks and clock-names (optional: to use more accurate clock for audio).
DFSDM_K>, <&rcc ADFSDM_K>; clock-names = "dfsdm", "audio"; status = "okay"; };&dfsdm { pinctrl-names = "default", "sleep"; pinctrl-0 = <&dfsdm_clkout_pins_a &dfsdm_data1_pins_a>; /* default pins */ pinctrl-1 = <&dfsdm_clkout_sleep_pins_a &dfsdm_data1_sleep_pins_a>; /* sleep pins for low-power mode */ spi-max-frequency = <2048000>; /* desired maximum clock rate */ clocks = <&rcc
3.2.2. Private resources for each DFSDM filter[edit | edit source]
Configure the filter(s) DT child node(s):
- Enable the DT child node(s) for the DFSDM filter(s) in use, by setting status = "okay".
- Override the compatible string by setting "st,stm32-dfsdm-dmic" (optional: only for audio digital microphone).
- Enable the channel(s), by setting st,adc-channels = <0 1 2...>.
- Configure the channel(s) by setting st,adc-channel-names, st,adc-channel-types (e.g. SPI or manchester) and st,adc-channel-clk-src (e.g. external or internal).
- Configure the filter order, by setting st,filter-order.
3.2.3. Additional configuration for DFSDM ADC[edit | edit source]
The DFSDM ADC device has an external analog front-end, the sigma delta modulator.
Configure the external sigma delta modulator for each channel (optional, not needed for audio digital microphone):
- Add your_sd_modulator DT node in the board dts file (see the generic sd-modulator[2] example here after).
- Add io-channels = <&your_sd_modulator> to the DFSDM filter child node in order to assign it to the filter channel(s).
3.2.4. Additional configuration for DFSDM audio[edit | edit source]
Additional child nodes must be added for audio soundcard configuration.
3.3. DT configuration examples[edit | edit source]
3.3.1. DFSDM ADC DT configuration example[edit | edit source]
The example below shows how to configure the DFSDM ADC channel 1, assigned to DFSDM filter 0:
- Add sd-modulator[2] in the board dts file.
sd_adc1: adc-1 { compatible = "sd-modulator"; #io-channel-cells = <0>; };
- Configure and enable DFSDM, configure channel 1 to use SPI (rising edge), associate it to filter0.
common resources for all DFSDM filters */ dfsdm0: filter@0 { st,adc-channels = <1>; /* Assign channel 1 to this filter */ st,adc-channel-names = "in1"; /* Give it a name */ st,adc-channel-types = "SPI_R"; /* SPI data on rising edge */ st,adc-channel-clk-src = "CLKOUT_F"; /* internal clock source used for conversion */ io-channels = <&sd_adc1>; /* phandle to the external sd-modulator */ st,filter-order = <1>; status = "okay"; }; };&dfsdm { /* Also configure
3.3.2. DFSDM audio DT configuration example[edit | edit source]
In this example two microphones are multiplexed on the same DFSDM input line. One microphone is sampled on the SPI clock rising edges, and the other on the SPI clock falling edges. By convention the rising edge corresponds to the left channel and the falling edge to the right channel. The st,adc-channel-types property allows to select either the left or the right channel on the input data line.
A channel y is connected to both the input lines DATAy and DATAy+1. For each channel, an input selector allows to select either the data from DATAy or DATAy+1 input line. The st,adc-alt-channel DT property is used to configure this channel input selector. Refer to the DFSDM "Serial channel transceivers" chapter of the STM32MP15 reference manuals for more details on the channel input selection.
- st,adc-alt-channel = <0> the channel x is fed by the input line DATAx
- st,adc-alt-channel = <1> the channel y is fed by the input line DATAy+1. If y=x-1, the channel x-1 is fed by the input line DATAx
The following device tree sample is an extraction of the STM32MP15 evaluation board device tree, highlighting the channels configuration for multiplexed data on input line. In this exemple the input line DATA1 provides the left audio samples to the channel 1 and the right audio samples to the channel 0.
common resources for all DFSDM filters */ dfsdm1: filter@1 { st,adc-channels = <0>; /* Use channel 0 fed by mic U2 signal wired to input 1 */ st,adc-alt-channel = <1>; /* Connect channel 0 to next input (input 1) */ st,adc-channel-types = "SPI_F"; /* mic U2 signal available on input 1 Falling edge (Right channel) */ }; dfsdm3: filter@3 { st,adc-channels = <1>; /* Use channel 1 fed by mic U4 signal wired to input 1 */ st,adc-alt-channel = <0>; /* Optional as set to 0 by default */ st,adc-channel-types = "SPI_R"; /* mic U4 signal available on input 1 Rising edge (Left channel) */ }; };&dfsdm { /* Also configure
Refer to STM32MP15 evaluation board device tree for the full DFSDM audio device tree configuration example.
4. How to configure the DT using STM32CubeMX[edit | edit source]
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.
5. References[edit | edit source]
Please refer to the following links for additional information:
- ↑ Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.yaml , STM32 DFSDM device tree bindings
- ↑ Jump up to: 2.0 2.1 2.2 Documentation/devicetree/bindings/iio/adc/sigma-delta-modulator.yaml , Generic Device-Tree bindings for sigma delta modulator
- ↑ arch/arm/boot/dts/stm32mp151.dtsi , STM32MP151 device tree file
- ↑ arch/arm/boot/dts/stm32mp131.dtsi , STM32MP131 device tree file