discoverpixy
Macros | Functions
stm32f4xx_sai.c File Reference

This file provides firmware functions to manage the following functionalities of the Serial Audio Interface (SAI): More...

#include "stm32f4xx_sai.h"
#include "stm32f4xx_rcc.h"
Include dependency graph for stm32f4xx_sai.c:

Macros

#define CR1_CLEAR_MASK   ((uint32_t)0xFF07C010)
 
#define FRCR_CLEAR_MASK   ((uint32_t)0xFFF88000)
 
#define SLOTR_CLEAR_MASK   ((uint32_t)0x0000F020)
 

Functions

void SAI_DeInit (SAI_TypeDef *SAIx)
 Deinitialize the SAIx peripheral registers to their default reset values. More...
 
void SAI_Init (SAI_Block_TypeDef *SAI_Block_x, SAI_InitTypeDef *SAI_InitStruct)
 Initializes the SAI Block x peripheral according to the specified parameters in the SAI_InitStruct. More...
 
void SAI_FrameInit (SAI_Block_TypeDef *SAI_Block_x, SAI_FrameInitTypeDef *SAI_FrameInitStruct)
 Initializes the SAI Block Audio frame according to the specified parameters in the SAI_FrameInitStruct. More...
 
void SAI_SlotInit (SAI_Block_TypeDef *SAI_Block_x, SAI_SlotInitTypeDef *SAI_SlotInitStruct)
 Initializes the SAI Block audio Slot according to the specified parameters in the SAI_SlotInitStruct. More...
 
void SAI_StructInit (SAI_InitTypeDef *SAI_InitStruct)
 Fills each SAI_InitStruct member with its default value. More...
 
void SAI_FrameStructInit (SAI_FrameInitTypeDef *SAI_FrameInitStruct)
 Fills each SAI_FrameInitStruct member with its default value. More...
 
void SAI_SlotStructInit (SAI_SlotInitTypeDef *SAI_SlotInitStruct)
 Fills each SAI_SlotInitStruct member with its default value. More...
 
void SAI_Cmd (SAI_Block_TypeDef *SAI_Block_x, FunctionalState NewState)
 Enables or disables the specified SAI Block peripheral. More...
 
void SAI_MonoModeConfig (SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_Mono_StreoMode)
 Configures the mono mode for the selected SAI block. More...
 
void SAI_TRIStateConfig (SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_TRIState)
 Configures the TRIState managment on data line for the selected SAI block. More...
 
void SAI_CompandingModeConfig (SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_CompandingMode)
 Configures the companding mode for the selected SAI block. More...
 
void SAI_MuteModeCmd (SAI_Block_TypeDef *SAI_Block_x, FunctionalState NewState)
 Enables or disables the Mute mode for the selected SAI block. More...
 
void SAI_MuteValueConfig (SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_MuteValue)
 Configure the mute value for the selected SAI block. More...
 
void SAI_MuteFrameCounterConfig (SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_MuteCounter)
 Enables or disables the Mute mode for the selected SAI block. More...
 
void SAI_FlushFIFO (SAI_Block_TypeDef *SAI_Block_x)
 Reinitialize the FIFO pointer. More...
 
uint32_t SAI_ReceiveData (SAI_Block_TypeDef *SAI_Block_x)
 Returns the most recent received data by the SAI block x peripheral. More...
 
void SAI_SendData (SAI_Block_TypeDef *SAI_Block_x, uint32_t Data)
 Transmits a Data through the SAI block x peripheral. More...
 
void SAI_DMACmd (SAI_Block_TypeDef *SAI_Block_x, FunctionalState NewState)
 Enables or disables the SAI Block x DMA interface. More...
 
void SAI_ITConfig (SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_IT, FunctionalState NewState)
 Enables or disables the specified SAI Block interrupts. More...
 
FlagStatus SAI_GetFlagStatus (SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_FLAG)
 Checks whether the specified SAI block x flag is set or not. More...
 
void SAI_ClearFlag (SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_FLAG)
 Clears the specified SAI Block x flag. More...
 
ITStatus SAI_GetITStatus (SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_IT)
 Checks whether the specified SAI Block x interrupt has occurred or not. More...
 
void SAI_ClearITPendingBit (SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_IT)
 Clears the SAI Block x interrupt pending bit. More...
 
FunctionalState SAI_GetCmdStatus (SAI_Block_TypeDef *SAI_Block_x)
 Returns the status of EN bit for the specified SAI Block x. More...
 
uint32_t SAI_GetFIFOStatus (SAI_Block_TypeDef *SAI_Block_x)
 Returns the current SAI Block x FIFO filled level. More...
 

Detailed Description

This file provides firmware functions to manage the following functionalities of the Serial Audio Interface (SAI):

Author
MCD Application Team
Version
V1.4.0
Date
04-August-2014
  • Initialization and Configuration
  • Data transfers functions
  • DMA transfers management
  • Interrupts and flags management
===============================================================================
                    ##### How to use this driver #####
===============================================================================
   [..] 
   
      (#) Enable peripheral clock using the following functions 
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_SAI1, ENABLE) for SAI1
 
      (#) For each SAI Block A/B enable SCK, SD, FS and MCLK GPIO clocks 
          using RCC_AHB1PeriphClockCmd() function.
 
      (#) Peripherals alternate function: 
          (++) Connect the pin to the desired peripherals' Alternate 
               Function (AF) using GPIO_PinAFConfig() function.
          (++) Configure the desired pin in alternate function by:
               GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
          (++) Select the type, pull-up/pull-down and output speed via 
               GPIO_PuPd, GPIO_OType and GPIO_Speed members
          (++) Call GPIO_Init() function
          -@@- If an external clock source is used then the I2S CKIN pin should be 
              also configured in Alternate function Push-pull pull-up mode.
               
     (#) The SAI clock can be generated from different clock source :
         PLL I2S, PLL SAI or external clock source.
         (++) The PLL I2S is configured using the following functions RCC_PLLI2SConfig(), 
              RCC_PLLI2SCmd(ENABLE), RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY) and 
              RCC_SAIPLLI2SClkDivConfig() or;
             
         (++) The PLL SAI is configured using the following functions RCC_PLLSAIConfig(), 
              RCC_PLLSAICmd(ENABLE), RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) and 
              RCC_SAIPLLSAIClkDivConfig()or;          
             
         (++) External clock source is configured using the function 
              RCC_I2SCLKConfig(RCC_I2S2CLKSource_Ext) and after setting correctly the 
              define constant I2S_EXTERNAL_CLOCK_VAL in the stm32f4xx_conf.h file.      
               
     (#) Each SAI Block A or B has its own clock generator to make these two blocks 
         completely independent. The Clock generator is configured using RCC_SAIBlockACLKConfig() and 
         RCC_SAIBlockBCLKConfig() functions.
                 
     (#) Each SAI Block A or B can be configured separetely : 
         (++) Program the Master clock divider, Audio mode, Protocol, Data Length, Clock Strobing Edge, 
              Synchronous mode, Output drive and FIFO Thresold using SAI_Init() function.   
              In case of master mode, program the Master clock divider (MCKDIV) using 
              the following formula :  
              (+++) MCLK_x = SAI_CK_x / (MCKDIV * 2) with MCLK_x = 256 * FS
              (+++) FS = SAI_CK_x / (MCKDIV * 2) * 256
              (+++) MCKDIV = SAI_CK_x / FS * 512
        (++) Program the Frame Length, Frame active Length, FS Definition, FS Polarity, 
             FS Offset using SAI_FrameInit() function.    
        (++) Program the Slot First Bit Offset, Slot Size, Slot Number, Slot Active 
             using SAI_SlotInit() function. 
                  
     (#) Enable the NVIC and the corresponding interrupt using the function 
         SAI_ITConfig() if you need to use interrupt mode. 
 
     (#) When using the DMA mode 
         (++) Configure the DMA using DMA_Init() function
         (++) Active the needed channel Request using SAI_DMACmd() function
  
     (#) Enable the SAI using the SAI_Cmd() function.
  
     (#) Enable the DMA using the DMA_Cmd() function when using DMA mode. 
 
     (#) The SAI has some specific functions which can be useful depending 
         on the audio protocol selected.  
         (++) Enable Mute mode when the audio block is a transmitter using SAI_MuteModeCmd()
              function and configure the value transmitted during mute using SAI_MuteValueConfig().  
         (++) Detect the Mute mode when audio block is a receiver using SAI_MuteFrameCounterConfig().             
         (++) Enable the MONO mode without any data preprocessing in memory when the number
              of slot is equal to 2 using SAI_MonoModeConfig() function.
         (++) Enable data companding algorithm (U law and A law) using SAI_CompandingModeConfig().
         (++) Choose the behavior of the SD line in output when an inactive slot is sent 
              on the data line using SAI_TRIStateConfig() function.   
 [..]               
  (@)    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.
                
  (@)    In master RX mode: enabling the audio block immediately generates the bit clock 
         and FS signal for the external slaves. 
               
  (@)    It is mandatory to respect the following conditions in order to avoid bad SAI behavior: 
           (+@)  First bit Offset <= (SLOT size - Data size)
           (+@)  Data size <= SLOT size
           (+@)  Number of SLOT x SLOT size = Frame length
           (+@)  The number of slots should be even when bit FSDEF in the SAI_xFRCR is set.    
Attention

© COPYRIGHT 2014 STMicroelectronics

Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this file except in compliance with the License. You may obtain a copy of the License at:

   http://www.st.com/software_license_agreement_liberty_v2

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.