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