32. Serial audio interface (SAI)

32.1 Introduction

The SAI interface (serial audio interface) offers a wide set of audio protocols due to its flexibility and wide range of configurations. Many stereo or mono audio applications may be targeted. I2S standards, LSB or MSB-justified, PCM/DSP, TDM, and AC'97 protocols may be addressed for example. SPDIF output is offered when the audio block is configured as a transmitter.

To bring this level of flexibility and reconfigurability, the SAI contains two independent audio subblocks. Each block has its own clock generator and I/O line controller.

The SAI works in master or slave configuration. The audio subblocks are either receiver or transmitter and work synchronously or not (with respect to the other one).

32.2 SAI main features

32.3 SAI implementation

Table 208. STM32F469xx and STM32F479xx SAI features

SAI featuresSAI1
I2S, LSB or MSB-justified, PCM/DSP, TDM, AC'97X
Mute modeX
Stereo/mono audio frame capabilityX
Data size configurable: 8-, 10-, 16-20-, 24-, 32-bitX
FIFO size8 words
SPDIFX
PDM-

32.4 SAI functional description

32.4.1 SAI block diagram

Figure 382 shows the SAI block diagram while Table 209 and Table 210 list SAI internal and external signals.

Figure 382. SAI functional block diagram

Figure 382. SAI functional block diagram. The diagram shows the internal architecture of the Serial Audio Interface (SAI). At the top, a 32-bit APB bus is connected to an APB Interface block. This block is connected to the SAI ACR1 register and the Clock generator for Audio block A. The Clock generator receives sai_a_ker_ck and sai_pclk inputs. Audio block A contains a FIFO, FIFO ctrl, Configuration and status registers, FSM, and a 32-bit shift register. The FIFO and FIFO ctrl are connected to the APB Interface. The Configuration and status registers are connected to the APB Interface and the FSM. The FSM is connected to the 32-bit shift register. The 32-bit shift register is connected to the IO Line Management block. The IO Line Management block has pins for FS_A, SCK_A, SD_A, MCLK_A, FS_B, SCK_B, SD_B, and MCLK_B. Audio block B is similar to Audio block A, with its own FIFO, FIFO ctrl, Configuration and status registers, FSM, and 32-bit shift register. It is connected to an APB Interface block, which is connected to the SAI BCR1 register and the Clock generator for Audio block B. The Clock generator receives sai_b_ker_ck input. The APB Interface for Audio block B is connected to a 32-bit APB bus at the bottom. The SAI BCR1 register is also connected to the 32-bit APB bus. The diagram is labeled MSV46160V1.
Figure 382. SAI functional block diagram. The diagram shows the internal architecture of the Serial Audio Interface (SAI). At the top, a 32-bit APB bus is connected to an APB Interface block. This block is connected to the SAI ACR1 register and the Clock generator for Audio block A. The Clock generator receives sai_a_ker_ck and sai_pclk inputs. Audio block A contains a FIFO, FIFO ctrl, Configuration and status registers, FSM, and a 32-bit shift register. The FIFO and FIFO ctrl are connected to the APB Interface. The Configuration and status registers are connected to the APB Interface and the FSM. The FSM is connected to the 32-bit shift register. The 32-bit shift register is connected to the IO Line Management block. The IO Line Management block has pins for FS_A, SCK_A, SD_A, MCLK_A, FS_B, SCK_B, SD_B, and MCLK_B. Audio block B is similar to Audio block A, with its own FIFO, FIFO ctrl, Configuration and status registers, FSM, and 32-bit shift register. It is connected to an APB Interface block, which is connected to the SAI BCR1 register and the Clock generator for Audio block B. The Clock generator receives sai_b_ker_ck input. The APB Interface for Audio block B is connected to a 32-bit APB bus at the bottom. The SAI BCR1 register is also connected to the 32-bit APB bus. The diagram is labeled MSV46160V1.

The SAI is mainly composed of two audio subblocks with their own clock generator. Each audio block integrates a 32-bit shift register controlled by their own functional state machine. Data are stored or read from the dedicated FIFO. FIFO may be accessed by the CPU, or by DMA to leave the CPU free during the communication. Each audio block is independent. They can be synchronous with each other.

An I/O line controller manages a set of 4 dedicated pins (SD, SCK, FS, MCLK) for a given audio block in the SAI. Some of these pins can be shared if the two subblocks are declared as synchronous to leave some free to be used as general purpose I/Os. The MCLK pin can be output, or not, depending on the application, the decoder requirement and whether the audio block is configured as the master.

If one SAI is configured to operate synchronously with another one, even more I/Os can be freed (except for pins SD_x).

The functional state machine can be configured to address a wide range of audio protocols. Some registers are present to set up the desired protocols (audio frame waveform generator).

The audio subblock can be a transmitter or receiver, in master or slave mode. The master mode means the SCK_x bit clock and the frame synchronization signal are generated from the SAI, whereas in slave mode, they come from another external or internal master. There is a particular case for which the FS signal direction is not directly linked to the master or slave mode definition. In AC'97 protocol, it is an SAI output even if the SAI (link controller) is set up to consume the SCK clock (and so to be in Slave mode).

Note: For ease of reading of this section, the notation SAI_x refers to SAI_A or SAI_B, where 'x' represents the SAI A or B subblock.

32.4.2 SAI pins and internal signals

Table 209. SAI internal input/output signals

Internal signal nameSignal typeDescription
sai_a_gbl_it/
sai_b_gbl_it
OutputAudio block A and B global interrupts
sai_a_dma,
sai_b_dma
Input/outputAudio block A and B DMA acknowledges and requests
sai_a_ker_ck/
sai_b_ker_ck
InputAudio block A/B kernel clock
sai_pclkInputAPB clock

Table 210. SAI input/output pins

Pin namePin typeComments
SAI_SCK_A/BInput/outputAudio block A/B bit clock
SAI_MCLK_A/BOutputAudio block A/B master clock
SAI_SD_A/BInput/outputData line for block A/B
SAI_FS_A/BInput/outputFrame synchronization line for audio block A/B

32.4.3 Main SAI modes

Each audio subblock of the SAI can be configured to be master or slave via the MODE bits in the SAI_xCR1 register of the selected audio block.

Master mode

In master mode, the SAI delivers the timing signals to the external connected device:

Both SCK_x, FS_x and MCLK_x are configured as outputs.

Slave mode

The SAI expects to receive timing signals from an external device.

In slave mode, the MCLK_x pin is not used and can be assigned to another function.

It is recommended to enable the slave device before enabling the master.

Configuring and enabling SAI modes

Each audio subblock can be independently defined as a transmitter or receiver through the MODE bit in the SAI_xCR1 register of the corresponding audio block. As a result, the SAI_SD_x pin is respectively configured as an output or an input.

Two master audio blocks in the same SAI can be configured with two different MCLK and SCK clock frequencies. In this case, they have to be configured in asynchronous mode.

Each of the audio blocks in the SAI is enabled by the SAIEN bit in the SAI_xCR1 register. As soon as this bit is active, the transmitter or the receiver is sensitive to the activity on the clock, data, and synchronization lines in slave mode.

In master Tx mode, enabling the audio block immediately generates the bit clock for the external slaves even if there is no data in the FIFO. However, FS signal generation is conditioned by the presence of data in the FIFO. After the FIFO receives the first data to transmit, this data is output to external slaves. If there is no data to transmit in the FIFO, 0 values are then sent in the audio frame with an underrun flag generation.

In slave mode, the audio frame starts when the audio block is enabled and when a start of frame is detected.

In Slave Tx mode, no underrun event is possible on the first frame after the audio block is enabled, because the mandatory operating sequence in this case is:

  1. 1. Write into the SAI_xDR (by software or by DMA).
  2. 2. Wait until the FIFO threshold (FLH) flag is different from 0b000 (FIFO empty).
  3. 3. Enable the audio block in slave transmitter mode.

32.4.4 SAI synchronization mode

SAI subclock A and B can be synchronized.

Internal synchronization

An audio subblock can be configured to operate synchronously with the second audio subblock in the same SAI. In this case, the bit clock and the frame synchronization signals are shared to reduce the number of external pins used for the communication. The audio block configured in synchronous mode sees its own SCK_x, FS_x, and MCLK_x pins released back as GPIOs while the audio block configured in asynchronous mode is the one for which FS_x and SCK_x and MCLK_x I/O pins are relevant (if the audio block is considered as master).

Typically, the audio block in synchronous mode can be used to configure the SAI in full duplex mode. One of the two audio blocks can be configured as a master and the other as slave, or both as slaves with one asynchronous block (corresponding SYNCEN[1:0] bits set to 00 in SAI_xCR1) and one synchronous block (corresponding SYNCEN[1:0] bits set to 01 in the SAI_xCR1 register).

Note: Due to internal resynchronization stages, PCLK APB frequency must be higher than twice the bit rate clock frequency.

32.4.5 Audio data size

The audio frame can target different data sizes by configuring bit DS[2:0] in the SAI_xCR1 register. The data sizes may be 8, 10, 16, 20, 24, or 32 bits. During the transfer, either the

MSB or the LSB of the data is sent first, depending on the configuration of the LSBFIRST bit in the SAI_xCR1 register.

32.4.6 Frame synchronization

The FS signal acts as the frame synchronization signal in the audio frame (start of frame). The shape of this signal is completely configurable to target the different audio protocols with their own specificities concerning this frame synchronization behavior. This reconfigurability is done using the SAI_xFRCR register. Figure 383 illustrates this flexibility.

Figure 383. Audio frame

Timing diagram of an audio frame showing the relationship between the Frame Synchronization (FS) signal, the Serial Clock (SCK), and the Serial Data (SD) lines. The diagram illustrates two cases for the FS signal: one where the falling edge occurs at the start of a slot (FSOFF = 0) and another where it occurs at the start of a slot (FSOFF = 1). The FS signal is active for up to 128 bits, and the total FS length can be up to 256 bits. The SD lines are divided into slots (Slot 0, Slot 1, Slot 2, Slot 3, Slot 4, etc.). The diagram also shows the relationship between the FS signal and the SCK signal, which is a periodic clock signal. The diagram is labeled with 'MSv30037V2' in the bottom right corner.
Timing diagram of an audio frame showing the relationship between the Frame Synchronization (FS) signal, the Serial Clock (SCK), and the Serial Data (SD) lines. The diagram illustrates two cases for the FS signal: one where the falling edge occurs at the start of a slot (FSOFF = 0) and another where it occurs at the start of a slot (FSOFF = 1). The FS signal is active for up to 128 bits, and the total FS length can be up to 256 bits. The SD lines are divided into slots (Slot 0, Slot 1, Slot 2, Slot 3, Slot 4, etc.). The diagram also shows the relationship between the FS signal and the SCK signal, which is a periodic clock signal. The diagram is labeled with 'MSv30037V2' in the bottom right corner.

In AC'97 mode or in SPDIF mode (bit PRTCFCG[1:0] = 10 or PRTCFCG[1:0] = 01 in the SAI_xCR1 register), the frame synchronization shape is forced to match the AC'97 protocol. The SAI_xFRCR register value is ignored.

Each audio block is independent and consequently each one requires a specific configuration.

Frame length

The audio frame length can be configured to up to 256-bit clock cycles, by configuring the FRL[7:0] field in the SAI_xFRCR register.

If the frame length is greater than the number of declared slots for the frame, the remaining bits to transmit are extended to 0 or the SD line is released to high-Z depending on the state of bit TRIS in the SAI_xCR2 register (refer to FS signal role ). In reception mode, the remaining bit is ignored.

If bit NODIV is cleared, (FRL+1) must be equal to a power of 2, from 8 to 256, to ensure that an audio frame contains an integer number of MCLK pulses per bit clock cycle.

If bit NODIV is set, the (FRL+1) field can take any value from 8 to 256. Refer to Section 32.4.8: SAI clock generator

The audio frame length is mainly used to specify to the slave the number of bit clock cycles per audio frame sent by the external master. It is used mainly to detect from the master any anticipated or late occurrence of the frame synchronization signal during an ongoing audio frame. In this case, an error is generated. For more details, refer to Section 32.4.13: Error flags .

In slave mode, there are no constraints on the FRL[7:0] configuration in the SAI_xFRCR register.

The number of bits in the frame is equal to FRL[7:0] + 1.

The minimum number of bits to transfer in an audio frame is 8.

Frame synchronization polarity

The FSPOL bit in the SAI_xFRCR register sets the active polarity of the FS pin from which a frame is started. The start of the frame is edge sensitive.

In slave mode, the audio block waits for a valid frame to start transmitting or receiving. The start of the frame is synchronized to this signal. It is effective only if the start of the frame is not detected during an ongoing communication and assimilated to an anticipated start of frame (refer to Section 32.4.13: Error flags ).

In master mode, the frame synchronization is sent continuously each time an audio frame is complete until the SAIEN bit in the SAI_xCR1 register is cleared. If no data are present in the FIFO at the end of the previous audio frame, an underrun condition is managed as described in Section 32.4.13: Error flags , but the audio communication flow is not interrupted.

Frame synchronization active level length

The FSALL[6:0] bits of the SAI_xFRCR register enable the configuration of the length of the active level of the frame synchronization signal. The length can be set from 1- to 128-bit clock cycles.

As an example, the active length can be half of the frame length in I2S, LSB or MSB-justified modes, or one-bit wide for PCM/DSP or TDM.

Frame synchronization offset

Depending on the audio protocol targeted in the application, the frame synchronization signal can be asserted when transmitting the last bit or the first bit of the audio frame (this is the case in I2S standard protocol and in MSB-justified protocol, respectively). The FSOFF bit in the SAI_xFRCR register enables the possibility to choose between two configurations.

FS signal role

The FS signal can have a different meaning depending on the FS function. FSDEF bit in the SAI_xFRCR register selects which meaning it has:

When the FS signal is considered as a start of frame and channel side identification within the frame, the number of declared slots must be considered to be half the number for the left channel and half the number for the right channel. If the number of bit clock cycles on half audio frame is greater than the number of slots dedicated to a channel side, and TRIS = 0, 0 is sent for transmission for the remaining bit clock cycles in the SAI_xCR2 register. Otherwise, if TRIS = 1, the SD line is released to high-Z. In reception mode, the remaining bit clock cycles are not considered until the channel side changes.

Figure 384. FS role is start of frame + channel side identification (FSDEF = TRIS = 1)

Timing diagram for SAI when slots are not aligned with the audio frame. The FS signal goes low at the start of the audio frame and returns high at the half-frame point. The sck signal is a continuous square wave. The slot sequence shows Slot 0 ON, Slot 1 OFF, Slot 2 ON, followed by a break, then Slot 3 ON, Slot 4 OFF, Slot 5 ON, followed by another break. Timing diagram for SAI when slots are aligned with the audio frame. The FS signal goes low at the start of the audio frame and returns high at the half-frame point. The sck signal is a continuous square wave. The slot sequence shows Slot 0, Slot 1, Slot 2, Slot 3, Slot 4, Slot 5, all within the first half of the frame.

Number of slots not aligned with the audio frame

Audio frame

Half of frame

FS

sck

slot Slot 0 ON Slot 1 OFF Slot 2 ON // Slot 3 ON Slot 4 OFF Slot 5 ON //

Number of slots aligned with the audio frame

Audio frame

Half of frame

FS

sck

slot Slot 0 Slot 1 Slot 2 Slot 3 Slot 4 Slot 5

MS30038V2

Timing diagram for SAI when slots are not aligned with the audio frame. The FS signal goes low at the start of the audio frame and returns high at the half-frame point. The sck signal is a continuous square wave. The slot sequence shows Slot 0 ON, Slot 1 OFF, Slot 2 ON, followed by a break, then Slot 3 ON, Slot 4 OFF, Slot 5 ON, followed by another break. Timing diagram for SAI when slots are aligned with the audio frame. The FS signal goes low at the start of the audio frame and returns high at the half-frame point. The sck signal is a continuous square wave. The slot sequence shows Slot 0, Slot 1, Slot 2, Slot 3, Slot 4, Slot 5, all within the first half of the frame.
  1. 1. The frame length must be even.

If the FSDEF bit in SAI_xFRCR is kept clear, so FS signal is equivalent to a start of frame, and if the number of slots defined in NBSLOT[3:0] in SAI_xSLOTR multiplied by the number of bits by slot configured in SLOTSZ[1:0] in SAI_xSLOTR is less than the frame size (bit FRL[7:0] in the SAI_xFRCR register), then:

Figure 385. FS role is start of frame (FSDEF = 0)

Timing diagram for SAI audio frame showing the relationship between the FS signal, SCK signal, and data slots.

The diagram illustrates the timing of an audio frame. The top signal is the FS (Frame Synchronization) signal, which is a square wave that goes high at the start of the audio frame and returns low at the start of the next frame. The middle signal is the SCK (Serial Clock) signal, which is a continuous square wave. The bottom signal is the SD (Serial Data) line, which is divided into slots: Slot 0, Slot 1, Slot 2, ..., Slot n. The data for Slot n is shown as a horizontal line. Below the slots, there is a note: "Data = 0 after slot n if TRIS = 0" and "SD output released (HI-Z) after slot n if TRIS = 1". The diagram is labeled "MS30039V1" in the bottom right corner.

Timing diagram for SAI audio frame showing the relationship between the FS signal, SCK signal, and data slots.

The FS signal is not used when the audio block in transmitter mode is configured to get the SPDIF output on the SD line. The corresponding FS I/O is released and left free for other purposes.

32.4.7 Slot configuration

The slot is the basic element in the audio frame. The number of slots in the audio frame is equal to NBSLOT[3:0] + 1.

The maximum number of slots per audio frame is fixed at 16.

For AC'97 protocol or SPDIF (when bit PRTCFCFG[1:0] = 10 or PRTCFCFG[1:0] = 01), the number of slots is automatically set to target the protocol specification, and the value of NBSLOT[3:0] is ignored.

Each slot can be defined as a valid slot, or not, by setting SLOTEN[15:0] bits of the SAI_xSLOTR register.

When an invalid slot is transferred, the SD data line is either forced to 0 or released to high-Z depending on the TRIS bit configuration (refer to Output data line management on an inactive slot ) in transmitter mode. In receiver mode, the received value from the end of this slot is ignored. Consequently, there is no FIFO access and so no request to read or write the FIFO linked to this inactive slot status.

The slot size is also configurable as shown in Figure 386 . The size of the slots is selected by configuring the SLOTSZ[1:0] bits in the SAI_xSLOTR register. The size is applied identically for each slot in an audio frame.

Figure 386. Slot size configuration with FBOFF = 0 in SAI_xSLOTR

Figure 386: Slot size configuration with FBOFF = 0 in SAI_xSLOTR. The diagram shows two columns: 'Audio block is transmitter' and 'Audio block is receiver'. Both columns show three slot configurations. In the transmitter column, the first slot has 'data size' only. The second slot has 'data size' followed by '00..00', with a 16-bit width indicated. The third slot has 'data size' followed by '00..00', with a 32-bit width indicated. In the receiver column, the first slot has 'data size' only. The second slot has 'data size' followed by 'X..X', with a 16-bit width indicated. The third slot has 'data size' followed by 'XX..XX', with a 32-bit width indicated. A note at the bottom right says 'X: don't care' and 'MSV30033V1'.
Figure 386: Slot size configuration with FBOFF = 0 in SAI_xSLOTR. The diagram shows two columns: 'Audio block is transmitter' and 'Audio block is receiver'. Both columns show three slot configurations. In the transmitter column, the first slot has 'data size' only. The second slot has 'data size' followed by '00..00', with a 16-bit width indicated. The third slot has 'data size' followed by '00..00', with a 32-bit width indicated. In the receiver column, the first slot has 'data size' only. The second slot has 'data size' followed by 'X..X', with a 16-bit width indicated. The third slot has 'data size' followed by 'XX..XX', with a 32-bit width indicated. A note at the bottom right says 'X: don't care' and 'MSV30033V1'.

It is possible to choose the position of the first data bit to transfer within the slots. This offset is configured by FBOFF[4:0] bits in the SAI_xSLOTR register. 0 values are injected in transmitter mode from the beginning of the slot until this offset position is reached. In reception, the bit in the offset phase is ignored. This feature targets the LSB justified protocol (if the offset is equal to the slot size minus the data size).

Figure 387. First bit offset

Figure 387: First bit offset. The diagram shows two columns: 'Audio block is transmitter' and 'Audio block is receiver'. Both columns show three slot configurations. In the transmitter column, the first slot has 'data size' only. The second slot has 'FBOFF' (00), 'data size', and '00', with a 16-bit width indicated. The third slot has 'FBOFF = SLOT SZ - DS' (00..00) and 'data size', with a 32-bit width indicated. In the receiver column, the first slot has 'data size' only. The second slot has 'FBOFF' (XX), 'data size', and 'XX', with a 16-bit width indicated. The third slot has 'FBOFF = SLOT SZ - DS' (XX..XX) and 'data size', with a 32-bit width indicated. A note at the bottom right says 'X: don't care' and 'MSV30034V1'.
Figure 387: First bit offset. The diagram shows two columns: 'Audio block is transmitter' and 'Audio block is receiver'. Both columns show three slot configurations. In the transmitter column, the first slot has 'data size' only. The second slot has 'FBOFF' (00), 'data size', and '00', with a 16-bit width indicated. The third slot has 'FBOFF = SLOT SZ - DS' (00..00) and 'data size', with a 32-bit width indicated. In the receiver column, the first slot has 'data size' only. The second slot has 'FBOFF' (XX), 'data size', and 'XX', with a 16-bit width indicated. The third slot has 'FBOFF = SLOT SZ - DS' (XX..XX) and 'data size', with a 32-bit width indicated. A note at the bottom right says 'X: don't care' and 'MSV30034V1'.

It is mandatory to respect the following conditions to avoid bad SAI behavior:

The number of slots must be even when bit FSDEF in the SAI_xFRCR register is set.

In AC'97 and SPDIF protocol (bit PRTCFC[1:0] = 10 or PRTCFC[1:0] = 01), the slot size is automatically set as defined in Section 32.4.10: AC'97 link controller .

32.4.8 SAI clock generator

Each audio block has its own clock generator that makes these two blocks completely independent. There is no difference in terms of functionality between these two clock generators.

When the audio block is configured as Master, the clock generator provides the communication clock (the bit clock) and the master clock for external decoders.

When the audio block is defined as slave, the clock generator is OFF.

Figure 388 illustrates the architecture of the audio block clock generator.

Figure 388. Audio block clock generator overview

Figure 388. Audio block clock generator overview. The diagram shows the internal architecture of the SAI clock generator. A sai_x_ker_ck clock signal enters from the left and is split into two paths. The first path goes through a 'Master clock divider' block, which is controlled by MCKDIV[3:0]. The output of this divider is connected to a 2-to-1 multiplexer. The second path for sai_x_ker_ck goes through another 2-to-1 multiplexer, which is controlled by NODIV. The outputs of these two multiplexers are combined and then enter a 'Bit clock divider' block, which is controlled by FRL[7:0]. The output of the bit clock divider is connected to a third 2-to-1 multiplexer, also controlled by NODIV. The final output is SCK_x. The MCLK_x output is also shown, which is the output of the first multiplexer. The diagram is labeled MSv30040V2.
Figure 388. Audio block clock generator overview. The diagram shows the internal architecture of the SAI clock generator. A sai_x_ker_ck clock signal enters from the left and is split into two paths. The first path goes through a 'Master clock divider' block, which is controlled by MCKDIV[3:0]. The output of this divider is connected to a 2-to-1 multiplexer. The second path for sai_x_ker_ck goes through another 2-to-1 multiplexer, which is controlled by NODIV. The outputs of these two multiplexers are combined and then enter a 'Bit clock divider' block, which is controlled by FRL[7:0]. The output of the bit clock divider is connected to a third 2-to-1 multiplexer, also controlled by NODIV. The final output is SCK_x. The MCLK_x output is also shown, which is the output of the first multiplexer. The diagram is labeled MSv30040V2.

Note: If NODIV is set to 1, the MCLK_x signal is set at 0 level if this pin is configured as the SAI pin in GPIO peripherals.

The clock source for the clock generator comes from the product clock controller. The sai_x_ker_ck clock is equivalent to the master clock, which can be divided for the external decoders using bit MCKDIV[3:0]:

\[ \text{MCLK\_x} = \text{sai\_x\_ker\_ck} / (\text{MCKDIV}[3:0] * 2), \text{ if MCKDIV}[3:0] \text{ is not equal to 0000.} \]
\[ \text{MCLK\_x} = \text{sai\_x\_ker\_ck}, \text{ if MCKDIV}[3:0] \text{ is equal to 0000.} \]

MCLK_x signal is used only in Free protocol mode.

The division must be even to keep 50% on the duty cycle on the MCLK output and on the SCK_x clock. If bit MCKDIV[3:0] = 0000, division by one is applied to obtain MCLK_x equal to sai_x_ker_ck.

In the SAI, the single ratio \( \text{MCLK/FS} = 256 \) is considered. Mostly, three frequency ranges are encountered, as illustrated in Table 211 .

Table 211. Example of possible audio frequency sampling range
Input sai_x_ker_ck clock frequencyMost usual audio frequency sampling achievableMCKDIV[3:0]
192 kHz x 256192 kHzMCKDIV[3:0] = 0000
96 kHzMCKDIV[3:0] = 0001
48 kHzMCKDIV[3:0] = 0010
16 kHzMCKDIV[3:0] = 0110
8 kHzMCKDIV[3:0] = 1100
44.1 kHz x 25644.1 kHzMCKDIV[3:0] = 0000
22.05 kHzMCKDIV[3:0] = 0001
11.025 kHzMCKDIV[3:0] = 0010
sai_x_ker_ck = MCLK (1)MCLKMCKDIV[3:0] = 0000

1. This may happen when the product clock controller selects an external clock source, instead of PLL clock.

The master clock can be generated externally on an I/O pad for external decoders if the corresponding audio block is declared as master with bit NODIV = 0 in the SAI_xCR1 register. In slave, the value set in this last bit is ignored since the clock generator is OFF, and the MCLK_x I/O pin is released for use as a general purpose I/O.

The bit clock is derived from the master clock. The bit clock divider sets the divider factor between the bit clock (SCK_x) and the master clock (MCLK_x) following the formula:

\[ SCK\_x = MCLK \times (FRL[7:0] + 1) / 256 \]

Where:

256 is the fixed ratio between MCLK and the audio frequency sampling.

FRL[7:0] is the number of bit clock cycles- 1 in the audio frame, configured in the SAI_xFRCR register.

In master mode, it is mandatory that (FRL[7:0] +1) is equal to a number with a power of 2 (refer to Section 32.4.6: Frame synchronization ) to obtain an even integer number of MCLK_x pulses by bit clock cycle. The 50% duty cycle is guaranteed on the bit clock (SCK_x).

The sai_x_ker_ck clock can also be equal to the bit clock frequency. In this case, the NODIV bit in the SAI_xCR1 register should be set and the value inside the MCKDIV divider and the bit clock divider will be ignored. In this case, the number of bits per frame is fully configurable without the need to be equal to a power of two.

The bit clock strobing edge on SCK can be configured by bit CKSTR in the SAI_xCR1 register.

Refer to Section 32.4.11: SPDIF output for details on clock generator programming in SPDIF mode.

32.4.9 Internal FIFOs

Each audio block in the SAI has its own FIFO. Depending on if the block is defined to be a transmitter or a receiver, the FIFO can be written or read, respectively. Thus, there is only one FIFO request linked to the FREQ bit in the SAI_xSR register.

An interrupt is generated if the FREQIE bit is enabled in the SAI_xIM register. This depends on:

Interrupt generation in transmitter mode

The interrupt generation depends on the FIFO configuration in transmitter mode:

Interrupt generation in reception mode

The interrupt generation depends on the FIFO configuration in reception mode:

in SAI_xSR are higher than or equal to 0b001). This interrupt (FREQ bit in the SAI_xSR register) is cleared by hardware when the FIFO becomes empty (FLVL[2:0] bits in the SAI_xSR are equal to 0b000), that is, no data are stored in FIFO.

Like interrupt generation, the SAI can use the DMA if the DMAEN bit in the SAI_xCR1 register is set. The FREQ bit assertion mechanism is the same as the interrupt generation mechanism described above for FREQIE.

Each FIFO is an 8-word FIFO. Each read or write operation from/to the FIFO targets one word FIFO location whatever the access size. Each FIFO word contains one audio slot. FIFO pointers are incremented by one word after each access to the SAI_xDR register.

Data must be right-aligned when written in the SAI_xDR register.

Data received are right-aligned in the SAI_xDR register.

The FIFO pointers can be reinitialized when the SAI is disabled by configuring the FFLUSH bit in the SAI_xCR2 register. If FFLUSH is set when the SAI is enabled, the data present in the FIFO are lost automatically.

The SAI is able to work as an AC'97 link controller. In this protocol:

To select this protocol, set the PRTCFCFG[1:0] bits in the SAI_xCR1 register to 10. When AC'97 mode is selected, only data sizes of 16 or 20 bits can be used, otherwise the SAI behavior is not guaranteed.

The FS signal from the block defined as asynchronous is configured automatically as an output, since the AC'97 controller link drives the FS signal whatever the master or slave configuration.

Figure 389 shows an AC'97 audio frame structure.

Figure 389. AC'97 audio frame

Diagram of AC'97 audio frame structure showing 13 slots. Slot 0 is a 16-bit tag. Slots 1-12 are 20-bit data slots. The diagram shows SDI and SDO lines with their respective data types for each slot.
SignalSlot 0 (Tag)Slot 1Slot 2Slot 3Slot 4Slot 5Slot 6Slot 7Slot 8Slot 9Slot 10Slot 11Slot 12
SDITagCMD ADDRCMD DATAPCM LFRONTPCM RFRONTLINE1 DACPCM CENTERPCM LSURRPCM RSURRPCM LFELINE2 DACHSET DACIO CTRL
SDOTagSTATUS ADDRSTATUS DATAPCM LEFTPCM RIGHTLINE1 ADCPCM MICRSR VDRSR VDRSR LVDLINE2 ADCHSETIO STATUS

MS192343V1

Diagram of AC'97 audio frame structure showing 13 slots. Slot 0 is a 16-bit tag. Slots 1-12 are 20-bit data slots. The diagram shows SDI and SDO lines with their respective data types for each slot.

Note: In the AC'97 protocol, bit 2 of the tag is reserved (always 0), so bit 2 of the TAG is forced to 0 level whatever the value written in the SAI FIFO.

For more details about tag representation, refer to the AC'97 protocol standard.

One SAI can be used to target an AC'97 point-to-point communication.

In receiver mode, the SAI acting as an AC'97 link controller requires no FIFO request and so no data storage in the FIFO when the codec-ready bit in slot 0 is decoded low. If bit CNRDYIE is enabled in the SAI_xIM register, flag CNRDY is set in the SAI_xSR register and an interrupt is generated. This flag is dedicated to the AC'97 protocol.

Clock generator programming in AC’97 mode

In AC’97 mode, the frame length is fixed at 256 bits, and its frequency must be set to 48 kHz. The formulas given in Section 32.4.8: SAI clock generator must be used with \( FRL = 255 \) , to generate the proper frame rate ( \( F_{FS\_x} \) ).

32.4.11 SPDIF output

The SPDIF interface is available in transmitter mode only. It supports the audio IEC60958.

To select SPDIF mode, set the PRTCFG[1:0] bits to 01 in the SAI_xCR1 register.

For SPDIF protocol:

Figure 390. SPDIF format

Figure 390. SPDIF format diagram showing the structure of an SPDIF block and frame. The top part shows Block N and Block N+1, each containing 192 frames (Frame 0 to Frame 191). Each frame is composed of two 32-bit subframes. Each subframe is composed of a SOPD pattern (4-bit) followed by 28 bits of channel information (24 data bits + 4 status bits). The SOPD pattern is B, W, M, W. The channel information is D0, D1, D2, D3, D4, ..., D20, D21, D22, D23, VP, U, CS. The diagram also shows the mapping of Channel A and Channel B to the subframes.

The diagram illustrates the SPDIF format. At the top, a horizontal timeline shows 'Block N' and 'Block N+1'. 'Block N' contains 'Frame 0', 'Frame 1', and 'Frame 191'. 'Block N+1' contains 'Frame 0'. Each frame is divided into two 'Sub-frame' units. Each sub-frame is further divided into 'Channel A' and 'Channel B' sections, each preceded by a 'B', 'W', or 'M' bit. Below this, a detailed view of a sub-frame shows a 'SOPD' (4-bit) section followed by a '24-bit data' section and a 'Status bit' section. The SOPD section is labeled 'SOPD B,M,W'. The 24-bit data section is labeled 'D0 D1 D2 D3 D4' followed by a break and 'D20 D21 D22 D23'. The status bit section is labeled 'VP U CS'. Lines connect the 'B', 'W', and 'M' bits in the sub-frames to the 'SOPD' section, and the data and status bits to the '24-bit data' and 'Status bit' sections respectively. The diagram is labeled 'MS30042V1' in the bottom right corner.

Figure 390. SPDIF format diagram showing the structure of an SPDIF block and frame. The top part shows Block N and Block N+1, each containing 192 frames (Frame 0 to Frame 191). Each frame is composed of two 32-bit subframes. Each subframe is composed of a SOPD pattern (4-bit) followed by 28 bits of channel information (24 data bits + 4 status bits). The SOPD pattern is B, W, M, W. The channel information is D0, D1, D2, D3, D4, ..., D20, D21, D22, D23, VP, U, CS. The diagram also shows the mapping of Channel A and Channel B to the subframes.

An SPDIF block contains 192 frames. Each frame is composed of two 32-bit subframes, generally one for the left channel and one for the right channel. Each subframe is composed of a SOPD pattern (4-bit) to specify if the subframe is the start of a block (and so is identifying a channel A) or if it is identifying a channel A somewhere in the block, or if it is referring to channel B (see Table 212 ). The next 28 bits of channel information are composed of 24 data bits + 4 status bits.

Table 212. SOPD pattern

SOPDPreamble codingDescription
last bit is 0last bit is 1
B1110100000010111Channel A data at the start of block
W1110010000011011Channel B data somewhere in the block
M1110001000011101Channel A data

The data stored in SAI_xDR has to be filled as follows:

If the data size is 20 bits, the data must be mapped on SAI_xDR[23:4].

If the data size is 16 bits, the data must be mapped on SAI_xDR[23:8].

SAI_xDR[23] always represents the MSB.

Figure 391. SAI_xDR register ordering

Diagram of SAI_xDR register ordering showing a 27-bit register (bits 26 to 0). Bits 26, 25, and 24 are labeled CS, U, and V respectively, and are grouped as 'Status bits'. Bits 23 down to 0 are labeled D23 through D0 and are grouped as 'Data[23:0]'. The diagram shows the register layout with bit 26 on the left and bit 0 on the right.
Diagram of SAI_xDR register ordering showing a 27-bit register (bits 26 to 0). Bits 26, 25, and 24 are labeled CS, U, and V respectively, and are grouped as 'Status bits'. Bits 23 down to 0 are labeled D23 through D0 and are grouped as 'Data[23:0]'. The diagram shows the register layout with bit 26 on the left and bit 0 on the right.

Note: The transfer is always performed with LSB first.

The SAI first sends the adequate preamble for each subframe in a block. The SAI_xDR is then sent on the SD line (Manchester coded). The SAI ends the subframe by transferring the parity bit calculated as described in Table 213 .

Table 213. Parity bit calculation

SAI_xDR[26:0]Parity bit P value transferred
odd number of 00
odd number of 11

The underrun is the only error flag available in the SAI_xSR register for SPDIF mode since the SAI can only operate in transmitter mode. As a result, the following sequence must be

executed to recover from an underrun error detected via the underrun interrupt or the underrun status bit:

  1. 1. Disable the DMA stream (via the DMA peripheral) if the DMA is used.
  2. 2. Disable the SAI and check that the peripheral is physically disabled by polling the SAIEN bit in the SAI_xCR1 register.
  3. 3. Clear the COVRUNDR flag in the SAI_xCLRFR register.
  4. 4. Flush the FIFO by setting the FFLUSH bit in SAI_xCR2.

The software needs to point to the address of the future data corresponding to the start of a new block (data for preamble B). If the DMA is used, the DMA source base address pointer must be updated accordingly.

  1. 5. Enable the DMA stream (DMA peripheral) again if the DMA is used to manage data transfers according to the new source base address.
  2. 6. Enable the SAI again by configuring the SAIEN bit in the SAI_xCR1 register.

Clock generator programming in SPDIF generator mode

For the SPDIF generator, the SAI provides a bit clock twice as fast as the symbol-rate. The table below shows examples of symbol rates with respect to the audio sampling rate.

Table 214. Audio sampling frequency versus symbol rates

Audio sampling frequencies (F S )Symbol-rate
44.1 kHz2.8224 MHz
48 kHz3.072 MHz
96 kHz6.144 MHz
192 kHz12.288 MHz

More generally, the relationship between the audio sampling frequency (F S ) and the bit clock rate (F SCK_x ) is given by the formula:

\[ F_S = \frac{F_{SCK\_x}}{128} \]

The bit clock rate is obtained as follows:

\[ F_{SCK\_x} = F_{sai\_x\_ker\_ck} \]

Note: The above formulas are valid only if NODIV is set to 1 in the SAI_ACR1 register.

32.4.12 Specific features

The SAI interface embeds specific features that can be useful depending on the audio protocol selected. These functions are accessible through specific bits of the SAI_xCR2 register.

Mute mode

The mute mode can be used when the audio subblock is a transmitter or a receiver.

Audio subblock in transmission mode

In transmitter mode, the mute mode can be selected at any time. The mute mode is active for entire audio frames. The MUTE bit in the SAI_xCR2 register enables the mute mode when it is configured during an ongoing frame.

The mute mode bit is strobed only at the end of the frame. If it is set at this time, the mute mode is active at the beginning of the new audio frame and for a complete frame, until the next end of frame. The bit is then strobed to determine if the next frame is still a mute frame.

If the number of slots set through the NBSLOT[3:0] bits in the SAI_xSLOTR register is lower than or equal to 2, it is possible to specify if the value sent in mute mode is 0 or if it is the last value of each slot. The selection is done via the MUTEVAL bit in the SAI_xCR2 register.

If the number of slots set in the NBSLOT[3:0] bits in the SAI_xSLOTR register is greater than 2, the MUTEVAL bit in the SAI_xCR2 register is meaningless as 0 values are sent on each bit on each slot.

The FIFO pointers are still incremented in mute mode. This means that data present in the FIFO and for which the mute mode is requested are discarded.

Audio subblock in reception mode

In reception mode, it is possible to detect a mute mode sent from the external transmitter when all the declared and valid slots of the audio frame receive 0 for a given consecutive number of audio frames (MUTECNT[5:0] bits in the SAI_xCR2 register).

When the number of MUTE frames is detected, the MUTEDET flag in the SAI_xSR register is set and an interrupt can be generated if the MUTEDETIE bit is set in SAI_xCR2.

The mute frame counter is cleared when the audio subblock is disabled or when a valid slot receives at least one data in an audio frame. The interrupt is generated just once, when the counter reaches the value specified in the MUTECNT[5:0] bits. The interrupt event is then reinitialized when the counter is cleared.

Note: The mute mode is not available for SPDIF audio blocks.

Mono/stereo mode

In transmitter mode, the mono mode can be addressed without any data preprocessing in memory, assuming the number of slots is equal to 2 (NBSLOT[3:0] = 0001 in SAI_xSLOTR). In this case, the access time to and from the FIFO is reduced by 2 since the data for slot 0 is duplicated into data slot 1.

To enable the mono mode:

  1. 1. Set the MONO bit to 1 in the SAI_xCR1 register.
  2. 2. Set NBSLOT to 1 and SLOTEN to 3 in SAI_xSLOTR.

In reception mode, the MONO bit can be set and is meaningful only if the number of slots is equal to 2, like in transmitter mode. When it is set, only slot 0 data are stored in the FIFO. The data belonging to slot 1 are discarded since, in this case, it is supposed to be the same as the previous slot. If the data flow in reception mode is a real stereo audio flow with a distinct and different left and right data, the MONO bit is meaningless. The conversion from the output stereo file to the equivalent mono file is done by software.

Companding mode

Telecommunication applications can require processing the data to be transmitted or received using a data companding algorithm.

Depending on the COMP[1:0] bits in the SAI_xCR2 register (used only when free protocol mode is selected), the application software can choose to process or not the data before sending it on the SD serial output line (compression) or to expand the data after the reception on the SD serial input line (expansion), as illustrated in Figure 392 . The two companding modes supported are the \( \mu \) -Law and the A-Law logs, which are a part of the CCITT G.711 recommendation.

The companding standard used in the United States and Japan is the \( \mu \) -Law. It supports 14 bits of dynamic range (COMP[1:0] = 10 in the SAI_xCR2 register).

The European companding standard is A-Law and supports 13 bits of dynamic range (COMP[1:0] = 11 in the SAI_xCR2 register).

Both \( \mu \) -Law and A-Law companding standard can be computed based on 1's complement or 2's complement representation, depending on the CPL bit setting in the SAI_xCR2 register.

In \( \mu \) -Law and A-Law standards, data are coded as 8 bits with MSB alignment. Companded data are always 8 bits wide. For this reason, the DS[2:0] bits in the SAI_xCR1 register are forced to 010 when the SAI audio block is enabled (the SAIEN bit = 1 in the SAI_xCR1 register) and when one of these two companding modes is selected through the COMP[1:0] bits.

If no companding processing is required, the COMP[1:0] bits must be kept clear.

Figure 392. Data companding hardware in an audio block in the SAI

Figure 392: Data companding hardware in an audio block in the SAI. The diagram shows two modes: Receiver mode (bit MODE[0] = 1 in SAI_xCR1) and Transmitter mode (bit MODE[0] = 0 in SAI_xCR1). In Receiver mode, data from the SD line enters a 32-bit shift register, then an 'expand' block, and finally a multiplexer controlled by COMP[1]. The output of the multiplexer goes to the FIFO. In Transmitter mode, data from the FIFO goes to a 'compress' block, then a multiplexer controlled by COMP[1], and finally a 32-bit shift register which outputs to the SD line.

The diagram illustrates the data flow for companding in the SAI audio block. It is divided into two sections: Receiver mode and Transmitter mode.

Figure 392: Data companding hardware in an audio block in the SAI. The diagram shows two modes: Receiver mode (bit MODE[0] = 1 in SAI_xCR1) and Transmitter mode (bit MODE[0] = 0 in SAI_xCR1). In Receiver mode, data from the SD line enters a 32-bit shift register, then an 'expand' block, and finally a multiplexer controlled by COMP[1]. The output of the multiplexer goes to the FIFO. In Transmitter mode, data from the FIFO goes to a 'compress' block, then a multiplexer controlled by COMP[1], and finally a 32-bit shift register which outputs to the SD line.
  1. 1. Not applicable when AC'97 or SPDIF are selected.

Expansion and compression mode are automatically selected through SAI_xCR2:

Output data line management on an inactive slot

In transmitter mode, it is possible to choose the behavior of the SD line output when an inactive slot is sent on the data line (via the TRIS bit).

It is important to note that the two transmitters cannot attempt to drive the same SD output pin simultaneously, which may result in a short circuit. To ensure a gap between transmissions, if the data is lower than 32-bit, the data can be extended to 32-bit by setting the bit SLOTSZ[1:0] = 10 in the SAI_xSLOTR register. The SD output pin is then tri-stated at the end of the LSB of the active slot (during the padding to 0 phase to extend the data to 32-bit) if the following slot is declared inactive.

In addition, if the number of slots multiplied by the slot size is lower than the frame length, the SD output line is tri-stated when the padding to 0 is done to complete the audio frame.

Figure 393 illustrates these behaviors.

Figure 393. Tristate strategy on SD output line on an inactive slot

Timing diagram showing tristate strategy on SD output line for two cases: frame length equal to number of slots, and frame length greater than number of slots. It shows the relationship between the sck signal, slot activation (ON/OFF), and the data output (Data 0, Data 1, Data m).

Bit TRIS = 1 in the SAI_xCR1 and frame length = number of slots

Audio frame

sck

Slot size = data size

slotSlot 0 ONSlot 1 OFFSlot 2 OFFSlot 3 ON.. ON.. ONSlot n ON

SD (output)

Data 0

Data 1

Data m

Slot size > data size

slotSlot 0 ONSlot 1 OFFSlot 2 OFFSlot 3 ON.. ON.. ONSlot n ON

SD (output)

Data 0

Data 1

Data m

slot

Slot 0 ONSlot 1 OFFSlot 2 OFFSlot 3 ON.. ON.. ONSlot n ON

SD (output)

Data 0

Data m

Bit TRIS = 1 in the SAI_xCR1 and frame length > number of slots

Audio frame

sck

Slot size = data size

slotSlot 0 ONSlot 1 OFFSlot 2 OFF.. ONSlot n ON

SD (output)

Data 0

Data m

Slot size > data size

slotSlot 0 ONSlot 1 OFFSlot 2 OFF.. ONSlot n ON

SD (output)

Data 0

Data m

slot

Slot 0 ONSlot 1 OFFSlot 2 OFF.. ON.. ON

SD (output)

Data m

MSV192345V1

Timing diagram showing tristate strategy on SD output line for two cases: frame length equal to number of slots, and frame length greater than number of slots. It shows the relationship between the sck signal, slot activation (ON/OFF), and the data output (Data 0, Data 1, Data m).

When the selected audio protocol uses the FS signal as a start of frame and a channel side identification (bit FSDEF = 1 in the SAI_xFRCR register), the tristate mode is managed according to Figure 394 (where the bit TRIS in the SAI_xCR1 register = 1, and FSDEF=1, and half frame length is higher than number of slots/2, and NBSLOT=6).

Figure 394. Tristate on output data line in a protocol like I2S

Timing diagram showing SAI output data lines (SD) in tristate mode. The diagram illustrates two scenarios: 'Slot size = data size' and 'Slot size > data size'. In both cases, the SD (output) line is shown as a series of data packets (Data 0, Data 1, Data 2, Data 3, ..., Data m) that are only active during the 'ON' slots. During the 'OFF' slots, the line is in a high-impedance (tristate) condition, indicated by a crossed-out line. The SCK line is shown as a continuous square wave. The diagram is labeled MSv192346V1.
Timing diagram showing SAI output data lines (SD) in tristate mode. The diagram illustrates two scenarios: 'Slot size = data size' and 'Slot size > data size'. In both cases, the SD (output) line is shown as a series of data packets (Data 0, Data 1, Data 2, Data 3, ..., Data m) that are only active during the 'ON' slots. During the 'OFF' slots, the line is in a high-impedance (tristate) condition, indicated by a crossed-out line. The SCK line is shown as a continuous square wave. The diagram is labeled MSv192346V1.

If the TRIS bit in the SAI_xCR2 register is cleared, all the high impedance states on the SD output line in Figure 393 and Figure 394 are replaced by a drive with a value of 0.

32.4.13 Error flags

The SAI implements the following error flags:

FIFO overrun/underrun (OVRUDR)

The FIFO overrun/underrun bit is called OVRUDR in the SAI_xSR register.

The overrun or underrun errors share the same bit since an audio block can be either receiver or transmitter and each audio block in a given SAI has its own SAI_xSR register.

Overrun

When the audio block is configured as receiver, an overrun condition may appear if data are received in an audio frame when the FIFO is full and not able to store the received data. In this case, the received data are lost, the OVRUDR flag in the SAI_xSR register is set, and an interrupt is generated if the OVRUDRIE bit is set in the SAI_xIM register. The slot number, from which the overrun occurs, is stored internally. No more data are stored into the FIFO until it becomes free to store new data. When the FIFO has at least one data free, the SAI audio block receiver stores new data (from a new audio frame) from the slot number that was stored internally when the overrun condition was detected. This avoids data slot dealignment in the destination memory (refer to Figure 395).

The OVRUDR flag is cleared when the COVRUDR bit is set in the SAI_xCLRFR register.

Figure 395. Overrun detection error

Timing diagram for Figure 395 showing an overrun detection error. The diagram includes four waveforms: sck (serial clock), data, FIFO full, and OVRUDR. The sck waveform is a periodic square wave. The data waveform shows a sequence of slots: Slot 0 ON, Slot 1 ON, Slot 1 ON (marked with a slash), Slot 0 ON, Slot 1 ON, Slot n ON (marked with a slash), and Slot n ON. The FIFO full waveform is a step function that goes high when the FIFO is full and low when it is not. The OVRUDR waveform is a step function that goes high when the overrun detection flag is set. The diagram shows that when the FIFO is full, new data for Slot 1 is discarded, and the OVRUDR flag is set. The text 'Received data discarded' is present, and 'COVRUDR = 1' is indicated at the end of the OVRUDR signal. The MSV192348V2 identifier is in the bottom right corner.

Example: FIFO overrun on Slot 1

MSV192348V2

Timing diagram for Figure 395 showing an overrun detection error. The diagram includes four waveforms: sck (serial clock), data, FIFO full, and OVRUDR. The sck waveform is a periodic square wave. The data waveform shows a sequence of slots: Slot 0 ON, Slot 1 ON, Slot 1 ON (marked with a slash), Slot 0 ON, Slot 1 ON, Slot n ON (marked with a slash), and Slot n ON. The FIFO full waveform is a step function that goes high when the FIFO is full and low when it is not. The OVRUDR waveform is a step function that goes high when the overrun detection flag is set. The diagram shows that when the FIFO is full, new data for Slot 1 is discarded, and the OVRUDR flag is set. The text 'Received data discarded' is present, and 'COVRUDR = 1' is indicated at the end of the OVRUDR signal. The MSV192348V2 identifier is in the bottom right corner.

Underrun

An underrun may occur when the audio block in the SAI is a transmitter and the FIFO is empty when data need to be transmitted. If an underrun is detected, the slot number for which the event occurs is stored and the MUTE value (00) is sent until the FIFO is ready to transmit the data corresponding to the slot for which the underrun was detected (refer to Figure 396 ). This avoids desynchronization between the memory pointer and the slot in the audio frame.

The underrun event sets the OVRUDR flag in the SAI_xSR register and an interrupt is generated if the OVRUDRIE bit is set in the SAI_xIM register. To clear this flag, set the COVRUDR bit in the SAI_xCLRFR register.

The underrun event can occur when the audio subblock is configured as master or slave.

Figure 396. FIFO underrun event

Timing diagram for Figure 396 showing a FIFO underrun event. The diagram includes four waveforms: sck (serial clock), data (SD output), FIFO empty, and OVRUND. The sck waveform is a periodic square wave. The data waveform shows a sequence of slots: Slot 0 ON, MUTE, MUTE (marked with a slash), MUTE, Slot 1 ON, ... ON (marked with a slash), and Slot 0 ON. A note indicates 'Slot size = data size'. The FIFO empty waveform is a step function that goes high when the FIFO is empty and low when it is not. The OVRUND waveform is a step function that goes high when the underrun event occurs and low when it is cleared. The diagram shows that when the FIFO is empty, the OVRUND flag is set. The text 'OVRUND=1' is indicated at the end of the OVRUND signal. The MSV192347V2 identifier is in the bottom right corner.

Example: FIFO underrun on Slot 1

MSV192347V2

Timing diagram for Figure 396 showing a FIFO underrun event. The diagram includes four waveforms: sck (serial clock), data (SD output), FIFO empty, and OVRUND. The sck waveform is a periodic square wave. The data waveform shows a sequence of slots: Slot 0 ON, MUTE, MUTE (marked with a slash), MUTE, Slot 1 ON, ... ON (marked with a slash), and Slot 0 ON. A note indicates 'Slot size = data size'. The FIFO empty waveform is a step function that goes high when the FIFO is empty and low when it is not. The OVRUND waveform is a step function that goes high when the underrun event occurs and low when it is cleared. The diagram shows that when the FIFO is empty, the OVRUND flag is set. The text 'OVRUND=1' is indicated at the end of the OVRUND signal. The MSV192347V2 identifier is in the bottom right corner.

Anticipated frame synchronization detection (AFSDET)

The AFSDET flag is used only in slave mode. It is never asserted in master mode. It indicates that a frame synchronization (FS) has been detected earlier than expected since the frame length, the frame polarity, and the frame offset are defined and known.

Anticipated frame detection sets the AFSDET flag in the SAI_xSR register.

This detection has no effect on the current audio frame, which is not sensitive to the anticipated FS. This means that “parasitic” events on signal FS are flagged without any perturbation of the current audio frame.

An interrupt is generated if the AFSDETIE bit is set in the SAI_xIM register. To clear the AFSDET flag, the CAFSDET bit must be set in the SAI_xCLRFR register.

To resynchronize with the master after an anticipated frame detection error, four steps are required:

  1. 1. Disable the SAI block by resetting the SAIEN bit in the SAI_xCR1 register. To make sure that the SAI is disabled, read back the SAIEN bit and check it is set to 0.
  2. 2. Flush the FIFO via the FFLUS bit in the SAI_xCR2 register.
  3. 3. Enable the SAI peripheral again (SAIEN bit set to 1).
  4. 4. The SAI block waits for the assertion on FS to restart the synchronization with master.

Note: The AFSDET flag is not asserted in AC'97 mode since the SAI audio block acts as a link controller and generates the FS signal even when declared as slave. It has no meaning in SPDIF mode since the FS signal is not used.

Late frame synchronization detection

The LFSDET flag in the SAI_xSR register can be set only when the SAI audio block operates as a slave. The frame length, the frame polarity, and the frame-offset configuration are known in register SAI_xFRCR.

If the external master does not send the FS signal at the expected time, thus generating the signal too late, the LFSDET flag is set and an interrupt is generated if the LFSDETIE bit is set in the SAI_xIM register.

The LFSDET flag is cleared when the CLFSDET bit is set in the SAI_xCLRFR register.

The late frame synchronization detection flag is set when the corresponding error is detected. The SAI needs to be resynchronized with the master (see sequence described in Anticipated frame synchronization detection (AFSDET) ).

In a noisy environment, glitches on the SCK clock may be wrongly detected by the audio block state machine and shift the SAI data at a wrong frame position. This event can be detected by the SAI and reported as a late frame synchronization detection error.

There is no corruption if the external master is not managing the audio data frame transfer in continuous mode, which must not be the case in most applications. In this case, the LFSDET flag is set.

Note: The LFSDET flag is not asserted in AC'97 mode since the SAI audio block acts as a link controller and generates the FS signal even when declared as slave. It has no meaning in SPDIF mode since the signal FS is not used by the protocol.

Codec not ready (CNRDY AC'97)

The CNRDY flag in the SAI_xSR register is relevant only if the SAI audio block is configured to operate in AC'97 mode (PRTCFCG[1:0] = 10 in the SAI_xCR1 register). If the CNRDYIE bit is set in the SAI_xIM register, an interrupt is generated when the CNRDY flag is set.

CNRDY is asserted when the codec is not ready to communicate during the reception of the TAG 0 (slot 0) of the AC'97 audio frame. In this case, no data are automatically stored into the FIFO since the codec is not ready, until the TAG 0 indicates that the codec is ready. All the active slots defined in the SAI_xSLOTR register are captured when the codec is ready.

To clear the CNRDY flag, the CCNRDY bit must be set in the SAI_xCLRFR register.

Wrong clock configuration in master mode (with NODIV = 0)

When the audio block operates as a master (MODE[1] = 0) and the NODIV bit is equal to 0, the WCKCFG flag is set as soon as the SAI is enabled if the following conditions are met:

The MODE, NODIV, and SAIEN bits belong to the SAI_xCR1 register and FRL to the SAI_xFRCR register.

If the WCKCFGIE bit is set, an interrupt is generated when the WCKCFG flag is set in the SAI_xSR register. To clear this flag, set the CWCKCFG bit in the SAI_xCLRFR register.

When the WCKCFG bit is set, the audio block is automatically disabled, thus performing a hardware clear of the SAIEN bit.

32.4.14 Disabling the SAI

The SAI audio block can be disabled at any moment by clearing the SAIEN bit in the SAI_xCR1 register. All the already started frames are automatically completed before the SAI stops working. The SAIEN bit remains high until the SAI is completely switched off at the end of the current audio frame transfer.

If an audio block in the SAI operates synchronously with the other one, the one that is the master must be disabled first.

32.4.15 SAI DMA interface

To free the CPU and to optimize bus bandwidth, each SAI audio block has an independent DMA interface to read/write from/to the SAI_xDR register (to access the internal FIFO). There is one DMA channel per audio subblock supporting the basic DMA request/acknowledge protocol.

To configure the audio subblock for DMA transfer, set the DMAEN bit in the SAI_xCR1 register. The DMA request is managed directly by the FIFO controller depending on the FIFO threshold level (for more details refer to Section 32.4.9: Internal FIFOs ). The DMA transfer direction is linked to the SAI audio subblock configuration:

Follow the sequence below to configure the SAI interface in DMA mode:

  1. 1. Configure the SAI and FIFO threshold levels to specify when the DMA request is launched.
  2. 2. Configure the SAI DMA channel.
  3. 3. Enable the DMA.
  4. 4. Enable the SAI interface.

32.5 SAI interrupts

The SAI supports 7 interrupt sources, as shown in Table 215 .

Table 215. SAI interrupt sources

Interrupt acronymInterrupt sourceInterrupt groupAudio block modeInterrupt enableInterrupt clear
SAIFREQFREQMaster or slave
Receiver or transmitter
FREQIE in SAI_xIM registerDepends on:
– FIFO threshold setting (FLVL bits in SAI_xCR2)
– Communication direction (transmitter or receiver)

For more details refer to Section 32.4.9: Internal FIFOs
OVRUDRERRORMaster or slave
Receiver or transmitter
OVRUDRIE in SAI_xIM registerCOVRUDR = 1 in SAI_xCLRFR register
AFSDETERRORSlave (not used in AC'97 mode and SPDIF mode)AFSDETIE in SAI_xIM registerCAFSDET = 1 in SAI_xCLRFR register
LFSDETERRORSlave (not used in AC'97 mode and SPDIF mode)LFSDETIE in SAI_xIM registerCLFSDET = 1 in SAI_xCLRFR register
CNRDYERRORSlave (only in AC'97 mode)CNRDYIE in SAI_xIM registerCCNRDY = 1 in SAI_xCLRFR register
MUTEDETMUTEMaster or slave
Receiver mode only
MUTEDETIE in SAI_xIM registerCMUTEDET = 1 in SAI_xCLRFR register
WCKCFGERRORMaster with NODIV = 0 in SAI_xCR1 registerWCKCFGIE in SAI_xIM registerCWCKCFG = 1 in SAI_xCLRFR register

Follow the sequence below to enable an interrupt:

  1. 1. Disable SAI interrupt.
  2. 2. Configure SAI.
  3. 3. Configure SAI interrupt source.
  4. 4. Enable SAI.

32.6 SAI registers

The peripheral registers have to be accessed by words (32 bits).

32.6.1 SAI configuration register 1 (SAI_ACR1)

Address offset: 0x04

Reset value: 0x0000 0040

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.MCKDIV[3:0]NODIVRes.DMAENSAIEN
rwrwrwrwrwrwrw

1514131211109876543210
Res.Res.OUTDIVMONOSYNCEN[1:0]CKSTRLSBFIRSTDS[2:0]Res.PRTCFCFG[1:0]MODE[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:24 Reserved, must be kept at reset value.

Bits 23:20 MCKDIV[3:0]: Master clock divider

These bits are set and cleared by software. These bits are meaningless when the audio block operates in slave mode. They have to be configured when the audio block is disabled.
0000: Divides by 1 the master clock input.

Others: the master clock frequency is calculated accordingly to the following formula:

\[ F_{SCK\_x} = \frac{F_{sai\_x\_ker\_ck}}{MCKDIV \times 2} \]

Bit 19 NODIV : No divider

This bit is set and cleared by software.

0: Master clock generator is enabled

1: No divider used in the clock generator (in this case Master Clock Divider bit has no effect)

Bit 18 Reserved, must be kept at reset value.

Bit 17 DMAEN : DMA enable

This bit is set and cleared by software.

0: DMA disabled

1: DMA enabled

Note: Since the audio block defaults to operate as a transmitter after reset, the MODE[1:0] bits must be configured before setting DMAEN to avoid a DMA request in receiver mode.

Bit 16 SAIEN : Audio block enable

This bit is set by software.

To switch off the audio block, the application software must program this bit to 0 and poll the bit till it reads back 0, meaning that the block is completely disabled. Before setting this bit to 1, check that it is set to 0, otherwise the enable command is not taken into account.

This bit enables to control the state of the SAI audio block. If it is disabled when an audio frame transfer is ongoing, the ongoing transfer completes and the cell is fully disabled at the end of this audio frame transfer.

0: SAI audio block disabled

1: SAI audio block enabled.

Note: When the SAI block (A or B) is configured in master mode, the clock must be present on the SAI block input before setting SAIEN bit.

Bits 15:14 Reserved, must be kept at reset value.

Bit 13 OUTDRIV : Output drive

This bit is set and cleared by software.

0: Audio block output driven when SAIEN is set

1: Audio block output driven immediately after the setting of this bit.

Note: This bit has to be set before enabling the audio block and after the audio block configuration.

Bit 12 MONO : Mono mode

This bit is set and cleared by software. It is meaningful only when the number of slots is equal to 2. When the mono mode is selected, slot 0 data are duplicated on slot 1 when the audio block operates as a transmitter. In reception mode, the slot1 is discarded and only the data received from slot 0 are stored. Refer to Section : Mono/stereo mode for more details.

0: Stereo mode

1: Mono mode.

Bits 11:10 SYNCEN[1:0] : Synchronization enable

These bits are set and cleared by software. They must be configured when the audio subblock is disabled.

00: audio subblock in asynchronous mode.

01: audio subblock is synchronous with the other internal audio subblock. In this case, the audio subblock must be configured in slave mode

10: Reserved.

11: Reserved

Note: The audio subblock must be configured as asynchronous when SPDIF mode is enabled.

Bit 9 CKSTR : Clock strobing edge

This bit is set and cleared by software. It must be configured when the audio block is disabled. This bit has no meaning in SPDIF audio protocol.

0: Signals generated by the SAI change on SCK rising edge, while signals received by the SAI are sampled on the SCK falling edge.

1: Signals generated by the SAI change on SCK falling edge, while signals received by the SAI are sampled on the SCK rising edge.

Bit 8 LSBFIRST : Least significant bit first

This bit is set and cleared by software. It must be configured when the audio block is disabled. This bit has no meaning in AC'97 audio protocol since AC'97 data are always transferred with the MSB first. This bit has no meaning in SPDIF audio protocol since in SPDIF data are always transferred with LSB first.

0: Data are transferred with MSB first

1: Data are transferred with LSB first

Bits 7:5 DS[2:0] : Data size

These bits are set and cleared by software. These bits are ignored when the SPDIF protocols are selected (bit PRTCFG[1:0]), because the frame and the data size are fixed in such case. When the companding mode is selected through COMP[1:0] bits, DS[1:0] are ignored since the data size is fixed to 8 bits by the algorithm.

These bits must be configured when the audio block is disabled.

000: Reserved

001: Reserved

010: 8 bits

011: 10 bits

100: 16 bits

101: 20 bits

110: 24 bits

111: 32 bits

Bit 4 Reserved, must be kept at reset value.

Bits 3:2 PRTCFCG[1:0] : Protocol configuration

These bits are set and cleared by software. These bits have to be configured when the audio block is disabled.

00: Free protocol. Free protocol enables to use the powerful configuration of the audio block to address a specific audio protocol (such as I2S, LSB/MSB justified, TDM, PCM/DSP...) by setting most of the configuration register bits as well as frame configuration register.

01: SPDIF protocol

10: AC'97 protocol

11: Reserved

Bits 1:0 MODE[1:0] : SAIx audio block mode

These bits are set and cleared by software. They must be configured when SAIx audio block is disabled.

00: Master transmitter

01: Master receiver

10: Slave transmitter

11: Slave receiver

Note: When the audio block is configured in SPDIF mode, the master transmitter mode is forced (MODE[1:0] = 00).

32.6.2 SAI configuration register 2 (SAI_ACR2)

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
COMP[1:0]CPLMUTECNT[5:0]MUTE VALMUTETRISF FLUSHFTH[2:0]
rwrwrwrwrwrwwrw

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:14 COMP[1:0] : Companding mode.

These bits are set and cleared by software. The \( \mu \) -Law and the A-Law log are a part of the CCITT G.711 recommendation, the type of complement that is used depends on CPL bit .

The data expansion or data compression are determined by the state of bit MODE[0].

The data compression is applied if the audio block is configured as a transmitter.

The data expansion is automatically applied when the audio block is configured as a receiver.

Refer to Section : Companding mode for more details.

00: No companding algorithm

01: Reserved.

10: \( \mu \) -Law algorithm

11: A-Law algorithm

Note: Companding mode is applicable only when Free protocol mode is selected.

Bit 13 CPL: Complement bit.

This bit is set and cleared by software.

It defines the type of complement to be used for companding mode

0: 1's complement representation.

1: 2's complement representation.

Note: This bit has effect only when the companding mode is \( \mu \) -Law algorithm or A-Law algorithm.

Bits 12:7 MUTECNT[5:0]: Mute counter.

These bits are set and cleared by software. They are used only in reception mode.

The value set in these bits is compared to the number of consecutive mute frames detected in reception. When the number of mute frames is equal to this value, the flag MUTEDET is set and an interrupt is generated if bit MUTEDETIE is set.

Refer to Section : Mute mode for more details.

Bit 6 MUTEVAL: Mute value.

This bit is set and cleared by software. It is meaningful only when the audio block operates as a transmitter, the number of slots is lower or equal to 2 and the MUTE bit is set.

If more slots are declared, the bit value sent during the transmission in mute mode is equal to 0, whatever the value of MUTEVAL.

if the number of slot is lower or equal to 2 and MUTEVAL = 1, the MUTE value transmitted for each slot is the one sent during the previous frame.

Refer to Section : Mute mode for more details.

0: Bit value 0 is sent during the mute mode.

1: Last values are sent during the mute mode.

Note: This bit is meaningless and must not be used for SPDIF audio blocks.

Bit 5 MUTE: Mute.

This bit is set and cleared by software. It is meaningful only when the audio block operates as a transmitter. The MUTE value is linked to value of MUTEVAL if the number of slots is lower or equal to 2, or equal to 0 if it is greater than 2.

Refer to Section : Mute mode for more details.

0: No mute mode.

1: Mute mode enabled.

Note: This bit is meaningless and must not be used for SPDIF audio blocks.

Bit 4 TRIS: Tristate management on data line.

This bit is set and cleared by software. It is meaningful only if the audio block is configured as a transmitter. This bit is not used when the audio block is configured in SPDIF mode. It must be configured when SAI is disabled.

Refer to Section : Output data line management on an inactive slot for more details.

0: SD output line is still driven by the SAI when a slot is inactive.

1: SD output line is released (HI-Z) at the end of the last data bit of the last active slot if the next one is inactive.

Bit 3 FFLUSH: FIFO flush.

This bit is set by software. It is always read as 0. This bit must be configured when the SAI is disabled.

0: No FIFO flush.

1: FIFO flush. Programming this bit to 1 triggers the FIFO Flush. All the internal FIFO pointers (read and write) are cleared. In this case data still present in the FIFO are lost (no more transmission or received data lost). Before flushing, SAI DMA stream/interrupt must be disabled

Bits 2:0 FTH[2:0] : FIFO threshold.

This bit is set and cleared by software.

000: FIFO empty

001: ¼ FIFO

010: ½ FIFO

011: ¾ FIFO

100: FIFO full

101: Reserved

110: Reserved

111: Reserved

32.6.3 SAI frame configuration register (SAI_AFRCR)

Address offset: 0x0C

Reset value: 0x0000 0007

Note: This register has no meaning in AC'97 and SPDIF audio protocol.

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.FSOFFFSPOLFSDEF
rwrwr

1514131211109876543210
Res.FSALL[6:0]FRL[7:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:19 Reserved, must be kept at reset value.

Bit 18 FSOFF : Frame synchronization offset.

This bit is set and cleared by software. It is meaningless and is not used in AC'97 or SPDIF audio block configuration. This bit must be configured when the audio block is disabled.

0: FS is asserted on the first bit of the slot 0.

1: FS is asserted one bit before the first bit of the slot 0.

Bit 17 FSPOL : Frame synchronization polarity.

This bit is set and cleared by software. It is used to configure the level of the start of frame on the FS signal. It is meaningless and is not used in AC'97 or SPDIF audio block configuration.

This bit must be configured when the audio block is disabled.

0: FS is active low (falling edge)

1: FS is active high (rising edge)

Bit 16 FSDEF : Frame synchronization definition.

This bit is set and cleared by software.

0: FS signal is a start frame signal

1: FS signal is a start of frame signal + channel side identification

When the bit is set, the number of slots defined in the SAI_xSLOTR register has to be even. It means that half of this number of slots are dedicated to the left channel and the other slots for the right channel (e.g: this bit has to be set for I2S or MSB/LSB-justified protocols...).

This bit is meaningless and is not used in AC'97 or SPDIF audio block configuration. It must be configured when the audio block is disabled.

Bit 15 Reserved, must be kept at reset value.

Bits 14:8 FSALL[6:0] : Frame synchronization active level length.

These bits are set and cleared by software. They specify the length in number of bit clock (SCK) + 1 (FSALL[6:0] + 1) of the active level of the FS signal in the audio frame

These bits are meaningless and are not used in AC'97 or SPDIF audio block configuration.

They must be configured when the audio block is disabled.

Bits 7:0 FRL[7:0] : Frame length.

These bits are set and cleared by software. They define the audio frame length expressed in number of SCK clock cycles: the number of bits in the frame is equal to FRL[7:0] + 1.

The minimum number of bits to transfer in an audio frame must be equal to 8, otherwise the audio block behaves in an unexpected way. This is the case when the data size is 8 bits and only one slot 0 is defined in NBSLOT[4:0] of SAI_xSLOTR register (NBSLOT[3:0] = 0000).

In master mode, if the master clock (available on MCLK_x pin) is used, the frame length must be aligned with a number equal to a power of 2, ranging from 8 to 256. When the master clock is not used (NODIV = 1), it is recommended to program the frame length to an value ranging from 8 to 256.

These bits are meaningless and are not used in AC'97 or SPDIF audio block configuration. They must be configured when the audio block is disabled.

32.6.4 SAI slot register (SAI_ASLOTR)

Address offset: 0x10

Reset value: 0x0000 0000

Note: This register has no meaning in AC'97 and SPDIF audio protocol.

31302928272625242322212019181716
SLOTEN[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.NBSLOT[3:0]SLOTSZ[1:0]Res.FBOFF[4:0]
rwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 SLOTEN[15:0] : Slot enable.

These bits are set and cleared by software.

Each SLOTEN bit corresponds to a slot position from 0 to 15 (maximum 16 slots).

0: Inactive slot.

1: Active slot.

The slot must be enabled when the audio block is disabled.

They are ignored in AC'97 or SPDIF mode.

Bits 15:12 Reserved, must be kept at reset value.

Bits 11:8 NBSLOT[3:0] : Number of slots in an audio frame.

These bits are set and cleared by software.

The value set in this bitfield represents the number of slots + 1 in the audio frame (including the number of inactive slots). The maximum number of slots is 16.

The number of slots must be even if FSDEF bit in the SAI_xFRCR register is set.

The number of slots must be configured when the audio block is disabled.

They are ignored in AC'97 or SPDIF mode.

Bits 7:6 SLOTSZ[1:0] : Slot size

This bits is set and cleared by software.

The slot size must be higher or equal to the data size. If this condition is not respected, the behavior of the SAI is undetermined.

Refer to Output data line management on an inactive slot for information on how to drive SD line.

These bits must be set when the audio block is disabled.

They are ignored in AC'97 or SPDIF mode.

00: The slot size is equivalent to the data size (specified in DS[3:0] in the SAI_xCR1 register).

01: 16-bit

10: 32-bit

11: Reserved

Bit 5 Reserved, must be kept at reset value.

Bits 4:0 FBOFF[4:0] : First bit offset

These bits are set and cleared by software.

The value set in this bitfield defines the position of the first data transfer bit in the slot. It represents an offset value. In transmission mode, the bits outside the data field are forced to 0. In reception mode, the extra received bits are discarded.

These bits must be set when the audio block is disabled.

They are ignored in AC'97 or SPDIF mode.

32.6.5 SAI interrupt mask register (SAI_AIM)

Address offset: 0x14

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.LFSDETI
IE
AFSDETI
E
CNRDY
IE
FREQ
IE
WCKCFG
IE
MUTEDET
IE
OVRUDR
IE
rwrwrwrwrwrwrw

Bits 31:7 Reserved, must be kept at reset value.

Bit 6 LFSDETI : Late frame synchronization detection interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When this bit is set, an interrupt is generated if the LFSDET bit is set in the SAI_xSR register.

This bit is meaningless in AC'97, SPDIF mode or when the audio block operates as a master.

Bit 5 AFSDETI : Anticipated frame synchronization detection interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When this bit is set, an interrupt is generated if the AFSDET bit in the SAI_xSR register is set.

This bit is meaningless in AC'97, SPDIF mode or when the audio block operates as a master.

Bit 4 CNRDYIE : Codec not ready interrupt enable (AC'97).

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When the interrupt is enabled, the audio block detects in the slot 0 (tag0) of the AC'97 frame if the Codec connected to this line is ready or not. If it is not ready, the CNRDY flag in the SAI_xSR register is set and an interrupt is generated.

This bit has a meaning only if the AC'97 mode is selected through PRTCFG[1:0] bits and the audio block is operates as a receiver.

Bit 3 FREQIE : FIFO request interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When this bit is set, an interrupt is generated if the FREQ bit in the SAI_xSR register is set.

Since the audio block defaults to operate as a transmitter after reset, the MODE bit must be configured before setting FREQIE to avoid a parasitic interrupt in receiver mode,

Bit 2 WCKCFGIE : Wrong clock configuration interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

This bit is taken into account only if the audio block is configured as a master (MODE[1] = 0) and NODIV = 0.

It generates an interrupt if the WCKCFG flag in the SAI_xSR register is set.

Note: This bit is used only in Free protocol mode and is meaningless in other modes.

Bit 1 MUTEDETIE : Mute detection interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When this bit is set, an interrupt is generated if the MUTEDET bit in the SAI_xSR register is set.

This bit has a meaning only if the audio block is configured in receiver mode.

Bit 0 OVRUDRIE : Overrun/underrun interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When this bit is set, an interrupt is generated if the OVRUDR bit in the SAI_xSR register is set.

32.6.6 SAI status register (SAI_ASR)

Address offset: 0x18

Reset value: 0x0000 0008

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.FLVL[2:0]
rrr
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.LFSDETAFSDETCNRDYFREQWCKCFGMUTEDETOVRUDR
rrrrrrr

Bits 31:19 Reserved, must be kept at reset value.

Bits 18:16 FLVL[2:0] : FIFO level threshold.

This bit is read only. The FIFO level threshold flag is managed only by hardware and its setting depends on SAI block configuration (transmitter or receiver mode).

000: FIFO empty (transmitter and receiver modes)

001: FIFO \( \leq \frac{1}{4} \) but not empty (transmitter mode), FIFO \( < \frac{1}{4} \) but not empty (receiver mode)

010: \( \frac{1}{4} < \text{FIFO} \leq \frac{1}{2} \) (transmitter mode), \( \frac{1}{4} \leq \text{FIFO} < \frac{1}{2} \) (receiver mode)

011: \( \frac{1}{2} < \text{FIFO} \leq \frac{3}{4} \) (transmitter mode), \( \frac{1}{2} \leq \text{FIFO} < \frac{3}{4} \) (receiver mode)

100: \( \frac{3}{4} < \text{FIFO} \) but not full (transmitter mode), \( \frac{3}{4} \leq \text{FIFO} \) but not full (receiver mode)

101: FIFO full (transmitter and receiver modes)

Others: Reserved

Bits 15:7 Reserved, must be kept at reset value.

Bit 6 LFSDET : Late frame synchronization detection.

This bit is read only.

0: No error.

1: Frame synchronization signal is not present at the right time.

This flag can be set only if the audio block is configured in slave mode.

It is not used in AC'97 or SPDIF mode.

It can generate an interrupt if LFSDETIE bit is set in the SAI_xIM register.

This flag is cleared when the software sets bit CLFSDET in SAI_xCLRFR register

Bit 5 AFSDET : Anticipated frame synchronization detection.

This bit is read only.

0: No error.

1: Frame synchronization signal is detected earlier than expected.

This flag can be set only if the audio block is configured in slave mode.

It is not used in AC'97 or SPDIF mode.

It can generate an interrupt if AFSDETIE bit is set in SAI_xIM register.

This flag is cleared when the software sets CAFSDET bit in SAI_xCLRFR register.

Bit 4 CNRDY : Codec not ready.

This bit is read only.

0: External AC'97 Codec is ready

1: External AC'97 Codec is not ready

This bit is used only when the AC'97 audio protocol is selected in the SAI_xCR1 register and configured in receiver mode.

It can generate an interrupt if CNRDYIE bit is set in SAI_xIM register.

This flag is cleared when the software sets CCNRDY bit in SAI_xCLRFR register.

Bit 3 FREQ : FIFO request.

This bit is read only.

0: No FIFO request.

1: FIFO request to read or to write the SAI_xDR.

The request depends on the audio block configuration:

This flag can generate an interrupt if FREQIE bit is set in SAI_xIM register.

Bit 2 WCKCFG : Wrong clock configuration flag.

This bit is read only.

0: Clock configuration is correct

1: Clock configuration does not respect the rule concerning the frame length specification defined in Section 32.4.6: Frame synchronization (configuration of FRL[7:0] bit in the SAI_xFRCR register)

This bit is used only when the audio block operates in master mode (MODE[1] = 0) and NODIV = 0.

It can generate an interrupt if WCKCFGIE bit is set in SAI_xIM register.

This flag is cleared when the software sets CWCKCFG bit in SAI_xCLRFR register.

Bit 1 MUTEDET : Mute detection.

This bit is read only.

0: No MUTE detection on the SD input line

1: MUTE value detected on the SD input line (0 value) for a specified number of consecutive audio frame

This flag is set if consecutive 0 values are received in each slot of a given audio frame and for a consecutive number of audio frames (set in the MUTECNT bit in the SAI_xCR2 register).

It can generate an interrupt if MUTEDETIE bit is set in SAI_xIM register.

This flag is cleared when the software sets bit CMUTEDET in the SAI_xCLRFR register.

Bit 0 OVRUDR : Overrun / underrun.

This bit is read only.

0: No overrun/underrun error.

1: Overrun/underrun error detection.

The overrun and underrun conditions can occur only when the audio block is configured as a receiver and a transmitter, respectively.

It can generate an interrupt if OVRUDRIE bit is set in SAI_xIM register.

This flag is cleared when the software sets COVRUDR bit in SAI_xCLRFR register.

32.6.7 SAI clear flag register (SAI_ACLRFR)

Address offset: 0x1C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.CLFSDDETCAFSDETCCNRDYRes.CWCKCFGCMUTEDETCOVRUDR
wwwwww

Bits 31:7 Reserved, must be kept at reset value.

Bit 6 CLFSDDET : Clear late frame synchronization detection flag.

This bit is write only.

Programming this bit to 1 clears the LFSDET flag in the SAI_xSR register.

This bit is not used in AC'97 or SPDIF mode

Reading this bit always returns the value 0.

32.6.8 SAI data register (SAI_ADR)

Address offset: 0x20

Reset value: 0x0000 0000

31302928272625242322212019181716
DATA[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
DATA[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 DATA[31:0] : Data

A write to this register loads the FIFO provided the FIFO is not full.
A read from this register empties the FIFO if the FIFO is not empty.

32.6.9 SAI configuration register 1 (SAI_BCR1)

Address offset: 0x24

Reset value: 0x0000 0040

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.MCKDIV[3:0]NODIVRes.DMAENSAIEN
rwrwrwrwrwrwrw

1514131211109876543210
Res.Res.OUTDRIVMONOSYNCEN[1:0]CKSTRLSBFIRSTDS[2:0]Res.PRTCFCFG[1:0]MODE[1:0]
rwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:24 Reserved, must be kept at reset value.

Bits 23:20 MCKDIV[3:0]: Master clock divider

These bits are set and cleared by software. These bits are meaningless when the audio block operates in slave mode. They have to be configured when the audio block is disabled.

0000: Divides by 1 the master clock input.

Others: the master clock frequency is calculated accordingly to the following formula:

\[ F_{SCK\_x} = \frac{F_{sai\_x\_ker\_ck}}{MCKDIV \times 2} \]

Bit 19 NODIV : No divider

This bit is set and cleared by software.

0: Master clock generator is enabled

1: No divider used in the clock generator (in this case Master Clock Divider bit has no effect)

Bit 18 Reserved, must be kept at reset value.

Bit 17 DMAEN : DMA enable

This bit is set and cleared by software.

0: DMA disabled

1: DMA enabled

Note: Since the audio block defaults to operate as a transmitter after reset, the MODE[1:0] bits must be configured before setting DMAEN to avoid a DMA request in receiver mode.

Bit 16 SAIEN : Audio block enable

This bit is set by software.

To switch off the audio block, the application software must program this bit to 0 and poll the bit till it reads back 0, meaning that the block is completely disabled. Before setting this bit to 1, check that it is set to 0, otherwise the enable command is not taken into account.

This bit enables to control the state of the SAI audio block. If it is disabled when an audio frame transfer is ongoing, the ongoing transfer completes and the cell is fully disabled at the end of this audio frame transfer.

0: SAI audio block disabled

1: SAI audio block enabled.

Note: When the SAI block (A or B) is configured in master mode, the clock must be present on the SAI block input before setting SAIEN bit.

Bits 15:14 Reserved, must be kept at reset value.

Bit 13 OUTDRIV : Output drive

This bit is set and cleared by software.

0: Audio block output driven when SAIEN is set

1: Audio block output driven immediately after the setting of this bit.

Note: This bit has to be set before enabling the audio block and after the audio block configuration.

Bit 12 MONO : Mono mode

This bit is set and cleared by software. It is meaningful only when the number of slots is equal to 2. When the mono mode is selected, slot 0 data are duplicated on slot 1 when the audio block operates as a transmitter. In reception mode, the slot1 is discarded and only the data received from slot 0 are stored. Refer to Section : Mono/stereo mode for more details.

0: Stereo mode

1: Mono mode.

Bits 11:10 SYNCEN[1:0] : Synchronization enable

These bits are set and cleared by software. They must be configured when the audio subblock is disabled.

00: audio subblock in asynchronous mode.

01: audio subblock is synchronous with the other internal audio subblock. In this case, the audio subblock must be configured in slave mode

10: Reserved.

11: Reserved

Note: The audio subblock must be configured as asynchronous when SPDIF mode is enabled.

Bit 9 CKSTR : Clock strobing edge

This bit is set and cleared by software. It must be configured when the audio block is disabled. This bit has no meaning in SPDIF audio protocol.

0: Signals generated by the SAI change on SCK rising edge, while signals received by the SAI are sampled on the SCK falling edge.

1: Signals generated by the SAI change on SCK falling edge, while signals received by the SAI are sampled on the SCK rising edge.

Bit 8 LSBFIRST : Least significant bit first

This bit is set and cleared by software. It must be configured when the audio block is disabled. This bit has no meaning in AC'97 audio protocol since AC'97 data are always transferred with the MSB first. This bit has no meaning in SPDIF audio protocol since in SPDIF data are always transferred with LSB first.

0: Data are transferred with MSB first

1: Data are transferred with LSB first

Bits 7:5 DS[2:0] : Data size

These bits are set and cleared by software. These bits are ignored when the SPDIF protocols are selected (bit PRTCFCFG[1:0]), because the frame and the data size are fixed in such case. When the companding mode is selected through COMP[1:0] bits, DS[1:0] are ignored since the data size is fixed to 8 bits by the algorithm.

These bits must be configured when the audio block is disabled.

000: Reserved

001: Reserved

010: 8 bits

011: 10 bits

100: 16 bits

101: 20 bits

110: 24 bits

111: 32 bits

Bit 4 Reserved, must be kept at reset value.

Bits 3:2 PRTCFG[1:0] : Protocol configuration

These bits are set and cleared by software. These bits have to be configured when the audio block is disabled.

00: Free protocol. Free protocol enables to use the powerful configuration of the audio block to address a specific audio protocol (such as I2S, LSB/MSB justified, TDM, PCM/DSP...) by setting most of the configuration register bits as well as frame configuration register.

01: SPDIF protocol

10: AC'97 protocol

11: Reserved

Bits 1:0 MODE[1:0] : SAIx audio block mode

These bits are set and cleared by software. They must be configured when SAIx audio block is disabled.

00: Master transmitter

01: Master receiver

10: Slave transmitter

11: Slave receiver

Note: When the audio block is configured in SPDIF mode, the master transmitter mode is forced (MODE[1:0] = 00). In Master transmitter mode, the audio block starts generating the FS and the clocks immediately.

32.6.10 SAI configuration register 2 (SAI_BCR2)

Address offset: 0x28

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
COMP[1:0]CPLMUTECNT[5:0]MUTE VALMUTETRISF FLUSHFTH[2:0]
rwrwrwrwrwrwrwrwrwrwrwrwwrwrwrw

Bits 31:16 Reserved, must be kept at reset value.

Bits 15:14 COMP[1:0] : Companding mode.

These bits are set and cleared by software. The \( \mu \) -Law and the A-Law log are a part of the CCITT G.711 recommendation, the type of complement that is used depends on CPL bit .

The data expansion or data compression are determined by the state of bit MODE[0].

The data compression is applied if the audio block is configured as a transmitter.

The data expansion is automatically applied when the audio block is configured as a receiver.

Refer to Section : Companding mode for more details.

00: No companding algorithm

01: Reserved.

10: \( \mu \) -Law algorithm

11: A-Law algorithm

Note: Companding mode is applicable only when Free protocol mode is selected.

Bit 13 CPL: Complement bit.

This bit is set and cleared by software.

It defines the type of complement to be used for companding mode

0: 1's complement representation.

1: 2's complement representation.

Note: This bit has effect only when the companding mode is \( \mu \) -Law algorithm or A-Law algorithm.

Bits 12:7 MUTE CNT[5:0]: Mute counter.

These bits are set and cleared by software. They are used only in reception mode.

The value set in these bits is compared to the number of consecutive mute frames detected in reception. When the number of mute frames is equal to this value, the flag MUTEDET is set and an interrupt is generated if bit MUTEDETIE is set.

Refer to Section : Mute mode for more details.

Bit 6 MUTE VAL: Mute value.

This bit is set and cleared by software. It is meaningful only when the audio block operates as a transmitter, the number of slots is lower or equal to 2 and the MUTE bit is set.

If more slots are declared, the bit value sent during the transmission in mute mode is equal to 0, whatever the value of MUTE VAL.

if the number of slot is lower or equal to 2 and MUTE VAL = 1, the MUTE value transmitted for each slot is the one sent during the previous frame.

Refer to Section : Mute mode for more details.

0: Bit value 0 is sent during the mute mode.

1: Last values are sent during the mute mode.

Note: This bit is meaningless and must not be used for SPDIF audio blocks.

Bit 5 MUTE: Mute.

This bit is set and cleared by software. It is meaningful only when the audio block operates as a transmitter. The MUTE value is linked to value of MUTE VAL if the number of slots is lower or equal to 2, or equal to 0 if it is greater than 2.

Refer to Section : Mute mode for more details.

0: No mute mode.

1: Mute mode enabled.

Note: This bit is meaningless and must not be used for SPDIF audio blocks.

Bit 4 TRIS: Tristate management on data line.

This bit is set and cleared by software. It is meaningful only if the audio block is configured as a transmitter. This bit is not used when the audio block is configured in SPDIF mode. It must be configured when SAI is disabled.

Refer to Section : Output data line management on an inactive slot for more details.

0: SD output line is still driven by the SAI when a slot is inactive.

1: SD output line is released (HI-Z) at the end of the last data bit of the last active slot if the next one is inactive.

Bit 3 FFLUSH: FIFO flush.

This bit is set by software. It is always read as 0. This bit must be configured when the SAI is disabled.

0: No FIFO flush.

1: FIFO flush. Programming this bit to 1 triggers the FIFO Flush. All the internal FIFO pointers (read and write) are cleared. In this case data still present in the FIFO are lost (no more transmission or received data lost). Before flushing, SAI DMA stream/interrupt must be disabled

Bits 2:0 FTH[2:0] : FIFO threshold.

This bit is set and cleared by software.

000: FIFO empty

001: ¼ FIFO

010: ½ FIFO

011: ¾ FIFO

100: FIFO full

101: Reserved

110: Reserved

111: Reserved

32.6.11 SAI frame configuration register (SAI_BFCR)

Address offset: 0x2C

Reset value: 0x0000 0007

Note: This register has no meaning in AC'97 and SPDIF audio protocol

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.FSOFFFSPOLFSDEF
rwrwr
1514131211109876543210
Res.FSALL[6:0]FRL[7:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:19 Reserved, must be kept at reset value.

Bit 18 FSOFF : Frame synchronization offset.

This bit is set and cleared by software. It is meaningless and is not used in AC'97 or SPDIF audio block configuration. This bit must be configured when the audio block is disabled.

0: FS is asserted on the first bit of the slot 0.

1: FS is asserted one bit before the first bit of the slot 0.

Bit 17 FSPOL : Frame synchronization polarity.

This bit is set and cleared by software. It is used to configure the level of the start of frame on the FS signal. It is meaningless and is not used in AC'97 or SPDIF audio block configuration.

This bit must be configured when the audio block is disabled.

0: FS is active low (falling edge)

1: FS is active high (rising edge)

Bit 16 FSDEF : Frame synchronization definition.

This bit is set and cleared by software.

0: FS signal is a start frame signal

1: FS signal is a start of frame signal + channel side identification

When the bit is set, the number of slots defined in the SAI_xSLOTR register has to be even. It means that half of this number of slots is dedicated to the left channel and the other slots for the right channel (e.g: this bit has to be set for I2S or MSB/LSB-justified protocols...).

This bit is meaningless and is not used in AC'97 or SPDIF audio block configuration. It must be configured when the audio block is disabled.

Bit 15 Reserved, must be kept at reset value.

Bits 14:8 FSALL[6:0] : Frame synchronization active level length.

These bits are set and cleared by software. They specify the length in number of bit clock (SCK) + 1 (FSALL[6:0] + 1) of the active level of the FS signal in the audio frame

These bits are meaningless and are not used in AC'97 or SPDIF audio block configuration.

They must be configured when the audio block is disabled.

Bits 7:0 FRL[7:0] : Frame length.

These bits are set and cleared by software. They define the audio frame length expressed in number of SCK clock cycles: the number of bits in the frame is equal to FRL[7:0] + 1.

The minimum number of bits to transfer in an audio frame must be equal to 8, otherwise the audio block behaves in an unexpected way. This is the case when the data size is 8 bits and only one slot 0 is defined in NBSLOT[4:0] of SAI_xSLOTR register (NBSLOT[3:0] = 0000).

In master mode, if the master clock (available on MCLK_x pin) is used, the frame length must be aligned with a number equal to a power of 2, ranging from 8 to 256. When the master clock is not used (NODIV = 1), it is recommended to program the frame length to an value ranging from 8 to 256.

These bits are meaningless and are not used in AC'97 or SPDIF audio block configuration.

32.6.12 SAI slot register (SAI_BLOTR)

Address offset: 0x30

Reset value: 0x0000 0000

Note: This register has no meaning in AC'97 and SPDIF audio protocol.

31302928272625242322212019181716
SLOTEN[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
Res.Res.Res.Res.NBSLOT[3:0]SLOTSZ[1:0]Res.FBOFF[4:0]
rwrwrwrwrwrwrwrwrwrwrw

Bits 31:16 SLOTEN[15:0] : Slot enable.

These bits are set and cleared by software.

Each SLOTEN bit corresponds to a slot position from 0 to 15 (maximum 16 slots).

0: Inactive slot.

1: Active slot.

The slot must be enabled when the audio block is disabled.

They are ignored in AC'97 or SPDIF mode.

Bits 15:12 Reserved, must be kept at reset value.

Bits 11:8 NBSLOT[3:0] : Number of slots in an audio frame.

These bits are set and cleared by software.

The value set in this bitfield represents the number of slots + 1 in the audio frame (including the number of inactive slots). The maximum number of slots is 16.

The number of slots must be even if FSDEF bit in the SAI_xFRCR register is set.

The number of slots must be configured when the audio block is disabled.

They are ignored in AC'97 or SPDIF mode.

Bits 7:6 SLOTSZ[1:0] : Slot size

This bits is set and cleared by software.

The slot size must be higher or equal to the data size. If this condition is not respected, the behavior of the SAI is undetermined.

Refer to Output data line management on an inactive slot for information on how to drive SD line.

These bits must be set when the audio block is disabled.

They are ignored in AC'97 or SPDIF mode.

00: The slot size is equivalent to the data size (specified in DS[3:0] in the SAI_xCR1 register).

01: 16-bit

10: 32-bit

11: Reserved

Bit 5 Reserved, must be kept at reset value.

Bits 4:0 FBOFF[4:0] : First bit offset

These bits are set and cleared by software.

The value set in this bitfield defines the position of the first data transfer bit in the slot. It represents an offset value. In transmission mode, the bits outside the data field are forced to 0. In reception mode, the extra received bits are discarded.

These bits must be set when the audio block is disabled.

They are ignored in AC'97 or SPDIF mode.

32.6.13 SAI interrupt mask register (SAI_BIM)

Address offset: 0x34

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.LFSDET IEAFSDET IECNRDY IEFREQ IEWCKCFG IEMUTEDET IEOVRUDR IE
rwrwrwrwrwrwrw

Bits 31:7 Reserved, must be kept at reset value.

Bit 6 LFSDETIE : Late frame synchronization detection interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When this bit is set, an interrupt is generated if the LFSDET bit is set in the SAI_xSR register.

This bit is meaningless in AC'97, SPDIF mode or when the audio block operates as a master.

Bit 5 AFSDETIE : Anticipated frame synchronization detection interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When this bit is set, an interrupt is generated if the AFSDET bit in the SAI_xSR register is set.

This bit is meaningless in AC'97, SPDIF mode or when the audio block operates as a master.

Bit 4 CNRDYIE : Codec not ready interrupt enable (AC'97).

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When the interrupt is enabled, the audio block detects in the slot 0 (tag0) of the AC'97 frame if the Codec connected to this line is ready or not. If it is not ready, the CNRDY flag in the SAI_xSR register is set and an interrupt is generated.

This bit has a meaning only if the AC'97 mode is selected through PRTCFG[1:0] bits and the audio block is operates as a receiver.

Bit 3 FREQIE : FIFO request interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When this bit is set, an interrupt is generated if the FREQ bit in the SAI_xSR register is set.

Since the audio block defaults to operate as a transmitter after reset, the MODE bit must be configured before setting FREQIE to avoid a parasitic interrupt in receiver mode,

Bit 2 WCKCFGIE : Wrong clock configuration interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

This bit is taken into account only if the audio block is configured as a master (MODE[1] = 0) and NODIV = 0.

It generates an interrupt if the WCKCFG flag in the SAI_xSR register is set.

Note: This bit is used only in Free protocol mode and is meaningless in other modes.

Bit 1 MUTEDETIE : Mute detection interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When this bit is set, an interrupt is generated if the MUTEDET bit in the SAI_xSR register is set.

This bit has a meaning only if the audio block is configured in receiver mode.

Bit 0 OVRUDRIE : Overrun/underrun interrupt enable.

This bit is set and cleared by software.

0: Interrupt is disabled

1: Interrupt is enabled

When this bit is set, an interrupt is generated if the OVRUDR bit in the SAI_xSR register is set.

32.6.14 SAI status register (SAI_BSR)

Address offset: 0x38

Reset value: 0x0000 0008

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.FLVL[2:0]
rrr
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.LFSDETAFSDETCNRDYFREQWCKCFGMUTEDETOVRUDR
rrrrrrr

Bits 31:19 Reserved, must be kept at reset value.

Bits 18:16 FLVL[2:0] : FIFO level threshold.

This bit is read only. The FIFO level threshold flag is managed only by hardware and its setting depends on SAI block configuration (transmitter or receiver mode).

000: FIFO empty (transmitter and receiver modes)

001: FIFO \( \leq \frac{1}{4} \) but not empty (transmitter mode), FIFO \( < \frac{1}{4} \) but not empty (receiver mode)

010: \( \frac{1}{4} < \text{FIFO} \leq \frac{1}{2} \) (transmitter mode), \( \frac{1}{4} \leq \text{FIFO} < \frac{1}{2} \) (receiver mode)

011: \( \frac{1}{2} < \text{FIFO} \leq \frac{3}{4} \) (transmitter mode), \( \frac{1}{2} \leq \text{FIFO} < \frac{3}{4} \) (receiver mode)

100: \( \frac{3}{4} < \text{FIFO} \) but not full (transmitter mode), \( \frac{3}{4} \leq \text{FIFO} \) but not full (receiver mode)

101: FIFO full (transmitter and receiver modes)

Others: Reserved

Bits 15:7 Reserved, must be kept at reset value.

Bit 6 LFSDET : Late frame synchronization detection.

This bit is read only.

0: No error.

1: Frame synchronization signal is not present at the right time.

This flag can be set only if the audio block is configured in slave mode.

It is not used in AC'97 or SPDIF mode.

It can generate an interrupt if LFSDETIE bit is set in the SAI_xIM register.

This flag is cleared when the software sets bit CLFSDET in SAI_xCLRFR register

Bit 5 AFSDET : Anticipated frame synchronization detection.

This bit is read only.

0: No error.

1: Frame synchronization signal is detected earlier than expected.

This flag can be set only if the audio block is configured in slave mode.

It is not used in AC'97 or SPDIF mode.

It can generate an interrupt if AFSDETIE bit is set in SAI_xIM register.

This flag is cleared when the software sets CAFSDET bit in SAI_xCLRFR register.

Bit 4 CNRDY : Codec not ready.

This bit is read only.

0: External AC'97 Codec is ready

1: External AC'97 Codec is not ready

This bit is used only when the AC'97 audio protocol is selected in the SAI_xCR1 register and configured in receiver mode.

It can generate an interrupt if CNRDYIE bit is set in SAI_xIM register.

This flag is cleared when the software sets CCNRDY bit in SAI_xCLRFR register.

Bit 3 FREQ : FIFO request.

This bit is read only.

0: No FIFO request.

1: FIFO request to read or to write the SAI_xDR.

The request depends on the audio block configuration:

This flag can generate an interrupt if FREQIE bit is set in SAI_xIM register.

Bit 2 WCKCFG : Wrong clock configuration flag.

This bit is read only.

0: Clock configuration is correct

1: Clock configuration does not respect the rule concerning the frame length specification defined in Section 32.4.6: Frame synchronization (configuration of FRL[7:0] bit in the SAI_xFRCR register)

This bit is used only when the audio block operates in master mode (MODE[1] = 0) and NODIV = 0.

It can generate an interrupt if WCKCFGIE bit is set in SAI_xIM register.

This flag is cleared when the software sets CWCKCFG bit in SAI_xCLRFR register.

Bit 1 MUTEDET : Mute detection.

This bit is read only.

0: No MUTE detection on the SD input line

1: MUTE value detected on the SD input line (0 value) for a specified number of consecutive audio frame

This flag is set if consecutive 0 values are received in each slot of a given audio frame and for a consecutive number of audio frames (set in the MUTECNT bit in the SAI_xCR2 register).

It can generate an interrupt if MUTEDETIE bit is set in SAI_xIM register.

This flag is cleared when the software sets bit CMUTEDET in the SAI_xCLRFR register.

Bit 0 OVRUDR : Overrun / underrun.

This bit is read only.

0: No overrun/underrun error.

1: Overrun/underrun error detection.

The overrun and underrun conditions can occur only when the audio block is configured as a receiver and a transmitter, respectively.

It can generate an interrupt if OVRUDRIE bit is set in SAI_xIM register.

This flag is cleared when the software sets COVRUDR bit in SAI_xCLRFR register.

32.6.15 SAI clear flag register (SAI_BCLRFR)

Address offset: 0x3C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.CLFSDDETCAFSDETCCNRDYRes.CWCKCFGCMUTEDETCOVRUDR
wwwwww

Bits 31:7 Reserved, must be kept at reset value.

Bit 6 CLFSDET : Clear late frame synchronization detection flag.

This bit is write only.

Programming this bit to 1 clears the LFSDET flag in the SAI_xSR register.

This bit is not used in AC’97or SPDIF mode

Reading this bit always returns the value 0.

Bit 5 CAFSDET : Clear anticipated frame synchronization detection flag.

This bit is write only.

Programming this bit to 1 clears the AFSDET flag in the SAI_xSR register.

It is not used in AC’97or SPDIF mode.

Reading this bit always returns the value 0.

Bit 4 CCNRDY : Clear Codec not ready flag.

This bit is write only.

Programming this bit to 1 clears the CNRDY flag in the SAI_xSR register.

This bit is used only when the AC’97 audio protocol is selected in the SAI_xCR1 register.

Reading this bit always returns the value 0.

Bit 3 Reserved, must be kept at reset value.

Bit 2 CWCKCFG : Clear wrong clock configuration flag.

This bit is write only.

Programming this bit to 1 clears the WCKCFG flag in the SAI_xSR register.

This bit is used only when the audio block is set as master (MODE[1] = 0) and NODIV = 0 in the SAI_xCR1 register.

Reading this bit always returns the value 0.

Bit 1 CMUTEDET : Mute detection flag.

This bit is write only.

Programming this bit to 1 clears the MUTEDET flag in the SAI_xSR register.

Reading this bit always returns the value 0.

Bit 0 COVRUDR : Clear overrun / underrun.

This bit is write only.

Programming this bit to 1 clears the OVRUDR flag in the SAI_xSR register.

Reading this bit always returns the value 0.

32.6.16 SAI data register (SAI_BDR)

Address offset: 0x40

Reset value: 0x0000 0000

31302928272625242322212019181716
DATA[31:16]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
DATA[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 DATA[31:0] : Data

A write to this register loads the FIFO provided the FIFO is not full.

A read from this register empties the FIFO if the FIFO is not empty.

32.6.17 SAI register map

Table 216. SAI register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
ResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResRes
0x0000Reserved
0x0004 or 0x0024SAI_xCR1ResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResRes
Reset value
0x08 or 0x28SAI_xCR2ResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResRes
Reset value
0x0C or 0x2CSAI_xFCRResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResRes
Reset value
0x10 or 0x30SAI_xSLOTRSLOTEN[15:0]
Reset value00000000000000000000000000000000
0x14 or 0x34SAI_xIMResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResRes
Reset value
0x18 or 0x38SAI_xSRResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResRes
Reset value
0x1C or 0x3CSAI_xCLRFRResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResResRes
Reset value
0x20 or 0x40SAI_xDRDATA[31:0]
Reset value00000000000000000000000000000000

Refer to Section 2.2 for the register boundary addresses.