38
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * @file stm32f4xx_hal_irda.c
|
|
4 * @author MCD Application Team
|
|
5 * @version V1.2.0
|
|
6 * @date 26-December-2014
|
|
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
|
|
13 *
|
|
14 @verbatim
|
|
15 ==============================================================================
|
|
16 ##### How to use this driver #####
|
|
17 ==============================================================================
|
|
18 [..]
|
|
19 The IRDA HAL driver can be used as follows:
|
|
20
|
|
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 initialized 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.
|
|
39
|
|
40 (#) Program the Baud Rate, Word Length, Parity, IrDA Mode, Prescaler
|
|
41 and Mode(Receiver/Transmitter) in the hirda Init structure.
|
|
42
|
|
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 customized 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.
|
|
49
|
|
50 (#) Three operation modes are available within this driver :
|
|
51
|
|
52 *** Polling mode IO operation ***
|
|
53 =================================
|
|
54 [..]
|
|
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()
|
|
57
|
|
58 *** Interrupt mode IO operation ***
|
|
59 ===================================
|
|
60 [..]
|
|
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
|
|
69
|
|
70 *** DMA mode IO operation ***
|
|
71 =============================
|
|
72 [..]
|
|
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
|
|
81
|
|
82 *** IRDA HAL driver macros list ***
|
|
83 ===================================
|
|
84 [..]
|
|
85 Below the list of most used macros in IRDA HAL driver.
|
|
86
|
|
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
|
|
93
|
|
94 (@) You can refer to the IRDA HAL driver header file for more useful macros
|
|
95
|
|
96 @endverbatim
|
|
97 ******************************************************************************
|
|
98 * @attention
|
|
99 *
|
|
100 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
|
|
101 *
|
|
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.
|
|
112 *
|
|
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.
|
|
123 *
|
|
124 ******************************************************************************
|
|
125 */
|
|
126
|
|
127 /* Includes ------------------------------------------------------------------*/
|
|
128 #include "stm32f4xx_hal.h"
|
|
129
|
|
130 /** @addtogroup STM32F4xx_HAL_Driver
|
|
131 * @{
|
|
132 */
|
|
133
|
|
134 /** @defgroup IRDA IRDA
|
|
135 * @brief HAL IRDA module driver
|
|
136 * @{
|
|
137 */
|
|
138
|
|
139 #ifdef HAL_IRDA_MODULE_ENABLED
|
|
140
|
|
141 /* Private typedef -----------------------------------------------------------*/
|
|
142 /* Private define ------------------------------------------------------------*/
|
|
143 /** @addtogroup IRDA_Private_Constants
|
|
144 * @{
|
|
145 */
|
|
146 #define IRDA_TIMEOUT_VALUE 22000
|
|
147 /**
|
|
148 * @}
|
|
149 */
|
|
150 /* Private macro -------------------------------------------------------------*/
|
|
151 /* Private variables ---------------------------------------------------------*/
|
|
152 /* Private function prototypes -----------------------------------------------*/
|
|
153 /** @addtogroup IRDA_Private_Functions
|
|
154 * @{
|
|
155 */
|
|
156 static void IRDA_SetConfig (IRDA_HandleTypeDef *hirda);
|
|
157 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
|
|
158 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda);
|
|
159 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
|
|
160 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
|
|
161 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma);
|
|
162 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
|
|
163 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma);
|
|
164 static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
|
|
165 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
|
|
166 /**
|
|
167 * @}
|
|
168 */
|
|
169 /* Exported functions --------------------------------------------------------*/
|
|
170 /** @defgroup IRDA_Exported_Functions IrDA Exported Functions
|
|
171 * @{
|
|
172 */
|
|
173
|
|
174 /** @defgroup IRDA_Exported_Functions_Group1 IrDA Initialization and de-initialization functions
|
|
175 * @brief Initialization and Configuration functions
|
|
176 *
|
|
177 @verbatim
|
|
178
|
|
179 ===============================================================================
|
|
180 ##### Initialization and Configuration functions #####
|
|
181 ===============================================================================
|
|
182 [..]
|
|
183 This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
|
|
184 in IrDA mode.
|
|
185 (+) For the asynchronous mode only these parameters can be configured:
|
|
186 (++) BaudRate
|
|
187 (++) WordLength
|
|
188 (++) Parity: If the parity is enabled, then the MSB bit of the data written
|
|
189 in the data register is transmitted but is changed by the parity bit.
|
|
190 Depending on the frame length defined by the M bit (8-bits or 9-bits),
|
|
191 please refer to Reference manual for possible IRDA frame formats.
|
|
192 (++) Prescaler: A pulse of width less than two and greater than one PSC period(s) may or may
|
|
193 not be rejected. The receiver set up time should be managed by software. The IrDA physical layer
|
|
194 specification specifies a minimum of 10 ms delay between transmission and
|
|
195 reception (IrDA is a half duplex protocol).
|
|
196 (++) Mode: Receiver/transmitter modes
|
|
197 (++) IrDAMode: the IrDA can operate in the Normal mode or in the Low power mode.
|
|
198 [..]
|
|
199 The HAL_IRDA_Init() API follows IRDA configuration procedures (details for the procedures
|
|
200 are available in reference manual).
|
|
201
|
|
202 @endverbatim
|
|
203 * @{
|
|
204 */
|
|
205
|
|
206 /**
|
|
207 * @brief Initializes the IRDA mode according to the specified
|
|
208 * parameters in the IRDA_InitTypeDef and create the associated handle.
|
|
209 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
210 * the configuration information for the specified IRDA module.
|
|
211 * @retval HAL status
|
|
212 */
|
|
213 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
|
|
214 {
|
|
215 /* Check the IRDA handle allocation */
|
|
216 if(hirda == NULL)
|
|
217 {
|
|
218 return HAL_ERROR;
|
|
219 }
|
|
220
|
|
221 /* Check the IRDA instance parameters */
|
|
222 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
|
|
223 /* Check the IRDA mode parameter in the IRDA handle */
|
|
224 assert_param(IS_IRDA_POWERMODE(hirda->Init.IrDAMode));
|
|
225
|
|
226 if(hirda->State == HAL_IRDA_STATE_RESET)
|
|
227 {
|
|
228 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
|
|
229 HAL_IRDA_MspInit(hirda);
|
|
230 }
|
|
231
|
|
232 hirda->State = HAL_IRDA_STATE_BUSY;
|
|
233
|
|
234 /* Disable the IRDA peripheral */
|
|
235 __HAL_IRDA_DISABLE(hirda);
|
|
236
|
|
237 /* Set the IRDA communication parameters */
|
|
238 IRDA_SetConfig(hirda);
|
|
239
|
|
240 /* In IrDA mode, the following bits must be kept cleared:
|
|
241 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
|
|
242 - SCEN and HDSEL bits in the USART_CR3 register.*/
|
|
243 hirda->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_STOP | USART_CR2_CLKEN);
|
|
244 hirda->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL);
|
|
245
|
|
246 /* Enable the IRDA peripheral */
|
|
247 __HAL_IRDA_ENABLE(hirda);
|
|
248
|
|
249 /* Set the prescaler */
|
|
250 MODIFY_REG(hirda->Instance->GTPR, USART_GTPR_PSC, hirda->Init.Prescaler);
|
|
251
|
|
252 /* Configure the IrDA mode */
|
|
253 MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.IrDAMode);
|
|
254
|
|
255 /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
|
|
256 hirda->Instance->CR3 |= USART_CR3_IREN;
|
|
257
|
|
258 /* Initialize the IRDA state*/
|
|
259 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
|
|
260 hirda->State= HAL_IRDA_STATE_READY;
|
|
261
|
|
262 return HAL_OK;
|
|
263 }
|
|
264
|
|
265 /**
|
|
266 * @brief DeInitializes the IRDA peripheral
|
|
267 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
268 * the configuration information for the specified IRDA module.
|
|
269 * @retval HAL status
|
|
270 */
|
|
271 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
|
|
272 {
|
|
273 /* Check the IRDA handle allocation */
|
|
274 if(hirda == NULL)
|
|
275 {
|
|
276 return HAL_ERROR;
|
|
277 }
|
|
278
|
|
279 /* Check the parameters */
|
|
280 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
|
|
281
|
|
282 hirda->State = HAL_IRDA_STATE_BUSY;
|
|
283
|
|
284 /* Disable the Peripheral */
|
|
285 __HAL_IRDA_DISABLE(hirda);
|
|
286
|
|
287 /* DeInit the low level hardware */
|
|
288 HAL_IRDA_MspDeInit(hirda);
|
|
289
|
|
290 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
|
|
291
|
|
292 hirda->State = HAL_IRDA_STATE_RESET;
|
|
293
|
|
294 /* Release Lock */
|
|
295 __HAL_UNLOCK(hirda);
|
|
296
|
|
297 return HAL_OK;
|
|
298 }
|
|
299
|
|
300 /**
|
|
301 * @brief IRDA MSP Init.
|
|
302 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
303 * the configuration information for the specified IRDA module.
|
|
304 * @retval None
|
|
305 */
|
|
306 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
|
|
307 {
|
|
308 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
309 the HAL_IRDA_MspInit could be implemented in the user file
|
|
310 */
|
|
311 }
|
|
312
|
|
313 /**
|
|
314 * @brief IRDA MSP DeInit.
|
|
315 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
316 * the configuration information for the specified IRDA module.
|
|
317 * @retval None
|
|
318 */
|
|
319 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
|
|
320 {
|
|
321 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
322 the HAL_IRDA_MspDeInit could be implemented in the user file
|
|
323 */
|
|
324 }
|
|
325
|
|
326 /**
|
|
327 * @}
|
|
328 */
|
|
329
|
|
330 /** @defgroup IRDA_Exported_Functions_Group2 IO operation functions
|
|
331 * @brief IRDA Transmit/Receive functions
|
|
332 *
|
|
333 @verbatim
|
|
334 ===============================================================================
|
|
335 ##### IO operation functions #####
|
|
336 ===============================================================================
|
|
337 This subsection provides a set of functions allowing to manage the IRDA data transfers.
|
|
338 [..]
|
|
339 IrDA is a half duplex communication protocol. If the Transmitter is busy, any data
|
|
340 on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver
|
|
341 is busy, data on the TX from the USART to IrDA will not be encoded by IrDA.
|
|
342 While receiving data, transmission should be avoided as the data to be transmitted
|
|
343 could be corrupted.
|
|
344
|
|
345 (#) There are two modes of transfer:
|
|
346 (++) Blocking mode: The communication is performed in polling mode.
|
|
347 The HAL status of all data processing is returned by the same function
|
|
348 after finishing transfer.
|
|
349 (++) No-Blocking mode: The communication is performed using Interrupts
|
|
350 or DMA, These APIs return the HAL status.
|
|
351 The end of the data processing will be indicated through the
|
|
352 dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when
|
|
353 using DMA mode.
|
|
354 The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks
|
|
355 will be executed respectively at the end of the transmit or Receive process
|
|
356 The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected
|
|
357
|
|
358 (#) Blocking mode API's are :
|
|
359 (++) HAL_IRDA_Transmit()
|
|
360 (++) HAL_IRDA_Receive()
|
|
361
|
|
362 (#) Non Blocking mode APIs with Interrupt are :
|
|
363 (++) HAL_IRDA_Transmit_IT()
|
|
364 (++) HAL_IRDA_Receive_IT()
|
|
365 (++) HAL_IRDA_IRQHandler()
|
|
366
|
|
367 (#) Non Blocking mode functions with DMA are :
|
|
368 (++) HAL_IRDA_Transmit_DMA()
|
|
369 (++) HAL_IRDA_Receive_DMA()
|
|
370
|
|
371 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
|
|
372 (++) HAL_IRDA_TxCpltCallback()
|
|
373 (++) HAL_IRDA_RxCpltCallback()
|
|
374 (++) HAL_IRDA_ErrorCallback()
|
|
375
|
|
376 @endverbatim
|
|
377 * @{
|
|
378 */
|
|
379
|
|
380 /**
|
|
381 * @brief Sends an amount of data in blocking mode.
|
|
382 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
383 * the configuration information for the specified IRDA module.
|
|
384 * @param pData: Pointer to data buffer
|
|
385 * @param Size: Amount of data to be sent
|
|
386 * @param Timeout: Specify timeout value
|
|
387 * @retval HAL status
|
|
388 */
|
|
389 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
|
|
390 {
|
|
391 uint16_t* tmp;
|
|
392 uint32_t tmp1 = 0;
|
|
393
|
|
394 tmp1 = hirda->State;
|
|
395 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_RX))
|
|
396 {
|
|
397 if((pData == NULL) || (Size == 0))
|
|
398 {
|
|
399 return HAL_ERROR;
|
|
400 }
|
|
401
|
|
402 /* Process Locked */
|
|
403 __HAL_LOCK(hirda);
|
|
404
|
|
405 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
|
|
406 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
|
|
407 {
|
|
408 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
|
|
409 }
|
|
410 else
|
|
411 {
|
|
412 hirda->State = HAL_IRDA_STATE_BUSY_TX;
|
|
413 }
|
|
414
|
|
415 hirda->TxXferSize = Size;
|
|
416 hirda->TxXferCount = Size;
|
|
417 while(hirda->TxXferCount > 0)
|
|
418 {
|
|
419 hirda->TxXferCount--;
|
|
420 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
|
|
421 {
|
|
422 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, Timeout) != HAL_OK)
|
|
423 {
|
|
424 return HAL_TIMEOUT;
|
|
425 }
|
|
426 tmp = (uint16_t*) pData;
|
|
427 hirda->Instance->DR = (*tmp & (uint16_t)0x01FF);
|
|
428 if(hirda->Init.Parity == IRDA_PARITY_NONE)
|
|
429 {
|
|
430 pData +=2;
|
|
431 }
|
|
432 else
|
|
433 {
|
|
434 pData +=1;
|
|
435 }
|
|
436 }
|
|
437 else
|
|
438 {
|
|
439 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, Timeout) != HAL_OK)
|
|
440 {
|
|
441 return HAL_TIMEOUT;
|
|
442 }
|
|
443 hirda->Instance->DR = (*pData++ & (uint8_t)0xFF);
|
|
444 }
|
|
445 }
|
|
446
|
|
447 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, Timeout) != HAL_OK)
|
|
448 {
|
|
449 return HAL_TIMEOUT;
|
|
450 }
|
|
451
|
|
452 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
|
|
453 {
|
|
454 hirda->State = HAL_IRDA_STATE_BUSY_RX;
|
|
455 }
|
|
456 else
|
|
457 {
|
|
458 hirda->State = HAL_IRDA_STATE_READY;
|
|
459 }
|
|
460
|
|
461 /* Process Unlocked */
|
|
462 __HAL_UNLOCK(hirda);
|
|
463
|
|
464 return HAL_OK;
|
|
465 }
|
|
466 else
|
|
467 {
|
|
468 return HAL_BUSY;
|
|
469 }
|
|
470 }
|
|
471
|
|
472 /**
|
|
473 * @brief Receive an amount of data in blocking mode.
|
|
474 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
475 * the configuration information for the specified IRDA module.
|
|
476 * @param pData: Pointer to data buffer
|
|
477 * @param Size: Amount of data to be received
|
|
478 * @param Timeout: Specify timeout value
|
|
479 * @retval HAL status
|
|
480 */
|
|
481 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
|
|
482 {
|
|
483 uint16_t* tmp;
|
|
484 uint32_t tmp1 = 0;
|
|
485
|
|
486 tmp1 = hirda->State;
|
|
487 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_TX))
|
|
488 {
|
|
489 if((pData == NULL) || (Size == 0))
|
|
490 {
|
|
491 return HAL_ERROR;
|
|
492 }
|
|
493
|
|
494 /* Process Locked */
|
|
495 __HAL_LOCK(hirda);
|
|
496
|
|
497 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
|
|
498 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
|
|
499 {
|
|
500 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
|
|
501 }
|
|
502 else
|
|
503 {
|
|
504 hirda->State = HAL_IRDA_STATE_BUSY_RX;
|
|
505 }
|
|
506 hirda->RxXferSize = Size;
|
|
507 hirda->RxXferCount = Size;
|
|
508 /* Check the remain data to be received */
|
|
509 while(hirda->RxXferCount > 0)
|
|
510 {
|
|
511 hirda->RxXferCount--;
|
|
512 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
|
|
513 {
|
|
514 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, Timeout) != HAL_OK)
|
|
515 {
|
|
516 return HAL_TIMEOUT;
|
|
517 }
|
|
518 tmp = (uint16_t*) pData ;
|
|
519 if(hirda->Init.Parity == IRDA_PARITY_NONE)
|
|
520 {
|
|
521 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x01FF);
|
|
522 pData +=2;
|
|
523 }
|
|
524 else
|
|
525 {
|
|
526 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x00FF);
|
|
527 pData +=1;
|
|
528 }
|
|
529 }
|
|
530 else
|
|
531 {
|
|
532 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, Timeout) != HAL_OK)
|
|
533 {
|
|
534 return HAL_TIMEOUT;
|
|
535 }
|
|
536 if(hirda->Init.Parity == IRDA_PARITY_NONE)
|
|
537 {
|
|
538 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x00FF);
|
|
539 }
|
|
540 else
|
|
541 {
|
|
542 *pData++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x007F);
|
|
543 }
|
|
544 }
|
|
545 }
|
|
546 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
|
|
547 {
|
|
548 hirda->State = HAL_IRDA_STATE_BUSY_TX;
|
|
549 }
|
|
550 else
|
|
551 {
|
|
552 hirda->State = HAL_IRDA_STATE_READY;
|
|
553 }
|
|
554
|
|
555 /* Process Unlocked */
|
|
556 __HAL_UNLOCK(hirda);
|
|
557
|
|
558 return HAL_OK;
|
|
559 }
|
|
560 else
|
|
561 {
|
|
562 return HAL_BUSY;
|
|
563 }
|
|
564 }
|
|
565
|
|
566 /**
|
|
567 * @brief Send an amount of data in non blocking mode.
|
|
568 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
569 * the configuration information for the specified IRDA module.
|
|
570 * @param pData: Pointer to data buffer
|
|
571 * @param Size: Amount of data to be sent
|
|
572 * @retval HAL status
|
|
573 */
|
|
574 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
|
|
575 {
|
|
576 uint32_t tmp1 = 0;
|
|
577
|
|
578 tmp1 = hirda->State;
|
|
579 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_RX))
|
|
580 {
|
|
581 if((pData == NULL) || (Size == 0))
|
|
582 {
|
|
583 return HAL_ERROR;
|
|
584 }
|
|
585 /* Process Locked */
|
|
586 __HAL_LOCK(hirda);
|
|
587
|
|
588 hirda->pTxBuffPtr = pData;
|
|
589 hirda->TxXferSize = Size;
|
|
590 hirda->TxXferCount = Size;
|
|
591 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
|
|
592 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
|
|
593 {
|
|
594 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
|
|
595 }
|
|
596 else
|
|
597 {
|
|
598 hirda->State = HAL_IRDA_STATE_BUSY_TX;
|
|
599 }
|
|
600
|
|
601 /* Process Unlocked */
|
|
602 __HAL_UNLOCK(hirda);
|
|
603
|
|
604 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
|
|
605 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
|
|
606
|
|
607 /* Enable the IRDA Transmit Data Register Empty Interrupt */
|
|
608 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TXE);
|
|
609
|
|
610 return HAL_OK;
|
|
611 }
|
|
612 else
|
|
613 {
|
|
614 return HAL_BUSY;
|
|
615 }
|
|
616 }
|
|
617
|
|
618 /**
|
|
619 * @brief Receives an amount of data in non blocking mode.
|
|
620 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
621 * the configuration information for the specified IRDA module.
|
|
622 * @param pData: Pointer to data buffer
|
|
623 * @param Size: Amount of data to be received
|
|
624 * @retval HAL status
|
|
625 */
|
|
626 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
|
|
627 {
|
|
628 uint32_t tmp1 = 0;
|
|
629
|
|
630 tmp1 = hirda->State;
|
|
631 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_TX))
|
|
632 {
|
|
633 if((pData == NULL) || (Size == 0))
|
|
634 {
|
|
635 return HAL_ERROR;
|
|
636 }
|
|
637
|
|
638 /* Process Locked */
|
|
639 __HAL_LOCK(hirda);
|
|
640
|
|
641 hirda->pRxBuffPtr = pData;
|
|
642 hirda->RxXferSize = Size;
|
|
643 hirda->RxXferCount = Size;
|
|
644 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
|
|
645 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
|
|
646 {
|
|
647 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
|
|
648 }
|
|
649 else
|
|
650 {
|
|
651 hirda->State = HAL_IRDA_STATE_BUSY_RX;
|
|
652 }
|
|
653
|
|
654 /* Process Unlocked */
|
|
655 __HAL_UNLOCK(hirda);
|
|
656
|
|
657 /* Enable the IRDA Data Register not empty Interrupt */
|
|
658 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_RXNE);
|
|
659
|
|
660 /* Enable the IRDA Parity Error Interrupt */
|
|
661 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_PE);
|
|
662
|
|
663 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
|
|
664 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
|
|
665
|
|
666 return HAL_OK;
|
|
667 }
|
|
668 else
|
|
669 {
|
|
670 return HAL_BUSY;
|
|
671 }
|
|
672 }
|
|
673
|
|
674 /**
|
|
675 * @brief Sends an amount of data in non blocking mode.
|
|
676 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
677 * the configuration information for the specified IRDA module.
|
|
678 * @param pData: Pointer to data buffer
|
|
679 * @param Size: Amount of data to be sent
|
|
680 * @retval HAL status
|
|
681 */
|
|
682 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
|
|
683 {
|
|
684 uint32_t *tmp;
|
|
685 uint32_t tmp1 = 0;
|
|
686
|
|
687 tmp1 = hirda->State;
|
|
688 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_RX))
|
|
689 {
|
|
690 if((pData == NULL) || (Size == 0))
|
|
691 {
|
|
692 return HAL_ERROR;
|
|
693 }
|
|
694
|
|
695 /* Process Locked */
|
|
696 __HAL_LOCK(hirda);
|
|
697
|
|
698 hirda->pTxBuffPtr = pData;
|
|
699 hirda->TxXferSize = Size;
|
|
700 hirda->TxXferCount = Size;
|
|
701 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
|
|
702
|
|
703 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
|
|
704 {
|
|
705 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
|
|
706 }
|
|
707 else
|
|
708 {
|
|
709 hirda->State = HAL_IRDA_STATE_BUSY_TX;
|
|
710 }
|
|
711
|
|
712 /* Set the IRDA DMA transfer complete callback */
|
|
713 hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
|
|
714
|
|
715 /* Set the IRDA DMA half transfer complete callback */
|
|
716 hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
|
|
717
|
|
718 /* Set the DMA error callback */
|
|
719 hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
|
|
720
|
|
721 /* Enable the IRDA transmit DMA Stream */
|
|
722 tmp = (uint32_t*)&pData;
|
|
723 HAL_DMA_Start_IT(hirda->hdmatx, *(uint32_t*)tmp, (uint32_t)&hirda->Instance->DR, Size);
|
|
724
|
|
725 /* Clear the TC flag in the SR register by writing 0 to it */
|
|
726 __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_FLAG_TC);
|
|
727
|
|
728 /* Enable the DMA transfer for transmit request by setting the DMAT bit
|
|
729 in the USART CR3 register */
|
|
730 hirda->Instance->CR3 |= USART_CR3_DMAT;
|
|
731
|
|
732 /* Process Unlocked */
|
|
733 __HAL_UNLOCK(hirda);
|
|
734
|
|
735 return HAL_OK;
|
|
736 }
|
|
737 else
|
|
738 {
|
|
739 return HAL_BUSY;
|
|
740 }
|
|
741 }
|
|
742
|
|
743 /**
|
|
744 * @brief Receives an amount of data in non blocking mode.
|
|
745 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
746 * the configuration information for the specified IRDA module.
|
|
747 * @param pData: Pointer to data buffer
|
|
748 * @param Size: Amount of data to be received
|
|
749 * @note When the IRDA parity is enabled (PCE = 1) the data received contain the parity bit.
|
|
750 * @retval HAL status
|
|
751 */
|
|
752 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
|
|
753 {
|
|
754 uint32_t *tmp;
|
|
755 uint32_t tmp1 = 0;
|
|
756
|
|
757 tmp1 = hirda->State;
|
|
758 if((tmp1 == HAL_IRDA_STATE_READY) || (tmp1 == HAL_IRDA_STATE_BUSY_TX))
|
|
759 {
|
|
760 if((pData == NULL) || (Size == 0))
|
|
761 {
|
|
762 return HAL_ERROR;
|
|
763 }
|
|
764
|
|
765 /* Process Locked */
|
|
766 __HAL_LOCK(hirda);
|
|
767
|
|
768 hirda->pRxBuffPtr = pData;
|
|
769 hirda->RxXferSize = Size;
|
|
770 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
|
|
771 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
|
|
772 {
|
|
773 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
|
|
774 }
|
|
775 else
|
|
776 {
|
|
777 hirda->State = HAL_IRDA_STATE_BUSY_RX;
|
|
778 }
|
|
779
|
|
780 /* Set the IRDA DMA transfer complete callback */
|
|
781 hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
|
|
782
|
|
783 /* Set the IRDA DMA half transfer complete callback */
|
|
784 hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
|
|
785
|
|
786 /* Set the DMA error callback */
|
|
787 hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
|
|
788
|
|
789 /* Enable the DMA Stream */
|
|
790 tmp = (uint32_t*)&pData;
|
|
791 HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->DR, *(uint32_t*)tmp, Size);
|
|
792
|
|
793 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
|
|
794 in the USART CR3 register */
|
|
795 hirda->Instance->CR3 |= USART_CR3_DMAR;
|
|
796
|
|
797 /* Process Unlocked */
|
|
798 __HAL_UNLOCK(hirda);
|
|
799
|
|
800 return HAL_OK;
|
|
801 }
|
|
802 else
|
|
803 {
|
|
804 return HAL_BUSY;
|
|
805 }
|
|
806 }
|
|
807
|
|
808 /**
|
|
809 * @brief Pauses the DMA Transfer.
|
|
810 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
811 * the configuration information for the specified IRDA module.
|
|
812 * @retval HAL status
|
|
813 */
|
|
814 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
|
|
815 {
|
|
816 /* Process Locked */
|
|
817 __HAL_LOCK(hirda);
|
|
818
|
|
819 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
|
|
820 {
|
|
821 /* Disable the UART DMA Tx request */
|
|
822 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
|
|
823 }
|
|
824 else if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
|
|
825 {
|
|
826 /* Disable the UART DMA Rx request */
|
|
827 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
|
|
828 }
|
|
829 else if (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
|
|
830 {
|
|
831 /* Disable the UART DMA Tx & Rx requests */
|
|
832 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
|
|
833 hirda->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
|
|
834 }
|
|
835 else
|
|
836 {
|
|
837 /* Process Unlocked */
|
|
838 __HAL_UNLOCK(hirda);
|
|
839
|
|
840 return HAL_ERROR;
|
|
841 }
|
|
842
|
|
843 /* Process Unlocked */
|
|
844 __HAL_UNLOCK(hirda);
|
|
845
|
|
846 return HAL_OK;
|
|
847 }
|
|
848
|
|
849 /**
|
|
850 * @brief Resumes the DMA Transfer.
|
|
851 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
852 * the configuration information for the specified UART module.
|
|
853 * @retval HAL status
|
|
854 */
|
|
855 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
|
|
856 {
|
|
857 /* Process Locked */
|
|
858 __HAL_LOCK(hirda);
|
|
859
|
|
860 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
|
|
861 {
|
|
862 /* Enable the UART DMA Tx request */
|
|
863 hirda->Instance->CR3 |= USART_CR3_DMAT;
|
|
864 }
|
|
865 else if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
|
|
866 {
|
|
867 /* Clear the Overrun flag before resuming the Rx transfer */
|
|
868 __HAL_IRDA_CLEAR_OREFLAG(hirda);
|
|
869 /* Enable the UART DMA Rx request */
|
|
870 hirda->Instance->CR3 |= USART_CR3_DMAR;
|
|
871 }
|
|
872 else if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
|
|
873 {
|
|
874 /* Clear the Overrun flag before resuming the Rx transfer */
|
|
875 __HAL_IRDA_CLEAR_OREFLAG(hirda);
|
|
876 /* Enable the UART DMA Tx & Rx request */
|
|
877 hirda->Instance->CR3 |= USART_CR3_DMAT;
|
|
878 hirda->Instance->CR3 |= USART_CR3_DMAR;
|
|
879 }
|
|
880 else
|
|
881 {
|
|
882 /* Process Unlocked */
|
|
883 __HAL_UNLOCK(hirda);
|
|
884
|
|
885 return HAL_ERROR;
|
|
886 }
|
|
887
|
|
888 /* Process Unlocked */
|
|
889 __HAL_UNLOCK(hirda);
|
|
890
|
|
891 return HAL_OK;
|
|
892 }
|
|
893
|
|
894 /**
|
|
895 * @brief Stops the DMA Transfer.
|
|
896 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
897 * the configuration information for the specified UART module.
|
|
898 * @retval HAL status
|
|
899 */
|
|
900 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
|
|
901 {
|
|
902 /* The Lock is not implemented on this API to allow the user application
|
|
903 to call the HAL UART API under callbacks HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback():
|
|
904 when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
|
|
905 and the correspond call back is executed HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback()
|
|
906 */
|
|
907
|
|
908 /* Disable the UART Tx/Rx DMA requests */
|
|
909 hirda->Instance->CR3 &= ~USART_CR3_DMAT;
|
|
910 hirda->Instance->CR3 &= ~USART_CR3_DMAR;
|
|
911
|
|
912 /* Abort the UART DMA tx Stream */
|
|
913 if(hirda->hdmatx != NULL)
|
|
914 {
|
|
915 HAL_DMA_Abort(hirda->hdmatx);
|
|
916 }
|
|
917 /* Abort the UART DMA rx Stream */
|
|
918 if(hirda->hdmarx != NULL)
|
|
919 {
|
|
920 HAL_DMA_Abort(hirda->hdmarx);
|
|
921 }
|
|
922
|
|
923 hirda->State = HAL_IRDA_STATE_READY;
|
|
924
|
|
925 return HAL_OK;
|
|
926 }
|
|
927
|
|
928 /**
|
|
929 * @brief This function handles IRDA interrupt request.
|
|
930 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
931 * the configuration information for the specified IRDA module.
|
|
932 * @retval None
|
|
933 */
|
|
934 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
|
|
935 {
|
|
936 uint32_t tmp1 = 0, tmp2 =0;
|
|
937
|
|
938 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_PE);
|
|
939 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE);
|
|
940 /* IRDA parity error interrupt occurred -------------------------------------*/
|
|
941 if((tmp1 != RESET) && (tmp2 != RESET))
|
|
942 {
|
|
943 __HAL_IRDA_CLEAR_PEFLAG(hirda);
|
|
944 hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
|
|
945 }
|
|
946
|
|
947 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_FE);
|
|
948 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
|
|
949 /* IRDA frame error interrupt occurred --------------------------------------*/
|
|
950 if((tmp1 != RESET) && (tmp2 != RESET))
|
|
951 {
|
|
952 __HAL_IRDA_CLEAR_FEFLAG(hirda);
|
|
953 hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
|
|
954 }
|
|
955
|
|
956 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_NE);
|
|
957 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
|
|
958 /* IRDA noise error interrupt occurred --------------------------------------*/
|
|
959 if((tmp1 != RESET) && (tmp2 != RESET))
|
|
960 {
|
|
961 __HAL_IRDA_CLEAR_NEFLAG(hirda);
|
|
962 hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
|
|
963 }
|
|
964
|
|
965 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_ORE);
|
|
966 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR);
|
|
967 /* IRDA Over-Run interrupt occurred -----------------------------------------*/
|
|
968 if((tmp1 != RESET) && (tmp2 != RESET))
|
|
969 {
|
|
970 __HAL_IRDA_CLEAR_OREFLAG(hirda);
|
|
971 hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
|
|
972 }
|
|
973
|
|
974 /* Call the Error call Back in case of Errors */
|
|
975 if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
|
|
976 {
|
|
977 /* Set the IRDA state ready to be able to start again the process */
|
|
978 hirda->State = HAL_IRDA_STATE_READY;
|
|
979 HAL_IRDA_ErrorCallback(hirda);
|
|
980 }
|
|
981
|
|
982 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_RXNE);
|
|
983 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_RXNE);
|
|
984 /* IRDA in mode Receiver ---------------------------------------------------*/
|
|
985 if((tmp1 != RESET) && (tmp2 != RESET))
|
|
986 {
|
|
987 IRDA_Receive_IT(hirda);
|
|
988 }
|
|
989
|
|
990 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_TXE);
|
|
991 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TXE);
|
|
992 /* IRDA in mode Transmitter ------------------------------------------------*/
|
|
993 if((tmp1 != RESET) &&(tmp2 != RESET))
|
|
994 {
|
|
995 IRDA_Transmit_IT(hirda);
|
|
996 }
|
|
997
|
|
998 tmp1 = __HAL_IRDA_GET_FLAG(hirda, IRDA_FLAG_TC);
|
|
999 tmp2 = __HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TC);
|
|
1000 /* IRDA in mode Transmitter (transmission end) -----------------------------*/
|
|
1001 if((tmp1 != RESET) && (tmp2 != RESET))
|
|
1002 {
|
|
1003 IRDA_EndTransmit_IT(hirda);
|
|
1004 }
|
|
1005 }
|
|
1006
|
|
1007 /**
|
|
1008 * @brief Tx Transfer complete callbacks.
|
|
1009 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1010 * the configuration information for the specified IRDA module.
|
|
1011 * @retval None
|
|
1012 */
|
|
1013 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
|
|
1014 {
|
|
1015 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
1016 the HAL_IRDA_TxCpltCallback could be implemented in the user file
|
|
1017 */
|
|
1018 }
|
|
1019
|
|
1020 /**
|
|
1021 * @brief Tx Half Transfer completed callbacks.
|
|
1022 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1023 * the configuration information for the specified USART module.
|
|
1024 * @retval None
|
|
1025 */
|
|
1026 __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
|
|
1027 {
|
|
1028 /* NOTE: This function Should not be modified, when the callback is needed,
|
|
1029 the HAL_IRDA_TxHalfCpltCallback could be implemented in the user file
|
|
1030 */
|
|
1031 }
|
|
1032
|
|
1033 /**
|
|
1034 * @brief Rx Transfer complete callbacks.
|
|
1035 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1036 * the configuration information for the specified IRDA module.
|
|
1037 * @retval None
|
|
1038 */
|
|
1039 __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
|
|
1040 {
|
|
1041 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
1042 the HAL_IRDA_RxCpltCallback could be implemented in the user file
|
|
1043 */
|
|
1044 }
|
|
1045
|
|
1046 /**
|
|
1047 * @brief Rx Half Transfer complete callbacks.
|
|
1048 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1049 * the configuration information for the specified IRDA module.
|
|
1050 * @retval None
|
|
1051 */
|
|
1052 __weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
|
|
1053 {
|
|
1054 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
1055 the HAL_IRDA_RxHalfCpltCallback could be implemented in the user file
|
|
1056 */
|
|
1057 }
|
|
1058
|
|
1059 /**
|
|
1060 * @brief IRDA error callbacks.
|
|
1061 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1062 * the configuration information for the specified IRDA module.
|
|
1063 * @retval None
|
|
1064 */
|
|
1065 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
|
|
1066 {
|
|
1067 /* NOTE : This function Should not be modified, when the callback is needed,
|
|
1068 the HAL_IRDA_ErrorCallback could be implemented in the user file
|
|
1069 */
|
|
1070 }
|
|
1071
|
|
1072 /**
|
|
1073 * @}
|
|
1074 */
|
|
1075
|
|
1076 /** @defgroup IRDA_Exported_Functions_Group3 Peripheral State and Errors functions
|
|
1077 * @brief IRDA State and Errors functions
|
|
1078 *
|
|
1079 @verbatim
|
|
1080 ==============================================================================
|
|
1081 ##### Peripheral State and Errors functions #####
|
|
1082 ==============================================================================
|
|
1083 [..]
|
|
1084 This subsection provides a set of functions allowing to return the State of IrDA
|
|
1085 communication process and also return Peripheral Errors occurred during communication process
|
|
1086 (+) HAL_IRDA_GetState() API can be helpful to check in run-time the state of the IrDA peripheral.
|
|
1087 (+) HAL_IRDA_GetError() check in run-time errors that could be occurred during communication.
|
|
1088
|
|
1089 @endverbatim
|
|
1090 * @{
|
|
1091 */
|
|
1092
|
|
1093 /**
|
|
1094 * @brief Returns the IRDA state.
|
|
1095 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1096 * the configuration information for the specified IRDA module.
|
|
1097 * @retval HAL state
|
|
1098 */
|
|
1099 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda)
|
|
1100 {
|
|
1101 return hirda->State;
|
|
1102 }
|
|
1103
|
|
1104 /**
|
|
1105 * @brief Return the IARDA error code
|
|
1106 * @param hirda : pointer to a IRDA_HandleTypeDef structure that contains
|
|
1107 * the configuration information for the specified IRDA.
|
|
1108 * @retval IRDA Error Code
|
|
1109 */
|
|
1110 uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda)
|
|
1111 {
|
|
1112 return hirda->ErrorCode;
|
|
1113 }
|
|
1114
|
|
1115 /**
|
|
1116 * @}
|
|
1117 */
|
|
1118
|
|
1119 /**
|
|
1120 * @brief DMA IRDA transmit process complete callback.
|
|
1121 * @param hdma : DMA handle
|
|
1122 * @retval None
|
|
1123 */
|
|
1124 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
|
|
1125 {
|
|
1126 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
1127 /* DMA Normal mode */
|
|
1128 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
|
|
1129 {
|
|
1130 hirda->TxXferCount = 0;
|
|
1131
|
|
1132 /* Disable the DMA transfer for transmit request by setting the DMAT bit
|
|
1133 in the IRDA CR3 register */
|
|
1134 hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAT);
|
|
1135
|
|
1136 /* Enable the IRDA Transmit Complete Interrupt */
|
|
1137 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TC);
|
|
1138 }
|
|
1139 /* DMA Circular mode */
|
|
1140 else
|
|
1141 {
|
|
1142 HAL_IRDA_TxCpltCallback(hirda);
|
|
1143 }
|
|
1144 }
|
|
1145
|
|
1146 /**
|
|
1147 * @brief DMA IRDA receive process half complete callback
|
|
1148 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
|
1149 * the configuration information for the specified DMA module.
|
|
1150 * @retval None
|
|
1151 */
|
|
1152 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
|
|
1153 {
|
|
1154 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
1155
|
|
1156 HAL_IRDA_TxHalfCpltCallback(hirda);
|
|
1157 }
|
|
1158
|
|
1159 /**
|
|
1160 * @brief DMA IRDA receive process complete callback.
|
|
1161 * @param hdma: DMA handle
|
|
1162 * @retval None
|
|
1163 */
|
|
1164 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
|
|
1165 {
|
|
1166 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
1167 /* DMA Normal mode */
|
|
1168 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
|
|
1169 {
|
|
1170 hirda->RxXferCount = 0;
|
|
1171
|
|
1172 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
|
|
1173 in the IRDA CR3 register */
|
|
1174 hirda->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAR);
|
|
1175
|
|
1176 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
|
|
1177 {
|
|
1178 hirda->State = HAL_IRDA_STATE_BUSY_TX;
|
|
1179 }
|
|
1180 else
|
|
1181 {
|
|
1182 hirda->State = HAL_IRDA_STATE_READY;
|
|
1183 }
|
|
1184 }
|
|
1185
|
|
1186 HAL_IRDA_RxCpltCallback(hirda);
|
|
1187 }
|
|
1188
|
|
1189 /**
|
|
1190 * @brief DMA IRDA receive process half complete callback
|
|
1191 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
|
|
1192 * the configuration information for the specified DMA module.
|
|
1193 * @retval None
|
|
1194 */
|
|
1195 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
|
|
1196 {
|
|
1197 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
1198
|
|
1199 HAL_IRDA_RxHalfCpltCallback(hirda);
|
|
1200 }
|
|
1201
|
|
1202 /**
|
|
1203 * @brief DMA IRDA communication error callback.
|
|
1204 * @param hdma: DMA handle
|
|
1205 * @retval None
|
|
1206 */
|
|
1207 static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
|
|
1208 {
|
|
1209 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
|
|
1210
|
|
1211 hirda->RxXferCount = 0;
|
|
1212 hirda->TxXferCount = 0;
|
|
1213 hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
|
|
1214 hirda->State= HAL_IRDA_STATE_READY;
|
|
1215
|
|
1216 HAL_IRDA_ErrorCallback(hirda);
|
|
1217 }
|
|
1218
|
|
1219 /**
|
|
1220 * @brief This function handles IRDA Communication Timeout.
|
|
1221 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1222 * the configuration information for the specified IRDA module.
|
|
1223 * @param Flag: specifies the IRDA flag to check.
|
|
1224 * @param Status: The new Flag status (SET or RESET).
|
|
1225 * @param Timeout: Timeout duration
|
|
1226 * @retval HAL status
|
|
1227 */
|
|
1228 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
|
|
1229 {
|
|
1230 uint32_t tickstart = 0;
|
|
1231
|
|
1232 /* Get tick */
|
|
1233 tickstart = HAL_GetTick();
|
|
1234
|
|
1235 /* Wait until flag is set */
|
|
1236 if(Status == RESET)
|
|
1237 {
|
|
1238 while(__HAL_IRDA_GET_FLAG(hirda, Flag) == RESET)
|
|
1239 {
|
|
1240 /* Check for the Timeout */
|
|
1241 if(Timeout != HAL_MAX_DELAY)
|
|
1242 {
|
|
1243 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
|
|
1244 {
|
|
1245 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
|
|
1246 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
|
|
1247 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
|
|
1248 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
|
|
1249 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
|
|
1250
|
|
1251 hirda->State= HAL_IRDA_STATE_READY;
|
|
1252
|
|
1253 /* Process Unlocked */
|
|
1254 __HAL_UNLOCK(hirda);
|
|
1255
|
|
1256 return HAL_TIMEOUT;
|
|
1257 }
|
|
1258 }
|
|
1259 }
|
|
1260 }
|
|
1261 else
|
|
1262 {
|
|
1263 while(__HAL_IRDA_GET_FLAG(hirda, Flag) != RESET)
|
|
1264 {
|
|
1265 /* Check for the Timeout */
|
|
1266 if(Timeout != HAL_MAX_DELAY)
|
|
1267 {
|
|
1268 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
|
|
1269 {
|
|
1270 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
|
|
1271 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
|
|
1272 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
|
|
1273 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
|
|
1274 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
|
|
1275
|
|
1276 hirda->State= HAL_IRDA_STATE_READY;
|
|
1277
|
|
1278 /* Process Unlocked */
|
|
1279 __HAL_UNLOCK(hirda);
|
|
1280
|
|
1281 return HAL_TIMEOUT;
|
|
1282 }
|
|
1283 }
|
|
1284 }
|
|
1285 }
|
|
1286 return HAL_OK;
|
|
1287 }
|
|
1288
|
|
1289 /**
|
|
1290 * @brief Send an amount of data in non blocking mode.
|
|
1291 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1292 * the configuration information for the specified IRDA module.
|
|
1293 * @retval HAL status
|
|
1294 */
|
|
1295 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
|
|
1296 {
|
|
1297 uint16_t* tmp;
|
|
1298 uint32_t tmp1 = 0;
|
|
1299
|
|
1300 tmp1 = hirda->State;
|
|
1301 if((tmp1 == HAL_IRDA_STATE_BUSY_TX) || (tmp1 == HAL_IRDA_STATE_BUSY_TX_RX))
|
|
1302 {
|
|
1303 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
|
|
1304 {
|
|
1305 tmp = (uint16_t*) hirda->pTxBuffPtr;
|
|
1306 hirda->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
|
|
1307 if(hirda->Init.Parity == IRDA_PARITY_NONE)
|
|
1308 {
|
|
1309 hirda->pTxBuffPtr += 2;
|
|
1310 }
|
|
1311 else
|
|
1312 {
|
|
1313 hirda->pTxBuffPtr += 1;
|
|
1314 }
|
|
1315 }
|
|
1316 else
|
|
1317 {
|
|
1318 hirda->Instance->DR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0x00FF);
|
|
1319 }
|
|
1320
|
|
1321 if(--hirda->TxXferCount == 0)
|
|
1322 {
|
|
1323 /* Disable the IRDA Transmit Data Register Empty Interrupt */
|
|
1324 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
|
|
1325
|
|
1326 /* Enable the IRDA Transmit Complete Interrupt */
|
|
1327 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TC);
|
|
1328 }
|
|
1329
|
|
1330 return HAL_OK;
|
|
1331 }
|
|
1332 else
|
|
1333 {
|
|
1334 return HAL_BUSY;
|
|
1335 }
|
|
1336 }
|
|
1337
|
|
1338 /**
|
|
1339 * @brief Wraps up transmission in non blocking mode.
|
|
1340 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1341 * the configuration information for the specified IRDA module.
|
|
1342 * @retval HAL status
|
|
1343 */
|
|
1344 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda)
|
|
1345 {
|
|
1346 /* Disable the IRDA Transmit Complete Interrupt */
|
|
1347 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TC);
|
|
1348
|
|
1349 /* Check if a receive process is ongoing or not */
|
|
1350 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
|
|
1351 {
|
|
1352 hirda->State = HAL_IRDA_STATE_BUSY_RX;
|
|
1353 }
|
|
1354 else
|
|
1355 {
|
|
1356 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
|
|
1357 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
|
|
1358
|
|
1359 hirda->State = HAL_IRDA_STATE_READY;
|
|
1360 }
|
|
1361
|
|
1362 HAL_IRDA_TxCpltCallback(hirda);
|
|
1363
|
|
1364 return HAL_OK;
|
|
1365 }
|
|
1366
|
|
1367 /**
|
|
1368 * @brief Receives an amount of data in non blocking mode.
|
|
1369 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1370 * the configuration information for the specified IRDA module.
|
|
1371 * @retval HAL status
|
|
1372 */
|
|
1373 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
|
|
1374 {
|
|
1375 uint16_t* tmp;
|
|
1376 uint32_t tmp1 = 0;
|
|
1377
|
|
1378 tmp1 = hirda->State;
|
|
1379 if((tmp1 == HAL_IRDA_STATE_BUSY_RX) || (tmp1 == HAL_IRDA_STATE_BUSY_TX_RX))
|
|
1380 {
|
|
1381 if(hirda->Init.WordLength == IRDA_WORDLENGTH_9B)
|
|
1382 {
|
|
1383 tmp = (uint16_t*) hirda->pRxBuffPtr;
|
|
1384 if(hirda->Init.Parity == IRDA_PARITY_NONE)
|
|
1385 {
|
|
1386 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x01FF);
|
|
1387 hirda->pRxBuffPtr += 2;
|
|
1388 }
|
|
1389 else
|
|
1390 {
|
|
1391 *tmp = (uint16_t)(hirda->Instance->DR & (uint16_t)0x00FF);
|
|
1392 hirda->pRxBuffPtr += 1;
|
|
1393 }
|
|
1394 }
|
|
1395 else
|
|
1396 {
|
|
1397 if(hirda->Init.Parity == IRDA_PARITY_NONE)
|
|
1398 {
|
|
1399 *hirda->pRxBuffPtr++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x00FF);
|
|
1400 }
|
|
1401 else
|
|
1402 {
|
|
1403 *hirda->pRxBuffPtr++ = (uint8_t)(hirda->Instance->DR & (uint8_t)0x007F);
|
|
1404 }
|
|
1405 }
|
|
1406
|
|
1407 if(--hirda->RxXferCount == 0)
|
|
1408 {
|
|
1409
|
|
1410 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
|
|
1411
|
|
1412 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
|
|
1413 {
|
|
1414 hirda->State = HAL_IRDA_STATE_BUSY_TX;
|
|
1415 }
|
|
1416 else
|
|
1417 {
|
|
1418 /* Disable the IRDA Parity Error Interrupt */
|
|
1419 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
|
|
1420
|
|
1421 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
|
|
1422 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
|
|
1423
|
|
1424 hirda->State = HAL_IRDA_STATE_READY;
|
|
1425 }
|
|
1426 HAL_IRDA_RxCpltCallback(hirda);
|
|
1427
|
|
1428 return HAL_OK;
|
|
1429 }
|
|
1430 return HAL_OK;
|
|
1431 }
|
|
1432 else
|
|
1433 {
|
|
1434 return HAL_BUSY;
|
|
1435 }
|
|
1436 }
|
|
1437
|
|
1438 /**
|
|
1439 * @brief Configures the IRDA peripheral.
|
|
1440 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
|
|
1441 * the configuration information for the specified IRDA module.
|
|
1442 * @retval None
|
|
1443 */
|
|
1444 static void IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
|
|
1445 {
|
|
1446 uint32_t tmpreg = 0x00;
|
|
1447
|
|
1448 /* Check the parameters */
|
|
1449 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
|
|
1450 assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
|
|
1451 assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
|
|
1452 assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
|
|
1453 assert_param(IS_IRDA_MODE(hirda->Init.Mode));
|
|
1454
|
|
1455 /*-------------------------- IRDA CR2 Configuration ------------------------*/
|
|
1456 /* Clear STOP[13:12] bits */
|
|
1457 hirda->Instance->CR2 &= (uint32_t)~((uint32_t)USART_CR2_STOP);
|
|
1458
|
|
1459 /*-------------------------- USART CR1 Configuration -----------------------*/
|
|
1460 tmpreg = hirda->Instance->CR1;
|
|
1461
|
|
1462 /* Clear M, PCE, PS, TE and RE bits */
|
|
1463 tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | \
|
|
1464 USART_CR1_RE));
|
|
1465
|
|
1466 /* Configure the USART Word Length, Parity and mode:
|
|
1467 Set the M bits according to hirda->Init.WordLength value
|
|
1468 Set PCE and PS bits according to hirda->Init.Parity value
|
|
1469 Set TE and RE bits according to hirda->Init.Mode value */
|
|
1470 tmpreg |= (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode;
|
|
1471
|
|
1472 /* Write to USART CR1 */
|
|
1473 hirda->Instance->CR1 = (uint32_t)tmpreg;
|
|
1474
|
|
1475 /*-------------------------- USART CR3 Configuration -----------------------*/
|
|
1476 /* Clear CTSE and RTSE bits */
|
|
1477 hirda->Instance->CR3 &= (uint32_t)~((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE));
|
|
1478
|
|
1479 /*-------------------------- USART BRR Configuration -----------------------*/
|
|
1480 if((hirda->Instance == USART1) || (hirda->Instance == USART6))
|
|
1481 {
|
|
1482 hirda->Instance->BRR = IRDA_BRR(HAL_RCC_GetPCLK2Freq(), hirda->Init.BaudRate);
|
|
1483 }
|
|
1484 else
|
|
1485 {
|
|
1486 hirda->Instance->BRR = IRDA_BRR(HAL_RCC_GetPCLK1Freq(), hirda->Init.BaudRate);
|
|
1487 }
|
|
1488 }
|
|
1489 /**
|
|
1490 * @}
|
|
1491 */
|
|
1492
|
|
1493 #endif /* HAL_IRDA_MODULE_ENABLED */
|
|
1494 /**
|
|
1495 * @}
|
|
1496 */
|
|
1497
|
|
1498 /**
|
|
1499 * @}
|
|
1500 */
|
|
1501
|
|
1502 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|