]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_usart_ex.h
2 ******************************************************************************
3 * @file stm32f0xx_hal_usart_ex.h
4 * @author MCD Application Team
6 * @date 11-December-2014
7 * @brief Header file of USART HAL Extension module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
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.
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.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F0xx_HAL_USART_EX_H
40 #define __STM32F0xx_HAL_USART_EX_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f0xx_hal_def.h"
49 /** @addtogroup STM32F0xx_HAL_Driver
53 /** @defgroup USARTEx USARTEx Extended HAL module driver
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /** @defgroup USARTEx_Exported_Constants USARTEx Exported Constants
63 /** @defgroup USARTEx_Word_Length USARTEx Word Length
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))
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) */
91 /* Exported macro ------------------------------------------------------------*/
93 /** @defgroup USARTEx_Exported_Macros USARTEx Exported Macros
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__.
102 #if defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx)
103 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
105 switch(__HAL_RCC_GET_USART1_SOURCE()) \
107 case RCC_USART1CLKSOURCE_PCLK1: \
108 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
110 case RCC_USART1CLKSOURCE_HSI: \
111 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
113 case RCC_USART1CLKSOURCE_SYSCLK: \
114 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
116 case RCC_USART1CLKSOURCE_LSE: \
117 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
120 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
124 #elif defined (STM32F030x8) || defined (STM32F070x6) || \
125 defined (STM32F042x6) || defined (STM32F048xx) || \
126 defined (STM32F051x8) || defined (STM32F058xx)
127 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
129 if((__HANDLE__)->Instance == USART1) \
131 switch(__HAL_RCC_GET_USART1_SOURCE()) \
133 case RCC_USART1CLKSOURCE_PCLK1: \
134 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
136 case RCC_USART1CLKSOURCE_HSI: \
137 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
139 case RCC_USART1CLKSOURCE_SYSCLK: \
140 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
142 case RCC_USART1CLKSOURCE_LSE: \
143 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
146 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
150 else if((__HANDLE__)->Instance == USART2) \
152 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
156 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
159 #elif defined (STM32F070xB)
160 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
162 if((__HANDLE__)->Instance == USART1) \
164 switch(__HAL_RCC_GET_USART1_SOURCE()) \
166 case RCC_USART1CLKSOURCE_PCLK1: \
167 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
169 case RCC_USART1CLKSOURCE_HSI: \
170 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
172 case RCC_USART1CLKSOURCE_SYSCLK: \
173 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
175 case RCC_USART1CLKSOURCE_LSE: \
176 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
179 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
183 else if((__HANDLE__)->Instance == USART2) \
185 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
187 else if((__HANDLE__)->Instance == USART3) \
189 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
191 else if((__HANDLE__)->Instance == USART4) \
193 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
197 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
200 #elif defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)
201 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
203 if((__HANDLE__)->Instance == USART1) \
205 switch(__HAL_RCC_GET_USART1_SOURCE()) \
207 case RCC_USART1CLKSOURCE_PCLK1: \
208 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
210 case RCC_USART1CLKSOURCE_HSI: \
211 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
213 case RCC_USART1CLKSOURCE_SYSCLK: \
214 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
216 case RCC_USART1CLKSOURCE_LSE: \
217 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
220 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
224 else if((__HANDLE__)->Instance == USART2) \
226 switch(__HAL_RCC_GET_USART2_SOURCE()) \
228 case RCC_USART2CLKSOURCE_PCLK1: \
229 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
231 case RCC_USART2CLKSOURCE_HSI: \
232 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
234 case RCC_USART2CLKSOURCE_SYSCLK: \
235 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
237 case RCC_USART2CLKSOURCE_LSE: \
238 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
241 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
245 else if((__HANDLE__)->Instance == USART3) \
247 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
249 else if((__HANDLE__)->Instance == USART4) \
251 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
255 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
258 #elif defined(STM32F091xC) || defined (STM32F098xx)
259 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
261 if((__HANDLE__)->Instance == USART1) \
263 switch(__HAL_RCC_GET_USART1_SOURCE()) \
265 case RCC_USART1CLKSOURCE_PCLK1: \
266 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
268 case RCC_USART1CLKSOURCE_HSI: \
269 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
271 case RCC_USART1CLKSOURCE_SYSCLK: \
272 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
274 case RCC_USART1CLKSOURCE_LSE: \
275 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
278 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
282 else if((__HANDLE__)->Instance == USART2) \
284 switch(__HAL_RCC_GET_USART2_SOURCE()) \
286 case RCC_USART2CLKSOURCE_PCLK1: \
287 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
289 case RCC_USART2CLKSOURCE_HSI: \
290 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
292 case RCC_USART2CLKSOURCE_SYSCLK: \
293 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
295 case RCC_USART2CLKSOURCE_LSE: \
296 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
299 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
303 else if((__HANDLE__)->Instance == USART3) \
305 switch(__HAL_RCC_GET_USART3_SOURCE()) \
307 case RCC_USART3CLKSOURCE_PCLK1: \
308 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
310 case RCC_USART3CLKSOURCE_HSI: \
311 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
313 case RCC_USART3CLKSOURCE_SYSCLK: \
314 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
316 case RCC_USART3CLKSOURCE_LSE: \
317 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
320 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
324 else if((__HANDLE__)->Instance == USART4) \
326 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
328 else if((__HANDLE__)->Instance == USART5) \
330 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
332 else if((__HANDLE__)->Instance == USART6) \
334 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
336 else if((__HANDLE__)->Instance == USART7) \
338 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
340 else if((__HANDLE__)->Instance == USART8) \
342 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
346 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
349 #elif defined(STM32F030xC)
350 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
352 if((__HANDLE__)->Instance == USART1) \
354 switch(__HAL_RCC_GET_USART1_SOURCE()) \
356 case RCC_USART1CLKSOURCE_PCLK1: \
357 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
359 case RCC_USART1CLKSOURCE_HSI: \
360 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
362 case RCC_USART1CLKSOURCE_SYSCLK: \
363 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
365 case RCC_USART1CLKSOURCE_LSE: \
366 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
369 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
373 else if((__HANDLE__)->Instance == USART2) \
375 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
377 else if((__HANDLE__)->Instance == USART3) \
379 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
381 else if((__HANDLE__)->Instance == USART4) \
383 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
385 else if((__HANDLE__)->Instance == USART5) \
387 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
389 else if((__HANDLE__)->Instance == USART6) \
391 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
395 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
398 #endif /* defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx) */
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
407 * @param __HANDLE__: specifies the USART Handle
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__) \
415 if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \
417 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
419 (__HANDLE__)->Mask = 0x01FF ; \
423 (__HANDLE__)->Mask = 0x00FF ; \
426 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \
428 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
430 (__HANDLE__)->Mask = 0x00FF ; \
434 (__HANDLE__)->Mask = 0x007F ; \
437 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_7B) \
439 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
441 (__HANDLE__)->Mask = 0x007F ; \
445 (__HANDLE__)->Mask = 0x003F ; \
450 #define __HAL_USART_MASK_COMPUTATION(__HANDLE__) \
452 if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \
454 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
456 (__HANDLE__)->Mask = 0x01FF ; \
460 (__HANDLE__)->Mask = 0x00FF ; \
463 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \
465 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
467 (__HANDLE__)->Mask = 0x00FF ; \
471 (__HANDLE__)->Mask = 0x007F ; \
475 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
476 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
477 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
482 /* Exported functions --------------------------------------------------------*/
483 /* Initialization and de-initialization functions ****************************/
484 /* I/O operation functions ***************************************************/
485 /* Peripheral Control functions **********************************************/
486 /* Peripheral State functions ************************************************/
500 #endif /* __STM32F0xx_HAL_USART_EX_H */
502 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/