Skip to main content
Visitor II
September 22, 2025
Question

stm32mp1 sai synchronous slave

  • September 22, 2025
  • 1 reply
  • 581 views

Hi

I have stm32mp157c in my custom board i connect sai2 to codec(tlv320aic), i config sai2a as master (WITHOUT MASTER CLK OUTPUT) and sai2b as synchronous slave, mclk for codec come from rcc mco1 and this is my dts:

 

 

sound {
// compatible = "audio-graph-card", "simple-audio-card";
compatible = "audio-graph-card";
label = "AUDIOcard1";

routing =
"Playback" , "MCLK",
"Capture" , "MCLK";
dais = <&sai2a_port &sai2b_port>;
status = "okay";
};

sai2a:audio-controller@4400b004{
status = "okay";

/* USER CODE BEGIN sai2a */
dma-names = "tx";
// #clock-cells = <0>;
clocks = <&rcc SAI2_K>;
clock-names = "sai_ck";
 
frame-master;
bitclock-master;
 
sai2a_port: port {
sai2a_endpoint: endpoint {
remote-endpoint = <&tlv320_tx_endpoint>;
format = "i2s";
};
};
/* USER CODE END sai2a */
};

sai2b:audio-controller@4400b024{
status = "okay";

/* USER CODE BEGIN sai2b */
dma-names = "rx";
st,sync = <&sai2a 2>; /* Set SAI2B as slave of SAI2A. */

clocks = <&rcc SAI2_K>, <&sai2a>;
clock-names = "sai_ck", "NCLK";
 
sai2b_port: port {
sai2b_endpoint: endpoint {
remote-endpoint = <&tlv320_rx_endpoint>;
format = "i2s";
};
};

codec: tlv320aic32x4@18 {
compatible = "ti,tlv320aic32x4";
reg = <0x18>;
clocks = <&rcc CK_MCO1>;
clock-names = "MCLK";
ldoin-supply = <&v3v3>;
reset-gpios = <&gpioi 0 GPIO_ACTIVE_LOW>;
#sound-dai-cells = <0>;
status = "okay";
port {
#address-cells = <1>;
#size-cells = <0>;
tlv320_tx_endpoint: endpoint@0 {
reg = <0>;
remote-endpoint = <&sai2a_endpoint>;
};
tlv320_rx_endpoint: endpoint@1 {
reg = <1>;
remote-endpoint = <&sai2b_endpoint>;
};
};
 
now my tx path is ok and i can play sound but rx path for capture has some issue when run arecord
board ># arecord -D hw:0,1 -f S16_LE -c 2 -r 44100 -d 5 test.wav
arecord: pcm_read:2151: read error: Input/output error


i see in rx path bitclock and word clock desn't generate (from stm32mp1)
how should i config dts for this situation that can have sai2a as master WITHOUT MASTER CLOCK OUT and sai2b as synchronous slave
i read this thread:
    This topic has been closed for replies.

    1 reply

    ST Employee
    September 23, 2025

    Hello @jacob-sorber,

     

    According to my understanding of your DT, SAI provides FS and SCK, but not MCLK, which is provided by mco1 to the codec : I'am not sure we can consider SAI as master.

     

    I would recommand to move frame-master and bitclock-master under the codec so it is fully master, and keep sai2b as slave of sai2a.

     

    BR,

    Christophe

     

    Visitor II
    September 24, 2025

    Hi 
    I have to use stm32mp1 as (sai2) as master beacause if set codec (tlv320)  as master it need a clock (MCLK) with special frequency that mco1 can't reproduce, (its (tlv320) drvier force mco1 to reproduce a clk and stm32mp1 mco1 can't be set to that value so mp1 hangs)

    also in stm32h7 I  use this codec (tlv320) and connect sai2 and sai is master in tx and rx path  and everything is OK in capture and playback (but in baremetal)