2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_irda.c
\r
4 * @author MCD Application Team
\r
6 * @date 06-March-2015
\r
7 * @brief IRDA HAL module driver.
\r
8 * This file provides firmware functions to manage the following
\r
9 * functionalities of the IrDA SIR ENDEC block (IrDA):
\r
10 * + Initialization and de-initialization methods
\r
11 * + IO operation methods
\r
12 * + Peripheral Control methods
\r
15 ==============================================================================
\r
16 ##### How to use this driver #####
\r
17 ==============================================================================
\r
19 The IRDA HAL driver can be used as follows:
\r
21 (#) Declare a IRDA_HandleTypeDef handle structure.
\r
22 (#) Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API:
\r
23 (##) Enable the USARTx interface clock.
\r
24 (##) IRDA pins configuration:
\r
25 (+++) Enable the clock for the IRDA GPIOs.
\r
26 (+++) Configure these IRDA pins as alternate function pull-up.
\r
27 (##) NVIC configuration if you need to use interrupt process (HAL_IRDA_Transmit_IT()
\r
28 and HAL_IRDA_Receive_IT() APIs):
\r
29 (+++) Configure the USARTx interrupt priority.
\r
30 (+++) Enable the NVIC USART IRQ handle.
\r
31 (##) DMA Configuration if you need to use DMA process (HAL_IRDA_Transmit_DMA()
\r
32 and HAL_IRDA_Receive_DMA() APIs):
\r
33 (+++) Declare a DMA handle structure for the Tx/Rx stream.
\r
34 (+++) Enable the DMAx interface clock.
\r
35 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
\r
36 (+++) Configure the DMA Tx/Rx Stream.
\r
37 (+++) Associate the initialized DMA handle to the IRDA DMA Tx/Rx handle.
\r
38 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream.
\r
40 (#) Program the Baud Rate, Word Length, Parity, IrDA Mode, Prescaler
\r
41 and Mode(Receiver/Transmitter) in the hirda Init structure.
\r
43 (#) Initialize the IRDA registers by calling the HAL_IRDA_Init() API:
\r
44 (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
\r
45 by calling the customized HAL_IRDA_MspInit() API.
\r
46 -@@- The specific IRDA interrupts (Transmission complete interrupt,
\r
47 RXNE interrupt and Error Interrupts) will be managed using the macros
\r
48 __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.
\r
50 (#) Three operation modes are available within this driver :
\r
52 *** Polling mode IO operation ***
\r
53 =================================
\r
55 (+) Send an amount of data in blocking mode using HAL_IRDA_Transmit()
\r
56 (+) Receive an amount of data in blocking mode using HAL_IRDA_Receive()
\r
58 *** Interrupt mode IO operation ***
\r
59 ===================================
\r
61 (+) Send an amount of data in non blocking mode using HAL_IRDA_Transmit_IT()
\r
62 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can
\r
63 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback
\r
64 (+) Receive an amount of data in non blocking mode using HAL_IRDA_Receive_IT()
\r
65 (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can
\r
66 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback
\r
67 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
\r
68 add his own code by customization of function pointer HAL_IRDA_ErrorCallback
\r
70 *** DMA mode IO operation ***
\r
71 =============================
\r
73 (+) Send an amount of data in non blocking mode (DMA) using HAL_IRDA_Transmit_DMA()
\r
74 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can
\r
75 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback
\r
76 (+) Receive an amount of data in non blocking mode (DMA) using HAL_IRDA_Receive_DMA()
\r
77 (+) At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can
\r
78 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback
\r
79 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
\r
80 add his own code by customization of function pointer HAL_IRDA_ErrorCallback
\r
82 *** IRDA HAL driver macros list ***
\r
83 ===================================
\r
85 Below the list of most used macros in IRDA HAL driver.
\r
87 (+) __HAL_IRDA_ENABLE: Enable the IRDA peripheral
\r
88 (+) __HAL_IRDA_DISABLE: Disable the IRDA peripheral
\r
89 (+) __HAL_IRDA_GET_FLAG : Checks whether the specified IRDA flag is set or not
\r
90 (+) __HAL_IRDA_CLEAR_FLAG : Clears the specified IRDA pending flag
\r
91 (+) __HAL_IRDA_ENABLE_IT: Enables the specified IRDA interrupt
\r
92 (+) __HAL_IRDA_DISABLE_IT: Disables the specified IRDA interrupt
\r
94 (@) You can refer to the IRDA HAL driver header file for more useful macros
\r
97 ******************************************************************************
\r
100 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
102 * Redistribution and use in source and binary forms, with or without modification,
\r
103 * are permitted provided that the following conditions are met:
\r
104 * 1. Redistributions of source code must retain the above copyright notice,
\r
105 * this list of conditions and the following disclaimer.
\r
106 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
107 * this list of conditions and the following disclaimer in the documentation
\r
108 * and/or other materials provided with the distribution.
\r
109 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
110 * may be used to endorse or promote products derived from this software
\r
111 * without specific prior written permission.
\r
113 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
114 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
115 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
116 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
117 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
118 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
119 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
120 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
121 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
122 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
124 ******************************************************************************
\r
127 /* Includes ------------------------------------------------------------------*/
\r
128 #include "stm32f7xx_hal.h"
\r
130 /** @addtogroup STM32F7xx_HAL_Driver
\r
134 /** @defgroup IRDA IRDA
\r
135 * @brief HAL IRDA module driver
\r
138 #ifdef HAL_IRDA_MODULE_ENABLED
\r
140 /* Private typedef -----------------------------------------------------------*/
\r
141 /* Private define ------------------------------------------------------------*/
\r
142 /** @addtogroup IRDA_Private_Constants
\r
145 #define TEACK_REACK_TIMEOUT 1000
\r
146 #define HAL_IRDA_TXDMA_TIMEOUTVALUE 22000
\r
147 #define IRDA_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE \
\r
148 | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE))
\r
152 /* Private macro -------------------------------------------------------------*/
\r
153 /* Private variables ---------------------------------------------------------*/
\r
154 /* Private function prototypes -----------------------------------------------*/
\r
155 /** @addtogroup IRDA_Private_Functions
\r
158 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
\r
159 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma);
\r
160 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
\r
161 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma);
\r
162 static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
\r
163 static void IRDA_SetConfig (IRDA_HandleTypeDef *hirda);
\r
164 static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda);
\r
165 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
\r
166 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
\r
167 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
\r
171 /* Exported functions --------------------------------------------------------*/
\r
172 /** @defgroup IRDA_Exported_Functions IrDA Exported Functions
\r
176 /** @defgroup IRDA_Exported_Functions_Group1 IrDA Initialization and de-initialization functions
\r
177 * @brief Initialization and Configuration functions
\r
181 ===============================================================================
\r
182 ##### Initialization and Configuration functions #####
\r
183 ===============================================================================
\r
185 This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
\r
187 (+) For the asynchronous mode only these parameters can be configured:
\r
190 (++) Parity: If the parity is enabled, then the MSB bit of the data written
\r
191 in the data register is transmitted but is changed by the parity bit.
\r
192 Depending on the frame length defined by the M bit (8-bits or 9-bits),
\r
193 please refer to Reference manual for possible IRDA frame formats.
\r
194 (++) Prescaler: A pulse of width less than two and greater than one PSC period(s) may or may
\r
195 not be rejected. The receiver set up time should be managed by software. The IrDA physical layer
\r
196 specification specifies a minimum of 10 ms delay between transmission and
\r
197 reception (IrDA is a half duplex protocol).
\r
198 (++) Mode: Receiver/transmitter modes
\r
199 (++) IrDAMode: the IrDA can operate in the Normal mode or in the Low power mode.
\r
201 The HAL_IRDA_Init() API follows IRDA configuration procedures (details for the procedures
\r
202 are available in reference manual).
\r
209 * @brief Initializes the IRDA mode according to the specified
\r
210 * parameters in the IRDA_InitTypeDef and create the associated handle.
\r
211 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
212 * the configuration information for the specified IRDA module.
\r
213 * @retval HAL status
\r
215 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
\r
217 /* Check the IRDA handle allocation */
\r
223 /* Check the USART/UART associated to the IRDA handle */
\r
224 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
\r
226 if(hirda->State == HAL_IRDA_STATE_RESET)
\r
228 /* Init the low level hardware : GPIO, CLOCK, CORTEX */
\r
229 HAL_IRDA_MspInit(hirda);
\r
232 hirda->State = HAL_IRDA_STATE_BUSY;
\r
234 /* Disable the Peripheral to update the configuration registers */
\r
235 __HAL_IRDA_DISABLE(hirda);
\r
237 /* Set the IRDA Communication parameters */
\r
238 IRDA_SetConfig(hirda);
\r
240 /* In IRDA mode, the following bits must be kept cleared:
\r
241 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
\r
242 - SCEN and HDSEL bits in the USART_CR3 register.*/
\r
243 hirda->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP);
\r
244 hirda->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL);
\r
246 /* set the UART/USART in IRDA mode */
\r
247 hirda->Instance->CR3 |= USART_CR3_IREN;
\r
249 /* Enable the Peripheral */
\r
250 __HAL_IRDA_ENABLE(hirda);
\r
252 /* TEACK and/or REACK to check before moving hirda->State to Ready */
\r
253 return (IRDA_CheckIdleState(hirda));
\r
257 * @brief DeInitializes the IRDA peripheral
\r
258 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
259 * the configuration information for the specified IRDA module.
\r
260 * @retval HAL status
\r
262 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
\r
264 /* Check the IRDA handle allocation */
\r
270 /* Check the parameters */
\r
271 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
\r
273 hirda->State = HAL_IRDA_STATE_BUSY;
\r
275 /* DeInit the low level hardware */
\r
276 HAL_IRDA_MspDeInit(hirda);
\r
277 /* Disable the Peripheral */
\r
278 __HAL_IRDA_DISABLE(hirda);
\r
280 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
281 hirda->State = HAL_IRDA_STATE_RESET;
\r
284 __HAL_UNLOCK(hirda);
\r
290 * @brief IRDA MSP Init.
\r
291 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
292 * the configuration information for the specified IRDA module.
\r
295 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
\r
297 /* NOTE : This function Should not be modified, when the callback is needed,
\r
298 the HAL_IRDA_MspInit could be implemented in the user file
\r
303 * @brief IRDA MSP DeInit.
\r
304 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
305 * the configuration information for the specified IRDA module.
\r
308 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
\r
310 /* NOTE : This function Should not be modified, when the callback is needed,
\r
311 the HAL_IRDA_MspDeInit could be implemented in the user file
\r
319 /** @defgroup IRDA_Exported_Functions_Group2 IO operation functions
\r
320 * @brief IRDA Transmit/Receive functions
\r
323 ===============================================================================
\r
324 ##### IO operation functions #####
\r
325 ===============================================================================
\r
326 This subsection provides a set of functions allowing to manage the IRDA data transfers.
\r
328 IrDA is a half duplex communication protocol. If the Transmitter is busy, any data
\r
329 on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver
\r
330 is busy, data on the TX from the USART to IrDA will not be encoded by IrDA.
\r
331 While receiving data, transmission should be avoided as the data to be transmitted
\r
332 could be corrupted.
\r
334 (#) There are two modes of transfer:
\r
335 (++) Blocking mode: the communication is performed in polling mode.
\r
336 The HAL status of all data processing is returned by the same function
\r
337 after finishing transfer.
\r
338 (++) No-Blocking mode: the communication is performed using Interrupts
\r
339 or DMA, these API's return the HAL status.
\r
340 The end of the data processing will be indicated through the
\r
341 dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when
\r
343 The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks
\r
344 will be executed respectively at the end of the Transmit or Receive process
\r
345 The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected
\r
347 (#) Blocking mode API's are :
\r
348 (++) HAL_IRDA_Transmit()
\r
349 (++) HAL_IRDA_Receive()
\r
351 (#) Non-Blocking mode API's with Interrupt are :
\r
352 (++) HAL_IRDA_Transmit_IT()
\r
353 (++) HAL_IRDA_Receive_IT()
\r
354 (++) HAL_IRDA_IRQHandler()
\r
355 (++) IRDA_Transmit_IT()
\r
356 (++) IRDA_Receive_IT()
\r
358 (#) Non-Blocking mode functions with DMA are :
\r
359 (++) HAL_IRDA_Transmit_DMA()
\r
360 (++) HAL_IRDA_Receive_DMA()
\r
362 (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
\r
363 (++) HAL_IRDA_TxCpltCallback()
\r
364 (++) HAL_IRDA_RxCpltCallback()
\r
365 (++) HAL_IRDA_ErrorCallback()
\r
372 * @brief Sends an amount of data in blocking mode.
\r
373 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
374 * the configuration information for the specified IRDA module.
\r
375 * @param pData: Pointer to data buffer
\r
376 * @param Size: Amount of data to be sent
\r
377 * @param Timeout: Specify timeout value
\r
378 * @retval HAL status
\r
380 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
\r
384 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
\r
386 if((pData == NULL) || (Size == 0))
\r
391 /* Process Locked */
\r
393 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
395 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
\r
397 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
401 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
404 hirda->TxXferSize = Size;
\r
405 hirda->TxXferCount = Size;
\r
406 while(hirda->TxXferCount > 0)
\r
408 hirda->TxXferCount--;
\r
410 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, Timeout) != HAL_OK)
\r
412 return HAL_TIMEOUT;
\r
414 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
\r
416 tmp = (uint16_t*) pData;
\r
417 hirda->Instance->TDR = (*tmp & (uint16_t)0x01FF);
\r
422 hirda->Instance->TDR = (*pData++ & (uint8_t)0xFF);
\r
426 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, Timeout) != HAL_OK)
\r
428 return HAL_TIMEOUT;
\r
431 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
433 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
437 hirda->State = HAL_IRDA_STATE_READY;
\r
440 /* Process Unlocked */
\r
441 __HAL_UNLOCK(hirda);
\r
452 * @brief Receive an amount of data in blocking mode.
\r
453 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
454 * the configuration information for the specified IRDA module.
\r
455 * @param pData: Pointer to data buffer
\r
456 * @param Size: Amount of data to be received
\r
457 * @param Timeout: Specify timeout value
\r
458 * @retval HAL status
\r
460 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
\r
465 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
\r
467 if((pData == NULL) || (Size == 0))
\r
472 /* Process Locked */
\r
474 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
476 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
\r
478 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
482 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
485 hirda->RxXferSize = Size;
\r
486 hirda->RxXferCount = Size;
\r
488 /* Computation of the mask to apply to the RDR register
\r
489 of the UART associated to the IRDA */
\r
490 IRDA_MASK_COMPUTATION(hirda);
\r
491 uhMask = hirda->Mask;
\r
493 /* Check data remaining to be received */
\r
494 while(hirda->RxXferCount > 0)
\r
496 hirda->RxXferCount--;
\r
498 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, Timeout) != HAL_OK)
\r
500 return HAL_TIMEOUT;
\r
502 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
\r
504 tmp = (uint16_t*) pData ;
\r
505 *tmp = (uint16_t)(hirda->Instance->RDR & uhMask);
\r
510 *pData++ = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask);
\r
514 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
516 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
520 hirda->State = HAL_IRDA_STATE_READY;
\r
523 /* Process Unlocked */
\r
524 __HAL_UNLOCK(hirda);
\r
535 * @brief Send an amount of data in non blocking mode.
\r
536 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
537 * the configuration information for the specified IRDA module.
\r
538 * @param pData: Pointer to data buffer
\r
539 * @param Size: Amount of data to be sent
\r
540 * @retval HAL status
\r
542 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
\r
544 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
\r
546 if((pData == NULL) || (Size == 0))
\r
551 /* Process Locked */
\r
554 hirda->pTxBuffPtr = pData;
\r
555 hirda->TxXferSize = Size;
\r
556 hirda->TxXferCount = Size;
\r
558 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
559 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
\r
561 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
565 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
568 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
\r
569 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
\r
571 /* Process Unlocked */
\r
572 __HAL_UNLOCK(hirda);
\r
574 /* Enable the IRDA Transmit Complete Interrupt */
\r
575 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TC);
\r
586 * @brief Receives an amount of data in non blocking mode.
\r
587 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
588 * the configuration information for the specified IRDA module.
\r
589 * @param pData: Pointer to data buffer
\r
590 * @param Size: Amount of data to be received
\r
591 * @retval HAL status
\r
593 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
\r
595 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
\r
597 if((pData == NULL) || (Size == 0))
\r
602 /* Process Locked */
\r
605 hirda->pRxBuffPtr = pData;
\r
606 hirda->RxXferSize = Size;
\r
607 hirda->RxXferCount = Size;
\r
609 /* Computation of the mask to apply to the RDR register
\r
610 of the UART associated to the IRDA */
\r
611 IRDA_MASK_COMPUTATION(hirda);
\r
613 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
614 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
\r
616 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
620 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
623 /* Enable the IRDA Parity Error Interrupt */
\r
624 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_PE);
\r
626 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
\r
627 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
\r
629 /* Process Unlocked */
\r
630 __HAL_UNLOCK(hirda);
\r
632 /* Enable the IRDA Data Register not empty Interrupt */
\r
633 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_RXNE);
\r
644 * @brief Sends an amount of data in non blocking mode.
\r
645 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
646 * the configuration information for the specified IRDA module.
\r
647 * @param pData: Pointer to data buffer
\r
648 * @param Size: Amount of data to be sent
\r
649 * @retval HAL status
\r
651 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
\r
655 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
\r
657 if((pData == NULL) || (Size == 0))
\r
662 /* Process Locked */
\r
665 hirda->pTxBuffPtr = pData;
\r
666 hirda->TxXferSize = Size;
\r
667 hirda->TxXferCount = Size;
\r
669 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
671 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
\r
673 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
677 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
680 /* Set the IRDA DMA transfer complete callback */
\r
681 hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
\r
683 /* Set the IRDA DMA half transfer complete callback */
\r
684 hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
\r
686 /* Set the DMA error callback */
\r
687 hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
\r
689 /* Enable the IRDA transmit DMA channel */
\r
690 tmp = (uint32_t*)&pData;
\r
691 HAL_DMA_Start_IT(hirda->hdmatx, *(uint32_t*)tmp, (uint32_t)&hirda->Instance->TDR, Size);
\r
693 /* Clear the TC flag in the SR register by writing 0 to it */
\r
694 __HAL_IRDA_CLEAR_IT(hirda, IRDA_FLAG_TC);
\r
696 /* Enable the DMA transfer for transmit request by setting the DMAT bit
\r
697 in the IRDA CR3 register */
\r
698 hirda->Instance->CR3 |= USART_CR3_DMAT;
\r
700 /* Process Unlocked */
\r
701 __HAL_UNLOCK(hirda);
\r
712 * @brief Receives an amount of data in non blocking mode.
\r
713 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
714 * the configuration information for the specified IRDA module.
\r
715 * @param pData: Pointer to data buffer
\r
716 * @param Size: Amount of data to be received
\r
717 * @note When the IRDA parity is enabled (PCE = 1) the data received contain the parity bit.
\r
718 * @retval HAL status
\r
720 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
\r
724 if ((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
\r
726 if((pData == NULL) || (Size == 0))
\r
731 /* Process Locked */
\r
734 hirda->pRxBuffPtr = pData;
\r
735 hirda->RxXferSize = Size;
\r
737 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
738 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
\r
740 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
\r
744 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
747 /* Set the IRDA DMA transfer complete callback */
\r
748 hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
\r
750 /* Set the IRDA DMA half transfer complete callback */
\r
751 hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
\r
753 /* Set the DMA error callback */
\r
754 hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
\r
756 /* Enable the DMA channel */
\r
757 tmp = (uint32_t*)&pData;
\r
758 HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->RDR, *(uint32_t*)tmp, Size);
\r
760 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
\r
761 in the IRDA CR3 register */
\r
762 hirda->Instance->CR3 |= USART_CR3_DMAR;
\r
764 /* Process Unlocked */
\r
765 __HAL_UNLOCK(hirda);
\r
776 * @brief Pauses the DMA Transfer.
\r
777 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
778 * the configuration information for the specified IRDA module.
\r
779 * @retval HAL status
\r
781 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
\r
783 /* Process Locked */
\r
786 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
\r
788 /* Disable the UART DMA Tx request */
\r
789 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
\r
791 else if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
\r
793 /* Disable the UART DMA Rx request */
\r
794 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
\r
796 else if (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
798 /* Disable the UART DMA Tx & Rx requests */
\r
799 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
\r
800 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
\r
803 /* Process Unlocked */
\r
804 __HAL_UNLOCK(hirda);
\r
810 * @brief Resumes the DMA Transfer.
\r
811 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
812 * the configuration information for the specified UART module.
\r
813 * @retval HAL status
\r
815 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
\r
817 /* Process Locked */
\r
820 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
\r
822 /* Enable the UART DMA Tx request */
\r
823 hirda->Instance->CR3 |= USART_CR3_DMAT;
\r
825 else if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
\r
827 /* Clear the Overrun flag before resuming the Rx transfer*/
\r
828 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_OREF);
\r
830 /* Enable the UART DMA Rx request */
\r
831 hirda->Instance->CR3 |= USART_CR3_DMAR;
\r
833 else if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
835 /* Clear the Overrun flag before resuming the Rx transfer*/
\r
836 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_OREF);
\r
838 /* Enable the UART DMA Tx & Rx request */
\r
839 hirda->Instance->CR3 |= USART_CR3_DMAT;
\r
840 hirda->Instance->CR3 |= USART_CR3_DMAR;
\r
843 /* Process Unlocked */
\r
844 __HAL_UNLOCK(hirda);
\r
850 * @brief Stops the DMA Transfer.
\r
851 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
852 * the configuration information for the specified UART module.
\r
853 * @retval HAL status
\r
855 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
\r
857 /* The Lock is not implemented on this API to allow the user application
\r
858 to call the HAL UART API under callbacks HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback():
\r
859 when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
\r
860 and the correspond call back is executed HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback()
\r
863 /* Disable the UART Tx/Rx DMA requests */
\r
864 hirda->Instance->CR3 &= ~USART_CR3_DMAT;
\r
865 hirda->Instance->CR3 &= ~USART_CR3_DMAR;
\r
867 /* Abort the UART DMA tx channel */
\r
868 if(hirda->hdmatx != NULL)
\r
870 HAL_DMA_Abort(hirda->hdmatx);
\r
872 /* Abort the UART DMA rx channel */
\r
873 if(hirda->hdmarx != NULL)
\r
875 HAL_DMA_Abort(hirda->hdmarx);
\r
878 hirda->State = HAL_IRDA_STATE_READY;
\r
884 * @brief This function handles IRDA interrupt request.
\r
885 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
886 * the configuration information for the specified IRDA module.
\r
889 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
\r
891 /* IRDA parity error interrupt occurred -------------------------------------*/
\r
892 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_PE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE) != RESET))
\r
894 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_PEF);
\r
896 hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
\r
897 /* Set the IRDA state ready to be able to start again the process */
\r
898 hirda->State = HAL_IRDA_STATE_READY;
\r
901 /* IRDA frame error interrupt occurred --------------------------------------*/
\r
902 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_FE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
\r
904 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_FEF);
\r
906 hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
\r
907 /* Set the IRDA state ready to be able to start again the process */
\r
908 hirda->State = HAL_IRDA_STATE_READY;
\r
911 /* IRDA noise error interrupt occurred --------------------------------------*/
\r
912 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_NE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
\r
914 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_NEF);
\r
916 hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
\r
917 /* Set the IRDA state ready to be able to start again the process */
\r
918 hirda->State = HAL_IRDA_STATE_READY;
\r
921 /* IRDA Over-Run interrupt occurred -----------------------------------------*/
\r
922 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_ORE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
\r
924 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_OREF);
\r
926 hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
\r
927 /* Set the IRDA state ready to be able to start again the process */
\r
928 hirda->State = HAL_IRDA_STATE_READY;
\r
931 /* Call IRDA Error Call back function if need be --------------------------*/
\r
932 if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
\r
934 HAL_IRDA_ErrorCallback(hirda);
\r
937 /* IRDA in mode Receiver ---------------------------------------------------*/
\r
938 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_RXNE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_RXNE) != RESET))
\r
940 IRDA_Receive_IT(hirda);
\r
941 /* Clear RXNE interrupt flag */
\r
942 __HAL_IRDA_SEND_REQ(hirda, IRDA_RXDATA_FLUSH_REQUEST);
\r
945 /* IRDA in mode Transmitter ------------------------------------------------*/
\r
946 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_TXE) != RESET) &&(__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TXE) != RESET))
\r
948 IRDA_Transmit_IT(hirda);
\r
954 * @brief Tx Transfer complete callbacks.
\r
955 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
956 * the configuration information for the specified IRDA module.
\r
959 __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
\r
961 /* NOTE : This function should not be modified, when the callback is needed,
\r
962 the HAL_IRDA_TxHalfCpltCallback can be implemented in the user file
\r
967 * @brief Tx Half Transfer completed callbacks.
\r
968 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
969 * the configuration information for the specified USART module.
\r
972 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
\r
974 /* NOTE : This function should not be modified, when the callback is needed,
\r
975 the HAL_IRDA_TxCpltCallback can be implemented in the user file
\r
980 * @brief Rx Transfer complete callbacks.
\r
981 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
982 * the configuration information for the specified IRDA module.
\r
985 __weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
\r
987 /* NOTE : This function should not be modified, when the callback is needed,
\r
988 the HAL_IRDA_RxHalfCpltCallback can be implemented in the user file
\r
993 * @brief Rx Half Transfer complete callbacks.
\r
994 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
995 * the configuration information for the specified IRDA module.
\r
998 __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
\r
1000 /* NOTE : This function should not be modified, when the callback is needed,
\r
1001 the HAL_IRDA_RxCpltCallback can be implemented in the user file
\r
1006 * @brief IRDA error callbacks.
\r
1007 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1008 * the configuration information for the specified IRDA module.
\r
1011 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
\r
1013 /* NOTE : This function should not be modified, when the callback is needed,
\r
1014 the HAL_IRDA_ErrorCallback can be implemented in the user file
\r
1022 /** @defgroup IRDA_Exported_Functions_Group3 Peripheral Control functions
\r
1023 * @brief IRDA control functions
\r
1026 ===============================================================================
\r
1027 ##### Peripheral Control functions #####
\r
1028 ===============================================================================
\r
1030 This subsection provides a set of functions allowing to control the IRDA.
\r
1031 (+) HAL_IRDA_GetState() API can be helpful to check in run-time the state of the IRDA peripheral.
\r
1032 (+) IRDA_SetConfig() API is used to configure the IRDA communications parameters.
\r
1038 * @brief Returns the IRDA state.
\r
1039 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1040 * the configuration information for the specified IRDA module.
\r
1041 * @retval HAL state
\r
1043 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda)
\r
1045 return hirda->State;
\r
1049 * @brief Return the IRDA error code
\r
1050 * @param hirda : pointer to a IRDA_HandleTypeDef structure that contains
\r
1051 * the configuration information for the specified IRDA.
\r
1052 * @retval IRDA Error Code
\r
1054 uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda)
\r
1056 return hirda->ErrorCode;
\r
1064 * @brief Configure the IRDA peripheral
\r
1065 * @param hirda: irda handle
\r
1068 static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
\r
1070 uint32_t tmpreg = 0x00000000;
\r
1071 uint32_t clocksource = 0x00000000;
\r
1073 /* Check the communication parameters */
\r
1074 assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
\r
1075 assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
\r
1076 assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
\r
1077 assert_param(IS_IRDA_TX_RX_MODE(hirda->Init.Mode));
\r
1078 assert_param(IS_IRDA_PRESCALER(hirda->Init.Prescaler));
\r
1079 assert_param(IS_IRDA_POWERMODE(hirda->Init.PowerMode));
\r
1080 /*-------------------------- USART CR1 Configuration -----------------------*/
\r
1081 /* Configure the IRDA Word Length, Parity and transfer Mode:
\r
1082 Set the M bits according to hirda->Init.WordLength value
\r
1083 Set PCE and PS bits according to hirda->Init.Parity value
\r
1084 Set TE and RE bits according to hirda->Init.Mode value */
\r
1085 tmpreg = (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode ;
\r
1087 MODIFY_REG(hirda->Instance->CR1, IRDA_CR1_FIELDS, tmpreg);
\r
1089 /*-------------------------- USART CR3 Configuration -----------------------*/
\r
1090 MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.PowerMode);
\r
1092 /*-------------------------- USART GTPR Configuration ----------------------*/
\r
1093 MODIFY_REG(hirda->Instance->GTPR, (uint32_t)USART_GTPR_PSC, hirda->Init.Prescaler);
\r
1095 /*-------------------------- USART BRR Configuration -----------------------*/
\r
1096 IRDA_GETCLOCKSOURCE(hirda, clocksource);
\r
1097 switch (clocksource)
\r
1099 case IRDA_CLOCKSOURCE_PCLK1:
\r
1100 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK1Freq() / hirda->Init.BaudRate);
\r
1102 case IRDA_CLOCKSOURCE_PCLK2:
\r
1103 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK2Freq() / hirda->Init.BaudRate);
\r
1105 case IRDA_CLOCKSOURCE_HSI:
\r
1106 hirda->Instance->BRR = (uint16_t)(HSI_VALUE / hirda->Init.BaudRate);
\r
1108 case IRDA_CLOCKSOURCE_SYSCLK:
\r
1109 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetSysClockFreq() / hirda->Init.BaudRate);
\r
1111 case IRDA_CLOCKSOURCE_LSE:
\r
1112 hirda->Instance->BRR = (uint16_t)(LSE_VALUE / hirda->Init.BaudRate);
\r
1120 * @brief Check the IRDA Idle State
\r
1121 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1122 * the configuration information for the specified IRDA module.
\r
1123 * @retval HAL status
\r
1125 static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda)
\r
1127 /* Initialize the IRDA ErrorCode */
\r
1128 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
\r
1130 /* Check if the Transmitter is enabled */
\r
1131 if((hirda->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
\r
1133 /* Wait until TEACK flag is set */
\r
1134 if(IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_TEACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK)
\r
1136 hirda->State= HAL_IRDA_STATE_TIMEOUT;
\r
1137 return HAL_TIMEOUT;
\r
1140 /* Check if the Receiver is enabled */
\r
1141 if((hirda->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
\r
1143 if(IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_REACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK)
\r
1145 hirda->State= HAL_IRDA_STATE_TIMEOUT;
\r
1146 return HAL_TIMEOUT;
\r
1149 /* Process Unlocked */
\r
1150 __HAL_UNLOCK(hirda);
\r
1152 /* Initialize the IRDA state*/
\r
1153 hirda->State= HAL_IRDA_STATE_READY;
\r
1159 * @brief This function handles IRDA Communication Timeout.
\r
1160 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1161 * the configuration information for the specified IRDA module.
\r
1162 * @param Flag: specifies the IRDA flag to check.
\r
1163 * @param Status: The new Flag status (SET or RESET).
\r
1164 * @param Timeout: Timeout duration
\r
1165 * @retval HAL status
\r
1167 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
\r
1169 uint32_t tickstart = 0x00;
\r
1170 tickstart = HAL_GetTick();
\r
1172 /* Wait until flag is set */
\r
1173 if(Status == RESET)
\r
1175 while(__HAL_IRDA_GET_FLAG(hirda, Flag) == RESET)
\r
1177 /* Check for the Timeout */
\r
1178 if(Timeout != HAL_MAX_DELAY)
\r
1180 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
1182 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
\r
1183 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
\r
1184 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
\r
1185 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
\r
1186 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
\r
1188 hirda->State= HAL_IRDA_STATE_TIMEOUT;
\r
1190 /* Process Unlocked */
\r
1191 __HAL_UNLOCK(hirda);
\r
1193 return HAL_TIMEOUT;
\r
1200 while(__HAL_IRDA_GET_FLAG(hirda, Flag) != RESET)
\r
1202 /* Check for the Timeout */
\r
1203 if(Timeout != HAL_MAX_DELAY)
\r
1205 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
\r
1207 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
\r
1208 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
\r
1209 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
\r
1210 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
\r
1211 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
\r
1213 hirda->State= HAL_IRDA_STATE_TIMEOUT;
\r
1215 /* Process Unlocked */
\r
1216 __HAL_UNLOCK(hirda);
\r
1218 return HAL_TIMEOUT;
\r
1227 * @brief Send an amount of data in non blocking mode.
\r
1228 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1229 * the configuration information for the specified IRDA module.
\r
1230 * @retval HAL status
\r
1232 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
\r
1236 if((hirda->State == HAL_IRDA_STATE_BUSY_TX) || (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX))
\r
1238 if(hirda->TxXferCount == 0)
\r
1240 /* Disable the IRDA Transmit Complete Interrupt */
\r
1241 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
\r
1243 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
1245 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
1249 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
\r
1250 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
\r
1252 hirda->State = HAL_IRDA_STATE_READY;
\r
1255 HAL_IRDA_TxCpltCallback(hirda);
\r
1261 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
\r
1263 tmp = (uint16_t*) hirda->pTxBuffPtr;
\r
1264 hirda->Instance->TDR = (*tmp & (uint16_t)0x01FF);
\r
1265 hirda->pTxBuffPtr += 2;
\r
1269 hirda->Instance->TDR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0xFF);
\r
1271 hirda->TxXferCount--;
\r
1282 * @brief Receive an amount of data in non blocking mode.
\r
1283 * Function called under interruption only, once
\r
1284 * interruptions have been enabled by HAL_IRDA_Receive_IT()
\r
1285 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1286 * the configuration information for the specified IRDA module.
\r
1287 * @retval HAL status
\r
1289 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
\r
1292 uint16_t uhMask = hirda->Mask;
\r
1294 if ((hirda->State == HAL_IRDA_STATE_BUSY_RX) || (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX))
\r
1296 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
\r
1298 tmp = (uint16_t*) hirda->pRxBuffPtr ;
\r
1299 *tmp = (uint16_t)(hirda->Instance->RDR & uhMask);
\r
1300 hirda->pRxBuffPtr +=2;
\r
1304 *hirda->pRxBuffPtr++ = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask);
\r
1307 if(--hirda->RxXferCount == 0)
\r
1309 while(HAL_IS_BIT_SET(hirda->Instance->ISR, IRDA_FLAG_RXNE))
\r
1312 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
\r
1314 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
1316 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
1320 /* Disable the IRDA Parity Error Interrupt */
\r
1321 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
\r
1323 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
\r
1324 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
\r
1326 hirda->State = HAL_IRDA_STATE_READY;
\r
1329 HAL_IRDA_RxCpltCallback(hirda);
\r
1343 * @brief DMA IRDA Tx transfer completed callback
\r
1344 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
\r
1345 * the configuration information for the specified IRDA module.
\r
1348 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
\r
1350 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1352 /* DMA Normal mode */
\r
1353 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
\r
1355 hirda->TxXferCount = 0;
\r
1357 /* Disable the DMA transfer for transmit request by setting the DMAT bit
\r
1358 in the IRDA CR3 register */
\r
1359 hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAT);
\r
1361 /* Wait for IRDA TC Flag */
\r
1362 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, HAL_IRDA_TXDMA_TIMEOUTVALUE) != HAL_OK)
\r
1364 /* Timeout Occured */
\r
1365 hirda->State = HAL_IRDA_STATE_TIMEOUT;
\r
1366 HAL_IRDA_ErrorCallback(hirda);
\r
1372 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
1374 hirda->State = HAL_IRDA_STATE_BUSY_RX;
\r
1378 hirda->State = HAL_IRDA_STATE_READY;
\r
1380 HAL_IRDA_TxCpltCallback(hirda);
\r
1383 /* DMA Circular mode */
\r
1386 HAL_IRDA_TxCpltCallback(hirda);
\r
1391 * @brief DMA IRDA receive process half complete callback
\r
1392 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
1393 * the configuration information for the specified DMA module.
\r
1396 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
\r
1398 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1400 HAL_IRDA_TxHalfCpltCallback(hirda);
\r
1404 * @brief DMA IRDA Rx Transfer completed callback
\r
1405 * @param hdma: DMA handle
\r
1408 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
\r
1410 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1411 /* DMA Normal mode */
\r
1412 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
\r
1414 hirda->RxXferCount = 0;
\r
1416 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
\r
1417 in the IRDA CR3 register */
\r
1418 hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAR);
\r
1420 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
\r
1422 hirda->State = HAL_IRDA_STATE_BUSY_TX;
\r
1426 hirda->State = HAL_IRDA_STATE_READY;
\r
1430 HAL_IRDA_RxCpltCallback(hirda);
\r
1434 * @brief DMA IRDA receive process half complete callback
\r
1435 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
\r
1436 * the configuration information for the specified DMA module.
\r
1439 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
\r
1441 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1443 HAL_IRDA_RxHalfCpltCallback(hirda);
\r
1447 * @brief DMA IRDA communication error callback
\r
1448 * @param hdma: DMA handle
\r
1451 static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
\r
1453 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1454 hirda->RxXferCount = 0;
\r
1455 hirda->TxXferCount = 0;
\r
1456 hirda->State= HAL_IRDA_STATE_READY;
\r
1457 hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
\r
1458 HAL_IRDA_ErrorCallback(hirda);
\r
1469 #endif /* HAL_IRDA_MODULE_ENABLED */
\r
1475 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r