]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_usart_ex.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F0 / stm32f0xx_hal_usart_ex.h
1 /**
2 ******************************************************************************
3 * @file stm32f0xx_hal_usart_ex.h
4 * @author MCD Application Team
5 * @version V1.2.0
6 * @date 11-December-2014
7 * @brief Header file of USART HAL Extension module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12 *
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************
36 */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F0xx_HAL_USART_EX_H
40 #define __STM32F0xx_HAL_USART_EX_H
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f0xx_hal_def.h"
48
49 /** @addtogroup STM32F0xx_HAL_Driver
50 * @{
51 */
52
53 /** @defgroup USARTEx USARTEx Extended HAL module driver
54 * @{
55 */
56
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /** @defgroup USARTEx_Exported_Constants USARTEx Exported Constants
60 * @{
61 */
62
63 /** @defgroup USARTEx_Word_Length USARTEx Word Length
64 * @{
65 */
66 #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
67 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
68 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
69 #define USART_WORDLENGTH_7B ((uint32_t)USART_CR1_M1)
70 #define USART_WORDLENGTH_8B ((uint32_t)0x00000000)
71 #define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M0)
72 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WORDLENGTH_7B) || \
73 ((LENGTH) == USART_WORDLENGTH_8B) || \
74 ((LENGTH) == USART_WORDLENGTH_9B))
75 #else
76 #define USART_WORDLENGTH_8B ((uint32_t)0x00000000)
77 #define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
78 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WORDLENGTH_8B) || \
79 ((LENGTH) == USART_WORDLENGTH_9B))
80 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || defined (STM32F070xB) || \
81 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
82 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
83 /**
84 * @}
85 */
86
87 /**
88 * @}
89 */
90
91 /* Exported macro ------------------------------------------------------------*/
92
93 /** @defgroup USARTEx_Exported_Macros USARTEx Exported Macros
94 * @{
95 */
96
97 /** @brief Reports the USART clock source.
98 * @param __HANDLE__: specifies the USART Handle
99 * @param __CLOCKSOURCE__ : output variable
100 * @retval the USART clocking source, written in __CLOCKSOURCE__.
101 */
102 #if defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx)
103 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
104 do { \
105 switch(__HAL_RCC_GET_USART1_SOURCE()) \
106 { \
107 case RCC_USART1CLKSOURCE_PCLK1: \
108 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
109 break; \
110 case RCC_USART1CLKSOURCE_HSI: \
111 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
112 break; \
113 case RCC_USART1CLKSOURCE_SYSCLK: \
114 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
115 break; \
116 case RCC_USART1CLKSOURCE_LSE: \
117 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
118 break; \
119 default: \
120 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
121 break; \
122 } \
123 } while(0)
124 #elif defined (STM32F030x8) || defined (STM32F070x6) || \
125 defined (STM32F042x6) || defined (STM32F048xx) || \
126 defined (STM32F051x8) || defined (STM32F058xx)
127 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
128 do { \
129 if((__HANDLE__)->Instance == USART1) \
130 { \
131 switch(__HAL_RCC_GET_USART1_SOURCE()) \
132 { \
133 case RCC_USART1CLKSOURCE_PCLK1: \
134 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
135 break; \
136 case RCC_USART1CLKSOURCE_HSI: \
137 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
138 break; \
139 case RCC_USART1CLKSOURCE_SYSCLK: \
140 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
141 break; \
142 case RCC_USART1CLKSOURCE_LSE: \
143 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
144 break; \
145 default: \
146 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
147 break; \
148 } \
149 } \
150 else if((__HANDLE__)->Instance == USART2) \
151 { \
152 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
153 } \
154 else \
155 { \
156 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
157 } \
158 } while(0)
159 #elif defined (STM32F070xB)
160 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
161 do { \
162 if((__HANDLE__)->Instance == USART1) \
163 { \
164 switch(__HAL_RCC_GET_USART1_SOURCE()) \
165 { \
166 case RCC_USART1CLKSOURCE_PCLK1: \
167 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
168 break; \
169 case RCC_USART1CLKSOURCE_HSI: \
170 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
171 break; \
172 case RCC_USART1CLKSOURCE_SYSCLK: \
173 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
174 break; \
175 case RCC_USART1CLKSOURCE_LSE: \
176 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
177 break; \
178 default: \
179 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
180 break; \
181 } \
182 } \
183 else if((__HANDLE__)->Instance == USART2) \
184 { \
185 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
186 } \
187 else if((__HANDLE__)->Instance == USART3) \
188 { \
189 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
190 } \
191 else if((__HANDLE__)->Instance == USART4) \
192 { \
193 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
194 } \
195 else \
196 { \
197 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
198 } \
199 } while(0)
200 #elif defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)
201 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
202 do { \
203 if((__HANDLE__)->Instance == USART1) \
204 { \
205 switch(__HAL_RCC_GET_USART1_SOURCE()) \
206 { \
207 case RCC_USART1CLKSOURCE_PCLK1: \
208 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
209 break; \
210 case RCC_USART1CLKSOURCE_HSI: \
211 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
212 break; \
213 case RCC_USART1CLKSOURCE_SYSCLK: \
214 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
215 break; \
216 case RCC_USART1CLKSOURCE_LSE: \
217 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
218 break; \
219 default: \
220 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
221 break; \
222 } \
223 } \
224 else if((__HANDLE__)->Instance == USART2) \
225 { \
226 switch(__HAL_RCC_GET_USART2_SOURCE()) \
227 { \
228 case RCC_USART2CLKSOURCE_PCLK1: \
229 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
230 break; \
231 case RCC_USART2CLKSOURCE_HSI: \
232 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
233 break; \
234 case RCC_USART2CLKSOURCE_SYSCLK: \
235 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
236 break; \
237 case RCC_USART2CLKSOURCE_LSE: \
238 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
239 break; \
240 default: \
241 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
242 break; \
243 } \
244 } \
245 else if((__HANDLE__)->Instance == USART3) \
246 { \
247 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
248 } \
249 else if((__HANDLE__)->Instance == USART4) \
250 { \
251 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
252 } \
253 else \
254 { \
255 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
256 } \
257 } while(0)
258 #elif defined(STM32F091xC) || defined (STM32F098xx)
259 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
260 do { \
261 if((__HANDLE__)->Instance == USART1) \
262 { \
263 switch(__HAL_RCC_GET_USART1_SOURCE()) \
264 { \
265 case RCC_USART1CLKSOURCE_PCLK1: \
266 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
267 break; \
268 case RCC_USART1CLKSOURCE_HSI: \
269 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
270 break; \
271 case RCC_USART1CLKSOURCE_SYSCLK: \
272 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
273 break; \
274 case RCC_USART1CLKSOURCE_LSE: \
275 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
276 break; \
277 default: \
278 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
279 break; \
280 } \
281 } \
282 else if((__HANDLE__)->Instance == USART2) \
283 { \
284 switch(__HAL_RCC_GET_USART2_SOURCE()) \
285 { \
286 case RCC_USART2CLKSOURCE_PCLK1: \
287 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
288 break; \
289 case RCC_USART2CLKSOURCE_HSI: \
290 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
291 break; \
292 case RCC_USART2CLKSOURCE_SYSCLK: \
293 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
294 break; \
295 case RCC_USART2CLKSOURCE_LSE: \
296 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
297 break; \
298 default: \
299 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
300 break; \
301 } \
302 } \
303 else if((__HANDLE__)->Instance == USART3) \
304 { \
305 switch(__HAL_RCC_GET_USART3_SOURCE()) \
306 { \
307 case RCC_USART3CLKSOURCE_PCLK1: \
308 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
309 break; \
310 case RCC_USART3CLKSOURCE_HSI: \
311 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
312 break; \
313 case RCC_USART3CLKSOURCE_SYSCLK: \
314 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
315 break; \
316 case RCC_USART3CLKSOURCE_LSE: \
317 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
318 break; \
319 default: \
320 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
321 break; \
322 } \
323 } \
324 else if((__HANDLE__)->Instance == USART4) \
325 { \
326 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
327 } \
328 else if((__HANDLE__)->Instance == USART5) \
329 { \
330 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
331 } \
332 else if((__HANDLE__)->Instance == USART6) \
333 { \
334 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
335 } \
336 else if((__HANDLE__)->Instance == USART7) \
337 { \
338 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
339 } \
340 else if((__HANDLE__)->Instance == USART8) \
341 { \
342 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
343 } \
344 else \
345 { \
346 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
347 } \
348 } while(0)
349 #elif defined(STM32F030xC)
350 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
351 do { \
352 if((__HANDLE__)->Instance == USART1) \
353 { \
354 switch(__HAL_RCC_GET_USART1_SOURCE()) \
355 { \
356 case RCC_USART1CLKSOURCE_PCLK1: \
357 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
358 break; \
359 case RCC_USART1CLKSOURCE_HSI: \
360 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
361 break; \
362 case RCC_USART1CLKSOURCE_SYSCLK: \
363 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
364 break; \
365 case RCC_USART1CLKSOURCE_LSE: \
366 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
367 break; \
368 default: \
369 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
370 break; \
371 } \
372 } \
373 else if((__HANDLE__)->Instance == USART2) \
374 { \
375 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
376 } \
377 else if((__HANDLE__)->Instance == USART3) \
378 { \
379 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
380 } \
381 else if((__HANDLE__)->Instance == USART4) \
382 { \
383 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
384 } \
385 else if((__HANDLE__)->Instance == USART5) \
386 { \
387 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
388 } \
389 else if((__HANDLE__)->Instance == USART6) \
390 { \
391 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
392 } \
393 else \
394 { \
395 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
396 } \
397 } while(0)
398 #endif /* defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx) */
399
400
401 /** @brief Reports the USART mask to apply to retrieve the received data
402 * according to the word length and to the parity bits activation.
403 * If PCE = 1, the parity bit is not included in the data extracted
404 * by the reception API().
405 * This masking operation is not carried out in the case of
406 * DMA transfers.
407 * @param __HANDLE__: specifies the USART Handle
408 * @retval none
409 */
410 #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
411 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
412 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
413 #define __HAL_USART_MASK_COMPUTATION(__HANDLE__) \
414 do { \
415 if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \
416 { \
417 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
418 { \
419 (__HANDLE__)->Mask = 0x01FF ; \
420 } \
421 else \
422 { \
423 (__HANDLE__)->Mask = 0x00FF ; \
424 } \
425 } \
426 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \
427 { \
428 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
429 { \
430 (__HANDLE__)->Mask = 0x00FF ; \
431 } \
432 else \
433 { \
434 (__HANDLE__)->Mask = 0x007F ; \
435 } \
436 } \
437 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_7B) \
438 { \
439 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
440 { \
441 (__HANDLE__)->Mask = 0x007F ; \
442 } \
443 else \
444 { \
445 (__HANDLE__)->Mask = 0x003F ; \
446 } \
447 } \
448 } while(0)
449 #else
450 #define __HAL_USART_MASK_COMPUTATION(__HANDLE__) \
451 do { \
452 if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \
453 { \
454 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
455 { \
456 (__HANDLE__)->Mask = 0x01FF ; \
457 } \
458 else \
459 { \
460 (__HANDLE__)->Mask = 0x00FF ; \
461 } \
462 } \
463 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \
464 { \
465 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
466 { \
467 (__HANDLE__)->Mask = 0x00FF ; \
468 } \
469 else \
470 { \
471 (__HANDLE__)->Mask = 0x007F ; \
472 } \
473 } \
474 } while(0)
475 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
476 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
477 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
478 /**
479 * @}
480 */
481
482 /* Exported functions --------------------------------------------------------*/
483 /* Initialization and de-initialization functions ****************************/
484 /* I/O operation functions ***************************************************/
485 /* Peripheral Control functions **********************************************/
486 /* Peripheral State functions ************************************************/
487
488 /**
489 * @}
490 */
491
492 /**
493 * @}
494 */
495
496 #ifdef __cplusplus
497 }
498 #endif
499
500 #endif /* __STM32F0xx_HAL_USART_EX_H */
501
502 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
503
Imprint / Impressum