提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file stm32f0xx_hal_usart_ex.h |
|
4 |
* @author MCD Application Team |
|
5 |
* @brief Header file of USART HAL Extended 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_EX_H |
|
38 |
#define __STM32F0xx_HAL_USART_EX_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 USARTEx |
|
52 |
* @{ |
|
53 |
*/ |
|
54 |
|
|
55 |
/* Exported types ------------------------------------------------------------*/ |
|
56 |
/* Exported constants --------------------------------------------------------*/ |
|
57 |
/** @defgroup USARTEx_Exported_Constants USARTEx Exported Constants |
|
58 |
* @{ |
|
59 |
*/ |
|
60 |
|
|
61 |
/** @defgroup USARTEx_Word_Length USARTEx Word Length |
|
62 |
* @{ |
|
63 |
*/ |
|
64 |
#if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \ |
|
65 |
defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \ |
|
66 |
defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) |
|
67 |
#define USART_WORDLENGTH_7B ((uint32_t)USART_CR1_M1) /*!< 7-bit long USART frame */ |
|
68 |
#define USART_WORDLENGTH_8B (0x00000000U) /*!< 8-bit long USART frame */ |
|
69 |
#define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M0) /*!< 9-bit long USART frame */ |
|
70 |
#else |
|
71 |
#define USART_WORDLENGTH_8B (0x00000000U) /*!< 8-bit long USART frame */ |
|
72 |
#define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M) /*!< 9-bit long USART frame */ |
|
73 |
#endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || defined (STM32F070xB) || \ |
|
74 |
defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \ |
|
75 |
defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */ |
|
76 |
/** |
|
77 |
* @} |
|
78 |
*/ |
|
79 |
|
|
80 |
/** @defgroup USART_Request_Parameters USARTEx Request Parameters |
|
81 |
* @{ |
|
82 |
*/ |
|
83 |
#define USART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */ |
|
84 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
|
85 |
#define USART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */ |
|
86 |
#else |
|
87 |
#endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */ |
|
88 |
/** |
|
89 |
* @} |
|
90 |
*/ |
|
91 |
|
|
92 |
/** @defgroup USART_Flags USART Flags |
|
93 |
* Elements values convention: 0xXXXX |
|
94 |
* - 0xXXXX : Flag mask in the ISR register |
|
95 |
* @{ |
|
96 |
*/ |
|
97 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
|
98 |
#define USART_FLAG_REACK (0x00400000U) /*!< USART receive enable acknowledge flag */ |
|
99 |
#endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */ |
|
100 |
#define USART_FLAG_TEACK (0x00200000U) /*!< USART transmit enable acknowledge flag */ |
|
101 |
#define USART_FLAG_BUSY (0x00010000U) /*!< USART busy flag */ |
|
102 |
#define USART_FLAG_CTS (0x00000400U) /*!< USART clear to send flag */ |
|
103 |
#define USART_FLAG_CTSIF (0x00000200U) /*!< USART clear to send interrupt flag */ |
|
104 |
#define USART_FLAG_TXE (0x00000080U) /*!< USART transmit data register empty */ |
|
105 |
#define USART_FLAG_TC (0x00000040U) /*!< USART transmission complete */ |
|
106 |
#define USART_FLAG_RXNE (0x00000020U) /*!< USART read data register not empty */ |
|
107 |
#define USART_FLAG_IDLE (0x00000010U) /*!< USART idle flag */ |
|
108 |
#define USART_FLAG_ORE (0x00000008U) /*!< USART overrun error */ |
|
109 |
#define USART_FLAG_NE (0x00000004U) /*!< USART noise error */ |
|
110 |
#define USART_FLAG_FE (0x00000002U) /*!< USART frame error */ |
|
111 |
#define USART_FLAG_PE (0x00000001U) /*!< USART parity error */ |
|
112 |
/** |
|
113 |
* @} |
|
114 |
*/ |
|
115 |
|
|
116 |
/** |
|
117 |
* @} |
|
118 |
*/ |
|
119 |
|
|
120 |
/* Exported macros ------------------------------------------------------------*/ |
|
121 |
/** @defgroup USARTEx_Exported_Macros USARTEx Exported Macros |
|
122 |
* @{ |
|
123 |
*/ |
|
124 |
|
|
125 |
/** @brief Flush the USART Data registers. |
|
126 |
* @param __HANDLE__ specifies the USART Handle. |
|
127 |
* @retval None |
|
128 |
*/ |
|
129 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
|
130 |
#define __HAL_USART_FLUSH_DRREGISTER(__HANDLE__) \ |
|
131 |
do{ \ |
|
132 |
SET_BIT((__HANDLE__)->Instance->RQR, USART_RXDATA_FLUSH_REQUEST); \ |
|
133 |
SET_BIT((__HANDLE__)->Instance->RQR, USART_TXDATA_FLUSH_REQUEST); \ |
|
134 |
} while(0) |
|
135 |
#else |
|
136 |
#define __HAL_USART_FLUSH_DRREGISTER(__HANDLE__) \ |
|
137 |
do{ \ |
|
138 |
SET_BIT((__HANDLE__)->Instance->RQR, USART_RXDATA_FLUSH_REQUEST); \ |
|
139 |
} while(0) |
|
140 |
#endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */ |
|
141 |
|
|
142 |
/** |
|
143 |
* @} |
|
144 |
*/ |
|
145 |
|
|
146 |
/* Private macros ------------------------------------------------------------*/ |
|
147 |
/** @defgroup USARTEx_Private_Macros USARTEx Private Macros |
|
148 |
* @{ |
|
149 |
*/ |
|
150 |
|
|
151 |
/** @brief Report the USART clock source. |
|
152 |
* @param __HANDLE__ specifies the USART Handle. |
|
153 |
* @param __CLOCKSOURCE__ output variable. |
|
154 |
* @retval the USART clocking source, written in __CLOCKSOURCE__. |
|
155 |
*/ |
|
156 |
#if defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx) |
|
157 |
#define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ |
|
158 |
do { \ |
|
159 |
switch(__HAL_RCC_GET_USART1_SOURCE()) \ |
|
160 |
{ \ |
|
161 |
case RCC_USART1CLKSOURCE_PCLK1: \ |
|
162 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
163 |
break; \ |
|
164 |
case RCC_USART1CLKSOURCE_HSI: \ |
|
165 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ |
|
166 |
break; \ |
|
167 |
case RCC_USART1CLKSOURCE_SYSCLK: \ |
|
168 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ |
|
169 |
break; \ |
|
170 |
case RCC_USART1CLKSOURCE_LSE: \ |
|
171 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ |
|
172 |
break; \ |
|
173 |
default: \ |
|
174 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
175 |
break; \ |
|
176 |
} \ |
|
177 |
} while(0) |
|
178 |
#elif defined (STM32F030x8) || defined (STM32F070x6) || \ |
|
179 |
defined (STM32F042x6) || defined (STM32F048xx) || \ |
|
180 |
defined (STM32F051x8) || defined (STM32F058xx) |
|
181 |
#define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ |
|
182 |
do { \ |
|
183 |
if((__HANDLE__)->Instance == USART1) \ |
|
184 |
{ \ |
|
185 |
switch(__HAL_RCC_GET_USART1_SOURCE()) \ |
|
186 |
{ \ |
|
187 |
case RCC_USART1CLKSOURCE_PCLK1: \ |
|
188 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
189 |
break; \ |
|
190 |
case RCC_USART1CLKSOURCE_HSI: \ |
|
191 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ |
|
192 |
break; \ |
|
193 |
case RCC_USART1CLKSOURCE_SYSCLK: \ |
|
194 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ |
|
195 |
break; \ |
|
196 |
case RCC_USART1CLKSOURCE_LSE: \ |
|
197 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ |
|
198 |
break; \ |
|
199 |
default: \ |
|
200 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
201 |
break; \ |
|
202 |
} \ |
|
203 |
} \ |
|
204 |
else if((__HANDLE__)->Instance == USART2) \ |
|
205 |
{ \ |
|
206 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
207 |
} \ |
|
208 |
else \ |
|
209 |
{ \ |
|
210 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
211 |
} \ |
|
212 |
} while(0) |
|
213 |
#elif defined (STM32F070xB) |
|
214 |
#define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ |
|
215 |
do { \ |
|
216 |
if((__HANDLE__)->Instance == USART1) \ |
|
217 |
{ \ |
|
218 |
switch(__HAL_RCC_GET_USART1_SOURCE()) \ |
|
219 |
{ \ |
|
220 |
case RCC_USART1CLKSOURCE_PCLK1: \ |
|
221 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
222 |
break; \ |
|
223 |
case RCC_USART1CLKSOURCE_HSI: \ |
|
224 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ |
|
225 |
break; \ |
|
226 |
case RCC_USART1CLKSOURCE_SYSCLK: \ |
|
227 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ |
|
228 |
break; \ |
|
229 |
case RCC_USART1CLKSOURCE_LSE: \ |
|
230 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ |
|
231 |
break; \ |
|
232 |
default: \ |
|
233 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
234 |
break; \ |
|
235 |
} \ |
|
236 |
} \ |
|
237 |
else if((__HANDLE__)->Instance == USART2) \ |
|
238 |
{ \ |
|
239 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
240 |
} \ |
|
241 |
else if((__HANDLE__)->Instance == USART3) \ |
|
242 |
{ \ |
|
243 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
244 |
} \ |
|
245 |
else if((__HANDLE__)->Instance == USART4) \ |
|
246 |
{ \ |
|
247 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
248 |
} \ |
|
249 |
else \ |
|
250 |
{ \ |
|
251 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
252 |
} \ |
|
253 |
} while(0) |
|
254 |
#elif defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) |
|
255 |
#define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ |
|
256 |
do { \ |
|
257 |
if((__HANDLE__)->Instance == USART1) \ |
|
258 |
{ \ |
|
259 |
switch(__HAL_RCC_GET_USART1_SOURCE()) \ |
|
260 |
{ \ |
|
261 |
case RCC_USART1CLKSOURCE_PCLK1: \ |
|
262 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
263 |
break; \ |
|
264 |
case RCC_USART1CLKSOURCE_HSI: \ |
|
265 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ |
|
266 |
break; \ |
|
267 |
case RCC_USART1CLKSOURCE_SYSCLK: \ |
|
268 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ |
|
269 |
break; \ |
|
270 |
case RCC_USART1CLKSOURCE_LSE: \ |
|
271 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ |
|
272 |
break; \ |
|
273 |
default: \ |
|
274 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
275 |
break; \ |
|
276 |
} \ |
|
277 |
} \ |
|
278 |
else if((__HANDLE__)->Instance == USART2) \ |
|
279 |
{ \ |
|
280 |
switch(__HAL_RCC_GET_USART2_SOURCE()) \ |
|
281 |
{ \ |
|
282 |
case RCC_USART2CLKSOURCE_PCLK1: \ |
|
283 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
284 |
break; \ |
|
285 |
case RCC_USART2CLKSOURCE_HSI: \ |
|
286 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ |
|
287 |
break; \ |
|
288 |
case RCC_USART2CLKSOURCE_SYSCLK: \ |
|
289 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ |
|
290 |
break; \ |
|
291 |
case RCC_USART2CLKSOURCE_LSE: \ |
|
292 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ |
|
293 |
break; \ |
|
294 |
default: \ |
|
295 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
296 |
break; \ |
|
297 |
} \ |
|
298 |
} \ |
|
299 |
else if((__HANDLE__)->Instance == USART3) \ |
|
300 |
{ \ |
|
301 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
302 |
} \ |
|
303 |
else if((__HANDLE__)->Instance == USART4) \ |
|
304 |
{ \ |
|
305 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
306 |
} \ |
|
307 |
else \ |
|
308 |
{ \ |
|
309 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
310 |
} \ |
|
311 |
} while(0) |
|
312 |
#elif defined(STM32F091xC) || defined (STM32F098xx) |
|
313 |
#define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ |
|
314 |
do { \ |
|
315 |
if((__HANDLE__)->Instance == USART1) \ |
|
316 |
{ \ |
|
317 |
switch(__HAL_RCC_GET_USART1_SOURCE()) \ |
|
318 |
{ \ |
|
319 |
case RCC_USART1CLKSOURCE_PCLK1: \ |
|
320 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
321 |
break; \ |
|
322 |
case RCC_USART1CLKSOURCE_HSI: \ |
|
323 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ |
|
324 |
break; \ |
|
325 |
case RCC_USART1CLKSOURCE_SYSCLK: \ |
|
326 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ |
|
327 |
break; \ |
|
328 |
case RCC_USART1CLKSOURCE_LSE: \ |
|
329 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ |
|
330 |
break; \ |
|
331 |
default: \ |
|
332 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
333 |
break; \ |
|
334 |
} \ |
|
335 |
} \ |
|
336 |
else if((__HANDLE__)->Instance == USART2) \ |
|
337 |
{ \ |
|
338 |
switch(__HAL_RCC_GET_USART2_SOURCE()) \ |
|
339 |
{ \ |
|
340 |
case RCC_USART2CLKSOURCE_PCLK1: \ |
|
341 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
342 |
break; \ |
|
343 |
case RCC_USART2CLKSOURCE_HSI: \ |
|
344 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ |
|
345 |
break; \ |
|
346 |
case RCC_USART2CLKSOURCE_SYSCLK: \ |
|
347 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ |
|
348 |
break; \ |
|
349 |
case RCC_USART2CLKSOURCE_LSE: \ |
|
350 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ |
|
351 |
break; \ |
|
352 |
default: \ |
|
353 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
354 |
break; \ |
|
355 |
} \ |
|
356 |
} \ |
|
357 |
else if((__HANDLE__)->Instance == USART3) \ |
|
358 |
{ \ |
|
359 |
switch(__HAL_RCC_GET_USART3_SOURCE()) \ |
|
360 |
{ \ |
|
361 |
case RCC_USART3CLKSOURCE_PCLK1: \ |
|
362 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
363 |
break; \ |
|
364 |
case RCC_USART3CLKSOURCE_HSI: \ |
|
365 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ |
|
366 |
break; \ |
|
367 |
case RCC_USART3CLKSOURCE_SYSCLK: \ |
|
368 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ |
|
369 |
break; \ |
|
370 |
case RCC_USART3CLKSOURCE_LSE: \ |
|
371 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ |
|
372 |
break; \ |
|
373 |
default: \ |
|
374 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
375 |
break; \ |
|
376 |
} \ |
|
377 |
} \ |
|
378 |
else if((__HANDLE__)->Instance == USART4) \ |
|
379 |
{ \ |
|
380 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
381 |
} \ |
|
382 |
else if((__HANDLE__)->Instance == USART5) \ |
|
383 |
{ \ |
|
384 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
385 |
} \ |
|
386 |
else if((__HANDLE__)->Instance == USART6) \ |
|
387 |
{ \ |
|
388 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
389 |
} \ |
|
390 |
else if((__HANDLE__)->Instance == USART7) \ |
|
391 |
{ \ |
|
392 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
393 |
} \ |
|
394 |
else if((__HANDLE__)->Instance == USART8) \ |
|
395 |
{ \ |
|
396 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
397 |
} \ |
|
398 |
else \ |
|
399 |
{ \ |
|
400 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
401 |
} \ |
|
402 |
} while(0) |
|
403 |
#elif defined(STM32F030xC) |
|
404 |
#define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ |
|
405 |
do { \ |
|
406 |
if((__HANDLE__)->Instance == USART1) \ |
|
407 |
{ \ |
|
408 |
switch(__HAL_RCC_GET_USART1_SOURCE()) \ |
|
409 |
{ \ |
|
410 |
case RCC_USART1CLKSOURCE_PCLK1: \ |
|
411 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
412 |
break; \ |
|
413 |
case RCC_USART1CLKSOURCE_HSI: \ |
|
414 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ |
|
415 |
break; \ |
|
416 |
case RCC_USART1CLKSOURCE_SYSCLK: \ |
|
417 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ |
|
418 |
break; \ |
|
419 |
case RCC_USART1CLKSOURCE_LSE: \ |
|
420 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ |
|
421 |
break; \ |
|
422 |
default: \ |
|
423 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
424 |
break; \ |
|
425 |
} \ |
|
426 |
} \ |
|
427 |
else if((__HANDLE__)->Instance == USART2) \ |
|
428 |
{ \ |
|
429 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
430 |
} \ |
|
431 |
else if((__HANDLE__)->Instance == USART3) \ |
|
432 |
{ \ |
|
433 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
434 |
} \ |
|
435 |
else if((__HANDLE__)->Instance == USART4) \ |
|
436 |
{ \ |
|
437 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
438 |
} \ |
|
439 |
else if((__HANDLE__)->Instance == USART5) \ |
|
440 |
{ \ |
|
441 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
442 |
} \ |
|
443 |
else if((__HANDLE__)->Instance == USART6) \ |
|
444 |
{ \ |
|
445 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ |
|
446 |
} \ |
|
447 |
else \ |
|
448 |
{ \ |
|
449 |
(__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ |
|
450 |
} \ |
|
451 |
} while(0) |
|
452 |
#endif /* defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx) */ |
|
453 |
|
|
454 |
|
|
455 |
/** @brief Compute the USART mask to apply to retrieve the received data |
|
456 |
* according to the word length and to the parity bits activation. |
|
457 |
* @note If PCE = 1, the parity bit is not included in the data extracted |
|
458 |
* by the reception API(). |
|
459 |
* This masking operation is not carried out in the case of |
|
460 |
* DMA transfers. |
|
461 |
* @param __HANDLE__ specifies the USART Handle. |
|
462 |
* @retval None, the mask to apply to USART RDR register is stored in (__HANDLE__)->Mask field. |
|
463 |
*/ |
|
464 |
#if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \ |
|
465 |
defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \ |
|
466 |
defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) |
|
467 |
#define USART_MASK_COMPUTATION(__HANDLE__) \ |
|
468 |
do { \ |
|
469 |
if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \ |
|
470 |
{ \ |
|
471 |
if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ |
|
472 |
{ \ |
|
473 |
(__HANDLE__)->Mask = 0x01FFU; \ |
|
474 |
} \ |
|
475 |
else \ |
|
476 |
{ \ |
|
477 |
(__HANDLE__)->Mask = 0x00FFU; \ |
|
478 |
} \ |
|
479 |
} \ |
|
480 |
else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \ |
|
481 |
{ \ |
|
482 |
if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ |
|
483 |
{ \ |
|
484 |
(__HANDLE__)->Mask = 0x00FFU; \ |
|
485 |
} \ |
|
486 |
else \ |
|
487 |
{ \ |
|
488 |
(__HANDLE__)->Mask = 0x007FU; \ |
|
489 |
} \ |
|
490 |
} \ |
|
491 |
else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_7B) \ |
|
492 |
{ \ |
|
493 |
if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ |
|
494 |
{ \ |
|
495 |
(__HANDLE__)->Mask = 0x007FU; \ |
|
496 |
} \ |
|
497 |
else \ |
|
498 |
{ \ |
|
499 |
(__HANDLE__)->Mask = 0x003FU; \ |
|
500 |
} \ |
|
501 |
} \ |
|
502 |
} while(0) |
|
503 |
#else |
|
504 |
#define USART_MASK_COMPUTATION(__HANDLE__) \ |
|
505 |
do { \ |
|
506 |
if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \ |
|
507 |
{ \ |
|
508 |
if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ |
|
509 |
{ \ |
|
510 |
(__HANDLE__)->Mask = 0x01FFU; \ |
|
511 |
} \ |
|
512 |
else \ |
|
513 |
{ \ |
|
514 |
(__HANDLE__)->Mask = 0x00FFU; \ |
|
515 |
} \ |
|
516 |
} \ |
|
517 |
else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \ |
|
518 |
{ \ |
|
519 |
if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ |
|
520 |
{ \ |
|
521 |
(__HANDLE__)->Mask = 0x00FFU; \ |
|
522 |
} \ |
|
523 |
else \ |
|
524 |
{ \ |
|
525 |
(__HANDLE__)->Mask = 0x007FU; \ |
|
526 |
} \ |
|
527 |
} \ |
|
528 |
} while(0) |
|
529 |
#endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \ |
|
530 |
defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \ |
|
531 |
defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */ |
|
532 |
|
|
533 |
|
|
534 |
/** |
|
535 |
* @brief Ensure that USART frame length is valid. |
|
536 |
* @param __LENGTH__ USART frame length. |
|
537 |
* @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid) |
|
538 |
*/ |
|
539 |
#if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \ |
|
540 |
defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \ |
|
541 |
defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) |
|
542 |
#define IS_USART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == USART_WORDLENGTH_7B) || \ |
|
543 |
((__LENGTH__) == USART_WORDLENGTH_8B) || \ |
|
544 |
((__LENGTH__) == USART_WORDLENGTH_9B)) |
|
545 |
#else |
|
546 |
#define IS_USART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == USART_WORDLENGTH_8B) || \ |
|
547 |
((__LENGTH__) == USART_WORDLENGTH_9B)) |
|
548 |
#endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || defined (STM32F070xB) || \ |
|
549 |
defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \ |
|
550 |
defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */ |
|
551 |
|
|
552 |
/** |
|
553 |
* @brief Ensure that USART request parameter is valid. |
|
554 |
* @param __PARAM__ USART request parameter. |
|
555 |
* @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid) |
|
556 |
*/ |
|
557 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
|
558 |
#define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \ |
|
559 |
((__PARAM__) == USART_TXDATA_FLUSH_REQUEST)) |
|
560 |
#else |
|
561 |
#define IS_USART_REQUEST_PARAMETER(__PARAM__) ((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) |
|
562 |
#endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */ |
|
563 |
|
|
564 |
/** |
|
565 |
* @} |
|
566 |
*/ |
|
567 |
|
|
568 |
/* Exported functions --------------------------------------------------------*/ |
|
569 |
|
|
570 |
/** |
|
571 |
* @} |
|
572 |
*/ |
|
573 |
|
|
574 |
/** |
|
575 |
* @} |
|
576 |
*/ |
|
577 |
|
|
578 |
#ifdef __cplusplus |
|
579 |
} |
|
580 |
#endif |
|
581 |
|
|
582 |
#endif /* __STM32F0xx_HAL_USART_EX_H */ |
|
583 |
|
|
584 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
|
585 |
|