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