]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_usart.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32L0 / stm32l0xx_hal_usart.h
1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_hal_usart.h
4   * @author  MCD Application Team
5   * @version V1.2.0
6   * @date    06-February-2015
7   * @brief   Header file of USART HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2015 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   * Unless required by applicable law or agreed to in writing, software 
36   * distributed under the License is distributed on an "AS IS" BASIS, 
37   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38   * See the License for the specific language governing permissions and
39   * limitations under the License.
40   *
41   ******************************************************************************
42   */ 
43
44 /* Define to prevent recursive inclusion -------------------------------------*/
45 #ifndef __STM32L0xx_HAL_USART_H
46 #define __STM32L0xx_HAL_USART_H
47
48 #ifdef __cplusplus
49  extern "C" {
50 #endif
51
52 /* Includes ------------------------------------------------------------------*/
53 #include "stm32l0xx_hal_def.h"
54
55 /** @addtogroup STM32L0xx_HAL_Driver
56   * @{
57   */
58
59 /** @defgroup USART USART (Synchronous UART)
60   * @{
61   */ 
62
63 /******************************************************************************/
64 /* Exported types ------------------------------------------------------------*/
65 /******************************************************************************/
66
67    /** @defgroup USART_Exported_Types USART Exported Types
68   * @{
69   */
70
71 /** @defgroup USART_Init_Configuration USART initialization configuration structure
72   * @{
73   */
74 /** 
75   * @brief USART Init Structure definition  
76   */ 
77 typedef struct
78 {
79   uint32_t BaudRate;                  /*!< This member configures the Usart communication baud rate.
80                                            The baud rate is computed using the following formula:
81                                               Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate))) */
82
83   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
84                                            This parameter can be a value of @ref USARTEx_Word_Length */
85
86   uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
87                                            This parameter can be a value of @ref USART_Stop_Bits */
88
89   uint32_t Parity;                   /*!< Specifies the parity mode.
90                                            This parameter can be a value of @ref USART_Parity
91                                            @note When parity is enabled, the computed parity is inserted
92                                                  at the MSB position of the transmitted data (9th bit when
93                                                  the word length is set to 9 data bits; 8th bit when the
94                                                  word length is set to 8 data bits). */
95  
96   uint32_t Mode;                      /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
97                                            This parameter can be a value of @ref USART_Mode */
98
99   uint32_t CLKPolarity;               /*!< Specifies the steady state of the serial clock.
100                                            This parameter can be a value of @ref USART_Clock_Polarity */
101
102   uint32_t CLKPhase;                  /*!< Specifies the clock transition on which the bit capture is made.
103                                            This parameter can be a value of @ref USART_Clock_Phase */
104
105   uint32_t CLKLastBit;                /*!< Specifies whether the clock pulse corresponding to the last transmitted
106                                            data bit (MSB) has to be output on the SCLK pin in synchronous mode.
107                                            This parameter can be a value of @ref USART_Last_Bit */
108 }USART_InitTypeDef;
109
110 /**
111   * @}
112   */
113
114 /** @defgroup USART_State_Definition  USART state definition
115   * @{
116   */
117 /** 
118   * @brief HAL State structures definition  
119   */ 
120 typedef enum
121 {
122   HAL_USART_STATE_RESET             = 0x00,    /*!< Peripheral Reset state */  
123   HAL_USART_STATE_READY             = 0x01,    /*!< Peripheral Initialized and ready for use */
124   HAL_USART_STATE_BUSY              = 0x02,    /*!< an internal process is ongoing */   
125   HAL_USART_STATE_BUSY_TX           = 0x12,    /*!< Data Transmission process is ongoing */ 
126   HAL_USART_STATE_BUSY_RX           = 0x22,    /*!< Data Reception process is ongoing */
127   HAL_USART_STATE_BUSY_TX_RX        = 0x32,    /*!< Data Transmission Reception process is ongoing */
128   HAL_USART_STATE_TIMEOUT           = 0x03,    /*!< Timeout state */
129   HAL_USART_STATE_ERROR             = 0x04     /*!< Error */      
130 }HAL_USART_StateTypeDef;
131 /**
132   * @}
133   */
134 /** @defgroup USART_Error_Definition  USART error definition
135   * @{
136   */
137 /** 
138   * @brief  HAL USART Error Code  definition
139   */ 
140
141 #define   HAL_USART_ERROR_NONE      ((uint32_t)0x00)    /*!< No error            */
142 #define   HAL_USART_ERROR_PE        ((uint32_t)0x01)    /*!< Parity error        */
143 #define   HAL_USART_ERROR_NE        ((uint32_t)0x02)    /*!< Noise error         */
144 #define   HAL_USART_ERROR_FE        ((uint32_t)0x04)    /*!< frame error         */
145 #define   HAL_USART_ERROR_ORE       ((uint32_t)0x08)    /*!< Overrun error       */
146 #define   HAL_USART_ERROR_DMA       ((uint32_t)0x10)    /*!< DMA transfer error  */
147
148 /**
149   * @}
150   */
151 /** @defgroup USART_Clock_SourceDefinition  USART clock source definition
152   * @{
153   */
154 /** 
155   * @brief  USART clock sources definitions
156   */
157 typedef enum
158 {
159   USART_CLOCKSOURCE_PCLK1      = 0x00,    /*!< PCLK1 clock source  */
160   USART_CLOCKSOURCE_PCLK2      = 0x01,    /*!< PCLK2 clock source  */
161   USART_CLOCKSOURCE_HSI        = 0x02,    /*!< HSI clock source    */
162   USART_CLOCKSOURCE_SYSCLK     = 0x04,    /*!< SYSCLK clock source */
163   USART_CLOCKSOURCE_LSE        = 0x08     /*!< LSE clock source     */
164 }USART_ClockSourceTypeDef;
165 /**
166   * @}
167   */
168 /** @defgroup USART_handle_Definition  Handle structure definition
169   * @{
170   */
171 /** 
172   * @brief  USART handle Structure definition  
173   */
174
175 typedef struct
176 {
177   USART_TypeDef                 *Instance;        /*!<  USART registers base address        */
178
179   USART_InitTypeDef             Init;             /*!<  Usart communication parameters      */
180   
181   uint8_t                       *pTxBuffPtr;      /*!<  Pointer to Usart Tx transfer Buffer */
182   
183   uint16_t                      TxXferSize;       /*!<  Usart Tx Transfer size              */
184   
185   __IO uint16_t                 TxXferCount;      /*!<  Usart Tx Transfer Counter           */
186   
187   uint8_t                       *pRxBuffPtr;      /*!<  Pointer to Usart Rx transfer Buffer */
188   
189   uint16_t                      RxXferSize;       /*!<  Usart Rx Transfer size              */
190   
191   __IO uint16_t                 RxXferCount;      /*!<  Usart Rx Transfer Counter           */
192
193   uint16_t                      Mask;             /* USART Rx RDR register mask             */  
194   
195   DMA_HandleTypeDef             *hdmatx;          /*!<  Usart Tx DMA Handle parameters      */
196     
197   DMA_HandleTypeDef             *hdmarx;          /*!<  Usart Rx DMA Handle parameters      */
198   
199   HAL_LockTypeDef                Lock;            /*!<  Locking object                      */
200   
201   __IO HAL_USART_StateTypeDef    State;           /*!<  Usart communication state           */
202   
203   __IO uint32_t                  ErrorCode;       /*!<  USART Error code                    */
204   
205 }USART_HandleTypeDef;
206 /**
207   * @}
208   */
209 /**
210   * @}
211   */
212
213 /* Exported constants --------------------------------------------------------*/
214 /** @defgroup USART_Exported_Constants USART Exported Constants
215   * @{
216   */
217
218 /** @defgroup USART_Stop_Bits USART stop bit definition
219   * @{
220   */
221 #define USART_STOPBITS_1                     ((uint32_t)0x0000)
222 #define USART_STOPBITS_0_5                   ((uint32_t)USART_CR2_STOP_0)
223 #define USART_STOPBITS_2                     ((uint32_t)USART_CR2_STOP_1)
224 #define USART_STOPBITS_1_5                   ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
225 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_STOPBITS_1) || \
226                                          ((STOPBITS) == USART_STOPBITS_0_5) || \
227                                          ((STOPBITS) == USART_STOPBITS_1_5) || \
228                                          ((STOPBITS) == USART_STOPBITS_2))
229 /**
230   * @}
231   */ 
232
233 /** @defgroup USART_Parity USART parity definition
234   * @{
235   */ 
236 #define USART_PARITY_NONE                    ((uint32_t)0x0000)
237 #define USART_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
238 #define USART_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 
239 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_PARITY_NONE) || \
240                                      ((PARITY) == USART_PARITY_EVEN) || \
241                                      ((PARITY) == USART_PARITY_ODD))
242 /**
243   * @}
244   */ 
245
246 /** @defgroup USART_Mode USART mode definition
247   * @{
248   */ 
249 #define USART_MODE_RX                        ((uint32_t)USART_CR1_RE)
250 #define USART_MODE_TX                        ((uint32_t)USART_CR1_TE)
251 #define USART_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
252 #define IS_USART_MODE(MODE)     (((MODE) == USART_MODE_RX) || \
253                                  ((MODE) == USART_MODE_TX) || \
254                                  ((MODE) == USART_MODE_TX_RX))
255 /**
256   * @}
257   */
258     
259 /** @defgroup USART_Clock USART clock activation definition
260   * @{
261   */ 
262 #define USART_CLOCK_DISABLE                 ((uint32_t)0x0000)
263 #define USART_CLOCK_ENABLE                  ((uint32_t)USART_CR2_CLKEN)
264 #define IS_USART_CLOCK(CLOCK)      (((CLOCK) == USART_CLOCK_DISABLE) || \
265                                    ((CLOCK) == USART_CLOCK_ENABLE))
266 /**
267   * @}
268   */ 
269
270 /** @defgroup USART_Clock_Polarity USART polarity level definition
271   * @{
272   */
273 #define USART_POLARITY_LOW                   ((uint32_t)0x0000)
274 #define USART_POLARITY_HIGH                  ((uint32_t)USART_CR2_CPOL)
275 #define IS_USART_POLARITY(CPOL) (((CPOL) == USART_POLARITY_LOW) || ((CPOL) == USART_POLARITY_HIGH))
276 /**
277   * @}
278   */ 
279
280 /** @defgroup USART_Clock_Phase USART clock phase definition
281   * @{
282   */
283 #define USART_PHASE_1EDGE                    ((uint32_t)0x0000)
284 #define USART_PHASE_2EDGE                    ((uint32_t)USART_CR2_CPHA)
285 #define IS_USART_PHASE(CPHA) (((CPHA) == USART_PHASE_1EDGE) || ((CPHA) == USART_PHASE_2EDGE))
286 /**
287   * @}
288   */
289
290 /** @defgroup USART_Last_Bit USART last bit activation definition
291   * @{
292   */
293 #define USART_LASTBIT_DISABLE                ((uint32_t)0x0000)
294 #define USART_LASTBIT_ENABLE                 ((uint32_t)USART_CR2_LBCL)
295 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LASTBIT_DISABLE) || \
296                                        ((LASTBIT) == USART_LASTBIT_ENABLE))
297 /**
298   * @}
299   */
300
301
302 /** @defgroup USART_Flags USART flag definitions
303   *        Elements values convention: 0xXXXX
304   *           - 0xXXXX  : Flag mask in the ISR register
305   * @{
306   */
307 #define USART_FLAG_REACK                     ((uint32_t)0x00400000)
308 #define USART_FLAG_TEACK                     ((uint32_t)0x00200000)  
309 #define USART_FLAG_BUSY                      ((uint32_t)0x00010000)
310 #define USART_FLAG_CTS                       ((uint32_t)0x00000400)
311 #define USART_FLAG_CTSIF                     ((uint32_t)0x00000200)
312 #define USART_FLAG_LBDF                      ((uint32_t)0x00000100)
313 #define USART_FLAG_TXE                       ((uint32_t)0x00000080)
314 #define USART_FLAG_TC                        ((uint32_t)0x00000040)
315 #define USART_FLAG_RXNE                      ((uint32_t)0x00000020)
316 #define USART_FLAG_IDLE                      ((uint32_t)0x00000010)
317 #define USART_FLAG_ORE                       ((uint32_t)0x00000008)
318 #define USART_FLAG_NE                        ((uint32_t)0x00000004)
319 #define USART_FLAG_FE                        ((uint32_t)0x00000002)
320 #define USART_FLAG_PE                        ((uint32_t)0x00000001)
321 /**
322   * @}
323   */
324
325 /** @defgroup USART_Interrupt_definition USART interrupt definition
326   *        Elements values convention: 0000ZZZZ0XXYYYYYb
327   *           - YYYYY  : Interrupt source position in the XX register (5bits)
328   *           - XX  : Interrupt source register (2bits)
329   *                 - 01: CR1 register
330   *                 - 10: CR2 register
331   *                 - 11: CR3 register
332   *           - ZZZZ  : Flag position in the ISR register(4bits)
333   * @{
334   */
335   
336 #define USART_IT_PE                          ((uint16_t)0x0028)
337 #define USART_IT_TXE                         ((uint16_t)0x0727)
338 #define USART_IT_TC                          ((uint16_t)0x0626)
339 #define USART_IT_RXNE                        ((uint16_t)0x0525)
340 #define USART_IT_IDLE                        ((uint16_t)0x0424)
341 #define USART_IT_ERR                         ((uint16_t)0x0060)
342
343 #define USART_IT_ORE                         ((uint16_t)0x0300)
344 #define USART_IT_NE                          ((uint16_t)0x0200)
345 #define USART_IT_FE                          ((uint16_t)0x0100)
346 /**
347   * @}
348   */
349
350 /** @defgroup USART_IT_CLEAR_Flags USART interrupt clear flags definition
351   * @{
352   */
353 #define USART_CLEAR_PEF                       USART_ICR_PECF            /*!< Parity Error Clear Flag */          
354 #define USART_CLEAR_FEF                       USART_ICR_FECF            /*!< Framing Error Clear Flag */         
355 #define USART_CLEAR_NEF                       USART_ICR_NCF             /*!< Noise detected Clear Flag */        
356 #define USART_CLEAR_OREF                      USART_ICR_ORECF           /*!< OverRun Error Clear Flag */         
357 #define USART_CLEAR_IDLEF                     USART_ICR_IDLECF          /*!< IDLE line detected Clear Flag */    
358 #define USART_CLEAR_TCF                       USART_ICR_TCCF            /*!< Transmission Complete Clear Flag */ 
359 #define USART_CLEAR_CTSF                      USART_ICR_CTSCF           /*!< CTS Interrupt Clear Flag */         
360 /**
361   * @}
362   */ 
363
364 /** @defgroup USART_Request_Parameters USART request parameter definition
365   * @{
366   */
367 #define USART_RXDATA_FLUSH_REQUEST        ((uint32_t)USART_RQR_RXFRQ)        /*!< Receive Data flush Request */ 
368 #define USART_TXDATA_FLUSH_REQUEST        ((uint32_t)USART_RQR_TXFRQ)        /*!< Transmit data flush Request */
369 #define IS_USART_REQUEST_PARAMETER(PARAM) (((PARAM) == USART_RXDATA_FLUSH_REQUEST) || \
370                                            ((PARAM) == USART_TXDATA_FLUSH_REQUEST))   
371 /**
372   * @}
373   */
374
375 /** @defgroup USART_Interruption_Mask USART interruption mask definition
376   * @{
377   */  
378 #define USART_IT_MASK                             ((uint16_t)0x001F)  
379 /**
380   * @}
381   */
382
383 /**
384   * @}
385   */
386   
387     
388 /* Exported macro ------------------------------------------------------------*/
389
390 /** @defgroup USART_Exported_Macros USART Exported Macros
391   * @{
392   */
393 /** @brief Reset USART handle state
394   * @param  __HANDLE__: specifies the USART Handle.
395   *         The Handle Instance which can be USART1 or USART2.
396   * @retval None
397   */
398 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__)  ((__HANDLE__)->State = HAL_USART_STATE_RESET)
399
400 /** @brief  Flush the USART Data registers
401   * @param  __HANDLE__: specifies the USART Handle.
402   */
403 #define __HAL_USART_FLUSH_DRREGISTER(__HANDLE__)  \
404   do{                \
405       SET_BIT((__HANDLE__)->Instance->RQR, USART_RXDATA_FLUSH_REQUEST); \
406       SET_BIT((__HANDLE__)->Instance->RQR, USART_TXDATA_FLUSH_REQUEST); \
407     } while(0)
408
409
410
411 /** @brief  Checks whether the specified USART flag is set or not.
412   * @param  __HANDLE__: specifies the USART Handle which can be USART1 or USART2.
413   * @param  __FLAG__: specifies the flag to check.
414   *        This parameter can be one of the following values:
415   *            @arg USART_FLAG_REACK: Receive enable ackowledge flag
416   *            @arg USART_FLAG_TEACK: Transmit enable ackowledge flag
417   *            @arg USART_FLAG_BUSY:  Busy flag                  
418   *            @arg USART_FLAG_CTS:   CTS Change flag         
419   *            @arg USART_FLAG_TXE:   Transmit data register empty flag
420   *            @arg USART_FLAG_TC:    Transmission Complete flag
421   *            @arg USART_FLAG_RXNE:  Receive data register not empty flag
422   *            @arg USART_FLAG_IDLE:  Idle Line detection flag
423   *            @arg USART_FLAG_ORE:   OverRun Error flag
424   *            @arg USART_FLAG_NE:    Noise Error flag
425   *            @arg USART_FLAG_FE:    Framing Error flag
426   *            @arg USART_FLAG_PE:    Parity Error flag
427   * @retval The new state of __FLAG__ (TRUE or FALSE).
428   */
429 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
430
431 /** @brief  Clears the specified USART pending flag.
432   * @param  __HANDLE__: specifies the USART Handle.
433   * @param  __FLAG__: specifies the flag to check.
434   *          This parameter can be any combination of the following values:
435   *            @arg USART_CLEAR_PEF
436   *            @arg USART_CLEAR_FEF
437   *            @arg USART_CLEAR_NEF
438   *            @arg USART_CLEAR_OREF
439   *            @arg USART_CLEAR_IDLEF
440   *            @arg USART_CLEAR_TCF
441   *            @arg USART_CLEAR_LBDF
442   *            @arg USART_CLEAR_CTSF
443   *            @arg USART_CLEAR_RTOF
444   *            @arg USART_CLEAR_EOBF
445   *            @arg USART_CLEAR_CMF
446   *            @arg USART_CLEAR_WUF
447   * @retval None
448   */
449 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = ~(__FLAG__))
450
451 /** @brief  Clear the USART PE pending flag.
452   * @param  __HANDLE__: specifies the UART Handle.
453   * @retval None
454   */
455 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG(__HANDLE__,USART_CLEAR_PEF)
456
457 /** @brief  Clear the USART FE pending flag.
458   * @param  __HANDLE__: specifies the UART Handle.
459   * @retval None
460   */
461 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG(__HANDLE__,USART_CLEAR_FEF)
462
463 /** @brief  Clear the UART NE pending flag.
464   * @param  __HANDLE__: specifies the UART Handle.
465   * @retval None
466   */
467 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__)  __HAL_USART_CLEAR_FLAG(__HANDLE__,USART_CLEAR_NEF)
468
469 /** @brief  Clear the UART ORE pending flag.
470   * @param  __HANDLE__: specifies the UART Handle.
471   * @retval None
472   */
473 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG(__HANDLE__,USART_CLEAR_OREF)
474
475 /** @brief  Clear the UART IDLE pending flag.
476   * @param  __HANDLE__: specifies the UART Handle.
477   * @retval None
478   */
479 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG(__HANDLE__,USART_CLEAR_IDLEF)
480
481 /** @brief  Enables the specified USART interrupt.
482   * @param  __HANDLE__: specifies the USART Handle which can be USART1 or USART2.
483   * @param  __INTERRUPT__: specifies the USART interrupt source to enable.
484   *          This parameter can be one of the following values:
485   *            @arg USART_IT_TXE:  Transmit Data Register empty interrupt
486   *            @arg USART_IT_TC:   Transmission complete interrupt
487   *            @arg USART_IT_RXNE: Receive Data register not empty interrupt
488   *            @arg USART_IT_IDLE: Idle line detection interrupt
489   *            @arg USART_IT_PE:   Parity Error interrupt
490   *            @arg USART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
491   * @retval None
492   */
493 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__)(((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 |= (1 << ((__INTERRUPT__) & USART_IT_MASK))): \
494                                                         ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 |= (1 << ((__INTERRUPT__) & USART_IT_MASK))): \
495                                                         ((__HANDLE__)->Instance->CR3 |= (1 << ((__INTERRUPT__) & USART_IT_MASK))))
496
497 /** @brief  Disables the specified USART interrupt.
498   * @param  __HANDLE__: specifies the USART Handle which can be USART1 or USART2.
499   * @param  __INTERRUPT__: specifies the USART interrupt source to disable.
500   *          This parameter can be one of the following values:
501   *            @arg USART_IT_TXE:  Transmit Data Register empty interrupt
502   *            @arg USART_IT_TC:   Transmission complete interrupt
503   *            @arg USART_IT_RXNE: Receive Data register not empty interrupt
504   *            @arg USART_IT_IDLE: Idle line detection interrupt
505   *            @arg USART_IT_PE:   Parity Error interrupt
506   *            @arg USART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
507   * @retval None
508   */
509 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & USART_IT_MASK))): \
510                                                         ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & USART_IT_MASK))): \
511                                                         ((__HANDLE__)->Instance->CR3 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & USART_IT_MASK))))
512
513 /** @brief  Checks whether the specified USART interrupt has occurred or not.
514   * @param  __HANDLE__: specifies the USART Handle which can be USART1 or USART2.
515   * @param  __IT__: specifies the USART interrupt source to check.
516   *          This parameter can be one of the following values:
517   *            @arg USART_IT_TXE: Transmit Data Register empty interrupt
518   *            @arg USART_IT_TC:  Transmission complete interrupt
519   *            @arg USART_IT_RXNE: Receive Data register not empty interrupt
520   *            @arg USART_IT_IDLE: Idle line detection interrupt
521   *            @arg USART_IT_ORE: OverRun Error interrupt
522   *            @arg USART_IT_NE: Noise Error interrupt
523   *            @arg USART_IT_FE: Framing Error interrupt
524   *            @arg USART_IT_PE: Parity Error interrupt
525   * @retval The new state of __IT__ (TRUE or FALSE).
526   */
527 #define __HAL_USART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08))) 
528
529 /** @brief  Checks whether the specified USART interrupt source is enabled.
530   * @param  __HANDLE__: specifies the USART Handle which can be USART1 or USART2.
531   * @param  __IT__: specifies the USART interrupt source to check.
532   *          This parameter can be one of the following values:
533   *            @arg USART_IT_TXE: Transmit Data Register empty interrupt
534   *            @arg USART_IT_TC:  Transmission complete interrupt
535   *            @arg USART_IT_RXNE: Receive Data register not empty interrupt
536   *            @arg USART_IT_IDLE: Idle line detection interrupt
537   *            @arg USART_IT_ORE: OverRun Error interrupt
538   *            @arg USART_IT_NE: Noise Error interrupt
539   *            @arg USART_IT_FE: Framing Error interrupt
540   *            @arg USART_IT_PE: Parity Error interrupt
541   * @retval The new state of __IT__ (TRUE or FALSE).
542   */
543 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5) == 2)? \
544                                                    (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << \
545                                                    (((uint16_t)(__IT__)) & USART_IT_MASK)))
546
547
548 /** @brief  Clears the specified USART ISR flag, in setting the proper ICR register flag.
549   * @param  __HANDLE__: specifies the USART Handle which can be USART1 or USART2.
550   * @param  __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
551   *                       to clear the corresponding interrupt
552   *          This parameter can be one of the following values:
553   *            @arg USART_CLEAR_PEF: Parity Error Clear Flag
554   *            @arg USART_CLEAR_FEF: Framing Error Clear Flag
555   *            @arg USART_CLEAR_NEF: Noise detected Clear Flag
556   *            @arg USART_CLEAR_OREF: OverRun Error Clear Flag
557   *            @arg USART_CLEAR_IDLEF: IDLE line detected Clear Flag
558   *            @arg USART_CLEAR_TCF: Transmission Complete Clear Flag 
559   *            @arg USART_CLEAR_CTSF: CTS Interrupt Clear Flag
560   * @retval None
561   */
562 #define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__)) 
563
564 /** @brief  Set a specific USART request flag.
565   * @param  __HANDLE__: specifies the USART Handle which can be USART1 or USART2.
566   * @param  __REQ__: specifies the request flag to set
567   *          This parameter can be one of the following values:
568   *            @arg USART_RXDATA_FLUSH_REQUEST: Receive Data flush Request 
569   *            @arg USART_TXDATA_FLUSH_REQUEST: Transmit data flush Request 
570   *
571   * @retval None
572   */ 
573 #define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
574
575 /** @brief  Enables the USART one bit sample method
576   * @param  __HANDLE__: specifies the USART Handle.
577   * @retval None
578   */
579 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
580
581 /** @brief  Disables the UART one bit sample method
582   * @param  __HANDLE__: specifies the UART Handle.
583   * @retval None
584   */
585 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
586
587 /** @brief  Enable USART
588   * @param  __HANDLE__: specifies the USART Handle.
589   *         The Handle Instance which can be USART1 or USART2.
590   * @retval None
591   */ 
592 #define __HAL_USART_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
593
594 /** @brief  Disable USART
595   * @param  __HANDLE__: specifies the USART Handle.
596   *         The Handle Instance which can be USART1 or USART2.
597   * @retval None
598   */ 
599 #define __HAL_USART_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
600   
601
602 /** @brief  Check USART Baud rate
603   * @param  BAUDRATE: Baudrate specified by the user
604   *         The maximum Baud Rate is derived from the maximum clock on L0 (i.e. 32 MHz) 
605   *         divided by the smallest oversampling used on the USART (i.e. 8) 
606   * @retval Test result (TRUE or FALSE).
607   */
608 #define IS_USART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 4000001)
609
610 /**
611   * @}
612   */
613       
614 /* Include USART HAL Extension module */
615 #include "stm32l0xx_hal_usart_ex.h"
616 /* Exported functions --------------------------------------------------------*/
617 /** @defgroup USART_Exported_Functions USART Exported Functions
618   * @{
619   */
620 /* Initialization/de-initialization functions  ********************************/
621 /** @defgroup USART_Exported_Functions_Group1 Initialization/de-initialization functions
622  *  @{
623  */
624 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
625 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
626 void HAL_USART_MspInit(USART_HandleTypeDef *husart);
627 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
628 /**
629   * @}
630   */
631 /* IO operation functions *****************************************************/
632 /** @defgroup USART_Exported_Functions_Group2 IO operation functions
633  *  @{
634  */
635 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
636 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
637 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
638 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
639 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
640 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData,  uint16_t Size);
641 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
642 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
643 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
644 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
645 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
646 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
647 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
648 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
649 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
650 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
651 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
652 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
653 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
654 /**
655   * @}
656   */
657 /* IO operation functions *****************************************************/
658 /** @defgroup USART_Exported_Functions_Group3 Peripheral State functions
659  *  @{
660  */
661 /* Peripheral State functions  ************************************************/
662 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
663 uint32_t               HAL_USART_GetError(USART_HandleTypeDef *husart);
664 /**
665   * @}
666   */
667 /**
668   * @}
669   */
670 /**
671   * @}
672   */ 
673 /**
674   * @}
675   */
676   
677 #ifdef __cplusplus
678 }
679 #endif
680
681 #endif /* __STM32L0xx_HAL_USART_H */
682
683 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
684