mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_i2s.c@634:ac7d6880524d, 2015-09-28 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Sep 28 20:15:09 2015 +0100
- Revision:
- 634:ac7d6880524d
- Parent:
- 632:7687fb9c4f91
Synchronized with git revision 9b7d23d47153c298a6d24de9a415202705889d11
Full URL: https://github.com/mbedmicro/mbed/commit/9b7d23d47153c298a6d24de9a415202705889d11/
Revert "[NUCLEO_F303K8] add support of the STM32F303K8"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 237:f3da66175598 | 1 | /** |
mbed_official | 237:f3da66175598 | 2 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 3 | * @file stm32f3xx_hal_i2s.c |
mbed_official | 237:f3da66175598 | 4 | * @author MCD Application Team |
mbed_official | 634:ac7d6880524d | 5 | * @version V1.1.0 |
mbed_official | 634:ac7d6880524d | 6 | * @date 12-Sept-2014 |
mbed_official | 237:f3da66175598 | 7 | * @brief I2S HAL module driver. |
mbed_official | 237:f3da66175598 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 237:f3da66175598 | 9 | * functionalities of the Integrated Interchip Sound (I2S) peripheral: |
mbed_official | 237:f3da66175598 | 10 | * + Initialization and de-initialization functions |
mbed_official | 237:f3da66175598 | 11 | * + IO operation functions |
mbed_official | 237:f3da66175598 | 12 | * + Peripheral State and Errors functions |
mbed_official | 237:f3da66175598 | 13 | @verbatim |
mbed_official | 237:f3da66175598 | 14 | =============================================================================== |
mbed_official | 237:f3da66175598 | 15 | ##### How to use this driver ##### |
mbed_official | 237:f3da66175598 | 16 | =============================================================================== |
mbed_official | 237:f3da66175598 | 17 | [..] |
mbed_official | 237:f3da66175598 | 18 | The I2S HAL driver can be used as follows: |
mbed_official | 237:f3da66175598 | 19 | |
mbed_official | 237:f3da66175598 | 20 | (#) Declare a I2S_HandleTypeDef handle structure. |
mbed_official | 237:f3da66175598 | 21 | (#) Initialize the I2S low level resources by implement the HAL_I2S_MspInit() API: |
mbed_official | 237:f3da66175598 | 22 | (##) Enable the SPIx interface clock. |
mbed_official | 237:f3da66175598 | 23 | (##) I2S pins configuration: |
mbed_official | 237:f3da66175598 | 24 | (+++) Enable the clock for the I2S GPIOs. |
mbed_official | 237:f3da66175598 | 25 | (+++) Configure these I2S pins as alternate function pull-up. |
mbed_official | 237:f3da66175598 | 26 | (##) NVIC configuration if you need to use interrupt process (HAL_I2S_Transmit_IT() |
mbed_official | 237:f3da66175598 | 27 | and HAL_I2S_Receive_IT() APIs). |
mbed_official | 237:f3da66175598 | 28 | (+++) Configure the I2Sx interrupt priority. |
mbed_official | 237:f3da66175598 | 29 | (+++) Enable the NVIC I2S IRQ handle. |
mbed_official | 237:f3da66175598 | 30 | (##) DMA Configuration if you need to use DMA process (HAL_I2S_Transmit_DMA() |
mbed_official | 237:f3da66175598 | 31 | and HAL_I2S_Receive_DMA() APIs: |
mbed_official | 237:f3da66175598 | 32 | (+++) Declare a DMA handle structure for the Tx/Rx channel. |
mbed_official | 237:f3da66175598 | 33 | (+++) Enable the DMAx interface clock. |
mbed_official | 237:f3da66175598 | 34 | (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
mbed_official | 237:f3da66175598 | 35 | (+++) Configure the DMA Tx/Rx Channel. |
mbed_official | 237:f3da66175598 | 36 | (+++) Associate the initilalized DMA handle to the I2S DMA Tx/Rx handle. |
mbed_official | 237:f3da66175598 | 37 | (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the |
mbed_official | 237:f3da66175598 | 38 | DMA Tx/Rx Channel. |
mbed_official | 237:f3da66175598 | 39 | |
mbed_official | 237:f3da66175598 | 40 | (#) Program the Mode, Standard, Data Format, MCLK Output, Audio frequency and Polarity |
mbed_official | 237:f3da66175598 | 41 | using HAL_I2S_Init() function. |
mbed_official | 237:f3da66175598 | 42 | |
mbed_official | 237:f3da66175598 | 43 | -@- The specific I2S interrupts (Transmission complete interrupt, |
mbed_official | 237:f3da66175598 | 44 | RXNE interrupt and Error Interrupts) will be managed using the macros |
mbed_official | 237:f3da66175598 | 45 | __HAL_I2S_ENABLE_IT() and __HAL_I2S_DISABLE_IT() inside the transmit and receive process. |
mbed_official | 237:f3da66175598 | 46 | -@- Make sure that either: |
mbed_official | 237:f3da66175598 | 47 | (+@) I2S clock is configured based on SYSCLK or |
mbed_official | 237:f3da66175598 | 48 | (+@) External clock source is configured after setting correctly |
mbed_official | 237:f3da66175598 | 49 | the define constant EXTERNAL_CLOCK_VALUE in the stm32f3xx_hal_conf.h file. |
mbed_official | 237:f3da66175598 | 50 | |
mbed_official | 237:f3da66175598 | 51 | (#) Three mode of operations are available within this driver : |
mbed_official | 237:f3da66175598 | 52 | |
mbed_official | 237:f3da66175598 | 53 | *** Polling mode IO operation *** |
mbed_official | 237:f3da66175598 | 54 | ================================= |
mbed_official | 237:f3da66175598 | 55 | [..] |
mbed_official | 237:f3da66175598 | 56 | (+) Send an amount of data in blocking mode using HAL_I2S_Transmit() |
mbed_official | 237:f3da66175598 | 57 | (+) Receive an amount of data in blocking mode using HAL_I2S_Receive() |
mbed_official | 237:f3da66175598 | 58 | |
mbed_official | 237:f3da66175598 | 59 | *** Interrupt mode IO operation *** |
mbed_official | 237:f3da66175598 | 60 | =================================== |
mbed_official | 237:f3da66175598 | 61 | [..] |
mbed_official | 237:f3da66175598 | 62 | (+) Send an amount of data in non blocking mode using HAL_I2S_Transmit_IT() |
mbed_official | 237:f3da66175598 | 63 | (+) At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 64 | add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback |
mbed_official | 237:f3da66175598 | 65 | (+) At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 66 | add his own code by customization of function pointer HAL_I2S_TxCpltCallback |
mbed_official | 237:f3da66175598 | 67 | (+) Receive an amount of data in non blocking mode using HAL_I2S_Receive_IT() |
mbed_official | 237:f3da66175598 | 68 | (+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 69 | add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback |
mbed_official | 237:f3da66175598 | 70 | (+) At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 71 | add his own code by customization of function pointer HAL_I2S_RxCpltCallback |
mbed_official | 237:f3da66175598 | 72 | (+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can |
mbed_official | 237:f3da66175598 | 73 | add his own code by customization of function pointer HAL_I2S_ErrorCallback |
mbed_official | 237:f3da66175598 | 74 | |
mbed_official | 237:f3da66175598 | 75 | *** DMA mode IO operation *** |
mbed_official | 237:f3da66175598 | 76 | ============================== |
mbed_official | 237:f3da66175598 | 77 | [..] |
mbed_official | 237:f3da66175598 | 78 | (+) Send an amount of data in non blocking mode (DMA) using HAL_I2S_Transmit_DMA() |
mbed_official | 237:f3da66175598 | 79 | (+) At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 80 | add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback |
mbed_official | 237:f3da66175598 | 81 | (+) At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 82 | add his own code by customization of function pointer HAL_I2S_TxCpltCallback |
mbed_official | 237:f3da66175598 | 83 | (+) Receive an amount of data in non blocking mode (DMA) using HAL_I2S_Receive_DMA() |
mbed_official | 237:f3da66175598 | 84 | (+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 85 | add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback |
mbed_official | 237:f3da66175598 | 86 | (+) At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can |
mbed_official | 237:f3da66175598 | 87 | add his own code by customization of function pointer HAL_I2S_RxCpltCallback |
mbed_official | 237:f3da66175598 | 88 | (+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can |
mbed_official | 237:f3da66175598 | 89 | add his own code by customization of function pointer HAL_I2S_ErrorCallback |
mbed_official | 237:f3da66175598 | 90 | (+) Pause the DMA Transfer using HAL_I2S_DMAPause() |
mbed_official | 237:f3da66175598 | 91 | (+) Resume the DMA Transfer using HAL_I2S_DMAResume() |
mbed_official | 237:f3da66175598 | 92 | (+) Stop the DMA Transfer using HAL_I2S_DMAStop() |
mbed_official | 237:f3da66175598 | 93 | |
mbed_official | 237:f3da66175598 | 94 | *** I2S HAL driver macros list *** |
mbed_official | 237:f3da66175598 | 95 | ============================================= |
mbed_official | 237:f3da66175598 | 96 | [..] |
mbed_official | 237:f3da66175598 | 97 | Below the list of most used macros in I2S HAL driver. |
mbed_official | 237:f3da66175598 | 98 | |
mbed_official | 237:f3da66175598 | 99 | (+) __HAL_I2S_ENABLE: Enable the specified SPI peripheral (in I2S mode) |
mbed_official | 237:f3da66175598 | 100 | (+) __HAL_I2S_DISABLE: Disable the specified SPI peripheral (in I2S mode) |
mbed_official | 237:f3da66175598 | 101 | (+) __HAL_I2S_ENABLE_IT : Enable the specified I2S interrupts |
mbed_official | 237:f3da66175598 | 102 | (+) __HAL_I2S_DISABLE_IT : Disable the specified I2S interrupts |
mbed_official | 237:f3da66175598 | 103 | (+) __HAL_I2S_GET_FLAG: Check whether the specified I2S flag is set or not |
mbed_official | 237:f3da66175598 | 104 | |
mbed_official | 237:f3da66175598 | 105 | [..] |
mbed_official | 237:f3da66175598 | 106 | (@) You can refer to the I2S HAL driver header file for more useful macros |
mbed_official | 237:f3da66175598 | 107 | |
mbed_official | 237:f3da66175598 | 108 | @endverbatim |
mbed_official | 237:f3da66175598 | 109 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 110 | * @attention |
mbed_official | 237:f3da66175598 | 111 | * |
mbed_official | 634:ac7d6880524d | 112 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 237:f3da66175598 | 113 | * |
mbed_official | 237:f3da66175598 | 114 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 237:f3da66175598 | 115 | * are permitted provided that the following conditions are met: |
mbed_official | 237:f3da66175598 | 116 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 237:f3da66175598 | 117 | * this list of conditions and the following disclaimer. |
mbed_official | 237:f3da66175598 | 118 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 237:f3da66175598 | 119 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 237:f3da66175598 | 120 | * and/or other materials provided with the distribution. |
mbed_official | 237:f3da66175598 | 121 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 237:f3da66175598 | 122 | * may be used to endorse or promote products derived from this software |
mbed_official | 237:f3da66175598 | 123 | * without specific prior written permission. |
mbed_official | 237:f3da66175598 | 124 | * |
mbed_official | 237:f3da66175598 | 125 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 237:f3da66175598 | 126 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 237:f3da66175598 | 127 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 237:f3da66175598 | 128 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 237:f3da66175598 | 129 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 237:f3da66175598 | 130 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 237:f3da66175598 | 131 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 237:f3da66175598 | 132 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 237:f3da66175598 | 133 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 237:f3da66175598 | 134 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 237:f3da66175598 | 135 | * |
mbed_official | 237:f3da66175598 | 136 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 137 | */ |
mbed_official | 237:f3da66175598 | 138 | |
mbed_official | 237:f3da66175598 | 139 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 140 | #include "stm32f3xx_hal.h" |
mbed_official | 237:f3da66175598 | 141 | |
mbed_official | 237:f3da66175598 | 142 | /** @addtogroup STM32F3xx_HAL_Driver |
mbed_official | 237:f3da66175598 | 143 | * @{ |
mbed_official | 237:f3da66175598 | 144 | */ |
mbed_official | 237:f3da66175598 | 145 | |
mbed_official | 375:3d36234a1087 | 146 | /** @defgroup I2S I2S HAL module driver |
mbed_official | 237:f3da66175598 | 147 | * @brief I2S HAL module driver |
mbed_official | 237:f3da66175598 | 148 | * @{ |
mbed_official | 237:f3da66175598 | 149 | */ |
mbed_official | 237:f3da66175598 | 150 | |
mbed_official | 237:f3da66175598 | 151 | #ifdef HAL_I2S_MODULE_ENABLED |
mbed_official | 237:f3da66175598 | 152 | |
mbed_official | 375:3d36234a1087 | 153 | #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \ |
mbed_official | 375:3d36234a1087 | 154 | defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \ |
mbed_official | 375:3d36234a1087 | 155 | defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx) || \ |
mbed_official | 375:3d36234a1087 | 156 | defined(STM32F373xC) || defined(STM32F378xx) |
mbed_official | 237:f3da66175598 | 157 | |
mbed_official | 237:f3da66175598 | 158 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 159 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 160 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 161 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 162 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 375:3d36234a1087 | 163 | /** @defgroup I2S_Private_Functions I2S Private Functions |
mbed_official | 375:3d36234a1087 | 164 | * @{ |
mbed_official | 375:3d36234a1087 | 165 | */ |
mbed_official | 237:f3da66175598 | 166 | static void I2S_DMATxCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 167 | static void I2S_DMATxHalfCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 168 | static void I2S_DMARxCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 169 | static void I2S_DMARxHalfCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 170 | static void I2S_DMAError(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 171 | static void I2S_Transmit_IT(I2S_HandleTypeDef *hi2s); |
mbed_official | 237:f3da66175598 | 172 | static void I2S_Receive_IT(I2S_HandleTypeDef *hi2s); |
mbed_official | 237:f3da66175598 | 173 | static HAL_StatusTypeDef I2S_WaitFlagStateUntilTimeout(I2S_HandleTypeDef *hi2s, uint32_t Flag, uint32_t State, uint32_t Timeout); |
mbed_official | 375:3d36234a1087 | 174 | /** |
mbed_official | 375:3d36234a1087 | 175 | * @} |
mbed_official | 375:3d36234a1087 | 176 | */ |
mbed_official | 237:f3da66175598 | 177 | |
mbed_official | 375:3d36234a1087 | 178 | /* Exported functions ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 179 | |
mbed_official | 375:3d36234a1087 | 180 | /** @defgroup I2S_Exported_Functions I2S Exported Functions |
mbed_official | 237:f3da66175598 | 181 | * @{ |
mbed_official | 237:f3da66175598 | 182 | */ |
mbed_official | 237:f3da66175598 | 183 | |
mbed_official | 375:3d36234a1087 | 184 | /** @defgroup I2S_Exported_Functions_Group1 Initialization and de-initialization functions |
mbed_official | 237:f3da66175598 | 185 | * @brief Initialization and Configuration functions |
mbed_official | 237:f3da66175598 | 186 | * |
mbed_official | 237:f3da66175598 | 187 | @verbatim |
mbed_official | 237:f3da66175598 | 188 | =============================================================================== |
mbed_official | 237:f3da66175598 | 189 | ##### Initialization and de-initialization functions ##### |
mbed_official | 237:f3da66175598 | 190 | =============================================================================== |
mbed_official | 237:f3da66175598 | 191 | [..] This subsection provides a set of functions allowing to initialize and |
mbed_official | 237:f3da66175598 | 192 | de-initialiaze the I2Sx peripheral in simplex mode: |
mbed_official | 237:f3da66175598 | 193 | |
mbed_official | 237:f3da66175598 | 194 | (+) User must Implement HAL_I2S_MspInit() function in which he configures |
mbed_official | 237:f3da66175598 | 195 | all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ). |
mbed_official | 237:f3da66175598 | 196 | |
mbed_official | 237:f3da66175598 | 197 | (+) Call the function HAL_I2S_Init() to configure the selected device with |
mbed_official | 237:f3da66175598 | 198 | the selected configuration: |
mbed_official | 237:f3da66175598 | 199 | (++) Mode |
mbed_official | 237:f3da66175598 | 200 | (++) Standard |
mbed_official | 237:f3da66175598 | 201 | (++) Data Format |
mbed_official | 237:f3da66175598 | 202 | (++) MCLK Output |
mbed_official | 237:f3da66175598 | 203 | (++) Audio frequency |
mbed_official | 237:f3da66175598 | 204 | (++) Polarity |
mbed_official | 237:f3da66175598 | 205 | (++) Full duplex mode |
mbed_official | 237:f3da66175598 | 206 | |
mbed_official | 237:f3da66175598 | 207 | (+) Call the function HAL_I2S_DeInit() to restore the default configuration |
mbed_official | 237:f3da66175598 | 208 | of the selected I2Sx periperal. |
mbed_official | 237:f3da66175598 | 209 | @endverbatim |
mbed_official | 237:f3da66175598 | 210 | * @{ |
mbed_official | 237:f3da66175598 | 211 | */ |
mbed_official | 237:f3da66175598 | 212 | |
mbed_official | 237:f3da66175598 | 213 | /** |
mbed_official | 237:f3da66175598 | 214 | * @brief Initializes the I2S according to the specified parameters |
mbed_official | 237:f3da66175598 | 215 | * in the I2S_InitTypeDef and create the associated handle. |
mbed_official | 375:3d36234a1087 | 216 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 217 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 218 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 219 | */ |
mbed_official | 237:f3da66175598 | 220 | __weak HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 221 | { |
mbed_official | 237:f3da66175598 | 222 | /* Note : This function is defined into this file for library reference. */ |
mbed_official | 237:f3da66175598 | 223 | /* Function content is located into file stm32f3xx_hal_i2s_ex.c to */ |
mbed_official | 237:f3da66175598 | 224 | /* handle the possible I2S interfaces defined in STM32F3xx devices */ |
mbed_official | 237:f3da66175598 | 225 | |
mbed_official | 237:f3da66175598 | 226 | /* Return error status as not implemented here */ |
mbed_official | 237:f3da66175598 | 227 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 228 | } |
mbed_official | 237:f3da66175598 | 229 | |
mbed_official | 237:f3da66175598 | 230 | /** |
mbed_official | 237:f3da66175598 | 231 | * @brief DeInitializes the I2S peripheral |
mbed_official | 375:3d36234a1087 | 232 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 233 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 234 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 235 | */ |
mbed_official | 237:f3da66175598 | 236 | HAL_StatusTypeDef HAL_I2S_DeInit(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 237 | { |
mbed_official | 237:f3da66175598 | 238 | /* Check the I2S handle allocation */ |
mbed_official | 634:ac7d6880524d | 239 | if(hi2s == HAL_NULL) |
mbed_official | 237:f3da66175598 | 240 | { |
mbed_official | 237:f3da66175598 | 241 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 242 | } |
mbed_official | 237:f3da66175598 | 243 | |
mbed_official | 237:f3da66175598 | 244 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 245 | assert_param(IS_I2S_ALL_INSTANCE(hi2s->Instance)); |
mbed_official | 237:f3da66175598 | 246 | |
mbed_official | 237:f3da66175598 | 247 | hi2s->State = HAL_I2S_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 248 | |
mbed_official | 237:f3da66175598 | 249 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */ |
mbed_official | 237:f3da66175598 | 250 | HAL_I2S_MspDeInit(hi2s); |
mbed_official | 237:f3da66175598 | 251 | |
mbed_official | 237:f3da66175598 | 252 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 253 | hi2s->State = HAL_I2S_STATE_RESET; |
mbed_official | 237:f3da66175598 | 254 | |
mbed_official | 237:f3da66175598 | 255 | /* Release Lock */ |
mbed_official | 237:f3da66175598 | 256 | __HAL_UNLOCK(hi2s); |
mbed_official | 237:f3da66175598 | 257 | |
mbed_official | 237:f3da66175598 | 258 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 259 | } |
mbed_official | 237:f3da66175598 | 260 | |
mbed_official | 237:f3da66175598 | 261 | /** |
mbed_official | 237:f3da66175598 | 262 | * @brief I2S MSP Init |
mbed_official | 375:3d36234a1087 | 263 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 264 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 265 | * @retval None |
mbed_official | 237:f3da66175598 | 266 | */ |
mbed_official | 237:f3da66175598 | 267 | __weak void HAL_I2S_MspInit(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 268 | { |
mbed_official | 237:f3da66175598 | 269 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 270 | the HAL_I2S_MspInit could be implemented in the user file |
mbed_official | 237:f3da66175598 | 271 | */ |
mbed_official | 237:f3da66175598 | 272 | } |
mbed_official | 237:f3da66175598 | 273 | |
mbed_official | 237:f3da66175598 | 274 | /** |
mbed_official | 237:f3da66175598 | 275 | * @brief I2S MSP DeInit |
mbed_official | 375:3d36234a1087 | 276 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 277 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 278 | * @retval None |
mbed_official | 237:f3da66175598 | 279 | */ |
mbed_official | 237:f3da66175598 | 280 | __weak void HAL_I2S_MspDeInit(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 281 | { |
mbed_official | 237:f3da66175598 | 282 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 283 | the HAL_I2S_MspDeInit could be implemented in the user file |
mbed_official | 237:f3da66175598 | 284 | */ |
mbed_official | 237:f3da66175598 | 285 | } |
mbed_official | 237:f3da66175598 | 286 | |
mbed_official | 237:f3da66175598 | 287 | /** |
mbed_official | 237:f3da66175598 | 288 | * @} |
mbed_official | 237:f3da66175598 | 289 | */ |
mbed_official | 237:f3da66175598 | 290 | |
mbed_official | 375:3d36234a1087 | 291 | /** @defgroup I2S_Exported_Functions_Group2 Input and Output operation functions |
mbed_official | 237:f3da66175598 | 292 | * @brief Data transfers functions |
mbed_official | 237:f3da66175598 | 293 | * |
mbed_official | 237:f3da66175598 | 294 | @verbatim |
mbed_official | 237:f3da66175598 | 295 | =============================================================================== |
mbed_official | 237:f3da66175598 | 296 | ##### IO operation functions ##### |
mbed_official | 237:f3da66175598 | 297 | =============================================================================== |
mbed_official | 237:f3da66175598 | 298 | [..] |
mbed_official | 237:f3da66175598 | 299 | This subsection provides a set of functions allowing to manage the I2S data |
mbed_official | 237:f3da66175598 | 300 | transfers. |
mbed_official | 237:f3da66175598 | 301 | |
mbed_official | 375:3d36234a1087 | 302 | (#) There are two modes of transfer: |
mbed_official | 237:f3da66175598 | 303 | (++) Blocking mode : The communication is performed in the polling mode. |
mbed_official | 237:f3da66175598 | 304 | The status of all data processing is returned by the same function |
mbed_official | 237:f3da66175598 | 305 | after finishing transfer. |
mbed_official | 237:f3da66175598 | 306 | (++) No-Blocking mode : The communication is performed using Interrupts |
mbed_official | 237:f3da66175598 | 307 | or DMA. These functions return the status of the transfer startup. |
mbed_official | 237:f3da66175598 | 308 | The end of the data processing will be indicated through the |
mbed_official | 237:f3da66175598 | 309 | dedicated I2S IRQ when using Interrupt mode or the DMA IRQ when |
mbed_official | 237:f3da66175598 | 310 | using DMA mode. |
mbed_official | 237:f3da66175598 | 311 | |
mbed_official | 237:f3da66175598 | 312 | (#) Blocking mode functions are : |
mbed_official | 237:f3da66175598 | 313 | (++) HAL_I2S_Transmit() |
mbed_official | 237:f3da66175598 | 314 | (++) HAL_I2S_Receive() |
mbed_official | 237:f3da66175598 | 315 | |
mbed_official | 237:f3da66175598 | 316 | (#) No-Blocking mode functions with Interrupt are : |
mbed_official | 237:f3da66175598 | 317 | (++) HAL_I2S_Transmit_IT() |
mbed_official | 237:f3da66175598 | 318 | (++) HAL_I2S_Receive_IT() |
mbed_official | 237:f3da66175598 | 319 | |
mbed_official | 237:f3da66175598 | 320 | (#) No-Blocking mode functions with DMA are : |
mbed_official | 237:f3da66175598 | 321 | (++) HAL_I2S_Transmit_DMA() |
mbed_official | 237:f3da66175598 | 322 | (++) HAL_I2S_Receive_DMA() |
mbed_official | 237:f3da66175598 | 323 | |
mbed_official | 375:3d36234a1087 | 324 | (#) A set of Transfer Complete Callbacks are provided in non Blocking mode: |
mbed_official | 237:f3da66175598 | 325 | (++) HAL_I2S_TxCpltCallback() |
mbed_official | 237:f3da66175598 | 326 | (++) HAL_I2S_RxCpltCallback() |
mbed_official | 237:f3da66175598 | 327 | (++) HAL_I2S_ErrorCallback() |
mbed_official | 237:f3da66175598 | 328 | |
mbed_official | 237:f3da66175598 | 329 | @endverbatim |
mbed_official | 237:f3da66175598 | 330 | * @{ |
mbed_official | 237:f3da66175598 | 331 | */ |
mbed_official | 237:f3da66175598 | 332 | |
mbed_official | 237:f3da66175598 | 333 | /** |
mbed_official | 237:f3da66175598 | 334 | * @brief Transmit an amount of data in blocking mode |
mbed_official | 375:3d36234a1087 | 335 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 336 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 337 | * @param pData: a 16-bit pointer to data buffer. |
mbed_official | 237:f3da66175598 | 338 | * @param Size: number of data sample to be sent: |
mbed_official | 237:f3da66175598 | 339 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 237:f3da66175598 | 340 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 237:f3da66175598 | 341 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 237:f3da66175598 | 342 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 237:f3da66175598 | 343 | * @param Timeout: Timeout duration |
mbed_official | 237:f3da66175598 | 344 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 237:f3da66175598 | 345 | * between Master and Slave(example: audio streaming). |
mbed_official | 237:f3da66175598 | 346 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 347 | */ |
mbed_official | 237:f3da66175598 | 348 | HAL_StatusTypeDef HAL_I2S_Transmit(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 349 | { |
mbed_official | 634:ac7d6880524d | 350 | if((pData == HAL_NULL ) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 351 | { |
mbed_official | 237:f3da66175598 | 352 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 353 | } |
mbed_official | 237:f3da66175598 | 354 | |
mbed_official | 237:f3da66175598 | 355 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 237:f3da66175598 | 356 | { |
mbed_official | 237:f3da66175598 | 357 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 237:f3da66175598 | 358 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 237:f3da66175598 | 359 | { |
mbed_official | 237:f3da66175598 | 360 | hi2s->TxXferSize = (Size << 1); |
mbed_official | 237:f3da66175598 | 361 | hi2s->TxXferCount = (Size << 1); |
mbed_official | 237:f3da66175598 | 362 | } |
mbed_official | 237:f3da66175598 | 363 | else |
mbed_official | 237:f3da66175598 | 364 | { |
mbed_official | 237:f3da66175598 | 365 | hi2s->TxXferSize = Size; |
mbed_official | 237:f3da66175598 | 366 | hi2s->TxXferCount = Size; |
mbed_official | 237:f3da66175598 | 367 | } |
mbed_official | 237:f3da66175598 | 368 | |
mbed_official | 237:f3da66175598 | 369 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 370 | __HAL_LOCK(hi2s); |
mbed_official | 237:f3da66175598 | 371 | |
mbed_official | 237:f3da66175598 | 372 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 373 | hi2s->State = HAL_I2S_STATE_BUSY_TX; |
mbed_official | 237:f3da66175598 | 374 | |
mbed_official | 237:f3da66175598 | 375 | /* Check if the I2S is already enabled */ |
mbed_official | 237:f3da66175598 | 376 | if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 237:f3da66175598 | 377 | { |
mbed_official | 237:f3da66175598 | 378 | /* Enable I2S peripheral */ |
mbed_official | 237:f3da66175598 | 379 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 237:f3da66175598 | 380 | } |
mbed_official | 237:f3da66175598 | 381 | |
mbed_official | 237:f3da66175598 | 382 | while(hi2s->TxXferCount > 0) |
mbed_official | 237:f3da66175598 | 383 | { |
mbed_official | 237:f3da66175598 | 384 | hi2s->Instance->DR = (*pData++); |
mbed_official | 237:f3da66175598 | 385 | hi2s->TxXferCount--; |
mbed_official | 237:f3da66175598 | 386 | /* Wait until TXE flag is set */ |
mbed_official | 237:f3da66175598 | 387 | if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_TXE, SET, Timeout) != HAL_OK) |
mbed_official | 237:f3da66175598 | 388 | { |
mbed_official | 237:f3da66175598 | 389 | /* Set the error code and execute error callback*/ |
mbed_official | 237:f3da66175598 | 390 | hi2s->ErrorCode |= HAL_I2S_ERROR_TIMEOUT; |
mbed_official | 237:f3da66175598 | 391 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 237:f3da66175598 | 392 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 393 | } |
mbed_official | 237:f3da66175598 | 394 | |
mbed_official | 237:f3da66175598 | 395 | /* Check if an underrun occurs */ |
mbed_official | 237:f3da66175598 | 396 | if(__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_UDR) == SET) |
mbed_official | 237:f3da66175598 | 397 | { |
mbed_official | 237:f3da66175598 | 398 | /* Set the I2S State ready */ |
mbed_official | 237:f3da66175598 | 399 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 400 | |
mbed_official | 237:f3da66175598 | 401 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 402 | __HAL_UNLOCK(hi2s); |
mbed_official | 237:f3da66175598 | 403 | |
mbed_official | 237:f3da66175598 | 404 | /* Set the error code and execute error callback*/ |
mbed_official | 237:f3da66175598 | 405 | hi2s->ErrorCode |= HAL_I2S_ERROR_UDR; |
mbed_official | 237:f3da66175598 | 406 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 237:f3da66175598 | 407 | |
mbed_official | 237:f3da66175598 | 408 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 409 | } |
mbed_official | 237:f3da66175598 | 410 | } |
mbed_official | 237:f3da66175598 | 411 | |
mbed_official | 237:f3da66175598 | 412 | /* Wait until Busy flag is reset */ |
mbed_official | 237:f3da66175598 | 413 | if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_BSY, RESET, Timeout) != HAL_OK) |
mbed_official | 237:f3da66175598 | 414 | { |
mbed_official | 237:f3da66175598 | 415 | /* Set the error code and execute error callback*/ |
mbed_official | 237:f3da66175598 | 416 | hi2s->ErrorCode |= HAL_I2S_ERROR_TIMEOUT; |
mbed_official | 237:f3da66175598 | 417 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 237:f3da66175598 | 418 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 419 | } |
mbed_official | 237:f3da66175598 | 420 | |
mbed_official | 237:f3da66175598 | 421 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 422 | |
mbed_official | 237:f3da66175598 | 423 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 424 | __HAL_UNLOCK(hi2s); |
mbed_official | 237:f3da66175598 | 425 | |
mbed_official | 237:f3da66175598 | 426 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 427 | } |
mbed_official | 237:f3da66175598 | 428 | else |
mbed_official | 237:f3da66175598 | 429 | { |
mbed_official | 237:f3da66175598 | 430 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 431 | } |
mbed_official | 237:f3da66175598 | 432 | } |
mbed_official | 237:f3da66175598 | 433 | |
mbed_official | 237:f3da66175598 | 434 | /** |
mbed_official | 237:f3da66175598 | 435 | * @brief Receive an amount of data in blocking mode |
mbed_official | 375:3d36234a1087 | 436 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 437 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 438 | * @param pData: a 16-bit pointer to data buffer. |
mbed_official | 237:f3da66175598 | 439 | * @param Size: number of data sample to be sent: |
mbed_official | 237:f3da66175598 | 440 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 237:f3da66175598 | 441 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 237:f3da66175598 | 442 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 237:f3da66175598 | 443 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 237:f3da66175598 | 444 | * @param Timeout: Timeout duration |
mbed_official | 237:f3da66175598 | 445 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 237:f3da66175598 | 446 | * between Master and Slave(example: audio streaming). |
mbed_official | 237:f3da66175598 | 447 | * @note In I2S Master Receiver mode, just after enabling the peripheral the clock will be generate |
mbed_official | 237:f3da66175598 | 448 | * in continouse way and as the I2S is not disabled at the end of the I2S transaction. |
mbed_official | 237:f3da66175598 | 449 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 450 | */ |
mbed_official | 237:f3da66175598 | 451 | HAL_StatusTypeDef HAL_I2S_Receive(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 452 | { |
mbed_official | 634:ac7d6880524d | 453 | if((pData == HAL_NULL ) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 454 | { |
mbed_official | 237:f3da66175598 | 455 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 456 | } |
mbed_official | 237:f3da66175598 | 457 | |
mbed_official | 237:f3da66175598 | 458 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 237:f3da66175598 | 459 | { |
mbed_official | 237:f3da66175598 | 460 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 237:f3da66175598 | 461 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 237:f3da66175598 | 462 | { |
mbed_official | 237:f3da66175598 | 463 | hi2s->RxXferSize = (Size << 1); |
mbed_official | 237:f3da66175598 | 464 | hi2s->RxXferCount = (Size << 1); |
mbed_official | 237:f3da66175598 | 465 | } |
mbed_official | 237:f3da66175598 | 466 | else |
mbed_official | 237:f3da66175598 | 467 | { |
mbed_official | 237:f3da66175598 | 468 | hi2s->RxXferSize = Size; |
mbed_official | 237:f3da66175598 | 469 | hi2s->RxXferCount = Size; |
mbed_official | 237:f3da66175598 | 470 | } |
mbed_official | 237:f3da66175598 | 471 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 472 | __HAL_LOCK(hi2s); |
mbed_official | 237:f3da66175598 | 473 | |
mbed_official | 237:f3da66175598 | 474 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 475 | hi2s->State = HAL_I2S_STATE_BUSY_RX; |
mbed_official | 237:f3da66175598 | 476 | |
mbed_official | 237:f3da66175598 | 477 | /* Check if the I2S is already enabled */ |
mbed_official | 237:f3da66175598 | 478 | if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 237:f3da66175598 | 479 | { |
mbed_official | 237:f3da66175598 | 480 | /* Enable I2S peripheral */ |
mbed_official | 237:f3da66175598 | 481 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 237:f3da66175598 | 482 | } |
mbed_official | 237:f3da66175598 | 483 | |
mbed_official | 237:f3da66175598 | 484 | /* Check if Master Receiver mode is selected */ |
mbed_official | 237:f3da66175598 | 485 | if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX) |
mbed_official | 237:f3da66175598 | 486 | { |
mbed_official | 237:f3da66175598 | 487 | /* Clear the Overrun Flag by a read operation on the SPI_DR register followed by a read |
mbed_official | 237:f3da66175598 | 488 | access to the SPI_SR register. */ |
mbed_official | 237:f3da66175598 | 489 | __HAL_I2S_CLEAR_OVRFLAG(hi2s); |
mbed_official | 237:f3da66175598 | 490 | } |
mbed_official | 237:f3da66175598 | 491 | |
mbed_official | 237:f3da66175598 | 492 | /* Receive data */ |
mbed_official | 237:f3da66175598 | 493 | while(hi2s->RxXferCount > 0) |
mbed_official | 237:f3da66175598 | 494 | { |
mbed_official | 237:f3da66175598 | 495 | /* Wait until RXNE flag is set */ |
mbed_official | 237:f3da66175598 | 496 | if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_RXNE, SET, Timeout) != HAL_OK) |
mbed_official | 237:f3da66175598 | 497 | { |
mbed_official | 237:f3da66175598 | 498 | /* Set the error code and execute error callback*/ |
mbed_official | 237:f3da66175598 | 499 | hi2s->ErrorCode |= HAL_I2S_ERROR_TIMEOUT; |
mbed_official | 237:f3da66175598 | 500 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 237:f3da66175598 | 501 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 502 | } |
mbed_official | 237:f3da66175598 | 503 | |
mbed_official | 237:f3da66175598 | 504 | /* Check if an overrun occurs */ |
mbed_official | 237:f3da66175598 | 505 | if(__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_OVR) == SET) |
mbed_official | 237:f3da66175598 | 506 | { |
mbed_official | 237:f3da66175598 | 507 | /* Set the I2S State ready */ |
mbed_official | 237:f3da66175598 | 508 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 509 | |
mbed_official | 237:f3da66175598 | 510 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 511 | __HAL_UNLOCK(hi2s); |
mbed_official | 237:f3da66175598 | 512 | |
mbed_official | 237:f3da66175598 | 513 | /* Set the error code and execute error callback*/ |
mbed_official | 237:f3da66175598 | 514 | hi2s->ErrorCode |= HAL_I2S_ERROR_OVR; |
mbed_official | 237:f3da66175598 | 515 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 237:f3da66175598 | 516 | |
mbed_official | 237:f3da66175598 | 517 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 518 | } |
mbed_official | 237:f3da66175598 | 519 | |
mbed_official | 237:f3da66175598 | 520 | (*pData++) = hi2s->Instance->DR; |
mbed_official | 237:f3da66175598 | 521 | hi2s->RxXferCount--; |
mbed_official | 237:f3da66175598 | 522 | } |
mbed_official | 237:f3da66175598 | 523 | |
mbed_official | 237:f3da66175598 | 524 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 525 | |
mbed_official | 237:f3da66175598 | 526 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 527 | __HAL_UNLOCK(hi2s); |
mbed_official | 237:f3da66175598 | 528 | |
mbed_official | 237:f3da66175598 | 529 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 530 | } |
mbed_official | 237:f3da66175598 | 531 | else |
mbed_official | 237:f3da66175598 | 532 | { |
mbed_official | 237:f3da66175598 | 533 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 534 | } |
mbed_official | 237:f3da66175598 | 535 | } |
mbed_official | 237:f3da66175598 | 536 | |
mbed_official | 237:f3da66175598 | 537 | /** |
mbed_official | 237:f3da66175598 | 538 | * @brief Transmit an amount of data in non-blocking mode with Interrupt |
mbed_official | 375:3d36234a1087 | 539 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 540 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 541 | * @param pData: a 16-bit pointer to data buffer. |
mbed_official | 237:f3da66175598 | 542 | * @param Size: number of data sample to be sent: |
mbed_official | 237:f3da66175598 | 543 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 237:f3da66175598 | 544 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 237:f3da66175598 | 545 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 237:f3da66175598 | 546 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 237:f3da66175598 | 547 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 237:f3da66175598 | 548 | * between Master and Slave(example: audio streaming). |
mbed_official | 237:f3da66175598 | 549 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 550 | */ |
mbed_official | 237:f3da66175598 | 551 | HAL_StatusTypeDef HAL_I2S_Transmit_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size) |
mbed_official | 237:f3da66175598 | 552 | { |
mbed_official | 237:f3da66175598 | 553 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 237:f3da66175598 | 554 | { |
mbed_official | 634:ac7d6880524d | 555 | if((pData == HAL_NULL) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 556 | { |
mbed_official | 237:f3da66175598 | 557 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 558 | } |
mbed_official | 237:f3da66175598 | 559 | |
mbed_official | 237:f3da66175598 | 560 | hi2s->pTxBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 561 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 237:f3da66175598 | 562 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 237:f3da66175598 | 563 | { |
mbed_official | 237:f3da66175598 | 564 | hi2s->TxXferSize = (Size << 1); |
mbed_official | 237:f3da66175598 | 565 | hi2s->TxXferCount = (Size << 1); |
mbed_official | 237:f3da66175598 | 566 | } |
mbed_official | 237:f3da66175598 | 567 | else |
mbed_official | 237:f3da66175598 | 568 | { |
mbed_official | 237:f3da66175598 | 569 | hi2s->TxXferSize = Size; |
mbed_official | 237:f3da66175598 | 570 | hi2s->TxXferCount = Size; |
mbed_official | 237:f3da66175598 | 571 | } |
mbed_official | 237:f3da66175598 | 572 | |
mbed_official | 237:f3da66175598 | 573 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 574 | __HAL_LOCK(hi2s); |
mbed_official | 237:f3da66175598 | 575 | |
mbed_official | 237:f3da66175598 | 576 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 577 | hi2s->State = HAL_I2S_STATE_BUSY_TX; |
mbed_official | 237:f3da66175598 | 578 | |
mbed_official | 237:f3da66175598 | 579 | /* Enable TXE and ERR interrupt */ |
mbed_official | 237:f3da66175598 | 580 | __HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_ERR)); |
mbed_official | 237:f3da66175598 | 581 | |
mbed_official | 237:f3da66175598 | 582 | /* Check if the I2S is already enabled */ |
mbed_official | 237:f3da66175598 | 583 | if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 237:f3da66175598 | 584 | { |
mbed_official | 237:f3da66175598 | 585 | /* Enable I2S peripheral */ |
mbed_official | 237:f3da66175598 | 586 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 237:f3da66175598 | 587 | } |
mbed_official | 237:f3da66175598 | 588 | |
mbed_official | 237:f3da66175598 | 589 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 590 | __HAL_UNLOCK(hi2s); |
mbed_official | 237:f3da66175598 | 591 | |
mbed_official | 237:f3da66175598 | 592 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 593 | } |
mbed_official | 237:f3da66175598 | 594 | else |
mbed_official | 237:f3da66175598 | 595 | { |
mbed_official | 237:f3da66175598 | 596 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 597 | } |
mbed_official | 237:f3da66175598 | 598 | } |
mbed_official | 237:f3da66175598 | 599 | |
mbed_official | 237:f3da66175598 | 600 | /** |
mbed_official | 237:f3da66175598 | 601 | * @brief Receive an amount of data in non-blocking mode with Interrupt |
mbed_official | 375:3d36234a1087 | 602 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 603 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 604 | * @param pData: a 16-bit pointer to the Receive data buffer. |
mbed_official | 237:f3da66175598 | 605 | * @param Size: number of data sample to be sent: |
mbed_official | 237:f3da66175598 | 606 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 237:f3da66175598 | 607 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 237:f3da66175598 | 608 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 237:f3da66175598 | 609 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 237:f3da66175598 | 610 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 237:f3da66175598 | 611 | * between Master and Slave(example: audio streaming). |
mbed_official | 237:f3da66175598 | 612 | * @note It is recommended to use DMA for the I2S receiver to avoid de-synchronisation |
mbed_official | 237:f3da66175598 | 613 | * between Master and Slave otherwise the I2S interrupt should be optimized. |
mbed_official | 237:f3da66175598 | 614 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 615 | */ |
mbed_official | 237:f3da66175598 | 616 | HAL_StatusTypeDef HAL_I2S_Receive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size) |
mbed_official | 237:f3da66175598 | 617 | { |
mbed_official | 237:f3da66175598 | 618 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 237:f3da66175598 | 619 | { |
mbed_official | 634:ac7d6880524d | 620 | if((pData == HAL_NULL) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 621 | { |
mbed_official | 237:f3da66175598 | 622 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 623 | } |
mbed_official | 237:f3da66175598 | 624 | |
mbed_official | 237:f3da66175598 | 625 | hi2s->pRxBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 626 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 237:f3da66175598 | 627 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 237:f3da66175598 | 628 | { |
mbed_official | 237:f3da66175598 | 629 | hi2s->RxXferSize = (Size << 1); |
mbed_official | 237:f3da66175598 | 630 | hi2s->RxXferCount = (Size << 1); |
mbed_official | 237:f3da66175598 | 631 | } |
mbed_official | 237:f3da66175598 | 632 | else |
mbed_official | 237:f3da66175598 | 633 | { |
mbed_official | 237:f3da66175598 | 634 | hi2s->RxXferSize = Size; |
mbed_official | 237:f3da66175598 | 635 | hi2s->RxXferCount = Size; |
mbed_official | 237:f3da66175598 | 636 | } |
mbed_official | 237:f3da66175598 | 637 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 638 | __HAL_LOCK(hi2s); |
mbed_official | 237:f3da66175598 | 639 | |
mbed_official | 237:f3da66175598 | 640 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 641 | hi2s->State = HAL_I2S_STATE_BUSY_RX; |
mbed_official | 237:f3da66175598 | 642 | |
mbed_official | 237:f3da66175598 | 643 | /* Enable TXE and ERR interrupt */ |
mbed_official | 237:f3da66175598 | 644 | __HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_ERR)); |
mbed_official | 237:f3da66175598 | 645 | |
mbed_official | 237:f3da66175598 | 646 | /* Check if the I2S is already enabled */ |
mbed_official | 237:f3da66175598 | 647 | if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 237:f3da66175598 | 648 | { |
mbed_official | 237:f3da66175598 | 649 | /* Enable I2S peripheral */ |
mbed_official | 237:f3da66175598 | 650 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 237:f3da66175598 | 651 | } |
mbed_official | 237:f3da66175598 | 652 | |
mbed_official | 237:f3da66175598 | 653 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 654 | __HAL_UNLOCK(hi2s); |
mbed_official | 237:f3da66175598 | 655 | |
mbed_official | 237:f3da66175598 | 656 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 657 | } |
mbed_official | 237:f3da66175598 | 658 | else |
mbed_official | 237:f3da66175598 | 659 | { |
mbed_official | 237:f3da66175598 | 660 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 661 | } |
mbed_official | 237:f3da66175598 | 662 | } |
mbed_official | 237:f3da66175598 | 663 | |
mbed_official | 237:f3da66175598 | 664 | /** |
mbed_official | 237:f3da66175598 | 665 | * @brief Transmit an amount of data in non-blocking mode with DMA |
mbed_official | 375:3d36234a1087 | 666 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 667 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 668 | * @param pData: a 16-bit pointer to the Transmit data buffer. |
mbed_official | 237:f3da66175598 | 669 | * @param Size: number of data sample to be sent: |
mbed_official | 237:f3da66175598 | 670 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 237:f3da66175598 | 671 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 237:f3da66175598 | 672 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 237:f3da66175598 | 673 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 237:f3da66175598 | 674 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 237:f3da66175598 | 675 | * between Master and Slave(example: audio streaming). |
mbed_official | 237:f3da66175598 | 676 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 677 | */ |
mbed_official | 237:f3da66175598 | 678 | HAL_StatusTypeDef HAL_I2S_Transmit_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size) |
mbed_official | 237:f3da66175598 | 679 | { |
mbed_official | 237:f3da66175598 | 680 | uint32_t *tmp; |
mbed_official | 237:f3da66175598 | 681 | |
mbed_official | 634:ac7d6880524d | 682 | if((pData == HAL_NULL) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 683 | { |
mbed_official | 237:f3da66175598 | 684 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 685 | } |
mbed_official | 237:f3da66175598 | 686 | |
mbed_official | 237:f3da66175598 | 687 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 237:f3da66175598 | 688 | { |
mbed_official | 237:f3da66175598 | 689 | hi2s->pTxBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 690 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 237:f3da66175598 | 691 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 237:f3da66175598 | 692 | { |
mbed_official | 237:f3da66175598 | 693 | hi2s->TxXferSize = (Size << 1); |
mbed_official | 237:f3da66175598 | 694 | hi2s->TxXferCount = (Size << 1); |
mbed_official | 237:f3da66175598 | 695 | } |
mbed_official | 237:f3da66175598 | 696 | else |
mbed_official | 237:f3da66175598 | 697 | { |
mbed_official | 237:f3da66175598 | 698 | hi2s->TxXferSize = Size; |
mbed_official | 237:f3da66175598 | 699 | hi2s->TxXferCount = Size; |
mbed_official | 237:f3da66175598 | 700 | } |
mbed_official | 237:f3da66175598 | 701 | |
mbed_official | 237:f3da66175598 | 702 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 703 | __HAL_LOCK(hi2s); |
mbed_official | 237:f3da66175598 | 704 | |
mbed_official | 237:f3da66175598 | 705 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 706 | hi2s->State = HAL_I2S_STATE_BUSY_TX; |
mbed_official | 237:f3da66175598 | 707 | |
mbed_official | 237:f3da66175598 | 708 | /* Set the I2S Tx DMA Half transfer complete callback */ |
mbed_official | 237:f3da66175598 | 709 | hi2s->hdmatx->XferHalfCpltCallback = I2S_DMATxHalfCplt; |
mbed_official | 237:f3da66175598 | 710 | |
mbed_official | 237:f3da66175598 | 711 | /* Set the I2S TxDMA transfer complete callback */ |
mbed_official | 237:f3da66175598 | 712 | hi2s->hdmatx->XferCpltCallback = I2S_DMATxCplt; |
mbed_official | 237:f3da66175598 | 713 | |
mbed_official | 237:f3da66175598 | 714 | /* Set the DMA error callback */ |
mbed_official | 237:f3da66175598 | 715 | hi2s->hdmatx->XferErrorCallback = I2S_DMAError; |
mbed_official | 237:f3da66175598 | 716 | |
mbed_official | 237:f3da66175598 | 717 | /* Enable the Tx DMA Channel */ |
mbed_official | 237:f3da66175598 | 718 | tmp = (uint32_t*)&pData; |
mbed_official | 237:f3da66175598 | 719 | HAL_DMA_Start_IT(hi2s->hdmatx, *(uint32_t*)tmp, (uint32_t)&hi2s->Instance->DR, hi2s->TxXferSize); |
mbed_official | 237:f3da66175598 | 720 | |
mbed_official | 237:f3da66175598 | 721 | /* Check if the I2S is already enabled */ |
mbed_official | 237:f3da66175598 | 722 | if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 237:f3da66175598 | 723 | { |
mbed_official | 237:f3da66175598 | 724 | /* Enable I2S peripheral */ |
mbed_official | 237:f3da66175598 | 725 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 237:f3da66175598 | 726 | } |
mbed_official | 237:f3da66175598 | 727 | |
mbed_official | 237:f3da66175598 | 728 | /* Enable Tx DMA Request */ |
mbed_official | 237:f3da66175598 | 729 | hi2s->Instance->CR2 |= SPI_CR2_TXDMAEN; |
mbed_official | 237:f3da66175598 | 730 | |
mbed_official | 237:f3da66175598 | 731 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 732 | __HAL_UNLOCK(hi2s); |
mbed_official | 237:f3da66175598 | 733 | |
mbed_official | 237:f3da66175598 | 734 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 735 | } |
mbed_official | 237:f3da66175598 | 736 | else |
mbed_official | 237:f3da66175598 | 737 | { |
mbed_official | 237:f3da66175598 | 738 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 739 | } |
mbed_official | 237:f3da66175598 | 740 | } |
mbed_official | 237:f3da66175598 | 741 | |
mbed_official | 237:f3da66175598 | 742 | /** |
mbed_official | 237:f3da66175598 | 743 | * @brief Receive an amount of data in non-blocking mode with DMA |
mbed_official | 375:3d36234a1087 | 744 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 745 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 746 | * @param pData: a 16-bit pointer to the Receive data buffer. |
mbed_official | 237:f3da66175598 | 747 | * @param Size: number of data sample to be sent: |
mbed_official | 237:f3da66175598 | 748 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 237:f3da66175598 | 749 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 237:f3da66175598 | 750 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 237:f3da66175598 | 751 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 237:f3da66175598 | 752 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 237:f3da66175598 | 753 | * between Master and Slave(example: audio streaming). |
mbed_official | 237:f3da66175598 | 754 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 755 | */ |
mbed_official | 237:f3da66175598 | 756 | HAL_StatusTypeDef HAL_I2S_Receive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size) |
mbed_official | 237:f3da66175598 | 757 | { |
mbed_official | 237:f3da66175598 | 758 | uint32_t *tmp; |
mbed_official | 237:f3da66175598 | 759 | |
mbed_official | 634:ac7d6880524d | 760 | if((pData == HAL_NULL) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 761 | { |
mbed_official | 237:f3da66175598 | 762 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 763 | } |
mbed_official | 237:f3da66175598 | 764 | |
mbed_official | 237:f3da66175598 | 765 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 237:f3da66175598 | 766 | { |
mbed_official | 237:f3da66175598 | 767 | hi2s->pRxBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 768 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 237:f3da66175598 | 769 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 237:f3da66175598 | 770 | { |
mbed_official | 237:f3da66175598 | 771 | hi2s->RxXferSize = (Size << 1); |
mbed_official | 237:f3da66175598 | 772 | hi2s->RxXferCount = (Size << 1); |
mbed_official | 237:f3da66175598 | 773 | } |
mbed_official | 237:f3da66175598 | 774 | else |
mbed_official | 237:f3da66175598 | 775 | { |
mbed_official | 237:f3da66175598 | 776 | hi2s->RxXferSize = Size; |
mbed_official | 237:f3da66175598 | 777 | hi2s->RxXferCount = Size; |
mbed_official | 237:f3da66175598 | 778 | } |
mbed_official | 237:f3da66175598 | 779 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 780 | __HAL_LOCK(hi2s); |
mbed_official | 237:f3da66175598 | 781 | |
mbed_official | 237:f3da66175598 | 782 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 783 | hi2s->State = HAL_I2S_STATE_BUSY_RX; |
mbed_official | 237:f3da66175598 | 784 | |
mbed_official | 237:f3da66175598 | 785 | /* Set the I2S Rx DMA Half transfer complete callback */ |
mbed_official | 237:f3da66175598 | 786 | hi2s->hdmarx->XferHalfCpltCallback = I2S_DMARxHalfCplt; |
mbed_official | 237:f3da66175598 | 787 | |
mbed_official | 237:f3da66175598 | 788 | /* Set the I2S Rx DMA transfer complete callback */ |
mbed_official | 237:f3da66175598 | 789 | hi2s->hdmarx->XferCpltCallback = I2S_DMARxCplt; |
mbed_official | 237:f3da66175598 | 790 | |
mbed_official | 237:f3da66175598 | 791 | /* Set the DMA error callback */ |
mbed_official | 237:f3da66175598 | 792 | hi2s->hdmarx->XferErrorCallback = I2S_DMAError; |
mbed_official | 237:f3da66175598 | 793 | |
mbed_official | 237:f3da66175598 | 794 | /* Check if Master Receiver mode is selected */ |
mbed_official | 237:f3da66175598 | 795 | if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX) |
mbed_official | 237:f3da66175598 | 796 | { |
mbed_official | 237:f3da66175598 | 797 | /* Clear the Overrun Flag by a read operation to the SPI_DR register followed by a read |
mbed_official | 237:f3da66175598 | 798 | access to the SPI_SR register. */ |
mbed_official | 237:f3da66175598 | 799 | __HAL_I2S_CLEAR_OVRFLAG(hi2s); |
mbed_official | 237:f3da66175598 | 800 | } |
mbed_official | 237:f3da66175598 | 801 | |
mbed_official | 237:f3da66175598 | 802 | /* Enable the Rx DMA Channel */ |
mbed_official | 237:f3da66175598 | 803 | tmp = (uint32_t*)&pData; |
mbed_official | 237:f3da66175598 | 804 | HAL_DMA_Start_IT(hi2s->hdmarx, (uint32_t)&hi2s->Instance->DR, *(uint32_t*)tmp, hi2s->RxXferSize); |
mbed_official | 237:f3da66175598 | 805 | |
mbed_official | 237:f3da66175598 | 806 | /* Check if the I2S is already enabled */ |
mbed_official | 237:f3da66175598 | 807 | if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 237:f3da66175598 | 808 | { |
mbed_official | 237:f3da66175598 | 809 | /* Enable I2S peripheral */ |
mbed_official | 237:f3da66175598 | 810 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 237:f3da66175598 | 811 | } |
mbed_official | 237:f3da66175598 | 812 | |
mbed_official | 237:f3da66175598 | 813 | /* Enable Rx DMA Request */ |
mbed_official | 237:f3da66175598 | 814 | hi2s->Instance->CR2 |= SPI_CR2_RXDMAEN; |
mbed_official | 237:f3da66175598 | 815 | |
mbed_official | 237:f3da66175598 | 816 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 817 | __HAL_UNLOCK(hi2s); |
mbed_official | 237:f3da66175598 | 818 | |
mbed_official | 237:f3da66175598 | 819 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 820 | } |
mbed_official | 237:f3da66175598 | 821 | else |
mbed_official | 237:f3da66175598 | 822 | { |
mbed_official | 237:f3da66175598 | 823 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 824 | } |
mbed_official | 237:f3da66175598 | 825 | } |
mbed_official | 237:f3da66175598 | 826 | |
mbed_official | 237:f3da66175598 | 827 | /** |
mbed_official | 237:f3da66175598 | 828 | * @brief This function handles I2S interrupt request. |
mbed_official | 375:3d36234a1087 | 829 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 830 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 831 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 832 | */ |
mbed_official | 237:f3da66175598 | 833 | void HAL_I2S_IRQHandler(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 834 | { |
mbed_official | 237:f3da66175598 | 835 | __IO uint32_t i2ssr = hi2s->Instance->SR; |
mbed_official | 237:f3da66175598 | 836 | |
mbed_official | 237:f3da66175598 | 837 | if(hi2s->State == HAL_I2S_STATE_BUSY_RX) |
mbed_official | 237:f3da66175598 | 838 | { |
mbed_official | 237:f3da66175598 | 839 | /* I2S in mode Receiver ----------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 840 | if(((i2ssr & I2S_FLAG_RXNE) == I2S_FLAG_RXNE) && (__HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_RXNE) != RESET)) |
mbed_official | 237:f3da66175598 | 841 | { |
mbed_official | 237:f3da66175598 | 842 | I2S_Receive_IT(hi2s); |
mbed_official | 237:f3da66175598 | 843 | } |
mbed_official | 237:f3da66175598 | 844 | |
mbed_official | 237:f3da66175598 | 845 | /* I2S Overrun error interrupt occured -------------------------------------*/ |
mbed_official | 237:f3da66175598 | 846 | if(((i2ssr & I2S_FLAG_OVR) == I2S_FLAG_OVR) && (__HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR) != RESET)) |
mbed_official | 237:f3da66175598 | 847 | { |
mbed_official | 237:f3da66175598 | 848 | /* Disable RXNE and ERR interrupt */ |
mbed_official | 237:f3da66175598 | 849 | __HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_ERR)); |
mbed_official | 237:f3da66175598 | 850 | |
mbed_official | 237:f3da66175598 | 851 | /* Set the I2S State ready */ |
mbed_official | 237:f3da66175598 | 852 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 853 | |
mbed_official | 237:f3da66175598 | 854 | /* Set the error code and execute error callback*/ |
mbed_official | 237:f3da66175598 | 855 | hi2s->ErrorCode |= HAL_I2S_ERROR_OVR; |
mbed_official | 237:f3da66175598 | 856 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 237:f3da66175598 | 857 | } |
mbed_official | 237:f3da66175598 | 858 | } |
mbed_official | 237:f3da66175598 | 859 | else if(hi2s->State == HAL_I2S_STATE_BUSY_TX) |
mbed_official | 237:f3da66175598 | 860 | { |
mbed_official | 237:f3da66175598 | 861 | /* I2S in mode Tramitter ---------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 862 | if(((i2ssr & I2S_FLAG_TXE) == I2S_FLAG_TXE) && (__HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_TXE) != RESET)) |
mbed_official | 237:f3da66175598 | 863 | { |
mbed_official | 237:f3da66175598 | 864 | I2S_Transmit_IT(hi2s); |
mbed_official | 237:f3da66175598 | 865 | } |
mbed_official | 237:f3da66175598 | 866 | |
mbed_official | 237:f3da66175598 | 867 | /* I2S Underrun error interrupt occured ------------------------------------*/ |
mbed_official | 237:f3da66175598 | 868 | if(((i2ssr & I2S_FLAG_UDR) == I2S_FLAG_UDR) && (__HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR) != RESET)) |
mbed_official | 237:f3da66175598 | 869 | { |
mbed_official | 237:f3da66175598 | 870 | /* Disable TXE and ERR interrupt */ |
mbed_official | 237:f3da66175598 | 871 | __HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_ERR)); |
mbed_official | 237:f3da66175598 | 872 | |
mbed_official | 237:f3da66175598 | 873 | /* Set the I2S State ready */ |
mbed_official | 237:f3da66175598 | 874 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 875 | |
mbed_official | 237:f3da66175598 | 876 | /* Set the error code and execute error callback*/ |
mbed_official | 237:f3da66175598 | 877 | hi2s->ErrorCode |= HAL_I2S_ERROR_UDR; |
mbed_official | 237:f3da66175598 | 878 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 237:f3da66175598 | 879 | } |
mbed_official | 237:f3da66175598 | 880 | } |
mbed_official | 237:f3da66175598 | 881 | } |
mbed_official | 237:f3da66175598 | 882 | |
mbed_official | 237:f3da66175598 | 883 | /** |
mbed_official | 375:3d36234a1087 | 884 | * @} |
mbed_official | 375:3d36234a1087 | 885 | */ |
mbed_official | 375:3d36234a1087 | 886 | |
mbed_official | 375:3d36234a1087 | 887 | /** |
mbed_official | 375:3d36234a1087 | 888 | * @} |
mbed_official | 375:3d36234a1087 | 889 | */ |
mbed_official | 375:3d36234a1087 | 890 | |
mbed_official | 375:3d36234a1087 | 891 | /** @addtogroup I2S_Private_Functions I2S Private Functions |
mbed_official | 375:3d36234a1087 | 892 | * @{ |
mbed_official | 375:3d36234a1087 | 893 | */ |
mbed_official | 375:3d36234a1087 | 894 | /** |
mbed_official | 237:f3da66175598 | 895 | * @brief This function handles I2S Communication Timeout. |
mbed_official | 375:3d36234a1087 | 896 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 897 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 898 | * @param Flag: Flag checked |
mbed_official | 237:f3da66175598 | 899 | * @param State: Value of the flag expected |
mbed_official | 237:f3da66175598 | 900 | * @param Timeout: Duration of the timeout |
mbed_official | 237:f3da66175598 | 901 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 902 | */ |
mbed_official | 237:f3da66175598 | 903 | static HAL_StatusTypeDef I2S_WaitFlagStateUntilTimeout(I2S_HandleTypeDef *hi2s, uint32_t Flag, |
mbed_official | 237:f3da66175598 | 904 | uint32_t State, uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 905 | { |
mbed_official | 237:f3da66175598 | 906 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 907 | |
mbed_official | 237:f3da66175598 | 908 | while((__HAL_I2S_GET_FLAG(hi2s, Flag)) != State) |
mbed_official | 237:f3da66175598 | 909 | { |
mbed_official | 237:f3da66175598 | 910 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 237:f3da66175598 | 911 | { |
mbed_official | 237:f3da66175598 | 912 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
mbed_official | 237:f3da66175598 | 913 | { |
mbed_official | 237:f3da66175598 | 914 | /* Set the I2S State ready */ |
mbed_official | 237:f3da66175598 | 915 | hi2s->State= HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 916 | |
mbed_official | 237:f3da66175598 | 917 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 918 | __HAL_UNLOCK(hi2s); |
mbed_official | 237:f3da66175598 | 919 | |
mbed_official | 237:f3da66175598 | 920 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 921 | } |
mbed_official | 237:f3da66175598 | 922 | } |
mbed_official | 237:f3da66175598 | 923 | } |
mbed_official | 237:f3da66175598 | 924 | |
mbed_official | 237:f3da66175598 | 925 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 926 | } |
mbed_official | 375:3d36234a1087 | 927 | /** |
mbed_official | 375:3d36234a1087 | 928 | * @} |
mbed_official | 375:3d36234a1087 | 929 | */ |
mbed_official | 237:f3da66175598 | 930 | |
mbed_official | 375:3d36234a1087 | 931 | /** @addtogroup I2S_Exported_Functions I2S Exported Functions |
mbed_official | 375:3d36234a1087 | 932 | * @{ |
mbed_official | 375:3d36234a1087 | 933 | */ |
mbed_official | 375:3d36234a1087 | 934 | |
mbed_official | 375:3d36234a1087 | 935 | /** @addtogroup I2S_Exported_Functions_Group2 Input and Output operation functions |
mbed_official | 375:3d36234a1087 | 936 | * @{ |
mbed_official | 375:3d36234a1087 | 937 | */ |
mbed_official | 237:f3da66175598 | 938 | /** |
mbed_official | 237:f3da66175598 | 939 | * @brief Tx Transfer Half completed callbacks |
mbed_official | 375:3d36234a1087 | 940 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 941 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 942 | * @retval None |
mbed_official | 237:f3da66175598 | 943 | */ |
mbed_official | 237:f3da66175598 | 944 | __weak void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 945 | { |
mbed_official | 237:f3da66175598 | 946 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 947 | the HAL_I2S_TxHalfCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 948 | */ |
mbed_official | 237:f3da66175598 | 949 | } |
mbed_official | 237:f3da66175598 | 950 | |
mbed_official | 237:f3da66175598 | 951 | /** |
mbed_official | 237:f3da66175598 | 952 | * @brief Tx Transfer completed callbacks |
mbed_official | 375:3d36234a1087 | 953 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 954 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 955 | * @retval None |
mbed_official | 237:f3da66175598 | 956 | */ |
mbed_official | 237:f3da66175598 | 957 | __weak void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 958 | { |
mbed_official | 237:f3da66175598 | 959 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 960 | the HAL_I2S_TxCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 961 | */ |
mbed_official | 237:f3da66175598 | 962 | } |
mbed_official | 237:f3da66175598 | 963 | |
mbed_official | 237:f3da66175598 | 964 | /** |
mbed_official | 237:f3da66175598 | 965 | * @brief Rx Transfer half completed callbacks |
mbed_official | 375:3d36234a1087 | 966 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 967 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 968 | * @retval None |
mbed_official | 237:f3da66175598 | 969 | */ |
mbed_official | 237:f3da66175598 | 970 | __weak void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 971 | { |
mbed_official | 237:f3da66175598 | 972 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 973 | the HAL_I2S_RxCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 974 | */ |
mbed_official | 237:f3da66175598 | 975 | } |
mbed_official | 237:f3da66175598 | 976 | |
mbed_official | 237:f3da66175598 | 977 | /** |
mbed_official | 237:f3da66175598 | 978 | * @brief Rx Transfer completed callbacks |
mbed_official | 375:3d36234a1087 | 979 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 980 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 981 | * @retval None |
mbed_official | 237:f3da66175598 | 982 | */ |
mbed_official | 237:f3da66175598 | 983 | __weak void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 984 | { |
mbed_official | 237:f3da66175598 | 985 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 986 | the HAL_I2S_RxCpltCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 987 | */ |
mbed_official | 237:f3da66175598 | 988 | } |
mbed_official | 237:f3da66175598 | 989 | |
mbed_official | 237:f3da66175598 | 990 | /** |
mbed_official | 237:f3da66175598 | 991 | * @brief I2S error callbacks |
mbed_official | 375:3d36234a1087 | 992 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 993 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 994 | * @retval None |
mbed_official | 237:f3da66175598 | 995 | */ |
mbed_official | 237:f3da66175598 | 996 | __weak void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 997 | { |
mbed_official | 237:f3da66175598 | 998 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 999 | the HAL_I2S_ErrorCallback could be implemented in the user file |
mbed_official | 237:f3da66175598 | 1000 | */ |
mbed_official | 237:f3da66175598 | 1001 | } |
mbed_official | 237:f3da66175598 | 1002 | |
mbed_official | 237:f3da66175598 | 1003 | /** |
mbed_official | 237:f3da66175598 | 1004 | * @} |
mbed_official | 237:f3da66175598 | 1005 | */ |
mbed_official | 237:f3da66175598 | 1006 | |
mbed_official | 375:3d36234a1087 | 1007 | /** @defgroup I2S_Exported_Functions_Group3 Peripheral State and Errors functions |
mbed_official | 237:f3da66175598 | 1008 | * @brief Peripheral State functions |
mbed_official | 237:f3da66175598 | 1009 | * |
mbed_official | 237:f3da66175598 | 1010 | @verbatim |
mbed_official | 237:f3da66175598 | 1011 | =============================================================================== |
mbed_official | 237:f3da66175598 | 1012 | ##### Peripheral State and Errors functions ##### |
mbed_official | 237:f3da66175598 | 1013 | =============================================================================== |
mbed_official | 237:f3da66175598 | 1014 | [..] |
mbed_official | 375:3d36234a1087 | 1015 | This subsection permits to get in run-time the status of the peripheral |
mbed_official | 237:f3da66175598 | 1016 | and the data flow. |
mbed_official | 237:f3da66175598 | 1017 | |
mbed_official | 237:f3da66175598 | 1018 | @endverbatim |
mbed_official | 237:f3da66175598 | 1019 | * @{ |
mbed_official | 237:f3da66175598 | 1020 | */ |
mbed_official | 237:f3da66175598 | 1021 | |
mbed_official | 237:f3da66175598 | 1022 | /** |
mbed_official | 237:f3da66175598 | 1023 | * @brief Return the I2S state |
mbed_official | 375:3d36234a1087 | 1024 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 1025 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 1026 | * @retval HAL state |
mbed_official | 237:f3da66175598 | 1027 | */ |
mbed_official | 237:f3da66175598 | 1028 | HAL_I2S_StateTypeDef HAL_I2S_GetState(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 1029 | { |
mbed_official | 237:f3da66175598 | 1030 | return hi2s->State; |
mbed_official | 237:f3da66175598 | 1031 | } |
mbed_official | 237:f3da66175598 | 1032 | |
mbed_official | 237:f3da66175598 | 1033 | /** |
mbed_official | 237:f3da66175598 | 1034 | * @brief Return the I2S error code |
mbed_official | 375:3d36234a1087 | 1035 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 1036 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 1037 | * @retval I2S Error Code |
mbed_official | 237:f3da66175598 | 1038 | */ |
mbed_official | 237:f3da66175598 | 1039 | HAL_I2S_ErrorTypeDef HAL_I2S_GetError(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 1040 | { |
mbed_official | 237:f3da66175598 | 1041 | return hi2s->ErrorCode; |
mbed_official | 237:f3da66175598 | 1042 | } |
mbed_official | 237:f3da66175598 | 1043 | /** |
mbed_official | 237:f3da66175598 | 1044 | * @} |
mbed_official | 237:f3da66175598 | 1045 | */ |
mbed_official | 237:f3da66175598 | 1046 | |
mbed_official | 237:f3da66175598 | 1047 | /** |
mbed_official | 237:f3da66175598 | 1048 | * @} |
mbed_official | 237:f3da66175598 | 1049 | */ |
mbed_official | 237:f3da66175598 | 1050 | |
mbed_official | 375:3d36234a1087 | 1051 | /** @addtogroup I2S_Private_Functions I2S Private Functions |
mbed_official | 375:3d36234a1087 | 1052 | * @{ |
mbed_official | 375:3d36234a1087 | 1053 | */ |
mbed_official | 237:f3da66175598 | 1054 | /** |
mbed_official | 237:f3da66175598 | 1055 | * @brief DMA I2S transmit process complete callback |
mbed_official | 375:3d36234a1087 | 1056 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 1057 | * the configuration information for the specified DMA module. |
mbed_official | 237:f3da66175598 | 1058 | * @retval None |
mbed_official | 237:f3da66175598 | 1059 | */ |
mbed_official | 237:f3da66175598 | 1060 | static void I2S_DMATxCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 1061 | { |
mbed_official | 237:f3da66175598 | 1062 | I2S_HandleTypeDef* hi2s = ( I2S_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 237:f3da66175598 | 1063 | |
mbed_official | 237:f3da66175598 | 1064 | /* Disable Tx DMA Request */ |
mbed_official | 237:f3da66175598 | 1065 | hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_TXDMAEN); |
mbed_official | 237:f3da66175598 | 1066 | |
mbed_official | 237:f3da66175598 | 1067 | hi2s->TxXferCount = 0; |
mbed_official | 237:f3da66175598 | 1068 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 1069 | |
mbed_official | 237:f3da66175598 | 1070 | HAL_I2S_TxCpltCallback(hi2s); |
mbed_official | 237:f3da66175598 | 1071 | } |
mbed_official | 237:f3da66175598 | 1072 | |
mbed_official | 237:f3da66175598 | 1073 | /** |
mbed_official | 237:f3da66175598 | 1074 | * @brief DMA I2S transmit process half complete callback |
mbed_official | 375:3d36234a1087 | 1075 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 1076 | * the configuration information for the specified DMA module. |
mbed_official | 237:f3da66175598 | 1077 | * @retval None |
mbed_official | 237:f3da66175598 | 1078 | */ |
mbed_official | 237:f3da66175598 | 1079 | static void I2S_DMATxHalfCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 1080 | { |
mbed_official | 237:f3da66175598 | 1081 | I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 237:f3da66175598 | 1082 | |
mbed_official | 237:f3da66175598 | 1083 | HAL_I2S_TxHalfCpltCallback(hi2s); |
mbed_official | 237:f3da66175598 | 1084 | } |
mbed_official | 237:f3da66175598 | 1085 | |
mbed_official | 237:f3da66175598 | 1086 | /** |
mbed_official | 237:f3da66175598 | 1087 | * @brief DMA I2S receive process complete callback |
mbed_official | 375:3d36234a1087 | 1088 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 1089 | * the configuration information for the specified DMA module. |
mbed_official | 237:f3da66175598 | 1090 | * @retval None |
mbed_official | 237:f3da66175598 | 1091 | */ |
mbed_official | 237:f3da66175598 | 1092 | static void I2S_DMARxCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 1093 | { |
mbed_official | 237:f3da66175598 | 1094 | I2S_HandleTypeDef* hi2s = ( I2S_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 237:f3da66175598 | 1095 | |
mbed_official | 237:f3da66175598 | 1096 | /* Disable Rx DMA Request */ |
mbed_official | 237:f3da66175598 | 1097 | hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_RXDMAEN); |
mbed_official | 237:f3da66175598 | 1098 | hi2s->RxXferCount = 0; |
mbed_official | 237:f3da66175598 | 1099 | |
mbed_official | 237:f3da66175598 | 1100 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 1101 | HAL_I2S_RxCpltCallback(hi2s); |
mbed_official | 237:f3da66175598 | 1102 | } |
mbed_official | 237:f3da66175598 | 1103 | |
mbed_official | 237:f3da66175598 | 1104 | /** |
mbed_official | 237:f3da66175598 | 1105 | * @brief DMA I2S receive process half complete callback |
mbed_official | 375:3d36234a1087 | 1106 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 1107 | * the configuration information for the specified DMA module. |
mbed_official | 237:f3da66175598 | 1108 | * @retval None |
mbed_official | 237:f3da66175598 | 1109 | */ |
mbed_official | 237:f3da66175598 | 1110 | static void I2S_DMARxHalfCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 1111 | { |
mbed_official | 237:f3da66175598 | 1112 | I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 237:f3da66175598 | 1113 | |
mbed_official | 237:f3da66175598 | 1114 | HAL_I2S_RxHalfCpltCallback(hi2s); |
mbed_official | 237:f3da66175598 | 1115 | } |
mbed_official | 237:f3da66175598 | 1116 | |
mbed_official | 237:f3da66175598 | 1117 | /** |
mbed_official | 237:f3da66175598 | 1118 | * @brief DMA I2S communication error callback |
mbed_official | 375:3d36234a1087 | 1119 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 1120 | * the configuration information for the specified DMA module. |
mbed_official | 237:f3da66175598 | 1121 | * @retval None |
mbed_official | 237:f3da66175598 | 1122 | */ |
mbed_official | 237:f3da66175598 | 1123 | static void I2S_DMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 1124 | { |
mbed_official | 237:f3da66175598 | 1125 | I2S_HandleTypeDef* hi2s = ( I2S_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 237:f3da66175598 | 1126 | |
mbed_official | 237:f3da66175598 | 1127 | /* Disable Rx and Tx DMA Request */ |
mbed_official | 237:f3da66175598 | 1128 | hi2s->Instance->CR2 &= (uint32_t)(~(SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN)); |
mbed_official | 237:f3da66175598 | 1129 | hi2s->TxXferCount = 0; |
mbed_official | 237:f3da66175598 | 1130 | hi2s->RxXferCount = 0; |
mbed_official | 237:f3da66175598 | 1131 | |
mbed_official | 237:f3da66175598 | 1132 | hi2s->State= HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 1133 | |
mbed_official | 237:f3da66175598 | 1134 | /* Set the error code and execute error callback*/ |
mbed_official | 237:f3da66175598 | 1135 | hi2s->ErrorCode |= HAL_I2S_ERROR_DMA; |
mbed_official | 237:f3da66175598 | 1136 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 237:f3da66175598 | 1137 | } |
mbed_official | 237:f3da66175598 | 1138 | |
mbed_official | 237:f3da66175598 | 1139 | /** |
mbed_official | 237:f3da66175598 | 1140 | * @brief Transmit an amount of data in non-blocking mode with Interrupt |
mbed_official | 375:3d36234a1087 | 1141 | * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains |
mbed_official | 375:3d36234a1087 | 1142 | * the configuration information for I2S module |
mbed_official | 237:f3da66175598 | 1143 | * @retval None |
mbed_official | 237:f3da66175598 | 1144 | */ |
mbed_official | 237:f3da66175598 | 1145 | static void I2S_Transmit_IT(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 1146 | { |
mbed_official | 237:f3da66175598 | 1147 | /* Transmit data */ |
mbed_official | 237:f3da66175598 | 1148 | hi2s->Instance->DR = (*hi2s->pTxBuffPtr++); |
mbed_official | 237:f3da66175598 | 1149 | hi2s->TxXferCount--; |
mbed_official | 237:f3da66175598 | 1150 | |
mbed_official | 237:f3da66175598 | 1151 | if(hi2s->TxXferCount == 0) |
mbed_official | 237:f3da66175598 | 1152 | { |
mbed_official | 237:f3da66175598 | 1153 | /* Disable TXE and ERR interrupt */ |
mbed_official | 237:f3da66175598 | 1154 | __HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_ERR)); |
mbed_official | 375:3d36234a1087 | 1155 | |
mbed_official | 237:f3da66175598 | 1156 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 1157 | HAL_I2S_TxCpltCallback(hi2s); |
mbed_official | 237:f3da66175598 | 1158 | } |
mbed_official | 237:f3da66175598 | 1159 | } |
mbed_official | 237:f3da66175598 | 1160 | |
mbed_official | 237:f3da66175598 | 1161 | /** |
mbed_official | 237:f3da66175598 | 1162 | * @brief Receive an amount of data in non-blocking mode with Interrupt |
mbed_official | 237:f3da66175598 | 1163 | * @param hi2s: I2S handle |
mbed_official | 237:f3da66175598 | 1164 | * @retval None |
mbed_official | 237:f3da66175598 | 1165 | */ |
mbed_official | 237:f3da66175598 | 1166 | static void I2S_Receive_IT(I2S_HandleTypeDef *hi2s) |
mbed_official | 237:f3da66175598 | 1167 | { |
mbed_official | 237:f3da66175598 | 1168 | /* Receive data */ |
mbed_official | 237:f3da66175598 | 1169 | (*hi2s->pRxBuffPtr++) = hi2s->Instance->DR; |
mbed_official | 237:f3da66175598 | 1170 | hi2s->RxXferCount--; |
mbed_official | 237:f3da66175598 | 1171 | |
mbed_official | 237:f3da66175598 | 1172 | if(hi2s->RxXferCount == 0) |
mbed_official | 237:f3da66175598 | 1173 | { |
mbed_official | 237:f3da66175598 | 1174 | /* Disable RXNE and ERR interrupt */ |
mbed_official | 237:f3da66175598 | 1175 | __HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_ERR)); |
mbed_official | 375:3d36234a1087 | 1176 | |
mbed_official | 237:f3da66175598 | 1177 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 237:f3da66175598 | 1178 | HAL_I2S_RxCpltCallback(hi2s); |
mbed_official | 237:f3da66175598 | 1179 | } |
mbed_official | 237:f3da66175598 | 1180 | } |
mbed_official | 375:3d36234a1087 | 1181 | /** |
mbed_official | 375:3d36234a1087 | 1182 | * @} |
mbed_official | 375:3d36234a1087 | 1183 | */ |
mbed_official | 237:f3da66175598 | 1184 | |
mbed_official | 375:3d36234a1087 | 1185 | #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */ |
mbed_official | 375:3d36234a1087 | 1186 | /* STM32F302xC || STM32F303xC || STM32F358xx || */ |
mbed_official | 375:3d36234a1087 | 1187 | /* STM32F301x8 || STM32F302x8 || STM32F318xx || */ |
mbed_official | 375:3d36234a1087 | 1188 | /* STM32F373xC || STM32F378xx */ |
mbed_official | 237:f3da66175598 | 1189 | |
mbed_official | 237:f3da66175598 | 1190 | #endif /* HAL_I2S_MODULE_ENABLED */ |
mbed_official | 237:f3da66175598 | 1191 | /** |
mbed_official | 237:f3da66175598 | 1192 | * @} |
mbed_official | 237:f3da66175598 | 1193 | */ |
mbed_official | 237:f3da66175598 | 1194 | |
mbed_official | 237:f3da66175598 | 1195 | /** |
mbed_official | 237:f3da66175598 | 1196 | * @} |
mbed_official | 237:f3da66175598 | 1197 | */ |
mbed_official | 237:f3da66175598 | 1198 | |
mbed_official | 237:f3da66175598 | 1199 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |