STM32H735xx HAL User Manual
stm32h7xx_hal_irda.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32h7xx_hal_irda.c
00004   * @author  MCD Application Team
00005   * @brief   IRDA HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of the IrDA (Infrared Data Association) Peripheral
00008   *          (IRDA)
00009   *           + Initialization and de-initialization functions
00010   *           + IO operation functions
00011   *           + Peripheral State and Errors functions
00012   *           + Peripheral Control functions
00013   *
00014   ******************************************************************************
00015   * @attention
00016   *
00017   * Copyright (c) 2017 STMicroelectronics.
00018   * All rights reserved.
00019   *
00020   * This software is licensed under terms that can be found in the LICENSE file
00021   * in the root directory of this software component.
00022   * If no LICENSE file comes with this software, it is provided AS-IS.
00023   *
00024   ******************************************************************************
00025   @verbatim
00026   ==============================================================================
00027                         ##### How to use this driver #####
00028   ==============================================================================
00029   [..]
00030     The IRDA HAL driver can be used as follows:
00031 
00032     (#) Declare a IRDA_HandleTypeDef handle structure (eg. IRDA_HandleTypeDef hirda).
00033     (#) Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API
00034         in setting the associated USART or UART in IRDA mode:
00035         (++) Enable the USARTx/UARTx interface clock.
00036         (++) USARTx/UARTx pins configuration:
00037             (+++) Enable the clock for the USARTx/UARTx GPIOs.
00038             (+++) Configure these USARTx/UARTx pins (TX as alternate function pull-up, RX as alternate function Input).
00039         (++) NVIC configuration if you need to use interrupt process (HAL_IRDA_Transmit_IT()
00040              and HAL_IRDA_Receive_IT() APIs):
00041             (+++) Configure the USARTx/UARTx interrupt priority.
00042             (+++) Enable the NVIC USARTx/UARTx IRQ handle.
00043             (+++) The specific IRDA interrupts (Transmission complete interrupt,
00044                   RXNE interrupt and Error Interrupts) will be managed using the macros
00045                   __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.
00046 
00047         (++) DMA Configuration if you need to use DMA process (HAL_IRDA_Transmit_DMA()
00048              and HAL_IRDA_Receive_DMA() APIs):
00049             (+++) Declare a DMA handle structure for the Tx/Rx channel.
00050             (+++) Enable the DMAx interface clock.
00051             (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
00052             (+++) Configure the DMA Tx/Rx channel.
00053             (+++) Associate the initialized DMA handle to the IRDA DMA Tx/Rx handle.
00054             (+++) Configure the priority and enable the NVIC for the transfer
00055                   complete interrupt on the DMA Tx/Rx channel.
00056 
00057     (#) Program the Baud Rate, Word Length and Parity and Mode(Receiver/Transmitter),
00058         the normal or low power mode and the clock prescaler in the hirda handle Init structure.
00059 
00060     (#) Initialize the IRDA registers by calling the HAL_IRDA_Init() API:
00061         (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
00062              by calling the customized HAL_IRDA_MspInit() API.
00063 
00064          -@@- The specific IRDA interrupts (Transmission complete interrupt,
00065              RXNE interrupt and Error Interrupts) will be managed using the macros
00066              __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.
00067 
00068     (#) Three operation modes are available within this driver :
00069 
00070      *** Polling mode IO operation ***
00071      =================================
00072      [..]
00073        (+) Send an amount of data in blocking mode using HAL_IRDA_Transmit()
00074        (+) Receive an amount of data in blocking mode using HAL_IRDA_Receive()
00075 
00076      *** Interrupt mode IO operation ***
00077      ===================================
00078      [..]
00079        (+) Send an amount of data in non-blocking mode using HAL_IRDA_Transmit_IT()
00080        (+) At transmission end of transfer HAL_IRDA_TxCpltCallback() is executed and user can
00081             add his own code by customization of function pointer HAL_IRDA_TxCpltCallback()
00082        (+) Receive an amount of data in non-blocking mode using HAL_IRDA_Receive_IT()
00083        (+) At reception end of transfer HAL_IRDA_RxCpltCallback() is executed and user can
00084             add his own code by customization of function pointer HAL_IRDA_RxCpltCallback()
00085        (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
00086             add his own code by customization of function pointer HAL_IRDA_ErrorCallback()
00087 
00088      *** DMA mode IO operation ***
00089      ==============================
00090      [..]
00091        (+) Send an amount of data in non-blocking mode (DMA) using HAL_IRDA_Transmit_DMA()
00092        (+) At transmission half of transfer HAL_IRDA_TxHalfCpltCallback() is executed and user can
00093             add his own code by customization of function pointer HAL_IRDA_TxHalfCpltCallback()
00094        (+) At transmission end of transfer HAL_IRDA_TxCpltCallback() is executed and user can
00095             add his own code by customization of function pointer HAL_IRDA_TxCpltCallback()
00096        (+) Receive an amount of data in non-blocking mode (DMA) using HAL_IRDA_Receive_DMA()
00097        (+) At reception half of transfer HAL_IRDA_RxHalfCpltCallback() is executed and user can
00098             add his own code by customization of function pointer HAL_IRDA_RxHalfCpltCallback()
00099        (+) At reception end of transfer HAL_IRDA_RxCpltCallback() is executed and user can
00100             add his own code by customization of function pointer HAL_IRDA_RxCpltCallback()
00101        (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
00102             add his own code by customization of function pointer HAL_IRDA_ErrorCallback()
00103 
00104      *** IRDA HAL driver macros list ***
00105      ====================================
00106      [..]
00107        Below the list of most used macros in IRDA HAL driver.
00108 
00109        (+) __HAL_IRDA_ENABLE: Enable the IRDA peripheral
00110        (+) __HAL_IRDA_DISABLE: Disable the IRDA peripheral
00111        (+) __HAL_IRDA_GET_FLAG : Check whether the specified IRDA flag is set or not
00112        (+) __HAL_IRDA_CLEAR_FLAG : Clear the specified IRDA pending flag
00113        (+) __HAL_IRDA_ENABLE_IT: Enable the specified IRDA interrupt
00114        (+) __HAL_IRDA_DISABLE_IT: Disable the specified IRDA interrupt
00115        (+) __HAL_IRDA_GET_IT_SOURCE: Check whether or not the specified IRDA interrupt is enabled
00116 
00117      [..]
00118        (@) You can refer to the IRDA HAL driver header file for more useful macros
00119 
00120     ##### Callback registration #####
00121     ==================================
00122 
00123     [..]
00124     The compilation define USE_HAL_IRDA_REGISTER_CALLBACKS when set to 1
00125     allows the user to configure dynamically the driver callbacks.
00126 
00127     [..]
00128     Use Function HAL_IRDA_RegisterCallback() to register a user callback.
00129     Function HAL_IRDA_RegisterCallback() allows to register following callbacks:
00130     (+) TxHalfCpltCallback        : Tx Half Complete Callback.
00131     (+) TxCpltCallback            : Tx Complete Callback.
00132     (+) RxHalfCpltCallback        : Rx Half Complete Callback.
00133     (+) RxCpltCallback            : Rx Complete Callback.
00134     (+) ErrorCallback             : Error Callback.
00135     (+) AbortCpltCallback         : Abort Complete Callback.
00136     (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback.
00137     (+) AbortReceiveCpltCallback  : Abort Receive Complete Callback.
00138     (+) MspInitCallback           : IRDA MspInit.
00139     (+) MspDeInitCallback         : IRDA MspDeInit.
00140     This function takes as parameters the HAL peripheral handle, the Callback ID
00141     and a pointer to the user callback function.
00142 
00143     [..]
00144     Use function HAL_IRDA_UnRegisterCallback() to reset a callback to the default
00145     weak (surcharged) function.
00146     HAL_IRDA_UnRegisterCallback() takes as parameters the HAL peripheral handle,
00147     and the Callback ID.
00148     This function allows to reset following callbacks:
00149     (+) TxHalfCpltCallback        : Tx Half Complete Callback.
00150     (+) TxCpltCallback            : Tx Complete Callback.
00151     (+) RxHalfCpltCallback        : Rx Half Complete Callback.
00152     (+) RxCpltCallback            : Rx Complete Callback.
00153     (+) ErrorCallback             : Error Callback.
00154     (+) AbortCpltCallback         : Abort Complete Callback.
00155     (+) AbortTransmitCpltCallback : Abort Transmit Complete Callback.
00156     (+) AbortReceiveCpltCallback  : Abort Receive Complete Callback.
00157     (+) MspInitCallback           : IRDA MspInit.
00158     (+) MspDeInitCallback         : IRDA MspDeInit.
00159 
00160     [..]
00161     By default, after the HAL_IRDA_Init() and when the state is HAL_IRDA_STATE_RESET
00162     all callbacks are set to the corresponding weak (surcharged) functions:
00163     examples HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxHalfCpltCallback().
00164     Exception done for MspInit and MspDeInit functions that are respectively
00165     reset to the legacy weak (surcharged) functions in the HAL_IRDA_Init()
00166     and HAL_IRDA_DeInit() only when these callbacks are null (not registered beforehand).
00167     If not, MspInit or MspDeInit are not null, the HAL_IRDA_Init() and HAL_IRDA_DeInit()
00168     keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
00169 
00170     [..]
00171     Callbacks can be registered/unregistered in HAL_IRDA_STATE_READY state only.
00172     Exception done MspInit/MspDeInit that can be registered/unregistered
00173     in HAL_IRDA_STATE_READY or HAL_IRDA_STATE_RESET state, thus registered (user)
00174     MspInit/DeInit callbacks can be used during the Init/DeInit.
00175     In that case first register the MspInit/MspDeInit user callbacks
00176     using HAL_IRDA_RegisterCallback() before calling HAL_IRDA_DeInit()
00177     or HAL_IRDA_Init() function.
00178 
00179     [..]
00180     When The compilation define USE_HAL_IRDA_REGISTER_CALLBACKS is set to 0 or
00181     not defined, the callback registration feature is not available
00182     and weak (surcharged) callbacks are used.
00183 
00184   @endverbatim
00185   ******************************************************************************
00186   */
00187 
00188 /* Includes ------------------------------------------------------------------*/
00189 #include "stm32h7xx_hal.h"
00190 
00191 /** @addtogroup STM32H7xx_HAL_Driver
00192   * @{
00193   */
00194 
00195 /** @defgroup IRDA IRDA
00196   * @brief HAL IRDA module driver
00197   * @{
00198   */
00199 
00200 #ifdef HAL_IRDA_MODULE_ENABLED
00201 
00202 /* Private typedef -----------------------------------------------------------*/
00203 /* Private define ------------------------------------------------------------*/
00204 /** @defgroup IRDA_Private_Constants IRDA Private Constants
00205   * @{
00206   */
00207 #define IRDA_TEACK_REACK_TIMEOUT            1000U                                   /*!< IRDA TX or RX enable acknowledge time-out value  */
00208 
00209 #define IRDA_CR1_FIELDS  ((uint32_t)(USART_CR1_M | USART_CR1_PCE \
00210                                      | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE))  /*!< UART or USART CR1 fields of parameters set by IRDA_SetConfig API */
00211 
00212 #define USART_BRR_MIN    0x10U        /*!< USART BRR minimum authorized value */
00213 
00214 #define USART_BRR_MAX    0x0000FFFFU  /*!< USART BRR maximum authorized value */
00215 /**
00216   * @}
00217   */
00218 
00219 /* Private macros ------------------------------------------------------------*/
00220 /** @defgroup IRDA_Private_Macros IRDA Private Macros
00221   * @{
00222   */
00223 /** @brief  BRR division operation to set BRR register in 16-bit oversampling mode.
00224   * @param  __PCLK__ IRDA clock source.
00225   * @param  __BAUD__ Baud rate set by the user.
00226   * @param  __PRESCALER__ IRDA clock prescaler value.
00227   * @retval Division result
00228   */
00229 #define IRDA_DIV_SAMPLING16(__PCLK__, __BAUD__, __PRESCALER__)  ((((__PCLK__)/IRDAPrescTable[(__PRESCALER__)])\
00230                                                                   + ((__BAUD__)/2U)) / (__BAUD__))
00231 /**
00232   * @}
00233   */
00234 
00235 /* Private variables ---------------------------------------------------------*/
00236 /* Private function prototypes -----------------------------------------------*/
00237 /** @addtogroup IRDA_Private_Functions
00238   * @{
00239   */
00240 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
00241 void IRDA_InitCallbacksToDefault(IRDA_HandleTypeDef *hirda);
00242 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
00243 static HAL_StatusTypeDef IRDA_SetConfig(IRDA_HandleTypeDef *hirda);
00244 static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda);
00245 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status,
00246                                                      uint32_t Tickstart, uint32_t Timeout);
00247 static void IRDA_EndTxTransfer(IRDA_HandleTypeDef *hirda);
00248 static void IRDA_EndRxTransfer(IRDA_HandleTypeDef *hirda);
00249 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
00250 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma);
00251 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
00252 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma);
00253 static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
00254 static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma);
00255 static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
00256 static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
00257 static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
00258 static void IRDA_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
00259 static void IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
00260 static void IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda);
00261 static void IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
00262 /**
00263   * @}
00264   */
00265 
00266 /* Exported functions --------------------------------------------------------*/
00267 
00268 /** @defgroup IRDA_Exported_Functions IRDA Exported Functions
00269   * @{
00270   */
00271 
00272 /** @defgroup IRDA_Exported_Functions_Group1 Initialization and de-initialization functions
00273   *  @brief    Initialization and Configuration functions
00274   *
00275 @verbatim
00276   ==============================================================================
00277               ##### Initialization and Configuration functions #####
00278   ==============================================================================
00279   [..]
00280   This subsection provides a set of functions allowing to initialize the USARTx
00281   in asynchronous IRDA mode.
00282   (+) For the asynchronous mode only these parameters can be configured:
00283       (++) Baud Rate
00284       (++) Word Length
00285       (++) Parity: If the parity is enabled, then the MSB bit of the data written
00286            in the data register is transmitted but is changed by the parity bit.
00287       (++) Power mode
00288       (++) Prescaler setting
00289       (++) Receiver/transmitter modes
00290 
00291   [..]
00292   The HAL_IRDA_Init() API follows the USART asynchronous configuration procedures
00293   (details for the procedures are available in reference manual).
00294 
00295 @endverbatim
00296 
00297   Depending on the frame length defined by the M1 and M0 bits (7-bit,
00298   8-bit or 9-bit), the possible IRDA frame formats are listed in the
00299   following table.
00300 
00301     Table 1. IRDA frame format.
00302     +-----------------------------------------------------------------------+
00303     |  M1 bit |  M0 bit |  PCE bit  |             IRDA frame                |
00304     |---------|---------|-----------|---------------------------------------|
00305     |    0    |    0    |    0      |    | SB |    8 bit data   | STB |     |
00306     |---------|---------|-----------|---------------------------------------|
00307     |    0    |    0    |    1      |    | SB | 7 bit data | PB | STB |     |
00308     |---------|---------|-----------|---------------------------------------|
00309     |    0    |    1    |    0      |    | SB |    9 bit data   | STB |     |
00310     |---------|---------|-----------|---------------------------------------|
00311     |    0    |    1    |    1      |    | SB | 8 bit data | PB | STB |     |
00312     |---------|---------|-----------|---------------------------------------|
00313     |    1    |    0    |    0      |    | SB |    7 bit data   | STB |     |
00314     |---------|---------|-----------|---------------------------------------|
00315     |    1    |    0    |    1      |    | SB | 6 bit data | PB | STB |     |
00316     +-----------------------------------------------------------------------+
00317 
00318   * @{
00319   */
00320 
00321 /**
00322   * @brief Initialize the IRDA mode according to the specified
00323   *        parameters in the IRDA_InitTypeDef and initialize the associated handle.
00324   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
00325   *               the configuration information for the specified IRDA module.
00326   * @retval HAL status
00327   */
00328 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
00329 {
00330   /* Check the IRDA handle allocation */
00331   if (hirda == NULL)
00332   {
00333     return HAL_ERROR;
00334   }
00335 
00336   /* Check the USART/UART associated to the IRDA handle */
00337   assert_param(IS_IRDA_INSTANCE(hirda->Instance));
00338 
00339   if (hirda->gState == HAL_IRDA_STATE_RESET)
00340   {
00341     /* Allocate lock resource and initialize it */
00342     hirda->Lock = HAL_UNLOCKED;
00343 
00344 #if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
00345     IRDA_InitCallbacksToDefault(hirda);
00346 
00347     if (hirda->MspInitCallback == NULL)
00348     {
00349       hirda->MspInitCallback = HAL_IRDA_MspInit;
00350     }
00351 
00352     /* Init the low level hardware */
00353     hirda->MspInitCallback(hirda);
00354 #else
00355     /* Init the low level hardware : GPIO, CLOCK */
00356     HAL_IRDA_MspInit(hirda);
00357 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
00358   }
00359 
00360   hirda->gState = HAL_IRDA_STATE_BUSY;
00361 
00362   /* Disable the Peripheral to update the configuration registers */
00363   __HAL_IRDA_DISABLE(hirda);
00364 
00365   /* Set the IRDA Communication parameters */
00366   if (IRDA_SetConfig(hirda) == HAL_ERROR)
00367   {
00368     return HAL_ERROR;
00369   }
00370 
00371   /* In IRDA mode, the following bits must be kept cleared:
00372   - LINEN, STOP and CLKEN bits in the USART_CR2 register,
00373   - SCEN and HDSEL bits in the USART_CR3 register.*/
00374   CLEAR_BIT(hirda->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP));
00375   CLEAR_BIT(hirda->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
00376 
00377   /* set the UART/USART in IRDA mode */
00378   hirda->Instance->CR3 |= USART_CR3_IREN;
00379 
00380   /* Enable the Peripheral */
00381   __HAL_IRDA_ENABLE(hirda);
00382 
00383   /* TEACK and/or REACK to check before moving hirda->gState and hirda->RxState to Ready */
00384   return (IRDA_CheckIdleState(hirda));
00385 }
00386 
00387 /**
00388   * @brief DeInitialize the IRDA peripheral.
00389   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
00390   *               the configuration information for the specified IRDA module.
00391   * @retval HAL status
00392   */
00393 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
00394 {
00395   /* Check the IRDA handle allocation */
00396   if (hirda == NULL)
00397   {
00398     return HAL_ERROR;
00399   }
00400 
00401   /* Check the USART/UART associated to the IRDA handle */
00402   assert_param(IS_IRDA_INSTANCE(hirda->Instance));
00403 
00404   hirda->gState = HAL_IRDA_STATE_BUSY;
00405 
00406   /* DeInit the low level hardware */
00407 #if USE_HAL_IRDA_REGISTER_CALLBACKS == 1
00408   if (hirda->MspDeInitCallback == NULL)
00409   {
00410     hirda->MspDeInitCallback = HAL_IRDA_MspDeInit;
00411   }
00412   /* DeInit the low level hardware */
00413   hirda->MspDeInitCallback(hirda);
00414 #else
00415   HAL_IRDA_MspDeInit(hirda);
00416 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
00417   /* Disable the Peripheral */
00418   __HAL_IRDA_DISABLE(hirda);
00419 
00420   hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
00421   hirda->gState    = HAL_IRDA_STATE_RESET;
00422   hirda->RxState   = HAL_IRDA_STATE_RESET;
00423 
00424   /* Process Unlock */
00425   __HAL_UNLOCK(hirda);
00426 
00427   return HAL_OK;
00428 }
00429 
00430 /**
00431   * @brief Initialize the IRDA MSP.
00432   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
00433   *               the configuration information for the specified IRDA module.
00434   * @retval None
00435   */
00436 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
00437 {
00438   /* Prevent unused argument(s) compilation warning */
00439   UNUSED(hirda);
00440 
00441   /* NOTE: This function should not be modified, when the callback is needed,
00442            the HAL_IRDA_MspInit can be implemented in the user file
00443    */
00444 }
00445 
00446 /**
00447   * @brief DeInitialize the IRDA MSP.
00448   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
00449   *               the configuration information for the specified IRDA module.
00450   * @retval None
00451   */
00452 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
00453 {
00454   /* Prevent unused argument(s) compilation warning */
00455   UNUSED(hirda);
00456 
00457   /* NOTE: This function should not be modified, when the callback is needed,
00458            the HAL_IRDA_MspDeInit can be implemented in the user file
00459    */
00460 }
00461 
00462 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
00463 /**
00464   * @brief  Register a User IRDA Callback
00465   *         To be used instead of the weak predefined callback
00466   * @param  hirda irda handle
00467   * @param  CallbackID ID of the callback to be registered
00468   *         This parameter can be one of the following values:
00469   *           @arg @ref HAL_IRDA_TX_HALFCOMPLETE_CB_ID Tx Half Complete Callback ID
00470   *           @arg @ref HAL_IRDA_TX_COMPLETE_CB_ID Tx Complete Callback ID
00471   *           @arg @ref HAL_IRDA_RX_HALFCOMPLETE_CB_ID Rx Half Complete Callback ID
00472   *           @arg @ref HAL_IRDA_RX_COMPLETE_CB_ID Rx Complete Callback ID
00473   *           @arg @ref HAL_IRDA_ERROR_CB_ID Error Callback ID
00474   *           @arg @ref HAL_IRDA_ABORT_COMPLETE_CB_ID Abort Complete Callback ID
00475   *           @arg @ref HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID Abort Transmit Complete Callback ID
00476   *           @arg @ref HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID Abort Receive Complete Callback ID
00477   *           @arg @ref HAL_IRDA_MSPINIT_CB_ID MspInit Callback ID
00478   *           @arg @ref HAL_IRDA_MSPDEINIT_CB_ID MspDeInit Callback ID
00479   * @param  pCallback pointer to the Callback function
00480   * @retval HAL status
00481   */
00482 HAL_StatusTypeDef HAL_IRDA_RegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID,
00483                                             pIRDA_CallbackTypeDef pCallback)
00484 {
00485   HAL_StatusTypeDef status = HAL_OK;
00486 
00487   if (pCallback == NULL)
00488   {
00489     /* Update the error code */
00490     hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
00491 
00492     return HAL_ERROR;
00493   }
00494   /* Process locked */
00495   __HAL_LOCK(hirda);
00496 
00497   if (hirda->gState == HAL_IRDA_STATE_READY)
00498   {
00499     switch (CallbackID)
00500     {
00501       case HAL_IRDA_TX_HALFCOMPLETE_CB_ID :
00502         hirda->TxHalfCpltCallback = pCallback;
00503         break;
00504 
00505       case HAL_IRDA_TX_COMPLETE_CB_ID :
00506         hirda->TxCpltCallback = pCallback;
00507         break;
00508 
00509       case HAL_IRDA_RX_HALFCOMPLETE_CB_ID :
00510         hirda->RxHalfCpltCallback = pCallback;
00511         break;
00512 
00513       case HAL_IRDA_RX_COMPLETE_CB_ID :
00514         hirda->RxCpltCallback = pCallback;
00515         break;
00516 
00517       case HAL_IRDA_ERROR_CB_ID :
00518         hirda->ErrorCallback = pCallback;
00519         break;
00520 
00521       case HAL_IRDA_ABORT_COMPLETE_CB_ID :
00522         hirda->AbortCpltCallback = pCallback;
00523         break;
00524 
00525       case HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID :
00526         hirda->AbortTransmitCpltCallback = pCallback;
00527         break;
00528 
00529       case HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID :
00530         hirda->AbortReceiveCpltCallback = pCallback;
00531         break;
00532 
00533       case HAL_IRDA_MSPINIT_CB_ID :
00534         hirda->MspInitCallback = pCallback;
00535         break;
00536 
00537       case HAL_IRDA_MSPDEINIT_CB_ID :
00538         hirda->MspDeInitCallback = pCallback;
00539         break;
00540 
00541       default :
00542         /* Update the error code */
00543         hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
00544 
00545         /* Return error status */
00546         status =  HAL_ERROR;
00547         break;
00548     }
00549   }
00550   else if (hirda->gState == HAL_IRDA_STATE_RESET)
00551   {
00552     switch (CallbackID)
00553     {
00554       case HAL_IRDA_MSPINIT_CB_ID :
00555         hirda->MspInitCallback = pCallback;
00556         break;
00557 
00558       case HAL_IRDA_MSPDEINIT_CB_ID :
00559         hirda->MspDeInitCallback = pCallback;
00560         break;
00561 
00562       default :
00563         /* Update the error code */
00564         hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
00565 
00566         /* Return error status */
00567         status =  HAL_ERROR;
00568         break;
00569     }
00570   }
00571   else
00572   {
00573     /* Update the error code */
00574     hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
00575 
00576     /* Return error status */
00577     status =  HAL_ERROR;
00578   }
00579 
00580   /* Release Lock */
00581   __HAL_UNLOCK(hirda);
00582 
00583   return status;
00584 }
00585 
00586 /**
00587   * @brief  Unregister an IRDA callback
00588   *         IRDA callback is redirected to the weak predefined callback
00589   * @param  hirda irda handle
00590   * @param  CallbackID ID of the callback to be unregistered
00591   *         This parameter can be one of the following values:
00592   *           @arg @ref HAL_IRDA_TX_HALFCOMPLETE_CB_ID Tx Half Complete Callback ID
00593   *           @arg @ref HAL_IRDA_TX_COMPLETE_CB_ID Tx Complete Callback ID
00594   *           @arg @ref HAL_IRDA_RX_HALFCOMPLETE_CB_ID Rx Half Complete Callback ID
00595   *           @arg @ref HAL_IRDA_RX_COMPLETE_CB_ID Rx Complete Callback ID
00596   *           @arg @ref HAL_IRDA_ERROR_CB_ID Error Callback ID
00597   *           @arg @ref HAL_IRDA_ABORT_COMPLETE_CB_ID Abort Complete Callback ID
00598   *           @arg @ref HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID Abort Transmit Complete Callback ID
00599   *           @arg @ref HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID Abort Receive Complete Callback ID
00600   *           @arg @ref HAL_IRDA_MSPINIT_CB_ID MspInit Callback ID
00601   *           @arg @ref HAL_IRDA_MSPDEINIT_CB_ID MspDeInit Callback ID
00602   * @retval HAL status
00603   */
00604 HAL_StatusTypeDef HAL_IRDA_UnRegisterCallback(IRDA_HandleTypeDef *hirda, HAL_IRDA_CallbackIDTypeDef CallbackID)
00605 {
00606   HAL_StatusTypeDef status = HAL_OK;
00607 
00608   /* Process locked */
00609   __HAL_LOCK(hirda);
00610 
00611   if (HAL_IRDA_STATE_READY == hirda->gState)
00612   {
00613     switch (CallbackID)
00614     {
00615       case HAL_IRDA_TX_HALFCOMPLETE_CB_ID :
00616         hirda->TxHalfCpltCallback = HAL_IRDA_TxHalfCpltCallback;               /* Legacy weak  TxHalfCpltCallback    */
00617         break;
00618 
00619       case HAL_IRDA_TX_COMPLETE_CB_ID :
00620         hirda->TxCpltCallback = HAL_IRDA_TxCpltCallback;                       /* Legacy weak TxCpltCallback         */
00621         break;
00622 
00623       case HAL_IRDA_RX_HALFCOMPLETE_CB_ID :
00624         hirda->RxHalfCpltCallback = HAL_IRDA_RxHalfCpltCallback;               /* Legacy weak RxHalfCpltCallback     */
00625         break;
00626 
00627       case HAL_IRDA_RX_COMPLETE_CB_ID :
00628         hirda->RxCpltCallback = HAL_IRDA_RxCpltCallback;                       /* Legacy weak RxCpltCallback         */
00629         break;
00630 
00631       case HAL_IRDA_ERROR_CB_ID :
00632         hirda->ErrorCallback = HAL_IRDA_ErrorCallback;                         /* Legacy weak ErrorCallback          */
00633         break;
00634 
00635       case HAL_IRDA_ABORT_COMPLETE_CB_ID :
00636         hirda->AbortCpltCallback = HAL_IRDA_AbortCpltCallback;                 /* Legacy weak AbortCpltCallback      */
00637         break;
00638 
00639       case HAL_IRDA_ABORT_TRANSMIT_COMPLETE_CB_ID :
00640         hirda->AbortTransmitCpltCallback = HAL_IRDA_AbortTransmitCpltCallback; /* Legacy weak
00641                                                                                   AbortTransmitCpltCallback          */
00642         break;
00643 
00644       case HAL_IRDA_ABORT_RECEIVE_COMPLETE_CB_ID :
00645         hirda->AbortReceiveCpltCallback = HAL_IRDA_AbortReceiveCpltCallback;   /* Legacy weak
00646                                                                                   AbortReceiveCpltCallback           */
00647         break;
00648 
00649       case HAL_IRDA_MSPINIT_CB_ID :
00650         hirda->MspInitCallback = HAL_IRDA_MspInit;                             /* Legacy weak MspInitCallback        */
00651         break;
00652 
00653       case HAL_IRDA_MSPDEINIT_CB_ID :
00654         hirda->MspDeInitCallback = HAL_IRDA_MspDeInit;                         /* Legacy weak MspDeInitCallback      */
00655         break;
00656 
00657       default :
00658         /* Update the error code */
00659         hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
00660 
00661         /* Return error status */
00662         status =  HAL_ERROR;
00663         break;
00664     }
00665   }
00666   else if (HAL_IRDA_STATE_RESET == hirda->gState)
00667   {
00668     switch (CallbackID)
00669     {
00670       case HAL_IRDA_MSPINIT_CB_ID :
00671         hirda->MspInitCallback = HAL_IRDA_MspInit;
00672         break;
00673 
00674       case HAL_IRDA_MSPDEINIT_CB_ID :
00675         hirda->MspDeInitCallback = HAL_IRDA_MspDeInit;
00676         break;
00677 
00678       default :
00679         /* Update the error code */
00680         hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
00681 
00682         /* Return error status */
00683         status =  HAL_ERROR;
00684         break;
00685     }
00686   }
00687   else
00688   {
00689     /* Update the error code */
00690     hirda->ErrorCode |= HAL_IRDA_ERROR_INVALID_CALLBACK;
00691 
00692     /* Return error status */
00693     status =  HAL_ERROR;
00694   }
00695 
00696   /* Release Lock */
00697   __HAL_UNLOCK(hirda);
00698 
00699   return status;
00700 }
00701 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
00702 
00703 /**
00704   * @}
00705   */
00706 
00707 /** @defgroup IRDA_Exported_Functions_Group2 IO operation functions
00708   *  @brief   IRDA Transmit and Receive functions
00709   *
00710 @verbatim
00711  ===============================================================================
00712                          ##### IO operation functions #####
00713  ===============================================================================
00714   [..]
00715     This subsection provides a set of functions allowing to manage the IRDA data transfers.
00716 
00717   [..]
00718     IrDA is a half duplex communication protocol. If the Transmitter is busy, any data
00719     on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver
00720     is busy, data on the TX from the USART to IrDA will not be encoded by IrDA.
00721     While receiving data, transmission should be avoided as the data to be transmitted
00722     could be corrupted.
00723 
00724   [..]
00725     (#) There are two modes of transfer:
00726         (++) Blocking mode: the communication is performed in polling mode.
00727              The HAL status of all data processing is returned by the same function
00728              after finishing transfer.
00729         (++) Non-Blocking mode: the communication is performed using Interrupts
00730              or DMA, these API's return the HAL status.
00731              The end of the data processing will be indicated through the
00732              dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when
00733              using DMA mode.
00734              The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks
00735              will be executed respectively at the end of the Transmit or Receive process
00736              The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected
00737 
00738     (#) Blocking mode APIs are :
00739         (++) HAL_IRDA_Transmit()
00740         (++) HAL_IRDA_Receive()
00741 
00742     (#) Non Blocking mode APIs with Interrupt are :
00743         (++) HAL_IRDA_Transmit_IT()
00744         (++) HAL_IRDA_Receive_IT()
00745         (++) HAL_IRDA_IRQHandler()
00746 
00747     (#) Non Blocking mode functions with DMA are :
00748         (++) HAL_IRDA_Transmit_DMA()
00749         (++) HAL_IRDA_Receive_DMA()
00750         (++) HAL_IRDA_DMAPause()
00751         (++) HAL_IRDA_DMAResume()
00752         (++) HAL_IRDA_DMAStop()
00753 
00754     (#) A set of Transfer Complete Callbacks are provided in Non Blocking mode:
00755         (++) HAL_IRDA_TxHalfCpltCallback()
00756         (++) HAL_IRDA_TxCpltCallback()
00757         (++) HAL_IRDA_RxHalfCpltCallback()
00758         (++) HAL_IRDA_RxCpltCallback()
00759         (++) HAL_IRDA_ErrorCallback()
00760 
00761     (#) Non-Blocking mode transfers could be aborted using Abort API's :
00762         (++) HAL_IRDA_Abort()
00763         (++) HAL_IRDA_AbortTransmit()
00764         (++) HAL_IRDA_AbortReceive()
00765         (++) HAL_IRDA_Abort_IT()
00766         (++) HAL_IRDA_AbortTransmit_IT()
00767         (++) HAL_IRDA_AbortReceive_IT()
00768 
00769     (#) For Abort services based on interrupts (HAL_IRDA_Abortxxx_IT), a set of Abort Complete Callbacks are provided:
00770         (++) HAL_IRDA_AbortCpltCallback()
00771         (++) HAL_IRDA_AbortTransmitCpltCallback()
00772         (++) HAL_IRDA_AbortReceiveCpltCallback()
00773 
00774     (#) In Non-Blocking mode transfers, possible errors are split into 2 categories.
00775         Errors are handled as follows :
00776         (++) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is
00777              to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error
00778              in Interrupt mode reception .
00779              Received character is then retrieved and stored in Rx buffer, Error code is set to allow user
00780              to identify error type, and HAL_IRDA_ErrorCallback() user callback is executed.
00781              Transfer is kept ongoing on IRDA side.
00782              If user wants to abort it, Abort services should be called by user.
00783         (++) Error is considered as Blocking : Transfer could not be completed properly and is aborted.
00784              This concerns Overrun Error In Interrupt mode reception and all errors in DMA mode.
00785              Error code is set to allow user to identify error type, and
00786              HAL_IRDA_ErrorCallback() user callback is executed.
00787 
00788 @endverbatim
00789   * @{
00790   */
00791 
00792 /**
00793   * @brief Send an amount of data in blocking mode.
00794   * @note  When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
00795   *        the sent data is handled as a set of u16. In this case, Size must reflect the number
00796   *        of u16 available through pData.
00797   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
00798   *               the configuration information for the specified IRDA module.
00799   * @param pData Pointer to data buffer (u8 or u16 data elements).
00800   * @param Size Amount of data elements (u8 or u16) to be sent.
00801   * @param Timeout Specify timeout value.
00802   * @retval HAL status
00803   */
00804 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size, uint32_t Timeout)
00805 {
00806   const uint8_t  *pdata8bits;
00807   const uint16_t *pdata16bits;
00808   uint32_t tickstart;
00809 
00810   /* Check that a Tx process is not already ongoing */
00811   if (hirda->gState == HAL_IRDA_STATE_READY)
00812   {
00813     if ((pData == NULL) || (Size == 0U))
00814     {
00815       return  HAL_ERROR;
00816     }
00817 
00818     /* Process Locked */
00819     __HAL_LOCK(hirda);
00820 
00821     hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
00822     hirda->gState = HAL_IRDA_STATE_BUSY_TX;
00823 
00824     /* Init tickstart for timeout management */
00825     tickstart = HAL_GetTick();
00826 
00827     hirda->TxXferSize = Size;
00828     hirda->TxXferCount = Size;
00829 
00830     /* In case of 9bits/No Parity transfer, pData needs to be handled as a uint16_t pointer */
00831     if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
00832     {
00833       pdata8bits  = NULL;
00834       pdata16bits = (const uint16_t *) pData; /* Derogation R.11.3 */
00835     }
00836     else
00837     {
00838       pdata8bits  = pData;
00839       pdata16bits = NULL;
00840     }
00841 
00842     while (hirda->TxXferCount > 0U)
00843     {
00844       hirda->TxXferCount--;
00845 
00846       if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
00847       {
00848         return HAL_TIMEOUT;
00849       }
00850       if (pdata8bits == NULL)
00851       {
00852         hirda->Instance->TDR = (uint16_t)(*pdata16bits & 0x01FFU);
00853         pdata16bits++;
00854       }
00855       else
00856       {
00857         hirda->Instance->TDR = (uint8_t)(*pdata8bits & 0xFFU);
00858         pdata8bits++;
00859       }
00860     }
00861 
00862     if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
00863     {
00864       return HAL_TIMEOUT;
00865     }
00866 
00867     /* At end of Tx process, restore hirda->gState to Ready */
00868     hirda->gState = HAL_IRDA_STATE_READY;
00869 
00870     /* Process Unlocked */
00871     __HAL_UNLOCK(hirda);
00872 
00873     return HAL_OK;
00874   }
00875   else
00876   {
00877     return HAL_BUSY;
00878   }
00879 }
00880 
00881 /**
00882   * @brief Receive an amount of data in blocking mode.
00883   * @note  When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
00884   *        the received data is handled as a set of u16. In this case, Size must reflect the number
00885   *        of u16 available through pData.
00886   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
00887   *                the configuration information for the specified IRDA module.
00888   * @param pData Pointer to data buffer (u8 or u16 data elements).
00889   * @param Size Amount of data elements (u8 or u16) to be received.
00890   * @param Timeout Specify timeout value.
00891   * @retval HAL status
00892   */
00893 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
00894 {
00895   uint8_t  *pdata8bits;
00896   uint16_t *pdata16bits;
00897   uint16_t uhMask;
00898   uint32_t tickstart;
00899 
00900   /* Check that a Rx process is not already ongoing */
00901   if (hirda->RxState == HAL_IRDA_STATE_READY)
00902   {
00903     if ((pData == NULL) || (Size == 0U))
00904     {
00905       return  HAL_ERROR;
00906     }
00907 
00908     /* Process Locked */
00909     __HAL_LOCK(hirda);
00910 
00911     hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
00912     hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
00913 
00914     /* Init tickstart for timeout management */
00915     tickstart = HAL_GetTick();
00916 
00917     hirda->RxXferSize = Size;
00918     hirda->RxXferCount = Size;
00919 
00920     /* Computation of the mask to apply to RDR register
00921        of the UART associated to the IRDA */
00922     IRDA_MASK_COMPUTATION(hirda);
00923     uhMask = hirda->Mask;
00924 
00925     /* In case of 9bits/No Parity transfer, pRxData needs to be handled as a uint16_t pointer */
00926     if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
00927     {
00928       pdata8bits  = NULL;
00929       pdata16bits = (uint16_t *) pData; /* Derogation R.11.3 */
00930     }
00931     else
00932     {
00933       pdata8bits  = pData;
00934       pdata16bits = NULL;
00935     }
00936 
00937     /* Check data remaining to be received */
00938     while (hirda->RxXferCount > 0U)
00939     {
00940       hirda->RxXferCount--;
00941 
00942       if (IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
00943       {
00944         return HAL_TIMEOUT;
00945       }
00946       if (pdata8bits == NULL)
00947       {
00948         *pdata16bits = (uint16_t)(hirda->Instance->RDR & uhMask);
00949         pdata16bits++;
00950       }
00951       else
00952       {
00953         *pdata8bits = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask);
00954         pdata8bits++;
00955       }
00956     }
00957 
00958     /* At end of Rx process, restore hirda->RxState to Ready */
00959     hirda->RxState = HAL_IRDA_STATE_READY;
00960 
00961     /* Process Unlocked */
00962     __HAL_UNLOCK(hirda);
00963 
00964     return HAL_OK;
00965   }
00966   else
00967   {
00968     return HAL_BUSY;
00969   }
00970 }
00971 
00972 /**
00973   * @brief Send an amount of data in interrupt mode.
00974   * @note  When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
00975   *        the sent data is handled as a set of u16. In this case, Size must reflect the number
00976   *        of u16 available through pData.
00977   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
00978   *                the configuration information for the specified IRDA module.
00979   * @param pData Pointer to data buffer (u8 or u16 data elements).
00980   * @param Size Amount of data elements (u8 or u16) to be sent.
00981   * @retval HAL status
00982   */
00983 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size)
00984 {
00985   /* Check that a Tx process is not already ongoing */
00986   if (hirda->gState == HAL_IRDA_STATE_READY)
00987   {
00988     if ((pData == NULL) || (Size == 0U))
00989     {
00990       return HAL_ERROR;
00991     }
00992 
00993     /* Process Locked */
00994     __HAL_LOCK(hirda);
00995 
00996     hirda->pTxBuffPtr = pData;
00997     hirda->TxXferSize = Size;
00998     hirda->TxXferCount = Size;
00999 
01000     hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
01001     hirda->gState = HAL_IRDA_STATE_BUSY_TX;
01002 
01003     /* Process Unlocked */
01004     __HAL_UNLOCK(hirda);
01005 
01006     /* Enable the IRDA Transmit Data Register Empty Interrupt */
01007     SET_BIT(hirda->Instance->CR1, USART_CR1_TXEIE_TXFNFIE);
01008 
01009     return HAL_OK;
01010   }
01011   else
01012   {
01013     return HAL_BUSY;
01014   }
01015 }
01016 
01017 /**
01018   * @brief Receive an amount of data in interrupt mode.
01019   * @note  When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
01020   *        the received data is handled as a set of u16. In this case, Size must reflect the number
01021   *        of u16 available through pData.
01022   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
01023   *                the configuration information for the specified IRDA module.
01024   * @param pData Pointer to data buffer (u8 or u16 data elements).
01025   * @param Size Amount of data elements (u8 or u16) to be received.
01026   * @retval HAL status
01027   */
01028 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
01029 {
01030   /* Check that a Rx process is not already ongoing */
01031   if (hirda->RxState == HAL_IRDA_STATE_READY)
01032   {
01033     if ((pData == NULL) || (Size == 0U))
01034     {
01035       return HAL_ERROR;
01036     }
01037 
01038     /* Process Locked */
01039     __HAL_LOCK(hirda);
01040 
01041     hirda->pRxBuffPtr = pData;
01042     hirda->RxXferSize = Size;
01043     hirda->RxXferCount = Size;
01044 
01045     /* Computation of the mask to apply to the RDR register
01046        of the UART associated to the IRDA */
01047     IRDA_MASK_COMPUTATION(hirda);
01048 
01049     hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
01050     hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
01051 
01052     /* Process Unlocked */
01053     __HAL_UNLOCK(hirda);
01054 
01055     if (hirda->Init.Parity != IRDA_PARITY_NONE)
01056     {
01057       /* Enable the IRDA Parity Error and Data Register not empty Interrupts */
01058       SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE_RXFNEIE);
01059     }
01060     else
01061     {
01062       /* Enable the IRDA Data Register not empty Interrupts */
01063       SET_BIT(hirda->Instance->CR1, USART_CR1_RXNEIE_RXFNEIE);
01064     }
01065 
01066     /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
01067     SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
01068 
01069     return HAL_OK;
01070   }
01071   else
01072   {
01073     return HAL_BUSY;
01074   }
01075 }
01076 
01077 /**
01078   * @brief Send an amount of data in DMA mode.
01079   * @note  When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
01080   *        the sent data is handled as a set of u16. In this case, Size must reflect the number
01081   *        of u16 available through pData.
01082   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
01083   *               the configuration information for the specified IRDA module.
01084   * @param pData pointer to data buffer (u8 or u16 data elements).
01085   * @param Size Amount of data elements (u8 or u16) to be sent.
01086   * @retval HAL status
01087   */
01088 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, const uint8_t *pData, uint16_t Size)
01089 {
01090   /* Check that a Tx process is not already ongoing */
01091   if (hirda->gState == HAL_IRDA_STATE_READY)
01092   {
01093     if ((pData == NULL) || (Size == 0U))
01094     {
01095       return HAL_ERROR;
01096     }
01097 
01098     /* Process Locked */
01099     __HAL_LOCK(hirda);
01100 
01101     hirda->pTxBuffPtr = pData;
01102     hirda->TxXferSize = Size;
01103     hirda->TxXferCount = Size;
01104 
01105     hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
01106     hirda->gState = HAL_IRDA_STATE_BUSY_TX;
01107 
01108     /* Set the IRDA DMA transfer complete callback */
01109     hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
01110 
01111     /* Set the IRDA DMA half transfer complete callback */
01112     hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
01113 
01114     /* Set the DMA error callback */
01115     hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
01116 
01117     /* Set the DMA abort callback */
01118     hirda->hdmatx->XferAbortCallback = NULL;
01119 
01120     /* Enable the IRDA transmit DMA channel */
01121     if (HAL_DMA_Start_IT(hirda->hdmatx, (uint32_t)hirda->pTxBuffPtr, (uint32_t)&hirda->Instance->TDR, Size) == HAL_OK)
01122     {
01123       /* Clear the TC flag in the ICR register */
01124       __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_CLEAR_TCF);
01125 
01126       /* Process Unlocked */
01127       __HAL_UNLOCK(hirda);
01128 
01129       /* Enable the DMA transfer for transmit request by setting the DMAT bit
01130          in the USART CR3 register */
01131       SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
01132 
01133       return HAL_OK;
01134     }
01135     else
01136     {
01137       /* Set error code to DMA */
01138       hirda->ErrorCode = HAL_IRDA_ERROR_DMA;
01139 
01140       /* Process Unlocked */
01141       __HAL_UNLOCK(hirda);
01142 
01143       /* Restore hirda->gState to ready */
01144       hirda->gState = HAL_IRDA_STATE_READY;
01145 
01146       return HAL_ERROR;
01147     }
01148   }
01149   else
01150   {
01151     return HAL_BUSY;
01152   }
01153 }
01154 
01155 /**
01156   * @brief Receive an amount of data in DMA mode.
01157   * @note  When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
01158   *        the received data is handled as a set of u16. In this case, Size must reflect the number
01159   *        of u16 available through pData.
01160   * @note   When the IRDA parity is enabled (PCE = 1), the received data contains
01161   *         the parity bit (MSB position).
01162   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
01163   *               the configuration information for the specified IRDA module.
01164   * @param pData Pointer to data buffer (u8 or u16 data elements).
01165   * @param Size Amount of data elements (u8 or u16) to be received.
01166   * @retval HAL status
01167   */
01168 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
01169 {
01170   /* Check that a Rx process is not already ongoing */
01171   if (hirda->RxState == HAL_IRDA_STATE_READY)
01172   {
01173     if ((pData == NULL) || (Size == 0U))
01174     {
01175       return HAL_ERROR;
01176     }
01177 
01178     /* Process Locked */
01179     __HAL_LOCK(hirda);
01180 
01181     hirda->pRxBuffPtr = pData;
01182     hirda->RxXferSize = Size;
01183 
01184     hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
01185     hirda->RxState = HAL_IRDA_STATE_BUSY_RX;
01186 
01187     /* Set the IRDA DMA transfer complete callback */
01188     hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
01189 
01190     /* Set the IRDA DMA half transfer complete callback */
01191     hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
01192 
01193     /* Set the DMA error callback */
01194     hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
01195 
01196     /* Set the DMA abort callback */
01197     hirda->hdmarx->XferAbortCallback = NULL;
01198 
01199     /* Enable the DMA channel */
01200     if (HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->RDR, (uint32_t)hirda->pRxBuffPtr, Size) == HAL_OK)
01201     {
01202       /* Process Unlocked */
01203       __HAL_UNLOCK(hirda);
01204 
01205       if (hirda->Init.Parity != IRDA_PARITY_NONE)
01206       {
01207         /* Enable the UART Parity Error Interrupt */
01208         SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
01209       }
01210 
01211       /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
01212       SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
01213 
01214       /* Enable the DMA transfer for the receiver request by setting the DMAR bit
01215          in the USART CR3 register */
01216       SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
01217 
01218       return HAL_OK;
01219     }
01220     else
01221     {
01222       /* Set error code to DMA */
01223       hirda->ErrorCode = HAL_IRDA_ERROR_DMA;
01224 
01225       /* Process Unlocked */
01226       __HAL_UNLOCK(hirda);
01227 
01228       /* Restore hirda->RxState to ready */
01229       hirda->RxState = HAL_IRDA_STATE_READY;
01230 
01231       return HAL_ERROR;
01232     }
01233   }
01234   else
01235   {
01236     return HAL_BUSY;
01237   }
01238 }
01239 
01240 
01241 /**
01242   * @brief Pause the DMA Transfer.
01243   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
01244   *                the configuration information for the specified IRDA module.
01245   * @retval HAL status
01246   */
01247 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
01248 {
01249   /* Process Locked */
01250   __HAL_LOCK(hirda);
01251 
01252   if (hirda->gState == HAL_IRDA_STATE_BUSY_TX)
01253   {
01254     if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
01255     {
01256       /* Disable the IRDA DMA Tx request */
01257       CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
01258     }
01259   }
01260   if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
01261   {
01262     if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
01263     {
01264       /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
01265       CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
01266       CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
01267 
01268       /* Disable the IRDA DMA Rx request */
01269       CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
01270     }
01271   }
01272 
01273   /* Process Unlocked */
01274   __HAL_UNLOCK(hirda);
01275 
01276   return HAL_OK;
01277 }
01278 
01279 /**
01280   * @brief Resume the DMA Transfer.
01281   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
01282   *                the configuration information for the specified UART module.
01283   * @retval HAL status
01284   */
01285 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
01286 {
01287   /* Process Locked */
01288   __HAL_LOCK(hirda);
01289 
01290   if (hirda->gState == HAL_IRDA_STATE_BUSY_TX)
01291   {
01292     /* Enable the IRDA DMA Tx request */
01293     SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
01294   }
01295   if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
01296   {
01297     /* Clear the Overrun flag before resuming the Rx transfer*/
01298     __HAL_IRDA_CLEAR_OREFLAG(hirda);
01299 
01300     /* Re-enable PE and ERR (Frame error, noise error, overrun error) interrupts */
01301     if (hirda->Init.Parity != IRDA_PARITY_NONE)
01302     {    
01303       SET_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
01304     }
01305     SET_BIT(hirda->Instance->CR3, USART_CR3_EIE);
01306 
01307     /* Enable the IRDA DMA Rx request */
01308     SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
01309   }
01310 
01311   /* Process Unlocked */
01312   __HAL_UNLOCK(hirda);
01313 
01314   return HAL_OK;
01315 }
01316 
01317 /**
01318   * @brief Stop the DMA Transfer.
01319   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
01320   *                the configuration information for the specified UART module.
01321   * @retval HAL status
01322   */
01323 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
01324 {
01325   /* The Lock is not implemented on this API to allow the user application
01326      to call the HAL IRDA API under callbacks HAL_IRDA_TxCpltCallback() / HAL_IRDA_RxCpltCallback() /
01327      HAL_IRDA_TxHalfCpltCallback / HAL_IRDA_RxHalfCpltCallback:
01328      indeed, when HAL_DMA_Abort() API is called, the DMA TX/RX Transfer or Half Transfer complete
01329      interrupt is generated if the DMA transfer interruption occurs at the middle or at the end of
01330      the stream and the corresponding call back is executed. */
01331 
01332   /* Stop IRDA DMA Tx request if ongoing */
01333   if (hirda->gState == HAL_IRDA_STATE_BUSY_TX)
01334   {
01335     if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
01336     {
01337       CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
01338 
01339       /* Abort the IRDA DMA Tx channel */
01340       if (hirda->hdmatx != NULL)
01341       {
01342         if (HAL_DMA_Abort(hirda->hdmatx) != HAL_OK)
01343         {
01344           if (HAL_DMA_GetError(hirda->hdmatx) == HAL_DMA_ERROR_TIMEOUT)
01345           {
01346             /* Set error code to DMA */
01347             hirda->ErrorCode = HAL_IRDA_ERROR_DMA;
01348 
01349             return HAL_TIMEOUT;
01350           }
01351         }
01352       }
01353 
01354       IRDA_EndTxTransfer(hirda);
01355     }
01356   }
01357 
01358   /* Stop IRDA DMA Rx request if ongoing */
01359   if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
01360   {
01361     if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
01362     {
01363       CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
01364 
01365       /* Abort the IRDA DMA Rx channel */
01366       if (hirda->hdmarx != NULL)
01367       {
01368         if (HAL_DMA_Abort(hirda->hdmarx) != HAL_OK)
01369         {
01370           if (HAL_DMA_GetError(hirda->hdmarx) == HAL_DMA_ERROR_TIMEOUT)
01371           {
01372             /* Set error code to DMA */
01373             hirda->ErrorCode = HAL_IRDA_ERROR_DMA;
01374 
01375             return HAL_TIMEOUT;
01376           }
01377         }
01378       }
01379 
01380       IRDA_EndRxTransfer(hirda);
01381     }
01382   }
01383 
01384   return HAL_OK;
01385 }
01386 
01387 /**
01388   * @brief  Abort ongoing transfers (blocking mode).
01389   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
01390   *               the configuration information for the specified UART module.
01391   * @note   This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
01392   *         This procedure performs following operations :
01393   *           - Disable IRDA Interrupts (Tx and Rx)
01394   *           - Disable the DMA transfer in the peripheral register (if enabled)
01395   *           - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
01396   *           - Set handle State to READY
01397   * @note   This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
01398   * @retval HAL status
01399   */
01400 HAL_StatusTypeDef HAL_IRDA_Abort(IRDA_HandleTypeDef *hirda)
01401 {
01402   /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
01403   CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE | \
01404                                    USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE));
01405   CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
01406 
01407   /* Disable the IRDA DMA Tx request if enabled */
01408   if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
01409   {
01410     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
01411 
01412     /* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
01413     if (hirda->hdmatx != NULL)
01414     {
01415       /* Set the IRDA DMA Abort callback to Null.
01416          No call back execution at end of DMA abort procedure */
01417       hirda->hdmatx->XferAbortCallback = NULL;
01418 
01419       if (HAL_DMA_Abort(hirda->hdmatx) != HAL_OK)
01420       {
01421         if (HAL_DMA_GetError(hirda->hdmatx) == HAL_DMA_ERROR_TIMEOUT)
01422         {
01423           /* Set error code to DMA */
01424           hirda->ErrorCode = HAL_IRDA_ERROR_DMA;
01425 
01426           return HAL_TIMEOUT;
01427         }
01428       }
01429     }
01430   }
01431 
01432   /* Disable the IRDA DMA Rx request if enabled */
01433   if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
01434   {
01435     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
01436 
01437     /* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
01438     if (hirda->hdmarx != NULL)
01439     {
01440       /* Set the IRDA DMA Abort callback to Null.
01441          No call back execution at end of DMA abort procedure */
01442       hirda->hdmarx->XferAbortCallback = NULL;
01443 
01444       if (HAL_DMA_Abort(hirda->hdmarx) != HAL_OK)
01445       {
01446         if (HAL_DMA_GetError(hirda->hdmarx) == HAL_DMA_ERROR_TIMEOUT)
01447         {
01448           /* Set error code to DMA */
01449           hirda->ErrorCode = HAL_IRDA_ERROR_DMA;
01450 
01451           return HAL_TIMEOUT;
01452         }
01453       }
01454     }
01455   }
01456 
01457   /* Reset Tx and Rx transfer counters */
01458   hirda->TxXferCount = 0U;
01459   hirda->RxXferCount = 0U;
01460 
01461   /* Clear the Error flags in the ICR register */
01462   __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_CLEAR_OREF | IRDA_CLEAR_NEF | IRDA_CLEAR_PEF | IRDA_CLEAR_FEF);
01463 
01464   /* Restore hirda->gState and hirda->RxState to Ready */
01465   hirda->gState  = HAL_IRDA_STATE_READY;
01466   hirda->RxState = HAL_IRDA_STATE_READY;
01467 
01468   /* Reset Handle ErrorCode to No Error */
01469   hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
01470 
01471   return HAL_OK;
01472 }
01473 
01474 /**
01475   * @brief  Abort ongoing Transmit transfer (blocking mode).
01476   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
01477   *               the configuration information for the specified UART module.
01478   * @note   This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode.
01479   *         This procedure performs following operations :
01480   *           - Disable IRDA Interrupts (Tx)
01481   *           - Disable the DMA transfer in the peripheral register (if enabled)
01482   *           - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
01483   *           - Set handle State to READY
01484   * @note   This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
01485   * @retval HAL status
01486   */
01487 HAL_StatusTypeDef HAL_IRDA_AbortTransmit(IRDA_HandleTypeDef *hirda)
01488 {
01489   /* Disable TXEIE and TCIE interrupts */
01490   CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE));
01491 
01492   /* Disable the IRDA DMA Tx request if enabled */
01493   if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
01494   {
01495     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
01496 
01497     /* Abort the IRDA DMA Tx channel : use blocking DMA Abort API (no callback) */
01498     if (hirda->hdmatx != NULL)
01499     {
01500       /* Set the IRDA DMA Abort callback to Null.
01501          No call back execution at end of DMA abort procedure */
01502       hirda->hdmatx->XferAbortCallback = NULL;
01503 
01504       if (HAL_DMA_Abort(hirda->hdmatx) != HAL_OK)
01505       {
01506         if (HAL_DMA_GetError(hirda->hdmatx) == HAL_DMA_ERROR_TIMEOUT)
01507         {
01508           /* Set error code to DMA */
01509           hirda->ErrorCode = HAL_IRDA_ERROR_DMA;
01510 
01511           return HAL_TIMEOUT;
01512         }
01513       }
01514     }
01515   }
01516 
01517   /* Reset Tx transfer counter */
01518   hirda->TxXferCount = 0U;
01519 
01520   /* Restore hirda->gState to Ready */
01521   hirda->gState = HAL_IRDA_STATE_READY;
01522 
01523   return HAL_OK;
01524 }
01525 
01526 /**
01527   * @brief  Abort ongoing Receive transfer (blocking mode).
01528   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
01529   *               the configuration information for the specified UART module.
01530   * @note   This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode.
01531   *         This procedure performs following operations :
01532   *           - Disable IRDA Interrupts (Rx)
01533   *           - Disable the DMA transfer in the peripheral register (if enabled)
01534   *           - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
01535   *           - Set handle State to READY
01536   * @note   This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
01537   * @retval HAL status
01538   */
01539 HAL_StatusTypeDef HAL_IRDA_AbortReceive(IRDA_HandleTypeDef *hirda)
01540 {
01541   /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
01542   CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE));
01543   CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
01544 
01545   /* Disable the IRDA DMA Rx request if enabled */
01546   if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
01547   {
01548     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
01549 
01550     /* Abort the IRDA DMA Rx channel : use blocking DMA Abort API (no callback) */
01551     if (hirda->hdmarx != NULL)
01552     {
01553       /* Set the IRDA DMA Abort callback to Null.
01554          No call back execution at end of DMA abort procedure */
01555       hirda->hdmarx->XferAbortCallback = NULL;
01556 
01557       if (HAL_DMA_Abort(hirda->hdmarx) != HAL_OK)
01558       {
01559         if (HAL_DMA_GetError(hirda->hdmarx) == HAL_DMA_ERROR_TIMEOUT)
01560         {
01561           /* Set error code to DMA */
01562           hirda->ErrorCode = HAL_IRDA_ERROR_DMA;
01563 
01564           return HAL_TIMEOUT;
01565         }
01566       }
01567     }
01568   }
01569 
01570   /* Reset Rx transfer counter */
01571   hirda->RxXferCount = 0U;
01572 
01573   /* Clear the Error flags in the ICR register */
01574   __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_CLEAR_OREF | IRDA_CLEAR_NEF | IRDA_CLEAR_PEF | IRDA_CLEAR_FEF);
01575 
01576   /* Restore hirda->RxState to Ready */
01577   hirda->RxState = HAL_IRDA_STATE_READY;
01578 
01579   return HAL_OK;
01580 }
01581 
01582 /**
01583   * @brief  Abort ongoing transfers (Interrupt mode).
01584   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
01585   *               the configuration information for the specified UART module.
01586   * @note   This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
01587   *         This procedure performs following operations :
01588   *           - Disable IRDA Interrupts (Tx and Rx)
01589   *           - Disable the DMA transfer in the peripheral register (if enabled)
01590   *           - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
01591   *           - Set handle State to READY
01592   *           - At abort completion, call user abort complete callback
01593   * @note   This procedure is executed in Interrupt mode, meaning that abort procedure could be
01594   *         considered as completed only when user abort complete callback is executed (not when exiting function).
01595   * @retval HAL status
01596   */
01597 HAL_StatusTypeDef HAL_IRDA_Abort_IT(IRDA_HandleTypeDef *hirda)
01598 {
01599   uint32_t abortcplt = 1U;
01600 
01601   /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
01602   CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE | \
01603                                    USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE));
01604   CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
01605 
01606   /* If DMA Tx and/or DMA Rx Handles are associated to IRDA Handle, DMA Abort complete callbacks should be initialised
01607      before any call to DMA Abort functions */
01608   /* DMA Tx Handle is valid */
01609   if (hirda->hdmatx != NULL)
01610   {
01611     /* Set DMA Abort Complete callback if IRDA DMA Tx request if enabled.
01612        Otherwise, set it to NULL */
01613     if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
01614     {
01615       hirda->hdmatx->XferAbortCallback = IRDA_DMATxAbortCallback;
01616     }
01617     else
01618     {
01619       hirda->hdmatx->XferAbortCallback = NULL;
01620     }
01621   }
01622   /* DMA Rx Handle is valid */
01623   if (hirda->hdmarx != NULL)
01624   {
01625     /* Set DMA Abort Complete callback if IRDA DMA Rx request if enabled.
01626        Otherwise, set it to NULL */
01627     if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
01628     {
01629       hirda->hdmarx->XferAbortCallback = IRDA_DMARxAbortCallback;
01630     }
01631     else
01632     {
01633       hirda->hdmarx->XferAbortCallback = NULL;
01634     }
01635   }
01636 
01637   /* Disable the IRDA DMA Tx request if enabled */
01638   if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
01639   {
01640     /* Disable DMA Tx at UART level */
01641     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
01642 
01643     /* Abort the IRDA DMA Tx channel : use non blocking DMA Abort API (callback) */
01644     if (hirda->hdmatx != NULL)
01645     {
01646       /* IRDA Tx DMA Abort callback has already been initialised :
01647          will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
01648 
01649       /* Abort DMA TX */
01650       if (HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
01651       {
01652         hirda->hdmatx->XferAbortCallback = NULL;
01653       }
01654       else
01655       {
01656         abortcplt = 0U;
01657       }
01658     }
01659   }
01660 
01661   /* Disable the IRDA DMA Rx request if enabled */
01662   if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
01663   {
01664     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
01665 
01666     /* Abort the IRDA DMA Rx channel : use non blocking DMA Abort API (callback) */
01667     if (hirda->hdmarx != NULL)
01668     {
01669       /* IRDA Rx DMA Abort callback has already been initialised :
01670          will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
01671 
01672       /* Abort DMA RX */
01673       if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
01674       {
01675         hirda->hdmarx->XferAbortCallback = NULL;
01676         abortcplt = 1U;
01677       }
01678       else
01679       {
01680         abortcplt = 0U;
01681       }
01682     }
01683   }
01684 
01685   /* if no DMA abort complete callback execution is required => call user Abort Complete callback */
01686   if (abortcplt == 1U)
01687   {
01688     /* Reset Tx and Rx transfer counters */
01689     hirda->TxXferCount = 0U;
01690     hirda->RxXferCount = 0U;
01691 
01692     /* Reset errorCode */
01693     hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
01694 
01695     /* Clear the Error flags in the ICR register */
01696     __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_CLEAR_OREF | IRDA_CLEAR_NEF | IRDA_CLEAR_PEF | IRDA_CLEAR_FEF);
01697 
01698     /* Restore hirda->gState and hirda->RxState to Ready */
01699     hirda->gState  = HAL_IRDA_STATE_READY;
01700     hirda->RxState = HAL_IRDA_STATE_READY;
01701 
01702     /* As no DMA to be aborted, call directly user Abort complete callback */
01703 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
01704     /* Call registered Abort complete callback */
01705     hirda->AbortCpltCallback(hirda);
01706 #else
01707     /* Call legacy weak Abort complete callback */
01708     HAL_IRDA_AbortCpltCallback(hirda);
01709 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
01710   }
01711 
01712   return HAL_OK;
01713 }
01714 
01715 /**
01716   * @brief  Abort ongoing Transmit transfer (Interrupt mode).
01717   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
01718   *               the configuration information for the specified UART module.
01719   * @note   This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode.
01720   *         This procedure performs following operations :
01721   *           - Disable IRDA Interrupts (Tx)
01722   *           - Disable the DMA transfer in the peripheral register (if enabled)
01723   *           - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
01724   *           - Set handle State to READY
01725   *           - At abort completion, call user abort complete callback
01726   * @note   This procedure is executed in Interrupt mode, meaning that abort procedure could be
01727   *         considered as completed only when user abort complete callback is executed (not when exiting function).
01728   * @retval HAL status
01729   */
01730 HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT(IRDA_HandleTypeDef *hirda)
01731 {
01732   /* Disable TXEIE and TCIE interrupts */
01733   CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE));
01734 
01735   /* Disable the IRDA DMA Tx request if enabled */
01736   if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
01737   {
01738     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
01739 
01740     /* Abort the IRDA DMA Tx channel : use non blocking DMA Abort API (callback) */
01741     if (hirda->hdmatx != NULL)
01742     {
01743       /* Set the IRDA DMA Abort callback :
01744          will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
01745       hirda->hdmatx->XferAbortCallback = IRDA_DMATxOnlyAbortCallback;
01746 
01747       /* Abort DMA TX */
01748       if (HAL_DMA_Abort_IT(hirda->hdmatx) != HAL_OK)
01749       {
01750         /* Call Directly hirda->hdmatx->XferAbortCallback function in case of error */
01751         hirda->hdmatx->XferAbortCallback(hirda->hdmatx);
01752       }
01753     }
01754     else
01755     {
01756       /* Reset Tx transfer counter */
01757       hirda->TxXferCount = 0U;
01758 
01759       /* Restore hirda->gState to Ready */
01760       hirda->gState = HAL_IRDA_STATE_READY;
01761 
01762       /* As no DMA to be aborted, call directly user Abort complete callback */
01763 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
01764       /* Call registered Abort Transmit Complete Callback */
01765       hirda->AbortTransmitCpltCallback(hirda);
01766 #else
01767       /* Call legacy weak Abort Transmit Complete Callback */
01768       HAL_IRDA_AbortTransmitCpltCallback(hirda);
01769 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
01770     }
01771   }
01772   else
01773   {
01774     /* Reset Tx transfer counter */
01775     hirda->TxXferCount = 0U;
01776 
01777     /* Restore hirda->gState to Ready */
01778     hirda->gState = HAL_IRDA_STATE_READY;
01779 
01780     /* As no DMA to be aborted, call directly user Abort complete callback */
01781 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
01782     /* Call registered Abort Transmit Complete Callback */
01783     hirda->AbortTransmitCpltCallback(hirda);
01784 #else
01785     /* Call legacy weak Abort Transmit Complete Callback */
01786     HAL_IRDA_AbortTransmitCpltCallback(hirda);
01787 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
01788   }
01789 
01790   return HAL_OK;
01791 }
01792 
01793 /**
01794   * @brief  Abort ongoing Receive transfer (Interrupt mode).
01795   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
01796   *               the configuration information for the specified UART module.
01797   * @note   This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode.
01798   *         This procedure performs following operations :
01799   *           - Disable IRDA Interrupts (Rx)
01800   *           - Disable the DMA transfer in the peripheral register (if enabled)
01801   *           - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
01802   *           - Set handle State to READY
01803   *           - At abort completion, call user abort complete callback
01804   * @note   This procedure is executed in Interrupt mode, meaning that abort procedure could be
01805   *         considered as completed only when user abort complete callback is executed (not when exiting function).
01806   * @retval HAL status
01807   */
01808 HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT(IRDA_HandleTypeDef *hirda)
01809 {
01810   /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
01811   CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE));
01812   CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
01813 
01814   /* Disable the IRDA DMA Rx request if enabled */
01815   if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
01816   {
01817     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
01818 
01819     /* Abort the IRDA DMA Rx channel : use non blocking DMA Abort API (callback) */
01820     if (hirda->hdmarx != NULL)
01821     {
01822       /* Set the IRDA DMA Abort callback :
01823          will lead to call HAL_IRDA_AbortCpltCallback() at end of DMA abort procedure */
01824       hirda->hdmarx->XferAbortCallback = IRDA_DMARxOnlyAbortCallback;
01825 
01826       /* Abort DMA RX */
01827       if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
01828       {
01829         /* Call Directly hirda->hdmarx->XferAbortCallback function in case of error */
01830         hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
01831       }
01832     }
01833     else
01834     {
01835       /* Reset Rx transfer counter */
01836       hirda->RxXferCount = 0U;
01837 
01838       /* Clear the Error flags in the ICR register */
01839       __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_CLEAR_OREF | IRDA_CLEAR_NEF | IRDA_CLEAR_PEF | IRDA_CLEAR_FEF);
01840 
01841       /* Restore hirda->RxState to Ready */
01842       hirda->RxState = HAL_IRDA_STATE_READY;
01843 
01844       /* As no DMA to be aborted, call directly user Abort complete callback */
01845 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
01846       /* Call registered Abort Receive Complete Callback */
01847       hirda->AbortReceiveCpltCallback(hirda);
01848 #else
01849       /* Call legacy weak Abort Receive Complete Callback */
01850       HAL_IRDA_AbortReceiveCpltCallback(hirda);
01851 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
01852     }
01853   }
01854   else
01855   {
01856     /* Reset Rx transfer counter */
01857     hirda->RxXferCount = 0U;
01858 
01859     /* Clear the Error flags in the ICR register */
01860     __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_CLEAR_OREF | IRDA_CLEAR_NEF | IRDA_CLEAR_PEF | IRDA_CLEAR_FEF);
01861 
01862     /* Restore hirda->RxState to Ready */
01863     hirda->RxState = HAL_IRDA_STATE_READY;
01864 
01865     /* As no DMA to be aborted, call directly user Abort complete callback */
01866 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
01867     /* Call registered Abort Receive Complete Callback */
01868     hirda->AbortReceiveCpltCallback(hirda);
01869 #else
01870     /* Call legacy weak Abort Receive Complete Callback */
01871     HAL_IRDA_AbortReceiveCpltCallback(hirda);
01872 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
01873   }
01874 
01875   return HAL_OK;
01876 }
01877 
01878 /**
01879   * @brief Handle IRDA interrupt request.
01880   * @param hirda  Pointer to a IRDA_HandleTypeDef structure that contains
01881   *               the configuration information for the specified IRDA module.
01882   * @retval None
01883   */
01884 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
01885 {
01886   uint32_t isrflags   = READ_REG(hirda->Instance->ISR);
01887   uint32_t cr1its     = READ_REG(hirda->Instance->CR1);
01888   uint32_t cr3its;
01889   uint32_t errorflags;
01890   uint32_t errorcode;
01891 
01892   /* If no error occurs */
01893   errorflags = (isrflags & (uint32_t)(USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE));
01894   if (errorflags == 0U)
01895   {
01896     /* IRDA in mode Receiver ---------------------------------------------------*/
01897     if (((isrflags & USART_ISR_RXNE_RXFNE) != 0U) && ((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U))
01898     {
01899       IRDA_Receive_IT(hirda);
01900       return;
01901     }
01902   }
01903 
01904   /* If some errors occur */
01905   cr3its = READ_REG(hirda->Instance->CR3);
01906   if ((errorflags != 0U)
01907       && (((cr3its & USART_CR3_EIE) != 0U)
01908           || ((cr1its & (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE)) != 0U)))
01909   {
01910     /* IRDA parity error interrupt occurred -------------------------------------*/
01911     if (((isrflags & USART_ISR_PE) != 0U) && ((cr1its & USART_CR1_PEIE) != 0U))
01912     {
01913       __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_PEF);
01914 
01915       hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
01916     }
01917 
01918     /* IRDA frame error interrupt occurred --------------------------------------*/
01919     if (((isrflags & USART_ISR_FE) != 0U) && ((cr3its & USART_CR3_EIE) != 0U))
01920     {
01921       __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_FEF);
01922 
01923       hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
01924     }
01925 
01926     /* IRDA noise error interrupt occurred --------------------------------------*/
01927     if (((isrflags & USART_ISR_NE) != 0U) && ((cr3its & USART_CR3_EIE) != 0U))
01928     {
01929       __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_NEF);
01930 
01931       hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
01932     }
01933 
01934     /* IRDA Over-Run interrupt occurred -----------------------------------------*/
01935     if (((isrflags & USART_ISR_ORE) != 0U) &&
01936         (((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U) || ((cr3its & USART_CR3_EIE) != 0U)))
01937     {
01938       __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_OREF);
01939 
01940       hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
01941     }
01942 
01943     /* Call IRDA Error Call back function if need be --------------------------*/
01944     if (hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
01945     {
01946       /* IRDA in mode Receiver ---------------------------------------------------*/
01947       if (((isrflags & USART_ISR_RXNE_RXFNE) != 0U) && ((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U))
01948       {
01949         IRDA_Receive_IT(hirda);
01950       }
01951 
01952       /* If Overrun error occurs, or if any error occurs in DMA mode reception,
01953          consider error as blocking */
01954       errorcode = hirda->ErrorCode;
01955       if ((HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR)) ||
01956           ((errorcode & HAL_IRDA_ERROR_ORE) != 0U))
01957       {
01958         /* Blocking error : transfer is aborted
01959            Set the IRDA state ready to be able to start again the process,
01960            Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
01961         IRDA_EndRxTransfer(hirda);
01962 
01963         /* Disable the IRDA DMA Rx request if enabled */
01964         if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
01965         {
01966           CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
01967 
01968           /* Abort the IRDA DMA Rx channel */
01969           if (hirda->hdmarx != NULL)
01970           {
01971             /* Set the IRDA DMA Abort callback :
01972                will lead to call HAL_IRDA_ErrorCallback() at end of DMA abort procedure */
01973             hirda->hdmarx->XferAbortCallback = IRDA_DMAAbortOnError;
01974 
01975             /* Abort DMA RX */
01976             if (HAL_DMA_Abort_IT(hirda->hdmarx) != HAL_OK)
01977             {
01978               /* Call Directly hirda->hdmarx->XferAbortCallback function in case of error */
01979               hirda->hdmarx->XferAbortCallback(hirda->hdmarx);
01980             }
01981           }
01982           else
01983           {
01984 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
01985             /* Call registered user error callback */
01986             hirda->ErrorCallback(hirda);
01987 #else
01988             /* Call legacy weak user error callback */
01989             HAL_IRDA_ErrorCallback(hirda);
01990 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
01991           }
01992         }
01993         else
01994         {
01995 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
01996           /* Call registered user error callback */
01997           hirda->ErrorCallback(hirda);
01998 #else
01999           /* Call legacy weak user error callback */
02000           HAL_IRDA_ErrorCallback(hirda);
02001 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02002         }
02003       }
02004       else
02005       {
02006         /* Non Blocking error : transfer could go on.
02007            Error is notified to user through user error callback */
02008 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02009         /* Call registered user error callback */
02010         hirda->ErrorCallback(hirda);
02011 #else
02012         /* Call legacy weak user error callback */
02013         HAL_IRDA_ErrorCallback(hirda);
02014 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02015         hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
02016       }
02017     }
02018     return;
02019 
02020   } /* End if some error occurs */
02021 
02022   /* IRDA in mode Transmitter ------------------------------------------------*/
02023   if (((isrflags & USART_ISR_TXE_TXFNF) != 0U) && ((cr1its & USART_CR1_TXEIE_TXFNFIE) != 0U))
02024   {
02025     IRDA_Transmit_IT(hirda);
02026     return;
02027   }
02028 
02029   /* IRDA in mode Transmitter (transmission end) -----------------------------*/
02030   if (((isrflags & USART_ISR_TC) != 0U) && ((cr1its & USART_CR1_TCIE) != 0U))
02031   {
02032     IRDA_EndTransmit_IT(hirda);
02033     return;
02034   }
02035 
02036 }
02037 
02038 /**
02039   * @brief  Tx Transfer completed callback.
02040   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02041   *               the configuration information for the specified IRDA module.
02042   * @retval None
02043   */
02044 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
02045 {
02046   /* Prevent unused argument(s) compilation warning */
02047   UNUSED(hirda);
02048 
02049   /* NOTE : This function should not be modified, when the callback is needed,
02050             the HAL_IRDA_TxCpltCallback can be implemented in the user file.
02051    */
02052 }
02053 
02054 /**
02055   * @brief  Tx Half Transfer completed callback.
02056   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02057   *               the configuration information for the specified USART module.
02058   * @retval None
02059   */
02060 __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
02061 {
02062   /* Prevent unused argument(s) compilation warning */
02063   UNUSED(hirda);
02064 
02065   /* NOTE : This function should not be modified, when the callback is needed,
02066             the HAL_IRDA_TxHalfCpltCallback can be implemented in the user file.
02067    */
02068 }
02069 
02070 /**
02071   * @brief  Rx Transfer completed callback.
02072   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02073   *               the configuration information for the specified IRDA module.
02074   * @retval None
02075   */
02076 __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
02077 {
02078   /* Prevent unused argument(s) compilation warning */
02079   UNUSED(hirda);
02080 
02081   /* NOTE : This function should not be modified, when the callback is needed,
02082             the HAL_IRDA_RxCpltCallback can be implemented in the user file.
02083    */
02084 }
02085 
02086 /**
02087   * @brief  Rx Half Transfer complete callback.
02088   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02089   *               the configuration information for the specified IRDA module.
02090   * @retval None
02091   */
02092 __weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
02093 {
02094   /* Prevent unused argument(s) compilation warning */
02095   UNUSED(hirda);
02096 
02097   /* NOTE : This function should not be modified, when the callback is needed,
02098             the HAL_IRDA_RxHalfCpltCallback can be implemented in the user file.
02099    */
02100 }
02101 
02102 /**
02103   * @brief  IRDA error callback.
02104   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02105   *               the configuration information for the specified IRDA module.
02106   * @retval None
02107   */
02108 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
02109 {
02110   /* Prevent unused argument(s) compilation warning */
02111   UNUSED(hirda);
02112 
02113   /* NOTE : This function should not be modified, when the callback is needed,
02114             the HAL_IRDA_ErrorCallback can be implemented in the user file.
02115    */
02116 }
02117 
02118 /**
02119   * @brief  IRDA Abort Complete callback.
02120   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02121   *               the configuration information for the specified IRDA module.
02122   * @retval None
02123   */
02124 __weak void HAL_IRDA_AbortCpltCallback(IRDA_HandleTypeDef *hirda)
02125 {
02126   /* Prevent unused argument(s) compilation warning */
02127   UNUSED(hirda);
02128 
02129   /* NOTE : This function should not be modified, when the callback is needed,
02130             the HAL_IRDA_AbortCpltCallback can be implemented in the user file.
02131    */
02132 }
02133 
02134 /**
02135   * @brief  IRDA Abort Complete callback.
02136   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02137   *               the configuration information for the specified IRDA module.
02138   * @retval None
02139   */
02140 __weak void HAL_IRDA_AbortTransmitCpltCallback(IRDA_HandleTypeDef *hirda)
02141 {
02142   /* Prevent unused argument(s) compilation warning */
02143   UNUSED(hirda);
02144 
02145   /* NOTE : This function should not be modified, when the callback is needed,
02146             the HAL_IRDA_AbortTransmitCpltCallback can be implemented in the user file.
02147    */
02148 }
02149 
02150 /**
02151   * @brief  IRDA Abort Receive Complete callback.
02152   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02153   *               the configuration information for the specified IRDA module.
02154   * @retval None
02155   */
02156 __weak void HAL_IRDA_AbortReceiveCpltCallback(IRDA_HandleTypeDef *hirda)
02157 {
02158   /* Prevent unused argument(s) compilation warning */
02159   UNUSED(hirda);
02160 
02161   /* NOTE : This function should not be modified, when the callback is needed,
02162             the HAL_IRDA_AbortReceiveCpltCallback can be implemented in the user file.
02163    */
02164 }
02165 
02166 /**
02167   * @}
02168   */
02169 
02170 /** @defgroup IRDA_Exported_Functions_Group4 Peripheral State and Error functions
02171   *  @brief   IRDA State and Errors functions
02172   *
02173 @verbatim
02174   ==============================================================================
02175             ##### Peripheral State and Error functions #####
02176   ==============================================================================
02177   [..]
02178     This subsection provides a set of functions allowing to return the State of IrDA
02179     communication process and also return Peripheral Errors occurred during communication process
02180      (+) HAL_IRDA_GetState() API can be helpful to check in run-time the state
02181          of the IRDA peripheral handle.
02182      (+) HAL_IRDA_GetError() checks in run-time errors that could occur during
02183          communication.
02184 
02185 @endverbatim
02186   * @{
02187   */
02188 
02189 /**
02190   * @brief Return the IRDA handle state.
02191   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
02192   *                the configuration information for the specified IRDA module.
02193   * @retval HAL state
02194   */
02195 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda)
02196 {
02197   /* Return IRDA handle state */
02198   uint32_t temp1;
02199   uint32_t temp2;
02200   temp1 = (uint32_t)hirda->gState;
02201   temp2 = (uint32_t)hirda->RxState;
02202 
02203   return (HAL_IRDA_StateTypeDef)(temp1 | temp2);
02204 }
02205 
02206 /**
02207   * @brief Return the IRDA handle error code.
02208   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
02209   *               the configuration information for the specified IRDA module.
02210   * @retval IRDA Error Code
02211   */
02212 uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda)
02213 {
02214   return hirda->ErrorCode;
02215 }
02216 
02217 /**
02218   * @}
02219   */
02220 
02221 /**
02222   * @}
02223   */
02224 
02225 /** @defgroup IRDA_Private_Functions IRDA Private Functions
02226   * @{
02227   */
02228 
02229 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02230 /**
02231   * @brief  Initialize the callbacks to their default values.
02232   * @param  hirda IRDA handle.
02233   * @retval none
02234   */
02235 void IRDA_InitCallbacksToDefault(IRDA_HandleTypeDef *hirda)
02236 {
02237   /* Init the IRDA Callback settings */
02238   hirda->TxHalfCpltCallback        = HAL_IRDA_TxHalfCpltCallback;        /* Legacy weak TxHalfCpltCallback        */
02239   hirda->TxCpltCallback            = HAL_IRDA_TxCpltCallback;            /* Legacy weak TxCpltCallback            */
02240   hirda->RxHalfCpltCallback        = HAL_IRDA_RxHalfCpltCallback;        /* Legacy weak RxHalfCpltCallback        */
02241   hirda->RxCpltCallback            = HAL_IRDA_RxCpltCallback;            /* Legacy weak RxCpltCallback            */
02242   hirda->ErrorCallback             = HAL_IRDA_ErrorCallback;             /* Legacy weak ErrorCallback             */
02243   hirda->AbortCpltCallback         = HAL_IRDA_AbortCpltCallback;         /* Legacy weak AbortCpltCallback         */
02244   hirda->AbortTransmitCpltCallback = HAL_IRDA_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
02245   hirda->AbortReceiveCpltCallback  = HAL_IRDA_AbortReceiveCpltCallback;  /* Legacy weak AbortReceiveCpltCallback  */
02246 
02247 }
02248 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
02249 
02250 /**
02251   * @brief Configure the IRDA peripheral.
02252   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
02253   *               the configuration information for the specified IRDA module.
02254   * @retval HAL status
02255   */
02256 static HAL_StatusTypeDef IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
02257 {
02258   uint32_t tmpreg;
02259   IRDA_ClockSourceTypeDef clocksource;
02260   HAL_StatusTypeDef ret = HAL_OK;
02261   static const uint16_t IRDAPrescTable[12] = {1U, 2U, 4U, 6U, 8U, 10U, 12U, 16U, 32U, 64U, 128U, 256U};
02262   PLL2_ClocksTypeDef pll2_clocks;
02263   PLL3_ClocksTypeDef pll3_clocks;
02264   uint32_t pclk;
02265 
02266   /* Check the communication parameters */
02267   assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
02268   assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
02269   assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
02270   assert_param(IS_IRDA_TX_RX_MODE(hirda->Init.Mode));
02271   assert_param(IS_IRDA_PRESCALER(hirda->Init.Prescaler));
02272   assert_param(IS_IRDA_POWERMODE(hirda->Init.PowerMode));
02273   assert_param(IS_IRDA_CLOCKPRESCALER(hirda->Init.ClockPrescaler));
02274 
02275   /*-------------------------- USART CR1 Configuration -----------------------*/
02276   /* Configure the IRDA Word Length, Parity and transfer Mode:
02277      Set the M bits according to hirda->Init.WordLength value
02278      Set PCE and PS bits according to hirda->Init.Parity value
02279      Set TE and RE bits according to hirda->Init.Mode value */
02280   tmpreg = (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode ;
02281 
02282   MODIFY_REG(hirda->Instance->CR1, IRDA_CR1_FIELDS, tmpreg);
02283 
02284   /*-------------------------- USART CR3 Configuration -----------------------*/
02285   MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.PowerMode);
02286 
02287   /*--------------------- USART clock PRESC Configuration ----------------*/
02288   /* Configure
02289   * - IRDA Clock Prescaler: set PRESCALER according to hirda->Init.ClockPrescaler value */
02290   MODIFY_REG(hirda->Instance->PRESC, USART_PRESC_PRESCALER, hirda->Init.ClockPrescaler);
02291 
02292   /*-------------------------- USART GTPR Configuration ----------------------*/
02293   MODIFY_REG(hirda->Instance->GTPR, (uint16_t)USART_GTPR_PSC, (uint16_t)hirda->Init.Prescaler);
02294 
02295   /*-------------------------- USART BRR Configuration -----------------------*/
02296   IRDA_GETCLOCKSOURCE(hirda, clocksource);
02297   tmpreg =   0U;
02298   switch (clocksource)
02299   {
02300     case IRDA_CLOCKSOURCE_D2PCLK1:
02301       pclk = HAL_RCC_GetPCLK1Freq();
02302       tmpreg = (uint32_t)(IRDA_DIV_SAMPLING16(pclk, hirda->Init.BaudRate, hirda->Init.ClockPrescaler));
02303       break;
02304     case IRDA_CLOCKSOURCE_D2PCLK2:
02305       pclk = HAL_RCC_GetPCLK2Freq();
02306       tmpreg = (uint32_t)(IRDA_DIV_SAMPLING16(pclk, hirda->Init.BaudRate, hirda->Init.ClockPrescaler));
02307       break;
02308     case IRDA_CLOCKSOURCE_PLL2Q:
02309       HAL_RCCEx_GetPLL2ClockFreq(&pll2_clocks);
02310       tmpreg = (uint32_t)(IRDA_DIV_SAMPLING16(pll2_clocks.PLL2_Q_Frequency, hirda->Init.BaudRate, hirda->Init.ClockPrescaler));
02311       break;
02312     case IRDA_CLOCKSOURCE_PLL3Q:
02313       HAL_RCCEx_GetPLL3ClockFreq(&pll3_clocks);
02314       tmpreg = (uint32_t)(IRDA_DIV_SAMPLING16(pll3_clocks.PLL3_Q_Frequency, hirda->Init.BaudRate, hirda->Init.ClockPrescaler));
02315       break;
02316     case IRDA_CLOCKSOURCE_CSI:
02317       tmpreg = (uint32_t)(IRDA_DIV_SAMPLING16(CSI_VALUE, hirda->Init.BaudRate, hirda->Init.ClockPrescaler));
02318       break;
02319     case IRDA_CLOCKSOURCE_HSI:
02320       tmpreg = (uint32_t)(IRDA_DIV_SAMPLING16(HSI_VALUE, hirda->Init.BaudRate, hirda->Init.ClockPrescaler));
02321       break;
02322     case IRDA_CLOCKSOURCE_LSE:
02323       tmpreg = (uint32_t)(IRDA_DIV_SAMPLING16((uint32_t)LSE_VALUE, hirda->Init.BaudRate, hirda->Init.ClockPrescaler));
02324       break;
02325     default:
02326       ret = HAL_ERROR;
02327       break;
02328   }
02329 
02330   /* USARTDIV must be greater than or equal to 0d16 */
02331   if ((tmpreg >= USART_BRR_MIN) && (tmpreg <= USART_BRR_MAX))
02332   {
02333     hirda->Instance->BRR = (uint16_t)tmpreg;
02334   }
02335   else
02336   {
02337     ret = HAL_ERROR;
02338   }
02339 
02340   return ret;
02341 }
02342 
02343 /**
02344   * @brief Check the IRDA Idle State.
02345   * @param hirda Pointer to a IRDA_HandleTypeDef structure that contains
02346   *               the configuration information for the specified IRDA module.
02347   * @retval HAL status
02348   */
02349 static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda)
02350 {
02351   uint32_t tickstart;
02352 
02353   /* Initialize the IRDA ErrorCode */
02354   hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
02355 
02356   /* Init tickstart for timeout management */
02357   tickstart = HAL_GetTick();
02358 
02359   /* Check if the Transmitter is enabled */
02360   if ((hirda->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
02361   {
02362     /* Wait until TEACK flag is set */
02363     if (IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_TEACK, RESET, tickstart, IRDA_TEACK_REACK_TIMEOUT) != HAL_OK)
02364     {
02365       /* Timeout occurred */
02366       return HAL_TIMEOUT;
02367     }
02368   }
02369   /* Check if the Receiver is enabled */
02370   if ((hirda->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
02371   {
02372     /* Wait until REACK flag is set */
02373     if (IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_REACK, RESET, tickstart, IRDA_TEACK_REACK_TIMEOUT) != HAL_OK)
02374     {
02375       /* Timeout occurred */
02376       return HAL_TIMEOUT;
02377     }
02378   }
02379 
02380   /* Initialize the IRDA state*/
02381   hirda->gState  = HAL_IRDA_STATE_READY;
02382   hirda->RxState = HAL_IRDA_STATE_READY;
02383 
02384   /* Process Unlocked */
02385   __HAL_UNLOCK(hirda);
02386 
02387   return HAL_OK;
02388 }
02389 
02390 /**
02391   * @brief  Handle IRDA Communication Timeout. It waits
02392   *         until a flag is no longer in the specified status.
02393   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02394   *               the configuration information for the specified IRDA module.
02395   * @param  Flag Specifies the IRDA flag to check.
02396   * @param  Status The actual Flag status (SET or RESET)
02397   * @param  Tickstart Tick start value
02398   * @param  Timeout Timeout duration
02399   * @retval HAL status
02400   */
02401 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status,
02402                                                      uint32_t Tickstart, uint32_t Timeout)
02403 {
02404   /* Wait until flag is set */
02405   while ((__HAL_IRDA_GET_FLAG(hirda, Flag) ? SET : RESET) == Status)
02406   {
02407     /* Check for the Timeout */
02408     if (Timeout != HAL_MAX_DELAY)
02409     {
02410       if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
02411       {
02412         /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error)
02413            interrupts for the interrupt process */
02414         CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE | USART_CR1_TXEIE_TXFNFIE));
02415         CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
02416 
02417         hirda->gState  = HAL_IRDA_STATE_READY;
02418         hirda->RxState = HAL_IRDA_STATE_READY;
02419 
02420         /* Process Unlocked */
02421         __HAL_UNLOCK(hirda);
02422         return HAL_TIMEOUT;
02423       }
02424     }
02425   }
02426   return HAL_OK;
02427 }
02428 
02429 
02430 /**
02431   * @brief  End ongoing Tx transfer on IRDA peripheral (following error detection or Transmit completion).
02432   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02433   *               the configuration information for the specified IRDA module.
02434   * @retval None
02435   */
02436 static void IRDA_EndTxTransfer(IRDA_HandleTypeDef *hirda)
02437 {
02438   /* Disable TXEIE and TCIE interrupts */
02439   CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE));
02440 
02441   /* At end of Tx process, restore hirda->gState to Ready */
02442   hirda->gState = HAL_IRDA_STATE_READY;
02443 }
02444 
02445 
02446 /**
02447   * @brief  End ongoing Rx transfer on UART peripheral (following error detection or Reception completion).
02448   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02449   *               the configuration information for the specified IRDA module.
02450   * @retval None
02451   */
02452 static void IRDA_EndRxTransfer(IRDA_HandleTypeDef *hirda)
02453 {
02454   /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
02455   CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE));
02456   CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
02457 
02458   /* At end of Rx process, restore hirda->RxState to Ready */
02459   hirda->RxState = HAL_IRDA_STATE_READY;
02460 }
02461 
02462 
02463 /**
02464   * @brief  DMA IRDA transmit process complete callback.
02465   * @param  hdma Pointer to a DMA_HandleTypeDef structure that contains
02466   *              the configuration information for the specified DMA module.
02467   * @retval None
02468   */
02469 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
02470 {
02471   IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)(hdma->Parent);
02472 
02473   /* DMA Normal mode */
02474   if (hdma->Init.Mode != DMA_CIRCULAR)
02475   {
02476     hirda->TxXferCount = 0U;
02477 
02478     /* Disable the DMA transfer for transmit request by resetting the DMAT bit
02479        in the IRDA CR3 register */
02480     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
02481 
02482     /* Enable the IRDA Transmit Complete Interrupt */
02483     SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
02484   }
02485   /* DMA Circular mode */
02486   else
02487   {
02488 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02489     /* Call registered Tx complete callback */
02490     hirda->TxCpltCallback(hirda);
02491 #else
02492     /* Call legacy weak Tx complete callback */
02493     HAL_IRDA_TxCpltCallback(hirda);
02494 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02495   }
02496 
02497 }
02498 
02499 /**
02500   * @brief  DMA IRDA transmit process half complete callback.
02501   * @param  hdma Pointer to a DMA_HandleTypeDef structure that contains
02502   *              the configuration information for the specified DMA module.
02503   * @retval None
02504   */
02505 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
02506 {
02507   IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)(hdma->Parent);
02508 
02509 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02510   /* Call registered Tx Half complete callback */
02511   hirda->TxHalfCpltCallback(hirda);
02512 #else
02513   /* Call legacy weak Tx complete callback */
02514   HAL_IRDA_TxHalfCpltCallback(hirda);
02515 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02516 }
02517 
02518 /**
02519   * @brief  DMA IRDA receive process complete callback.
02520   * @param  hdma Pointer to a DMA_HandleTypeDef structure that contains
02521   *               the configuration information for the specified DMA module.
02522   * @retval None
02523   */
02524 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
02525 {
02526   IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)(hdma->Parent);
02527 
02528   /* DMA Normal mode */
02529   if (hdma->Init.Mode != DMA_CIRCULAR)
02530   {
02531     hirda->RxXferCount = 0U;
02532 
02533     /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
02534     CLEAR_BIT(hirda->Instance->CR1, USART_CR1_PEIE);
02535     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
02536 
02537     /* Disable the DMA transfer for the receiver request by resetting the DMAR bit
02538        in the IRDA CR3 register */
02539     CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
02540 
02541     /* At end of Rx process, restore hirda->RxState to Ready */
02542     hirda->RxState = HAL_IRDA_STATE_READY;
02543   }
02544 
02545 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02546   /* Call registered Rx complete callback */
02547   hirda->RxCpltCallback(hirda);
02548 #else
02549   /* Call legacy weak Rx complete callback */
02550   HAL_IRDA_RxCpltCallback(hirda);
02551 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
02552 }
02553 
02554 /**
02555   * @brief DMA IRDA receive process half complete callback.
02556   * @param hdma Pointer to a DMA_HandleTypeDef structure that contains
02557   *              the configuration information for the specified DMA module.
02558   * @retval None
02559   */
02560 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
02561 {
02562   IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)(hdma->Parent);
02563 
02564 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02565   /*Call registered Rx Half complete callback*/
02566   hirda->RxHalfCpltCallback(hirda);
02567 #else
02568   /* Call legacy weak Rx Half complete callback */
02569   HAL_IRDA_RxHalfCpltCallback(hirda);
02570 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02571 }
02572 
02573 /**
02574   * @brief DMA IRDA communication error callback.
02575   * @param hdma Pointer to a DMA_HandleTypeDef structure that contains
02576   *              the configuration information for the specified DMA module.
02577   * @retval None
02578   */
02579 static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
02580 {
02581   IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)(hdma->Parent);
02582 
02583   /* Stop IRDA DMA Tx request if ongoing */
02584   if (hirda->gState == HAL_IRDA_STATE_BUSY_TX)
02585   {
02586     if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAT))
02587     {
02588       hirda->TxXferCount = 0U;
02589       IRDA_EndTxTransfer(hirda);
02590     }
02591   }
02592 
02593   /* Stop IRDA DMA Rx request if ongoing */
02594   if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
02595   {
02596     if (HAL_IS_BIT_SET(hirda->Instance->CR3, USART_CR3_DMAR))
02597     {
02598       hirda->RxXferCount = 0U;
02599       IRDA_EndRxTransfer(hirda);
02600     }
02601   }
02602 
02603   hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
02604 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02605   /* Call registered user error callback */
02606   hirda->ErrorCallback(hirda);
02607 #else
02608   /* Call legacy weak user error callback */
02609   HAL_IRDA_ErrorCallback(hirda);
02610 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02611 }
02612 
02613 /**
02614   * @brief  DMA IRDA communication abort callback, when initiated by HAL services on Error
02615   *         (To be called at end of DMA Abort procedure following error occurrence).
02616   * @param  hdma DMA handle.
02617   * @retval None
02618   */
02619 static void IRDA_DMAAbortOnError(DMA_HandleTypeDef *hdma)
02620 {
02621   IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)(hdma->Parent);
02622   hirda->RxXferCount = 0U;
02623   hirda->TxXferCount = 0U;
02624 
02625 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02626   /* Call registered user error callback */
02627   hirda->ErrorCallback(hirda);
02628 #else
02629   /* Call legacy weak user error callback */
02630   HAL_IRDA_ErrorCallback(hirda);
02631 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02632 }
02633 
02634 /**
02635   * @brief  DMA IRDA Tx communication abort callback, when initiated by user
02636   *         (To be called at end of DMA Tx Abort procedure following user abort request).
02637   * @note   When this callback is executed, User Abort complete call back is called only if no
02638   *         Abort still ongoing for Rx DMA Handle.
02639   * @param  hdma DMA handle.
02640   * @retval None
02641   */
02642 static void IRDA_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
02643 {
02644   IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)(hdma->Parent);
02645 
02646   hirda->hdmatx->XferAbortCallback = NULL;
02647 
02648   /* Check if an Abort process is still ongoing */
02649   if (hirda->hdmarx != NULL)
02650   {
02651     if (hirda->hdmarx->XferAbortCallback != NULL)
02652     {
02653       return;
02654     }
02655   }
02656 
02657   /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
02658   hirda->TxXferCount = 0U;
02659   hirda->RxXferCount = 0U;
02660 
02661   /* Reset errorCode */
02662   hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
02663 
02664   /* Clear the Error flags in the ICR register */
02665   __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_CLEAR_OREF | IRDA_CLEAR_NEF | IRDA_CLEAR_PEF | IRDA_CLEAR_FEF);
02666 
02667   /* Restore hirda->gState and hirda->RxState to Ready */
02668   hirda->gState  = HAL_IRDA_STATE_READY;
02669   hirda->RxState = HAL_IRDA_STATE_READY;
02670 
02671   /* Call user Abort complete callback */
02672 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02673   /* Call registered Abort complete callback */
02674   hirda->AbortCpltCallback(hirda);
02675 #else
02676   /* Call legacy weak Abort complete callback */
02677   HAL_IRDA_AbortCpltCallback(hirda);
02678 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02679 }
02680 
02681 
02682 /**
02683   * @brief  DMA IRDA Rx communication abort callback, when initiated by user
02684   *         (To be called at end of DMA Rx Abort procedure following user abort request).
02685   * @note   When this callback is executed, User Abort complete call back is called only if no
02686   *         Abort still ongoing for Tx DMA Handle.
02687   * @param  hdma DMA handle.
02688   * @retval None
02689   */
02690 static void IRDA_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
02691 {
02692   IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)(hdma->Parent);
02693 
02694   hirda->hdmarx->XferAbortCallback = NULL;
02695 
02696   /* Check if an Abort process is still ongoing */
02697   if (hirda->hdmatx != NULL)
02698   {
02699     if (hirda->hdmatx->XferAbortCallback != NULL)
02700     {
02701       return;
02702     }
02703   }
02704 
02705   /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
02706   hirda->TxXferCount = 0U;
02707   hirda->RxXferCount = 0U;
02708 
02709   /* Reset errorCode */
02710   hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
02711 
02712   /* Clear the Error flags in the ICR register */
02713   __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_CLEAR_OREF | IRDA_CLEAR_NEF | IRDA_CLEAR_PEF | IRDA_CLEAR_FEF);
02714 
02715   /* Restore hirda->gState and hirda->RxState to Ready */
02716   hirda->gState  = HAL_IRDA_STATE_READY;
02717   hirda->RxState = HAL_IRDA_STATE_READY;
02718 
02719   /* Call user Abort complete callback */
02720 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02721   /* Call registered Abort complete callback */
02722   hirda->AbortCpltCallback(hirda);
02723 #else
02724   /* Call legacy weak Abort complete callback */
02725   HAL_IRDA_AbortCpltCallback(hirda);
02726 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02727 }
02728 
02729 
02730 /**
02731   * @brief  DMA IRDA Tx communication abort callback, when initiated by user by a call to
02732   *         HAL_IRDA_AbortTransmit_IT API (Abort only Tx transfer)
02733   *         (This callback is executed at end of DMA Tx Abort procedure following user abort request,
02734   *         and leads to user Tx Abort Complete callback execution).
02735   * @param  hdma DMA handle.
02736   * @retval None
02737   */
02738 static void IRDA_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
02739 {
02740   IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)(hdma->Parent);
02741 
02742   hirda->TxXferCount = 0U;
02743 
02744   /* Restore hirda->gState to Ready */
02745   hirda->gState = HAL_IRDA_STATE_READY;
02746 
02747   /* Call user Abort complete callback */
02748 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02749   /* Call registered Abort Transmit Complete Callback */
02750   hirda->AbortTransmitCpltCallback(hirda);
02751 #else
02752   /* Call legacy weak Abort Transmit Complete Callback */
02753   HAL_IRDA_AbortTransmitCpltCallback(hirda);
02754 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02755 }
02756 
02757 /**
02758   * @brief  DMA IRDA Rx communication abort callback, when initiated by user by a call to
02759   *         HAL_IRDA_AbortReceive_IT API (Abort only Rx transfer)
02760   *         (This callback is executed at end of DMA Rx Abort procedure following user abort request,
02761   *         and leads to user Rx Abort Complete callback execution).
02762   * @param  hdma DMA handle.
02763   * @retval None
02764   */
02765 static void IRDA_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
02766 {
02767   IRDA_HandleTypeDef *hirda = (IRDA_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
02768 
02769   hirda->RxXferCount = 0U;
02770 
02771   /* Clear the Error flags in the ICR register */
02772   __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_CLEAR_OREF | IRDA_CLEAR_NEF | IRDA_CLEAR_PEF | IRDA_CLEAR_FEF);
02773 
02774   /* Restore hirda->RxState to Ready */
02775   hirda->RxState = HAL_IRDA_STATE_READY;
02776 
02777   /* Call user Abort complete callback */
02778 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02779   /* Call registered Abort Receive Complete Callback */
02780   hirda->AbortReceiveCpltCallback(hirda);
02781 #else
02782   /* Call legacy weak Abort Receive Complete Callback */
02783   HAL_IRDA_AbortReceiveCpltCallback(hirda);
02784 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02785 }
02786 
02787 /**
02788   * @brief  Send an amount of data in interrupt mode.
02789   * @note   Function is called under interruption only, once
02790   *         interruptions have been enabled by HAL_IRDA_Transmit_IT().
02791   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02792   *               the configuration information for the specified IRDA module.
02793   * @retval None
02794   */
02795 static void IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
02796 {
02797   const uint16_t *tmp;
02798 
02799   /* Check that a Tx process is ongoing */
02800   if (hirda->gState == HAL_IRDA_STATE_BUSY_TX)
02801   {
02802     if (hirda->TxXferCount == 0U)
02803     {
02804       /* Disable the IRDA Transmit Data Register Empty Interrupt */
02805       CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TXEIE_TXFNFIE);
02806 
02807       /* Enable the IRDA Transmit Complete Interrupt */
02808       SET_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
02809     }
02810     else
02811     {
02812       if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
02813       {
02814         tmp = (const uint16_t *) hirda->pTxBuffPtr; /* Derogation R.11.3 */
02815         hirda->Instance->TDR = (uint16_t)(*tmp & 0x01FFU);
02816         hirda->pTxBuffPtr += 2U;
02817       }
02818       else
02819       {
02820         hirda->Instance->TDR = (uint8_t)(*hirda->pTxBuffPtr & 0xFFU);
02821         hirda->pTxBuffPtr++;
02822       }
02823       hirda->TxXferCount--;
02824     }
02825   }
02826 }
02827 
02828 /**
02829   * @brief  Wrap up transmission in non-blocking mode.
02830   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02831   *               the configuration information for the specified IRDA module.
02832   * @retval None
02833   */
02834 static void IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda)
02835 {
02836   /* Disable the IRDA Transmit Complete Interrupt */
02837   CLEAR_BIT(hirda->Instance->CR1, USART_CR1_TCIE);
02838 
02839   /* Tx process is ended, restore hirda->gState to Ready */
02840   hirda->gState = HAL_IRDA_STATE_READY;
02841 
02842 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02843   /* Call registered Tx complete callback */
02844   hirda->TxCpltCallback(hirda);
02845 #else
02846   /* Call legacy weak Tx complete callback */
02847   HAL_IRDA_TxCpltCallback(hirda);
02848 #endif /* USE_HAL_IRDA_REGISTER_CALLBACK */
02849 }
02850 
02851 /**
02852   * @brief  Receive an amount of data in interrupt mode.
02853   * @note   Function is called under interruption only, once
02854   *         interruptions have been enabled by HAL_IRDA_Receive_IT()
02855   * @param  hirda Pointer to a IRDA_HandleTypeDef structure that contains
02856   *               the configuration information for the specified IRDA module.
02857   * @retval None
02858   */
02859 static void IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
02860 {
02861   uint16_t *tmp;
02862   uint16_t  uhMask = hirda->Mask;
02863   uint16_t  uhdata;
02864 
02865   /* Check that a Rx process is ongoing */
02866   if (hirda->RxState == HAL_IRDA_STATE_BUSY_RX)
02867   {
02868     uhdata = (uint16_t) READ_REG(hirda->Instance->RDR);
02869     if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
02870     {
02871       tmp = (uint16_t *) hirda->pRxBuffPtr; /* Derogation R.11.3 */
02872       *tmp = (uint16_t)(uhdata & uhMask);
02873       hirda->pRxBuffPtr  += 2U;
02874     }
02875     else
02876     {
02877       *hirda->pRxBuffPtr = (uint8_t)(uhdata & (uint8_t)uhMask);
02878       hirda->pRxBuffPtr++;
02879     }
02880 
02881     hirda->RxXferCount--;
02882     if (hirda->RxXferCount == 0U)
02883     {
02884       /* Disable the IRDA Parity Error Interrupt and RXNE interrupt */
02885       CLEAR_BIT(hirda->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE));
02886 
02887       /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
02888       CLEAR_BIT(hirda->Instance->CR3, USART_CR3_EIE);
02889 
02890       /* Rx process is completed, restore hirda->RxState to Ready */
02891       hirda->RxState = HAL_IRDA_STATE_READY;
02892 
02893 #if (USE_HAL_IRDA_REGISTER_CALLBACKS == 1)
02894       /* Call registered Rx complete callback */
02895       hirda->RxCpltCallback(hirda);
02896 #else
02897       /* Call legacy weak Rx complete callback */
02898       HAL_IRDA_RxCpltCallback(hirda);
02899 #endif /* USE_HAL_IRDA_REGISTER_CALLBACKS */
02900     }
02901   }
02902   else
02903   {
02904     /* Clear RXNE interrupt flag */
02905     __HAL_IRDA_SEND_REQ(hirda, IRDA_RXDATA_FLUSH_REQUEST);
02906   }
02907 }
02908 
02909 /**
02910   * @}
02911   */
02912 
02913 #endif /* HAL_IRDA_MODULE_ENABLED */
02914 /**
02915   * @}
02916   */
02917 
02918 /**
02919   * @}
02920   */
02921 
02922