提交 | 用户 | age
|
bfc108
|
1 |
/**
|
Q |
2 |
******************************************************************************
|
|
3 |
* @file stm32f0xx_hal_usart.h
|
|
4 |
* @author MCD Application Team
|
|
5 |
* @brief Header file of USART HAL module.
|
|
6 |
******************************************************************************
|
|
7 |
* @attention
|
|
8 |
*
|
|
9 |
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
|
10 |
*
|
|
11 |
* Redistribution and use in source and binary forms, with or without modification,
|
|
12 |
* are permitted provided that the following conditions are met:
|
|
13 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
14 |
* this list of conditions and the following disclaimer.
|
|
15 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
16 |
* this list of conditions and the following disclaimer in the documentation
|
|
17 |
* and/or other materials provided with the distribution.
|
|
18 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
19 |
* may be used to endorse or promote products derived from this software
|
|
20 |
* without specific prior written permission.
|
|
21 |
*
|
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
23 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
24 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
25 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
26 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
27 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
28 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
29 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
30 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
31 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32 |
*
|
|
33 |
******************************************************************************
|
|
34 |
*/
|
|
35 |
|
|
36 |
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
37 |
#ifndef __STM32F0xx_HAL_USART_H
|
|
38 |
#define __STM32F0xx_HAL_USART_H
|
|
39 |
|
|
40 |
#ifdef __cplusplus
|
|
41 |
extern "C" {
|
|
42 |
#endif
|
|
43 |
|
|
44 |
/* Includes ------------------------------------------------------------------*/
|
|
45 |
#include "stm32f0xx_hal_def.h"
|
|
46 |
|
|
47 |
/** @addtogroup STM32F0xx_HAL_Driver
|
|
48 |
* @{
|
|
49 |
*/
|
|
50 |
|
|
51 |
/** @addtogroup USART
|
|
52 |
* @{
|
|
53 |
*/
|
|
54 |
|
|
55 |
/* Exported types ------------------------------------------------------------*/
|
|
56 |
/** @defgroup USART_Exported_Types USART Exported Types
|
|
57 |
* @{
|
|
58 |
*/
|
|
59 |
|
|
60 |
/**
|
|
61 |
* @brief USART Init Structure definition
|
|
62 |
*/
|
|
63 |
typedef struct
|
|
64 |
{
|
|
65 |
uint32_t BaudRate; /*!< This member configures the Usart communication baud rate.
|
|
66 |
The baud rate is computed using the following formula:
|
|
67 |
Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate))). */
|
|
68 |
|
|
69 |
uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
|
|
70 |
This parameter can be a value of @ref USARTEx_Word_Length. */
|
|
71 |
|
|
72 |
uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
|
|
73 |
This parameter can be a value of @ref USART_Stop_Bits. */
|
|
74 |
|
|
75 |
uint32_t Parity; /*!< Specifies the parity mode.
|
|
76 |
This parameter can be a value of @ref USART_Parity
|
|
77 |
@note When parity is enabled, the computed parity is inserted
|
|
78 |
at the MSB position of the transmitted data (9th bit when
|
|
79 |
the word length is set to 9 data bits; 8th bit when the
|
|
80 |
word length is set to 8 data bits). */
|
|
81 |
|
|
82 |
uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
|
|
83 |
This parameter can be a value of @ref USART_Mode. */
|
|
84 |
|
|
85 |
uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
|
|
86 |
This parameter can be a value of @ref USART_Clock_Polarity. */
|
|
87 |
|
|
88 |
uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
|
|
89 |
This parameter can be a value of @ref USART_Clock_Phase. */
|
|
90 |
|
|
91 |
uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
|
|
92 |
data bit (MSB) has to be output on the SCLK pin in synchronous mode.
|
|
93 |
This parameter can be a value of @ref USART_Last_Bit. */
|
|
94 |
}USART_InitTypeDef;
|
|
95 |
|
|
96 |
/**
|
|
97 |
* @brief HAL USART State structures definition
|
|
98 |
*/
|
|
99 |
typedef enum
|
|
100 |
{
|
|
101 |
HAL_USART_STATE_RESET = 0x00U, /*!< Peripheral is not initialized */
|
|
102 |
HAL_USART_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
|
|
103 |
HAL_USART_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
|
|
104 |
HAL_USART_STATE_BUSY_TX = 0x12U, /*!< Data Transmission process is ongoing */
|
|
105 |
HAL_USART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
|
|
106 |
HAL_USART_STATE_BUSY_TX_RX = 0x32U, /*!< Data Transmission Reception process is ongoing */
|
|
107 |
HAL_USART_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
|
|
108 |
HAL_USART_STATE_ERROR = 0x04U /*!< Error */
|
|
109 |
}HAL_USART_StateTypeDef;
|
|
110 |
|
|
111 |
/**
|
|
112 |
* @brief USART clock sources definitions
|
|
113 |
*/
|
|
114 |
typedef enum
|
|
115 |
{
|
|
116 |
USART_CLOCKSOURCE_PCLK1 = 0x00U, /*!< PCLK1 clock source */
|
|
117 |
USART_CLOCKSOURCE_HSI = 0x02U, /*!< HSI clock source */
|
|
118 |
USART_CLOCKSOURCE_SYSCLK = 0x04U, /*!< SYSCLK clock source */
|
|
119 |
USART_CLOCKSOURCE_LSE = 0x08U, /*!< LSE clock source */
|
|
120 |
USART_CLOCKSOURCE_UNDEFINED = 0x10U /*!< Undefined clock source */
|
|
121 |
}USART_ClockSourceTypeDef;
|
|
122 |
|
|
123 |
|
|
124 |
/**
|
|
125 |
* @brief USART handle Structure definition
|
|
126 |
*/
|
|
127 |
typedef struct
|
|
128 |
{
|
|
129 |
USART_TypeDef *Instance; /*!< USART registers base address */
|
|
130 |
|
|
131 |
USART_InitTypeDef Init; /*!< USART communication parameters */
|
|
132 |
|
|
133 |
uint8_t *pTxBuffPtr; /*!< Pointer to USART Tx transfer Buffer */
|
|
134 |
|
|
135 |
uint16_t TxXferSize; /*!< USART Tx Transfer size */
|
|
136 |
|
|
137 |
__IO uint16_t TxXferCount; /*!< USART Tx Transfer Counter */
|
|
138 |
|
|
139 |
uint8_t *pRxBuffPtr; /*!< Pointer to USART Rx transfer Buffer */
|
|
140 |
|
|
141 |
uint16_t RxXferSize; /*!< USART Rx Transfer size */
|
|
142 |
|
|
143 |
__IO uint16_t RxXferCount; /*!< USART Rx Transfer Counter */
|
|
144 |
|
|
145 |
uint16_t Mask; /*!< USART Rx RDR register mask */
|
|
146 |
|
|
147 |
DMA_HandleTypeDef *hdmatx; /*!< USART Tx DMA Handle parameters */
|
|
148 |
|
|
149 |
DMA_HandleTypeDef *hdmarx; /*!< USART Rx DMA Handle parameters */
|
|
150 |
|
|
151 |
HAL_LockTypeDef Lock; /*!< Locking object */
|
|
152 |
|
|
153 |
__IO HAL_USART_StateTypeDef State; /*!< USART communication state */
|
|
154 |
|
|
155 |
__IO uint32_t ErrorCode; /*!< USART Error code */
|
|
156 |
|
|
157 |
}USART_HandleTypeDef;
|
|
158 |
|
|
159 |
/**
|
|
160 |
* @}
|
|
161 |
*/
|
|
162 |
|
|
163 |
/* Exported constants --------------------------------------------------------*/
|
|
164 |
/** @defgroup USART_Exported_Constants USART Exported Constants
|
|
165 |
* @{
|
|
166 |
*/
|
|
167 |
|
|
168 |
/** @defgroup USART_Error USART Error
|
|
169 |
* @{
|
|
170 |
*/
|
|
171 |
#define HAL_USART_ERROR_NONE (0x00000000U) /*!< No error */
|
|
172 |
#define HAL_USART_ERROR_PE (0x00000001U) /*!< Parity error */
|
|
173 |
#define HAL_USART_ERROR_NE (0x00000002U) /*!< Noise error */
|
|
174 |
#define HAL_USART_ERROR_FE (0x00000004U) /*!< frame error */
|
|
175 |
#define HAL_USART_ERROR_ORE (0x00000008U) /*!< Overrun error */
|
|
176 |
#define HAL_USART_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
|
|
177 |
/**
|
|
178 |
* @}
|
|
179 |
*/
|
|
180 |
|
|
181 |
/** @defgroup USART_Stop_Bits USART Number of Stop Bits
|
|
182 |
* @{
|
|
183 |
*/
|
|
184 |
#ifdef USART_SMARTCARD_SUPPORT
|
|
185 |
#define USART_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0) /*!< USART frame with 0.5 stop bit */
|
|
186 |
#define USART_STOPBITS_1 (0x00000000U) /*!< USART frame with 1 stop bit */
|
|
187 |
#define USART_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1)) /*!< USART frame with 1.5 stop bits */
|
|
188 |
#define USART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1) /*!< USART frame with 2 stop bits */
|
|
189 |
#else
|
|
190 |
#define USART_STOPBITS_1 (0x00000000U) /*!< USART frame with 1 stop bit */
|
|
191 |
#define USART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1) /*!< USART frame with 2 stop bits */
|
|
192 |
#endif
|
|
193 |
/**
|
|
194 |
* @}
|
|
195 |
*/
|
|
196 |
|
|
197 |
/** @defgroup USART_Parity USART Parity
|
|
198 |
* @{
|
|
199 |
*/
|
|
200 |
#define USART_PARITY_NONE (0x00000000U) /*!< No parity */
|
|
201 |
#define USART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) /*!< Even parity */
|
|
202 |
#define USART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) /*!< Odd parity */
|
|
203 |
/**
|
|
204 |
* @}
|
|
205 |
*/
|
|
206 |
|
|
207 |
/** @defgroup USART_Mode USART Mode
|
|
208 |
* @{
|
|
209 |
*/
|
|
210 |
#define USART_MODE_RX ((uint32_t)USART_CR1_RE) /*!< RX mode */
|
|
211 |
#define USART_MODE_TX ((uint32_t)USART_CR1_TE) /*!< TX mode */
|
|
212 |
#define USART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) /*!< RX and TX mode */
|
|
213 |
/**
|
|
214 |
* @}
|
|
215 |
*/
|
|
216 |
|
|
217 |
/** @defgroup USART_Clock USART Clock
|
|
218 |
* @{
|
|
219 |
*/
|
|
220 |
#define USART_CLOCK_DISABLE (0x00000000U) /*!< USART clock disable */
|
|
221 |
#define USART_CLOCK_ENABLE ((uint32_t)USART_CR2_CLKEN) /*!< USART clock enable */
|
|
222 |
/**
|
|
223 |
* @}
|
|
224 |
*/
|
|
225 |
|
|
226 |
/** @defgroup USART_Clock_Polarity USART Clock Polarity
|
|
227 |
* @{
|
|
228 |
*/
|
|
229 |
#define USART_POLARITY_LOW (0x00000000U) /*!< USART Clock signal is steady Low */
|
|
230 |
#define USART_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL) /*!< USART Clock signal is steady High */
|
|
231 |
/**
|
|
232 |
* @}
|
|
233 |
*/
|
|
234 |
|
|
235 |
/** @defgroup USART_Clock_Phase USART Clock Phase
|
|
236 |
* @{
|
|
237 |
*/
|
|
238 |
#define USART_PHASE_1EDGE (0x00000000U) /*!< USART frame phase on first clock transition */
|
|
239 |
#define USART_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA) /*!< USART frame phase on second clock transition */
|
|
240 |
/**
|
|
241 |
* @}
|
|
242 |
*/
|
|
243 |
|
|
244 |
/** @defgroup USART_Last_Bit USART Last Bit
|
|
245 |
* @{
|
|
246 |
*/
|
|
247 |
#define USART_LASTBIT_DISABLE (0x00000000U) /*!< USART frame last data bit clock pulse not output to SCLK pin */
|
|
248 |
#define USART_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL) /*!< USART frame last data bit clock pulse output to SCLK pin */
|
|
249 |
/**
|
|
250 |
* @}
|
|
251 |
*/
|
|
252 |
|
|
253 |
/** @defgroup USART_Interrupt_definition USART Interrupts Definition
|
|
254 |
* Elements values convention: 0000ZZZZ0XXYYYYYb
|
|
255 |
* - YYYYY : Interrupt source position in the XX register (5bits)
|
|
256 |
* - XX : Interrupt source register (2bits)
|
|
257 |
* - 01: CR1 register
|
|
258 |
* - 10: CR2 register
|
|
259 |
* - 11: CR3 register
|
|
260 |
* - ZZZZ : Flag position in the ISR register(4bits)
|
|
261 |
* @{
|
|
262 |
*/
|
|
263 |
|
|
264 |
#define USART_IT_PE ((uint16_t)0x0028U) /*!< USART parity error interruption */
|
|
265 |
#define USART_IT_TXE ((uint16_t)0x0727U) /*!< USART transmit data register empty interruption */
|
|
266 |
#define USART_IT_TC ((uint16_t)0x0626U) /*!< USART transmission complete interruption */
|
|
267 |
#define USART_IT_RXNE ((uint16_t)0x0525U) /*!< USART read data register not empty interruption */
|
|
268 |
#define USART_IT_IDLE ((uint16_t)0x0424U) /*!< USART idle interruption */
|
|
269 |
#define USART_IT_ERR ((uint16_t)0x0060U) /*!< USART error interruption */
|
|
270 |
#define USART_IT_ORE ((uint16_t)0x0300U) /*!< USART overrun error interruption */
|
|
271 |
#define USART_IT_NE ((uint16_t)0x0200U) /*!< USART noise error interruption */
|
|
272 |
#define USART_IT_FE ((uint16_t)0x0100U) /*!< USART frame error interruption */
|
|
273 |
/**
|
|
274 |
* @}
|
|
275 |
*/
|
|
276 |
|
|
277 |
/** @defgroup USART_IT_CLEAR_Flags USART Interruption Clear Flags
|
|
278 |
* @{
|
|
279 |
*/
|
|
280 |
#define USART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
|
|
281 |
#define USART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
|
|
282 |
#define USART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
|
|
283 |
#define USART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
|
|
284 |
#define USART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
|
|
285 |
#define USART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
|
|
286 |
#define USART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
|
|
287 |
/**
|
|
288 |
* @}
|
|
289 |
*/
|
|
290 |
|
|
291 |
/** @defgroup USART_Interruption_Mask USART Interruption Flags Mask
|
|
292 |
* @{
|
|
293 |
*/
|
|
294 |
#define USART_IT_MASK ((uint16_t)0x001FU) /*!< USART interruptions flags mask */
|
|
295 |
/**
|
|
296 |
* @}
|
|
297 |
*/
|
|
298 |
|
|
299 |
/**
|
|
300 |
* @}
|
|
301 |
*/
|
|
302 |
|
|
303 |
/* Exported macros -----------------------------------------------------------*/
|
|
304 |
/** @defgroup USART_Exported_Macros USART Exported Macros
|
|
305 |
* @{
|
|
306 |
*/
|
|
307 |
|
|
308 |
/** @brief Reset USART handle state.
|
|
309 |
* @param __HANDLE__ USART handle.
|
|
310 |
* @retval None
|
|
311 |
*/
|
|
312 |
#define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
|
|
313 |
|
|
314 |
/** @brief Check whether the specified USART flag is set or not.
|
|
315 |
* @param __HANDLE__ specifies the USART Handle
|
|
316 |
* @param __FLAG__ specifies the flag to check.
|
|
317 |
* This parameter can be one of the following values:
|
|
318 |
@if STM32F030x6
|
|
319 |
@elseif STM32F030x8
|
|
320 |
@elseif STM32F030xC
|
|
321 |
@elseif STM32F070x6
|
|
322 |
@elseif STM32F070xB
|
|
323 |
@else
|
|
324 |
* @arg @ref USART_FLAG_REACK Receive enable acknowledge flag
|
|
325 |
@endif
|
|
326 |
* @arg @ref USART_FLAG_TEACK Transmit enable acknowledge flag
|
|
327 |
* @arg @ref USART_FLAG_BUSY Busy flag
|
|
328 |
* @arg @ref USART_FLAG_CTS CTS Change flag
|
|
329 |
* @arg @ref USART_FLAG_TXE Transmit data register empty flag
|
|
330 |
* @arg @ref USART_FLAG_TC Transmission Complete flag
|
|
331 |
* @arg @ref USART_FLAG_RXNE Receive data register not empty flag
|
|
332 |
* @arg @ref USART_FLAG_IDLE Idle Line detection flag
|
|
333 |
* @arg @ref USART_FLAG_ORE OverRun Error flag
|
|
334 |
* @arg @ref USART_FLAG_NE Noise Error flag
|
|
335 |
* @arg @ref USART_FLAG_FE Framing Error flag
|
|
336 |
* @arg @ref USART_FLAG_PE Parity Error flag
|
|
337 |
* @retval The new state of __FLAG__ (TRUE or FALSE).
|
|
338 |
*/
|
|
339 |
#define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
|
|
340 |
|
|
341 |
/** @brief Clear the specified USART pending flag.
|
|
342 |
* @param __HANDLE__ specifies the USART Handle.
|
|
343 |
* @param __FLAG__ specifies the flag to check.
|
|
344 |
* This parameter can be any combination of the following values:
|
|
345 |
* @arg @ref USART_CLEAR_PEF
|
|
346 |
* @arg @ref USART_CLEAR_FEF
|
|
347 |
* @arg @ref USART_CLEAR_NEF
|
|
348 |
* @arg @ref USART_CLEAR_OREF
|
|
349 |
* @arg @ref USART_CLEAR_IDLEF
|
|
350 |
* @arg @ref USART_CLEAR_TCF
|
|
351 |
* @arg @ref USART_CLEAR_CTSF
|
|
352 |
* @retval None
|
|
353 |
*/
|
|
354 |
#define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
|
|
355 |
|
|
356 |
/** @brief Clear the USART PE pending flag.
|
|
357 |
* @param __HANDLE__ specifies the USART Handle.
|
|
358 |
* @retval None
|
|
359 |
*/
|
|
360 |
#define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_PEF)
|
|
361 |
|
|
362 |
/** @brief Clear the USART FE pending flag.
|
|
363 |
* @param __HANDLE__ specifies the USART Handle.
|
|
364 |
* @retval None
|
|
365 |
*/
|
|
366 |
#define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_FEF)
|
|
367 |
|
|
368 |
/** @brief Clear the USART NE pending flag.
|
|
369 |
* @param __HANDLE__ specifies the USART Handle.
|
|
370 |
* @retval None
|
|
371 |
*/
|
|
372 |
#define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_NEF)
|
|
373 |
|
|
374 |
/** @brief Clear the USART ORE pending flag.
|
|
375 |
* @param __HANDLE__ specifies the USART Handle.
|
|
376 |
* @retval None
|
|
377 |
*/
|
|
378 |
#define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_OREF)
|
|
379 |
|
|
380 |
/** @brief Clear the USART IDLE pending flag.
|
|
381 |
* @param __HANDLE__ specifies the USART Handle.
|
|
382 |
* @retval None
|
|
383 |
*/
|
|
384 |
#define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_IDLEF)
|
|
385 |
|
|
386 |
/** @brief Enable the specified USART interrupt.
|
|
387 |
* @param __HANDLE__ specifies the USART Handle.
|
|
388 |
* @param __INTERRUPT__ specifies the USART interrupt source to enable.
|
|
389 |
* This parameter can be one of the following values:
|
|
390 |
* @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
|
|
391 |
* @arg @ref USART_IT_TC Transmission complete interrupt
|
|
392 |
* @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
|
|
393 |
* @arg @ref USART_IT_IDLE Idle line detection interrupt
|
|
394 |
* @arg @ref USART_IT_PE Parity Error interrupt
|
|
395 |
* @arg @ref USART_IT_ERR Error interrupt(Frame error, noise error, overrun error)
|
|
396 |
* @retval None
|
|
397 |
*/
|
|
398 |
#define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((__INTERRUPT__) & 0xFF) >> 5U) == 1U)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
|
|
399 |
((((__INTERRUPT__) & 0xFF) >> 5U) == 2U)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
|
|
400 |
((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))))
|
|
401 |
|
|
402 |
/** @brief Disable the specified USART interrupt.
|
|
403 |
* @param __HANDLE__ specifies the USART Handle.
|
|
404 |
* @param __INTERRUPT__ specifies the USART interrupt source to disable.
|
|
405 |
* This parameter can be one of the following values:
|
|
406 |
* @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
|
|
407 |
* @arg @ref USART_IT_TC Transmission complete interrupt
|
|
408 |
* @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
|
|
409 |
* @arg @ref USART_IT_IDLE Idle line detection interrupt
|
|
410 |
* @arg @ref USART_IT_PE Parity Error interrupt
|
|
411 |
* @arg @ref USART_IT_ERR Error interrupt(Frame error, noise error, overrun error)
|
|
412 |
* @retval None
|
|
413 |
*/
|
|
414 |
#define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((__INTERRUPT__) & 0xFF) >> 5U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
|
|
415 |
((((__INTERRUPT__) & 0xFF) >> 5U) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
|
|
416 |
((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))))
|
|
417 |
|
|
418 |
|
|
419 |
/** @brief Check whether the specified USART interrupt has occurred or not.
|
|
420 |
* @param __HANDLE__ specifies the USART Handle.
|
|
421 |
* @param __IT__ specifies the USART interrupt source to check.
|
|
422 |
* This parameter can be one of the following values:
|
|
423 |
* @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
|
|
424 |
* @arg @ref USART_IT_TC Transmission complete interrupt
|
|
425 |
* @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
|
|
426 |
* @arg @ref USART_IT_IDLE Idle line detection interrupt
|
|
427 |
* @arg @ref USART_IT_ORE OverRun Error interrupt
|
|
428 |
* @arg @ref USART_IT_NE Noise Error interrupt
|
|
429 |
* @arg @ref USART_IT_FE Framing Error interrupt
|
|
430 |
* @arg @ref USART_IT_PE Parity Error interrupt
|
|
431 |
* @retval The new state of __IT__ (TRUE or FALSE).
|
|
432 |
*/
|
|
433 |
#define __HAL_USART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & (1U << ((__IT__)>> 0x08U)))
|
|
434 |
|
|
435 |
/** @brief Check whether the specified USART interrupt source is enabled or not.
|
|
436 |
* @param __HANDLE__ specifies the USART Handle.
|
|
437 |
* @param __IT__ specifies the USART interrupt source to check.
|
|
438 |
* This parameter can be one of the following values:
|
|
439 |
* @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
|
|
440 |
* @arg @ref USART_IT_TC Transmission complete interrupt
|
|
441 |
* @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
|
|
442 |
* @arg @ref USART_IT_IDLE Idle line detection interrupt
|
|
443 |
* @arg @ref USART_IT_ORE OverRun Error interrupt
|
|
444 |
* @arg @ref USART_IT_NE Noise Error interrupt
|
|
445 |
* @arg @ref USART_IT_FE Framing Error interrupt
|
|
446 |
* @arg @ref USART_IT_PE Parity Error interrupt
|
|
447 |
* @retval The new state of __IT__ (TRUE or FALSE).
|
|
448 |
*/
|
|
449 |
#define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1U)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2U)? \
|
|
450 |
(__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (1U << \
|
|
451 |
(((uint16_t)(__IT__)) & USART_IT_MASK)))
|
|
452 |
|
|
453 |
|
|
454 |
/** @brief Clear the specified USART ISR flag, in setting the proper ICR register flag.
|
|
455 |
* @param __HANDLE__ specifies the USART Handle.
|
|
456 |
* @param __IT_CLEAR__ specifies the interrupt clear register flag that needs to be set
|
|
457 |
* to clear the corresponding interrupt.
|
|
458 |
* This parameter can be one of the following values:
|
|
459 |
* @arg @ref USART_CLEAR_PEF Parity Error Clear Flag
|
|
460 |
* @arg @ref USART_CLEAR_FEF Framing Error Clear Flag
|
|
461 |
* @arg @ref USART_CLEAR_NEF Noise detected Clear Flag
|
|
462 |
* @arg @ref USART_CLEAR_OREF OverRun Error Clear Flag
|
|
463 |
* @arg @ref USART_CLEAR_IDLEF IDLE line detected Clear Flag
|
|
464 |
* @arg @ref USART_CLEAR_TCF Transmission Complete Clear Flag
|
|
465 |
* @arg @ref USART_CLEAR_CTSF CTS Interrupt Clear Flag
|
|
466 |
* @retval None
|
|
467 |
*/
|
|
468 |
#define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
|
|
469 |
|
|
470 |
/** @brief Set a specific USART request flag.
|
|
471 |
* @param __HANDLE__ specifies the USART Handle.
|
|
472 |
* @param __REQ__ specifies the request flag to set.
|
|
473 |
* This parameter can be one of the following values:
|
|
474 |
* @arg @ref USART_RXDATA_FLUSH_REQUEST Receive Data flush Request
|
|
475 |
@if STM32F030x6
|
|
476 |
@elseif STM32F030x8
|
|
477 |
@elseif STM32F030xC
|
|
478 |
@elseif STM32F070x6
|
|
479 |
@elseif STM32F070xB
|
|
480 |
@else
|
|
481 |
* @arg @ref USART_TXDATA_FLUSH_REQUEST Transmit data flush Request
|
|
482 |
@endif
|
|
483 |
*
|
|
484 |
* @retval None
|
|
485 |
*/
|
|
486 |
#define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (__REQ__))
|
|
487 |
|
|
488 |
/** @brief Enable the USART one bit sample method.
|
|
489 |
* @param __HANDLE__ specifies the USART Handle.
|
|
490 |
* @retval None
|
|
491 |
*/
|
|
492 |
#define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
|
|
493 |
|
|
494 |
/** @brief Disable the USART one bit sample method.
|
|
495 |
* @param __HANDLE__ specifies the USART Handle.
|
|
496 |
* @retval None
|
|
497 |
*/
|
|
498 |
#define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
|
|
499 |
|
|
500 |
/** @brief Enable USART.
|
|
501 |
* @param __HANDLE__ specifies the USART Handle.
|
|
502 |
* @retval None
|
|
503 |
*/
|
|
504 |
#define __HAL_USART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
|
|
505 |
|
|
506 |
/** @brief Disable USART.
|
|
507 |
* @param __HANDLE__ specifies the USART Handle.
|
|
508 |
* @retval None
|
|
509 |
*/
|
|
510 |
#define __HAL_USART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
|
|
511 |
|
|
512 |
/**
|
|
513 |
* @}
|
|
514 |
*/
|
|
515 |
|
|
516 |
/* Private macros --------------------------------------------------------*/
|
|
517 |
/** @defgroup USART_Private_Macros USART Private Macros
|
|
518 |
* @{
|
|
519 |
*/
|
|
520 |
|
|
521 |
/** @brief Check USART Baud rate.
|
|
522 |
* @param __BAUDRATE__ Baudrate specified by the user.
|
|
523 |
* The maximum Baud Rate is derived from the maximum clock on F0 (i.e. 48 MHz)
|
|
524 |
* divided by the smallest oversampling used on the USART (i.e. 8)
|
|
525 |
* @retval Test result (TRUE or FALSE).
|
|
526 |
*/
|
|
527 |
#define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 6000001U)
|
|
528 |
|
|
529 |
/**
|
|
530 |
* @brief Ensure that USART frame number of stop bits is valid.
|
|
531 |
* @param __STOPBITS__ USART frame number of stop bits.
|
|
532 |
* @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
|
|
533 |
*/
|
|
534 |
#ifdef USART_SMARTCARD_SUPPORT
|
|
535 |
#define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_0_5) || \
|
|
536 |
((__STOPBITS__) == USART_STOPBITS_1) || \
|
|
537 |
((__STOPBITS__) == USART_STOPBITS_1_5) || \
|
|
538 |
((__STOPBITS__) == USART_STOPBITS_2))
|
|
539 |
#else
|
|
540 |
#define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_1) || \
|
|
541 |
((__STOPBITS__) == USART_STOPBITS_2))
|
|
542 |
#endif
|
|
543 |
|
|
544 |
/**
|
|
545 |
* @brief Ensure that USART frame parity is valid.
|
|
546 |
* @param __PARITY__ USART frame parity.
|
|
547 |
* @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
|
|
548 |
*/
|
|
549 |
#define IS_USART_PARITY(__PARITY__) (((__PARITY__) == USART_PARITY_NONE) || \
|
|
550 |
((__PARITY__) == USART_PARITY_EVEN) || \
|
|
551 |
((__PARITY__) == USART_PARITY_ODD))
|
|
552 |
|
|
553 |
/**
|
|
554 |
* @brief Ensure that USART communication mode is valid.
|
|
555 |
* @param __MODE__ USART communication mode.
|
|
556 |
* @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
|
|
557 |
*/
|
|
558 |
#define IS_USART_MODE(__MODE__) ((((__MODE__) & 0xFFFFFFF3U) == 0x00U) && ((__MODE__) != 0x00U))
|
|
559 |
|
|
560 |
/**
|
|
561 |
* @brief Ensure that USART clock state is valid.
|
|
562 |
* @param __CLOCK__ USART clock state.
|
|
563 |
* @retval SET (__CLOCK__ is valid) or RESET (__CLOCK__ is invalid)
|
|
564 |
*/
|
|
565 |
#define IS_USART_CLOCK(__CLOCK__) (((__CLOCK__) == USART_CLOCK_DISABLE) || \
|
|
566 |
((__CLOCK__) == USART_CLOCK_ENABLE))
|
|
567 |
|
|
568 |
/**
|
|
569 |
* @brief Ensure that USART frame polarity is valid.
|
|
570 |
* @param __CPOL__ USART frame polarity.
|
|
571 |
* @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
|
|
572 |
*/
|
|
573 |
#define IS_USART_POLARITY(__CPOL__) (((__CPOL__) == USART_POLARITY_LOW) || ((__CPOL__) == USART_POLARITY_HIGH))
|
|
574 |
|
|
575 |
/**
|
|
576 |
* @brief Ensure that USART frame phase is valid.
|
|
577 |
* @param __CPHA__ USART frame phase.
|
|
578 |
* @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid)
|
|
579 |
*/
|
|
580 |
#define IS_USART_PHASE(__CPHA__) (((__CPHA__) == USART_PHASE_1EDGE) || ((__CPHA__) == USART_PHASE_2EDGE))
|
|
581 |
|
|
582 |
/**
|
|
583 |
* @brief Ensure that USART frame last bit clock pulse setting is valid.
|
|
584 |
* @param __LASTBIT__ USART frame last bit clock pulse setting.
|
|
585 |
* @retval SET (__LASTBIT__ is valid) or RESET (__LASTBIT__ is invalid)
|
|
586 |
*/
|
|
587 |
#define IS_USART_LASTBIT(__LASTBIT__) (((__LASTBIT__) == USART_LASTBIT_DISABLE) || \
|
|
588 |
((__LASTBIT__) == USART_LASTBIT_ENABLE))
|
|
589 |
|
|
590 |
/**
|
|
591 |
* @}
|
|
592 |
*/
|
|
593 |
|
|
594 |
/* Include USART HAL Extended module */
|
|
595 |
#include "stm32f0xx_hal_usart_ex.h"
|
|
596 |
|
|
597 |
/* Exported functions --------------------------------------------------------*/
|
|
598 |
/** @addtogroup USART_Exported_Functions USART Exported Functions
|
|
599 |
* @{
|
|
600 |
*/
|
|
601 |
|
|
602 |
/** @addtogroup USART_Exported_Functions_Group1 Initialization and de-initialization functions
|
|
603 |
* @{
|
|
604 |
*/
|
|
605 |
|
|
606 |
/* Initialization and de-initialization functions ****************************/
|
|
607 |
HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
|
|
608 |
HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
|
|
609 |
void HAL_USART_MspInit(USART_HandleTypeDef *husart);
|
|
610 |
void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
|
|
611 |
|
|
612 |
/**
|
|
613 |
* @}
|
|
614 |
*/
|
|
615 |
|
|
616 |
/** @addtogroup USART_Exported_Functions_Group2 IO operation functions
|
|
617 |
* @{
|
|
618 |
*/
|
|
619 |
|
|
620 |
/* IO operation functions *****************************************************/
|
|
621 |
HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
|
|
622 |
HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
|
|
623 |
HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
|
|
624 |
HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
|
|
625 |
HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
|
|
626 |
HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
|
|
627 |
HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
|
|
628 |
HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
|
|
629 |
HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
|
|
630 |
HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
|
|
631 |
HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
|
|
632 |
HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
|
|
633 |
/* Transfer Abort functions */
|
|
634 |
HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart);
|
|
635 |
HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart);
|
|
636 |
|
|
637 |
void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
|
|
638 |
void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
|
|
639 |
void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
|
|
640 |
void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
|
|
641 |
void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
|
|
642 |
void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
|
|
643 |
void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
|
|
644 |
void HAL_USART_AbortCpltCallback (USART_HandleTypeDef *husart);
|
|
645 |
|
|
646 |
/**
|
|
647 |
* @}
|
|
648 |
*/
|
|
649 |
|
|
650 |
/* Peripheral Control functions ***********************************************/
|
|
651 |
|
|
652 |
/** @addtogroup USART_Exported_Functions_Group3 Peripheral State and Error functions
|
|
653 |
* @{
|
|
654 |
*/
|
|
655 |
|
|
656 |
/* Peripheral State and Error functions ***************************************/
|
|
657 |
HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
|
|
658 |
uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart);
|
|
659 |
|
|
660 |
/**
|
|
661 |
* @}
|
|
662 |
*/
|
|
663 |
|
|
664 |
/**
|
|
665 |
* @}
|
|
666 |
*/
|
|
667 |
|
|
668 |
/**
|
|
669 |
* @}
|
|
670 |
*/
|
|
671 |
|
|
672 |
/**
|
|
673 |
* @}
|
|
674 |
*/
|
|
675 |
|
|
676 |
#ifdef __cplusplus
|
|
677 |
}
|
|
678 |
#endif
|
|
679 |
|
|
680 |
#endif /* __STM32F0xx_HAL_USART_H */
|
|
681 |
|
|
682 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
683 |
|