mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_sai.c@384:ef87175507f1, 2014-11-04 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Nov 04 09:30:07 2014 +0000
- Revision:
- 384:ef87175507f1
- Parent:
- 380:510f0c3515e3
- Child:
- 532:fe11edbda85c
Synchronized with git revision 8f7778d898867246da01cfccb39396c2e419c1f6
Full URL: https://github.com/mbedmicro/mbed/commit/8f7778d898867246da01cfccb39396c2e419c1f6/
Targets: Nucleo F4xx - Reorder f4xx structure
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 87:085cde657901 | 1 | /** |
mbed_official | 87:085cde657901 | 2 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 3 | * @file stm32f4xx_hal_sai.c |
mbed_official | 87:085cde657901 | 4 | * @author MCD Application Team |
mbed_official | 369:2e96f1b71984 | 5 | * @version V1.1.0 |
mbed_official | 369:2e96f1b71984 | 6 | * @date 19-June-2014 |
mbed_official | 87:085cde657901 | 7 | * @brief SAI HAL module driver. |
mbed_official | 87:085cde657901 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 87:085cde657901 | 9 | * functionalities of the Serial Audio Interface (SAI) peripheral: |
mbed_official | 87:085cde657901 | 10 | * + Initialization/de-initialization functions |
mbed_official | 87:085cde657901 | 11 | * + I/O operation functions |
mbed_official | 87:085cde657901 | 12 | * + Peripheral Control functions |
mbed_official | 87:085cde657901 | 13 | * + Peripheral State functions |
mbed_official | 87:085cde657901 | 14 | * |
mbed_official | 87:085cde657901 | 15 | @verbatim |
mbed_official | 87:085cde657901 | 16 | ============================================================================== |
mbed_official | 87:085cde657901 | 17 | ##### How to use this driver ##### |
mbed_official | 87:085cde657901 | 18 | ============================================================================== |
mbed_official | 87:085cde657901 | 19 | |
mbed_official | 87:085cde657901 | 20 | [..] |
mbed_official | 226:b062af740e40 | 21 | The SAI HAL driver can be used as follows: |
mbed_official | 87:085cde657901 | 22 | |
mbed_official | 87:085cde657901 | 23 | (#) Declare a SAI_HandleTypeDef handle structure. |
mbed_official | 226:b062af740e40 | 24 | (#) Initialize the SAI low level resources by implementing the HAL_SAI_MspInit() API: |
mbed_official | 87:085cde657901 | 25 | (##) Enable the SAI interface clock. |
mbed_official | 87:085cde657901 | 26 | (##) SAI pins configuration: |
mbed_official | 87:085cde657901 | 27 | (+++) Enable the clock for the SAI GPIOs. |
mbed_official | 87:085cde657901 | 28 | (+++) Configure these SAI pins as alternate function pull-up. |
mbed_official | 87:085cde657901 | 29 | (##) NVIC configuration if you need to use interrupt process (HAL_SAI_Transmit_IT() |
mbed_official | 87:085cde657901 | 30 | and HAL_SAI_Receive_IT() APIs): |
mbed_official | 87:085cde657901 | 31 | (+++) Configure the SAI interrupt priority. |
mbed_official | 87:085cde657901 | 32 | (+++) Enable the NVIC SAI IRQ handle. |
mbed_official | 87:085cde657901 | 33 | |
mbed_official | 87:085cde657901 | 34 | (##) DMA Configuration if you need to use DMA process (HAL_SAI_Transmit_DMA() |
mbed_official | 87:085cde657901 | 35 | and HAL_SAI_Receive_DMA() APIs): |
mbed_official | 87:085cde657901 | 36 | (+++) Declare a DMA handle structure for the Tx/Rx stream. |
mbed_official | 87:085cde657901 | 37 | (+++) Enable the DMAx interface clock. |
mbed_official | 87:085cde657901 | 38 | (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
mbed_official | 87:085cde657901 | 39 | (+++) Configure the DMA Tx/Rx Stream. |
mbed_official | 87:085cde657901 | 40 | (+++) Associate the initialized DMA handle to the SAI DMA Tx/Rx handle. |
mbed_official | 87:085cde657901 | 41 | (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the |
mbed_official | 87:085cde657901 | 42 | DMA Tx/Rx Stream. |
mbed_official | 87:085cde657901 | 43 | |
mbed_official | 87:085cde657901 | 44 | (#) Program the SAI Mode, Standard, Data Format, MCLK Output, Audio frequency and Polarity |
mbed_official | 87:085cde657901 | 45 | using HAL_SAI_Init() function. |
mbed_official | 87:085cde657901 | 46 | |
mbed_official | 87:085cde657901 | 47 | -@- The specific SAI interrupts (FIFO request and Overrun underrun interrupt) |
mbed_official | 87:085cde657901 | 48 | will be managed using the macros __SAI_ENABLE_IT() and __SAI_DISABLE_IT() |
mbed_official | 87:085cde657901 | 49 | inside the transmit and receive process. |
mbed_official | 87:085cde657901 | 50 | |
mbed_official | 87:085cde657901 | 51 | [..] |
mbed_official | 87:085cde657901 | 52 | (@) Make sure that either: |
mbed_official | 87:085cde657901 | 53 | (+@) I2S PLL is configured or |
mbed_official | 87:085cde657901 | 54 | (+@) SAI PLL is configured or |
mbed_official | 87:085cde657901 | 55 | (+@) External clock source is configured after setting correctly |
mbed_official | 87:085cde657901 | 56 | the define constant EXTERNAL_CLOCK_VALUE in the stm32f4xx_hal_conf.h file. |
mbed_official | 87:085cde657901 | 57 | |
mbed_official | 87:085cde657901 | 58 | [..] |
mbed_official | 226:b062af740e40 | 59 | (@) In master Tx mode: enabling the audio block immediately generates the bit clock |
mbed_official | 87:085cde657901 | 60 | for the external slaves even if there is no data in the FIFO, However FS signal |
mbed_official | 87:085cde657901 | 61 | generation is conditioned by the presence of data in the FIFO. |
mbed_official | 87:085cde657901 | 62 | |
mbed_official | 87:085cde657901 | 63 | [..] |
mbed_official | 226:b062af740e40 | 64 | (@) In master Rx mode: enabling the audio block immediately generates the bit clock |
mbed_official | 87:085cde657901 | 65 | and FS signal for the external slaves. |
mbed_official | 87:085cde657901 | 66 | |
mbed_official | 87:085cde657901 | 67 | [..] |
mbed_official | 87:085cde657901 | 68 | (@) It is mandatory to respect the following conditions in order to avoid bad SAI behavior: |
mbed_official | 87:085cde657901 | 69 | (+@) First bit Offset <= (SLOT size - Data size) |
mbed_official | 87:085cde657901 | 70 | (+@) Data size <= SLOT size |
mbed_official | 87:085cde657901 | 71 | (+@) Number of SLOT x SLOT size = Frame length |
mbed_official | 87:085cde657901 | 72 | (+@) The number of slots should be even when SAI_FS_CHANNEL_IDENTIFICATION is selected. |
mbed_official | 87:085cde657901 | 73 | |
mbed_official | 87:085cde657901 | 74 | [..] |
mbed_official | 226:b062af740e40 | 75 | Three operation modes are available within this driver : |
mbed_official | 87:085cde657901 | 76 | |
mbed_official | 87:085cde657901 | 77 | *** Polling mode IO operation *** |
mbed_official | 87:085cde657901 | 78 | ================================= |
mbed_official | 87:085cde657901 | 79 | [..] |
mbed_official | 87:085cde657901 | 80 | (+) Send an amount of data in blocking mode using HAL_SAI_Transmit() |
mbed_official | 87:085cde657901 | 81 | (+) Receive an amount of data in blocking mode using HAL_SAI_Receive() |
mbed_official | 87:085cde657901 | 82 | |
mbed_official | 87:085cde657901 | 83 | *** Interrupt mode IO operation *** |
mbed_official | 87:085cde657901 | 84 | =================================== |
mbed_official | 87:085cde657901 | 85 | [..] |
mbed_official | 87:085cde657901 | 86 | (+) Send an amount of data in non blocking mode using HAL_SAI_Transmit_IT() |
mbed_official | 87:085cde657901 | 87 | (+) At transmission end of transfer HAL_SAI_TxCpltCallback is executed and user can |
mbed_official | 87:085cde657901 | 88 | add his own code by customization of function pointer HAL_SAI_TxCpltCallback |
mbed_official | 87:085cde657901 | 89 | (+) Receive an amount of data in non blocking mode using HAL_SAI_Receive_IT() |
mbed_official | 87:085cde657901 | 90 | (+) At reception end of transfer HAL_SAI_RxCpltCallback is executed and user can |
mbed_official | 87:085cde657901 | 91 | add his own code by customization of function pointer HAL_SAI_RxCpltCallback |
mbed_official | 87:085cde657901 | 92 | (+) In case of transfer Error, HAL_SAI_ErrorCallback() function is executed and user can |
mbed_official | 87:085cde657901 | 93 | add his own code by customization of function pointer HAL_SAI_ErrorCallback |
mbed_official | 87:085cde657901 | 94 | |
mbed_official | 87:085cde657901 | 95 | *** DMA mode IO operation *** |
mbed_official | 87:085cde657901 | 96 | ============================== |
mbed_official | 87:085cde657901 | 97 | [..] |
mbed_official | 87:085cde657901 | 98 | (+) Send an amount of data in non blocking mode (DMA) using HAL_SAI_Transmit_DMA() |
mbed_official | 87:085cde657901 | 99 | (+) At transmission end of transfer HAL_SAI_TxCpltCallback is executed and user can |
mbed_official | 87:085cde657901 | 100 | add his own code by customization of function pointer HAL_SAI_TxCpltCallback |
mbed_official | 87:085cde657901 | 101 | (+) Receive an amount of data in non blocking mode (DMA) using HAL_SAI_Receive_DMA() |
mbed_official | 87:085cde657901 | 102 | (+) At reception end of transfer HAL_SAI_RxCpltCallback is executed and user can |
mbed_official | 87:085cde657901 | 103 | add his own code by customization of function pointer HAL_SAI_RxCpltCallback |
mbed_official | 87:085cde657901 | 104 | (+) In case of transfer Error, HAL_SAI_ErrorCallback() function is executed and user can |
mbed_official | 87:085cde657901 | 105 | add his own code by customization of function pointer HAL_SAI_ErrorCallback |
mbed_official | 87:085cde657901 | 106 | (+) Pause the DMA Transfer using HAL_SAI_DMAPause() |
mbed_official | 87:085cde657901 | 107 | (+) Resume the DMA Transfer using HAL_SAI_DMAResume() |
mbed_official | 87:085cde657901 | 108 | (+) Stop the DMA Transfer using HAL_SAI_DMAStop() |
mbed_official | 87:085cde657901 | 109 | |
mbed_official | 87:085cde657901 | 110 | *** SAI HAL driver macros list *** |
mbed_official | 87:085cde657901 | 111 | ============================================= |
mbed_official | 87:085cde657901 | 112 | [..] |
mbed_official | 226:b062af740e40 | 113 | Below the list of most used macros in USART HAL driver : |
mbed_official | 87:085cde657901 | 114 | |
mbed_official | 87:085cde657901 | 115 | (+) __HAL_SAI_ENABLE: Enable the SAI peripheral |
mbed_official | 87:085cde657901 | 116 | (+) __HAL_SAI_DISABLE: Disable the SAI peripheral |
mbed_official | 87:085cde657901 | 117 | (+) __HAL_SAI_ENABLE_IT : Enable the specified SAI interrupts |
mbed_official | 87:085cde657901 | 118 | (+) __HAL_SAI_DISABLE_IT : Disable the specified SAI interrupts |
mbed_official | 87:085cde657901 | 119 | (+) __HAL_SAI_GET_IT_SOURCE: Check if the specified SAI interrupt source is |
mbed_official | 87:085cde657901 | 120 | enabled or disabled |
mbed_official | 87:085cde657901 | 121 | (+) __HAL_SAI_GET_FLAG: Check whether the specified SAI flag is set or not |
mbed_official | 87:085cde657901 | 122 | |
mbed_official | 87:085cde657901 | 123 | @endverbatim |
mbed_official | 87:085cde657901 | 124 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 125 | * @attention |
mbed_official | 87:085cde657901 | 126 | * |
mbed_official | 87:085cde657901 | 127 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 87:085cde657901 | 128 | * |
mbed_official | 87:085cde657901 | 129 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 87:085cde657901 | 130 | * are permitted provided that the following conditions are met: |
mbed_official | 87:085cde657901 | 131 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 87:085cde657901 | 132 | * this list of conditions and the following disclaimer. |
mbed_official | 87:085cde657901 | 133 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 87:085cde657901 | 134 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 87:085cde657901 | 135 | * and/or other materials provided with the distribution. |
mbed_official | 87:085cde657901 | 136 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 87:085cde657901 | 137 | * may be used to endorse or promote products derived from this software |
mbed_official | 87:085cde657901 | 138 | * without specific prior written permission. |
mbed_official | 87:085cde657901 | 139 | * |
mbed_official | 87:085cde657901 | 140 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 87:085cde657901 | 141 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 87:085cde657901 | 142 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 87:085cde657901 | 143 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 87:085cde657901 | 144 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 87:085cde657901 | 145 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 87:085cde657901 | 146 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 87:085cde657901 | 147 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 87:085cde657901 | 148 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 87:085cde657901 | 149 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 87:085cde657901 | 150 | * |
mbed_official | 87:085cde657901 | 151 | ****************************************************************************** |
mbed_official | 87:085cde657901 | 152 | */ |
mbed_official | 87:085cde657901 | 153 | |
mbed_official | 87:085cde657901 | 154 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 155 | #include "stm32f4xx_hal.h" |
mbed_official | 87:085cde657901 | 156 | |
mbed_official | 87:085cde657901 | 157 | /** @addtogroup STM32F4xx_HAL_Driver |
mbed_official | 87:085cde657901 | 158 | * @{ |
mbed_official | 87:085cde657901 | 159 | */ |
mbed_official | 87:085cde657901 | 160 | |
mbed_official | 87:085cde657901 | 161 | /** @defgroup SAI |
mbed_official | 87:085cde657901 | 162 | * @brief SAI HAL module driver |
mbed_official | 87:085cde657901 | 163 | * @{ |
mbed_official | 87:085cde657901 | 164 | */ |
mbed_official | 87:085cde657901 | 165 | |
mbed_official | 87:085cde657901 | 166 | #ifdef HAL_SAI_MODULE_ENABLED |
mbed_official | 87:085cde657901 | 167 | |
mbed_official | 87:085cde657901 | 168 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) |
mbed_official | 87:085cde657901 | 169 | |
mbed_official | 87:085cde657901 | 170 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 171 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 172 | /* SAI registers Masks */ |
mbed_official | 87:085cde657901 | 173 | #define CR1_CLEAR_MASK ((uint32_t)0xFF07C010) |
mbed_official | 87:085cde657901 | 174 | #define FRCR_CLEAR_MASK ((uint32_t)0xFFF88000) |
mbed_official | 87:085cde657901 | 175 | #define SLOTR_CLEAR_MASK ((uint32_t)0x0000F020) |
mbed_official | 87:085cde657901 | 176 | |
mbed_official | 369:2e96f1b71984 | 177 | #define SAI_TIMEOUT_VALUE 10 |
mbed_official | 87:085cde657901 | 178 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 179 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 180 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 87:085cde657901 | 181 | static void SAI_DMATxCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 87:085cde657901 | 182 | static void SAI_DMATxHalfCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 87:085cde657901 | 183 | static void SAI_DMARxCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 87:085cde657901 | 184 | static void SAI_DMARxHalfCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 87:085cde657901 | 185 | static void SAI_DMAError(DMA_HandleTypeDef *hdma); |
mbed_official | 87:085cde657901 | 186 | |
mbed_official | 87:085cde657901 | 187 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 188 | |
mbed_official | 87:085cde657901 | 189 | /** @defgroup SAI_Private_Functions |
mbed_official | 87:085cde657901 | 190 | * @{ |
mbed_official | 87:085cde657901 | 191 | */ |
mbed_official | 87:085cde657901 | 192 | |
mbed_official | 87:085cde657901 | 193 | /** @defgroup SAI_Group1 Initialization and de-initialization functions |
mbed_official | 87:085cde657901 | 194 | * @brief Initialization and Configuration functions |
mbed_official | 87:085cde657901 | 195 | * |
mbed_official | 87:085cde657901 | 196 | @verbatim |
mbed_official | 87:085cde657901 | 197 | =============================================================================== |
mbed_official | 87:085cde657901 | 198 | ##### Initialization and de-initialization functions ##### |
mbed_official | 87:085cde657901 | 199 | =============================================================================== |
mbed_official | 87:085cde657901 | 200 | [..] This subsection provides a set of functions allowing to initialize and |
mbed_official | 87:085cde657901 | 201 | de-initialize the SAIx peripheral: |
mbed_official | 87:085cde657901 | 202 | |
mbed_official | 226:b062af740e40 | 203 | (+) User must implement HAL_SAI_MspInit() function in which he configures |
mbed_official | 87:085cde657901 | 204 | all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ). |
mbed_official | 87:085cde657901 | 205 | |
mbed_official | 87:085cde657901 | 206 | (+) Call the function HAL_SAI_Init() to configure the selected device with |
mbed_official | 87:085cde657901 | 207 | the selected configuration: |
mbed_official | 87:085cde657901 | 208 | (++) Mode (Master/slave TX/RX) |
mbed_official | 87:085cde657901 | 209 | (++) Protocol |
mbed_official | 87:085cde657901 | 210 | (++) Data Size |
mbed_official | 87:085cde657901 | 211 | (++) MCLK Output |
mbed_official | 87:085cde657901 | 212 | (++) Audio frequency |
mbed_official | 87:085cde657901 | 213 | (++) FIFO Threshold |
mbed_official | 87:085cde657901 | 214 | (++) Frame Config |
mbed_official | 87:085cde657901 | 215 | (++) Slot Config |
mbed_official | 87:085cde657901 | 216 | |
mbed_official | 87:085cde657901 | 217 | (+) Call the function HAL_SAI_DeInit() to restore the default configuration |
mbed_official | 87:085cde657901 | 218 | of the selected SAI peripheral. |
mbed_official | 87:085cde657901 | 219 | |
mbed_official | 87:085cde657901 | 220 | @endverbatim |
mbed_official | 87:085cde657901 | 221 | * @{ |
mbed_official | 87:085cde657901 | 222 | */ |
mbed_official | 87:085cde657901 | 223 | |
mbed_official | 87:085cde657901 | 224 | /** |
mbed_official | 87:085cde657901 | 225 | * @brief Initializes the SAI according to the specified parameters |
mbed_official | 87:085cde657901 | 226 | * in the SAI_InitTypeDef and create the associated handle. |
mbed_official | 226:b062af740e40 | 227 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 228 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 229 | * @retval HAL status |
mbed_official | 87:085cde657901 | 230 | */ |
mbed_official | 87:085cde657901 | 231 | HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 232 | { |
mbed_official | 87:085cde657901 | 233 | uint32_t tmpreg = 0; |
mbed_official | 87:085cde657901 | 234 | uint32_t tmpclock = 0, tmp2clock = 0; |
mbed_official | 87:085cde657901 | 235 | /* This variable used to store the VCO Input (value in Hz) */ |
mbed_official | 87:085cde657901 | 236 | uint32_t vcoinput = 0; |
mbed_official | 87:085cde657901 | 237 | /* This variable used to store the SAI_CK_x (value in Hz) */ |
mbed_official | 87:085cde657901 | 238 | uint32_t saiclocksource = 0; |
mbed_official | 87:085cde657901 | 239 | |
mbed_official | 87:085cde657901 | 240 | /* Check the SAI handle allocation */ |
mbed_official | 384:ef87175507f1 | 241 | if(hsai == HAL_NULL) |
mbed_official | 87:085cde657901 | 242 | { |
mbed_official | 87:085cde657901 | 243 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 244 | } |
mbed_official | 87:085cde657901 | 245 | |
mbed_official | 87:085cde657901 | 246 | /* Check the SAI Block parameters */ |
mbed_official | 87:085cde657901 | 247 | assert_param(IS_SAI_BLOCK_PROTOCOL(hsai->Init.Protocol)); |
mbed_official | 87:085cde657901 | 248 | assert_param(IS_SAI_BLOCK_MODE(hsai->Init.AudioMode)); |
mbed_official | 87:085cde657901 | 249 | assert_param(IS_SAI_BLOCK_DATASIZE(hsai->Init.DataSize)); |
mbed_official | 87:085cde657901 | 250 | assert_param(IS_SAI_BLOCK_FIRST_BIT(hsai->Init.FirstBit)); |
mbed_official | 87:085cde657901 | 251 | assert_param(IS_SAI_BLOCK_CLOCK_STROBING(hsai->Init.ClockStrobing)); |
mbed_official | 87:085cde657901 | 252 | assert_param(IS_SAI_BLOCK_SYNCHRO(hsai->Init.Synchro)); |
mbed_official | 87:085cde657901 | 253 | assert_param(IS_SAI_BLOCK_OUTPUT_DRIVE(hsai->Init.OutputDrive)); |
mbed_official | 87:085cde657901 | 254 | assert_param(IS_SAI_BLOCK_NODIVIDER(hsai->Init.NoDivider)); |
mbed_official | 87:085cde657901 | 255 | assert_param(IS_SAI_BLOCK_FIFO_THRESHOLD(hsai->Init.FIFOThreshold)); |
mbed_official | 87:085cde657901 | 256 | assert_param(IS_SAI_AUDIO_FREQUENCY(hsai->Init.AudioFrequency)); |
mbed_official | 87:085cde657901 | 257 | |
mbed_official | 87:085cde657901 | 258 | /* Check the SAI Block Frame parameters */ |
mbed_official | 87:085cde657901 | 259 | assert_param(IS_SAI_BLOCK_FRAME_LENGTH(hsai->FrameInit.FrameLength)); |
mbed_official | 87:085cde657901 | 260 | assert_param(IS_SAI_BLOCK_ACTIVE_FRAME(hsai->FrameInit.ActiveFrameLength)); |
mbed_official | 87:085cde657901 | 261 | assert_param(IS_SAI_BLOCK_FS_DEFINITION(hsai->FrameInit.FSDefinition)); |
mbed_official | 87:085cde657901 | 262 | assert_param(IS_SAI_BLOCK_FS_POLARITY(hsai->FrameInit.FSPolarity)); |
mbed_official | 87:085cde657901 | 263 | assert_param(IS_SAI_BLOCK_FS_OFFSET(hsai->FrameInit.FSOffset)); |
mbed_official | 87:085cde657901 | 264 | |
mbed_official | 87:085cde657901 | 265 | /* Check the SAI Block Slot parameters */ |
mbed_official | 87:085cde657901 | 266 | assert_param(IS_SAI_BLOCK_FIRSTBIT_OFFSET(hsai->SlotInit.FirstBitOffset)); |
mbed_official | 87:085cde657901 | 267 | assert_param(IS_SAI_BLOCK_SLOT_SIZE(hsai->SlotInit.SlotSize)); |
mbed_official | 87:085cde657901 | 268 | assert_param(IS_SAI_BLOCK_SLOT_NUMBER(hsai->SlotInit.SlotNumber)); |
mbed_official | 87:085cde657901 | 269 | assert_param(IS_SAI_SLOT_ACTIVE(hsai->SlotInit.SlotActive)); |
mbed_official | 87:085cde657901 | 270 | |
mbed_official | 87:085cde657901 | 271 | if(hsai->State == HAL_SAI_STATE_RESET) |
mbed_official | 87:085cde657901 | 272 | { |
mbed_official | 87:085cde657901 | 273 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 87:085cde657901 | 274 | HAL_SAI_MspInit(hsai); |
mbed_official | 87:085cde657901 | 275 | } |
mbed_official | 87:085cde657901 | 276 | |
mbed_official | 87:085cde657901 | 277 | hsai->State = HAL_SAI_STATE_BUSY; |
mbed_official | 87:085cde657901 | 278 | |
mbed_official | 87:085cde657901 | 279 | /* Disable the selected SAI peripheral */ |
mbed_official | 87:085cde657901 | 280 | __HAL_SAI_DISABLE(hsai); |
mbed_official | 87:085cde657901 | 281 | |
mbed_official | 87:085cde657901 | 282 | /* SAI Block Configuration ------------------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 283 | /* SAI Block_x CR1 Configuration */ |
mbed_official | 87:085cde657901 | 284 | /* Get the SAI Block_x CR1 value */ |
mbed_official | 87:085cde657901 | 285 | tmpreg = hsai->Instance->CR1; |
mbed_official | 87:085cde657901 | 286 | /* Clear MODE, PRTCFG, DS, LSBFIRST, CKSTR, SYNCEN, OUTDRIV, NODIV, and MCKDIV bits */ |
mbed_official | 87:085cde657901 | 287 | tmpreg &= CR1_CLEAR_MASK; |
mbed_official | 87:085cde657901 | 288 | /* Configure SAI_Block_x: Audio Protocol, Data Size, first transmitted bit, Clock strobing |
mbed_official | 87:085cde657901 | 289 | edge, Synchronization mode, Output drive, Master Divider and FIFO level */ |
mbed_official | 87:085cde657901 | 290 | /* Set PRTCFG bits according to Protocol value */ |
mbed_official | 87:085cde657901 | 291 | /* Set DS bits according to DataSize value */ |
mbed_official | 87:085cde657901 | 292 | /* Set LSBFIRST bit according to FirstBit value */ |
mbed_official | 87:085cde657901 | 293 | /* Set CKSTR bit according to ClockStrobing value */ |
mbed_official | 87:085cde657901 | 294 | /* Set SYNCEN bit according to Synchro value */ |
mbed_official | 87:085cde657901 | 295 | /* Set OUTDRIV bit according to OutputDrive value */ |
mbed_official | 87:085cde657901 | 296 | /* Set NODIV bit according to NoDivider value */ |
mbed_official | 87:085cde657901 | 297 | tmpreg |= (uint32_t)(hsai->Init.Protocol | |
mbed_official | 87:085cde657901 | 298 | hsai->Init.AudioMode | |
mbed_official | 87:085cde657901 | 299 | hsai->Init.DataSize | |
mbed_official | 87:085cde657901 | 300 | hsai->Init.FirstBit | |
mbed_official | 87:085cde657901 | 301 | hsai->Init.ClockStrobing | |
mbed_official | 87:085cde657901 | 302 | hsai->Init.Synchro | |
mbed_official | 87:085cde657901 | 303 | hsai->Init.OutputDrive | |
mbed_official | 87:085cde657901 | 304 | hsai->Init.NoDivider); |
mbed_official | 87:085cde657901 | 305 | /* Write to SAI_Block_x CR1 */ |
mbed_official | 87:085cde657901 | 306 | hsai->Instance->CR1 = tmpreg; |
mbed_official | 87:085cde657901 | 307 | |
mbed_official | 87:085cde657901 | 308 | /* SAI Block_x CR2 Configuration */ |
mbed_official | 87:085cde657901 | 309 | /* Get the SAIBlock_x CR2 value */ |
mbed_official | 87:085cde657901 | 310 | tmpreg = hsai->Instance->CR2; |
mbed_official | 87:085cde657901 | 311 | /* Clear FTH bits */ |
mbed_official | 87:085cde657901 | 312 | tmpreg &= ~(SAI_xCR2_FTH); |
mbed_official | 87:085cde657901 | 313 | /* Configure the FIFO Level */ |
mbed_official | 87:085cde657901 | 314 | /* Set FTH bits according to SAI_FIFOThreshold value */ |
mbed_official | 87:085cde657901 | 315 | tmpreg |= (uint32_t)(hsai->Init.FIFOThreshold); |
mbed_official | 87:085cde657901 | 316 | /* Write to SAI_Block_x CR2 */ |
mbed_official | 87:085cde657901 | 317 | hsai->Instance->CR2 = tmpreg; |
mbed_official | 87:085cde657901 | 318 | |
mbed_official | 87:085cde657901 | 319 | /* SAI Block_x Frame Configuration -----------------------------------------*/ |
mbed_official | 87:085cde657901 | 320 | /* Get the SAI Block_x FRCR value */ |
mbed_official | 87:085cde657901 | 321 | tmpreg = hsai->Instance->FRCR; |
mbed_official | 87:085cde657901 | 322 | /* Clear FRL, FSALL, FSDEF, FSPOL, FSOFF bits */ |
mbed_official | 87:085cde657901 | 323 | tmpreg &= FRCR_CLEAR_MASK; |
mbed_official | 87:085cde657901 | 324 | /* Configure SAI_Block_x Frame: Frame Length, Active Frame Length, Frame Synchronization |
mbed_official | 87:085cde657901 | 325 | Definition, Frame Synchronization Polarity and Frame Synchronization Polarity */ |
mbed_official | 87:085cde657901 | 326 | /* Set FRL bits according to SAI_FrameLength value */ |
mbed_official | 87:085cde657901 | 327 | /* Set FSALL bits according to SAI_ActiveFrameLength value */ |
mbed_official | 87:085cde657901 | 328 | /* Set FSDEF bit according to SAI_FSDefinition value */ |
mbed_official | 87:085cde657901 | 329 | /* Set FSPOL bit according to SAI_FSPolarity value */ |
mbed_official | 87:085cde657901 | 330 | /* Set FSOFF bit according to SAI_FSOffset value */ |
mbed_official | 87:085cde657901 | 331 | tmpreg |= (uint32_t)((uint32_t)(hsai->FrameInit.FrameLength - 1) | |
mbed_official | 87:085cde657901 | 332 | hsai->FrameInit.FSOffset | |
mbed_official | 87:085cde657901 | 333 | hsai->FrameInit.FSDefinition | |
mbed_official | 87:085cde657901 | 334 | hsai->FrameInit.FSPolarity | |
mbed_official | 87:085cde657901 | 335 | (uint32_t)((hsai->FrameInit.ActiveFrameLength - 1) << 8)); |
mbed_official | 87:085cde657901 | 336 | |
mbed_official | 87:085cde657901 | 337 | /* Write to SAI_Block_x FRCR */ |
mbed_official | 87:085cde657901 | 338 | hsai->Instance->FRCR = tmpreg; |
mbed_official | 87:085cde657901 | 339 | |
mbed_official | 87:085cde657901 | 340 | /* SAI Block_x SLOT Configuration ------------------------------------------*/ |
mbed_official | 87:085cde657901 | 341 | /* Get the SAI Block_x SLOTR value */ |
mbed_official | 87:085cde657901 | 342 | tmpreg = hsai->Instance->SLOTR; |
mbed_official | 87:085cde657901 | 343 | /* Clear FBOFF, SLOTSZ, NBSLOT, SLOTEN bits */ |
mbed_official | 87:085cde657901 | 344 | tmpreg &= SLOTR_CLEAR_MASK; |
mbed_official | 87:085cde657901 | 345 | /* Configure SAI_Block_x Slot: First bit offset, Slot size, Number of Slot in |
mbed_official | 87:085cde657901 | 346 | audio frame and slots activated in audio frame */ |
mbed_official | 87:085cde657901 | 347 | /* Set FBOFF bits according to SAI_FirstBitOffset value */ |
mbed_official | 87:085cde657901 | 348 | /* Set SLOTSZ bits according to SAI_SlotSize value */ |
mbed_official | 87:085cde657901 | 349 | /* Set NBSLOT bits according to SAI_SlotNumber value */ |
mbed_official | 87:085cde657901 | 350 | /* Set SLOTEN bits according to SAI_SlotActive value */ |
mbed_official | 87:085cde657901 | 351 | tmpreg |= (uint32_t)(hsai->SlotInit.FirstBitOffset | |
mbed_official | 87:085cde657901 | 352 | hsai->SlotInit.SlotSize | |
mbed_official | 87:085cde657901 | 353 | hsai->SlotInit.SlotActive | |
mbed_official | 87:085cde657901 | 354 | (uint32_t)((hsai->SlotInit.SlotNumber - 1) << 8)); |
mbed_official | 87:085cde657901 | 355 | |
mbed_official | 87:085cde657901 | 356 | /* Write to SAI_Block_x SLOTR */ |
mbed_official | 87:085cde657901 | 357 | hsai->Instance->SLOTR = tmpreg; |
mbed_official | 87:085cde657901 | 358 | |
mbed_official | 87:085cde657901 | 359 | /* SAI Block_x Clock Configuration -----------------------------------------*/ |
mbed_official | 87:085cde657901 | 360 | /* Check the Clock parameters */ |
mbed_official | 87:085cde657901 | 361 | assert_param(IS_SAI_CLK_SOURCE(hsai->Init.ClockSource)); |
mbed_official | 87:085cde657901 | 362 | |
mbed_official | 87:085cde657901 | 363 | /* SAI Block clock source selection */ |
mbed_official | 87:085cde657901 | 364 | if(hsai->Instance == SAI1_Block_A) |
mbed_official | 87:085cde657901 | 365 | { |
mbed_official | 87:085cde657901 | 366 | __HAL_RCC_SAI_BLOCKACLKSOURCE_CONFIG(hsai->Init.ClockSource); |
mbed_official | 87:085cde657901 | 367 | } |
mbed_official | 87:085cde657901 | 368 | else |
mbed_official | 87:085cde657901 | 369 | { |
mbed_official | 87:085cde657901 | 370 | __HAL_RCC_SAI_BLOCKBCLKSOURCE_CONFIG((uint32_t)(hsai->Init.ClockSource << 2)); |
mbed_official | 87:085cde657901 | 371 | } |
mbed_official | 87:085cde657901 | 372 | |
mbed_official | 87:085cde657901 | 373 | /* VCO Input Clock value calculation */ |
mbed_official | 87:085cde657901 | 374 | if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI) |
mbed_official | 87:085cde657901 | 375 | { |
mbed_official | 87:085cde657901 | 376 | /* In Case the PLL Source is HSI (Internal Clock) */ |
mbed_official | 87:085cde657901 | 377 | vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)); |
mbed_official | 87:085cde657901 | 378 | } |
mbed_official | 87:085cde657901 | 379 | else |
mbed_official | 87:085cde657901 | 380 | { |
mbed_official | 87:085cde657901 | 381 | /* In Case the PLL Source is HSE (External Clock) */ |
mbed_official | 87:085cde657901 | 382 | vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM))); |
mbed_official | 87:085cde657901 | 383 | } |
mbed_official | 87:085cde657901 | 384 | |
mbed_official | 87:085cde657901 | 385 | /* SAI_CLK_x : SAI Block Clock configuration for different clock sources selected */ |
mbed_official | 87:085cde657901 | 386 | if(hsai->Init.ClockSource == SAI_CLKSOURCE_PLLSAI) |
mbed_official | 87:085cde657901 | 387 | { |
mbed_official | 87:085cde657901 | 388 | /* Configure the PLLI2S division factor */ |
mbed_official | 87:085cde657901 | 389 | /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */ |
mbed_official | 87:085cde657901 | 390 | /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */ |
mbed_official | 87:085cde657901 | 391 | /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */ |
mbed_official | 87:085cde657901 | 392 | tmpreg = (RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> 24; |
mbed_official | 87:085cde657901 | 393 | saiclocksource = (vcoinput * ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> 6))/(tmpreg); |
mbed_official | 87:085cde657901 | 394 | |
mbed_official | 87:085cde657901 | 395 | /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */ |
mbed_official | 87:085cde657901 | 396 | tmpreg = (((RCC->DCKCFGR & RCC_DCKCFGR_PLLSAIDIVQ) >> 8) + 1); |
mbed_official | 87:085cde657901 | 397 | saiclocksource = saiclocksource/(tmpreg); |
mbed_official | 87:085cde657901 | 398 | |
mbed_official | 87:085cde657901 | 399 | } |
mbed_official | 87:085cde657901 | 400 | else if(hsai->Init.ClockSource == SAI_CLKSOURCE_PLLI2S) |
mbed_official | 87:085cde657901 | 401 | { |
mbed_official | 87:085cde657901 | 402 | /* Configure the PLLI2S division factor */ |
mbed_official | 87:085cde657901 | 403 | /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */ |
mbed_official | 87:085cde657901 | 404 | /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */ |
mbed_official | 87:085cde657901 | 405 | /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */ |
mbed_official | 87:085cde657901 | 406 | tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> 24; |
mbed_official | 87:085cde657901 | 407 | saiclocksource = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6))/(tmpreg); |
mbed_official | 87:085cde657901 | 408 | |
mbed_official | 87:085cde657901 | 409 | /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */ |
mbed_official | 87:085cde657901 | 410 | tmpreg = ((RCC->DCKCFGR & RCC_DCKCFGR_PLLI2SDIVQ) + 1); |
mbed_official | 87:085cde657901 | 411 | saiclocksource = saiclocksource/(tmpreg); |
mbed_official | 87:085cde657901 | 412 | } |
mbed_official | 87:085cde657901 | 413 | else /* sConfig->ClockSource == SAI_CLKSource_Ext */ |
mbed_official | 87:085cde657901 | 414 | { |
mbed_official | 87:085cde657901 | 415 | /* Enable the External Clock selection */ |
mbed_official | 87:085cde657901 | 416 | __HAL_RCC_I2SCLK(RCC_I2SCLKSOURCE_EXT); |
mbed_official | 87:085cde657901 | 417 | |
mbed_official | 87:085cde657901 | 418 | saiclocksource = EXTERNAL_CLOCK_VALUE; |
mbed_official | 87:085cde657901 | 419 | } |
mbed_official | 87:085cde657901 | 420 | |
mbed_official | 87:085cde657901 | 421 | /* Configure Master Clock using the following formula : |
mbed_official | 87:085cde657901 | 422 | MCLK_x = SAI_CK_x / (MCKDIV[3:0] * 2) with MCLK_x = 256 * FS |
mbed_official | 87:085cde657901 | 423 | FS = SAI_CK_x / (MCKDIV[3:0] * 2) * 256 |
mbed_official | 87:085cde657901 | 424 | MCKDIV[3:0] = SAI_CK_x / FS * 512 */ |
mbed_official | 87:085cde657901 | 425 | if(hsai->Init.NoDivider == SAI_MASTERDIVIDER_ENABLED) |
mbed_official | 87:085cde657901 | 426 | { |
mbed_official | 87:085cde657901 | 427 | /* (saiclocksource x 10) to keep Significant digits */ |
mbed_official | 87:085cde657901 | 428 | tmpclock = (((saiclocksource * 10) / ((hsai->Init.AudioFrequency) * 512))); |
mbed_official | 87:085cde657901 | 429 | |
mbed_official | 87:085cde657901 | 430 | /* Get the result of modulo division */ |
mbed_official | 87:085cde657901 | 431 | tmp2clock = (tmpclock % 10); |
mbed_official | 87:085cde657901 | 432 | |
mbed_official | 87:085cde657901 | 433 | /* Round result to the nearest integer*/ |
mbed_official | 87:085cde657901 | 434 | if (tmp2clock > 8) |
mbed_official | 87:085cde657901 | 435 | { |
mbed_official | 87:085cde657901 | 436 | tmpclock = ((tmpclock / 10) + 1); |
mbed_official | 87:085cde657901 | 437 | } |
mbed_official | 87:085cde657901 | 438 | else |
mbed_official | 87:085cde657901 | 439 | { |
mbed_official | 87:085cde657901 | 440 | tmpclock = (tmpclock / 10); |
mbed_official | 87:085cde657901 | 441 | } |
mbed_official | 87:085cde657901 | 442 | /*Set MCKDIV value in CR1 register*/ |
mbed_official | 87:085cde657901 | 443 | hsai->Instance->CR1 |= (tmpclock << 20); |
mbed_official | 87:085cde657901 | 444 | |
mbed_official | 106:ced8cbb51063 | 445 | } |
mbed_official | 87:085cde657901 | 446 | |
mbed_official | 87:085cde657901 | 447 | /* Initialise the error code */ |
mbed_official | 87:085cde657901 | 448 | hsai->ErrorCode = HAL_SAI_ERROR_NONE; |
mbed_official | 106:ced8cbb51063 | 449 | |
mbed_official | 87:085cde657901 | 450 | /* Initialize the SAI state */ |
mbed_official | 87:085cde657901 | 451 | hsai->State= HAL_SAI_STATE_READY; |
mbed_official | 106:ced8cbb51063 | 452 | |
mbed_official | 87:085cde657901 | 453 | return HAL_OK; |
mbed_official | 87:085cde657901 | 454 | } |
mbed_official | 87:085cde657901 | 455 | |
mbed_official | 87:085cde657901 | 456 | /** |
mbed_official | 87:085cde657901 | 457 | * @brief DeInitializes the SAI peripheral. |
mbed_official | 226:b062af740e40 | 458 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 459 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 460 | * @retval HAL status |
mbed_official | 87:085cde657901 | 461 | */ |
mbed_official | 87:085cde657901 | 462 | HAL_StatusTypeDef HAL_SAI_DeInit(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 463 | { |
mbed_official | 87:085cde657901 | 464 | /* Check the SAI handle allocation */ |
mbed_official | 384:ef87175507f1 | 465 | if(hsai == HAL_NULL) |
mbed_official | 87:085cde657901 | 466 | { |
mbed_official | 87:085cde657901 | 467 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 468 | } |
mbed_official | 106:ced8cbb51063 | 469 | |
mbed_official | 87:085cde657901 | 470 | hsai->State = HAL_SAI_STATE_BUSY; |
mbed_official | 106:ced8cbb51063 | 471 | |
mbed_official | 87:085cde657901 | 472 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
mbed_official | 87:085cde657901 | 473 | HAL_SAI_MspDeInit(hsai); |
mbed_official | 87:085cde657901 | 474 | |
mbed_official | 87:085cde657901 | 475 | /* Initialize the error code */ |
mbed_official | 87:085cde657901 | 476 | hsai->ErrorCode = HAL_SAI_ERROR_NONE; |
mbed_official | 87:085cde657901 | 477 | |
mbed_official | 87:085cde657901 | 478 | /* Initialize the SAI state */ |
mbed_official | 87:085cde657901 | 479 | hsai->State = HAL_SAI_STATE_RESET; |
mbed_official | 106:ced8cbb51063 | 480 | |
mbed_official | 106:ced8cbb51063 | 481 | /* Release Lock */ |
mbed_official | 106:ced8cbb51063 | 482 | __HAL_UNLOCK(hsai); |
mbed_official | 106:ced8cbb51063 | 483 | |
mbed_official | 87:085cde657901 | 484 | return HAL_OK; |
mbed_official | 87:085cde657901 | 485 | } |
mbed_official | 87:085cde657901 | 486 | |
mbed_official | 87:085cde657901 | 487 | /** |
mbed_official | 87:085cde657901 | 488 | * @brief SAI MSP Init. |
mbed_official | 226:b062af740e40 | 489 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 490 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 491 | * @retval None |
mbed_official | 87:085cde657901 | 492 | */ |
mbed_official | 87:085cde657901 | 493 | __weak void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 494 | { |
mbed_official | 87:085cde657901 | 495 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 496 | the HAL_SAI_MspInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 497 | */ |
mbed_official | 87:085cde657901 | 498 | } |
mbed_official | 87:085cde657901 | 499 | |
mbed_official | 87:085cde657901 | 500 | /** |
mbed_official | 87:085cde657901 | 501 | * @brief SAI MSP DeInit. |
mbed_official | 226:b062af740e40 | 502 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 503 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 504 | * @retval None |
mbed_official | 87:085cde657901 | 505 | */ |
mbed_official | 87:085cde657901 | 506 | __weak void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 507 | { |
mbed_official | 87:085cde657901 | 508 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 509 | the HAL_SAI_MspDeInit could be implemented in the user file |
mbed_official | 87:085cde657901 | 510 | */ |
mbed_official | 87:085cde657901 | 511 | } |
mbed_official | 87:085cde657901 | 512 | |
mbed_official | 87:085cde657901 | 513 | /** |
mbed_official | 87:085cde657901 | 514 | * @} |
mbed_official | 87:085cde657901 | 515 | */ |
mbed_official | 87:085cde657901 | 516 | |
mbed_official | 87:085cde657901 | 517 | /** @defgroup SAI_Group2 IO operation functions |
mbed_official | 87:085cde657901 | 518 | * @brief Data transfers functions |
mbed_official | 87:085cde657901 | 519 | * |
mbed_official | 87:085cde657901 | 520 | @verbatim |
mbed_official | 87:085cde657901 | 521 | =============================================================================== |
mbed_official | 87:085cde657901 | 522 | ##### IO operation functions ##### |
mbed_official | 87:085cde657901 | 523 | =============================================================================== |
mbed_official | 87:085cde657901 | 524 | [..] |
mbed_official | 87:085cde657901 | 525 | This subsection provides a set of functions allowing to manage the SAI data |
mbed_official | 87:085cde657901 | 526 | transfers. |
mbed_official | 87:085cde657901 | 527 | |
mbed_official | 226:b062af740e40 | 528 | (+) There are two modes of transfer: |
mbed_official | 87:085cde657901 | 529 | (++) Blocking mode : The communication is performed in the polling mode. |
mbed_official | 87:085cde657901 | 530 | The status of all data processing is returned by the same function |
mbed_official | 87:085cde657901 | 531 | after finishing transfer. |
mbed_official | 87:085cde657901 | 532 | (++) No-Blocking mode : The communication is performed using Interrupts |
mbed_official | 87:085cde657901 | 533 | or DMA. These functions return the status of the transfer startup. |
mbed_official | 87:085cde657901 | 534 | The end of the data processing will be indicated through the |
mbed_official | 87:085cde657901 | 535 | dedicated SAI IRQ when using Interrupt mode or the DMA IRQ when |
mbed_official | 87:085cde657901 | 536 | using DMA mode. |
mbed_official | 87:085cde657901 | 537 | |
mbed_official | 87:085cde657901 | 538 | (+) Blocking mode functions are : |
mbed_official | 87:085cde657901 | 539 | (++) HAL_SAI_Transmit() |
mbed_official | 87:085cde657901 | 540 | (++) HAL_SAI_Receive() |
mbed_official | 87:085cde657901 | 541 | (++) HAL_SAI_TransmitReceive() |
mbed_official | 87:085cde657901 | 542 | |
mbed_official | 226:b062af740e40 | 543 | (+) Non Blocking mode functions with Interrupt are : |
mbed_official | 87:085cde657901 | 544 | (++) HAL_SAI_Transmit_IT() |
mbed_official | 87:085cde657901 | 545 | (++) HAL_SAI_Receive_IT() |
mbed_official | 87:085cde657901 | 546 | (++) HAL_SAI_TransmitReceive_IT() |
mbed_official | 87:085cde657901 | 547 | |
mbed_official | 226:b062af740e40 | 548 | (+) Non Blocking mode functions with DMA are : |
mbed_official | 87:085cde657901 | 549 | (++) HAL_SAI_Transmit_DMA() |
mbed_official | 87:085cde657901 | 550 | (++) HAL_SAI_Receive_DMA() |
mbed_official | 87:085cde657901 | 551 | (++) HAL_SAI_TransmitReceive_DMA() |
mbed_official | 87:085cde657901 | 552 | |
mbed_official | 226:b062af740e40 | 553 | (+) A set of Transfer Complete Callbacks are provided in non Blocking mode: |
mbed_official | 87:085cde657901 | 554 | (++) HAL_SAI_TxCpltCallback() |
mbed_official | 87:085cde657901 | 555 | (++) HAL_SAI_RxCpltCallback() |
mbed_official | 87:085cde657901 | 556 | (++) HAL_SAI_ErrorCallback() |
mbed_official | 87:085cde657901 | 557 | |
mbed_official | 87:085cde657901 | 558 | @endverbatim |
mbed_official | 87:085cde657901 | 559 | * @{ |
mbed_official | 87:085cde657901 | 560 | */ |
mbed_official | 87:085cde657901 | 561 | |
mbed_official | 87:085cde657901 | 562 | /** |
mbed_official | 87:085cde657901 | 563 | * @brief Transmits an amount of data in blocking mode. |
mbed_official | 226:b062af740e40 | 564 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 565 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 566 | * @param pData: Pointer to data buffer |
mbed_official | 87:085cde657901 | 567 | * @param Size: Amount of data to be sent |
mbed_official | 87:085cde657901 | 568 | * @param Timeout: Timeout duration |
mbed_official | 87:085cde657901 | 569 | * @retval HAL status |
mbed_official | 87:085cde657901 | 570 | */ |
mbed_official | 87:085cde657901 | 571 | HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint16_t* pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 572 | { |
mbed_official | 369:2e96f1b71984 | 573 | uint32_t tickstart = 0; |
mbed_official | 87:085cde657901 | 574 | |
mbed_official | 384:ef87175507f1 | 575 | if((pData == HAL_NULL ) || (Size == 0)) |
mbed_official | 87:085cde657901 | 576 | { |
mbed_official | 87:085cde657901 | 577 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 578 | } |
mbed_official | 87:085cde657901 | 579 | |
mbed_official | 87:085cde657901 | 580 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 87:085cde657901 | 581 | { |
mbed_official | 87:085cde657901 | 582 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 583 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 584 | |
mbed_official | 87:085cde657901 | 585 | hsai->State = HAL_SAI_STATE_BUSY_TX; |
mbed_official | 87:085cde657901 | 586 | |
mbed_official | 87:085cde657901 | 587 | /* Check if the SAI is already enabled */ |
mbed_official | 87:085cde657901 | 588 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 87:085cde657901 | 589 | { |
mbed_official | 87:085cde657901 | 590 | /* Enable SAI peripheral */ |
mbed_official | 87:085cde657901 | 591 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 87:085cde657901 | 592 | } |
mbed_official | 87:085cde657901 | 593 | |
mbed_official | 87:085cde657901 | 594 | while(Size > 0) |
mbed_official | 87:085cde657901 | 595 | { |
mbed_official | 369:2e96f1b71984 | 596 | /* Get tick */ |
mbed_official | 369:2e96f1b71984 | 597 | tickstart = HAL_GetTick(); |
mbed_official | 369:2e96f1b71984 | 598 | |
mbed_official | 87:085cde657901 | 599 | /* Wait the FIFO to be empty */ |
mbed_official | 87:085cde657901 | 600 | while(__HAL_SAI_GET_FLAG(hsai, SAI_xSR_FREQ) == RESET) |
mbed_official | 87:085cde657901 | 601 | { |
mbed_official | 87:085cde657901 | 602 | /* Check for the Timeout */ |
mbed_official | 87:085cde657901 | 603 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 87:085cde657901 | 604 | { |
mbed_official | 369:2e96f1b71984 | 605 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 369:2e96f1b71984 | 606 | { |
mbed_official | 87:085cde657901 | 607 | /* Update error code */ |
mbed_official | 87:085cde657901 | 608 | hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT; |
mbed_official | 87:085cde657901 | 609 | |
mbed_official | 87:085cde657901 | 610 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 611 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 612 | |
mbed_official | 87:085cde657901 | 613 | /* Change the SAI state */ |
mbed_official | 87:085cde657901 | 614 | hsai->State = HAL_SAI_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 615 | |
mbed_official | 87:085cde657901 | 616 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 617 | } |
mbed_official | 87:085cde657901 | 618 | } |
mbed_official | 87:085cde657901 | 619 | } |
mbed_official | 87:085cde657901 | 620 | hsai->Instance->DR = (*pData++); |
mbed_official | 87:085cde657901 | 621 | Size--; |
mbed_official | 87:085cde657901 | 622 | } |
mbed_official | 87:085cde657901 | 623 | |
mbed_official | 87:085cde657901 | 624 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 87:085cde657901 | 625 | |
mbed_official | 87:085cde657901 | 626 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 627 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 628 | |
mbed_official | 87:085cde657901 | 629 | return HAL_OK; |
mbed_official | 87:085cde657901 | 630 | } |
mbed_official | 87:085cde657901 | 631 | else |
mbed_official | 87:085cde657901 | 632 | { |
mbed_official | 87:085cde657901 | 633 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 634 | } |
mbed_official | 87:085cde657901 | 635 | } |
mbed_official | 87:085cde657901 | 636 | |
mbed_official | 87:085cde657901 | 637 | /** |
mbed_official | 87:085cde657901 | 638 | * @brief Receives an amount of data in blocking mode. |
mbed_official | 226:b062af740e40 | 639 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 640 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 641 | * @param pData: Pointer to data buffer |
mbed_official | 87:085cde657901 | 642 | * @param Size: Amount of data to be received |
mbed_official | 87:085cde657901 | 643 | * @param Timeout: Timeout duration |
mbed_official | 87:085cde657901 | 644 | * @retval HAL status |
mbed_official | 87:085cde657901 | 645 | */ |
mbed_official | 87:085cde657901 | 646 | HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 87:085cde657901 | 647 | { |
mbed_official | 369:2e96f1b71984 | 648 | uint32_t tickstart = 0; |
mbed_official | 87:085cde657901 | 649 | |
mbed_official | 384:ef87175507f1 | 650 | if((pData == HAL_NULL ) || (Size == 0)) |
mbed_official | 87:085cde657901 | 651 | { |
mbed_official | 87:085cde657901 | 652 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 653 | } |
mbed_official | 87:085cde657901 | 654 | |
mbed_official | 87:085cde657901 | 655 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 87:085cde657901 | 656 | { |
mbed_official | 87:085cde657901 | 657 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 658 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 659 | |
mbed_official | 87:085cde657901 | 660 | hsai->State = HAL_SAI_STATE_BUSY_RX; |
mbed_official | 87:085cde657901 | 661 | |
mbed_official | 87:085cde657901 | 662 | /* Check if the SAI is already enabled */ |
mbed_official | 87:085cde657901 | 663 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 87:085cde657901 | 664 | { |
mbed_official | 87:085cde657901 | 665 | /* Enable SAI peripheral */ |
mbed_official | 87:085cde657901 | 666 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 87:085cde657901 | 667 | } |
mbed_official | 87:085cde657901 | 668 | |
mbed_official | 87:085cde657901 | 669 | /* Receive data */ |
mbed_official | 87:085cde657901 | 670 | while(Size > 0) |
mbed_official | 87:085cde657901 | 671 | { |
mbed_official | 369:2e96f1b71984 | 672 | /* Get tick */ |
mbed_official | 369:2e96f1b71984 | 673 | tickstart = HAL_GetTick(); |
mbed_official | 369:2e96f1b71984 | 674 | |
mbed_official | 87:085cde657901 | 675 | /* Wait until RXNE flag is set */ |
mbed_official | 87:085cde657901 | 676 | while(__HAL_SAI_GET_FLAG(hsai, SAI_xSR_FREQ) == RESET) |
mbed_official | 87:085cde657901 | 677 | { |
mbed_official | 87:085cde657901 | 678 | /* Check for the Timeout */ |
mbed_official | 87:085cde657901 | 679 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 87:085cde657901 | 680 | { |
mbed_official | 369:2e96f1b71984 | 681 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
mbed_official | 369:2e96f1b71984 | 682 | { |
mbed_official | 87:085cde657901 | 683 | /* Update error code */ |
mbed_official | 87:085cde657901 | 684 | hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT; |
mbed_official | 87:085cde657901 | 685 | |
mbed_official | 87:085cde657901 | 686 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 687 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 688 | |
mbed_official | 87:085cde657901 | 689 | /* Change the SAI state */ |
mbed_official | 87:085cde657901 | 690 | hsai->State = HAL_SAI_STATE_TIMEOUT; |
mbed_official | 87:085cde657901 | 691 | |
mbed_official | 87:085cde657901 | 692 | return HAL_TIMEOUT; |
mbed_official | 87:085cde657901 | 693 | } |
mbed_official | 87:085cde657901 | 694 | } |
mbed_official | 87:085cde657901 | 695 | } |
mbed_official | 87:085cde657901 | 696 | |
mbed_official | 87:085cde657901 | 697 | (*pData++) = hsai->Instance->DR; |
mbed_official | 87:085cde657901 | 698 | Size--; |
mbed_official | 87:085cde657901 | 699 | } |
mbed_official | 87:085cde657901 | 700 | |
mbed_official | 87:085cde657901 | 701 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 87:085cde657901 | 702 | |
mbed_official | 87:085cde657901 | 703 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 704 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 705 | |
mbed_official | 87:085cde657901 | 706 | return HAL_OK; |
mbed_official | 87:085cde657901 | 707 | } |
mbed_official | 87:085cde657901 | 708 | else |
mbed_official | 87:085cde657901 | 709 | { |
mbed_official | 87:085cde657901 | 710 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 711 | } |
mbed_official | 87:085cde657901 | 712 | } |
mbed_official | 87:085cde657901 | 713 | |
mbed_official | 87:085cde657901 | 714 | /** |
mbed_official | 87:085cde657901 | 715 | * @brief Transmits an amount of data in no-blocking mode with Interrupt. |
mbed_official | 226:b062af740e40 | 716 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 717 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 718 | * @param pData: Pointer to data buffer |
mbed_official | 87:085cde657901 | 719 | * @param Size: Amount of data to be sent |
mbed_official | 87:085cde657901 | 720 | * @retval HAL status |
mbed_official | 87:085cde657901 | 721 | */ |
mbed_official | 87:085cde657901 | 722 | HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size) |
mbed_official | 87:085cde657901 | 723 | { |
mbed_official | 87:085cde657901 | 724 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 87:085cde657901 | 725 | { |
mbed_official | 384:ef87175507f1 | 726 | if((pData == HAL_NULL) || (Size == 0)) |
mbed_official | 87:085cde657901 | 727 | { |
mbed_official | 87:085cde657901 | 728 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 729 | } |
mbed_official | 87:085cde657901 | 730 | |
mbed_official | 87:085cde657901 | 731 | hsai->pTxBuffPtr = pData; |
mbed_official | 87:085cde657901 | 732 | hsai->TxXferSize = Size; |
mbed_official | 87:085cde657901 | 733 | hsai->TxXferCount = Size; |
mbed_official | 87:085cde657901 | 734 | |
mbed_official | 87:085cde657901 | 735 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 736 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 737 | |
mbed_official | 87:085cde657901 | 738 | hsai->State = HAL_SAI_STATE_BUSY_TX; |
mbed_official | 87:085cde657901 | 739 | |
mbed_official | 87:085cde657901 | 740 | /* Transmit data */ |
mbed_official | 87:085cde657901 | 741 | hsai->Instance->DR = (*hsai->pTxBuffPtr++); |
mbed_official | 87:085cde657901 | 742 | hsai->TxXferCount--; |
mbed_official | 87:085cde657901 | 743 | |
mbed_official | 87:085cde657901 | 744 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 745 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 746 | |
mbed_official | 87:085cde657901 | 747 | /* Enable FRQ and OVRUDR interrupts */ |
mbed_official | 87:085cde657901 | 748 | __HAL_SAI_ENABLE_IT(hsai, (SAI_IT_FREQ | SAI_IT_OVRUDR)); |
mbed_official | 87:085cde657901 | 749 | |
mbed_official | 87:085cde657901 | 750 | /* Check if the SAI is already enabled */ |
mbed_official | 87:085cde657901 | 751 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 87:085cde657901 | 752 | { |
mbed_official | 87:085cde657901 | 753 | /* Enable SAI peripheral */ |
mbed_official | 87:085cde657901 | 754 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 87:085cde657901 | 755 | } |
mbed_official | 87:085cde657901 | 756 | |
mbed_official | 87:085cde657901 | 757 | |
mbed_official | 87:085cde657901 | 758 | return HAL_OK; |
mbed_official | 87:085cde657901 | 759 | } |
mbed_official | 87:085cde657901 | 760 | else if(hsai->State == HAL_SAI_STATE_BUSY_TX) |
mbed_official | 87:085cde657901 | 761 | { |
mbed_official | 87:085cde657901 | 762 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 763 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 764 | |
mbed_official | 87:085cde657901 | 765 | /* Transmit data */ |
mbed_official | 87:085cde657901 | 766 | hsai->Instance->DR = (*hsai->pTxBuffPtr++); |
mbed_official | 87:085cde657901 | 767 | |
mbed_official | 87:085cde657901 | 768 | hsai->TxXferCount--; |
mbed_official | 87:085cde657901 | 769 | |
mbed_official | 87:085cde657901 | 770 | if(hsai->TxXferCount == 0) |
mbed_official | 87:085cde657901 | 771 | { |
mbed_official | 87:085cde657901 | 772 | /* Disable FREQ and OVRUDR interrupts */ |
mbed_official | 87:085cde657901 | 773 | __HAL_SAI_DISABLE_IT(hsai, (SAI_IT_FREQ | SAI_IT_OVRUDR)); |
mbed_official | 87:085cde657901 | 774 | |
mbed_official | 87:085cde657901 | 775 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 87:085cde657901 | 776 | |
mbed_official | 87:085cde657901 | 777 | HAL_SAI_TxCpltCallback(hsai); |
mbed_official | 87:085cde657901 | 778 | } |
mbed_official | 87:085cde657901 | 779 | |
mbed_official | 87:085cde657901 | 780 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 781 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 782 | |
mbed_official | 87:085cde657901 | 783 | return HAL_OK; |
mbed_official | 87:085cde657901 | 784 | } |
mbed_official | 87:085cde657901 | 785 | |
mbed_official | 87:085cde657901 | 786 | else |
mbed_official | 87:085cde657901 | 787 | { |
mbed_official | 87:085cde657901 | 788 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 789 | } |
mbed_official | 87:085cde657901 | 790 | } |
mbed_official | 87:085cde657901 | 791 | |
mbed_official | 87:085cde657901 | 792 | /** |
mbed_official | 87:085cde657901 | 793 | * @brief Receives an amount of data in no-blocking mode with Interrupt. |
mbed_official | 226:b062af740e40 | 794 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 795 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 796 | * @param pData: Pointer to data buffer |
mbed_official | 87:085cde657901 | 797 | * @param Size: Amount of data to be received |
mbed_official | 87:085cde657901 | 798 | * @retval HAL status |
mbed_official | 87:085cde657901 | 799 | */ |
mbed_official | 87:085cde657901 | 800 | HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size) |
mbed_official | 87:085cde657901 | 801 | { |
mbed_official | 87:085cde657901 | 802 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 87:085cde657901 | 803 | { |
mbed_official | 384:ef87175507f1 | 804 | if((pData == HAL_NULL) || (Size == 0)) |
mbed_official | 87:085cde657901 | 805 | { |
mbed_official | 87:085cde657901 | 806 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 807 | } |
mbed_official | 87:085cde657901 | 808 | |
mbed_official | 87:085cde657901 | 809 | hsai->pRxBuffPtr = pData; |
mbed_official | 87:085cde657901 | 810 | hsai->RxXferSize = Size; |
mbed_official | 87:085cde657901 | 811 | hsai->RxXferCount = Size; |
mbed_official | 87:085cde657901 | 812 | |
mbed_official | 87:085cde657901 | 813 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 814 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 815 | |
mbed_official | 87:085cde657901 | 816 | hsai->State = HAL_SAI_STATE_BUSY_RX; |
mbed_official | 87:085cde657901 | 817 | |
mbed_official | 87:085cde657901 | 818 | /* Enable TXE and OVRUDR interrupts */ |
mbed_official | 87:085cde657901 | 819 | __HAL_SAI_ENABLE_IT(hsai, (SAI_IT_FREQ | SAI_IT_OVRUDR)); |
mbed_official | 87:085cde657901 | 820 | |
mbed_official | 87:085cde657901 | 821 | /* Check if the SAI is already enabled */ |
mbed_official | 87:085cde657901 | 822 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 87:085cde657901 | 823 | { |
mbed_official | 87:085cde657901 | 824 | /* Enable SAI peripheral */ |
mbed_official | 87:085cde657901 | 825 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 87:085cde657901 | 826 | } |
mbed_official | 87:085cde657901 | 827 | |
mbed_official | 87:085cde657901 | 828 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 829 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 830 | |
mbed_official | 87:085cde657901 | 831 | return HAL_OK; |
mbed_official | 87:085cde657901 | 832 | } |
mbed_official | 87:085cde657901 | 833 | else if(hsai->State == HAL_SAI_STATE_BUSY_RX) |
mbed_official | 87:085cde657901 | 834 | { |
mbed_official | 87:085cde657901 | 835 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 836 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 837 | |
mbed_official | 87:085cde657901 | 838 | /* Receive data */ |
mbed_official | 87:085cde657901 | 839 | (*hsai->pRxBuffPtr++) = hsai->Instance->DR; |
mbed_official | 87:085cde657901 | 840 | |
mbed_official | 87:085cde657901 | 841 | hsai->RxXferCount--; |
mbed_official | 87:085cde657901 | 842 | |
mbed_official | 87:085cde657901 | 843 | if(hsai->RxXferCount == 0) |
mbed_official | 87:085cde657901 | 844 | { |
mbed_official | 87:085cde657901 | 845 | /* Disable TXE and OVRUDR interrupts */ |
mbed_official | 87:085cde657901 | 846 | __HAL_SAI_DISABLE_IT(hsai, (SAI_IT_FREQ | SAI_IT_OVRUDR)); |
mbed_official | 87:085cde657901 | 847 | |
mbed_official | 87:085cde657901 | 848 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 87:085cde657901 | 849 | HAL_SAI_RxCpltCallback(hsai); |
mbed_official | 87:085cde657901 | 850 | } |
mbed_official | 87:085cde657901 | 851 | |
mbed_official | 87:085cde657901 | 852 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 853 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 854 | |
mbed_official | 87:085cde657901 | 855 | return HAL_OK; |
mbed_official | 87:085cde657901 | 856 | } |
mbed_official | 87:085cde657901 | 857 | |
mbed_official | 87:085cde657901 | 858 | else |
mbed_official | 87:085cde657901 | 859 | { |
mbed_official | 87:085cde657901 | 860 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 861 | } |
mbed_official | 87:085cde657901 | 862 | } |
mbed_official | 87:085cde657901 | 863 | |
mbed_official | 87:085cde657901 | 864 | /** |
mbed_official | 87:085cde657901 | 865 | * @brief Pauses the audio stream playing from the Media. |
mbed_official | 226:b062af740e40 | 866 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 867 | * the configuration information for SAI module. |
mbed_official | 226:b062af740e40 | 868 | * @retval HAL status |
mbed_official | 87:085cde657901 | 869 | */ |
mbed_official | 87:085cde657901 | 870 | HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 871 | { |
mbed_official | 87:085cde657901 | 872 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 873 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 874 | |
mbed_official | 87:085cde657901 | 875 | /* Pause the audio file playing by disabling the SAI DMA requests */ |
mbed_official | 87:085cde657901 | 876 | hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN; |
mbed_official | 87:085cde657901 | 877 | |
mbed_official | 87:085cde657901 | 878 | |
mbed_official | 87:085cde657901 | 879 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 880 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 881 | |
mbed_official | 87:085cde657901 | 882 | return HAL_OK; |
mbed_official | 87:085cde657901 | 883 | } |
mbed_official | 87:085cde657901 | 884 | |
mbed_official | 87:085cde657901 | 885 | /** |
mbed_official | 87:085cde657901 | 886 | * @brief Resumes the audio stream playing from the Media. |
mbed_official | 226:b062af740e40 | 887 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 888 | * the configuration information for SAI module. |
mbed_official | 226:b062af740e40 | 889 | * @retval HAL status |
mbed_official | 87:085cde657901 | 890 | */ |
mbed_official | 87:085cde657901 | 891 | HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 892 | { |
mbed_official | 87:085cde657901 | 893 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 894 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 895 | |
mbed_official | 87:085cde657901 | 896 | /* Enable the SAI DMA requests */ |
mbed_official | 87:085cde657901 | 897 | hsai->Instance->CR1 |= SAI_xCR1_DMAEN; |
mbed_official | 87:085cde657901 | 898 | |
mbed_official | 87:085cde657901 | 899 | |
mbed_official | 87:085cde657901 | 900 | /* If the SAI peripheral is still not enabled, enable it */ |
mbed_official | 87:085cde657901 | 901 | if ((hsai->Instance->CR1 & SAI_xCR1_SAIEN) == 0) |
mbed_official | 87:085cde657901 | 902 | { |
mbed_official | 87:085cde657901 | 903 | /* Enable SAI peripheral */ |
mbed_official | 87:085cde657901 | 904 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 87:085cde657901 | 905 | } |
mbed_official | 87:085cde657901 | 906 | |
mbed_official | 87:085cde657901 | 907 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 908 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 909 | |
mbed_official | 87:085cde657901 | 910 | return HAL_OK; |
mbed_official | 87:085cde657901 | 911 | } |
mbed_official | 87:085cde657901 | 912 | |
mbed_official | 87:085cde657901 | 913 | /** |
mbed_official | 226:b062af740e40 | 914 | * @brief Stops the audio stream playing from the Media. |
mbed_official | 226:b062af740e40 | 915 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 916 | * the configuration information for SAI module. |
mbed_official | 226:b062af740e40 | 917 | * @retval HAL status |
mbed_official | 87:085cde657901 | 918 | */ |
mbed_official | 87:085cde657901 | 919 | HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 920 | { |
mbed_official | 87:085cde657901 | 921 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 922 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 923 | |
mbed_official | 87:085cde657901 | 924 | /* Disable the SAI DMA request */ |
mbed_official | 87:085cde657901 | 925 | hsai->Instance->CR1 &= ~SAI_xCR1_DMAEN; |
mbed_official | 87:085cde657901 | 926 | |
mbed_official | 106:ced8cbb51063 | 927 | /* Abort the SAI DMA Tx Stream */ |
mbed_official | 384:ef87175507f1 | 928 | if(hsai->hdmatx != HAL_NULL) |
mbed_official | 106:ced8cbb51063 | 929 | { |
mbed_official | 106:ced8cbb51063 | 930 | HAL_DMA_Abort(hsai->hdmatx); |
mbed_official | 106:ced8cbb51063 | 931 | } |
mbed_official | 106:ced8cbb51063 | 932 | /* Abort the SAI DMA Rx Stream */ |
mbed_official | 384:ef87175507f1 | 933 | if(hsai->hdmarx != HAL_NULL) |
mbed_official | 106:ced8cbb51063 | 934 | { |
mbed_official | 106:ced8cbb51063 | 935 | HAL_DMA_Abort(hsai->hdmarx); |
mbed_official | 106:ced8cbb51063 | 936 | } |
mbed_official | 106:ced8cbb51063 | 937 | |
mbed_official | 87:085cde657901 | 938 | /* Disable SAI peripheral */ |
mbed_official | 87:085cde657901 | 939 | __HAL_SAI_DISABLE(hsai); |
mbed_official | 87:085cde657901 | 940 | |
mbed_official | 87:085cde657901 | 941 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 87:085cde657901 | 942 | |
mbed_official | 87:085cde657901 | 943 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 944 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 945 | |
mbed_official | 87:085cde657901 | 946 | return HAL_OK; |
mbed_official | 87:085cde657901 | 947 | } |
mbed_official | 87:085cde657901 | 948 | /** |
mbed_official | 87:085cde657901 | 949 | * @brief Transmits an amount of data in no-blocking mode with DMA. |
mbed_official | 226:b062af740e40 | 950 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 951 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 952 | * @param pData: Pointer to data buffer |
mbed_official | 87:085cde657901 | 953 | * @param Size: Amount of data to be sent |
mbed_official | 87:085cde657901 | 954 | * @retval HAL status |
mbed_official | 87:085cde657901 | 955 | */ |
mbed_official | 87:085cde657901 | 956 | HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size) |
mbed_official | 87:085cde657901 | 957 | { |
mbed_official | 87:085cde657901 | 958 | uint32_t *tmp; |
mbed_official | 87:085cde657901 | 959 | |
mbed_official | 384:ef87175507f1 | 960 | if((pData == HAL_NULL) || (Size == 0)) |
mbed_official | 87:085cde657901 | 961 | { |
mbed_official | 87:085cde657901 | 962 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 963 | } |
mbed_official | 87:085cde657901 | 964 | |
mbed_official | 87:085cde657901 | 965 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 87:085cde657901 | 966 | { |
mbed_official | 87:085cde657901 | 967 | hsai->pTxBuffPtr = pData; |
mbed_official | 87:085cde657901 | 968 | hsai->TxXferSize = Size; |
mbed_official | 87:085cde657901 | 969 | hsai->TxXferCount = Size; |
mbed_official | 87:085cde657901 | 970 | |
mbed_official | 87:085cde657901 | 971 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 972 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 973 | |
mbed_official | 87:085cde657901 | 974 | hsai->State = HAL_SAI_STATE_BUSY_TX; |
mbed_official | 87:085cde657901 | 975 | |
mbed_official | 87:085cde657901 | 976 | /* Set the SAI Tx DMA Half transfert complete callback */ |
mbed_official | 87:085cde657901 | 977 | hsai->hdmatx->XferHalfCpltCallback = SAI_DMATxHalfCplt; |
mbed_official | 87:085cde657901 | 978 | |
mbed_official | 87:085cde657901 | 979 | /* Set the SAI TxDMA transfer complete callback */ |
mbed_official | 87:085cde657901 | 980 | hsai->hdmatx->XferCpltCallback = SAI_DMATxCplt; |
mbed_official | 87:085cde657901 | 981 | |
mbed_official | 87:085cde657901 | 982 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 983 | hsai->hdmatx->XferErrorCallback = SAI_DMAError; |
mbed_official | 87:085cde657901 | 984 | |
mbed_official | 87:085cde657901 | 985 | /* Enable the Tx DMA Stream */ |
mbed_official | 87:085cde657901 | 986 | tmp = (uint32_t*)&pData; |
mbed_official | 87:085cde657901 | 987 | HAL_DMA_Start_IT(hsai->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsai->Instance->DR, hsai->TxXferSize); |
mbed_official | 87:085cde657901 | 988 | |
mbed_official | 87:085cde657901 | 989 | /* Check if the SAI is already enabled */ |
mbed_official | 87:085cde657901 | 990 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 87:085cde657901 | 991 | { |
mbed_official | 87:085cde657901 | 992 | /* Enable SAI peripheral */ |
mbed_official | 87:085cde657901 | 993 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 87:085cde657901 | 994 | } |
mbed_official | 87:085cde657901 | 995 | |
mbed_official | 87:085cde657901 | 996 | /* Enable SAI Tx DMA Request */ |
mbed_official | 87:085cde657901 | 997 | hsai->Instance->CR1 |= SAI_xCR1_DMAEN; |
mbed_official | 87:085cde657901 | 998 | |
mbed_official | 87:085cde657901 | 999 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1000 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 1001 | |
mbed_official | 87:085cde657901 | 1002 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1003 | } |
mbed_official | 87:085cde657901 | 1004 | else |
mbed_official | 87:085cde657901 | 1005 | { |
mbed_official | 87:085cde657901 | 1006 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 1007 | } |
mbed_official | 87:085cde657901 | 1008 | } |
mbed_official | 87:085cde657901 | 1009 | |
mbed_official | 87:085cde657901 | 1010 | /** |
mbed_official | 226:b062af740e40 | 1011 | * @brief Receives an amount of data in no-blocking mode with DMA. |
mbed_official | 226:b062af740e40 | 1012 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1013 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 1014 | * @param pData: Pointer to data buffer |
mbed_official | 87:085cde657901 | 1015 | * @param Size: Amount of data to be received |
mbed_official | 87:085cde657901 | 1016 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1017 | */ |
mbed_official | 87:085cde657901 | 1018 | HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size) |
mbed_official | 87:085cde657901 | 1019 | { |
mbed_official | 87:085cde657901 | 1020 | uint32_t *tmp; |
mbed_official | 87:085cde657901 | 1021 | |
mbed_official | 384:ef87175507f1 | 1022 | if((pData == HAL_NULL) || (Size == 0)) |
mbed_official | 87:085cde657901 | 1023 | { |
mbed_official | 87:085cde657901 | 1024 | return HAL_ERROR; |
mbed_official | 87:085cde657901 | 1025 | } |
mbed_official | 87:085cde657901 | 1026 | |
mbed_official | 87:085cde657901 | 1027 | if(hsai->State == HAL_SAI_STATE_READY) |
mbed_official | 87:085cde657901 | 1028 | { |
mbed_official | 87:085cde657901 | 1029 | hsai->pRxBuffPtr = pData; |
mbed_official | 87:085cde657901 | 1030 | hsai->RxXferSize = Size; |
mbed_official | 87:085cde657901 | 1031 | hsai->RxXferCount = Size; |
mbed_official | 87:085cde657901 | 1032 | |
mbed_official | 87:085cde657901 | 1033 | /* Process Locked */ |
mbed_official | 87:085cde657901 | 1034 | __HAL_LOCK(hsai); |
mbed_official | 87:085cde657901 | 1035 | |
mbed_official | 87:085cde657901 | 1036 | hsai->State = HAL_SAI_STATE_BUSY_RX; |
mbed_official | 87:085cde657901 | 1037 | |
mbed_official | 87:085cde657901 | 1038 | /* Set the SAI Rx DMA Half transfert complete callback */ |
mbed_official | 87:085cde657901 | 1039 | hsai->hdmarx->XferHalfCpltCallback = SAI_DMARxHalfCplt; |
mbed_official | 87:085cde657901 | 1040 | |
mbed_official | 87:085cde657901 | 1041 | /* Set the SAI Rx DMA transfert complete callback */ |
mbed_official | 87:085cde657901 | 1042 | hsai->hdmarx->XferCpltCallback = SAI_DMARxCplt; |
mbed_official | 87:085cde657901 | 1043 | |
mbed_official | 87:085cde657901 | 1044 | /* Set the DMA error callback */ |
mbed_official | 87:085cde657901 | 1045 | hsai->hdmarx->XferErrorCallback = SAI_DMAError; |
mbed_official | 87:085cde657901 | 1046 | |
mbed_official | 87:085cde657901 | 1047 | /* Enable the Rx DMA Stream */ |
mbed_official | 87:085cde657901 | 1048 | tmp = (uint32_t*)&pData; |
mbed_official | 87:085cde657901 | 1049 | HAL_DMA_Start_IT(hsai->hdmarx, (uint32_t)&hsai->Instance->DR, *(uint32_t*)tmp, hsai->RxXferSize); |
mbed_official | 87:085cde657901 | 1050 | |
mbed_official | 87:085cde657901 | 1051 | /* Check if the SAI is already enabled */ |
mbed_official | 87:085cde657901 | 1052 | if((hsai->Instance->CR1 & SAI_xCR1_SAIEN) != SAI_xCR1_SAIEN) |
mbed_official | 87:085cde657901 | 1053 | { |
mbed_official | 87:085cde657901 | 1054 | /* Enable SAI peripheral */ |
mbed_official | 87:085cde657901 | 1055 | __HAL_SAI_ENABLE(hsai); |
mbed_official | 87:085cde657901 | 1056 | } |
mbed_official | 87:085cde657901 | 1057 | |
mbed_official | 87:085cde657901 | 1058 | /* Enable SAI Rx DMA Request */ |
mbed_official | 87:085cde657901 | 1059 | hsai->Instance->CR1 |= SAI_xCR1_DMAEN; |
mbed_official | 87:085cde657901 | 1060 | |
mbed_official | 87:085cde657901 | 1061 | /* Process Unlocked */ |
mbed_official | 87:085cde657901 | 1062 | __HAL_UNLOCK(hsai); |
mbed_official | 87:085cde657901 | 1063 | |
mbed_official | 87:085cde657901 | 1064 | return HAL_OK; |
mbed_official | 87:085cde657901 | 1065 | } |
mbed_official | 87:085cde657901 | 1066 | else |
mbed_official | 87:085cde657901 | 1067 | { |
mbed_official | 87:085cde657901 | 1068 | return HAL_BUSY; |
mbed_official | 87:085cde657901 | 1069 | } |
mbed_official | 87:085cde657901 | 1070 | } |
mbed_official | 87:085cde657901 | 1071 | |
mbed_official | 87:085cde657901 | 1072 | /** |
mbed_official | 87:085cde657901 | 1073 | * @brief This function handles SAI interrupt request. |
mbed_official | 226:b062af740e40 | 1074 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1075 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 1076 | * @retval HAL status |
mbed_official | 87:085cde657901 | 1077 | */ |
mbed_official | 87:085cde657901 | 1078 | void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 1079 | { |
mbed_official | 87:085cde657901 | 1080 | uint32_t tmp1 = 0, tmp2 = 0; |
mbed_official | 87:085cde657901 | 1081 | |
mbed_official | 87:085cde657901 | 1082 | if(hsai->State == HAL_SAI_STATE_BUSY_RX) |
mbed_official | 87:085cde657901 | 1083 | { |
mbed_official | 87:085cde657901 | 1084 | tmp1 = __HAL_SAI_GET_FLAG(hsai, SAI_xSR_FREQ); |
mbed_official | 87:085cde657901 | 1085 | tmp2 = __HAL_SAI_GET_IT_SOURCE(hsai, SAI_IT_FREQ); |
mbed_official | 87:085cde657901 | 1086 | /* SAI in mode Receiver --------------------------------------------------*/ |
mbed_official | 87:085cde657901 | 1087 | if((tmp1 != RESET) && (tmp2 != RESET)) |
mbed_official | 87:085cde657901 | 1088 | { |
mbed_official | 384:ef87175507f1 | 1089 | HAL_SAI_Receive_IT(hsai, HAL_NULL, 0); |
mbed_official | 87:085cde657901 | 1090 | } |
mbed_official | 87:085cde657901 | 1091 | |
mbed_official | 87:085cde657901 | 1092 | tmp1 = __HAL_SAI_GET_FLAG(hsai, SAI_FLAG_OVRUDR); |
mbed_official | 87:085cde657901 | 1093 | tmp2 = __HAL_SAI_GET_IT_SOURCE(hsai, SAI_IT_OVRUDR); |
mbed_official | 87:085cde657901 | 1094 | /* SAI Overrun error interrupt occurred ----------------------------------*/ |
mbed_official | 87:085cde657901 | 1095 | if((tmp1 != RESET) && (tmp2 != RESET)) |
mbed_official | 87:085cde657901 | 1096 | { |
mbed_official | 87:085cde657901 | 1097 | /* Change the SAI error code */ |
mbed_official | 87:085cde657901 | 1098 | hsai->ErrorCode = HAL_SAI_ERROR_OVR; |
mbed_official | 87:085cde657901 | 1099 | |
mbed_official | 87:085cde657901 | 1100 | /* Clear the SAI Overrun flag */ |
mbed_official | 87:085cde657901 | 1101 | __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR); |
mbed_official | 87:085cde657901 | 1102 | /* Set the SAI state ready to be able to start again the process */ |
mbed_official | 87:085cde657901 | 1103 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 87:085cde657901 | 1104 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 87:085cde657901 | 1105 | } |
mbed_official | 87:085cde657901 | 1106 | } |
mbed_official | 87:085cde657901 | 1107 | |
mbed_official | 87:085cde657901 | 1108 | if(hsai->State == HAL_SAI_STATE_BUSY_TX) |
mbed_official | 87:085cde657901 | 1109 | { |
mbed_official | 87:085cde657901 | 1110 | tmp1 = __HAL_SAI_GET_FLAG(hsai, SAI_xSR_FREQ); |
mbed_official | 87:085cde657901 | 1111 | tmp2 = __HAL_SAI_GET_IT_SOURCE(hsai, SAI_IT_FREQ); |
mbed_official | 87:085cde657901 | 1112 | /* SAI in mode Transmitter -----------------------------------------------*/ |
mbed_official | 87:085cde657901 | 1113 | if((tmp1 != RESET) && (tmp2 != RESET)) |
mbed_official | 87:085cde657901 | 1114 | { |
mbed_official | 384:ef87175507f1 | 1115 | HAL_SAI_Transmit_IT(hsai, HAL_NULL, 0); |
mbed_official | 87:085cde657901 | 1116 | } |
mbed_official | 87:085cde657901 | 1117 | |
mbed_official | 87:085cde657901 | 1118 | tmp1 = __HAL_SAI_GET_FLAG(hsai, SAI_FLAG_OVRUDR); |
mbed_official | 87:085cde657901 | 1119 | tmp2 = __HAL_SAI_GET_IT_SOURCE(hsai, SAI_IT_OVRUDR); |
mbed_official | 87:085cde657901 | 1120 | /* SAI Underrun error interrupt occurred ---------------------------------*/ |
mbed_official | 87:085cde657901 | 1121 | if((tmp1 != RESET) && (tmp2 != RESET)) |
mbed_official | 87:085cde657901 | 1122 | { |
mbed_official | 87:085cde657901 | 1123 | /* Change the SAI error code */ |
mbed_official | 87:085cde657901 | 1124 | hsai->ErrorCode = HAL_SAI_ERROR_UDR; |
mbed_official | 87:085cde657901 | 1125 | |
mbed_official | 87:085cde657901 | 1126 | /* Clear the SAI Underrun flag */ |
mbed_official | 87:085cde657901 | 1127 | __HAL_SAI_CLEAR_FLAG(hsai, SAI_FLAG_OVRUDR); |
mbed_official | 87:085cde657901 | 1128 | /* Set the SAI state ready to be able to start again the process */ |
mbed_official | 87:085cde657901 | 1129 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 87:085cde657901 | 1130 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 87:085cde657901 | 1131 | } |
mbed_official | 87:085cde657901 | 1132 | } |
mbed_official | 87:085cde657901 | 1133 | } |
mbed_official | 87:085cde657901 | 1134 | |
mbed_official | 87:085cde657901 | 1135 | /** |
mbed_official | 87:085cde657901 | 1136 | * @brief Tx Transfer completed callbacks. |
mbed_official | 226:b062af740e40 | 1137 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1138 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 1139 | * @retval None |
mbed_official | 87:085cde657901 | 1140 | */ |
mbed_official | 87:085cde657901 | 1141 | __weak void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 1142 | { |
mbed_official | 87:085cde657901 | 1143 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 1144 | the HAL_SAI_TxCpltCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 1145 | */ |
mbed_official | 87:085cde657901 | 1146 | } |
mbed_official | 87:085cde657901 | 1147 | |
mbed_official | 87:085cde657901 | 1148 | /** |
mbed_official | 87:085cde657901 | 1149 | * @brief Tx Transfer Half completed callbacks |
mbed_official | 226:b062af740e40 | 1150 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1151 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 1152 | * @retval None |
mbed_official | 87:085cde657901 | 1153 | */ |
mbed_official | 87:085cde657901 | 1154 | __weak void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 1155 | { |
mbed_official | 87:085cde657901 | 1156 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 1157 | the HAL_SAI_TxHalfCpltCallback could be implenetd in the user file |
mbed_official | 87:085cde657901 | 1158 | */ |
mbed_official | 87:085cde657901 | 1159 | } |
mbed_official | 87:085cde657901 | 1160 | |
mbed_official | 87:085cde657901 | 1161 | /** |
mbed_official | 87:085cde657901 | 1162 | * @brief Rx Transfer completed callbacks. |
mbed_official | 226:b062af740e40 | 1163 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1164 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 1165 | * @retval None |
mbed_official | 87:085cde657901 | 1166 | */ |
mbed_official | 87:085cde657901 | 1167 | __weak void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 1168 | { |
mbed_official | 87:085cde657901 | 1169 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 1170 | the HAL_SAI_RxCpltCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 1171 | */ |
mbed_official | 87:085cde657901 | 1172 | } |
mbed_official | 87:085cde657901 | 1173 | |
mbed_official | 87:085cde657901 | 1174 | /** |
mbed_official | 87:085cde657901 | 1175 | * @brief Rx Transfer half completed callbacks |
mbed_official | 226:b062af740e40 | 1176 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1177 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 1178 | * @retval None |
mbed_official | 87:085cde657901 | 1179 | */ |
mbed_official | 87:085cde657901 | 1180 | __weak void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 1181 | { |
mbed_official | 87:085cde657901 | 1182 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 1183 | the HAL_SAI_RxCpltCallback could be implenetd in the user file |
mbed_official | 87:085cde657901 | 1184 | */ |
mbed_official | 87:085cde657901 | 1185 | } |
mbed_official | 87:085cde657901 | 1186 | |
mbed_official | 87:085cde657901 | 1187 | /** |
mbed_official | 87:085cde657901 | 1188 | * @brief SAI error callbacks. |
mbed_official | 226:b062af740e40 | 1189 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1190 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 1191 | * @retval None |
mbed_official | 87:085cde657901 | 1192 | */ |
mbed_official | 87:085cde657901 | 1193 | __weak void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 1194 | { |
mbed_official | 87:085cde657901 | 1195 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 87:085cde657901 | 1196 | the HAL_SAI_ErrorCallback could be implemented in the user file |
mbed_official | 87:085cde657901 | 1197 | */ |
mbed_official | 87:085cde657901 | 1198 | } |
mbed_official | 87:085cde657901 | 1199 | |
mbed_official | 87:085cde657901 | 1200 | /** |
mbed_official | 87:085cde657901 | 1201 | * @} |
mbed_official | 87:085cde657901 | 1202 | */ |
mbed_official | 87:085cde657901 | 1203 | |
mbed_official | 87:085cde657901 | 1204 | |
mbed_official | 87:085cde657901 | 1205 | /** @defgroup SAI_Group3 Peripheral State functions |
mbed_official | 87:085cde657901 | 1206 | * @brief Peripheral State functions |
mbed_official | 87:085cde657901 | 1207 | * |
mbed_official | 87:085cde657901 | 1208 | @verbatim |
mbed_official | 87:085cde657901 | 1209 | =============================================================================== |
mbed_official | 87:085cde657901 | 1210 | ##### Peripheral State and Errors functions ##### |
mbed_official | 87:085cde657901 | 1211 | =============================================================================== |
mbed_official | 87:085cde657901 | 1212 | [..] |
mbed_official | 226:b062af740e40 | 1213 | This subsection permits to get in run-time the status of the peripheral |
mbed_official | 87:085cde657901 | 1214 | and the data flow. |
mbed_official | 87:085cde657901 | 1215 | |
mbed_official | 87:085cde657901 | 1216 | @endverbatim |
mbed_official | 87:085cde657901 | 1217 | * @{ |
mbed_official | 87:085cde657901 | 1218 | */ |
mbed_official | 87:085cde657901 | 1219 | |
mbed_official | 87:085cde657901 | 1220 | /** |
mbed_official | 87:085cde657901 | 1221 | * @brief Returns the SAI state. |
mbed_official | 226:b062af740e40 | 1222 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1223 | * the configuration information for SAI module. |
mbed_official | 87:085cde657901 | 1224 | * @retval HAL state |
mbed_official | 87:085cde657901 | 1225 | */ |
mbed_official | 87:085cde657901 | 1226 | HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 1227 | { |
mbed_official | 87:085cde657901 | 1228 | return hsai->State; |
mbed_official | 87:085cde657901 | 1229 | } |
mbed_official | 87:085cde657901 | 1230 | |
mbed_official | 87:085cde657901 | 1231 | /** |
mbed_official | 87:085cde657901 | 1232 | * @brief Return the SAI error code |
mbed_official | 87:085cde657901 | 1233 | * @param hsai : pointer to a SAI_HandleTypeDef structure that contains |
mbed_official | 87:085cde657901 | 1234 | * the configuration information for the specified SAI Block. |
mbed_official | 87:085cde657901 | 1235 | * @retval SAI Error Code |
mbed_official | 87:085cde657901 | 1236 | */ |
mbed_official | 87:085cde657901 | 1237 | uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai) |
mbed_official | 87:085cde657901 | 1238 | { |
mbed_official | 87:085cde657901 | 1239 | return hsai->ErrorCode; |
mbed_official | 87:085cde657901 | 1240 | } |
mbed_official | 87:085cde657901 | 1241 | /** |
mbed_official | 87:085cde657901 | 1242 | * @} |
mbed_official | 87:085cde657901 | 1243 | */ |
mbed_official | 87:085cde657901 | 1244 | |
mbed_official | 87:085cde657901 | 1245 | /** |
mbed_official | 87:085cde657901 | 1246 | * @brief DMA SAI transmit process complete callback. |
mbed_official | 226:b062af740e40 | 1247 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1248 | * the configuration information for the specified DMA module. |
mbed_official | 87:085cde657901 | 1249 | * @retval None |
mbed_official | 87:085cde657901 | 1250 | */ |
mbed_official | 87:085cde657901 | 1251 | static void SAI_DMATxCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 1252 | { |
mbed_official | 369:2e96f1b71984 | 1253 | uint32_t tickstart = 0; |
mbed_official | 87:085cde657901 | 1254 | |
mbed_official | 106:ced8cbb51063 | 1255 | SAI_HandleTypeDef* hsai = (SAI_HandleTypeDef*)((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 106:ced8cbb51063 | 1256 | |
mbed_official | 106:ced8cbb51063 | 1257 | if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0) |
mbed_official | 106:ced8cbb51063 | 1258 | { |
mbed_official | 106:ced8cbb51063 | 1259 | hsai->TxXferCount = 0; |
mbed_official | 106:ced8cbb51063 | 1260 | hsai->RxXferCount = 0; |
mbed_official | 106:ced8cbb51063 | 1261 | |
mbed_official | 106:ced8cbb51063 | 1262 | /* Disable SAI Tx DMA Request */ |
mbed_official | 106:ced8cbb51063 | 1263 | hsai->Instance->CR1 &= (uint32_t)(~SAI_xCR1_DMAEN); |
mbed_official | 106:ced8cbb51063 | 1264 | |
mbed_official | 369:2e96f1b71984 | 1265 | /* Get tick */ |
mbed_official | 369:2e96f1b71984 | 1266 | tickstart = HAL_GetTick(); |
mbed_official | 369:2e96f1b71984 | 1267 | |
mbed_official | 106:ced8cbb51063 | 1268 | /* Set timeout: 10 is the max delay to send the remaining data in the SAI FIFO */ |
mbed_official | 106:ced8cbb51063 | 1269 | /* Wait until FIFO is empty */ |
mbed_official | 106:ced8cbb51063 | 1270 | while(__HAL_SAI_GET_FLAG(hsai, SAI_xSR_FLVL) != RESET) |
mbed_official | 106:ced8cbb51063 | 1271 | { |
mbed_official | 106:ced8cbb51063 | 1272 | /* Check for the Timeout */ |
mbed_official | 369:2e96f1b71984 | 1273 | if((HAL_GetTick() - tickstart ) > SAI_TIMEOUT_VALUE) |
mbed_official | 106:ced8cbb51063 | 1274 | { |
mbed_official | 106:ced8cbb51063 | 1275 | /* Update error code */ |
mbed_official | 106:ced8cbb51063 | 1276 | hsai->ErrorCode |= HAL_SAI_ERROR_TIMEOUT; |
mbed_official | 106:ced8cbb51063 | 1277 | |
mbed_official | 106:ced8cbb51063 | 1278 | /* Change the SAI state */ |
mbed_official | 106:ced8cbb51063 | 1279 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 106:ced8cbb51063 | 1280 | } |
mbed_official | 106:ced8cbb51063 | 1281 | } |
mbed_official | 106:ced8cbb51063 | 1282 | |
mbed_official | 106:ced8cbb51063 | 1283 | hsai->State= HAL_SAI_STATE_READY; |
mbed_official | 106:ced8cbb51063 | 1284 | } |
mbed_official | 87:085cde657901 | 1285 | HAL_SAI_TxCpltCallback(hsai); |
mbed_official | 87:085cde657901 | 1286 | } |
mbed_official | 87:085cde657901 | 1287 | |
mbed_official | 87:085cde657901 | 1288 | /** |
mbed_official | 87:085cde657901 | 1289 | * @brief DMA SAI transmit process half complete callback |
mbed_official | 226:b062af740e40 | 1290 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1291 | * the configuration information for the specified DMA module. |
mbed_official | 87:085cde657901 | 1292 | * @retval None |
mbed_official | 87:085cde657901 | 1293 | */ |
mbed_official | 87:085cde657901 | 1294 | static void SAI_DMATxHalfCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 1295 | { |
mbed_official | 87:085cde657901 | 1296 | SAI_HandleTypeDef* hsai = (SAI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 87:085cde657901 | 1297 | |
mbed_official | 87:085cde657901 | 1298 | HAL_SAI_TxHalfCpltCallback(hsai); |
mbed_official | 87:085cde657901 | 1299 | } |
mbed_official | 87:085cde657901 | 1300 | |
mbed_official | 87:085cde657901 | 1301 | /** |
mbed_official | 87:085cde657901 | 1302 | * @brief DMA SAI receive process complete callback. |
mbed_official | 226:b062af740e40 | 1303 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1304 | * the configuration information for the specified DMA module. |
mbed_official | 87:085cde657901 | 1305 | * @retval None |
mbed_official | 87:085cde657901 | 1306 | */ |
mbed_official | 87:085cde657901 | 1307 | static void SAI_DMARxCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 1308 | { |
mbed_official | 87:085cde657901 | 1309 | SAI_HandleTypeDef* hsai = ( SAI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 106:ced8cbb51063 | 1310 | if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0) |
mbed_official | 106:ced8cbb51063 | 1311 | { |
mbed_official | 106:ced8cbb51063 | 1312 | /* Disable Rx DMA Request */ |
mbed_official | 106:ced8cbb51063 | 1313 | hsai->Instance->CR1 &= (uint32_t)(~SAI_xCR1_DMAEN); |
mbed_official | 106:ced8cbb51063 | 1314 | hsai->RxXferCount = 0; |
mbed_official | 106:ced8cbb51063 | 1315 | |
mbed_official | 106:ced8cbb51063 | 1316 | hsai->State = HAL_SAI_STATE_READY; |
mbed_official | 106:ced8cbb51063 | 1317 | } |
mbed_official | 87:085cde657901 | 1318 | HAL_SAI_RxCpltCallback(hsai); |
mbed_official | 87:085cde657901 | 1319 | } |
mbed_official | 87:085cde657901 | 1320 | |
mbed_official | 87:085cde657901 | 1321 | /** |
mbed_official | 87:085cde657901 | 1322 | * @brief DMA SAI receive process half complete callback |
mbed_official | 226:b062af740e40 | 1323 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1324 | * the configuration information for the specified DMA module. |
mbed_official | 87:085cde657901 | 1325 | * @retval None |
mbed_official | 87:085cde657901 | 1326 | */ |
mbed_official | 87:085cde657901 | 1327 | static void SAI_DMARxHalfCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 1328 | { |
mbed_official | 87:085cde657901 | 1329 | SAI_HandleTypeDef* hsai = (SAI_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 87:085cde657901 | 1330 | |
mbed_official | 87:085cde657901 | 1331 | HAL_SAI_RxHalfCpltCallback(hsai); |
mbed_official | 87:085cde657901 | 1332 | } |
mbed_official | 87:085cde657901 | 1333 | /** |
mbed_official | 87:085cde657901 | 1334 | * @brief DMA SAI communication error callback. |
mbed_official | 226:b062af740e40 | 1335 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 226:b062af740e40 | 1336 | * the configuration information for the specified DMA module. |
mbed_official | 87:085cde657901 | 1337 | * @retval None |
mbed_official | 87:085cde657901 | 1338 | */ |
mbed_official | 87:085cde657901 | 1339 | static void SAI_DMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 87:085cde657901 | 1340 | { |
mbed_official | 87:085cde657901 | 1341 | SAI_HandleTypeDef* hsai = ( SAI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 87:085cde657901 | 1342 | /* Set the SAI state ready to be able to start again the process */ |
mbed_official | 87:085cde657901 | 1343 | hsai->State= HAL_SAI_STATE_READY; |
mbed_official | 87:085cde657901 | 1344 | HAL_SAI_ErrorCallback(hsai); |
mbed_official | 87:085cde657901 | 1345 | |
mbed_official | 87:085cde657901 | 1346 | hsai->TxXferCount = 0; |
mbed_official | 87:085cde657901 | 1347 | hsai->RxXferCount = 0; |
mbed_official | 87:085cde657901 | 1348 | } |
mbed_official | 87:085cde657901 | 1349 | |
mbed_official | 87:085cde657901 | 1350 | /** |
mbed_official | 87:085cde657901 | 1351 | * @} |
mbed_official | 87:085cde657901 | 1352 | */ |
mbed_official | 87:085cde657901 | 1353 | |
mbed_official | 87:085cde657901 | 1354 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */ |
mbed_official | 87:085cde657901 | 1355 | #endif /* HAL_SAI_MODULE_ENABLED */ |
mbed_official | 87:085cde657901 | 1356 | /** |
mbed_official | 87:085cde657901 | 1357 | * @} |
mbed_official | 87:085cde657901 | 1358 | */ |
mbed_official | 87:085cde657901 | 1359 | |
mbed_official | 87:085cde657901 | 1360 | /** |
mbed_official | 87:085cde657901 | 1361 | * @} |
mbed_official | 87:085cde657901 | 1362 | */ |
mbed_official | 87:085cde657901 | 1363 | |
mbed_official | 87:085cde657901 | 1364 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |