2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_uart.c
\r
4 * @author MCD Application Team
\r
6 * @date 06-March-2015
\r
7 * @brief UART HAL module driver.
\r
9 * This file provides firmware functions to manage the following
\r
10 * functionalities of the Universal Asynchronous Receiver Transmitter (UART) peripheral:
\r
11 * + Initialization and de-initialization functions
\r
12 * + IO operation functions
\r
13 * + Peripheral Control functions
\r
14 * + Peripheral State and Errors functions
\r
17 ==============================================================================
\r
18 ##### How to use this driver #####
\r
19 ==============================================================================
\r
21 The UART HAL driver can be used as follows:
\r
23 (#) Declare a UART_HandleTypeDef handle structure.
\r
25 (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API:
\r
26 (##) Enable the USARTx interface clock.
\r
27 (##) UART pins configuration:
\r
28 (+++) Enable the clock for the UART GPIOs.
\r
29 (+++) Configure these UART pins as alternate function pull-up.
\r
30 (##) NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT()
\r
31 and HAL_UART_Receive_IT() APIs):
\r
32 (+++) Configure the USARTx interrupt priority.
\r
33 (+++) Enable the NVIC USART IRQ handle.
\r
34 (##) DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA()
\r
35 and HAL_UART_Receive_DMA() APIs):
\r
36 (+++) Declare a DMA handle structure for the Tx/Rx stream.
\r
37 (+++) Enable the DMAx interface clock.
\r
38 (+++) Configure the declared DMA handle structure with the required
\r
40 (+++) Configure the DMA Tx/Rx Stream.
\r
41 (+++) Associate the initialized DMA handle to the UART DMA Tx/Rx handle.
\r
42 (+++) Configure the priority and enable the NVIC for the transfer complete
\r
43 interrupt on the DMA Tx/Rx Stream.
\r
45 (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware
\r
46 flow control and Mode(Receiver/Transmitter) in the Init structure.
\r
48 (#) For the UART asynchronous mode, initialize the UART registers by calling
\r
49 the HAL_UART_Init() API.
\r
51 (#) For the UART Half duplex mode, initialize the UART registers by calling
\r
52 the HAL_HalfDuplex_Init() API.
\r
54 (#) For the LIN mode, initialize the UART registers by calling the HAL_LIN_Init() API.
\r
56 (#) For the Multi-Processor mode, initialize the UART registers by calling
\r
57 the HAL_MultiProcessor_Init() API.
\r
60 (@) The specific UART interrupts (Transmission complete interrupt,
\r
61 RXNE interrupt and Error Interrupts) will be managed using the macros
\r
62 __HAL_UART_ENABLE_IT() and __HAL_UART_DISABLE_IT() inside the transmit
\r
63 and receive process.
\r
66 (@) These APIs (HAL_UART_Init() and HAL_HalfDuplex_Init()) configure also the
\r
67 low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized
\r
68 HAL_UART_MspInit() API.
\r
71 Three operation modes are available within this driver :
\r
73 *** Polling mode IO operation ***
\r
74 =================================
\r
76 (+) Send an amount of data in blocking mode using HAL_UART_Transmit()
\r
77 (+) Receive an amount of data in blocking mode using HAL_UART_Receive()
\r
79 *** Interrupt mode IO operation ***
\r
80 ===================================
\r
82 (+) Send an amount of data in non blocking mode using HAL_UART_Transmit_IT()
\r
83 (+) At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can
\r
84 add his own code by customization of function pointer HAL_UART_TxCpltCallback
\r
85 (+) Receive an amount of data in non blocking mode using HAL_UART_Receive_IT()
\r
86 (+) At reception end of transfer HAL_UART_RxCpltCallback is executed and user can
\r
87 add his own code by customization of function pointer HAL_UART_RxCpltCallback
\r
88 (+) In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can
\r
89 add his own code by customization of function pointer HAL_UART_ErrorCallback
\r
91 *** DMA mode IO operation ***
\r
92 ==============================
\r
94 (+) Send an amount of data in non blocking mode (DMA) using HAL_UART_Transmit_DMA()
\r
95 (+) At transmission end of half transfer HAL_UART_TxHalfCpltCallback is executed and user can
\r
96 add his own code by customization of function pointer HAL_UART_TxHalfCpltCallback
\r
97 (+) At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can
\r
98 add his own code by customization of function pointer HAL_UART_TxCpltCallback
\r
99 (+) Receive an amount of data in non blocking mode (DMA) using HAL_UART_Receive_DMA()
\r
100 (+) At reception end of half transfer HAL_UART_RxHalfCpltCallback is executed and user can
\r
101 add his own code by customization of function pointer HAL_UART_RxHalfCpltCallback
\r
102 (+) At reception end of transfer HAL_UART_RxCpltCallback is executed and user can
\r
103 add his own code by customization of function pointer HAL_UART_RxCpltCallback
\r
104 (+) In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can
\r
105 add his own code by customization of function pointer HAL_UART_ErrorCallback
\r
106 (+) Pause the DMA Transfer using HAL_UART_DMAPause()
\r
107 (+) Resume the DMA Transfer using HAL_UART_DMAResume()
\r
108 (+) Stop the DMA Transfer using HAL_UART_DMAStop()
\r
110 *** UART HAL driver macros list ***
\r
111 =============================================
\r
113 Below the list of most used macros in UART HAL driver.
\r
115 (+) __HAL_UART_ENABLE: Enable the UART peripheral
\r
116 (+) __HAL_UART_DISABLE: Disable the UART peripheral
\r
117 (+) __HAL_UART_GET_FLAG : Check whether the specified UART flag is set or not
\r
118 (+) __HAL_UART_CLEAR_IT : Clears the specified UART ISR flag
\r
119 (+) __HAL_UART_ENABLE_IT: Enable the specified UART interrupt
\r
120 (+) __HAL_UART_DISABLE_IT: Disable the specified UART interrupt
\r
121 (+) __HAL_UART_GET_IT_SOURCE: Check whether the specified UART interrupt has occurred or not
\r
124 (@) You can refer to the UART HAL driver header file for more useful macros
\r
127 ******************************************************************************
\r
130 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
132 * Redistribution and use in source and binary forms, with or without modification,
\r
133 * are permitted provided that the following conditions are met:
\r
134 * 1. Redistributions of source code must retain the above copyright notice,
\r
135 * this list of conditions and the following disclaimer.
\r
136 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
137 * this list of conditions and the following disclaimer in the documentation
\r
138 * and/or other materials provided with the distribution.
\r
139 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
140 * may be used to endorse or promote products derived from this software
\r
141 * without specific prior written permission.
\r
143 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
144 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
145 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
146 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
147 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
148 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
149 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
150 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
151 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
152 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
154 ******************************************************************************
\r
157 /* Includes ------------------------------------------------------------------*/
\r
158 #include "stm32f7xx_hal.h"
\r
160 /** @addtogroup STM32F7xx_HAL_Driver
\r
164 /** @defgroup UART UART
\r
165 * @brief HAL UART module driver
\r
168 #ifdef HAL_UART_MODULE_ENABLED
\r
170 /* Private typedef -----------------------------------------------------------*/
\r
171 /* Private define ------------------------------------------------------------*/
\r
172 #define HAL_UART_TXDMA_TIMEOUTVALUE 22000
\r
173 #define UART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | \
\r
174 USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8))
\r
175 /* Private macro -------------------------------------------------------------*/
\r
176 /* Private variables ---------------------------------------------------------*/
\r
177 /* Private function prototypes -----------------------------------------------*/
\r
178 static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma);
\r
179 static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
\r
180 static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
\r
181 static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
\r
182 static void UART_DMAError(DMA_HandleTypeDef *hdma);
\r
183 static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart);
\r
184 static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart);
\r
185 /* Private functions ---------------------------------------------------------*/
\r
187 /** @defgroup UART_Private_Functions
\r
191 /** @defgroup HAL_UART_Group1 Initialization/de-initialization functions
\r
192 * @brief Initialization and Configuration functions
\r
195 ===============================================================================
\r
196 ##### Initialization and Configuration functions #####
\r
197 ===============================================================================
\r
199 This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
\r
200 in asynchronous mode.
\r
201 (+) For the asynchronous mode only these parameters can be configured:
\r
205 (++) Parity: If the parity is enabled, then the MSB bit of the data written
\r
206 in the data register is transmitted but is changed by the parity bit.
\r
207 Depending on the frame length defined by the M bit (8-bits or 9-bits),
\r
208 please refer to Reference manual for possible UART frame formats.
\r
209 (++) Hardware flow control
\r
210 (++) Receiver/transmitter modes
\r
211 (++) Over Sampling Method
\r
213 The HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init() and HAL_MultiProcessor_Init() APIs
\r
214 follow respectively the UART asynchronous, UART Half duplex, LIN and Multi-Processor
\r
215 configuration procedures (details for the procedures are available in reference manual (RM0329)).
\r
222 * @brief Initializes the UART mode according to the specified
\r
223 * parameters in the UART_InitTypeDef and creates the associated handle .
\r
224 * @param huart: uart handle
\r
225 * @retval HAL status
\r
227 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)
\r
229 /* Check the UART handle allocation */
\r
235 if(huart->Init.HwFlowCtl != UART_HWCONTROL_NONE)
\r
237 /* Check the parameters */
\r
238 assert_param(IS_UART_HWFLOW_INSTANCE(huart->Instance));
\r
242 /* Check the parameters */
\r
243 assert_param(IS_UART_INSTANCE(huart->Instance));
\r
246 if(huart->State == HAL_UART_STATE_RESET)
\r
248 /* Allocate lock resource and initialize it */
\r
249 huart->Lock = HAL_UNLOCKED;
\r
251 /* Init the low level hardware : GPIO, CLOCK */
\r
252 HAL_UART_MspInit(huart);
\r
255 huart->State = HAL_UART_STATE_BUSY;
\r
257 /* Disable the Peripheral */
\r
258 __HAL_UART_DISABLE(huart);
\r
260 /* Set the UART Communication parameters */
\r
261 if (UART_SetConfig(huart) == HAL_ERROR)
\r
266 if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
\r
268 UART_AdvFeatureConfig(huart);
\r
271 /* In asynchronous mode, the following bits must be kept cleared:
\r
272 - LINEN and CLKEN bits in the USART_CR2 register,
\r
273 - SCEN, HDSEL and IREN bits in the USART_CR3 register.*/
\r
274 huart->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN);
\r
275 huart->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN);
\r
277 /* Enable the Peripheral */
\r
278 __HAL_UART_ENABLE(huart);
\r
280 /* TEACK and/or REACK to check before moving huart->State to Ready */
\r
281 return (UART_CheckIdleState(huart));
\r
285 * @brief Initializes the half-duplex mode according to the specified
\r
286 * parameters in the UART_InitTypeDef and creates the associated handle .
\r
287 * @param huart: UART handle
\r
288 * @retval HAL status
\r
290 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart)
\r
292 /* Check the UART handle allocation */
\r
298 if(huart->State == HAL_UART_STATE_RESET)
\r
300 /* Init the low level hardware : GPIO, CLOCK */
\r
301 HAL_UART_MspInit(huart);
\r
304 huart->State = HAL_UART_STATE_BUSY;
\r
306 /* Disable the Peripheral */
\r
307 __HAL_UART_DISABLE(huart);
\r
309 /* Set the UART Communication parameters */
\r
310 if (UART_SetConfig(huart) == HAL_ERROR)
\r
315 if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
\r
317 UART_AdvFeatureConfig(huart);
\r
320 /* In half-duplex mode, the following bits must be kept cleared:
\r
321 - LINEN and CLKEN bits in the USART_CR2 register,
\r
322 - SCEN and IREN bits in the USART_CR3 register.*/
\r
323 huart->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN);
\r
324 huart->Instance->CR3 &= ~(USART_CR3_IREN | USART_CR3_SCEN);
\r
326 /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
\r
327 huart->Instance->CR3 |= USART_CR3_HDSEL;
\r
329 /* Enable the Peripheral */
\r
330 __HAL_UART_ENABLE(huart);
\r
332 /* TEACK and/or REACK to check before moving huart->State to Ready */
\r
333 return (UART_CheckIdleState(huart));
\r
338 * @brief Initializes the LIN mode according to the specified
\r
339 * parameters in the UART_InitTypeDef and creates the associated handle .
\r
340 * @param huart: uart handle
\r
341 * @param BreakDetectLength: specifies the LIN break detection length.
\r
342 * This parameter can be one of the following values:
\r
343 * @arg UART_LINBREAKDETECTLENGTH_10B: 10-bit break detection
\r
344 * @arg UART_LINBREAKDETECTLENGTH_11B: 11-bit break detection
\r
345 * @retval HAL status
\r
347 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength)
\r
349 /* Check the UART handle allocation */
\r
355 /* Check the parameters */
\r
356 assert_param(IS_UART_INSTANCE(huart->Instance));
\r
357 assert_param(IS_UART_LIN_BREAK_DETECT_LENGTH(BreakDetectLength));
\r
358 assert_param(IS_LIN_WORD_LENGTH(huart->Init.WordLength));
\r
360 if(huart->State == HAL_UART_STATE_RESET)
\r
362 /* Init the low level hardware : GPIO, CLOCK */
\r
363 HAL_UART_MspInit(huart);
\r
366 huart->State = HAL_UART_STATE_BUSY;
\r
368 /* Disable the Peripheral */
\r
369 __HAL_UART_DISABLE(huart);
\r
371 /* Set the UART Communication parameters */
\r
372 if (UART_SetConfig(huart) == HAL_ERROR)
\r
377 if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
\r
379 UART_AdvFeatureConfig(huart);
\r
382 /* In LIN mode, the following bits must be kept cleared:
\r
383 - LINEN and CLKEN bits in the USART_CR2 register,
\r
384 - SCEN and IREN bits in the USART_CR3 register.*/
\r
385 huart->Instance->CR2 &= ~(USART_CR2_CLKEN);
\r
386 huart->Instance->CR3 &= ~(USART_CR3_HDSEL | USART_CR3_IREN | USART_CR3_SCEN);
\r
388 /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
\r
389 huart->Instance->CR2 |= USART_CR2_LINEN;
\r
391 /* Set the USART LIN Break detection length. */
\r
392 MODIFY_REG(huart->Instance->CR2, USART_CR2_LBDL, BreakDetectLength);
\r
394 /* Enable the Peripheral */
\r
395 __HAL_UART_ENABLE(huart);
\r
397 /* TEACK and/or REACK to check before moving huart->State to Ready */
\r
398 return (UART_CheckIdleState(huart));
\r
404 * @brief Initializes the multiprocessor mode according to the specified
\r
405 * parameters in the UART_InitTypeDef and creates the associated handle.
\r
406 * @param huart: UART handle
\r
407 * @param Address: UART node address (4-, 6-, 7- or 8-bit long)
\r
408 * @param WakeUpMethod: specifies the UART wakeup method.
\r
409 * This parameter can be one of the following values:
\r
410 * @arg UART_WAKEUPMETHOD_IDLELINE: WakeUp by an idle line detection
\r
411 * @arg UART_WAKEUPMETHOD_ADDRESSMARK: WakeUp by an address mark
\r
412 * @note If the user resorts to idle line detection wake up, the Address parameter
\r
413 * is useless and ignored by the initialization function.
\r
414 * @note If the user resorts to address mark wake up, the address length detection
\r
415 * is configured by default to 4 bits only. For the UART to be able to
\r
416 * manage 6-, 7- or 8-bit long addresses detection
\r
417 * @retval HAL status
\r
419 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod)
\r
421 /* Check the UART handle allocation */
\r
427 /* Check the wake up method parameter */
\r
428 assert_param(IS_UART_WAKEUPMETHOD(WakeUpMethod));
\r
430 if(huart->State == HAL_UART_STATE_RESET)
\r
432 /* Init the low level hardware : GPIO, CLOCK */
\r
433 HAL_UART_MspInit(huart);
\r
436 huart->State = HAL_UART_STATE_BUSY;
\r
438 /* Disable the Peripheral */
\r
439 __HAL_UART_DISABLE(huart);
\r
441 /* Set the UART Communication parameters */
\r
442 if (UART_SetConfig(huart) == HAL_ERROR)
\r
447 if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
\r
449 UART_AdvFeatureConfig(huart);
\r
452 /* In multiprocessor mode, the following bits must be kept cleared:
\r
453 - LINEN and CLKEN bits in the USART_CR2 register,
\r
454 - SCEN, HDSEL and IREN bits in the USART_CR3 register. */
\r
455 huart->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN);
\r
456 huart->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN);
\r
458 if (WakeUpMethod == UART_WAKEUPMETHOD_ADDRESSMARK)
\r
460 /* If address mark wake up method is chosen, set the USART address node */
\r
461 MODIFY_REG(huart->Instance->CR2, USART_CR2_ADD, ((uint32_t)Address << UART_CR2_ADDRESS_LSB_POS));
\r
464 /* Set the wake up method by setting the WAKE bit in the CR1 register */
\r
465 MODIFY_REG(huart->Instance->CR1, USART_CR1_WAKE, WakeUpMethod);
\r
467 /* Enable the Peripheral */
\r
468 __HAL_UART_ENABLE(huart);
\r
470 /* TEACK and/or REACK to check before moving huart->State to Ready */
\r
471 return (UART_CheckIdleState(huart));
\r
478 * @brief DeInitializes the UART peripheral
\r
479 * @param huart: uart handle
\r
480 * @retval HAL status
\r
482 HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart)
\r
484 /* Check the UART handle allocation */
\r
490 /* Check the parameters */
\r
491 assert_param(IS_UART_INSTANCE(huart->Instance));
\r
493 huart->State = HAL_UART_STATE_BUSY;
\r
495 /* Disable the Peripheral */
\r
496 __HAL_UART_DISABLE(huart);
\r
498 huart->Instance->CR1 = 0x0;
\r
499 huart->Instance->CR2 = 0x0;
\r
500 huart->Instance->CR3 = 0x0;
\r
502 /* DeInit the low level hardware */
\r
503 HAL_UART_MspDeInit(huart);
\r
505 huart->ErrorCode = HAL_UART_ERROR_NONE;
\r
506 huart->State = HAL_UART_STATE_RESET;
\r
508 /* Process Unlock */
\r
509 __HAL_UNLOCK(huart);
\r
515 * @brief UART MSP Init
\r
516 * @param huart: uart handle
\r
519 __weak void HAL_UART_MspInit(UART_HandleTypeDef *huart)
\r
521 /* NOTE : This function should not be modified, when the callback is needed,
\r
522 the HAL_UART_MspInit can be implemented in the user file
\r
527 * @brief UART MSP DeInit
\r
528 * @param huart: uart handle
\r
531 __weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
\r
533 /* NOTE : This function should not be modified, when the callback is needed,
\r
534 the HAL_UART_MspDeInit can be implemented in the user file
\r
542 /** @defgroup HAL_UART_Group2 IO operation functions
\r
543 * @brief UART Transmit/Receive functions
\r
546 ===============================================================================
\r
547 ##### I/O operation functions #####
\r
548 ===============================================================================
\r
549 This subsection provides a set of functions allowing to manage the UART asynchronous
\r
550 and Half duplex data transfers.
\r
552 (#) There are two mode of transfer:
\r
553 (+) Blocking mode: The communication is performed in polling mode.
\r
554 The HAL status of all data processing is returned by the same function
\r
555 after finishing transfer.
\r
556 (+) No-Blocking mode: The communication is performed using Interrupts
\r
557 or DMA, These API's return the HAL status.
\r
558 The end of the data processing will be indicated through the
\r
559 dedicated UART IRQ when using Interrupt mode or the DMA IRQ when
\r
561 The HAL_UART_TxCpltCallback(), HAL_UART_RxCpltCallback() user callbacks
\r
562 will be executed respectively at the end of the transmit or Receive process
\r
563 The HAL_UART_ErrorCallback()user callback will be executed when a communication error is detected
\r
565 (#) Blocking mode API's are :
\r
566 (+) HAL_UART_Transmit()
\r
567 (+) HAL_UART_Receive()
\r
569 (#) Non-Blocking mode API's with Interrupt are :
\r
570 (+) HAL_UART_Transmit_IT()
\r
571 (+) HAL_UART_Receive_IT()
\r
572 (+) HAL_UART_IRQHandler()
\r
573 (+) UART_Transmit_IT()
\r
574 (+) UART_Receive_IT()
\r
576 (#) No-Blocking mode API's with DMA are :
\r
577 (+) HAL_UART_Transmit_DMA()
\r
578 (+) HAL_UART_Receive_DMA()
\r
579 (+) HAL_UART_DMAPause()
\r
580 (+) HAL_UART_DMAResume()
\r
581 (+) HAL_UART_DMAStop()
\r
583 (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
\r
584 (+) HAL_UART_TxHalfCpltCallback()
\r
585 (+) HAL_UART_TxCpltCallback()
\r
586 (+) HAL_UART_RxHalfCpltCallback()
\r
587 (+) HAL_UART_RxCpltCallback()
\r
588 (+) HAL_UART_ErrorCallback()
\r
591 -@- In the Half duplex communication, it is forbidden to run the transmit
\r
592 and receive process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX can't be useful.
\r
599 * @brief Send an amount of data in blocking mode
\r
600 * @param huart: uart handle
\r
601 * @param pData: pointer to data buffer
\r
602 * @param Size: amount of data to be sent
\r
603 * @param Timeout : Timeout duration
\r
604 * @retval HAL status
\r
606 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
\r
610 if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_RX))
\r
612 if((pData == NULL ) || (Size == 0))
\r
617 /* Process Locked */
\r
620 huart->ErrorCode = HAL_UART_ERROR_NONE;
\r
621 /* Check if a non-blocking receive process is ongoing or not */
\r
622 if(huart->State == HAL_UART_STATE_BUSY_RX)
\r
624 huart->State = HAL_UART_STATE_BUSY_TX_RX;
\r
628 huart->State = HAL_UART_STATE_BUSY_TX;
\r
631 huart->TxXferSize = Size;
\r
632 huart->TxXferCount = Size;
\r
633 while(huart->TxXferCount > 0)
\r
635 huart->TxXferCount--;
\r
636 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, Timeout) != HAL_OK)
\r
638 return HAL_TIMEOUT;
\r
640 if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
\r
642 tmp = (uint16_t*) pData;
\r
643 huart->Instance->TDR = (*tmp & (uint16_t)0x01FF);
\r
648 huart->Instance->TDR = (*pData++ & (uint8_t)0xFF);
\r
651 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, Timeout) != HAL_OK)
\r
653 return HAL_TIMEOUT;
\r
655 /* Check if a non-blocking receive Process is ongoing or not */
\r
656 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
\r
658 huart->State = HAL_UART_STATE_BUSY_RX;
\r
662 huart->State = HAL_UART_STATE_READY;
\r
665 /* Process Unlocked */
\r
666 __HAL_UNLOCK(huart);
\r
677 * @brief Receive an amount of data in blocking mode
\r
678 * @param huart: uart handle
\r
679 * @param pData: pointer to data buffer
\r
680 * @param Size: amount of data to be received
\r
681 * @param Timeout : Timeout duration
\r
682 * @retval HAL status
\r
684 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
\r
689 if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_TX))
\r
691 if((pData == NULL ) || (Size == 0))
\r
696 /* Process Locked */
\r
699 huart->ErrorCode = HAL_UART_ERROR_NONE;
\r
700 /* Check if a non-blocking transmit process is ongoing or not */
\r
701 if(huart->State == HAL_UART_STATE_BUSY_TX)
\r
703 huart->State = HAL_UART_STATE_BUSY_TX_RX;
\r
707 huart->State = HAL_UART_STATE_BUSY_RX;
\r
710 huart->RxXferSize = Size;
\r
711 huart->RxXferCount = Size;
\r
713 /* Computation of UART mask to apply to RDR register */
\r
714 UART_MASK_COMPUTATION(huart);
\r
715 uhMask = huart->Mask;
\r
717 /* as long as data have to be received */
\r
718 while(huart->RxXferCount > 0)
\r
720 huart->RxXferCount--;
\r
721 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, Timeout) != HAL_OK)
\r
723 return HAL_TIMEOUT;
\r
725 if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
\r
727 tmp = (uint16_t*) pData ;
\r
728 *tmp = (uint16_t)(huart->Instance->RDR & uhMask);
\r
733 *pData++ = (uint8_t)(huart->Instance->RDR & (uint8_t)uhMask);
\r
737 /* Check if a non-blocking transmit Process is ongoing or not */
\r
738 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
\r
740 huart->State = HAL_UART_STATE_BUSY_TX;
\r
744 huart->State = HAL_UART_STATE_READY;
\r
746 /* Process Unlocked */
\r
747 __HAL_UNLOCK(huart);
\r
758 * @brief Send an amount of data in interrupt mode
\r
759 * @param huart: uart handle
\r
760 * @param pData: pointer to data buffer
\r
761 * @param Size: amount of data to be sent
\r
762 * @retval HAL status
\r
764 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
\r
766 if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_RX))
\r
768 if((pData == NULL ) || (Size == 0))
\r
773 /* Process Locked */
\r
776 huart->pTxBuffPtr = pData;
\r
777 huart->TxXferSize = Size;
\r
778 huart->TxXferCount = Size;
\r
780 huart->ErrorCode = HAL_UART_ERROR_NONE;
\r
781 /* Check if a receive process is ongoing or not */
\r
782 if(huart->State == HAL_UART_STATE_BUSY_RX)
\r
784 huart->State = HAL_UART_STATE_BUSY_TX_RX;
\r
788 huart->State = HAL_UART_STATE_BUSY_TX;
\r
791 /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
\r
792 __HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
\r
794 /* Process Unlocked */
\r
795 __HAL_UNLOCK(huart);
\r
797 /* Enable the UART Transmit Data Register Empty Interrupt */
\r
798 __HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
\r
809 * @brief Receive an amount of data in interrupt mode
\r
810 * @param huart: uart handle
\r
811 * @param pData: pointer to data buffer
\r
812 * @param Size: amount of data to be received
\r
813 * @retval HAL status
\r
815 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
\r
817 if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_TX))
\r
819 if((pData == NULL ) || (Size == 0))
\r
824 /* Process Locked */
\r
827 huart->pRxBuffPtr = pData;
\r
828 huart->RxXferSize = Size;
\r
829 huart->RxXferCount = Size;
\r
831 /* Computation of UART mask to apply to RDR register */
\r
832 UART_MASK_COMPUTATION(huart);
\r
834 huart->ErrorCode = HAL_UART_ERROR_NONE;
\r
835 /* Check if a transmit process is ongoing or not */
\r
836 if(huart->State == HAL_UART_STATE_BUSY_TX)
\r
838 huart->State = HAL_UART_STATE_BUSY_TX_RX;
\r
842 huart->State = HAL_UART_STATE_BUSY_RX;
\r
845 /* Enable the UART Parity Error Interrupt */
\r
846 __HAL_UART_ENABLE_IT(huart, UART_IT_PE);
\r
848 /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
\r
849 __HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
\r
851 /* Process Unlocked */
\r
852 __HAL_UNLOCK(huart);
\r
854 /* Enable the UART Data Register not empty Interrupt */
\r
855 __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
\r
866 * @brief Send an amount of data in DMA mode
\r
867 * @param huart: uart handle
\r
868 * @param pData: pointer to data buffer
\r
869 * @param Size: amount of data to be sent
\r
870 * @retval HAL status
\r
872 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
\r
876 if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_RX))
\r
878 if((pData == NULL ) || (Size == 0))
\r
883 /* Process Locked */
\r
886 huart->pTxBuffPtr = pData;
\r
887 huart->TxXferSize = Size;
\r
888 huart->TxXferCount = Size;
\r
890 huart->ErrorCode = HAL_UART_ERROR_NONE;
\r
891 /* Check if a receive process is ongoing or not */
\r
892 if(huart->State == HAL_UART_STATE_BUSY_RX)
\r
894 huart->State = HAL_UART_STATE_BUSY_TX_RX;
\r
898 huart->State = HAL_UART_STATE_BUSY_TX;
\r
901 /* Set the UART DMA transfer complete callback */
\r
902 huart->hdmatx->XferCpltCallback = UART_DMATransmitCplt;
\r
904 /* Set the UART DMA Half transfer complete callback */
\r
905 huart->hdmatx->XferHalfCpltCallback = UART_DMATxHalfCplt;
\r
907 /* Set the DMA error callback */
\r
908 huart->hdmatx->XferErrorCallback = UART_DMAError;
\r
910 /* Enable the UART transmit DMA channel */
\r
911 tmp = (uint32_t*)&pData;
\r
912 HAL_DMA_Start_IT(huart->hdmatx, *(uint32_t*)tmp, (uint32_t)&huart->Instance->TDR, Size);
\r
914 /* Clear the TC flag in the SR register by writing 0 to it */
\r
915 __HAL_UART_CLEAR_IT(huart, UART_FLAG_TC);
\r
918 /* Enable the DMA transfer for transmit request by setting the DMAT bit
\r
919 in the UART CR3 register */
\r
920 huart->Instance->CR3 |= USART_CR3_DMAT;
\r
922 /* Process Unlocked */
\r
923 __HAL_UNLOCK(huart);
\r
934 * @brief Receive an amount of data in DMA mode
\r
935 * @param huart: uart handle
\r
936 * @param pData: pointer to data buffer
\r
937 * @param Size: amount of data to be received
\r
938 * @note When the UART parity is enabled (PCE = 1), the received data contain
\r
939 * the parity bit (MSB position)
\r
940 * @retval HAL status
\r
942 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
\r
946 if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_TX))
\r
948 if((pData == NULL ) || (Size == 0))
\r
953 /* Process Locked */
\r
956 huart->pRxBuffPtr = pData;
\r
957 huart->RxXferSize = Size;
\r
959 huart->ErrorCode = HAL_UART_ERROR_NONE;
\r
960 /* Check if a transmit process is ongoing or not */
\r
961 if(huart->State == HAL_UART_STATE_BUSY_TX)
\r
963 huart->State = HAL_UART_STATE_BUSY_TX_RX;
\r
967 huart->State = HAL_UART_STATE_BUSY_RX;
\r
970 /* Set the UART DMA transfer complete callback */
\r
971 huart->hdmarx->XferCpltCallback = UART_DMAReceiveCplt;
\r
973 /* Set the UART DMA Half transfer complete callback */
\r
974 huart->hdmarx->XferHalfCpltCallback = UART_DMARxHalfCplt;
\r
976 /* Set the DMA error callback */
\r
977 huart->hdmarx->XferErrorCallback = UART_DMAError;
\r
979 /* Enable the DMA channel */
\r
980 tmp = (uint32_t*)&pData;
\r
981 HAL_DMA_Start_IT(huart->hdmarx, (uint32_t)&huart->Instance->RDR, *(uint32_t*)tmp, Size);
\r
983 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
\r
984 in the UART CR3 register */
\r
985 huart->Instance->CR3 |= USART_CR3_DMAR;
\r
987 /* Process Unlocked */
\r
988 __HAL_UNLOCK(huart);
\r
999 * @brief Pauses the DMA Transfer.
\r
1000 * @param huart: UART handle
\r
1003 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart)
\r
1005 /* Process Locked */
\r
1006 __HAL_LOCK(huart);
\r
1008 if(huart->State == HAL_UART_STATE_BUSY_TX)
\r
1010 /* Disable the UART DMA Tx request */
\r
1011 huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
\r
1013 else if(huart->State == HAL_UART_STATE_BUSY_RX)
\r
1015 /* Disable the UART DMA Rx request */
\r
1016 huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
\r
1018 else if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
\r
1020 /* Disable the UART DMA Tx request */
\r
1021 huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
\r
1022 /* Disable the UART DMA Rx request */
\r
1023 huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
\r
1026 /* Process Unlocked */
\r
1027 __HAL_UNLOCK(huart);
\r
1033 * @brief Resumes the DMA Transfer.
\r
1034 * @param huart: UART handle
\r
1037 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart)
\r
1039 /* Process Locked */
\r
1040 __HAL_LOCK(huart);
\r
1042 if(huart->State == HAL_UART_STATE_BUSY_TX)
\r
1044 /* Enable the UART DMA Tx request */
\r
1045 huart->Instance->CR3 |= USART_CR3_DMAT;
\r
1047 else if(huart->State == HAL_UART_STATE_BUSY_RX)
\r
1049 /* Enable the UART DMA Rx request */
\r
1050 huart->Instance->CR3 |= USART_CR3_DMAR;
\r
1052 else if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
\r
1054 /* Enable the UART DMA Rx request before the DMA Tx request */
\r
1055 huart->Instance->CR3 |= USART_CR3_DMAR;
\r
1056 /* Enable the UART DMA Tx request */
\r
1057 huart->Instance->CR3 |= USART_CR3_DMAT;
\r
1060 /* If the UART peripheral is still not enabled, enable it */
\r
1061 if ((huart->Instance->CR1 & USART_CR1_UE) == 0)
\r
1063 /* Enable UART peripheral */
\r
1064 __HAL_UART_ENABLE(huart);
\r
1067 /* TEACK and/or REACK to check before moving huart->State to Ready */
\r
1068 return (UART_CheckIdleState(huart));
\r
1072 * @brief Stops the DMA Transfer.
\r
1073 * @param huart: UART handle
\r
1076 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart)
\r
1078 /* Process Locked */
\r
1079 __HAL_LOCK(huart);
\r
1081 /* Disable the UART Tx/Rx DMA requests */
\r
1082 huart->Instance->CR3 &= ~USART_CR3_DMAT;
\r
1083 huart->Instance->CR3 &= ~USART_CR3_DMAR;
\r
1085 /* Abort the UART DMA tx channel */
\r
1086 if(huart->hdmatx != NULL)
\r
1088 HAL_DMA_Abort(huart->hdmatx);
\r
1090 /* Abort the UART DMA rx channel */
\r
1091 if(huart->hdmarx != NULL)
\r
1093 HAL_DMA_Abort(huart->hdmarx);
\r
1096 /* Disable UART peripheral */
\r
1097 __HAL_UART_DISABLE(huart);
\r
1099 huart->State = HAL_UART_STATE_READY;
\r
1101 /* Process Unlocked */
\r
1102 __HAL_UNLOCK(huart);
\r
1108 * @brief This function handles UART interrupt request.
\r
1109 * @param huart: uart handle
\r
1112 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
\r
1114 /* UART parity error interrupt occurred -------------------------------------*/
\r
1115 if((__HAL_UART_GET_IT(huart, UART_IT_PE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_PE) != RESET))
\r
1117 __HAL_UART_CLEAR_PEFLAG(huart);
\r
1119 huart->ErrorCode |= HAL_UART_ERROR_PE;
\r
1120 /* Set the UART state ready to be able to start again the process */
\r
1121 huart->State = HAL_UART_STATE_READY;
\r
1124 /* UART frame error interrupt occurred --------------------------------------*/
\r
1125 if((__HAL_UART_GET_IT(huart, UART_IT_FE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR) != RESET))
\r
1127 __HAL_UART_CLEAR_FEFLAG(huart);
\r
1129 huart->ErrorCode |= HAL_UART_ERROR_FE;
\r
1130 /* Set the UART state ready to be able to start again the process */
\r
1131 huart->State = HAL_UART_STATE_READY;
\r
1134 /* UART noise error interrupt occurred --------------------------------------*/
\r
1135 if((__HAL_UART_GET_IT(huart, UART_IT_NE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR) != RESET))
\r
1137 __HAL_UART_CLEAR_NEFLAG(huart);
\r
1139 huart->ErrorCode |= HAL_UART_ERROR_NE;
\r
1140 /* Set the UART state ready to be able to start again the process */
\r
1141 huart->State = HAL_UART_STATE_READY;
\r
1144 /* UART Over-Run interrupt occurred -----------------------------------------*/
\r
1145 if((__HAL_UART_GET_IT(huart, UART_IT_ORE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR) != RESET))
\r
1147 __HAL_UART_CLEAR_OREFLAG(huart);
\r
1149 huart->ErrorCode |= HAL_UART_ERROR_ORE;
\r
1150 /* Set the UART state ready to be able to start again the process */
\r
1151 huart->State = HAL_UART_STATE_READY;
\r
1154 /* Call UART Error Call back function if need be --------------------------*/
\r
1155 if(huart->ErrorCode != HAL_UART_ERROR_NONE)
\r
1157 HAL_UART_ErrorCallback(huart);
\r
1160 /* UART in mode Receiver ---------------------------------------------------*/
\r
1161 if((__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE) != RESET))
\r
1163 UART_Receive_IT(huart);
\r
1164 /* Clear RXNE interrupt flag */
\r
1165 __HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST);
\r
1169 /* UART in mode Transmitter ------------------------------------------------*/
\r
1170 if((__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) &&(__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET))
\r
1172 UART_Transmit_IT(huart);
\r
1179 * @brief This function handles UART Communication Timeout.
\r
1180 * @param huart: UART handle
\r
1181 * @param Flag: specifies the UART flag to check.
\r
1182 * @param Status: The new Flag status (SET or RESET).
\r
1183 * @param Timeout: Timeout duration
\r
1184 * @retval HAL status
\r
1186 HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
\r
1188 uint32_t tickstart = HAL_GetTick();
\r
1190 /* Wait until flag is set */
\r
1191 if(Status == RESET)
\r
1193 while(__HAL_UART_GET_FLAG(huart, Flag) == RESET)
\r
1195 /* Check for the Timeout */
\r
1196 if(Timeout != HAL_MAX_DELAY)
\r
1198 if((Timeout == 0)||((HAL_GetTick()-tickstart) >= Timeout))
\r
1200 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
\r
1201 __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
\r
1202 __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
\r
1203 __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
\r
1204 __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
\r
1206 huart->State= HAL_UART_STATE_TIMEOUT;
\r
1208 /* Process Unlocked */
\r
1209 __HAL_UNLOCK(huart);
\r
1211 return HAL_TIMEOUT;
\r
1218 while(__HAL_UART_GET_FLAG(huart, Flag) != RESET)
\r
1220 /* Check for the Timeout */
\r
1221 if(Timeout != HAL_MAX_DELAY)
\r
1223 if((Timeout == 0)||((HAL_GetTick()-tickstart) >= Timeout))
\r
1225 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
\r
1226 __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
\r
1227 __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
\r
1228 __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
\r
1229 __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
\r
1231 huart->State= HAL_UART_STATE_TIMEOUT;
\r
1233 /* Process Unlocked */
\r
1234 __HAL_UNLOCK(huart);
\r
1236 return HAL_TIMEOUT;
\r
1247 * @brief DMA UART transmit process complete callback
\r
1248 * @param hdma: DMA handle
\r
1251 static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
\r
1253 UART_HandleTypeDef* huart = ( UART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1254 huart->TxXferCount = 0;
\r
1256 /* Disable the DMA transfer for transmit request by setting the DMAT bit
\r
1257 in the UART CR3 register */
\r
1258 huart->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DMAT);
\r
1260 /* Wait for UART TC Flag */
\r
1261 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, HAL_UART_TXDMA_TIMEOUTVALUE) != HAL_OK)
\r
1263 /* Timeout Occured */
\r
1264 huart->State = HAL_UART_STATE_TIMEOUT;
\r
1265 HAL_UART_ErrorCallback(huart);
\r
1270 /* Check if a receive process is ongoing or not */
\r
1271 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
\r
1273 huart->State = HAL_UART_STATE_BUSY_RX;
\r
1277 huart->State = HAL_UART_STATE_READY;
\r
1279 HAL_UART_TxCpltCallback(huart);
\r
1284 * @brief DMA UART transmit process half complete callback
\r
1285 * @param hdma : DMA handle
\r
1288 static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
\r
1290 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
\r
1292 HAL_UART_TxHalfCpltCallback(huart);
\r
1296 * @brief DMA UART receive process complete callback
\r
1297 * @param hdma: DMA handle
\r
1300 static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
\r
1302 UART_HandleTypeDef* huart = ( UART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1303 huart->RxXferCount = 0;
\r
1305 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
\r
1306 in the UART CR3 register */
\r
1307 huart->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DMAR);
\r
1309 /* Check if a transmit Process is ongoing or not */
\r
1310 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
\r
1312 huart->State = HAL_UART_STATE_BUSY_TX;
\r
1316 huart->State = HAL_UART_STATE_READY;
\r
1318 HAL_UART_RxCpltCallback(huart);
\r
1322 * @brief DMA UART receive process half complete callback
\r
1323 * @param hdma : DMA handle
\r
1326 static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
\r
1328 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
\r
1330 HAL_UART_RxHalfCpltCallback(huart);
\r
1334 * @brief DMA UART communication error callback
\r
1335 * @param hdma: DMA handle
\r
1338 static void UART_DMAError(DMA_HandleTypeDef *hdma)
\r
1340 UART_HandleTypeDef* huart = ( UART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
\r
1341 huart->RxXferCount = 0;
\r
1342 huart->TxXferCount = 0;
\r
1343 huart->State= HAL_UART_STATE_READY;
\r
1344 huart->ErrorCode |= HAL_UART_ERROR_DMA;
\r
1345 HAL_UART_ErrorCallback(huart);
\r
1349 * @brief Tx Transfer completed callbacks
\r
1350 * @param huart: uart handle
\r
1353 __weak void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
\r
1355 /* NOTE : This function should not be modified, when the callback is needed,
\r
1356 the HAL_UART_TxCpltCallback can be implemented in the user file
\r
1361 * @brief Tx Half Transfer completed callbacks.
\r
1362 * @param huart: UART handle
\r
1365 __weak void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart)
\r
1367 /* NOTE: This function should not be modified, when the callback is needed,
\r
1368 the HAL_UART_TxHalfCpltCallback can be implemented in the user file
\r
1373 * @brief Rx Transfer completed callbacks
\r
1374 * @param huart: uart handle
\r
1377 __weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
\r
1379 /* NOTE : This function should not be modified, when the callback is needed,
\r
1380 the HAL_UART_RxCpltCallback can be implemented in the user file
\r
1385 * @brief Rx Half Transfer completed callbacks.
\r
1386 * @param huart: UART handle
\r
1389 __weak void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
\r
1391 /* NOTE: This function should not be modified, when the callback is needed,
\r
1392 the HAL_UART_RxHalfCpltCallback can be implemented in the user file
\r
1397 * @brief UART error callbacks
\r
1398 * @param huart: uart handle
\r
1401 __weak void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
\r
1403 /* NOTE : This function should not be modified, when the callback is needed,
\r
1404 the HAL_UART_ErrorCallback can be implemented in the user file
\r
1409 * @brief Send an amount of data in interrupt mode
\r
1410 * Function called under interruption only, once
\r
1411 * interruptions have been enabled by HAL_UART_Transmit_IT()
\r
1412 * @param huart: UART handle
\r
1413 * @retval HAL status
\r
1415 static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart)
\r
1419 if ((huart->State == HAL_UART_STATE_BUSY_TX) || (huart->State == HAL_UART_STATE_BUSY_TX_RX))
\r
1422 if(huart->TxXferCount == 0)
\r
1424 /* Disable the UART Transmit Data Register Empty Interrupt */
\r
1425 __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
\r
1427 /* Check if a receive Process is ongoing or not */
\r
1428 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
\r
1430 huart->State = HAL_UART_STATE_BUSY_RX;
\r
1434 /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
\r
1435 __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
\r
1437 huart->State = HAL_UART_STATE_READY;
\r
1440 /* Wait on TC flag to be able to start a second transfer */
\r
1441 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, HAL_UART_TIMEOUT_VALUE) != HAL_OK)
\r
1443 return HAL_TIMEOUT;
\r
1446 HAL_UART_TxCpltCallback(huart);
\r
1452 if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
\r
1454 tmp = (uint16_t*) huart->pTxBuffPtr;
\r
1455 huart->Instance->TDR = (*tmp & (uint16_t)0x01FF);
\r
1456 huart->pTxBuffPtr += 2;
\r
1460 huart->Instance->TDR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0xFF);
\r
1463 huart->TxXferCount--;
\r
1475 * @brief Receive an amount of data in interrupt mode
\r
1476 * Function called under interruption only, once
\r
1477 * interruptions have been enabled by HAL_UART_Receive_IT()
\r
1478 * @param huart: UART handle
\r
1479 * @retval HAL status
\r
1481 static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
\r
1484 uint16_t uhMask = huart->Mask;
\r
1486 if((huart->State == HAL_UART_STATE_BUSY_RX) || (huart->State == HAL_UART_STATE_BUSY_TX_RX))
\r
1489 if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
\r
1491 tmp = (uint16_t*) huart->pRxBuffPtr ;
\r
1492 *tmp = (uint16_t)(huart->Instance->RDR & uhMask);
\r
1493 huart->pRxBuffPtr +=2;
\r
1497 *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->RDR & (uint8_t)uhMask);
\r
1500 if(--huart->RxXferCount == 0)
\r
1502 __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
\r
1504 /* Check if a transmit Process is ongoing or not */
\r
1505 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
\r
1507 huart->State = HAL_UART_STATE_BUSY_TX;
\r
1511 /* Disable the UART Parity Error Interrupt */
\r
1512 __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
\r
1514 /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
\r
1515 __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
\r
1517 huart->State = HAL_UART_STATE_READY;
\r
1520 HAL_UART_RxCpltCallback(huart);
\r
1537 /** @defgroup HAL_UART_Group3 Peripheral Control functions
\r
1538 * @brief UART control functions
\r
1541 ===============================================================================
\r
1542 ##### Peripheral Control functions #####
\r
1543 ===============================================================================
\r
1545 This subsection provides a set of functions allowing to control the UART.
\r
1546 (+) HAL_UART_GetState() API is helpful to check in run-time the state of the UART peripheral.
\r
1547 (+) HAL_MultiProcessor_EnableMuteMode() API enables mute mode
\r
1548 (+) HAL_MultiProcessor_DisableMuteMode() API disables mute mode
\r
1549 (+) HAL_MultiProcessor_EnterMuteMode() API enters mute mode
\r
1550 (+) HAL_MultiProcessor_EnableMuteMode() API enables mute mode
\r
1551 (+) UART_SetConfig() API configures the UART peripheral
\r
1552 (+) UART_AdvFeatureConfig() API optionally configures the UART advanced features
\r
1553 (+) UART_CheckIdleState() API ensures that TEACK and/or REACK are set after initialization
\r
1554 (+) HAL_HalfDuplex_EnableTransmitter() API disables receiver and enables transmitter
\r
1555 (+) HAL_HalfDuplex_EnableReceiver() API disables transmitter and enables receiver
\r
1556 (+) HAL_LIN_SendBreak() API transmits the break characters
\r
1562 * @brief Enable UART in mute mode (doesn't mean UART enters mute mode;
\r
1563 * to enter mute mode, HAL_MultiProcessor_EnterMuteMode() API must be called)
\r
1564 * @param huart: UART handle
\r
1565 * @retval HAL status
\r
1567 HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart)
\r
1569 /* Process Locked */
\r
1570 __HAL_LOCK(huart);
\r
1572 huart->State = HAL_UART_STATE_BUSY;
\r
1574 /* Enable USART mute mode by setting the MME bit in the CR1 register */
\r
1575 huart->Instance->CR1 |= USART_CR1_MME;
\r
1577 huart->State = HAL_UART_STATE_READY;
\r
1579 return (UART_CheckIdleState(huart));
\r
1583 * @brief Disable UART mute mode (doesn't mean it actually wakes up the software,
\r
1584 * as it may not have been in mute mode at this very moment).
\r
1585 * @param huart: uart handle
\r
1586 * @retval HAL status
\r
1588 HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart)
\r
1590 /* Process Locked */
\r
1591 __HAL_LOCK(huart);
\r
1593 huart->State = HAL_UART_STATE_BUSY;
\r
1595 /* Disable USART mute mode by clearing the MME bit in the CR1 register */
\r
1596 huart->Instance->CR1 &= ~(USART_CR1_MME);
\r
1598 huart->State = HAL_UART_STATE_READY;
\r
1600 return (UART_CheckIdleState(huart));
\r
1604 * @brief Enter UART mute mode (means UART actually enters mute mode).
\r
1605 * To exit from mute mode, HAL_MultiProcessor_DisableMuteMode() API must be called.
\r
1606 * @param huart: uart handle
\r
1607 * @retval HAL status
\r
1609 void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart)
\r
1611 __HAL_UART_SEND_REQ(huart, UART_MUTE_MODE_REQUEST);
\r
1617 * @brief return the UART state
\r
1618 * @param huart: uart handle
\r
1619 * @retval HAL state
\r
1621 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart)
\r
1623 return huart->State;
\r
1627 * @brief Return the UART error code
\r
1628 * @param huart : pointer to a UART_HandleTypeDef structure that contains
\r
1629 * the configuration information for the specified UART.
\r
1630 * @retval UART Error Code
\r
1632 uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart)
\r
1634 return huart->ErrorCode;
\r
1638 * @brief Configure the UART peripheral
\r
1639 * @param huart: uart handle
\r
1642 HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart)
\r
1644 uint32_t tmpreg = 0x00000000;
\r
1645 UART_ClockSourceTypeDef clocksource = UART_CLOCKSOURCE_UNDEFINED;
\r
1646 uint16_t brrtemp = 0x0000;
\r
1647 uint16_t usartdiv = 0x0000;
\r
1648 HAL_StatusTypeDef ret = HAL_OK;
\r
1650 /* Check the parameters */
\r
1651 assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate));
\r
1652 assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
\r
1653 assert_param(IS_UART_STOPBITS(huart->Init.StopBits));
\r
1654 assert_param(IS_UART_PARITY(huart->Init.Parity));
\r
1655 assert_param(IS_UART_MODE(huart->Init.Mode));
\r
1656 assert_param(IS_UART_HARDWARE_FLOW_CONTROL(huart->Init.HwFlowCtl));
\r
1657 assert_param(IS_UART_ONE_BIT_SAMPLE(huart->Init.OneBitSampling));
\r
1660 /*-------------------------- USART CR1 Configuration -----------------------*/
\r
1661 /* Clear M, PCE, PS, TE, RE and OVER8 bits and configure
\r
1662 * the UART Word Length, Parity, Mode and oversampling:
\r
1663 * set the M bits according to huart->Init.WordLength value
\r
1664 * set PCE and PS bits according to huart->Init.Parity value
\r
1665 * set TE and RE bits according to huart->Init.Mode value
\r
1666 * set OVER8 bit according to huart->Init.OverSampling value */
\r
1667 tmpreg = (uint32_t)huart->Init.WordLength | huart->Init.Parity | huart->Init.Mode | huart->Init.OverSampling ;
\r
1668 MODIFY_REG(huart->Instance->CR1, UART_CR1_FIELDS, tmpreg);
\r
1670 /*-------------------------- USART CR2 Configuration -----------------------*/
\r
1671 /* Configure the UART Stop Bits: Set STOP[13:12] bits according
\r
1672 * to huart->Init.StopBits value */
\r
1673 MODIFY_REG(huart->Instance->CR2, USART_CR2_STOP, huart->Init.StopBits);
\r
1675 /*-------------------------- USART CR3 Configuration -----------------------*/
\r
1677 * - UART HardWare Flow Control: set CTSE and RTSE bits according
\r
1678 * to huart->Init.HwFlowCtl value
\r
1679 * - one-bit sampling method versus three samples' majority rule according
\r
1680 * to huart->Init.OneBitSampling */
\r
1681 tmpreg = (uint32_t)huart->Init.HwFlowCtl | huart->Init.OneBitSampling ;
\r
1682 MODIFY_REG(huart->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE | USART_CR3_ONEBIT), tmpreg);
\r
1684 /*-------------------------- USART BRR Configuration -----------------------*/
\r
1685 UART_GETCLOCKSOURCE(huart, clocksource);
\r
1687 /* Check UART Over Sampling to set Baud Rate Register */
\r
1688 if (huart->Init.OverSampling == UART_OVERSAMPLING_8)
\r
1690 switch (clocksource)
\r
1692 case UART_CLOCKSOURCE_PCLK1:
\r
1693 usartdiv = (uint16_t)(UART_DIV_SAMPLING8(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate));
\r
1695 case UART_CLOCKSOURCE_PCLK2:
\r
1696 usartdiv = (uint16_t)(UART_DIV_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate));
\r
1698 case UART_CLOCKSOURCE_HSI:
\r
1699 usartdiv = (uint16_t)(UART_DIV_SAMPLING8(HSI_VALUE, huart->Init.BaudRate));
\r
1701 case UART_CLOCKSOURCE_SYSCLK:
\r
1702 usartdiv = (uint16_t)(UART_DIV_SAMPLING8(HAL_RCC_GetSysClockFreq(), huart->Init.BaudRate));
\r
1704 case UART_CLOCKSOURCE_LSE:
\r
1705 usartdiv = (uint16_t)(UART_DIV_SAMPLING8(LSE_VALUE, huart->Init.BaudRate));
\r
1707 case UART_CLOCKSOURCE_UNDEFINED:
\r
1713 brrtemp = usartdiv & 0xFFF0;
\r
1714 brrtemp |= (uint16_t)((usartdiv & (uint16_t)0x000F) >> 1U);
\r
1715 huart->Instance->BRR = brrtemp;
\r
1719 switch (clocksource)
\r
1721 case UART_CLOCKSOURCE_PCLK1:
\r
1722 huart->Instance->BRR = (uint16_t)(UART_DIV_SAMPLING16(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate));
\r
1724 case UART_CLOCKSOURCE_PCLK2:
\r
1725 huart->Instance->BRR = (uint16_t)(UART_DIV_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate));
\r
1727 case UART_CLOCKSOURCE_HSI:
\r
1728 huart->Instance->BRR = (uint16_t)(UART_DIV_SAMPLING16(HSI_VALUE, huart->Init.BaudRate));
\r
1730 case UART_CLOCKSOURCE_SYSCLK:
\r
1731 huart->Instance->BRR = (uint16_t)(UART_DIV_SAMPLING16(HAL_RCC_GetSysClockFreq(), huart->Init.BaudRate));
\r
1733 case UART_CLOCKSOURCE_LSE:
\r
1734 huart->Instance->BRR = (uint16_t)(UART_DIV_SAMPLING16(LSE_VALUE, huart->Init.BaudRate));
\r
1736 case UART_CLOCKSOURCE_UNDEFINED:
\r
1749 * @brief Configure the UART peripheral advanced features
\r
1750 * @param huart: uart handle
\r
1753 void UART_AdvFeatureConfig(UART_HandleTypeDef *huart)
\r
1755 /* Check whether the set of advanced features to configure is properly set */
\r
1756 assert_param(IS_UART_ADVFEATURE_INIT(huart->AdvancedInit.AdvFeatureInit));
\r
1758 /* if required, configure TX pin active level inversion */
\r
1759 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_TXINVERT_INIT))
\r
1761 assert_param(IS_UART_ADVFEATURE_TXINV(huart->AdvancedInit.TxPinLevelInvert));
\r
1762 MODIFY_REG(huart->Instance->CR2, USART_CR2_TXINV, huart->AdvancedInit.TxPinLevelInvert);
\r
1765 /* if required, configure RX pin active level inversion */
\r
1766 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_RXINVERT_INIT))
\r
1768 assert_param(IS_UART_ADVFEATURE_RXINV(huart->AdvancedInit.RxPinLevelInvert));
\r
1769 MODIFY_REG(huart->Instance->CR2, USART_CR2_RXINV, huart->AdvancedInit.RxPinLevelInvert);
\r
1772 /* if required, configure data inversion */
\r
1773 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_DATAINVERT_INIT))
\r
1775 assert_param(IS_UART_ADVFEATURE_DATAINV(huart->AdvancedInit.DataInvert));
\r
1776 MODIFY_REG(huart->Instance->CR2, USART_CR2_DATAINV, huart->AdvancedInit.DataInvert);
\r
1779 /* if required, configure RX/TX pins swap */
\r
1780 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_SWAP_INIT))
\r
1782 assert_param(IS_UART_ADVFEATURE_SWAP(huart->AdvancedInit.Swap));
\r
1783 MODIFY_REG(huart->Instance->CR2, USART_CR2_SWAP, huart->AdvancedInit.Swap);
\r
1786 /* if required, configure RX overrun detection disabling */
\r
1787 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_RXOVERRUNDISABLE_INIT))
\r
1789 assert_param(IS_UART_OVERRUN(huart->AdvancedInit.OverrunDisable));
\r
1790 MODIFY_REG(huart->Instance->CR3, USART_CR3_OVRDIS, huart->AdvancedInit.OverrunDisable);
\r
1793 /* if required, configure DMA disabling on reception error */
\r
1794 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_DMADISABLEONERROR_INIT))
\r
1796 assert_param(IS_UART_ADVFEATURE_DMAONRXERROR(huart->AdvancedInit.DMADisableonRxError));
\r
1797 MODIFY_REG(huart->Instance->CR3, USART_CR3_DDRE, huart->AdvancedInit.DMADisableonRxError);
\r
1800 /* if required, configure auto Baud rate detection scheme */
\r
1801 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_AUTOBAUDRATE_INIT))
\r
1803 assert_param(IS_UART_ADVFEATURE_AUTOBAUDRATE(huart->AdvancedInit.AutoBaudRateEnable));
\r
1804 MODIFY_REG(huart->Instance->CR2, USART_CR2_ABREN, huart->AdvancedInit.AutoBaudRateEnable);
\r
1805 /* set auto Baudrate detection parameters if detection is enabled */
\r
1806 if(huart->AdvancedInit.AutoBaudRateEnable == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE)
\r
1808 assert_param(IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(huart->AdvancedInit.AutoBaudRateMode));
\r
1809 MODIFY_REG(huart->Instance->CR2, USART_CR2_ABRMODE, huart->AdvancedInit.AutoBaudRateMode);
\r
1813 /* if required, configure MSB first on communication line */
\r
1814 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_MSBFIRST_INIT))
\r
1816 assert_param(IS_UART_ADVFEATURE_MSBFIRST(huart->AdvancedInit.MSBFirst));
\r
1817 MODIFY_REG(huart->Instance->CR2, USART_CR2_MSBFIRST, huart->AdvancedInit.MSBFirst);
\r
1824 * @brief Check the UART Idle State
\r
1825 * @param huart: uart handle
\r
1826 * @retval HAL status
\r
1828 HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart)
\r
1830 /* Initialize the UART ErrorCode */
\r
1831 huart->ErrorCode = HAL_UART_ERROR_NONE;
\r
1833 /* Check if the Transmitter is enabled */
\r
1834 if((huart->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
\r
1836 /* Wait until TEACK flag is set */
\r
1837 if(UART_WaitOnFlagUntilTimeout(huart, USART_ISR_TEACK, RESET, HAL_UART_TIMEOUT_VALUE) != HAL_OK)
\r
1839 /* Timeout Occured */
\r
1840 return HAL_TIMEOUT;
\r
1843 /* Check if the Receiver is enabled */
\r
1844 if((huart->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
\r
1846 /* Wait until REACK flag is set */
\r
1847 if(UART_WaitOnFlagUntilTimeout(huart, USART_ISR_REACK, RESET, HAL_UART_TIMEOUT_VALUE) != HAL_OK)
\r
1849 /* Timeout Occured */
\r
1850 return HAL_TIMEOUT;
\r
1854 /* Initialize the UART State */
\r
1855 huart->State= HAL_UART_STATE_READY;
\r
1857 /* Process Unlocked */
\r
1858 __HAL_UNLOCK(huart);
\r
1864 * @brief Enables the UART transmitter and disables the UART receiver.
\r
1865 * @param huart: UART handle
\r
1866 * @retval HAL status
\r
1869 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart)
\r
1871 /* Process Locked */
\r
1872 __HAL_LOCK(huart);
\r
1873 huart->State = HAL_UART_STATE_BUSY;
\r
1875 /* Clear TE and RE bits */
\r
1876 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TE | USART_CR1_RE));
\r
1877 /* Enable the USART's transmit interface by setting the TE bit in the USART CR1 register */
\r
1878 SET_BIT(huart->Instance->CR1, USART_CR1_TE);
\r
1880 huart->State= HAL_UART_STATE_READY;
\r
1881 /* Process Unlocked */
\r
1882 __HAL_UNLOCK(huart);
\r
1888 * @brief Enables the UART receiver and disables the UART transmitter.
\r
1889 * @param huart: UART handle
\r
1890 * @retval HAL status
\r
1892 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart)
\r
1894 /* Process Locked */
\r
1895 __HAL_LOCK(huart);
\r
1896 huart->State = HAL_UART_STATE_BUSY;
\r
1898 /* Clear TE and RE bits */
\r
1899 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TE | USART_CR1_RE));
\r
1900 /* Enable the USART's receive interface by setting the RE bit in the USART CR1 register */
\r
1901 SET_BIT(huart->Instance->CR1, USART_CR1_RE);
\r
1903 huart->State = HAL_UART_STATE_READY;
\r
1904 /* Process Unlocked */
\r
1905 __HAL_UNLOCK(huart);
\r
1912 * @brief Transmits break characters.
\r
1913 * @param huart: UART handle
\r
1914 * @retval HAL status
\r
1916 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart)
\r
1918 /* Check the parameters */
\r
1919 assert_param(IS_UART_INSTANCE(huart->Instance));
\r
1921 /* Process Locked */
\r
1922 __HAL_LOCK(huart);
\r
1924 huart->State = HAL_UART_STATE_BUSY;
\r
1926 /* Send break characters */
\r
1927 huart->Instance->RQR |= UART_SENDBREAK_REQUEST;
\r
1929 huart->State = HAL_UART_STATE_READY;
\r
1931 /* Process Unlocked */
\r
1932 __HAL_UNLOCK(huart);
\r
1946 #endif /* HAL_UART_MODULE_ENABLED */
\r
1955 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r