]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L1/stm32l1xx_hal_usart.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_usart.h
1 /**
2   ******************************************************************************
3   * @file    stm32l1xx_hal_usart.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 USART 
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_USART_H
41 #define __STM32L1xx_HAL_USART_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 USART
55   * @{
56   */ 
57
58 /* Exported types ------------------------------------------------------------*/ 
59 /** @defgroup USART_Exported_Types USART Exported Types
60   * @{
61   */ 
62
63
64 /** 
65   * @brief USART Init Structure definition
66   */ 
67 typedef struct
68 {
69   uint32_t BaudRate;                  /*!< This member configures the Usart communication baud rate.
70                                            The baud rate is computed using the following formula:
71                                            - IntegerDivider = ((PCLKx) / (8 * (husart->Init.BaudRate)))
72                                            - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
73
74   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
75                                            This parameter can be a value of @ref USART_Word_Length */
76
77   uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
78                                            This parameter can be a value of @ref USART_Stop_Bits */
79
80   uint32_t Parity;                   /*!< Specifies the parity mode.
81                                            This parameter can be a value of @ref USART_Parity
82                                            @note When parity is enabled, the computed parity is inserted
83                                                  at the MSB position of the transmitted data (9th bit when
84                                                  the word length is set to 9 data bits; 8th bit when the
85                                                  word length is set to 8 data bits). */
86  
87   uint32_t Mode;                      /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
88                                            This parameter can be a value of @ref USART_Mode */
89
90   uint32_t CLKPolarity;               /*!< Specifies the steady state of the serial clock.
91                                            This parameter can be a value of @ref USART_Clock_Polarity */
92
93   uint32_t CLKPhase;                  /*!< Specifies the clock transition on which the bit capture is made.
94                                            This parameter can be a value of @ref USART_Clock_Phase */
95
96   uint32_t CLKLastBit;                /*!< Specifies whether the clock pulse corresponding to the last transmitted
97                                            data bit (MSB) has to be output on the SCLK pin in synchronous mode.
98                                            This parameter can be a value of @ref USART_Last_Bit */
99 }USART_InitTypeDef;
100
101 /** 
102   * @brief HAL State structures definition
103   */ 
104 typedef enum
105 {
106   HAL_USART_STATE_RESET             = 0x00,    /*!< Peripheral is not initialized   */
107   HAL_USART_STATE_READY             = 0x01,    /*!< Peripheral Initialized and ready for use */
108   HAL_USART_STATE_BUSY              = 0x02,    /*!< an internal process is ongoing */   
109   HAL_USART_STATE_BUSY_TX           = 0x12,    /*!< Data Transmission process is ongoing */ 
110   HAL_USART_STATE_BUSY_RX           = 0x22,    /*!< Data Reception process is ongoing */
111   HAL_USART_STATE_BUSY_TX_RX        = 0x32,    /*!< Data Transmission Reception process is ongoing */
112   HAL_USART_STATE_TIMEOUT           = 0x03,    /*!< Timeout state */
113   HAL_USART_STATE_ERROR             = 0x04     /*!< Error */
114 }HAL_USART_StateTypeDef;
115
116 /** 
117   * @brief  HAL USART Error Code structure definition  
118   */ 
119 typedef enum
120 {
121   HAL_USART_ERROR_NONE      = 0x00,    /*!< No error            */
122   HAL_USART_ERROR_PE        = 0x01,    /*!< Parity error        */
123   HAL_USART_ERROR_NE        = 0x02,    /*!< Noise error         */
124   HAL_USART_ERROR_FE        = 0x04,    /*!< frame error         */
125   HAL_USART_ERROR_ORE       = 0x08,    /*!< Overrun error       */
126   HAL_USART_ERROR_DMA       = 0x10     /*!< DMA transfer error  */
127 }HAL_USART_ErrorTypeDef;
128
129 /** 
130   * @brief  USART handle Structure definition  
131   */  
132 typedef struct
133 {
134   USART_TypeDef                 *Instance;        /* USART registers base address        */
135   
136   USART_InitTypeDef             Init;             /* Usart communication parameters      */
137   
138   uint8_t                       *pTxBuffPtr;      /* Pointer to Usart Tx transfer Buffer */
139   
140   uint16_t                      TxXferSize;       /* Usart Tx Transfer size              */
141   
142   __IO uint16_t                 TxXferCount;      /* Usart Tx Transfer Counter           */
143   
144   uint8_t                       *pRxBuffPtr;      /* Pointer to Usart Rx transfer Buffer */
145   
146   uint16_t                      RxXferSize;       /* Usart Rx Transfer size              */
147   
148   __IO uint16_t                 RxXferCount;      /* Usart Rx Transfer Counter           */  
149   
150   DMA_HandleTypeDef             *hdmatx;          /* Usart Tx DMA Handle parameters      */
151     
152   DMA_HandleTypeDef             *hdmarx;          /* Usart Rx DMA Handle parameters      */
153   
154   HAL_LockTypeDef                Lock;            /* Locking object                      */
155   
156   __IO HAL_USART_StateTypeDef    State;           /* Usart communication state           */
157   
158   __IO HAL_USART_ErrorTypeDef    ErrorCode;        /* USART Error code                    */
159   
160 }USART_HandleTypeDef;
161
162 /**
163   * @}
164   */
165
166 /* Exported constants --------------------------------------------------------*/
167 /** @defgroup USART_Exported_Constants USART Exported constants
168   * @{
169   */
170
171 /** @defgroup USART_Word_Length USART Word Length
172   * @{
173   */
174 #define USART_WORDLENGTH_8B                  ((uint32_t)0x00000000)
175 #define USART_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)
176 #define IS_USART_WORD_LENGTH(LENGTH)     (((LENGTH) == USART_WORDLENGTH_8B) || \
177                                           ((LENGTH) == USART_WORDLENGTH_9B))
178 /**
179   * @}
180   */
181
182 /** @defgroup USART_Stop_Bits USART Number of Stop Bits
183   * @{
184   */
185 #define USART_STOPBITS_1                     ((uint32_t)0x00000000)
186 #define USART_STOPBITS_0_5                   ((uint32_t)USART_CR2_STOP_0)
187 #define USART_STOPBITS_2                     ((uint32_t)USART_CR2_STOP_1)
188 #define USART_STOPBITS_1_5                   ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
189 #define IS_USART_STOPBITS(STOPBITS)     (((STOPBITS) == USART_STOPBITS_1) || \
190                                          ((STOPBITS) == USART_STOPBITS_0_5) || \
191                                          ((STOPBITS) == USART_STOPBITS_1_5) || \
192                                          ((STOPBITS) == USART_STOPBITS_2))
193 /**
194   * @}
195   */ 
196
197 /** @defgroup USART_Parity USART Parity
198   * @{
199   */ 
200 #define USART_PARITY_NONE                    ((uint32_t)0x00000000)
201 #define USART_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
202 #define USART_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 
203 #define IS_USART_PARITY(PARITY)     (((PARITY) == USART_PARITY_NONE) || \
204                                      ((PARITY) == USART_PARITY_EVEN) || \
205                                      ((PARITY) == USART_PARITY_ODD))
206 /**
207   * @}
208   */ 
209
210 /** @defgroup USART_Mode USART Mode
211   * @{
212   */ 
213 #define USART_MODE_RX                        ((uint32_t)USART_CR1_RE)
214 #define USART_MODE_TX                        ((uint32_t)USART_CR1_TE)
215 #define USART_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
216 #define IS_USART_MODE(MODE) ((((MODE) & (uint32_t)0x0000FFF3) == 0x00) && ((MODE) != (uint32_t)0x00000000))
217 /**
218   * @}
219   */
220     
221 /** @defgroup USART_Clock USART Clock
222   * @{
223   */ 
224 #define USART_CLOCK_DISABLED                 ((uint32_t)0x00000000)
225 #define USART_CLOCK_ENABLED                  ((uint32_t)USART_CR2_CLKEN)
226 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_CLOCK_DISABLED) || \
227                                ((CLOCK) == USART_CLOCK_ENABLED))
228 /**
229   * @}
230   */ 
231
232 /** @defgroup USART_Clock_Polarity USART Clock Polarity
233   * @{
234   */
235 #define USART_POLARITY_LOW                   ((uint32_t)0x00000000)
236 #define USART_POLARITY_HIGH                  ((uint32_t)USART_CR2_CPOL)
237 #define IS_USART_POLARITY(CPOL) (((CPOL) == USART_POLARITY_LOW) || ((CPOL) == USART_POLARITY_HIGH))
238 /**
239   * @}
240   */ 
241
242 /** @defgroup USART_Clock_Phase USART Clock Phase
243   * @{
244   */
245 #define USART_PHASE_1EDGE                    ((uint32_t)0x00000000)
246 #define USART_PHASE_2EDGE                    ((uint32_t)USART_CR2_CPHA)
247 #define IS_USART_PHASE(CPHA) (((CPHA) == USART_PHASE_1EDGE) || ((CPHA) == USART_PHASE_2EDGE))
248 /**
249   * @}
250   */
251
252 /** @defgroup USART_Last_Bit USART Last Bit
253   * @{
254   */
255 #define USART_LASTBIT_DISABLE                ((uint32_t)0x00000000)
256 #define USART_LASTBIT_ENABLE                 ((uint32_t)USART_CR2_LBCL)
257 #define IS_USART_LASTBIT(LASTBIT)   (((LASTBIT) == USART_LASTBIT_DISABLE) || \
258                                      ((LASTBIT) == USART_LASTBIT_ENABLE))
259 /**
260   * @}
261   */
262
263 /** @defgroup USART_NACK_State USART NACK State
264   * @{
265   */
266 #define USARTNACK_ENABLED           ((uint32_t)USART_CR3_NACK)
267 #define USARTNACK_DISABLED          ((uint32_t)0x00000000)
268 #define IS_USART_NACK_STATE(NACK)   (((NACK) == USARTNACK_ENABLED) || \
269                                      ((NACK) == USARTNACK_DISABLED))
270 /**
271   * @}
272   */
273
274 /** @defgroup USART_Flags USART Flags
275   *        Elements values convention: 0xXXXX
276   *           - 0xXXXX  : Flag mask in the SR register
277   * @{
278   */
279
280 #define USART_FLAG_CTS                       ((uint32_t)USART_SR_CTS)
281 #define USART_FLAG_LBD                       ((uint32_t)USART_SR_LBD)
282 #define USART_FLAG_TXE                       ((uint32_t)USART_SR_TXE)
283 #define USART_FLAG_TC                        ((uint32_t)USART_SR_TC)
284 #define USART_FLAG_RXNE                      ((uint32_t)USART_SR_RXNE)
285 #define USART_FLAG_IDLE                      ((uint32_t)USART_SR_IDLE)
286 #define USART_FLAG_ORE                       ((uint32_t)USART_SR_ORE)
287 #define USART_FLAG_NE                        ((uint32_t)USART_SR_NE)
288 #define USART_FLAG_FE                        ((uint32_t)USART_SR_FE)
289 #define USART_FLAG_PE                        ((uint32_t)USART_SR_PE)
290 /**
291   * @}
292   */
293
294 /** @defgroup USART_Interrupt_definition USART Interrupts Definition
295   *        Elements values convention: 0xY000XXXX
296   *           - XXXX  : Interrupt mask in the XX register
297   *           - Y  : Interrupt source register (4bits)
298   *                 - 01: CR1 register
299   *                 - 10: CR2 register
300   *                 - 11: CR3 register
301   *
302   * @{
303   */
304 #define USART_IT_PE                          ((uint32_t)0x10000100)
305 #define USART_IT_TXE                         ((uint32_t)0x10000080)
306 #define USART_IT_TC                          ((uint32_t)0x10000040)
307 #define USART_IT_RXNE                        ((uint32_t)0x10000020)
308 #define USART_IT_IDLE                        ((uint32_t)0x10000010)
309
310 #define USART_IT_LBD                         ((uint32_t)0x20000040)
311 #define USART_IT_CTS                         ((uint32_t)0x30000400)
312
313 #define USART_IT_ERR                         ((uint32_t)0x30000001)
314
315
316 /**
317   * @}
318   */
319
320 /** @defgroup USART_Interruption_Mask    USART interruptions flag mask
321   * @{
322   */ 
323 #define USART_IT_MASK  ((uint32_t)0x0000FFFF)
324 /**
325   * @}
326   */
327
328 /**
329   * @}
330   */
331   
332 /* Exported macro ------------------------------------------------------------*/
333 /** @defgroup USART_Exported_Macros USART Exported Macros
334   * @{
335   */
336
337
338 /** @brief Reset USART handle state
339   * @param  __HANDLE__: specifies the USART Handle.
340   *         This parameter can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
341   * @retval None
342   */
343 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
344
345 /** @brief  Checks whether the specified USART flag is set or not.
346   * @param  __HANDLE__: specifies the USART Handle.
347   *         This parameter can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
348   * @param  __FLAG__: specifies the flag to check.
349   *        This parameter can be one of the following values:
350   *            @arg USART_FLAG_TXE:  Transmit data register empty flag
351   *            @arg USART_FLAG_TC:   Transmission Complete flag
352   *            @arg USART_FLAG_RXNE: Receive data register not empty flag
353   *            @arg USART_FLAG_IDLE: Idle Line detection flag
354   *            @arg USART_FLAG_ORE:  OverRun Error flag
355   *            @arg USART_FLAG_NE:   Noise Error flag
356   *            @arg USART_FLAG_FE:   Framing Error flag
357   *            @arg USART_FLAG_PE:   Parity Error flag
358   * @retval The new state of __FLAG__ (TRUE or FALSE).
359   */
360
361 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
362
363 /** @brief  Clears the specified USART pending flags.
364   * @param  __HANDLE__: specifies the USART Handle.
365   *         This parameter can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
366   * @param  __FLAG__: specifies the flag to check.
367   *          This parameter can be any combination of the following values:
368   *            @arg USART_FLAG_TC:   Transmission Complete flag.
369   *            @arg USART_FLAG_RXNE: Receive data register not empty flag.
370   *   
371   * @note   PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun 
372   *          error) and IDLE (Idle line detected) flags are cleared by software 
373   *          sequence: a read operation to USART_SR register followed by a read
374   *          operation to USART_DR register.
375   * @note   RXNE flag can be also cleared by a read to the USART_DR register.
376   * @note   TC flag can be also cleared by software sequence: a read operation to 
377   *          USART_SR register followed by a write operation to USART_DR register.
378   * @note   TXE flag is cleared only by a write to the USART_DR register.
379   *   
380   * @retval None
381   */
382 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__)  ((__HANDLE__)->Instance->SR = ~(__FLAG__))
383
384 /** @brief  Clear the USART PE pending flag.
385   * @param  __HANDLE__: specifies the USART Handle.
386   *         This parameter can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
387   * @retval None
388   */
389 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) do{(__HANDLE__)->Instance->SR;\
390                                                 (__HANDLE__)->Instance->DR;}while(0)
391 /** @brief  Clear the USART FE pending flag.
392   * @param  __HANDLE__: specifies the USART Handle.
393   *         This parameter can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
394   * @retval None
395   */
396 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
397
398 /** @brief  Clear the USART NE pending flag.
399   * @param  __HANDLE__: specifies the USART Handle.
400   *         This parameter can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
401   * @retval None
402   */
403 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
404
405 /** @brief  Clear the USART ORE pending flag.
406   * @param  __HANDLE__: specifies the USART Handle.
407   *         This parameter can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
408   * @retval None
409   */
410 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
411
412 /** @brief  Clear the USART IDLE pending flag.
413   * @param  __HANDLE__: specifies the USART Handle.
414   *         This parameter can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
415   * @retval None
416   */
417 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
418
419 /** @brief  Enables or disables the specified Usart interrupts.
420   * @param  __HANDLE__: specifies the USART Handle.
421   *         This parameter can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
422   * @param  __INTERRUPT__: specifies the USART interrupt source to check.
423   *          This parameter can be one of the following values:
424   *            @arg USART_IT_TXE:  Transmit Data Register empty interrupt
425   *            @arg USART_IT_TC:   Transmission complete interrupt
426   *            @arg USART_IT_RXNE: Receive Data register not empty interrupt
427   *            @arg USART_IT_IDLE: Idle line detection interrupt
428   *            @arg USART_IT_PE:   Parity Error interrupt
429   *            @arg USART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
430   * @retval None
431   */
432 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & USART_IT_MASK)): \
433                                                            (((__INTERRUPT__) >> 28) == 2)? ((__HANDLE__)->Instance->CR2 |=  ((__INTERRUPT__) & USART_IT_MASK)): \
434                                                            ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & USART_IT_MASK)))
435 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & USART_IT_MASK)): \
436                                                            (((__INTERRUPT__) >> 28) == 2)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & USART_IT_MASK)): \
437                                                            ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & USART_IT_MASK)))
438
439
440     
441 /** @brief  Checks whether the specified Usart interrupt has occurred or not.
442   * @param  __HANDLE__: specifies the USART Handle.
443   *         This parameter can be USARTx where x: 1, 2 or 3 to select the USART peripheral.
444   * @param  __IT__: specifies the USART interrupt source to check.
445   *          This parameter can be one of the following values:
446   *            @arg USART_IT_TXE: Transmit Data Register empty interrupt
447   *            @arg USART_IT_TC:  Transmission complete interrupt
448   *            @arg USART_IT_RXNE: Receive Data register not empty interrupt
449   *            @arg USART_IT_IDLE: Idle line detection interrupt
450   *            @arg USART_IT_ERR: Error interrupt
451   *            @arg USART_IT_PE: Parity Error interrupt
452   * @retval The new state of __IT__ (TRUE or FALSE).
453   */
454 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28) == 1)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28) == 2)? \
455                                                       (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & USART_IT_MASK))
456
457 /** @brief  Enable USART
458   * @param  __HANDLE__: specifies the USART Handle.
459   *         The Handle Instance can be USARTx where x: 1, 2, 3 to select the USART peripheral
460   * @retval None
461   */ 
462 #define __HAL_USART_ENABLE(__HANDLE__)               SET_BIT((__HANDLE__)->Instance->CR1,(USART_CR1_UE)) 
463
464 /** @brief  Disable USART
465   * @param  __HANDLE__: specifies the USART Handle.
466   *         The Handle Instance can be USARTx where x: 1, 2, 3 to select the USART peripheral
467   * @retval None
468   */ 
469 #define __HAL_USART_DISABLE(__HANDLE__)              CLEAR_BIT((__HANDLE__)->Instance->CR1,(USART_CR1_UE)) 
470  
471
472 /**
473   * @}
474   */
475
476 /* Private macros --------------------------------------------------------*/
477 /** @defgroup USART_Private_Macros   USART Private Macros
478   * @{
479   */
480
481 #define USART_DIV(__PCLK__, __BAUD__)                (((__PCLK__)*25)/(4*(__BAUD__)))
482 #define USART_DIVMANT(__PCLK__, __BAUD__)            (USART_DIV((__PCLK__), (__BAUD__))/100)
483 #define USART_DIVFRAQ(__PCLK__, __BAUD__)            (((USART_DIV((__PCLK__), (__BAUD__)) - (USART_DIVMANT((__PCLK__), (__BAUD__)) * 100)) * 16 + 50) / 100)
484 #define USART_BRR(__PCLK__, __BAUD__)                ((USART_DIVMANT((__PCLK__), (__BAUD__)) << 4)|(USART_DIVFRAQ((__PCLK__), (__BAUD__)) & 0x0F))
485
486 /** @brief  Check USART Baud rate
487   * @param  __BAUDRATE__: Baudrate specified by the user
488   *         The maximum Baud Rate is derived from the maximum clock on APB (i.e. 32 MHz) 
489   *         divided by the smallest oversampling used on the USART (i.e. 8)  
490   * @retval Test result (TRUE or FALSE) 
491   */ 
492 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 4000001)
493 /**
494   * @}
495   */
496
497
498 /* Exported functions --------------------------------------------------------*/
499
500 /** @addtogroup USART_Exported_Functions USART Exported Functions
501   * @{
502   */
503   
504 /** @addtogroup USART_Exported_Functions_Group1 USART Initialization and de-initialization functions 
505   * @{
506   */
507
508 /* Initialization and de-initialization functions  ******************************/
509 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
510 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
511 void HAL_USART_MspInit(USART_HandleTypeDef *husart);
512 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
513
514 /**
515   * @}
516   */
517
518 /** @addtogroup USART_Exported_Functions_Group2 IO operation functions 
519   * @{
520   */
521
522 /* IO operation functions *******************************************************/
523 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
524 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
525 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
526 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
527 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
528 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData,  uint16_t Size);
529 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
530 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
531 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
532 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
533 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
534 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
535 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
536 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
537 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
538 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
539 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
540 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
541 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
542
543 /**
544   * @}
545   */
546
547 /* Peripheral Control functions ***********************************************/
548
549 /** @addtogroup USART_Exported_Functions_Group3 Peripheral State and Errors functions 
550   * @{
551   */
552
553 /* Peripheral State and Error functions ***************************************/
554 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
555 uint32_t               HAL_USART_GetError(USART_HandleTypeDef *husart);
556
557 /**
558   * @}
559   */
560
561 /**
562   * @}
563   */
564
565 /**
566   * @}
567   */ 
568
569 /**
570   * @}
571   */
572
573 #ifdef __cplusplus
574 }
575 #endif
576
577 #endif /* __STM32L1xx_HAL_USART_H */
578
579 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/