Subversion Repositories EngineBay2

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 28
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal_uart.h
3
  * @file    stm32l1xx_hal_uart.h
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @version V1.2.0
-
 
6
  * @date    01-July-2016
-
 
7
  * @brief   This file contains all the functions prototypes for the UART
5
  * @brief   Header file of UART HAL module.
8
  *          firmware library.
-
 
9
  ******************************************************************************
6
  ******************************************************************************
10
  * @attention
7
  * @attention
11
  *
8
  *
12
  * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
9
  * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
-
 
10
  * All rights reserved.</center></h2>
13
  *
11
  *
14
  * Redistribution and use in source and binary forms, with or without modification,
12
  * This software component is licensed by ST under BSD 3-Clause license,
15
  * are permitted provided that the following conditions are met:
13
  * the "License"; You may not use this file except in compliance with the
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.
14
  * License. You may obtain a copy of the License at:
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
15
  *                        opensource.org/licenses/BSD-3-Clause
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
  *
16
  *
36
  ******************************************************************************
17
  ******************************************************************************
37
  */
18
  */
38
 
19
 
39
/* Define to prevent recursive inclusion -------------------------------------*/
20
/* Define to prevent recursive inclusion -------------------------------------*/
40
#ifndef __STM32L1xx_HAL_UART_H
21
#ifndef __STM32L1xx_HAL_UART_H
41
#define __STM32L1xx_HAL_UART_H
22
#define __STM32L1xx_HAL_UART_H
42
 
23
 
43
#ifdef __cplusplus
24
#ifdef __cplusplus
44
 extern "C" {
25
extern "C" {
45
#endif
26
#endif
46
 
27
 
47
/* Includes ------------------------------------------------------------------*/
28
/* Includes ------------------------------------------------------------------*/
48
#include "stm32l1xx_hal_def.h"
29
#include "stm32l1xx_hal_def.h"
49
 
30
 
Line 51... Line 32...
51
  * @{
32
  * @{
52
  */
33
  */
53
 
34
 
54
/** @addtogroup UART
35
/** @addtogroup UART
55
  * @{
36
  * @{
56
  */
37
  */
57
 
38
 
58
/* Exported types ------------------------------------------------------------*/
39
/* Exported types ------------------------------------------------------------*/
59
/** @defgroup UART_Exported_Types UART Exported Types
40
/** @defgroup UART_Exported_Types UART Exported Types
60
  * @{
41
  * @{
61
  */
42
  */
62
 
-
 
63
 
43
 
64
/**
44
/**
65
  * @brief UART Init Structure definition
45
  * @brief UART Init Structure definition
66
  */
46
  */
67
typedef struct
47
typedef struct
68
{
48
{
69
  uint32_t BaudRate;                  /*!< This member configures the UART communication baud rate.
49
  uint32_t BaudRate;                  /*!< This member configures the UART communication baud rate.
70
                                           The baud rate is computed using the following formula:
50
                                           The baud rate is computed using the following formula:
71
                                           - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (huart->Init.BaudRate)))
51
                                           - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (huart->Init.BaudRate)))
72
                                           - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8 * (OVR8+1)) + 0.5
52
                                           - 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. */
53
                                           Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */
74
 
54
 
75
  uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
55
  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 */
56
                                           This parameter can be a value of @ref UART_Word_Length */
77
 
57
 
Line 82... Line 62...
82
                                           This parameter can be a value of @ref UART_Parity
62
                                           This parameter can be a value of @ref UART_Parity
83
                                           @note When parity is enabled, the computed parity is inserted
63
                                           @note When parity is enabled, the computed parity is inserted
84
                                                 at the MSB position of the transmitted data (9th bit when
64
                                                 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
65
                                                 the word length is set to 9 data bits; 8th bit when the
86
                                                 word length is set to 8 data bits). */
66
                                                 word length is set to 8 data bits). */
87
 
67
 
88
  uint32_t Mode;                      /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
68
  uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
89
                                           This parameter can be a value of @ref UART_Mode */
69
                                           This parameter can be a value of @ref UART_Mode */
90
 
70
 
91
  uint32_t HwFlowCtl;                 /*!< Specifies wether the hardware flow control mode is enabled
71
  uint32_t HwFlowCtl;                 /*!< Specifies whether the hardware flow control mode is enabled or disabled.
92
                                           or disabled.
-
 
93
                                           This parameter can be a value of @ref UART_Hardware_Flow_Control */
72
                                           This parameter can be a value of @ref UART_Hardware_Flow_Control */
94
 
73
 
95
  uint32_t OverSampling;              /*!< Specifies wether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
74
  uint32_t OverSampling;              /*!< Specifies whether 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 */
75
                                           This parameter can be a value of @ref UART_Over_Sampling */
97
}UART_InitTypeDef;
76
} UART_InitTypeDef;
98
 
77
 
99
/**
78
/**
100
  * @brief HAL UART State structures definition  
79
  * @brief HAL UART State structures definition
-
 
80
  * @note  HAL UART State value is a combination of 2 different substates: gState and RxState.
-
 
81
  *        - gState contains UART state information related to global Handle management
-
 
82
  *          and also information related to Tx operations.
-
 
83
  *          gState value coding follow below described bitmap :
-
 
84
  *          b7-b6  Error information
-
 
85
  *             00 : No Error
-
 
86
  *             01 : (Not Used)
-
 
87
  *             10 : Timeout
-
 
88
  *             11 : Error
-
 
89
  *          b5     Peripheral initialization status
-
 
90
  *             0  : Reset (Peripheral not initialized)
-
 
91
  *             1  : Init done (Peripheral not initialized. HAL UART Init function already called)
-
 
92
  *          b4-b3  (not used)
-
 
93
  *             xx : Should be set to 00
-
 
94
  *          b2     Intrinsic process state
-
 
95
  *             0  : Ready
-
 
96
  *             1  : Busy (Peripheral busy with some configuration or internal operations)
-
 
97
  *          b1     (not used)
-
 
98
  *             x  : Should be set to 0
-
 
99
  *          b0     Tx state
-
 
100
  *             0  : Ready (no Tx operation ongoing)
-
 
101
  *             1  : Busy (Tx operation ongoing)
-
 
102
  *        - RxState contains information related to Rx operations.
-
 
103
  *          RxState value coding follow below described bitmap :
-
 
104
  *          b7-b6  (not used)
-
 
105
  *             xx : Should be set to 00
-
 
106
  *          b5     Peripheral initialization status
-
 
107
  *             0  : Reset (Peripheral not initialized)
-
 
108
  *             1  : Init done (Peripheral not initialized)
-
 
109
  *          b4-b2  (not used)
-
 
110
  *            xxx : Should be set to 000
-
 
111
  *          b1     Rx state
-
 
112
  *             0  : Ready (no Rx operation ongoing)
-
 
113
  *             1  : Busy (Rx operation ongoing)
-
 
114
  *          b0     (not used)
-
 
115
  *             x  : Should be set to 0.
101
  */
116
  */
102
typedef enum
117
typedef enum
103
{
118
{
104
  HAL_UART_STATE_RESET             = 0x00,    /*!< Peripheral is not initialized                      */
119
  HAL_UART_STATE_RESET             = 0x00U,    /*!< Peripheral is not yet Initialized
-
 
120
                                                   Value is allowed for gState and RxState */
105
  HAL_UART_STATE_READY             = 0x01,    /*!< Peripheral Initialized and ready for use           */
121
  HAL_UART_STATE_READY             = 0x20U,    /*!< Peripheral Initialized and ready for use
-
 
122
                                                   Value is allowed for gState and RxState */
106
  HAL_UART_STATE_BUSY              = 0x02,    /*!< an internal process is ongoing                     */
123
  HAL_UART_STATE_BUSY              = 0x24U,    /*!< an internal process is ongoing
-
 
124
                                                   Value is allowed for gState only */
107
  HAL_UART_STATE_BUSY_TX           = 0x12,    /*!< Data Transmission process is ongoing               */
125
  HAL_UART_STATE_BUSY_TX           = 0x21U,    /*!< Data Transmission process is ongoing
-
 
126
                                                   Value is allowed for gState only */
108
  HAL_UART_STATE_BUSY_RX           = 0x22,    /*!< Data Reception process is ongoing                  */
127
  HAL_UART_STATE_BUSY_RX           = 0x22U,    /*!< Data Reception process is ongoing
-
 
128
                                                   Value is allowed for RxState only */
109
  HAL_UART_STATE_BUSY_TX_RX        = 0x32,    /*!< Data Transmission and Reception process is ongoing */
129
  HAL_UART_STATE_BUSY_TX_RX        = 0x23U,    /*!< Data Transmission and Reception process is ongoing
-
 
130
                                                   Not to be used for neither gState nor RxState.
-
 
131
                                                   Value is result of combination (Or) between gState and RxState values */
110
  HAL_UART_STATE_TIMEOUT           = 0x03,    /*!< Timeout state                                      */
132
  HAL_UART_STATE_TIMEOUT           = 0xA0U,    /*!< Timeout state
-
 
133
                                                   Value is allowed for gState only */
111
  HAL_UART_STATE_ERROR             = 0x04     /*!< Error                                              */
134
  HAL_UART_STATE_ERROR             = 0xE0U     /*!< Error
-
 
135
                                                   Value is allowed for gState only */
112
}HAL_UART_StateTypeDef;
136
} HAL_UART_StateTypeDef;
113
 
137
 
114
/**
138
/**
115
  * @brief  UART handle Structure definition  
139
  * @brief  UART handle Structure definition
116
  */  
140
  */
117
typedef struct
141
typedef struct __UART_HandleTypeDef
118
{
142
{
119
  USART_TypeDef                 *Instance;        /*!< UART registers base address        */
143
  USART_TypeDef                 *Instance;        /*!< UART registers base address        */
120
 
144
 
121
  UART_InitTypeDef              Init;             /*!< UART communication parameters      */
145
  UART_InitTypeDef              Init;             /*!< UART communication parameters      */
122
 
146
 
123
  uint8_t                       *pTxBuffPtr;      /*!< Pointer to UART Tx transfer Buffer */
147
  uint8_t                       *pTxBuffPtr;      /*!< Pointer to UART Tx transfer Buffer */
124
 
148
 
125
  uint16_t                      TxXferSize;       /*!< UART Tx Transfer size              */
149
  uint16_t                      TxXferSize;       /*!< UART Tx Transfer size              */
126
 
150
 
127
  uint16_t                      TxXferCount;      /*!< UART Tx Transfer Counter           */
151
  __IO uint16_t                 TxXferCount;      /*!< UART Tx Transfer Counter           */
128
 
152
 
129
  uint8_t                       *pRxBuffPtr;      /*!< Pointer to UART Rx transfer Buffer */
153
  uint8_t                       *pRxBuffPtr;      /*!< Pointer to UART Rx transfer Buffer */
130
 
154
 
131
  uint16_t                      RxXferSize;       /*!< UART Rx Transfer size              */
155
  uint16_t                      RxXferSize;       /*!< UART Rx Transfer size              */
132
 
156
 
133
  uint16_t                      RxXferCount;      /*!< UART Rx Transfer Counter           */  
157
  __IO uint16_t                 RxXferCount;      /*!< UART Rx Transfer Counter           */
134
 
158
 
135
  DMA_HandleTypeDef             *hdmatx;          /*!< UART Tx DMA Handle parameters      */
159
  DMA_HandleTypeDef             *hdmatx;          /*!< UART Tx DMA Handle parameters      */
136
 
160
 
137
  DMA_HandleTypeDef             *hdmarx;          /*!< UART Rx DMA Handle parameters      */
161
  DMA_HandleTypeDef             *hdmarx;          /*!< UART Rx DMA Handle parameters      */
138
 
162
 
139
  HAL_LockTypeDef               Lock;             /*!< Locking object                     */
163
  HAL_LockTypeDef               Lock;             /*!< Locking object                     */
140
 
164
 
-
 
165
  __IO HAL_UART_StateTypeDef    gState;           /*!< UART state information related to global Handle management
-
 
166
                                                       and also related to Tx operations.
-
 
167
                                                       This parameter can be a value of @ref HAL_UART_StateTypeDef */
-
 
168
 
141
  __IO HAL_UART_StateTypeDef    State;            /*!< UART communication state           */
169
  __IO HAL_UART_StateTypeDef    RxState;          /*!< UART state information related to Rx operations.
-
 
170
                                                       This parameter can be a value of @ref HAL_UART_StateTypeDef */
142
 
171
 
143
  __IO uint32_t                 ErrorCode;        /*!< UART Error code                    */
172
  __IO uint32_t                 ErrorCode;        /*!< UART Error code                    */
144
 
173
 
-
 
174
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
-
 
175
  void (* TxHalfCpltCallback)(struct __UART_HandleTypeDef *huart);        /*!< UART Tx Half Complete Callback        */
-
 
176
  void (* TxCpltCallback)(struct __UART_HandleTypeDef *huart);            /*!< UART Tx Complete Callback             */
-
 
177
  void (* RxHalfCpltCallback)(struct __UART_HandleTypeDef *huart);        /*!< UART Rx Half Complete Callback        */
-
 
178
  void (* RxCpltCallback)(struct __UART_HandleTypeDef *huart);            /*!< UART Rx Complete Callback             */
-
 
179
  void (* ErrorCallback)(struct __UART_HandleTypeDef *huart);             /*!< UART Error Callback                   */
-
 
180
  void (* AbortCpltCallback)(struct __UART_HandleTypeDef *huart);         /*!< UART Abort Complete Callback          */
-
 
181
  void (* AbortTransmitCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Transmit Complete Callback */
-
 
182
  void (* AbortReceiveCpltCallback)(struct __UART_HandleTypeDef *huart);  /*!< UART Abort Receive Complete Callback  */
-
 
183
  void (* WakeupCallback)(struct __UART_HandleTypeDef *huart);            /*!< UART Wakeup Callback                  */
-
 
184
 
-
 
185
  void (* MspInitCallback)(struct __UART_HandleTypeDef *huart);           /*!< UART Msp Init callback                */
-
 
186
  void (* MspDeInitCallback)(struct __UART_HandleTypeDef *huart);         /*!< UART Msp DeInit callback              */
-
 
187
#endif  /* USE_HAL_UART_REGISTER_CALLBACKS */
-
 
188
 
145
}UART_HandleTypeDef;
189
} UART_HandleTypeDef;
-
 
190
 
-
 
191
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
-
 
192
/**
-
 
193
  * @brief  HAL UART Callback ID enumeration definition
-
 
194
  */
-
 
195
typedef enum
-
 
196
{
-
 
197
  HAL_UART_TX_HALFCOMPLETE_CB_ID         = 0x00U,    /*!< UART Tx Half Complete Callback ID        */
-
 
198
  HAL_UART_TX_COMPLETE_CB_ID             = 0x01U,    /*!< UART Tx Complete Callback ID             */
-
 
199
  HAL_UART_RX_HALFCOMPLETE_CB_ID         = 0x02U,    /*!< UART Rx Half Complete Callback ID        */
-
 
200
  HAL_UART_RX_COMPLETE_CB_ID             = 0x03U,    /*!< UART Rx Complete Callback ID             */
-
 
201
  HAL_UART_ERROR_CB_ID                   = 0x04U,    /*!< UART Error Callback ID                   */
-
 
202
  HAL_UART_ABORT_COMPLETE_CB_ID          = 0x05U,    /*!< UART Abort Complete Callback ID          */
-
 
203
  HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x06U,    /*!< UART Abort Transmit Complete Callback ID */
-
 
204
  HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID  = 0x07U,    /*!< UART Abort Receive Complete Callback ID  */
-
 
205
  HAL_UART_WAKEUP_CB_ID                  = 0x08U,    /*!< UART Wakeup Callback ID                  */
-
 
206
 
-
 
207
  HAL_UART_MSPINIT_CB_ID                 = 0x0BU,    /*!< UART MspInit callback ID                 */
-
 
208
  HAL_UART_MSPDEINIT_CB_ID               = 0x0CU     /*!< UART MspDeInit callback ID               */
-
 
209
 
-
 
210
} HAL_UART_CallbackIDTypeDef;
-
 
211
 
-
 
212
/**
-
 
213
  * @brief  HAL UART Callback pointer definition
-
 
214
  */
-
 
215
typedef  void (*pUART_CallbackTypeDef)(UART_HandleTypeDef *huart);  /*!< pointer to an UART callback function */
-
 
216
 
-
 
217
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
146
 
218
 
147
/**
219
/**
148
  * @}
220
  * @}
149
  */
221
  */
150
 
222
 
151
/* Exported constants --------------------------------------------------------*/
223
/* Exported constants --------------------------------------------------------*/
152
/** @defgroup UART_Exported_Constants UART Exported constants
224
/** @defgroup UART_Exported_Constants UART Exported Constants
153
  * @{
225
  * @{
154
  */
226
  */
155
 
227
 
156
/** @defgroup UART_Error_Codes   UART Error Codes
228
/** @defgroup UART_Error_Code UART Error Code
157
  * @{
229
  * @{
158
  */
230
  */
159
 
-
 
160
#define HAL_UART_ERROR_NONE      ((uint32_t)0x00)    /*!< No error            */
231
#define HAL_UART_ERROR_NONE              0x00000000U   /*!< No error            */
161
#define HAL_UART_ERROR_PE        ((uint32_t)0x01)    /*!< Parity error        */
232
#define HAL_UART_ERROR_PE                0x00000001U   /*!< Parity error        */
162
#define HAL_UART_ERROR_NE        ((uint32_t)0x02)    /*!< Noise error         */
233
#define HAL_UART_ERROR_NE                0x00000002U   /*!< Noise error         */
163
#define HAL_UART_ERROR_FE        ((uint32_t)0x04)    /*!< frame error         */
234
#define HAL_UART_ERROR_FE                0x00000004U   /*!< Frame error         */
164
#define HAL_UART_ERROR_ORE       ((uint32_t)0x08)    /*!< Overrun error       */
235
#define HAL_UART_ERROR_ORE               0x00000008U   /*!< Overrun error       */
165
#define HAL_UART_ERROR_DMA       ((uint32_t)0x10)    /*!< DMA transfer error  */
236
#define HAL_UART_ERROR_DMA               0x00000010U   /*!< DMA transfer error  */
166
 
-
 
-
 
237
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
-
 
238
#define  HAL_UART_ERROR_INVALID_CALLBACK 0x00000020U   /*!< Invalid Callback error  */
-
 
239
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
167
/**
240
/**
168
  * @}
241
  * @}
169
  */
242
  */
170
 
243
 
171
/** @defgroup UART_Word_Length   UART Word Length
244
/** @defgroup UART_Word_Length UART Word Length
172
  * @{
245
  * @{
173
  */
246
  */
174
#define UART_WORDLENGTH_8B                  ((uint32_t)0x00000000)
247
#define UART_WORDLENGTH_8B                  0x00000000U
175
#define UART_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)
248
#define UART_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)
176
/**
249
/**
177
  * @}
250
  * @}
178
  */
251
  */
179
 
252
 
180
/** @defgroup UART_Stop_Bits   UART Number of Stop Bits
253
/** @defgroup UART_Stop_Bits UART Number of Stop Bits
181
  * @{
254
  * @{
182
  */
255
  */
183
#define UART_STOPBITS_1                     ((uint32_t)0x00000000)
256
#define UART_STOPBITS_1                     0x00000000U
184
#define UART_STOPBITS_2                     ((uint32_t)USART_CR2_STOP_1)
257
#define UART_STOPBITS_2                     ((uint32_t)USART_CR2_STOP_1)
185
/**
258
/**
186
  * @}
259
  * @}
187
  */
260
  */
188
 
261
 
189
/** @defgroup UART_Parity  UART Parity
262
/** @defgroup UART_Parity UART Parity
190
  * @{
263
  * @{
191
  */
264
  */
192
#define UART_PARITY_NONE                    ((uint32_t)0x00000000)
265
#define UART_PARITY_NONE                    0x00000000U
193
#define UART_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
266
#define UART_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
194
#define UART_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 
267
#define UART_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
195
/**
268
/**
196
  * @}
269
  * @}
197
  */
270
  */
198
 
271
 
199
/** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
272
/** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
200
  * @{
273
  * @{
201
  */
274
  */
202
#define UART_HWCONTROL_NONE                  ((uint32_t)0x00000000)
275
#define UART_HWCONTROL_NONE                  0x00000000U
203
#define UART_HWCONTROL_RTS                   ((uint32_t)USART_CR3_RTSE)
276
#define UART_HWCONTROL_RTS                   ((uint32_t)USART_CR3_RTSE)
204
#define UART_HWCONTROL_CTS                   ((uint32_t)USART_CR3_CTSE)
277
#define UART_HWCONTROL_CTS                   ((uint32_t)USART_CR3_CTSE)
205
#define UART_HWCONTROL_RTS_CTS               ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
278
#define UART_HWCONTROL_RTS_CTS               ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
206
/**
279
/**
207
  * @}
280
  * @}
208
  */
281
  */
209
 
282
 
210
/** @defgroup UART_Mode UART Transfer Mode
283
/** @defgroup UART_Mode UART Transfer Mode
211
  * @{
284
  * @{
212
  */
285
  */
213
#define UART_MODE_RX                        ((uint32_t)USART_CR1_RE)
286
#define UART_MODE_RX                        ((uint32_t)USART_CR1_RE)
214
#define UART_MODE_TX                        ((uint32_t)USART_CR1_TE)
287
#define UART_MODE_TX                        ((uint32_t)USART_CR1_TE)
215
#define UART_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
288
#define UART_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE | USART_CR1_RE))
216
 
-
 
217
/**
289
/**
218
  * @}
290
  * @}
219
  */
291
  */
220
   
292
 
221
 /** @defgroup UART_State  UART State
293
/** @defgroup UART_State UART State
222
  * @{
294
  * @{
223
  */
295
  */
224
#define UART_STATE_DISABLE                  ((uint32_t)0x00000000)
296
#define UART_STATE_DISABLE                  0x00000000U
225
#define UART_STATE_ENABLE                   ((uint32_t)USART_CR1_UE)
297
#define UART_STATE_ENABLE                   ((uint32_t)USART_CR1_UE)
226
/**
298
/**
227
  * @}
299
  * @}
228
  */
300
  */
229
 
301
 
230
/** @defgroup UART_Over_Sampling UART Over Sampling
302
/** @defgroup UART_Over_Sampling UART Over Sampling
231
  * @{
303
  * @{
232
  */
304
  */
233
#define UART_OVERSAMPLING_16                    ((uint32_t)0x00000000)
305
#define UART_OVERSAMPLING_16                    0x00000000U
234
#define UART_OVERSAMPLING_8                     ((uint32_t)USART_CR1_OVER8)
306
#define UART_OVERSAMPLING_8                     ((uint32_t)USART_CR1_OVER8)
235
/**
307
/**
236
  * @}
308
  * @}
237
  */
309
  */
238
 
310
 
239
/** @defgroup UART_LIN_Break_Detection_Length  UART LIN Break Detection Length
311
/** @defgroup UART_LIN_Break_Detection_Length  UART LIN Break Detection Length
240
  * @{
312
  * @{
241
  */  
313
  */
242
#define UART_LINBREAKDETECTLENGTH_10B      ((uint32_t)0x00000000)
314
#define UART_LINBREAKDETECTLENGTH_10B      0x00000000U
243
#define UART_LINBREAKDETECTLENGTH_11B      ((uint32_t)USART_CR2_LBDL)
315
#define UART_LINBREAKDETECTLENGTH_11B      ((uint32_t)USART_CR2_LBDL)
244
/**
316
/**
245
  * @}
317
  * @}
246
  */
318
  */
247
 
319
 
248
/** @defgroup UART_WakeUp_functions UART Wakeup Functions
320
/** @defgroup UART_WakeUp_functions  UART Wakeup Functions
249
  * @{
321
  * @{
250
  */
322
  */
251
#define UART_WAKEUPMETHOD_IDLELINE                ((uint32_t)0x00000000)
323
#define UART_WAKEUPMETHOD_IDLELINE                0x00000000U
252
#define UART_WAKEUPMETHOD_ADDRESSMARK             ((uint32_t)USART_CR1_WAKE)
324
#define UART_WAKEUPMETHOD_ADDRESSMARK             ((uint32_t)USART_CR1_WAKE)
253
/**
325
/**
254
  * @}
326
  * @}
255
  */
327
  */
256
 
328
 
Line 275... Line 347...
275
 
347
 
276
/** @defgroup UART_Interrupt_definition  UART Interrupt Definitions
348
/** @defgroup UART_Interrupt_definition  UART Interrupt Definitions
277
  *        Elements values convention: 0xY000XXXX
349
  *        Elements values convention: 0xY000XXXX
278
  *           - XXXX  : Interrupt mask (16 bits) in the Y register
350
  *           - XXXX  : Interrupt mask (16 bits) in the Y register
279
  *           - Y  : Interrupt source register (2bits)
351
  *           - Y  : Interrupt source register (2bits)
280
  *                 - 0001: CR1 register
352
  *                   - 0001: CR1 register
281
  *                 - 0010: CR2 register
353
  *                   - 0010: CR2 register
282
  *                 - 0011: CR3 register
354
  *                   - 0011: CR3 register
283
  *
-
 
284
  * @{
355
  * @{
285
  */
356
  */
286
 
-
 
287
#define UART_IT_PE                       ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_PEIE))
-
 
288
#define UART_IT_TXE                      ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_TXEIE))
-
 
289
#define UART_IT_TC                       ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_TCIE))
-
 
290
#define UART_IT_RXNE                     ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_RXNEIE))
-
 
291
#define UART_IT_IDLE                     ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_IDLEIE))
-
 
292
 
357
 
-
 
358
#define UART_IT_PE                       ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
293
#define UART_IT_LBD                      ((uint32_t)(UART_CR2_REG_INDEX << 28 | USART_CR2_LBDIE))
359
#define UART_IT_TXE                      ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
-
 
360
#define UART_IT_TC                       ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
-
 
361
#define UART_IT_RXNE                     ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
-
 
362
#define UART_IT_IDLE                     ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
294
 
363
 
295
#define UART_IT_CTS                      ((uint32_t)(UART_CR3_REG_INDEX << 28 | USART_CR3_CTSIE))
364
#define UART_IT_LBD                      ((uint32_t)(UART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
296
#define UART_IT_ERR                      ((uint32_t)(UART_CR3_REG_INDEX << 28 | USART_CR3_EIE))
-
 
297
 
365
 
-
 
366
#define UART_IT_CTS                      ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
-
 
367
#define UART_IT_ERR                      ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_EIE))
298
/**
368
/**
299
  * @}
369
  * @}
300
  */
370
  */
301
 
371
 
302
/**
372
/**
303
  * @}
373
  * @}
304
  */
374
  */
305
 
375
 
306
   
-
 
307
/* Exported macro ------------------------------------------------------------*/
376
/* Exported macro ------------------------------------------------------------*/
308
/** @defgroup UART_Exported_Macros UART Exported Macros
377
/** @defgroup UART_Exported_Macros UART Exported Macros
309
  * @{
378
  * @{
310
  */
379
  */
311
 
380
 
312
 
-
 
313
/** @brief Reset UART handle state
381
/** @brief Reset UART handle gstate & RxState
314
  * @param  __HANDLE__: specifies the UART Handle.
382
  * @param  __HANDLE__ specifies the UART Handle.
315
  *         UART Handle selects the USARTx or UARTy peripheral
383
  *         UART Handle selects the USARTx or UARTy peripheral
316
  *         (USART,UART availability and x,y values depending on device).
384
  *         (USART,UART availability and x,y values depending on device).
317
  * @retval None
385
  * @retval None
318
  */
386
  */
-
 
387
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
319
#define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_UART_STATE_RESET)
388
#define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
-
 
389
                                                       (__HANDLE__)->gState = HAL_UART_STATE_RESET;      \
-
 
390
                                                       (__HANDLE__)->RxState = HAL_UART_STATE_RESET;     \
-
 
391
                                                       (__HANDLE__)->MspInitCallback = NULL;             \
-
 
392
                                                       (__HANDLE__)->MspDeInitCallback = NULL;           \
-
 
393
                                                     } while(0U)
-
 
394
#else
-
 
395
#define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
-
 
396
                                                       (__HANDLE__)->gState = HAL_UART_STATE_RESET;      \
-
 
397
                                                       (__HANDLE__)->RxState = HAL_UART_STATE_RESET;     \
-
 
398
                                                     } while(0U)
-
 
399
#endif /*USE_HAL_UART_REGISTER_CALLBACKS */
320
 
400
 
321
/** @brief  Flush the UART DR register
401
/** @brief  Flushes the UART DR register
322
  * @param  __HANDLE__: specifies the UART Handle.
402
  * @param  __HANDLE__ specifies the UART Handle.
323
  *         UART Handle selects the USARTx or UARTy peripheral
403
  *         UART Handle selects the USARTx or UARTy peripheral
324
  *         (USART,UART availability and x,y values depending on device).
404
  *         (USART,UART availability and x,y values depending on device).
325
  */
405
  */
326
#define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
406
#define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
327
 
407
 
328
/** @brief  Check whether the specified UART flag is set or not.
408
/** @brief  Checks whether the specified UART flag is set or not.
329
  * @param  __HANDLE__: specifies the UART Handle.
409
  * @param  __HANDLE__ specifies the UART Handle.
330
  *         UART Handle selects the USARTx or UARTy peripheral
410
  *         UART Handle selects the USARTx or UARTy peripheral
331
  *         (USART,UART availability and x,y values depending on device).
411
  *         (USART,UART availability and x,y values depending on device).
332
  * @param  __FLAG__: specifies the flag to check.
412
  * @param  __FLAG__ specifies the flag to check.
333
  *        This parameter can be one of the following values:
413
  *        This parameter can be one of the following values:
334
  *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5)
414
  *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5)
335
  *            @arg UART_FLAG_LBD:  LIN Break detection flag
415
  *            @arg UART_FLAG_LBD:  LIN Break detection flag
336
  *            @arg UART_FLAG_TXE:  Transmit data register empty flag
416
  *            @arg UART_FLAG_TXE:  Transmit data register empty flag
337
  *            @arg UART_FLAG_TC:   Transmission Complete flag
417
  *            @arg UART_FLAG_TC:   Transmission Complete flag
338
  *            @arg UART_FLAG_RXNE: Receive data register not empty flag
418
  *            @arg UART_FLAG_RXNE: Receive data register not empty flag
339
  *            @arg UART_FLAG_IDLE: Idle Line detection flag
419
  *            @arg UART_FLAG_IDLE: Idle Line detection flag
340
  *            @arg UART_FLAG_ORE:  OverRun Error flag
420
  *            @arg UART_FLAG_ORE:  Overrun Error flag
341
  *            @arg UART_FLAG_NE:   Noise Error flag
421
  *            @arg UART_FLAG_NE:   Noise Error flag
342
  *            @arg UART_FLAG_FE:   Framing Error flag
422
  *            @arg UART_FLAG_FE:   Framing Error flag
343
  *            @arg UART_FLAG_PE:   Parity Error flag
423
  *            @arg UART_FLAG_PE:   Parity Error flag
344
  * @retval The new state of __FLAG__ (TRUE or FALSE).
424
  * @retval The new state of __FLAG__ (TRUE or FALSE).
345
  */
425
  */
346
#define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))   
426
#define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
347
 
427
 
348
/** @brief  Clear the specified UART pending flag.
428
/** @brief  Clears the specified UART pending flag.
349
  * @param  __HANDLE__: specifies the UART Handle.
429
  * @param  __HANDLE__ specifies the UART Handle.
350
  *         UART Handle selects the USARTx or UARTy peripheral
430
  *         UART Handle selects the USARTx or UARTy peripheral
351
  *         (USART,UART availability and x,y values depending on device).
431
  *         (USART,UART availability and x,y values depending on device).
352
  * @param  __FLAG__: specifies the flag to check.
432
  * @param  __FLAG__ specifies the flag to check.
353
  *          This parameter can be any combination of the following values:
433
  *          This parameter can be any combination of the following values:
354
  *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5).
434
  *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5).
355
  *            @arg UART_FLAG_LBD:  LIN Break detection flag.
435
  *            @arg UART_FLAG_LBD:  LIN Break detection flag.
356
  *            @arg UART_FLAG_TC:   Transmission Complete flag.
436
  *            @arg UART_FLAG_TC:   Transmission Complete flag.
357
  *            @arg UART_FLAG_RXNE: Receive data register not empty flag.
437
  *            @arg UART_FLAG_RXNE: Receive data register not empty flag.
358
  *  
438
  *
359
  * @note   PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
439
  * @note   PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun
360
  *          error) and IDLE (Idle line detected) flags are cleared by software
440
  *          error) and IDLE (Idle line detected) flags are cleared by software
361
  *          sequence: a read operation to USART_SR register followed by a read
441
  *          sequence: a read operation to USART_SR register followed by a read
362
  *          operation to USART_DR register.
442
  *          operation to USART_DR register.
363
  * @note   RXNE flag can be also cleared by a read to the USART_DR register.
443
  * @note   RXNE flag can be also cleared by a read to the USART_DR register.
364
  * @note   TC flag can be also cleared by software sequence: a read operation to
444
  * @note   TC flag can be also cleared by software sequence: a read operation to
365
  *          USART_SR register followed by a write operation to USART_DR register.
445
  *          USART_SR register followed by a write operation to USART_DR register.
366
  * @note   TXE flag is cleared only by a write to the USART_DR register.
446
  * @note   TXE flag is cleared only by a write to the USART_DR register.
367
  *  
447
  *
368
  * @retval None
448
  * @retval None
369
  */
449
  */
370
#define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
450
#define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
371
 
451
 
372
/** @brief  Clear the UART PE pending flag.
452
/** @brief  Clears the UART PE pending flag.
373
  * @param  __HANDLE__: specifies the UART Handle.
453
  * @param  __HANDLE__ specifies the UART Handle.
374
  *         UART Handle selects the USARTx or UARTy peripheral
454
  *         UART Handle selects the USARTx or UARTy peripheral
375
  *         (USART,UART availability and x,y values depending on device).
455
  *         (USART,UART availability and x,y values depending on device).
376
  * @retval None
456
  * @retval None
377
  */
457
  */
378
#define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) \
458
#define __HAL_UART_CLEAR_PEFLAG(__HANDLE__)     \
379
do{                                         \
459
  do{                                           \
380
  __IO uint32_t tmpreg;                     \
460
    __IO uint32_t tmpreg = 0x00U;               \
381
  tmpreg = (__HANDLE__)->Instance->SR;      \
461
    tmpreg = (__HANDLE__)->Instance->SR;        \
382
  tmpreg = (__HANDLE__)->Instance->DR;      \
462
    tmpreg = (__HANDLE__)->Instance->DR;        \
383
  UNUSED(tmpreg);                           \
463
    UNUSED(tmpreg);                             \
384
}while(0)
464
  } while(0U)
385
 
-
 
386
 
-
 
387
 
465
 
388
/** @brief  Clear the UART FE pending flag.
466
/** @brief  Clears the UART FE pending flag.
389
  * @param  __HANDLE__: specifies the UART Handle.
467
  * @param  __HANDLE__ specifies the UART Handle.
390
  *         UART Handle selects the USARTx or UARTy peripheral
468
  *         UART Handle selects the USARTx or UARTy peripheral
391
  *         (USART,UART availability and x,y values depending on device).
469
  *         (USART,UART availability and x,y values depending on device).
392
  * @retval None
470
  * @retval None
393
  */
471
  */
394
#define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
472
#define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
395
 
473
 
396
/** @brief  Clear the UART NE pending flag.
474
/** @brief  Clears the UART NE pending flag.
397
  * @param  __HANDLE__: specifies the UART Handle.
475
  * @param  __HANDLE__ specifies the UART Handle.
398
  *         UART Handle selects the USARTx or UARTy peripheral
476
  *         UART Handle selects the USARTx or UARTy peripheral
399
  *         (USART,UART availability and x,y values depending on device).
477
  *         (USART,UART availability and x,y values depending on device).
400
  * @retval None
478
  * @retval None
401
  */
479
  */
402
#define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
480
#define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
403
 
481
 
404
/** @brief  Clear the UART ORE pending flag.
482
/** @brief  Clears the UART ORE pending flag.
405
  * @param  __HANDLE__: specifies the UART Handle.
483
  * @param  __HANDLE__ specifies the UART Handle.
406
  *         UART Handle selects the USARTx or UARTy peripheral
484
  *         UART Handle selects the USARTx or UARTy peripheral
407
  *         (USART,UART availability and x,y values depending on device).
485
  *         (USART,UART availability and x,y values depending on device).
408
  * @retval None
486
  * @retval None
409
  */
487
  */
410
#define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
488
#define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
411
 
489
 
412
/** @brief  Clear the UART IDLE pending flag.
490
/** @brief  Clears the UART IDLE pending flag.
413
  * @param  __HANDLE__: specifies the UART Handle.
491
  * @param  __HANDLE__ specifies the UART Handle.
414
  *         UART Handle selects the USARTx or UARTy peripheral
492
  *         UART Handle selects the USARTx or UARTy peripheral
415
  *         (USART,UART availability and x,y values depending on device).
493
  *         (USART,UART availability and x,y values depending on device).
416
  * @retval None
494
  * @retval None
417
  */
495
  */
418
#define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
496
#define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
419
                                                 
-
 
-
 
497
 
420
/** @brief  Enable the specified UART interrupt.
498
/** @brief  Enable the specified UART interrupt.
421
  * @param  __HANDLE__: specifies the UART Handle.
499
  * @param  __HANDLE__ specifies the UART Handle.
422
  *         UART Handle selects the USARTx or UARTy peripheral
500
  *         UART Handle selects the USARTx or UARTy peripheral
423
  *         (USART,UART availability and x,y values depending on device).
501
  *         (USART,UART availability and x,y values depending on device).
424
  * @param  __INTERRUPT__: specifies the UART interrupt source to enable.
502
  * @param  __INTERRUPT__ specifies the UART interrupt source to enable.
425
  *          This parameter can be one of the following values:
503
  *          This parameter can be one of the following values:
426
  *            @arg UART_IT_CTS:  CTS change interrupt
504
  *            @arg UART_IT_CTS:  CTS change interrupt
427
  *            @arg UART_IT_LBD:  LIN Break detection interrupt
505
  *            @arg UART_IT_LBD:  LIN Break detection interrupt
428
  *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
506
  *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
429
  *            @arg UART_IT_TC:   Transmission complete interrupt
507
  *            @arg UART_IT_TC:   Transmission complete interrupt
Line 431... Line 509...
431
  *            @arg UART_IT_IDLE: Idle line detection interrupt
509
  *            @arg UART_IT_IDLE: Idle line detection interrupt
432
  *            @arg UART_IT_PE:   Parity Error interrupt
510
  *            @arg UART_IT_PE:   Parity Error interrupt
433
  *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
511
  *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
434
  * @retval None
512
  * @retval None
435
  */
513
  */
436
#define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \
514
#define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \
437
                                                           (((__INTERRUPT__) >> 28) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |=  ((__INTERRUPT__) & UART_IT_MASK)): \
515
                                                           (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & UART_IT_MASK)): \
438
                                                           ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))
516
                                                           ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))
439
 
517
 
440
 
-
 
441
/** @brief  Disable the specified UART interrupt.
518
/** @brief  Disable the specified UART interrupt.
442
  * @param  __HANDLE__: specifies the UART Handle.
519
  * @param  __HANDLE__ specifies the UART Handle.
443
  *         UART Handle selects the USARTx or UARTy peripheral
520
  *         UART Handle selects the USARTx or UARTy peripheral
444
  *         (USART,UART availability and x,y values depending on device).
521
  *         (USART,UART availability and x,y values depending on device).
445
  * @param  __INTERRUPT__: specifies the UART interrupt source to disable.
522
  * @param  __INTERRUPT__ specifies the UART interrupt source to disable.
446
  *          This parameter can be one of the following values:
523
  *          This parameter can be one of the following values:
447
  *            @arg UART_IT_CTS:  CTS change interrupt
524
  *            @arg UART_IT_CTS:  CTS change interrupt
448
  *            @arg UART_IT_LBD:  LIN Break detection interrupt
525
  *            @arg UART_IT_LBD:  LIN Break detection interrupt
449
  *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
526
  *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
450
  *            @arg UART_IT_TC:   Transmission complete interrupt
527
  *            @arg UART_IT_TC:   Transmission complete interrupt
Line 452... Line 529...
452
  *            @arg UART_IT_IDLE: Idle line detection interrupt
529
  *            @arg UART_IT_IDLE: Idle line detection interrupt
453
  *            @arg UART_IT_PE:   Parity Error interrupt
530
  *            @arg UART_IT_PE:   Parity Error interrupt
454
  *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
531
  *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
455
  * @retval None
532
  * @retval None
456
  */
533
  */
457
#define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
534
#define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
458
                                                           (((__INTERRUPT__) >> 28) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
535
                                                           (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
459
                                                           ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK)))
536
                                                           ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK)))
460
   
537
 
461
/** @brief  Check whether the specified UART interrupt has occurred or not.
538
/** @brief  Checks whether the specified UART interrupt source is enabled or not.
462
  * @param  __HANDLE__: specifies the UART Handle.
539
  * @param  __HANDLE__ specifies the UART Handle.
463
  *         UART Handle selects the USARTx or UARTy peripheral
540
  *         UART Handle selects the USARTx or UARTy peripheral
464
  *         (USART,UART availability and x,y values depending on device).
541
  *         (USART,UART availability and x,y values depending on device).
465
  * @param  __IT__: specifies the UART interrupt source to check.
542
  * @param  __IT__ specifies the UART interrupt source to check.
466
  *          This parameter can be one of the following values:
543
  *          This parameter can be one of the following values:
467
  *            @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
544
  *            @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
468
  *            @arg UART_IT_LBD: LIN Break detection interrupt
545
  *            @arg UART_IT_LBD: LIN Break detection interrupt
469
  *            @arg UART_IT_TXE: Transmit Data Register empty interrupt
546
  *            @arg UART_IT_TXE: Transmit Data Register empty interrupt
470
  *            @arg UART_IT_TC:  Transmission complete interrupt
547
  *            @arg UART_IT_TC:  Transmission complete interrupt
471
  *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
548
  *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
472
  *            @arg UART_IT_IDLE: Idle line detection interrupt
549
  *            @arg UART_IT_IDLE: Idle line detection interrupt
473
  *            @arg UART_IT_ERR: Error interrupt
550
  *            @arg UART_IT_ERR: Error interrupt
474
  * @retval The new state of __IT__ (TRUE or FALSE).
551
  * @retval The new state of __IT__ (TRUE or FALSE).
475
  */
552
  */
476
#define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28) == UART_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28) == UART_CR2_REG_INDEX)? \
553
#define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == UART_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == UART_CR2_REG_INDEX)? \
477
                                                      (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK))
554
                                                      (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK))
478
 
555
 
479
/** @brief  macros to enables or disables the UART's one bit sampling method
-
 
480
  * @param  __HANDLE__: specifies the UART Handle.  
-
 
481
  *         This parameter can be USARTx with x: 1, 2 or 3, or UARTy with y:4 or 5 to select the USART or
-
 
482
  *         UART peripheral (availability depending on device for UARTy).
-
 
483
  * @retval None
-
 
484
  */    
-
 
485
#define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
-
 
486
#define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
-
 
487
 
-
 
488
/** @brief  Enable CTS flow control
556
/** @brief  Enable CTS flow control
489
  *         This macro allows to enable CTS hardware flow control for a given UART instance,
557
  * @note   This macro allows to enable CTS hardware flow control for a given UART instance,
490
  *         without need to call HAL_UART_Init() function.
558
  *         without need to call HAL_UART_Init() function.
491
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
559
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
492
  * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
560
  * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
493
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
561
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
494
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
562
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
495
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
563
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
496
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).                                                                                                                  
564
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
497
  * @param  __HANDLE__: specifies the UART Handle.
565
  * @param  __HANDLE__ specifies the UART Handle.
498
  *         This parameter can be any USARTx (supporting the HW Flow control feature).
566
  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
499
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
567
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
500
  * @retval None
568
  * @retval None
501
  */
569
  */
502
#define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__)        \
570
#define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__)        \
503
  do{                                                      \
571
  do{                                                      \
504
    SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE);  \
572
    SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE);  \
505
    (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE;        \
573
    (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE;        \
506
  } while(0)
574
  } while(0U)
507
 
575
 
508
/** @brief  Disable CTS flow control
576
/** @brief  Disable CTS flow control
509
  *         This macro allows to disable CTS hardware flow control for a given UART instance,
577
  * @note   This macro allows to disable CTS hardware flow control for a given UART instance,
510
  *         without need to call HAL_UART_Init() function.
578
  *         without need to call HAL_UART_Init() function.
511
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
579
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
512
  * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
580
  * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
513
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
581
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
514
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
582
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
515
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
583
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
516
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
584
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
517
  * @param  __HANDLE__: specifies the UART Handle.
585
  * @param  __HANDLE__ specifies the UART Handle.
518
  *         This parameter can be any USARTx (supporting the HW Flow control feature).
586
  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
519
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
587
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
520
  * @retval None
588
  * @retval None
521
  */
589
  */
522
#define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__)        \
590
#define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__)        \
523
  do{                                                       \
591
  do{                                                       \
524
    CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
592
    CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
525
    (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE);      \
593
    (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE);      \
526
  } while(0)
594
  } while(0U)
527
 
595
 
528
/** @brief  Enable RTS flow control
596
/** @brief  Enable RTS flow control
529
  *         This macro allows to enable RTS hardware flow control for a given UART instance,
597
  *         This macro allows to enable RTS hardware flow control for a given UART instance,
530
  *         without need to call HAL_UART_Init() function.
598
  *         without need to call HAL_UART_Init() function.
531
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
599
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
532
  * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
600
  * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
533
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
601
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
534
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
602
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
535
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
603
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
536
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
604
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
537
  * @param  __HANDLE__: specifies the UART Handle.
605
  * @param  __HANDLE__ specifies the UART Handle.
538
  *         This parameter can be any USARTx (supporting the HW Flow control feature).
606
  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
539
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
607
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
540
  * @retval None
608
  * @retval None
541
  */
609
  */
542
#define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__)       \
610
#define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__)       \
543
  do{                                                     \
611
  do{                                                     \
544
    SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
612
    SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
545
    (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE;       \
613
    (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE;       \
546
  } while(0)
614
  } while(0U)
547
 
615
 
548
/** @brief  Disable RTS flow control
616
/** @brief  Disable RTS flow control
549
  *         This macro allows to disable RTS hardware flow control for a given UART instance,
617
  *         This macro allows to disable RTS hardware flow control for a given UART instance,
550
  *         without need to call HAL_UART_Init() function.
618
  *         without need to call HAL_UART_Init() function.
551
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
619
  *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
552
  * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
620
  * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
553
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
621
  *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
554
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
622
  *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
555
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
623
  *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
556
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
624
  *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
557
  * @param  __HANDLE__: specifies the UART Handle.
625
  * @param  __HANDLE__ specifies the UART Handle.
558
  *         This parameter can be any USARTx (supporting the HW Flow control feature).
626
  *         The Handle Instance can be any USARTx (supporting the HW Flow control feature).
559
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
627
  *         It is used to select the USART peripheral (USART availability and x value depending on device).
560
  * @retval None
628
  * @retval None
561
  */
629
  */
562
#define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__)       \
630
#define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__)       \
563
  do{                                                      \
631
  do{                                                      \
564
    CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
632
    CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
565
    (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE);     \
633
    (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE);     \
566
  } while(0)
634
  } while(0U)
567
 
635
 
-
 
636
/** @brief  Macro to enable the UART's one bit sample method
-
 
637
  * @param  __HANDLE__ specifies the UART Handle.
-
 
638
  * @retval None
-
 
639
  */
-
 
640
#define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
-
 
641
 
-
 
642
/** @brief  Macro to disable the UART's one bit sample method
-
 
643
  * @param  __HANDLE__ specifies the UART Handle.
-
 
644
  * @retval None
-
 
645
  */
-
 
646
#define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
568
 
647
 
569
/** @brief  Enable UART
648
/** @brief  Enable UART
570
  * @param  __HANDLE__: specifies the UART Handle.
649
  * @param  __HANDLE__ specifies the UART Handle.
571
  *         UART Handle selects the USARTx or UARTy peripheral
-
 
572
  *         (USART,UART availability and x,y values depending on device).
-
 
573
  * @retval None
650
  * @retval None
574
  */
651
  */
575
#define __HAL_UART_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
652
#define __HAL_UART_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
576
 
653
 
577
/** @brief  Disable UART
654
/** @brief  Disable UART
578
  *         UART Handle selects the USARTx or UARTy peripheral
655
  * @param  __HANDLE__ specifies the UART Handle.
579
  *         (USART,UART availability and x,y values depending on device).
-
 
580
  * @retval None
656
  * @retval None
581
  */
657
  */
582
#define __HAL_UART_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
658
#define __HAL_UART_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
583
 
-
 
584
/**
-
 
585
  * @}
-
 
586
  */
-
 
587
 
-
 
588
 
-
 
589
/* Private macros --------------------------------------------------------*/
-
 
590
/** @defgroup UART_Private_Macros   UART Private Macros
-
 
591
  * @{
-
 
592
  */
-
 
593
 
-
 
594
#define UART_CR1_REG_INDEX               1    
-
 
595
#define UART_CR2_REG_INDEX               2    
-
 
596
#define UART_CR3_REG_INDEX               3    
-
 
597
 
-
 
598
#define UART_DIV_SAMPLING16(_PCLK_, _BAUD_)         (((_PCLK_)*25)/(4*(_BAUD_)))
-
 
599
#define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_)     (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100)
-
 
600
#define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_)     (((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100)) * 16 + 50) / 100)
-
 
601
/* UART BRR = mantissa + overflow + fraction
-
 
602
            = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0F) */
-
 
603
#define UART_BRR_SAMPLING16(_PCLK_, _BAUD_)            (((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4) + \
-
 
604
                                                        (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0xF0)) + \
-
 
605
                                                        (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0F))
-
 
606
#define UART_DIV_SAMPLING8(_PCLK_, _BAUD_)          (((_PCLK_)*25)/(2*(_BAUD_)))
-
 
607
#define UART_DIVMANT_SAMPLING8(_PCLK_, _BAUD_)      (UART_DIV_SAMPLING8((_PCLK_), (_BAUD_))/100)
-
 
608
#define UART_DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_)         (((UART_DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100)) * 8 + 50) / 100)
-
 
609
/* UART BRR = mantissa + overflow + fraction
-
 
610
            = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07) */
-
 
611
#define UART_BRR_SAMPLING8(_PCLK_, _BAUD_)             (((UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4) + \
-
 
612
                                                        ((UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0xF8) << 1)) + \
-
 
613
                                                        (UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x07))
-
 
614
#define IS_UART_WORD_LENGTH(LENGTH)       (((LENGTH) == UART_WORDLENGTH_8B) || \
-
 
615
                                           ((LENGTH) == UART_WORDLENGTH_9B))
-
 
616
#define IS_UART_LIN_WORD_LENGTH(LENGTH)   ((LENGTH) == UART_WORDLENGTH_8B)
-
 
617
 
-
 
618
#define IS_UART_STOPBITS(STOPBITS)     (((STOPBITS) == UART_STOPBITS_1) || \
-
 
619
                                        ((STOPBITS) == UART_STOPBITS_2))
-
 
620
 
-
 
621
#define IS_UART_PARITY(PARITY)         (((PARITY) == UART_PARITY_NONE) || \
-
 
622
                                        ((PARITY) == UART_PARITY_EVEN) || \
-
 
623
                                        ((PARITY) == UART_PARITY_ODD))
-
 
624
 
-
 
625
#define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
-
 
626
                                       (((CONTROL) == UART_HWCONTROL_NONE) || \
-
 
627
                                        ((CONTROL) == UART_HWCONTROL_RTS) || \
-
 
628
                                        ((CONTROL) == UART_HWCONTROL_CTS) || \
-
 
629
                                        ((CONTROL) == UART_HWCONTROL_RTS_CTS))
-
 
630
 
-
 
631
#define IS_UART_MODE(MODE)             ((((MODE) & (~((uint32_t)UART_MODE_TX_RX))) == 0x00) && \
-
 
632
                                        ((MODE) != (uint32_t)0x00000000))
-
 
633
 
-
 
634
#define IS_UART_STATE(STATE)           (((STATE) == UART_STATE_DISABLE) || \
-
 
635
                                        ((STATE) == UART_STATE_ENABLE))
-
 
636
 
-
 
637
#define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
-
 
638
                                        ((SAMPLING) == UART_OVERSAMPLING_8))
-
 
639
#define IS_UART_LIN_OVERSAMPLING(SAMPLING)  ((SAMPLING) == UART_OVERSAMPLING_16)
-
 
640
 
-
 
641
#define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
-
 
642
                                                 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
-
 
643
 
-
 
644
#define IS_UART_WAKEUPMETHOD(WAKEUP)   (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
-
 
645
                                        ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
-
 
646
 
-
 
647
 
-
 
648
/** Check UART Baud rate
-
 
649
  *         __BAUDRATE__: Baudrate specified by the user
-
 
650
  *         The maximum Baud Rate is derived from the maximum clock on APB (i.e. 32 MHz)
-
 
651
  *         divided by the smallest oversampling used on the USART (i.e. 8)
-
 
652
  * Return : TRUE or FALSE
-
 
653
  */
-
 
654
#define IS_UART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 4000001)
-
 
655
 
-
 
656
/** Check UART Node Address
-
 
657
  *         __ADDRESS__: UART Node address specified by the user
-
 
658
  *         UART Node address is used in Multi processor communication for wakeup
-
 
659
  *         with address mark detection.
-
 
660
  *         This parameter must be a number between Min_Data = 0 and Max_Data = 15
-
 
661
  * Return : TRUE or FALSE
-
 
662
  */
-
 
663
#define IS_UART_ADDRESS(__ADDRESS__) ((__ADDRESS__) <= 0xF)
-
 
664
 
-
 
665
/** UART interruptions flag mask
-
 
666
  */
-
 
667
#define UART_IT_MASK  ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
-
 
668
                                  USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE )
-
 
669
 
-
 
670
/**
659
/**
671
  * @}
660
  * @}
672
  */
661
  */
673
 
662
 
674
/* Exported functions --------------------------------------------------------*/
663
/* Exported functions --------------------------------------------------------*/
675
 
-
 
676
/** @addtogroup UART_Exported_Functions UART Exported Functions
664
/** @addtogroup UART_Exported_Functions
677
  * @{
665
  * @{
678
  */
666
  */
679
 
667
 
680
/** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
668
/** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
681
  * @{
669
  * @{
682
  */
670
  */
683
 
671
 
684
/* Initialization and de-initialization functions  ****************************/
672
/* Initialization/de-initialization functions  **********************************/
685
HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
673
HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
686
HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
674
HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
687
HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
675
HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
688
HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
676
HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
689
HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
677
HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart);
690
void HAL_UART_MspInit(UART_HandleTypeDef *huart);
678
void HAL_UART_MspInit(UART_HandleTypeDef *huart);
691
void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
679
void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
692
 
680
 
-
 
681
/* Callbacks Register/UnRegister functions  ***********************************/
-
 
682
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
-
 
683
HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID, pUART_CallbackTypeDef pCallback);
-
 
684
HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID);
-
 
685
#endif /* USE_HAL_UART_REGISTER_CALLBACKS */
-
 
686
 
693
/**
687
/**
694
  * @}
688
  * @}
695
  */
689
  */
696
 
690
 
697
/** @addtogroup UART_Exported_Functions_Group2 IO operation functions
691
/** @addtogroup UART_Exported_Functions_Group2 IO operation functions
698
  * @{
692
  * @{
699
  */
693
  */
700
 
694
 
701
/* IO operation functions *****************************************************/
695
/* IO operation functions *******************************************************/
702
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
696
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
703
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
697
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
704
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
698
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
705
HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
699
HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
706
HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
700
HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
707
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
701
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
708
HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
702
HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
709
HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
703
HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
710
HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
704
HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
-
 
705
/* Transfer Abort functions */
-
 
706
HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart);
-
 
707
HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);
-
 
708
HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);
-
 
709
HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart);
-
 
710
HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart);
-
 
711
HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart);
-
 
712
 
711
void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
713
void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
712
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
714
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
713
void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
715
void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
714
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
716
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
715
void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
717
void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
716
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
718
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
-
 
719
void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart);
-
 
720
void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart);
-
 
721
void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart);
717
 
722
 
718
/**
723
/**
719
  * @}
724
  * @}
720
  */
725
  */
721
 
726
 
722
/** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions
727
/** @addtogroup UART_Exported_Functions_Group3
723
  * @{
728
  * @{
724
  */
729
  */
725
 
-
 
726
/* Peripheral Control functions  ************************************************/
730
/* Peripheral Control functions  ************************************************/
727
HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
731
HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
728
HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
732
HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
729
HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart);
733
HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart);
730
HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
734
HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
731
HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
735
HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
732
 
-
 
733
/**
736
/**
734
  * @}
737
  * @}
735
  */
738
  */
736
 
739
 
737
/** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Errors functions
740
/** @addtogroup UART_Exported_Functions_Group4
738
  * @{
741
  * @{
739
  */
742
  */
740
 
-
 
741
/* Peripheral State and Errors functions  **************************************************/
743
/* Peripheral State functions  **************************************************/
742
HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
744
HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
743
uint32_t              HAL_UART_GetError(UART_HandleTypeDef *huart);
745
uint32_t              HAL_UART_GetError(UART_HandleTypeDef *huart);
-
 
746
/**
-
 
747
  * @}
-
 
748
  */
-
 
749
 
-
 
750
/**
-
 
751
  * @}
-
 
752
  */
-
 
753
/* Private types -------------------------------------------------------------*/
-
 
754
/* Private variables ---------------------------------------------------------*/
-
 
755
/* Private constants ---------------------------------------------------------*/
-
 
756
/** @defgroup UART_Private_Constants UART Private Constants
-
 
757
  * @{
-
 
758
  */
-
 
759
/** @brief UART interruptions flag mask
-
 
760
  *
-
 
761
  */
-
 
762
#define UART_IT_MASK                     0x0000FFFFU
-
 
763
 
-
 
764
#define UART_CR1_REG_INDEX               1U
-
 
765
#define UART_CR2_REG_INDEX               2U
-
 
766
#define UART_CR3_REG_INDEX               3U
-
 
767
/**
-
 
768
  * @}
-
 
769
  */
-
 
770
 
-
 
771
/* Private macros ------------------------------------------------------------*/
-
 
772
/** @defgroup UART_Private_Macros UART Private Macros
-
 
773
  * @{
-
 
774
  */
-
 
775
#define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
-
 
776
                                     ((LENGTH) == UART_WORDLENGTH_9B))
-
 
777
#define IS_UART_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B))
-
 
778
#define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
-
 
779
                                    ((STOPBITS) == UART_STOPBITS_2))
-
 
780
#define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
-
 
781
                                ((PARITY) == UART_PARITY_EVEN) || \
-
 
782
                                ((PARITY) == UART_PARITY_ODD))
-
 
783
#define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
-
 
784
                              (((CONTROL) == UART_HWCONTROL_NONE) || \
-
 
785
                               ((CONTROL) == UART_HWCONTROL_RTS) || \
-
 
786
                               ((CONTROL) == UART_HWCONTROL_CTS) || \
-
 
787
                               ((CONTROL) == UART_HWCONTROL_RTS_CTS))
-
 
788
#define IS_UART_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00U))
-
 
789
#define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
-
 
790
                              ((STATE) == UART_STATE_ENABLE))
-
 
791
#define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
-
 
792
                                        ((SAMPLING) == UART_OVERSAMPLING_8))
-
 
793
#define IS_UART_LIN_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16))
-
 
794
#define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
-
 
795
                                                 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
-
 
796
#define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
-
 
797
                                      ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
-
 
798
#define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) <= 4000000U)
-
 
799
#define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0x0FU)
-
 
800
 
-
 
801
#define UART_DIV_SAMPLING16(_PCLK_, _BAUD_)            (((_PCLK_)*25U)/(4U*(_BAUD_)))
-
 
802
#define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_)        (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100U)
-
 
803
#define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_)        ((((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100U)) * 16U) + 50U) / 100U)
-
 
804
/* UART BRR = mantissa + overflow + fraction
-
 
805
            = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0FU) */
-
 
806
#define UART_BRR_SAMPLING16(_PCLK_, _BAUD_)            (((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4U) + \
-
 
807
                                                        (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0xF0U)) + \
-
 
808
                                                        (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0FU))
-
 
809
 
-
 
810
#define UART_DIV_SAMPLING8(_PCLK_, _BAUD_)             (((_PCLK_)*25U)/(2U*(_BAUD_)))
-
 
811
#define UART_DIVMANT_SAMPLING8(_PCLK_, _BAUD_)         (UART_DIV_SAMPLING8((_PCLK_), (_BAUD_))/100U)
-
 
812
#define UART_DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_)         ((((UART_DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100U)) * 8U) + 50U) / 100U)
-
 
813
/* UART BRR = mantissa + overflow + fraction
-
 
814
            = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07U) */
-
 
815
#define UART_BRR_SAMPLING8(_PCLK_, _BAUD_)             (((UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4U) + \
-
 
816
                                                        ((UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0xF8U) << 1U)) + \
-
 
817
                                                        (UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x07U))
744
 
818
 
745
/**
819
/**
746
  * @}
820
  * @}
747
  */
821
  */
748
 
822
 
-
 
823
/* Private functions ---------------------------------------------------------*/
-
 
824
/** @defgroup UART_Private_Functions UART Private Functions
-
 
825
  * @{
-
 
826
  */
-
 
827
 
749
/**
828
/**
750
  * @}
829
  * @}
751
  */
830
  */
752
 
831
 
753
/**
832
/**
754
  * @}
833
  * @}
755
  */
834
  */
756
 
835
 
757
/**
836
/**
758
  * @}
837
  * @}
759
  */
838
  */
760
 
839