mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Mon Oct 27 09:45:07 2014 +0000
Revision:
369:2e96f1b71984
Parent:
226:b062af740e40
Synchronized with git revision 2d1f64de28cfb25c0e602532e3ce5ad1d9accbed

Full URL: https://github.com/mbedmicro/mbed/commit/2d1f64de28cfb25c0e602532e3ce5ad1d9accbed/

CMSIS: NUCLEO_F401RE - Update STM32Cube driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 87:085cde657901 1 /**
mbed_official 87:085cde657901 2 ******************************************************************************
mbed_official 87:085cde657901 3 * @file stm32f4xx_hal_i2s_ex.c
mbed_official 87:085cde657901 4 * @author MCD Application Team
mbed_official 369:2e96f1b71984 5 * @version V1.1.0
mbed_official 369:2e96f1b71984 6 * @date 19-June-2014
mbed_official 87:085cde657901 7 * @brief I2S HAL module driver.
mbed_official 87:085cde657901 8 * This file provides firmware functions to manage the following
mbed_official 87:085cde657901 9 * functionalities of I2S extension peripheral:
mbed_official 87:085cde657901 10 * + Extension features Functions
mbed_official 87:085cde657901 11 *
mbed_official 87:085cde657901 12 @verbatim
mbed_official 87:085cde657901 13 ==============================================================================
mbed_official 87:085cde657901 14 ##### I2S Extension features #####
mbed_official 87:085cde657901 15 ==============================================================================
mbed_official 87:085cde657901 16 [..]
mbed_official 87:085cde657901 17 (#) In I2S full duplex mode, each SPI peripheral is able to manage sending and receiving
mbed_official 87:085cde657901 18 data simultaneously using two data lines. Each SPI peripheral has an extended block
mbed_official 226:b062af740e40 19 called I2Sxext (i.e I2S2ext for SPI2 and I2S3ext for SPI3).
mbed_official 87:085cde657901 20 (#) The extension block is not a full SPI IP, it is used only as I2S slave to
mbed_official 87:085cde657901 21 implement full duplex mode. The extension block uses the same clock sources
mbed_official 87:085cde657901 22 as its master.
mbed_official 87:085cde657901 23
mbed_official 87:085cde657901 24 (#) Both I2Sx and I2Sx_ext can be configured as transmitters or receivers.
mbed_official 87:085cde657901 25
mbed_official 226:b062af740e40 26 [..]
mbed_official 226:b062af740e40 27 (@) Only I2Sx can deliver SCK and WS to I2Sx_ext in full duplex mode, where
mbed_official 87:085cde657901 28 I2Sx can be I2S2 or I2S3.
mbed_official 87:085cde657901 29
mbed_official 87:085cde657901 30 ##### How to use this driver #####
mbed_official 87:085cde657901 31 ===============================================================================
mbed_official 87:085cde657901 32 [..]
mbed_official 226:b062af740e40 33 Three operation modes are available within this driver :
mbed_official 87:085cde657901 34
mbed_official 87:085cde657901 35 *** Polling mode IO operation ***
mbed_official 87:085cde657901 36 =================================
mbed_official 87:085cde657901 37 [..]
mbed_official 87:085cde657901 38 (+) Send and receive in the same time an amount of data in blocking mode using HAL_I2S_TransmitReceive()
mbed_official 87:085cde657901 39
mbed_official 87:085cde657901 40 *** Interrupt mode IO operation ***
mbed_official 87:085cde657901 41 ===================================
mbed_official 87:085cde657901 42 [..]
mbed_official 87:085cde657901 43 (+) Send and receive in the same time an amount of data in non blocking mode using HAL_I2S_TransmitReceive_IT()
mbed_official 87:085cde657901 44 (+) At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can
mbed_official 87:085cde657901 45 add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback
mbed_official 87:085cde657901 46 (+) At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can
mbed_official 87:085cde657901 47 add his own code by customization of function pointer HAL_I2S_TxCpltCallback
mbed_official 87:085cde657901 48 (+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can
mbed_official 87:085cde657901 49 add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback
mbed_official 87:085cde657901 50 (+) At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can
mbed_official 87:085cde657901 51 add his own code by customization of function pointer HAL_I2S_RxCpltCallback
mbed_official 87:085cde657901 52 (+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can
mbed_official 87:085cde657901 53 add his own code by customization of function pointer HAL_I2S_ErrorCallback
mbed_official 87:085cde657901 54
mbed_official 87:085cde657901 55 *** DMA mode IO operation ***
mbed_official 87:085cde657901 56 ==============================
mbed_official 87:085cde657901 57 [..]
mbed_official 87:085cde657901 58 (+) Send and receive an amount of data in non blocking mode (DMA) using HAL_I2S_TransmitReceive_DMA()
mbed_official 87:085cde657901 59 (+) At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can
mbed_official 87:085cde657901 60 add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback
mbed_official 87:085cde657901 61 (+) At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can
mbed_official 87:085cde657901 62 add his own code by customization of function pointer HAL_I2S_TxCpltCallback
mbed_official 87:085cde657901 63 (+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can
mbed_official 87:085cde657901 64 add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback
mbed_official 87:085cde657901 65 (+) At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can
mbed_official 87:085cde657901 66 add his own code by customization of function pointer HAL_I2S_RxCpltCallback
mbed_official 87:085cde657901 67 (+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can
mbed_official 87:085cde657901 68 add his own code by customization of function pointer HAL_I2S_ErrorCallback
mbed_official 87:085cde657901 69 (+) Pause the DMA Transfer using HAL_I2S_DMAPause()
mbed_official 87:085cde657901 70 (+) Resume the DMA Transfer using HAL_I2S_DMAResume()
mbed_official 87:085cde657901 71 (+) Stop the DMA Transfer using HAL_I2S_DMAStop()
mbed_official 87:085cde657901 72
mbed_official 87:085cde657901 73 @endverbatim
mbed_official 87:085cde657901 74 ******************************************************************************
mbed_official 87:085cde657901 75 * @attention
mbed_official 87:085cde657901 76 *
mbed_official 87:085cde657901 77 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 87:085cde657901 78 *
mbed_official 87:085cde657901 79 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 87:085cde657901 80 * are permitted provided that the following conditions are met:
mbed_official 87:085cde657901 81 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 87:085cde657901 82 * this list of conditions and the following disclaimer.
mbed_official 87:085cde657901 83 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 87:085cde657901 84 * this list of conditions and the following disclaimer in the documentation
mbed_official 87:085cde657901 85 * and/or other materials provided with the distribution.
mbed_official 87:085cde657901 86 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 87:085cde657901 87 * may be used to endorse or promote products derived from this software
mbed_official 87:085cde657901 88 * without specific prior written permission.
mbed_official 87:085cde657901 89 *
mbed_official 87:085cde657901 90 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 87:085cde657901 91 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 87:085cde657901 92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 87:085cde657901 93 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 87:085cde657901 94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 87:085cde657901 95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 87:085cde657901 96 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 87:085cde657901 97 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 87:085cde657901 98 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 87:085cde657901 99 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 87:085cde657901 100 *
mbed_official 87:085cde657901 101 ******************************************************************************
mbed_official 87:085cde657901 102 */
mbed_official 87:085cde657901 103
mbed_official 87:085cde657901 104 /* Includes ------------------------------------------------------------------*/
mbed_official 87:085cde657901 105 #include "stm32f4xx_hal.h"
mbed_official 87:085cde657901 106
mbed_official 87:085cde657901 107 /** @addtogroup STM32F4xx_HAL_Driver
mbed_official 87:085cde657901 108 * @{
mbed_official 87:085cde657901 109 */
mbed_official 87:085cde657901 110
mbed_official 87:085cde657901 111 /** @defgroup I2SEx
mbed_official 87:085cde657901 112 * @brief I2S HAL module driver
mbed_official 87:085cde657901 113 * @{
mbed_official 87:085cde657901 114 */
mbed_official 87:085cde657901 115
mbed_official 87:085cde657901 116 #ifdef HAL_I2S_MODULE_ENABLED
mbed_official 87:085cde657901 117
mbed_official 87:085cde657901 118 /* Private typedef -----------------------------------------------------------*/
mbed_official 87:085cde657901 119 /* Private define ------------------------------------------------------------*/
mbed_official 87:085cde657901 120 /* Private macro -------------------------------------------------------------*/
mbed_official 87:085cde657901 121 /* Private variables ---------------------------------------------------------*/
mbed_official 87:085cde657901 122 /* Private function prototypes -----------------------------------------------*/
mbed_official 87:085cde657901 123 /* Private functions ---------------------------------------------------------*/
mbed_official 87:085cde657901 124
mbed_official 87:085cde657901 125 /** @defgroup I2SEx_Private_Functions
mbed_official 87:085cde657901 126 * @{
mbed_official 87:085cde657901 127 */
mbed_official 87:085cde657901 128
mbed_official 87:085cde657901 129 /** @defgroup I2SEx_Group1 Extension features functions
mbed_official 87:085cde657901 130 * @brief Extension features functions
mbed_official 87:085cde657901 131 *
mbed_official 87:085cde657901 132 @verbatim
mbed_official 87:085cde657901 133 ===============================================================================
mbed_official 87:085cde657901 134 ##### Extension features Functions #####
mbed_official 87:085cde657901 135 ===============================================================================
mbed_official 87:085cde657901 136 [..]
mbed_official 87:085cde657901 137 This subsection provides a set of functions allowing to manage the I2S data
mbed_official 87:085cde657901 138 transfers.
mbed_official 87:085cde657901 139
mbed_official 226:b062af740e40 140 (#) There are two modes of transfer:
mbed_official 87:085cde657901 141 (++) Blocking mode : The communication is performed in the polling mode.
mbed_official 87:085cde657901 142 The status of all data processing is returned by the same function
mbed_official 87:085cde657901 143 after finishing transfer.
mbed_official 87:085cde657901 144 (++) No-Blocking mode : The communication is performed using Interrupts
mbed_official 87:085cde657901 145 or DMA. These functions return the status of the transfer startup.
mbed_official 87:085cde657901 146 The end of the data processing will be indicated through the
mbed_official 87:085cde657901 147 dedicated I2S IRQ when using Interrupt mode or the DMA IRQ when
mbed_official 87:085cde657901 148 using DMA mode.
mbed_official 87:085cde657901 149
mbed_official 87:085cde657901 150 (#) Blocking mode functions are :
mbed_official 87:085cde657901 151 (++) HAL_I2S_TransmitReceive()
mbed_official 87:085cde657901 152
mbed_official 87:085cde657901 153 (#) No-Blocking mode functions with Interrupt are :
mbed_official 87:085cde657901 154 (++) HAL_I2S_TransmitReceive_IT()
mbed_official 87:085cde657901 155
mbed_official 87:085cde657901 156 (#) No-Blocking mode functions with DMA are :
mbed_official 87:085cde657901 157 (++) HAL_I2S_TransmitReceive_DMA()
mbed_official 87:085cde657901 158
mbed_official 226:b062af740e40 159 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
mbed_official 87:085cde657901 160 (++) HAL_I2S_TxCpltCallback()
mbed_official 87:085cde657901 161 (++) HAL_I2S_RxCpltCallback()
mbed_official 87:085cde657901 162 (++) HAL_I2S_ErrorCallback()
mbed_official 87:085cde657901 163
mbed_official 87:085cde657901 164 @endverbatim
mbed_official 87:085cde657901 165 * @{
mbed_official 87:085cde657901 166 */
mbed_official 87:085cde657901 167
mbed_official 87:085cde657901 168 /**
mbed_official 87:085cde657901 169 * @brief Full-Duplex Transmit/Receive data in blocking mode.
mbed_official 226:b062af740e40 170 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 171 * the configuration information for I2S module
mbed_official 87:085cde657901 172 * @param pTxData: a 16-bit pointer to the Transmit data buffer.
mbed_official 87:085cde657901 173 * @param pRxData: a 16-bit pointer to the Receive data buffer.
mbed_official 87:085cde657901 174 * @param Size: number of data sample to be sent:
mbed_official 87:085cde657901 175 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
mbed_official 87:085cde657901 176 * configuration phase, the Size parameter means the number of 16-bit data length
mbed_official 87:085cde657901 177 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
mbed_official 87:085cde657901 178 * the Size parameter means the number of 16-bit data length.
mbed_official 87:085cde657901 179 * @param Timeout: Timeout duration
mbed_official 87:085cde657901 180 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
mbed_official 87:085cde657901 181 * between Master and Slave(example: audio streaming).
mbed_official 87:085cde657901 182 * @retval HAL status
mbed_official 87:085cde657901 183 */
mbed_official 87:085cde657901 184 HAL_StatusTypeDef HAL_I2SEx_TransmitReceive(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData, uint16_t Size, uint32_t Timeout)
mbed_official 87:085cde657901 185 {
mbed_official 369:2e96f1b71984 186 uint32_t tickstart = 0;
mbed_official 369:2e96f1b71984 187 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 87:085cde657901 188
mbed_official 369:2e96f1b71984 189 if((pTxData == HAL_NULL ) || (pRxData == HAL_NULL ) || (Size == 0))
mbed_official 87:085cde657901 190 {
mbed_official 87:085cde657901 191 return HAL_ERROR;
mbed_official 87:085cde657901 192 }
mbed_official 87:085cde657901 193
mbed_official 87:085cde657901 194 /* Check the I2S State */
mbed_official 87:085cde657901 195 if(hi2s->State == HAL_I2S_STATE_READY)
mbed_official 87:085cde657901 196 {
mbed_official 87:085cde657901 197 tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 87:085cde657901 198 tmp2 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 87:085cde657901 199 /* Check the Data format: When a 16-bit data frame or a 16-bit data frame extended
mbed_official 87:085cde657901 200 is selected during the I2S configuration phase, the Size parameter means the number
mbed_official 87:085cde657901 201 of 16-bit data length in the transaction and when a 24-bit data frame or a 32-bit data
mbed_official 87:085cde657901 202 frame is selected the Size parameter means the number of 16-bit data length. */
mbed_official 87:085cde657901 203 if((tmp1 == I2S_DATAFORMAT_24B)|| \
mbed_official 87:085cde657901 204 (tmp2 == I2S_DATAFORMAT_32B))
mbed_official 87:085cde657901 205 {
mbed_official 87:085cde657901 206 hi2s->TxXferSize = Size*2;
mbed_official 87:085cde657901 207 hi2s->TxXferCount = Size*2;
mbed_official 87:085cde657901 208 hi2s->RxXferSize = Size*2;
mbed_official 87:085cde657901 209 hi2s->RxXferCount = Size*2;
mbed_official 87:085cde657901 210 }
mbed_official 87:085cde657901 211 else
mbed_official 87:085cde657901 212 {
mbed_official 87:085cde657901 213 hi2s->TxXferSize = Size;
mbed_official 87:085cde657901 214 hi2s->TxXferCount = Size;
mbed_official 87:085cde657901 215 hi2s->RxXferSize = Size;
mbed_official 87:085cde657901 216 hi2s->RxXferCount = Size;
mbed_official 87:085cde657901 217 }
mbed_official 87:085cde657901 218
mbed_official 87:085cde657901 219 /* Process Locked */
mbed_official 87:085cde657901 220 __HAL_LOCK(hi2s);
mbed_official 87:085cde657901 221
mbed_official 87:085cde657901 222 /* Set the I2S State busy TX/RX */
mbed_official 87:085cde657901 223 hi2s->State = HAL_I2S_STATE_BUSY_TX_RX;
mbed_official 87:085cde657901 224
mbed_official 87:085cde657901 225 tmp1 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
mbed_official 87:085cde657901 226 tmp2 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
mbed_official 87:085cde657901 227 /* Check if the I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX Mode is selected */
mbed_official 87:085cde657901 228 if((tmp1 == I2S_MODE_MASTER_TX) || (tmp2 == I2S_MODE_SLAVE_TX))
mbed_official 87:085cde657901 229 {
mbed_official 87:085cde657901 230 /* Check if the I2S is already enabled: The I2S is kept enabled at the end of transaction
mbed_official 87:085cde657901 231 to avoid the clock de-synchronization between Master and Slave. */
mbed_official 87:085cde657901 232 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 87:085cde657901 233 {
mbed_official 87:085cde657901 234 /* Enable I2Sext(receiver) before enabling I2Sx peripheral */
mbed_official 87:085cde657901 235 I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
mbed_official 87:085cde657901 236
mbed_official 87:085cde657901 237 /* Enable I2Sx peripheral */
mbed_official 87:085cde657901 238 __HAL_I2S_ENABLE(hi2s);
mbed_official 87:085cde657901 239 }
mbed_official 87:085cde657901 240
mbed_official 87:085cde657901 241 while(hi2s->TxXferCount > 0)
mbed_official 87:085cde657901 242 {
mbed_official 87:085cde657901 243 /* Wait until TXE flag is set */
mbed_official 87:085cde657901 244 if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_TXE, RESET, Timeout) != HAL_OK)
mbed_official 87:085cde657901 245 {
mbed_official 87:085cde657901 246 return HAL_TIMEOUT;
mbed_official 87:085cde657901 247 }
mbed_official 87:085cde657901 248 hi2s->Instance->DR = (*pTxData++);
mbed_official 87:085cde657901 249
mbed_official 369:2e96f1b71984 250 /* Get tick */
mbed_official 369:2e96f1b71984 251 tickstart = HAL_GetTick();
mbed_official 369:2e96f1b71984 252
mbed_official 87:085cde657901 253 /* Wait until RXNE flag is set */
mbed_official 87:085cde657901 254 while((I2SxEXT(hi2s->Instance)->SR & SPI_SR_RXNE) != SPI_SR_RXNE)
mbed_official 87:085cde657901 255 {
mbed_official 87:085cde657901 256 if(Timeout != HAL_MAX_DELAY)
mbed_official 87:085cde657901 257 {
mbed_official 369:2e96f1b71984 258 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 87:085cde657901 259 {
mbed_official 87:085cde657901 260 /* Process Unlocked */
mbed_official 87:085cde657901 261 __HAL_UNLOCK(hi2s);
mbed_official 87:085cde657901 262
mbed_official 87:085cde657901 263 return HAL_TIMEOUT;
mbed_official 87:085cde657901 264 }
mbed_official 87:085cde657901 265 }
mbed_official 87:085cde657901 266 }
mbed_official 87:085cde657901 267 (*pRxData++) = I2SxEXT(hi2s->Instance)->DR;
mbed_official 87:085cde657901 268
mbed_official 87:085cde657901 269 hi2s->TxXferCount--;
mbed_official 87:085cde657901 270 hi2s->RxXferCount--;
mbed_official 87:085cde657901 271 }
mbed_official 87:085cde657901 272 }
mbed_official 87:085cde657901 273 /* The I2S_MODE_MASTER_RX or I2S_MODE_SLAVE_RX Mode is selected */
mbed_official 87:085cde657901 274 else
mbed_official 87:085cde657901 275 {
mbed_official 87:085cde657901 276 /* Check if the I2S is already enabled */
mbed_official 87:085cde657901 277 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 87:085cde657901 278 {
mbed_official 87:085cde657901 279 /* Enable I2S peripheral before the I2Sext*/
mbed_official 87:085cde657901 280 __HAL_I2S_ENABLE(hi2s);
mbed_official 87:085cde657901 281
mbed_official 87:085cde657901 282 /* Enable I2Sext(transmitter) after enabling I2Sx peripheral */
mbed_official 87:085cde657901 283 I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
mbed_official 87:085cde657901 284 }
mbed_official 87:085cde657901 285 else
mbed_official 87:085cde657901 286 {
mbed_official 87:085cde657901 287 /* Check if Master Receiver mode is selected */
mbed_official 87:085cde657901 288 if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX)
mbed_official 87:085cde657901 289 {
mbed_official 87:085cde657901 290 /* Clear the Overrun Flag by a read operation on the SPI_DR register followed by a read
mbed_official 87:085cde657901 291 access to the SPI_SR register. */
mbed_official 87:085cde657901 292 __HAL_I2S_CLEAR_OVRFLAG(hi2s);
mbed_official 87:085cde657901 293 }
mbed_official 87:085cde657901 294 }
mbed_official 87:085cde657901 295 while(hi2s->TxXferCount > 0)
mbed_official 87:085cde657901 296 {
mbed_official 369:2e96f1b71984 297 /* Get tick */
mbed_official 369:2e96f1b71984 298 tickstart = HAL_GetTick();
mbed_official 369:2e96f1b71984 299
mbed_official 87:085cde657901 300 /* Wait until TXE flag is set */
mbed_official 87:085cde657901 301 while((I2SxEXT(hi2s->Instance)->SR & SPI_SR_TXE) != SPI_SR_TXE)
mbed_official 87:085cde657901 302 {
mbed_official 87:085cde657901 303 if(Timeout != HAL_MAX_DELAY)
mbed_official 87:085cde657901 304 {
mbed_official 369:2e96f1b71984 305 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 87:085cde657901 306 {
mbed_official 87:085cde657901 307 /* Process Unlocked */
mbed_official 87:085cde657901 308 __HAL_UNLOCK(hi2s);
mbed_official 87:085cde657901 309
mbed_official 87:085cde657901 310 return HAL_TIMEOUT;
mbed_official 87:085cde657901 311 }
mbed_official 87:085cde657901 312 }
mbed_official 87:085cde657901 313 }
mbed_official 87:085cde657901 314 I2SxEXT(hi2s->Instance)->DR = (*pTxData++);
mbed_official 87:085cde657901 315
mbed_official 87:085cde657901 316 /* Wait until RXNE flag is set */
mbed_official 87:085cde657901 317 if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_RXNE, RESET, Timeout) != HAL_OK)
mbed_official 87:085cde657901 318 {
mbed_official 87:085cde657901 319 return HAL_TIMEOUT;
mbed_official 87:085cde657901 320 }
mbed_official 87:085cde657901 321 (*pRxData++) = hi2s->Instance->DR;
mbed_official 87:085cde657901 322
mbed_official 87:085cde657901 323 hi2s->TxXferCount--;
mbed_official 87:085cde657901 324 hi2s->RxXferCount--;
mbed_official 87:085cde657901 325 }
mbed_official 87:085cde657901 326 }
mbed_official 87:085cde657901 327
mbed_official 87:085cde657901 328 /* Set the I2S State ready */
mbed_official 87:085cde657901 329 hi2s->State = HAL_I2S_STATE_READY;
mbed_official 87:085cde657901 330
mbed_official 87:085cde657901 331 /* Process Unlocked */
mbed_official 87:085cde657901 332 __HAL_UNLOCK(hi2s);
mbed_official 87:085cde657901 333
mbed_official 87:085cde657901 334 return HAL_OK;
mbed_official 87:085cde657901 335 }
mbed_official 87:085cde657901 336 else
mbed_official 87:085cde657901 337 {
mbed_official 87:085cde657901 338 return HAL_BUSY;
mbed_official 87:085cde657901 339 }
mbed_official 87:085cde657901 340 }
mbed_official 87:085cde657901 341
mbed_official 87:085cde657901 342 /**
mbed_official 87:085cde657901 343 * @brief Full-Duplex Transmit/Receive data in non-blocking mode using Interrupt
mbed_official 226:b062af740e40 344 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 345 * the configuration information for I2S module
mbed_official 87:085cde657901 346 * @param pTxData: a 16-bit pointer to the Transmit data buffer.
mbed_official 87:085cde657901 347 * @param pRxData: a 16-bit pointer to the Receive data buffer.
mbed_official 87:085cde657901 348 * @param Size: number of data sample to be sent:
mbed_official 87:085cde657901 349 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
mbed_official 87:085cde657901 350 * configuration phase, the Size parameter means the number of 16-bit data length
mbed_official 87:085cde657901 351 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
mbed_official 87:085cde657901 352 * the Size parameter means the number of 16-bit data length.
mbed_official 87:085cde657901 353 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
mbed_official 87:085cde657901 354 * between Master and Slave(example: audio streaming).
mbed_official 87:085cde657901 355 * @retval HAL status
mbed_official 87:085cde657901 356 */
mbed_official 87:085cde657901 357 HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData, uint16_t Size)
mbed_official 87:085cde657901 358 {
mbed_official 87:085cde657901 359 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 87:085cde657901 360
mbed_official 87:085cde657901 361 if(hi2s->State == HAL_I2S_STATE_READY)
mbed_official 87:085cde657901 362 {
mbed_official 369:2e96f1b71984 363 if((pTxData == HAL_NULL ) || (pRxData == HAL_NULL ) || (Size == 0))
mbed_official 87:085cde657901 364 {
mbed_official 87:085cde657901 365 return HAL_ERROR;
mbed_official 87:085cde657901 366 }
mbed_official 87:085cde657901 367
mbed_official 87:085cde657901 368 hi2s->pTxBuffPtr = pTxData;
mbed_official 87:085cde657901 369 hi2s->pRxBuffPtr = pRxData;
mbed_official 87:085cde657901 370
mbed_official 87:085cde657901 371 tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 87:085cde657901 372 tmp2 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 87:085cde657901 373 /* Check the Data format: When a 16-bit data frame or a 16-bit data frame extended
mbed_official 87:085cde657901 374 is selected during the I2S configuration phase, the Size parameter means the number
mbed_official 87:085cde657901 375 of 16-bit data length in the transaction and when a 24-bit data frame or a 32-bit data
mbed_official 87:085cde657901 376 frame is selected the Size parameter means the number of 16-bit data length. */
mbed_official 87:085cde657901 377 if((tmp1 == I2S_DATAFORMAT_24B)||\
mbed_official 87:085cde657901 378 (tmp2 == I2S_DATAFORMAT_32B))
mbed_official 87:085cde657901 379 {
mbed_official 87:085cde657901 380 hi2s->TxXferSize = Size*2;
mbed_official 87:085cde657901 381 hi2s->TxXferCount = Size*2;
mbed_official 87:085cde657901 382 hi2s->RxXferSize = Size*2;
mbed_official 87:085cde657901 383 hi2s->RxXferCount = Size*2;
mbed_official 87:085cde657901 384 }
mbed_official 87:085cde657901 385 else
mbed_official 87:085cde657901 386 {
mbed_official 87:085cde657901 387 hi2s->TxXferSize = Size;
mbed_official 87:085cde657901 388 hi2s->TxXferCount = Size;
mbed_official 87:085cde657901 389 hi2s->RxXferSize = Size;
mbed_official 87:085cde657901 390 hi2s->RxXferCount = Size;
mbed_official 87:085cde657901 391 }
mbed_official 87:085cde657901 392
mbed_official 87:085cde657901 393 /* Process Locked */
mbed_official 87:085cde657901 394 __HAL_LOCK(hi2s);
mbed_official 87:085cde657901 395
mbed_official 87:085cde657901 396 hi2s->State = HAL_I2S_STATE_BUSY_TX_RX;
mbed_official 87:085cde657901 397 hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
mbed_official 87:085cde657901 398
mbed_official 87:085cde657901 399 tmp1 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
mbed_official 87:085cde657901 400 tmp2 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
mbed_official 87:085cde657901 401 /* Check if the I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX Mode is selected */
mbed_official 87:085cde657901 402 if((tmp1 == I2S_MODE_MASTER_TX) || (tmp2 == I2S_MODE_SLAVE_TX))
mbed_official 87:085cde657901 403 {
mbed_official 87:085cde657901 404 /* Enable I2Sext RXNE and ERR interrupts */
mbed_official 87:085cde657901 405 I2SxEXT(hi2s->Instance)->CR2 |= (I2S_IT_RXNE | I2S_IT_ERR);
mbed_official 87:085cde657901 406
mbed_official 87:085cde657901 407 /* Enable I2Sx TXE and ERR interrupts */
mbed_official 87:085cde657901 408 __HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_ERR));
mbed_official 87:085cde657901 409
mbed_official 87:085cde657901 410 /* Check if the I2S is already enabled */
mbed_official 87:085cde657901 411 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 87:085cde657901 412 {
mbed_official 87:085cde657901 413 /* Enable I2Sext(receiver) before enabling I2Sx peripheral */
mbed_official 87:085cde657901 414 I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
mbed_official 87:085cde657901 415
mbed_official 87:085cde657901 416 /* Enable I2Sx peripheral */
mbed_official 87:085cde657901 417 __HAL_I2S_ENABLE(hi2s);
mbed_official 87:085cde657901 418 }
mbed_official 87:085cde657901 419 }
mbed_official 87:085cde657901 420 /* The I2S_MODE_MASTER_RX or I2S_MODE_SLAVE_RX Mode is selected */
mbed_official 87:085cde657901 421 else
mbed_official 87:085cde657901 422 {
mbed_official 87:085cde657901 423 /* Enable I2Sext TXE and ERR interrupts */
mbed_official 87:085cde657901 424 I2SxEXT(hi2s->Instance)->CR2 |= (I2S_IT_TXE |I2S_IT_ERR);
mbed_official 87:085cde657901 425
mbed_official 87:085cde657901 426 /* Enable I2Sext RXNE and ERR interrupts */
mbed_official 87:085cde657901 427 __HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_ERR));
mbed_official 87:085cde657901 428
mbed_official 87:085cde657901 429 /* Check if the I2S is already enabled */
mbed_official 87:085cde657901 430 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 87:085cde657901 431 {
mbed_official 87:085cde657901 432 /* Check if the I2S_MODE_MASTER_RX is selected */
mbed_official 87:085cde657901 433 if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX)
mbed_official 87:085cde657901 434 {
mbed_official 87:085cde657901 435 /* Prepare the First Data before enabling the I2S */
mbed_official 87:085cde657901 436 if(hi2s->TxXferCount != 0)
mbed_official 87:085cde657901 437 {
mbed_official 87:085cde657901 438 /* Transmit First data */
mbed_official 87:085cde657901 439 I2SxEXT(hi2s->Instance)->DR = (*hi2s->pTxBuffPtr++);
mbed_official 87:085cde657901 440 hi2s->TxXferCount--;
mbed_official 87:085cde657901 441
mbed_official 87:085cde657901 442 if(hi2s->TxXferCount == 0)
mbed_official 87:085cde657901 443 {
mbed_official 87:085cde657901 444 /* Disable I2Sext TXE interrupt */
mbed_official 87:085cde657901 445 I2SxEXT(hi2s->Instance)->CR2 &= ~I2S_IT_TXE;
mbed_official 87:085cde657901 446 }
mbed_official 87:085cde657901 447 }
mbed_official 87:085cde657901 448 }
mbed_official 87:085cde657901 449 /* Enable I2S peripheral */
mbed_official 87:085cde657901 450 __HAL_I2S_ENABLE(hi2s);
mbed_official 87:085cde657901 451
mbed_official 87:085cde657901 452 /* Enable I2Sext(transmitter) after enabling I2Sx peripheral */
mbed_official 87:085cde657901 453 I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
mbed_official 87:085cde657901 454 }
mbed_official 87:085cde657901 455 }
mbed_official 87:085cde657901 456 /* Process Unlocked */
mbed_official 87:085cde657901 457 __HAL_UNLOCK(hi2s);
mbed_official 87:085cde657901 458
mbed_official 87:085cde657901 459 return HAL_OK;
mbed_official 87:085cde657901 460 }
mbed_official 87:085cde657901 461 else
mbed_official 87:085cde657901 462 {
mbed_official 87:085cde657901 463 return HAL_BUSY;
mbed_official 87:085cde657901 464 }
mbed_official 87:085cde657901 465 }
mbed_official 87:085cde657901 466
mbed_official 87:085cde657901 467
mbed_official 87:085cde657901 468 /**
mbed_official 87:085cde657901 469 * @brief Full-Duplex Transmit/Receive data in non-blocking mode using DMA
mbed_official 226:b062af740e40 470 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 471 * the configuration information for I2S module
mbed_official 87:085cde657901 472 * @param pTxData: a 16-bit pointer to the Transmit data buffer.
mbed_official 87:085cde657901 473 * @param pRxData: a 16-bit pointer to the Receive data buffer.
mbed_official 87:085cde657901 474 * @param Size: number of data sample to be sent:
mbed_official 87:085cde657901 475 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
mbed_official 87:085cde657901 476 * configuration phase, the Size parameter means the number of 16-bit data length
mbed_official 87:085cde657901 477 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
mbed_official 87:085cde657901 478 * the Size parameter means the number of 16-bit data length.
mbed_official 87:085cde657901 479 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
mbed_official 87:085cde657901 480 * between Master and Slave(example: audio streaming).
mbed_official 87:085cde657901 481 * @retval HAL status
mbed_official 87:085cde657901 482 */
mbed_official 87:085cde657901 483 HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData, uint16_t Size)
mbed_official 87:085cde657901 484 {
mbed_official 87:085cde657901 485 uint32_t *tmp;
mbed_official 87:085cde657901 486 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 87:085cde657901 487
mbed_official 369:2e96f1b71984 488 if((pTxData == HAL_NULL ) || (pRxData == HAL_NULL ) || (Size == 0))
mbed_official 87:085cde657901 489 {
mbed_official 87:085cde657901 490 return HAL_ERROR;
mbed_official 87:085cde657901 491 }
mbed_official 87:085cde657901 492
mbed_official 87:085cde657901 493 if(hi2s->State == HAL_I2S_STATE_READY)
mbed_official 87:085cde657901 494 {
mbed_official 87:085cde657901 495 hi2s->pTxBuffPtr = pTxData;
mbed_official 87:085cde657901 496 hi2s->pRxBuffPtr = pRxData;
mbed_official 87:085cde657901 497
mbed_official 87:085cde657901 498 tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 87:085cde657901 499 tmp2 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 87:085cde657901 500 /* Check the Data format: When a 16-bit data frame or a 16-bit data frame extended
mbed_official 87:085cde657901 501 is selected during the I2S configuration phase, the Size parameter means the number
mbed_official 87:085cde657901 502 of 16-bit data length in the transaction and when a 24-bit data frame or a 32-bit data
mbed_official 87:085cde657901 503 frame is selected the Size parameter means the number of 16-bit data length. */
mbed_official 87:085cde657901 504 if((tmp1 == I2S_DATAFORMAT_24B)||\
mbed_official 87:085cde657901 505 (tmp2 == I2S_DATAFORMAT_32B))
mbed_official 87:085cde657901 506 {
mbed_official 87:085cde657901 507 hi2s->TxXferSize = Size*2;
mbed_official 87:085cde657901 508 hi2s->TxXferCount = Size*2;
mbed_official 87:085cde657901 509 hi2s->RxXferSize = Size*2;
mbed_official 87:085cde657901 510 hi2s->RxXferCount = Size*2;
mbed_official 87:085cde657901 511 }
mbed_official 87:085cde657901 512 else
mbed_official 87:085cde657901 513 {
mbed_official 87:085cde657901 514 hi2s->TxXferSize = Size;
mbed_official 87:085cde657901 515 hi2s->TxXferCount = Size;
mbed_official 87:085cde657901 516 hi2s->RxXferSize = Size;
mbed_official 87:085cde657901 517 hi2s->RxXferCount = Size;
mbed_official 87:085cde657901 518 }
mbed_official 87:085cde657901 519
mbed_official 87:085cde657901 520 /* Process Locked */
mbed_official 87:085cde657901 521 __HAL_LOCK(hi2s);
mbed_official 87:085cde657901 522
mbed_official 87:085cde657901 523 hi2s->State = HAL_I2S_STATE_BUSY_TX_RX;
mbed_official 87:085cde657901 524 hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
mbed_official 87:085cde657901 525
mbed_official 87:085cde657901 526 /* Set the I2S Rx DMA Half transfert complete callback */
mbed_official 87:085cde657901 527 hi2s->hdmarx->XferHalfCpltCallback = I2S_DMARxHalfCplt;
mbed_official 87:085cde657901 528
mbed_official 87:085cde657901 529 /* Set the I2S Rx DMA transfert complete callback */
mbed_official 87:085cde657901 530 hi2s->hdmarx->XferCpltCallback = I2S_DMARxCplt;
mbed_official 87:085cde657901 531
mbed_official 87:085cde657901 532 /* Set the I2S Rx DMA error callback */
mbed_official 87:085cde657901 533 hi2s->hdmarx->XferErrorCallback = I2S_DMAError;
mbed_official 87:085cde657901 534
mbed_official 87:085cde657901 535 /* Set the I2S Tx DMA Half transfert complete callback */
mbed_official 87:085cde657901 536 hi2s->hdmatx->XferHalfCpltCallback = I2S_DMATxHalfCplt;
mbed_official 87:085cde657901 537
mbed_official 87:085cde657901 538 /* Set the I2S Tx DMA transfert complete callback */
mbed_official 87:085cde657901 539 hi2s->hdmatx->XferCpltCallback = I2S_DMATxCplt;
mbed_official 87:085cde657901 540
mbed_official 87:085cde657901 541 /* Set the I2S Tx DMA error callback */
mbed_official 87:085cde657901 542 hi2s->hdmatx->XferErrorCallback = I2S_DMAError;
mbed_official 87:085cde657901 543
mbed_official 87:085cde657901 544 tmp1 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
mbed_official 87:085cde657901 545 tmp2 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
mbed_official 87:085cde657901 546 /* Check if the I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX Mode is selected */
mbed_official 87:085cde657901 547 if((tmp1 == I2S_MODE_MASTER_TX) || (tmp2 == I2S_MODE_SLAVE_TX))
mbed_official 87:085cde657901 548 {
mbed_official 87:085cde657901 549 /* Enable the Rx DMA Stream */
mbed_official 87:085cde657901 550 tmp = (uint32_t*)&pRxData;
mbed_official 87:085cde657901 551 HAL_DMA_Start_IT(hi2s->hdmarx, (uint32_t)&I2SxEXT(hi2s->Instance)->DR, *(uint32_t*)tmp, hi2s->RxXferSize);
mbed_official 87:085cde657901 552
mbed_official 87:085cde657901 553 /* Enable Rx DMA Request */
mbed_official 87:085cde657901 554 I2SxEXT(hi2s->Instance)->CR2 |= SPI_CR2_RXDMAEN;
mbed_official 87:085cde657901 555
mbed_official 87:085cde657901 556 /* Enable the Tx DMA Stream */
mbed_official 87:085cde657901 557 tmp = (uint32_t*)&pTxData;
mbed_official 87:085cde657901 558 HAL_DMA_Start_IT(hi2s->hdmatx, *(uint32_t*)tmp, (uint32_t)&hi2s->Instance->DR, hi2s->TxXferSize);
mbed_official 87:085cde657901 559
mbed_official 87:085cde657901 560 /* Enable Tx DMA Request */
mbed_official 87:085cde657901 561 hi2s->Instance->CR2 |= SPI_CR2_TXDMAEN;
mbed_official 87:085cde657901 562
mbed_official 87:085cde657901 563 /* Check if the I2S is already enabled */
mbed_official 87:085cde657901 564 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 87:085cde657901 565 {
mbed_official 87:085cde657901 566 /* Enable I2Sext(receiver) before enabling I2Sx peripheral */
mbed_official 87:085cde657901 567 I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
mbed_official 87:085cde657901 568
mbed_official 87:085cde657901 569 /* Enable I2S peripheral after the I2Sext */
mbed_official 87:085cde657901 570 __HAL_I2S_ENABLE(hi2s);
mbed_official 87:085cde657901 571 }
mbed_official 87:085cde657901 572 }
mbed_official 87:085cde657901 573 else
mbed_official 87:085cde657901 574 {
mbed_official 87:085cde657901 575 /* Enable the Tx DMA Stream */
mbed_official 87:085cde657901 576 tmp = (uint32_t*)&pTxData;
mbed_official 87:085cde657901 577 HAL_DMA_Start_IT(hi2s->hdmatx, *(uint32_t*)tmp, (uint32_t)&I2SxEXT(hi2s->Instance)->DR, hi2s->TxXferSize);
mbed_official 87:085cde657901 578
mbed_official 87:085cde657901 579 /* Enable Tx DMA Request */
mbed_official 87:085cde657901 580 I2SxEXT(hi2s->Instance)->CR2 |= SPI_CR2_TXDMAEN;
mbed_official 87:085cde657901 581
mbed_official 87:085cde657901 582 /* Enable the Rx DMA Stream */
mbed_official 87:085cde657901 583 tmp = (uint32_t*)&pRxData;
mbed_official 87:085cde657901 584 HAL_DMA_Start_IT(hi2s->hdmarx, (uint32_t)&hi2s->Instance->DR, *(uint32_t*)tmp, hi2s->RxXferSize);
mbed_official 87:085cde657901 585
mbed_official 87:085cde657901 586 /* Enable Rx DMA Request */
mbed_official 87:085cde657901 587 hi2s->Instance->CR2 |= SPI_CR2_RXDMAEN;
mbed_official 87:085cde657901 588
mbed_official 87:085cde657901 589 /* Check if the I2S is already enabled */
mbed_official 87:085cde657901 590 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 87:085cde657901 591 {
mbed_official 87:085cde657901 592 /* Enable I2S peripheral before the I2Sext */
mbed_official 87:085cde657901 593 __HAL_I2S_ENABLE(hi2s);
mbed_official 87:085cde657901 594
mbed_official 87:085cde657901 595 /* Enable I2Sext(transmitter) after enabling I2Sx peripheral */
mbed_official 87:085cde657901 596 I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
mbed_official 87:085cde657901 597 }
mbed_official 87:085cde657901 598 else
mbed_official 87:085cde657901 599 {
mbed_official 87:085cde657901 600 /* Check if Master Receiver mode is selected */
mbed_official 87:085cde657901 601 if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX)
mbed_official 87:085cde657901 602 {
mbed_official 87:085cde657901 603 /* Clear the Overrun Flag by a read operation on the SPI_DR register followed by a read
mbed_official 87:085cde657901 604 access to the SPI_SR register. */
mbed_official 87:085cde657901 605 __HAL_I2S_CLEAR_OVRFLAG(hi2s);
mbed_official 87:085cde657901 606 }
mbed_official 87:085cde657901 607 }
mbed_official 87:085cde657901 608 }
mbed_official 87:085cde657901 609
mbed_official 87:085cde657901 610 /* Process Unlocked */
mbed_official 87:085cde657901 611 __HAL_UNLOCK(hi2s);
mbed_official 87:085cde657901 612
mbed_official 87:085cde657901 613 return HAL_OK;
mbed_official 87:085cde657901 614 }
mbed_official 87:085cde657901 615 else
mbed_official 87:085cde657901 616 {
mbed_official 87:085cde657901 617 return HAL_BUSY;
mbed_official 87:085cde657901 618 }
mbed_official 87:085cde657901 619 }
mbed_official 87:085cde657901 620
mbed_official 87:085cde657901 621 /**
mbed_official 87:085cde657901 622 * @}
mbed_official 87:085cde657901 623 */
mbed_official 87:085cde657901 624
mbed_official 87:085cde657901 625 /**
mbed_official 87:085cde657901 626 * @brief Full-Duplex Transmit/Receive data in non-blocking mode using Interrupt
mbed_official 226:b062af740e40 627 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 226:b062af740e40 628 * the configuration information for I2S module
mbed_official 87:085cde657901 629 * @retval HAL status
mbed_official 87:085cde657901 630 */
mbed_official 87:085cde657901 631 HAL_StatusTypeDef I2SEx_TransmitReceive_IT(I2S_HandleTypeDef *hi2s)
mbed_official 87:085cde657901 632 {
mbed_official 87:085cde657901 633 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 87:085cde657901 634
mbed_official 87:085cde657901 635 if(hi2s->State == HAL_I2S_STATE_BUSY_TX_RX)
mbed_official 87:085cde657901 636 {
mbed_official 87:085cde657901 637 /* Process Locked */
mbed_official 87:085cde657901 638 __HAL_LOCK(hi2s);
mbed_official 87:085cde657901 639
mbed_official 87:085cde657901 640 tmp1 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
mbed_official 87:085cde657901 641 tmp2 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
mbed_official 87:085cde657901 642 /* Check if the I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX Mode is selected */
mbed_official 87:085cde657901 643 if((tmp1 == I2S_MODE_MASTER_TX) || (tmp2 == I2S_MODE_SLAVE_TX))
mbed_official 87:085cde657901 644 {
mbed_official 87:085cde657901 645 if(hi2s->TxXferCount != 0)
mbed_official 87:085cde657901 646 {
mbed_official 87:085cde657901 647 if(__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_TXE) != RESET)
mbed_official 87:085cde657901 648 {
mbed_official 87:085cde657901 649 /* Transmit data */
mbed_official 87:085cde657901 650 hi2s->Instance->DR = (*hi2s->pTxBuffPtr++);
mbed_official 87:085cde657901 651 hi2s->TxXferCount--;
mbed_official 87:085cde657901 652
mbed_official 87:085cde657901 653 if(hi2s->TxXferCount == 0)
mbed_official 87:085cde657901 654 {
mbed_official 87:085cde657901 655 /* Disable TXE interrupt */
mbed_official 87:085cde657901 656 __HAL_I2S_DISABLE_IT(hi2s, I2S_IT_TXE);
mbed_official 87:085cde657901 657 }
mbed_official 87:085cde657901 658 }
mbed_official 87:085cde657901 659 }
mbed_official 87:085cde657901 660
mbed_official 87:085cde657901 661 if(hi2s->RxXferCount != 0)
mbed_official 87:085cde657901 662 {
mbed_official 87:085cde657901 663 if((I2SxEXT(hi2s->Instance)->SR & SPI_SR_RXNE) == SPI_SR_RXNE)
mbed_official 87:085cde657901 664 {
mbed_official 87:085cde657901 665 /* Receive data */
mbed_official 87:085cde657901 666 (*hi2s->pRxBuffPtr++) = I2SxEXT(hi2s->Instance)->DR;
mbed_official 87:085cde657901 667 hi2s->RxXferCount--;
mbed_official 87:085cde657901 668
mbed_official 87:085cde657901 669 if(hi2s->RxXferCount == 0)
mbed_official 87:085cde657901 670 {
mbed_official 87:085cde657901 671 /* Disable I2Sext RXNE interrupt */
mbed_official 87:085cde657901 672 I2SxEXT(hi2s->Instance)->CR2 &= ~I2S_IT_RXNE;
mbed_official 87:085cde657901 673 }
mbed_official 87:085cde657901 674 }
mbed_official 87:085cde657901 675 }
mbed_official 87:085cde657901 676 }
mbed_official 87:085cde657901 677 /* The I2S_MODE_MASTER_RX or I2S_MODE_SLAVE_RX Mode is selected */
mbed_official 87:085cde657901 678 else
mbed_official 87:085cde657901 679 {
mbed_official 87:085cde657901 680 if(hi2s->TxXferCount != 0)
mbed_official 87:085cde657901 681 {
mbed_official 87:085cde657901 682 if((I2SxEXT(hi2s->Instance)->SR & SPI_SR_TXE) == SPI_SR_TXE)
mbed_official 87:085cde657901 683 {
mbed_official 87:085cde657901 684 /* Transmit data */
mbed_official 87:085cde657901 685 I2SxEXT(hi2s->Instance)->DR = (*hi2s->pTxBuffPtr++);
mbed_official 87:085cde657901 686 hi2s->TxXferCount--;
mbed_official 87:085cde657901 687
mbed_official 87:085cde657901 688 if(hi2s->TxXferCount == 0)
mbed_official 87:085cde657901 689 {
mbed_official 87:085cde657901 690 /* Disable I2Sext TXE interrupt */
mbed_official 87:085cde657901 691 I2SxEXT(hi2s->Instance)->CR2 &= ~I2S_IT_TXE;
mbed_official 87:085cde657901 692
mbed_official 87:085cde657901 693 HAL_I2S_TxCpltCallback(hi2s);
mbed_official 87:085cde657901 694 }
mbed_official 87:085cde657901 695 }
mbed_official 87:085cde657901 696 }
mbed_official 87:085cde657901 697 if(hi2s->RxXferCount != 0)
mbed_official 87:085cde657901 698 {
mbed_official 87:085cde657901 699 if(__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_RXNE) != RESET)
mbed_official 87:085cde657901 700 {
mbed_official 87:085cde657901 701 /* Receive data */
mbed_official 87:085cde657901 702 (*hi2s->pRxBuffPtr++) = hi2s->Instance->DR;
mbed_official 87:085cde657901 703 hi2s->RxXferCount--;
mbed_official 87:085cde657901 704
mbed_official 87:085cde657901 705 if(hi2s->RxXferCount == 0)
mbed_official 87:085cde657901 706 {
mbed_official 87:085cde657901 707 /* Disable RXNE interrupt */
mbed_official 87:085cde657901 708 __HAL_I2S_DISABLE_IT(hi2s, I2S_IT_RXNE);
mbed_official 87:085cde657901 709
mbed_official 87:085cde657901 710 HAL_I2S_RxCpltCallback(hi2s);
mbed_official 87:085cde657901 711 }
mbed_official 87:085cde657901 712 }
mbed_official 87:085cde657901 713 }
mbed_official 87:085cde657901 714 }
mbed_official 87:085cde657901 715
mbed_official 87:085cde657901 716 tmp1 = hi2s->RxXferCount;
mbed_official 87:085cde657901 717 tmp2 = hi2s->TxXferCount;
mbed_official 87:085cde657901 718 if((tmp1 == 0) && (tmp2 == 0))
mbed_official 87:085cde657901 719 {
mbed_official 87:085cde657901 720 /* Disable I2Sx ERR interrupt */
mbed_official 87:085cde657901 721 __HAL_I2S_DISABLE_IT(hi2s, I2S_IT_ERR);
mbed_official 87:085cde657901 722 /* Disable I2Sext ERR interrupt */
mbed_official 87:085cde657901 723 I2SxEXT(hi2s->Instance)->CR2 &= ~I2S_IT_ERR;
mbed_official 87:085cde657901 724
mbed_official 87:085cde657901 725 hi2s->State = HAL_I2S_STATE_READY;
mbed_official 87:085cde657901 726 }
mbed_official 87:085cde657901 727
mbed_official 87:085cde657901 728 /* Process Unlocked */
mbed_official 87:085cde657901 729 __HAL_UNLOCK(hi2s);
mbed_official 87:085cde657901 730
mbed_official 87:085cde657901 731 return HAL_OK;
mbed_official 87:085cde657901 732 }
mbed_official 87:085cde657901 733 else
mbed_official 87:085cde657901 734 {
mbed_official 87:085cde657901 735 return HAL_BUSY;
mbed_official 87:085cde657901 736 }
mbed_official 87:085cde657901 737 }
mbed_official 87:085cde657901 738
mbed_official 87:085cde657901 739 /**
mbed_official 87:085cde657901 740 * @}
mbed_official 87:085cde657901 741 */
mbed_official 87:085cde657901 742
mbed_official 87:085cde657901 743 #endif /* HAL_I2S_MODULE_ENABLED */
mbed_official 87:085cde657901 744 /**
mbed_official 87:085cde657901 745 * @}
mbed_official 87:085cde657901 746 */
mbed_official 87:085cde657901 747
mbed_official 87:085cde657901 748 /**
mbed_official 87:085cde657901 749 * @}
mbed_official 87:085cde657901 750 */
mbed_official 87:085cde657901 751
mbed_official 87:085cde657901 752 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/