 Hello and welcome to this presentation of the STM32 Serial Audio Interface. I will present the features of this interface, which is used to connect external audio devices. The Serial Audio Interface, or SAI, is integrated in STM32 products to provide an interface for communicating with external audio devices such as amplifiers, ADCs, DACs, audio codecs, and audio processors. This interface is fully configurable, supporting most digital audio standards, allowing easy connection to any existing audio devices. Due to the internal synchronization features of the SAI, the required IO pins are reduced to a minimum. The SAI can be programmed in three different modes. The free protocol mode allows the SAI to support standards such as I2S, PCM, and TDM Due to its flexibility, it is possible to customize the Serial Interface if needed. The SPDIF protocol mode allows the SAI to transmit audio samples using the IEC 6958 standard. The AC97 protocol is also supported by the SAI. The SAI supports all the standard audio sampling rates, depending on the crystal frequency used for the application. In addition, the SAI supports master and slave mode, half-duplex or full-duplex communication. It is also possible to synchronize several SAIs together. The SAI also provides a FIFO buffer of eight samples, and up to two interrupt and DMA interfaces. The SAI is composed of two independent sub-blocks, A and B. Each sub-block has its own APB interface, clock generator, FIFO buffer, DMA interface, and interrupt interface. Each sub-block can be configured in receive or transmit, master or slave with its own protocol. Internal and external synchronization allows two sub-blocks to be synchronized or two SAIs to be synchronized. Each sub-block can handle up to four IOs. FSX is the frame synchronization signal. SCKX is the bit clock. SDX is the serial data line. And MCLKX is the master clock. The STM32L4XX embeds two SAIs. Each SAI can receive a kernel clock, SAINCKX, from one of the three internal PLLs or from the pads, SAINXTCLK. The kernel clock is used by the SAI in order to generate the timing of the serial audio interface when programmed in master mode. The free protocol mode, the flexible programming interface, facilitates the configuration of most common audio standard interfaces. The following example shows some of the possibilities of the interface for I2S-like protocols. In I2S-like protocol, each edge of the frame synchronization or FS signal is used to align the slot's start position. The frame length, the duty cycle, and polarity can be adjusted. The clock strobing edge can be selected. The position of the slots with respect to the frame edges can be selected. The number of slots per frame needs to be an even number in I2S-like protocol. The following example shows some of the possibilities of the interface for the TDM-like protocols. In TDM-like protocol, only one edge of the frame synchronization, rising or falling, is used to align the slot's position. The frame length, the duty cycle, and polarity can be adjusted. The clock strobing edge can be selected. The position of the slots with respect to the frame active edge can be selected. The number of slots per frame, up to 16, can be selected. The slot size is always bigger than or equal to the data size. The SAI allows control of the position of the data inside each slot, and setting of the unused slots to HIZ if needed. This function can be useful when the data line is shared between several devices. In master mode, the SAI can generate the master clock, MCLK, or use an external master clock via SAI-X-EXT-CLK-PADS. The master clock can be used to provide a reference clock to the external audio codecs. In slave mode, the MCLK signal is not used. In master mode, it is up to the SAI to generate the timing in order to provide the correct sampling rate. In slave mode, the sampling rate is provided by the external audio device. The clock generator is needed for master mode communications. It is used to adjust the sampling rate of the serial audio interface. The clock generator provides the root frequency for the MCLK-X, SCK-X, and the FS-X. When the master clock or MCLK needs to be generated, the frame length must be a power of two. The ratio between the FS-X frequency and the MCLK-X frequency is fixed to 256. When the MCLK-X does not need to be generated, the frame length can take any value from 8 to 256. The internal synchronization can be used for communication requesting two data lanes, such as full-duplex I²S. The external synchronization can be used for communication requesting more than two data lanes, up to four, for example when interfacing HDMI ICS. All the sub-blocks synchronized together must use the same protocol characteristics. In order to reduce the data size, it is possible to insert in the data path an ALaw or Ulaw compender. Note that ALaw and Ulaw are not lossless compressors. Compending modes are generally used in telephony. The small data are amplified and the big data are attenuated. The SNR tends to be identical for a strong and for a weak signal. The SAI also provides a mute function. The anticipated or late frame error detection increases the interface reliability by detecting unexpected frame synchronization misalignment. The SAI guarantees the data alignment even if an underrun or overrun occurs. The SAI supports the audio IEC 6958 standard in transmit mode when configured in SPDIF mode. The software has to handle the CS, U and V bits. The SAI generates the parity bit according to the transmitted data. In the IEC 6958, the block structure is used to decode the channel status or CS and user information or U. Each block contains 192 frames. Each frame contains two subframes. Each subframe contains 32 bits. A synchronization preamble allows the detection of the block and subframe boundaries. The FSSAI CKX frequency must be adjusted in order to generate the proper audio sample rate. The data inside the transmit FIFO must be adjusted as shown in the slide. The MSB must always be at position 23. The SAI is able to work as an AC97 link controller. When this protocol is used, the frame length, the slot number and slot length are fixed by the hardware. Several events can be enabled in order to generate interrupts. The FIFO request event, the overrun underrun event, the anticipated or late frame synchronization event, the codec not ready event only in AC97 and the mute detection event. The WCKCFG event can be used in order to inform the user that the frame length of the SAI has been improperly programmed. This feature is only available in master mode. The SAI needs the bus interface clock or APB clock and the kernel clock or SAINCKX to work properly. For a full duplex master mode, two data lanes are needed so two subblocks need to be used. The master subblock A provides the synchronization to slave subblock B using the internal synchronization feature or IO line management. Using internal synchronization, the number of IOs required is reduced to its minimum. Another example of full duplex mode use case with the TDM protocol usage. The slot one is inactive or not used for subblock A, the slots two and three are inactive for subblock B. For both subblocks, the frame structure has four slots. The subblock A will generate three samples per frame. The subblock B will receive two samples per frame.