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