1. Article purpose[edit source]
This article explains how to configure the SPI/I2S internal peripheral when it is assigned to the Linux® OS. In that case, it is controlled by the ALSA framework.
The configuration is performed using the device tree mechanism that provides a hardware description of the I2S peripheral, used by the I2S linux driver.
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 source]
STM32 I2S device tree bindings [1] describes all the required and optional configuration properties.
3. DT configuration[edit source]
This hardware description is a combination of STM32 microprocessor [2] and board device tree files. See the Device tree for an explanation of the device tree file split.
STM32CubeMX can be used to generate the board device tree. Refer to How to configure the DT using STM32CubeMX for more details.
3.1. I2S clocks configuration[edit source]
Information |
The I2S peripheral parent clock may not be exactly a multiple of the audio stream rate. A debug trace can be enabled in the I2S Linux driver, to report the clock rate accuracy. A deviation of 1000 ppm, on the audio stream frequency, might be considered acceptable for most people. |
3.1.1. On STM32MP1 series[edit source]
Two parent clocks referred as "x8k" and "x11k", have to be declared for the I2S kernel clock:
- The "x8k" clock must be a multiple of 8kHz
- The "x11k" clock must be a multiple of 11.025kHz
One of these two clocks is selected at run-time through the I2S clock mux, depending on the requested audio stream sampling rate.
3.1.2. On STM32MP2 series[edit source]
The I2S driver uses a single parent clock for its kernel clock. At run-time, the I2S driver configures the rate of the parent clock, to the highest multiple frequency of the audio stream sampling rate.
3.2. DT configuration (STM32 level)[edit source]
This device tree describes the hardware parameters such as register addresses, interrupt, clock, and DMA. This set of properties may not vary for a given STM32MPU.
On STM32MP13x lines , the I2S nodes are declared in stm32mp131.dtsi[3].
On STM32MP15x lines , the I2S nodes are declared in stm32mp151.dtsi[4].
On STM32MP25x lines , the I2S nodes are declared in stm32mp251.dtsi[5].
3.3. DT configuration (board level)[edit source]
The I2S is an audio peripheral, which can be used as a component of a soundcard through Linux® kernel ALSA framework. This part of the device tree allows the configuration of the I2S to implement a soundcard. Refer to soundcard configuration for examples of I2S configuration for various boards.
3.4. DT configuration examples[edit source]
3.4.1. Setting I2S as a master clock provider[edit source]
The I2S peripheral can provide a clock to a codec through the MCLK output pin. In this case, it acts as master clock provider. The below DT sample gives an example of I2S configuration as a master clock provider.
&i2s2 { ... i2s2: audio-controller@4000b000 { #clock-cells = <0>; /* Set I2S2 as master clock provider */ ... i2s2_endpoint: endpoint { mclk-fs = <256>; /* Set mclk/fs ratio. (256 or 512) */ }; }; };
The codec has to be declared as a consumer of the I2S MCLK provider, in the Device Tree.
codec: { clocks = <&i2s2>; /* The codec is a consumer of I2S2 master clock */ clock-names = "MCLK"; /* Feed MCLK codec clock with I2S2 master clock provider */ ... };
Then as a consumer of the MCLK clock, the codec driver can enable the clock using the clock framework API.
An alternative is to enable the MCLK clock dynamically at runtime, using the ASoC DAPM mechanism. In this case the codec driver has to implement a DAPM clock supply widget through SND_SOC_DAPM_SUPPLY macro. An example of such DAPM widget can be found in Cirrus CS42L51 codec source code[6]. To allow MCLK activation/deactivation, DAPM routes must also be defined in the DT, between MCLK and audio stream widgets. These routes are defined in the sound card node, as shown below.
soundcard { routing = "Playback" , "MCLK", /* Set a route between "MCLK" and "playback" DAPM widgets */ "Capture" , "MCLK"; /* Set a route between "MCLK" and "capture" DAPM widgets */ ... };
4. How to configure the DT using STM32CubeMX[edit source]
The STM32CubeMX tool can be used to configure the STM32MPU device and get the corresponding platform configuration device tree files.
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 are preserved from one generation to another. Refer to the STM32CubeMX user manual for further information.
5. References[edit source]