2 ******************************************************************************
3 * @file stm32f4xx_hal_irda.c
4 * @author MCD Application Team
7 * @brief IRDA HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the IrDA SIR ENDEC block (IrDA):
10 * + Initialization and de-initialization methods
11 * + IO operation methods
12 * + Peripheral Control methods
15 ==============================================================================
16 ##### How to use this driver #####
17 ==============================================================================
19 The IRDA HAL driver can be used as follows:
21 (#) Declare a IRDA_HandleTypeDef handle structure.
22 (#) Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API:
23 (##) Enable the USARTx interface clock.
24 (##) IRDA pins configuration:
25 (+++) Enable the clock for the IRDA GPIOs.
26 (+++) Configure these IRDA pins as alternate function pull-up.
27 (##) NVIC configuration if you need to use interrupt process (HAL_IRDA_Transmit_IT()
28 and HAL_IRDA_Receive_IT() APIs):
29 (+++) Configure the USARTx interrupt priority.
30 (+++) Enable the NVIC USART IRQ handle.
31 (##) DMA Configuration if you need to use DMA process (HAL_IRDA_Transmit_DMA()
32 and HAL_IRDA_Receive_DMA() APIs):
33 (+++) Declare a DMA handle structure for the Tx/Rx stream.
34 (+++) Enable the DMAx interface clock.
35 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
36 (+++) Configure the DMA Tx/Rx Stream.
37 (+++) Associate the initilalized DMA handle to the IRDA DMA Tx/Rx handle.
38 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream.
40 (#) Program the Baud Rate, Word Length, Parity, IrDA Mode, Prescaler
41 and Mode(Receiver/Transmitter) in the hirda Init structure.
43 (#) Initialize the IRDA registers by calling the HAL_IRDA_Init() API:
44 (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
45 by calling the customed HAL_IRDA_MspInit() API.
46 -@@- The specific IRDA interrupts (Transmission complete interrupt,
47 RXNE interrupt and Error Interrupts) will be managed using the macros
48 __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.
50 (#) Three operation modes are available within this driver :
52 *** Polling mode IO operation ***
53 =================================
55 (+) Send an amount of data in blocking mode using HAL_IRDA_Transmit()
56 (+) Receive an amount of data in blocking mode using HAL_IRDA_Receive()
58 *** Interrupt mode IO operation ***
59 ===================================
61 (+) Send an amount of data in non blocking mode using HAL_IRDA_Transmit_IT()
62 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can
63 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback
64 (+) Receive an amount of data in non blocking mode using HAL_IRDA_Receive_IT()
65 (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can
66 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback
67 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
68 add his own code by customization of function pointer HAL_IRDA_ErrorCallback
70 *** DMA mode IO operation ***
71 =============================
73 (+) Send an amount of data in non blocking mode (DMA) using HAL_IRDA_Transmit_DMA()
74 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can
75 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback
76 (+) Receive an amount of data in non blocking mode (DMA) using HAL_IRDA_Receive_DMA()
77 (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can
78 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback
79 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
80 add his own code by customization of function pointer HAL_IRDA_ErrorCallback
82 *** IRDA HAL driver macros list ***
83 ===================================
85 Below the list of most used macros in IRDA HAL driver.
87 (+) __HAL_IRDA_ENABLE: Enable the IRDA peripheral
88 (+) __HAL_IRDA_DISABLE: Disable the IRDA peripheral
89 (+) __HAL_IRDA_GET_FLAG : Checks whether the specified IRDA flag is set or not
90 (+) __HAL_IRDA_CLEAR_FLAG : Clears the specified IRDA pending flag
91 (+) __HAL_IRDA_ENABLE_IT: Enables the specified IRDA interrupt
92 (+) __HAL_IRDA_DISABLE_IT: Disables the specified IRDA interrupt
94 (@) You can refer to the IRDA HAL driver header file for more useful macros
97 ******************************************************************************
100 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
102 * Redistribution and use in source and binary forms, with or without modification,
103 * are permitted provided that the following conditions are met:
104 * 1. Redistributions of source code must retain the above copyright notice,
105 * this list of conditions and the following disclaimer.
106 * 2. Redistributions in binary form must reproduce the above copyright notice,
107 * this list of conditions and the following disclaimer in the documentation
108 * and/or other materials provided with the distribution.
109 * 3. Neither the name of STMicroelectronics nor the names of its contributors
110 * may be used to endorse or promote products derived from this software
111 * without specific prior written permission.
113 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
114 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
115 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
116 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
117 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
118 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
119 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
120 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
121 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
122 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
124 ******************************************************************************
127 /* Includes ------------------------------------------------------------------*/
128 #include "stm32f4xx_hal.h"
130 /** @addtogroup STM32F4xx_HAL_Driver
135 * @brief HAL IRDA module driver
139 #ifdef HAL_IRDA_MODULE_ENABLED
141 /* Private typedef -----------------------------------------------------------*/
142 /* Private define ------------------------------------------------------------*/
143 #define IRDA_TIMEOUT_VALUE 22000
144 /* Private macro -------------------------------------------------------------*/
145 /* Private variables ---------------------------------------------------------*/
146 /* Private function prototypes -----------------------------------------------*/
147 static void IRDA_SetConfig (IRDA_HandleTypeDef *hirda);
148 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
149 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
150 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
151 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma);
152 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
153 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma);
154 static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
155 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
157 /* Private functions ---------------------------------------------------------*/
159 /** @defgroup IRDA_Private_Functions
163 /** @defgroup IRDA_Group1 IrDA Initialization and de-initialization functions
164 * @brief Initialization and Configuration functions
168 ===============================================================================
169 ##### Initialization and Configuration functions #####
170 ===============================================================================
172 This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
174 (+) For the asynchronous mode only these parameters can be configured:
177 (++) Parity: If the parity is enabled, then the MSB bit of the data written
178 in the data register is transmitted but is changed by the parity bit.
179 Depending on the frame length defined by the M bit (8-bits or 9-bits),
180 please refer to Reference manual for possible IRDA frame formats.
181 (++) Prescaler: A pulse of width less than two and greater than one PSC period(s) may or may
182 not be rejected. The receiver set up time should be managed by software. The IrDA physical layer
183 specification specifies a minimum of 10 ms delay between transmission and
184 reception (IrDA is a half duplex protocol).
185 (++) Mode: Receiver/transmitter modes
186 (++) IrDAMode: the IrDA can operate in the Normal mode or in the Low power mode.
188 The HAL_IRDA_Init() API follows IRDA configuration procedures (details for the procedures
189 are available in reference manual).
196 * @brief Initializes the IRDA mode according to the specified
197 * parameters in the IRDA_InitTypeDef and create the associated handle.
198 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
199 * the configuration information for the specified IRDA module.
202 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
204 /* Check the IRDA handle allocation */
205 if(hirda == HAL_NULL)
210 /* Check the IRDA instance parameters */
211 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
212 /* Check the IRDA mode parameter in the IRDA handle */
213 assert_param(IS_IRDA_POWERMODE(hirda->Init.IrDAMode));
215 if(hirda->State == HAL_IRDA_STATE_RESET)
217 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
218 HAL_IRDA_MspInit(hirda);
221 hirda->State = HAL_IRDA_STATE_BUSY;
223 /* Disable the IRDA peripheral */
224 __IRDA_DISABLE(hirda);
226 /* Set the IRDA communication parameters */
227 IRDA_SetConfig(hirda);
229 /* In IrDA mode, the following bits must be kept cleared:
230 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
231 - SCEN and HDSEL bits in the USART_CR3 register.*/
232 hirda->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_STOP | USART_CR2_CLKEN);
233 hirda->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL);
235 /* Enable the IRDA peripheral */
236 __IRDA_ENABLE(hirda);
238 /* Set the prescaler */
239 MODIFY_REG(hirda->Instance->GTPR, USART_GTPR_PSC, hirda->Init.Prescaler);
241 /* Configure the IrDA mode */
242 MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.IrDAMode);
244 /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
245 hirda->Instance->CR3 |= USART_CR3_IREN;
247 /* Initialize the IRDA state*/
248 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
249 hirda->State= HAL_IRDA_STATE_READY;
255 * @brief DeInitializes the IRDA peripheral
256 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
257 * the configuration information for the specified IRDA module.
260 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
262 /* Check the IRDA handle allocation */
263 if(hirda == HAL_NULL)
268 /* Check the parameters */
269 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
271 hirda->State = HAL_IRDA_STATE_BUSY;
273 /* DeInit the low level hardware */
274 HAL_IRDA_MspDeInit(hirda);
276 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
278 hirda->State = HAL_IRDA_STATE_RESET;
287 * @brief IRDA MSP Init.
288 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
289 * the configuration information for the specified IRDA module.
292 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
294 /* NOTE : This function Should not be modified, when the callback is needed,
295 the HAL_IRDA_MspInit could be implenetd in the user file
300 * @brief IRDA MSP DeInit.
301 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
302 * the configuration information for the specified IRDA module.
305 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
307 /* NOTE : This function Should not be modified, when the callback is needed,
308 the HAL_IRDA_MspDeInit could be implenetd in the user file
316 /** @defgroup IRDA_Group2 IO operation functions
317 * @brief IRDA Transmit/Receive functions
320 ===============================================================================
321 ##### IO operation functions #####
322 ===============================================================================
323 This subsection provides a set of functions allowing to manage the IRDA data transfers.
325 IrDA is a half duplex communication protocol. If the Transmitter is busy, any data
326 on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver
327 is busy, data on the TX from the USART to IrDA will not be encoded by IrDA.
328 While receiving data, transmission should be avoided as the data to be transmitted
331 (#) There are two modes of transfer:
332 (++) Blocking mode: The communication is performed in polling mode.
333 The HAL status of all data processing is returned by the same function
334 after finishing transfer.
335 (++) No-Blocking mode: The communication is performed using Interrupts
336 or DMA, These APIs return the HAL status.
337 The end of the data processing will be indicated through the
338 dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when
340 The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks
341 will be executed respectivelly at the end of the transmit or Receive process
342 The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected
344 (#) Blocking mode API's are :
345 (++) HAL_IRDA_Transmit()
346 (++) HAL_IRDA_Receive()
348 (#) Non Blocking mode APIs with Interrupt are :
349 (++) HAL_IRDA_Transmit_IT()
350 (++) HAL_IRDA_Receive_IT()
351 (++) HAL_IRDA_IRQHandler()
353 (#) Non Blocking mode functions with DMA are :
354 (++) HAL_IRDA_Transmit_DMA()
355 (++) HAL_IRDA_Receive_DMA()
357 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
358 (++) HAL_IRDA_TxCpltCallback()
359 (++) HAL_IRDA_RxCpltCallback()
360 (++) HAL_IRDA_ErrorCallback()
367 * @brief Sends an amount of data in blocking mode.
368 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
369 * the configuration information for the specified IRDA module.
370 * @param pData: Pointer to data buffer
371 * @param Size: Amount of data to be sent
372 * @param Timeout: Specify timeout value
375 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
381 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_RX))
383 if((pData == HAL_NULL) || (Size == 0))
391 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
392 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
394 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
398 hirda->State = HAL_IRDA_STATE_BUSY_TX;
401 hirda->TxXferSize = Size;
402 hirda->TxXferCount = Size;
403 while(hirda->TxXferCount > 0)
405 hirda->TxXferCount--;
406 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
408 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, Timeout) != HAL_OK)
412 tmp = (uint16_t*) pData;
413 hirda->Instance->DR = (*tmp & (uint16_t)0x01FF);
414 if(hirda->Init.Parity == IRDA_PARITY_NONE)
425 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, Timeout) != HAL_OK)
429 hirda->Instance->DR = (*pData++ & (uint8_t)0xFF);
433 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, Timeout) != HAL_OK)
438 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
440 hirda->State = HAL_IRDA_STATE_BUSY_RX;
444 hirda->State = HAL_IRDA_STATE_READY;
447 /* Process Unlocked */
459 * @brief Receive an amount of data in blocking mode.
460 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
461 * the configuration information for the specified IRDA module.
462 * @param pData: Pointer to data buffer
463 * @param Size: Amount of data to be received
464 * @param Timeout: Specify timeout value
467 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
473 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_TX))
475 if((pData == HAL_NULL) || (Size == 0))
483 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
484 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
486 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
490 hirda->State = HAL_IRDA_STATE_BUSY_RX;
492 hirda->RxXferSize = Size;
493 hirda->RxXferCount = Size;
494 /* Check the remain data to be received */
495 while(hirda->RxXferCount > 0)
497 hirda->RxXferCount--;
498 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
500 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, Timeout) != HAL_OK)
504 tmp = (uint16_t*) pData ;
505 if(hirda->Init.Parity == IRDA_PARITY_NONE)
507 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x01FF);
512 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x00FF);
518 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, Timeout) != HAL_OK)
522 if(hirda->Init.Parity == IRDA_PARITY_NONE)
524 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x00FF);
528 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x007F);
532 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
534 hirda->State = HAL_IRDA_STATE_BUSY_TX;
538 hirda->State = HAL_IRDA_STATE_READY;
541 /* Process Unlocked */
553 * @brief Send an amount of data in non blocking mode.
554 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
555 * the configuration information for the specified IRDA module.
556 * @param pData: Pointer to data buffer
557 * @param Size: Amount of data to be sent
560 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
565 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_RX))
567 if((pData == HAL_NULL) || (Size == 0))
574 hirda->pTxBuffPtr = pData;
575 hirda->TxXferSize = Size;
576 hirda->TxXferCount = Size;
577 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
578 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
580 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
584 hirda->State = HAL_IRDA_STATE_BUSY_TX;
587 /* Enable the IRDA Parity Error Interrupt */
588 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_PE);
590 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
591 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
593 /* Process Unlocked */
596 /* Enable the IRDA Transmit Data Register Empty Interrupt */
597 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TXE);
608 * @brief Receives an amount of data in non blocking mode.
609 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
610 * the configuration information for the specified IRDA module.
611 * @param pData: Pointer to data buffer
612 * @param Size: Amount of data to be received
615 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
620 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_TX))
622 if((pData == HAL_NULL) || (Size == 0))
630 hirda->pRxBuffPtr = pData;
631 hirda->RxXferSize = Size;
632 hirda->RxXferCount = Size;
633 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
634 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
636 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
640 hirda->State = HAL_IRDA_STATE_BUSY_RX;
643 /* Enable the IRDA Data Register not empty Interrupt */
644 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_RXNE);
646 /* Enable the IRDA Parity Error Interrupt */
647 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_PE);
649 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
650 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
652 /* Process Unlocked */
664 * @brief Sends an amount of data in non blocking mode.
665 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
666 * the configuration information for the specified IRDA module.
667 * @param pData: Pointer to data buffer
668 * @param Size: Amount of data to be sent
671 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
677 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_RX))
679 if((pData == HAL_NULL) || (Size == 0))
687 hirda->pTxBuffPtr = pData;
688 hirda->TxXferSize = Size;
689 hirda->TxXferCount = Size;
690 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
692 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
694 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
698 hirda->State = HAL_IRDA_STATE_BUSY_TX;
701 /* Set the IRDA DMA transfert complete callback */
702 hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
704 /* Set the IRDA DMA half transfert complete callback */
705 hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
707 /* Set the DMA error callback */
708 hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
710 /* Enable the IRDA transmit DMA Stream */
711 tmp = (uint32_t*)&pData;
712 HAL_DMA_Start_IT(hirda->hdmatx, *(uint32_t*)tmp, (uint32_t)&hirda->Instance->DR, Size);
714 /* Enable the DMA transfer for transmit request by setting the DMAT bit
715 in the USART CR3 register */
716 hirda->Instance->CR3 |= USART_CR3_DMAT;
718 /* Process Unlocked */
730 * @brief Receives an amount of data in non blocking mode.
731 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
732 * the configuration information for the specified IRDA module.
733 * @param pData: Pointer to data buffer
734 * @param Size: Amount of data to be received
735 * @note When the IRDA parity is enabled (PCE = 1) the data received contain the parity bit.
738 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
744 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_TX))
746 if((pData == HAL_NULL) || (Size == 0))
754 hirda->pRxBuffPtr = pData;
755 hirda->RxXferSize = Size;
756 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
757 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
759 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
763 hirda->State = HAL_IRDA_STATE_BUSY_RX;
766 /* Set the IRDA DMA transfert complete callback */
767 hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
769 /* Set the IRDA DMA half transfert complete callback */
770 hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
772 /* Set the DMA error callback */
773 hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
775 /* Enable the DMA Stream */
776 tmp = (uint32_t*)&pData;
777 HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->DR, *(uint32_t*)tmp, Size);
779 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
780 in the USART CR3 register */
781 hirda->Instance->CR3 |= USART_CR3_DMAR;
783 /* Process Unlocked */
795 * @brief Pauses the DMA Transfer.
796 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
797 * the configuration information for the specified IRDA module.
800 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
805 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
807 /* Disable the UART DMA Tx request */
808 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
810 else if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
812 /* Disable the UART DMA Rx request */
813 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
815 else if (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
817 /* Disable the UART DMA Tx & Rx requests */
818 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
819 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
822 /* Process Unlocked */
829 * @brief Resumes the DMA Transfer.
830 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
831 * the configuration information for the specified UART module.
834 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
839 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
841 /* Enable the UART DMA Tx request */
842 hirda->Instance->CR3 |= USART_CR3_DMAT;
844 else if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
846 /* Clear the Overrun flag before resumming the Rx transfer*/
847 __HAL_IRDA_CLEAR_OREFLAG(hirda);
848 /* Enable the UART DMA Rx request */
849 hirda->Instance->CR3 |= USART_CR3_DMAR;
851 else if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
853 /* Clear the Overrun flag before resumming the Rx transfer*/
854 __HAL_IRDA_CLEAR_OREFLAG(hirda);
855 /* Enable the UART DMA Tx & Rx request */
856 hirda->Instance->CR3 |= USART_CR3_DMAT;
857 hirda->Instance->CR3 |= USART_CR3_DMAR;
860 /* Process Unlocked */
867 * @brief Stops the DMA Transfer.
868 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
869 * the configuration information for the specified UART module.
872 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
874 /* The Lock is not implemented on this API to allow the user application
875 to call the HAL UART API under callbacks HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback():
876 when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
877 and the correspond call back is executed HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback()
880 /* Disable the UART Tx/Rx DMA requests */
881 hirda->Instance->CR3 &= ~USART_CR3_DMAT;
882 hirda->Instance->CR3 &= ~USART_CR3_DMAR;
884 /* Abort the UART DMA tx Stream */
885 if(hirda->hdmatx != HAL_NULL)
887 HAL_DMA_Abort(hirda->hdmatx);
889 /* Abort the UART DMA rx Stream */
890 if(hirda->hdmarx != HAL_NULL)
892 HAL_DMA_Abort(hirda->hdmarx);
895 hirda->State = HAL_IRDA_STATE_READY;
901 * @brief This function handles IRDA interrupt request.
902 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
903 * the configuration information for the specified IRDA module.
906 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
908 uint32_t tmp1 = 0, tmp2 =0;
910 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_PE);
911 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE);
912 /* IRDA parity error interrupt occurred -------------------------------------*/
913 if((tmp1 != RESET) && (tmp2 != RESET))
915 __HAL_IRDA_CLEAR_PEFLAG(hirda);
916 hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
919 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_FE);
920 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
921 /* IRDA frame error interrupt occurred --------------------------------------*/
922 if((tmp1 != RESET) && (tmp2 != RESET))
924 __HAL_IRDA_CLEAR_FEFLAG(hirda);
925 hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
928 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_NE);
929 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
930 /* IRDA noise error interrupt occurred --------------------------------------*/
931 if((tmp1 != RESET) && (tmp2 != RESET))
933 __HAL_IRDA_CLEAR_NEFLAG(hirda);
934 hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
937 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_ORE);
938 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
939 /* IRDA Over-Run interrupt occurred -----------------------------------------*/
940 if((tmp1 != RESET) && (tmp2 != RESET))
942 __HAL_IRDA_CLEAR_OREFLAG(hirda);
943 hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
946 /* Call the Error call Back in case of Errors */
947 if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
949 /* Set the IRDA state ready to be able to start again the process */
950 hirda->State = HAL_IRDA_STATE_READY;
951 HAL_IRDA_ErrorCallback(hirda);
954 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_RXNE);
955 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_RXNE);
956 /* IRDA in mode Receiver ---------------------------------------------------*/
957 if((tmp1 != RESET) && (tmp2 != RESET))
959 IRDA_Receive_IT(hirda);
962 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_TXE);
963 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TXE);
964 /* IRDA in mode Transmitter ------------------------------------------------*/
965 if((tmp1 != RESET) &&(tmp2 != RESET))
967 IRDA_Transmit_IT(hirda);
972 * @brief Tx Transfer complete callbacks.
973 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
974 * the configuration information for the specified IRDA module.
977 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
979 /* NOTE : This function Should not be modified, when the callback is needed,
980 the HAL_IRDA_TxCpltCallback could be implemented in the user file
985 * @brief Tx Half Transfer completed callbacks.
986 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
987 * the configuration information for the specified USART module.
990 __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
992 /* NOTE: This function Should not be modified, when the callback is needed,
993 the HAL_IRDA_TxHalfCpltCallback could be implemented in the user file
998 * @brief Rx Transfer complete callbacks.
999 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
1000 * the configuration information for the specified IRDA module.
1003 __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
1005 /* NOTE : This function Should not be modified, when the callback is needed,
1006 the HAL_IRDA_RxCpltCallback could be implemented in the user file
1011 * @brief Rx Half Transfer complete callbacks.
1012 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
1013 * the configuration information for the specified IRDA module.
1016 __weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
1018 /* NOTE : This function Should not be modified, when the callback is needed,
1019 the HAL_IRDA_RxHalfCpltCallback could be implemented in the user file
1024 * @brief IRDA error callbacks.
1025 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
1026 * the configuration information for the specified IRDA module.
1029 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
1031 /* NOTE : This function Should not be modified, when the callback is needed,
1032 the HAL_IRDA_ErrorCallback could be implemented in the user file
1040 /** @defgroup IRDA_Group3 Peripheral State and Errors functions
1041 * @brief IRDA State and Errors functions
1044 ==============================================================================
1045 ##### Peripheral State and Errors functions #####
1046 ==============================================================================
1048 This subsection provides a set of functions allowing to return the State of IrDA
1049 communication process and also return Peripheral Errors occurred during communication process
1050 (+) HAL_IRDA_GetState() API can be helpful to check in run-time the state of the IrDA peripheral.
1051 (+) HAL_IRDA_GetError() check in run-time errors that could be occurred during communication.
1058 * @brief Returns the IRDA state.
1059 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
1060 * the configuration information for the specified IRDA module.
1063 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda)
1065 return hirda->State;
1069 * @brief Return the IARDA error code
1070 * @param hirda : pointer to a IRDA_HandleTypeDef structure that contains
1071 * the configuration information for the specified IRDA.
1072 * @retval IRDA Error Code
1074 uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda)
1076 return hirda->ErrorCode;
1084 * @brief DMA IRDA transmit process complete callback.
1085 * @param hdma : DMA handle
1088 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
1090 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1091 /* DMA Normal mode */
1092 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
1094 hirda->TxXferCount = 0;
1096 /* Disable the DMA transfer for transmit request by setting the DMAT bit
1097 in the IRDA CR3 register */
1098 hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAT);
1100 /* Wait for IRDA TC Flag */
1101 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, IRDA_TIMEOUT_VALUE) != HAL_OK)
1103 /* Timeout occurred */
1104 hirda->State = HAL_IRDA_STATE_TIMEOUT;
1105 HAL_IRDA_ErrorCallback(hirda);
1110 /* Check if a receive process is ongoing or not */
1111 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
1113 hirda->State = HAL_IRDA_STATE_BUSY_RX;
1117 hirda->State = HAL_IRDA_STATE_READY;
1119 HAL_IRDA_TxCpltCallback(hirda);
1122 /* DMA Circular mode */
1125 HAL_IRDA_TxCpltCallback(hirda);
1130 * @brief DMA IRDA receive process half complete callback
1131 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1132 * the configuration information for the specified DMA module.
1135 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
1137 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1139 HAL_IRDA_TxHalfCpltCallback(hirda);
1143 * @brief DMA IRDA receive process complete callback.
1144 * @param hdma: DMA handle
1147 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
1149 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1150 /* DMA Normal mode */
1151 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
1153 hirda->RxXferCount = 0;
1155 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
1156 in the IRDA CR3 register */
1157 hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAR);
1159 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
1161 hirda->State = HAL_IRDA_STATE_BUSY_TX;
1165 hirda->State = HAL_IRDA_STATE_READY;
1169 HAL_IRDA_RxCpltCallback(hirda);
1173 * @brief DMA IRDA receive process half complete callback
1174 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1175 * the configuration information for the specified DMA module.
1178 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
1180 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1182 HAL_IRDA_RxHalfCpltCallback(hirda);
1186 * @brief DMA IRDA communication error callback.
1187 * @param hdma: DMA handle
1190 static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
1192 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1194 hirda->RxXferCount = 0;
1195 hirda->TxXferCount = 0;
1196 hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
1197 hirda->State= HAL_IRDA_STATE_READY;
1199 HAL_IRDA_ErrorCallback(hirda);
1203 * @brief This function handles IRDA Communication Timeout.
1204 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
1205 * the configuration information for the specified IRDA module.
1206 * @param Flag: specifies the IRDA flag to check.
1207 * @param Status: The new Flag status (SET or RESET).
1208 * @param Timeout: Timeout duration
1209 * @retval HAL status
1211 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
1213 uint32_t tickstart = 0;
1216 tickstart = HAL_GetTick();
1218 /* Wait until flag is set */
1221 while(__HAL_IRDA_GET_FLAG(hirda, Flag) == RESET)
1223 /* Check for the Timeout */
1224 if(Timeout != HAL_MAX_DELAY)
1226 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1228 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
1229 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
1230 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
1231 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
1232 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
1234 hirda->State= HAL_IRDA_STATE_READY;
1236 /* Process Unlocked */
1237 __HAL_UNLOCK(hirda);
1246 while(__HAL_IRDA_GET_FLAG(hirda, Flag) != RESET)
1248 /* Check for the Timeout */
1249 if(Timeout != HAL_MAX_DELAY)
1251 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1253 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
1254 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
1255 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
1256 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
1257 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
1259 hirda->State= HAL_IRDA_STATE_READY;
1261 /* Process Unlocked */
1262 __HAL_UNLOCK(hirda);
1273 * @brief Send an amount of data in non blocking mode.
1274 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
1275 * the configuration information for the specified IRDA module.
1276 * @retval HAL status
1278 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
1283 tmp1 = hirda->State;
1284 if((tmp1 == HAL_IRDA_STATE_BUSY_TX) || (tmp1 == HAL_IRDA_STATE_BUSY_TX_RX))
1286 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
1288 tmp = (uint16_t*) hirda->pTxBuffPtr;
1289 hirda->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
1290 if(hirda->Init.Parity == IRDA_PARITY_NONE)
1292 hirda->pTxBuffPtr += 2;
1296 hirda->pTxBuffPtr += 1;
1301 hirda->Instance->DR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0x00FF);
1304 if(--hirda->TxXferCount == 0)
1306 /* Disable the IRDA Transmit Data Register Empty Interrupt */
1307 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
1309 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
1311 hirda->State = HAL_IRDA_STATE_BUSY_RX;
1315 /* Disable the IRDA Parity Error Interrupt */
1316 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
1318 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
1319 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
1321 hirda->State = HAL_IRDA_STATE_READY;
1323 /* Wait on TC flag to be able to start a second transfer */
1324 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, IRDA_TIMEOUT_VALUE) != HAL_OK)
1328 HAL_IRDA_TxCpltCallback(hirda);
1342 * @brief Receives an amount of data in non blocking mode.
1343 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
1344 * the configuration information for the specified IRDA module.
1345 * @retval HAL status
1347 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
1352 tmp1 = hirda->State;
1353 if((tmp1 == HAL_IRDA_STATE_BUSY_RX) || (tmp1 == HAL_IRDA_STATE_BUSY_TX_RX))
1355 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
1357 tmp = (uint16_t*) hirda->pRxBuffPtr;
1358 if(hirda->Init.Parity == IRDA_PARITY_NONE)
1360 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x01FF);
1361 hirda->pRxBuffPtr += 2;
1365 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x00FF);
1366 hirda->pRxBuffPtr += 1;
1371 if(hirda->Init.Parity == IRDA_PARITY_NONE)
1373 *hirda->pRxBuffPtr++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x00FF);
1377 *hirda->pRxBuffPtr++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x007F);
1381 if(--hirda->RxXferCount == 0)
1384 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
1386 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
1388 hirda->State = HAL_IRDA_STATE_BUSY_TX;
1392 /* Disable the IRDA Parity Error Interrupt */
1393 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
1395 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
1396 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
1398 hirda->State = HAL_IRDA_STATE_READY;
1400 HAL_IRDA_RxCpltCallback(hirda);
1413 * @brief Configures the IRDA peripheral.
1414 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
1415 * the configuration information for the specified IRDA module.
1418 static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
1420 uint32_t tmpreg = 0x00;
1422 /* Check the parameters */
1423 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
1424 assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
1425 assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
1426 assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
1427 assert_param(IS_IRDA_MODE(hirda->Init.Mode));
1429 /*-------------------------- IRDA CR2 Configuration ------------------------*/
1430 /* Clear STOP[13:12] bits */
1431 hirda->Instance->CR2 &= (uint32_t)~((uint32_t)USART_CR2_STOP);
1433 /*-------------------------- USART CR1 Configuration -----------------------*/
1434 tmpreg = hirda->Instance->CR1;
1436 /* Clear M, PCE, PS, TE and RE bits */
1437 tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | \
1440 /* Configure the USART Word Length, Parity and mode:
1441 Set the M bits according to hirda->Init.WordLength value
1442 Set PCE and PS bits according to hirda->Init.Parity value
1443 Set TE and RE bits according to hirda->Init.Mode value */
1444 tmpreg |= (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode;
1446 /* Write to USART CR1 */
1447 hirda->Instance->CR1 = (uint32_t)tmpreg;
1449 /*-------------------------- USART CR3 Configuration -----------------------*/
1450 /* Clear CTSE and RTSE bits */
1451 hirda->Instance->CR3 &= (uint32_t)~((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE));
1453 /*-------------------------- USART BRR Configuration -----------------------*/
1454 if((hirda->Instance == USART1) || (hirda->Instance == USART6))
1456 hirda->Instance->BRR = __IRDA_BRR(HAL_RCC_GetPCLK2Freq(), hirda->Init.BaudRate);
1460 hirda->Instance->BRR = __IRDA_BRR(HAL_RCC_GetPCLK1Freq(), hirda->Init.BaudRate);
1471 #endif /* HAL_IRDA_MODULE_ENABLED */
1477 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/