]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_uart.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4 / stm32f4xx_hal_uart.h
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_uart.h
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    19-June-2014
7   * @brief   Header file of UART HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without specific prior written permission.
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************
36   */ 
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_UART_H
40 #define __STM32F4xx_HAL_UART_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
48
49 /** @addtogroup STM32F4xx_HAL_Driver
50   * @{
51   */
52
53 /** @addtogroup UART
54   * @{
55   */ 
56
57 /* Exported types ------------------------------------------------------------*/ 
58
59 /** 
60   * @brief UART Init Structure definition  
61   */ 
62 typedef struct
63 {
64   uint32_t BaudRate;                  /*!< This member configures the UART communication baud rate.
65                                            The baud rate is computed using the following formula:
66                                            - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (huart->Init.BaudRate)))
67                                            - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8 * (OVR8+1)) + 0.5 
68                                            Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */
69
70   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
71                                            This parameter can be a value of @ref UART_Word_Length */
72
73   uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
74                                            This parameter can be a value of @ref UART_Stop_Bits */
75
76   uint32_t Parity;                    /*!< Specifies the parity mode.
77                                            This parameter can be a value of @ref UART_Parity
78                                            @note When parity is enabled, the computed parity is inserted
79                                                  at the MSB position of the transmitted data (9th bit when
80                                                  the word length is set to 9 data bits; 8th bit when the
81                                                  word length is set to 8 data bits). */
82  
83   uint32_t Mode;                      /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
84                                            This parameter can be a value of @ref UART_Mode */
85
86   uint32_t HwFlowCtl;                 /*!< Specifies wether the hardware flow control mode is enabled
87                                            or disabled.
88                                            This parameter can be a value of @ref UART_Hardware_Flow_Control */
89   
90   uint32_t OverSampling;              /*!< Specifies wether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
91                                            This parameter can be a value of @ref UART_Over_Sampling */ 
92 }UART_InitTypeDef;
93
94 /** 
95   * @brief HAL UART State structures definition  
96   */ 
97 typedef enum
98 {
99   HAL_UART_STATE_RESET             = 0x00,    /*!< Peripheral is not yet Initialized                  */
100   HAL_UART_STATE_READY             = 0x01,    /*!< Peripheral Initialized and ready for use           */
101   HAL_UART_STATE_BUSY              = 0x02,    /*!< an internal process is ongoing                     */   
102   HAL_UART_STATE_BUSY_TX           = 0x12,    /*!< Data Transmission process is ongoing               */ 
103   HAL_UART_STATE_BUSY_RX           = 0x22,    /*!< Data Reception process is ongoing                  */
104   HAL_UART_STATE_BUSY_TX_RX        = 0x32,    /*!< Data Transmission and Reception process is ongoing */  
105   HAL_UART_STATE_TIMEOUT           = 0x03,    /*!< Timeout state                                      */
106   HAL_UART_STATE_ERROR             = 0x04     /*!< Error                                              */      
107 }HAL_UART_StateTypeDef;
108
109 /** 
110   * @brief  HAL UART Error Code structure definition  
111   */ 
112 typedef enum
113 {
114   HAL_UART_ERROR_NONE      = 0x00,    /*!< No error            */
115   HAL_UART_ERROR_PE        = 0x01,    /*!< Parity error        */
116   HAL_UART_ERROR_NE        = 0x02,    /*!< Noise error         */
117   HAL_UART_ERROR_FE        = 0x04,    /*!< frame error         */
118   HAL_UART_ERROR_ORE       = 0x08,    /*!< Overrun error       */
119   HAL_UART_ERROR_DMA       = 0x10     /*!< DMA transfer error  */
120 }HAL_UART_ErrorTypeDef;
121
122 /** 
123   * @brief  UART handle Structure definition  
124   */  
125 typedef struct
126 {
127   USART_TypeDef                 *Instance;        /* UART registers base address        */
128   
129   UART_InitTypeDef              Init;             /* UART communication parameters      */
130   
131   uint8_t                       *pTxBuffPtr;      /* Pointer to UART Tx transfer Buffer */
132   
133   uint16_t                      TxXferSize;       /* UART Tx Transfer size              */
134   
135   uint16_t                      TxXferCount;      /* UART Tx Transfer Counter           */
136   
137   uint8_t                       *pRxBuffPtr;      /* Pointer to UART Rx transfer Buffer */
138   
139   uint16_t                      RxXferSize;       /* UART Rx Transfer size              */
140   
141   uint16_t                      RxXferCount;      /* UART Rx Transfer Counter           */  
142   
143   DMA_HandleTypeDef             *hdmatx;          /* UART Tx DMA Handle parameters      */
144     
145   DMA_HandleTypeDef             *hdmarx;          /* UART Rx DMA Handle parameters      */
146   
147   HAL_LockTypeDef               Lock;            /* Locking object                     */
148
149   __IO HAL_UART_StateTypeDef    State;            /* UART communication state           */
150   
151   __IO HAL_UART_ErrorTypeDef    ErrorCode;        /* UART Error code                    */
152   
153 }UART_HandleTypeDef;
154
155 /* Exported constants --------------------------------------------------------*/
156 /** @defgroup UART_Exported_Constants
157   * @{
158   */
159   
160 /** @defgroup UART_Word_Length 
161   * @{
162   */
163 #define UART_WORDLENGTH_8B                  ((uint32_t)0x00000000)
164 #define UART_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)
165 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
166                                      ((LENGTH) == UART_WORDLENGTH_9B))
167 /**
168   * @}
169   */
170
171 /** @defgroup UART_Stop_Bits 
172   * @{
173   */
174 #define UART_STOPBITS_1                     ((uint32_t)0x00000000)
175 #define UART_STOPBITS_2                     ((uint32_t)USART_CR2_STOP_1)
176 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
177                                     ((STOPBITS) == UART_STOPBITS_2))
178 /**
179   * @}
180   */ 
181
182 /** @defgroup UART_Parity 
183   * @{
184   */ 
185 #define UART_PARITY_NONE                    ((uint32_t)0x00000000)
186 #define UART_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
187 #define UART_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 
188 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
189                                 ((PARITY) == UART_PARITY_EVEN) || \
190                                 ((PARITY) == UART_PARITY_ODD))
191 /**
192   * @}
193   */ 
194
195 /** @defgroup UART_Hardware_Flow_Control 
196   * @{
197   */ 
198 #define UART_HWCONTROL_NONE                  ((uint32_t)0x00000000)
199 #define UART_HWCONTROL_RTS                   ((uint32_t)USART_CR3_RTSE)
200 #define UART_HWCONTROL_CTS                   ((uint32_t)USART_CR3_CTSE)
201 #define UART_HWCONTROL_RTS_CTS               ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
202 #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
203                               (((CONTROL) == UART_HWCONTROL_NONE) || \
204                                ((CONTROL) == UART_HWCONTROL_RTS) || \
205                                ((CONTROL) == UART_HWCONTROL_CTS) || \
206                                ((CONTROL) == UART_HWCONTROL_RTS_CTS))
207 /**
208   * @}
209   */
210
211 /** @defgroup UART_Mode 
212   * @{
213   */ 
214 #define UART_MODE_RX                        ((uint32_t)USART_CR1_RE)
215 #define UART_MODE_TX                        ((uint32_t)USART_CR1_TE)
216 #define UART_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
217 #define IS_UART_MODE(MODE) ((((MODE) & (uint32_t)0x0000FFF3) == 0x00) && ((MODE) != (uint32_t)0x000000))
218 /**
219   * @}
220   */
221     
222  /** @defgroup UART_State 
223   * @{
224   */ 
225 #define UART_STATE_DISABLE                  ((uint32_t)0x00000000)
226 #define UART_STATE_ENABLE                   ((uint32_t)USART_CR1_UE)
227 #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
228                               ((STATE) == UART_STATE_ENABLE))
229 /**
230   * @}
231   */
232
233 /** @defgroup UART_Over_Sampling 
234   * @{
235   */
236 #define UART_OVERSAMPLING_16                    ((uint32_t)0x00000000)
237 #define UART_OVERSAMPLING_8                     ((uint32_t)USART_CR1_OVER8)
238 #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
239                                         ((SAMPLING) == UART_OVERSAMPLING_8))
240 /**
241   * @}
242   */
243
244 /** @defgroup UART_LIN_Break_Detection_Length 
245   * @{
246   */  
247 #define UART_LINBREAKDETECTLENGTH_10B      ((uint32_t)0x00000000)
248 #define UART_LINBREAKDETECTLENGTH_11B      ((uint32_t)0x00000020)
249 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
250                                                  ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
251 /**
252   * @}
253   */
254                                          
255 /** @defgroup UART_WakeUp_functions
256   * @{
257   */
258 #define UART_WAKEUPMETHODE_IDLELINE                ((uint32_t)0x00000000)
259 #define UART_WAKEUPMETHODE_ADDRESSMARK             ((uint32_t)0x00000800)
260 #define IS_UART_WAKEUPMETHODE(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHODE_IDLELINE) || \
261                                        ((WAKEUP) == UART_WAKEUPMETHODE_ADDRESSMARK))
262 /**
263   * @}
264   */
265
266 /** @defgroup UART_Flags 
267   *        Elements values convention: 0xXXXX
268   *           - 0xXXXX  : Flag mask in the SR register
269   * @{
270   */
271 #define UART_FLAG_CTS                       ((uint32_t)0x00000200)
272 #define UART_FLAG_LBD                       ((uint32_t)0x00000100)
273 #define UART_FLAG_TXE                       ((uint32_t)0x00000080)
274 #define UART_FLAG_TC                        ((uint32_t)0x00000040)
275 #define UART_FLAG_RXNE                      ((uint32_t)0x00000020)
276 #define UART_FLAG_IDLE                      ((uint32_t)0x00000010)
277 #define UART_FLAG_ORE                       ((uint32_t)0x00000008)
278 #define UART_FLAG_NE                        ((uint32_t)0x00000004)
279 #define UART_FLAG_FE                        ((uint32_t)0x00000002)
280 #define UART_FLAG_PE                        ((uint32_t)0x00000001)
281 /**
282   * @}
283   */
284
285 /** @defgroup UART_Interrupt_definition 
286   *        Elements values convention: 0xY000XXXX
287   *           - XXXX  : Interrupt mask in the XX register
288   *           - Y  : Interrupt source register (2bits)
289   *                 - 01: CR1 register
290   *                 - 10: CR2 register
291   *                 - 11: CR3 register
292   *
293   * @{
294   */  
295 #define UART_IT_PE                          ((uint32_t)0x10000100)
296 #define UART_IT_TXE                         ((uint32_t)0x10000080)
297 #define UART_IT_TC                          ((uint32_t)0x10000040)
298 #define UART_IT_RXNE                        ((uint32_t)0x10000020)
299 #define UART_IT_IDLE                        ((uint32_t)0x10000010)
300
301 #define UART_IT_LBD                         ((uint32_t)0x20000040)
302 #define UART_IT_CTS                         ((uint32_t)0x30000400)
303
304 #define UART_IT_ERR                         ((uint32_t)0x30000001)
305
306 /**
307   * @}
308   */
309
310 /**
311   * @}
312   */
313   
314 /* Exported macro ------------------------------------------------------------*/
315
316 /** @brief Reset UART handle state
317   * @param  __HANDLE__: specifies the UART Handle.
318   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
319   *         UART peripheral.
320   * @retval None
321   */
322 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_UART_STATE_RESET)
323
324 /** @brief  Flushs the UART DR register 
325   * @param  __HANDLE__: specifies the UART Handle.
326   */
327 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
328
329 /** @brief  Checks whether the specified UART flag is set or not.
330   * @param  __HANDLE__: specifies the UART Handle.
331   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
332   *         UART peripheral.
333   * @param  __FLAG__: specifies the flag to check.
334   *        This parameter can be one of the following values:
335   *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5)
336   *            @arg UART_FLAG_LBD:  LIN Break detection flag
337   *            @arg UART_FLAG_TXE:  Transmit data register empty flag
338   *            @arg UART_FLAG_TC:   Transmission Complete flag
339   *            @arg UART_FLAG_RXNE: Receive data register not empty flag
340   *            @arg UART_FLAG_IDLE: Idle Line detection flag
341   *            @arg UART_FLAG_ORE:  OverRun Error flag
342   *            @arg UART_FLAG_NE:   Noise Error flag
343   *            @arg UART_FLAG_FE:   Framing Error flag
344   *            @arg UART_FLAG_PE:   Parity Error flag
345   * @retval The new state of __FLAG__ (TRUE or FALSE).
346   */
347
348 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))   
349      
350 /** @brief  Clears the specified UART pending flag.
351   * @param  __HANDLE__: specifies the UART Handle.
352   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
353   *         UART peripheral.
354   * @param  __FLAG__: specifies the flag to check.
355   *          This parameter can be any combination of the following values:
356   *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5).
357   *            @arg UART_FLAG_LBD:  LIN Break detection flag.
358   *            @arg UART_FLAG_TC:   Transmission Complete flag.
359   *            @arg UART_FLAG_RXNE: Receive data register not empty flag.
360   *   
361   * @note   PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun 
362   *          error) and IDLE (Idle line detected) flags are cleared by software 
363   *          sequence: a read operation to USART_SR register followed by a read
364   *          operation to USART_DR register.
365   * @note   RXNE flag can be also cleared by a read to the USART_DR register.
366   * @note   TC flag can be also cleared by software sequence: a read operation to 
367   *          USART_SR register followed by a write operation to USART_DR register.
368   * @note   TXE flag is cleared only by a write to the USART_DR register.
369   *   
370   * @retval None
371   */
372 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
373
374 /** @brief  Clear the UART PE pending flag.
375   * @param  __HANDLE__: specifies the UART Handle.
376   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
377   *         UART peripheral.
378   * @retval None
379   */
380 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) do{(__HANDLE__)->Instance->SR;\
381                                                (__HANDLE__)->Instance->DR;}while(0)
382 /** @brief  Clear the UART FE pending flag.
383   * @param  __HANDLE__: specifies the UART Handle.
384   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
385   *         UART peripheral.
386   * @retval None
387   */
388 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
389
390 /** @brief  Clear the UART NE pending flag.
391   * @param  __HANDLE__: specifies the UART Handle.
392   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
393   *         UART peripheral.
394   * @retval None
395   */
396 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
397
398 /** @brief  Clear the UART ORE pending flag.
399   * @param  __HANDLE__: specifies the UART Handle.
400   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
401   *         UART peripheral.
402   * @retval None
403   */
404 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
405
406 /** @brief  Clear the UART IDLE pending flag.
407   * @param  __HANDLE__: specifies the UART Handle.
408   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
409   *         UART peripheral.
410   * @retval None
411   */
412 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
413                                                  
414 /** @brief  Enables or disables the specified UART interrupt.
415   * @param  __HANDLE__: specifies the UART Handle.
416   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
417   *         UART peripheral.
418   * @param  __INTERRUPT__: specifies the UART interrupt source to check.
419   *          This parameter can be one of the following values:
420   *            @arg UART_IT_CTS:  CTS change interrupt
421   *            @arg UART_IT_LBD:  LIN Break detection interrupt
422   *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
423   *            @arg UART_IT_TC:   Transmission complete interrupt
424   *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
425   *            @arg UART_IT_IDLE: Idle line detection interrupt
426   *            @arg UART_IT_PE:   Parity Error interrupt
427   *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
428   * @param  NewState: new state of the specified UART interrupt.
429   *          This parameter can be: ENABLE or DISABLE.
430   * @retval None
431   */
432 #define UART_IT_MASK  ((uint32_t)0x0000FFFF)
433 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \
434                                                            (((__INTERRUPT__) >> 28) == 2)? ((__HANDLE__)->Instance->CR2 |=  ((__INTERRUPT__) & UART_IT_MASK)): \
435                                                         ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))
436 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
437                                                            (((__INTERRUPT__) >> 28) == 2)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
438                                                         ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK)))
439     
440 /** @brief  Checks whether the specified UART interrupt has occurred or not.
441   * @param  __HANDLE__: specifies the UART Handle.
442   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
443   *         UART peripheral.
444   * @param  __IT__: specifies the UART interrupt source to check.
445   *          This parameter can be one of the following values:
446   *            @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
447   *            @arg UART_IT_LBD: LIN Break detection interrupt
448   *            @arg UART_IT_TXE: Transmit Data Register empty interrupt
449   *            @arg UART_IT_TC:  Transmission complete interrupt
450   *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
451   *            @arg UART_IT_IDLE: Idle line detection interrupt
452   *            @arg USART_IT_ERR: Error interrupt
453   * @retval The new state of __IT__ (TRUE or FALSE).
454   */
455 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28) == 1)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28) == 2)? \
456                                                       (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK))
457
458 /** @brief  Enable CTS flow control 
459   *         This macro allows to enable CTS hardware flow control for a given UART instance, 
460   *         without need to call HAL_UART_Init() function.
461   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
462   * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
463   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
464   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
465   *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
466   *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).                                                                                                                  
467   * @param  __HANDLE__: specifies the UART Handle.
468   *         The Handle Instance can be USART1, USART2 or LPUART.
469   * @retval None
470   */
471 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__)        \
472   do{                                                      \
473     SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE);  \
474     (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE;        \
475   } while(0)
476
477 /** @brief  Disable CTS flow control 
478   *         This macro allows to disable CTS hardware flow control for a given UART instance, 
479   *         without need to call HAL_UART_Init() function.
480   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
481   * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
482   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
483   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
484   *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
485   *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 
486   * @param  __HANDLE__: specifies the UART Handle.
487   *         The Handle Instance can be USART1, USART2 or LPUART.
488   * @retval None
489   */
490 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__)        \
491   do{                                                       \
492     CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
493     (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE);      \
494   } while(0)
495
496 /** @brief  Enable RTS flow control 
497   *         This macro allows to enable RTS hardware flow control for a given UART instance, 
498   *         without need to call HAL_UART_Init() function.
499   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
500   * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
501   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
502   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
503   *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
504   *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 
505   * @param  __HANDLE__: specifies the UART Handle.
506   *         The Handle Instance can be USART1, USART2 or LPUART.
507   * @retval None
508   */
509 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__)       \
510   do{                                                     \
511     SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
512     (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE;       \
513   } while(0)
514
515 /** @brief  Disable RTS flow control 
516   *         This macro allows to disable RTS hardware flow control for a given UART instance, 
517   *         without need to call HAL_UART_Init() function.
518   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
519   * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
520   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
521   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
522   *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
523   *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 
524   * @param  __HANDLE__: specifies the UART Handle.
525   *         The Handle Instance can be USART1, USART2 or LPUART.
526   * @retval None
527   */
528 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__)       \
529   do{                                                      \
530     CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
531     (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE);     \
532   } while(0)
533
534 /** @brief  macros to enables or disables the UART's one bit sampling method
535   * @param  __HANDLE__: specifies the UART Handle.  
536   * @retval None
537   */     
538 #define __HAL_UART_ONEBIT_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
539 #define __HAL_UART_ONEBIT_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
540
541 #define __HAL_UART_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
542 #define __HAL_UART_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
543     
544 #define __DIV_SAMPLING16(_PCLK_, _BAUD_)            (((_PCLK_)*25)/(4*(_BAUD_)))
545 #define __DIVMANT_SAMPLING16(_PCLK_, _BAUD_)        (__DIV_SAMPLING16((_PCLK_), (_BAUD_))/100)
546 #define __DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_)        (((__DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (__DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100)) * 16 + 50) / 100)
547 #define __UART_BRR_SAMPLING16(_PCLK_, _BAUD_)       ((__DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4)|(__DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0F))
548
549 #define __DIV_SAMPLING8(_PCLK_, _BAUD_)             (((_PCLK_)*25)/(2*(_BAUD_)))
550 #define __DIVMANT_SAMPLING8(_PCLK_, _BAUD_)         (__DIV_SAMPLING8((_PCLK_), (_BAUD_))/100)
551 #define __DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_)         (((__DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (__DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100)) * 16 + 50) / 100)
552 #define __UART_BRR_SAMPLING8(_PCLK_, _BAUD_)        ((__DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4)|(__DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x0F))
553
554 #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001)
555 #define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)                             
556
557 /* Exported functions --------------------------------------------------------*/
558 /* Initialization/de-initialization functions  **********************************/
559 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
560 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
561 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
562 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethode);
563 HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
564 void HAL_UART_MspInit(UART_HandleTypeDef *huart);
565 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
566
567 /* IO operation functions *******************************************************/
568 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
569 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
570 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
571 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
572 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
573 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
574 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
575 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
576 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
577 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
578 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
579 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
580 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
581 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
582 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
583
584 /* Peripheral Control functions  ************************************************/
585 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
586 HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
587 HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart);
588 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
589 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
590
591 /* Peripheral State functions  **************************************************/
592 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
593 uint32_t              HAL_UART_GetError(UART_HandleTypeDef *huart);
594
595 /**
596   * @}
597   */ 
598
599 /**
600   * @}
601   */ 
602   
603 #ifdef __cplusplus
604 }
605 #endif
606
607 #endif /* __STM32F4xx_HAL_UART_H */
608
609 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/