2 ******************************************************************************
3 * @file stm32f0xx_hal_uart_ex.h
4 * @author MCD Application Team
6 * @date 11-December-2014
7 * @brief Header file of UART 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_UART_EX_H
40 #define __STM32F0xx_HAL_UART_EX_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f0xx_hal_def.h"
49 /** @addtogroup STM32F0xx_HAL_Driver
53 /** @addtogroup UARTEx
57 /* Exported types ------------------------------------------------------------*/
58 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
59 /** @defgroup UARTEx_Exported_Types UARTEx Exported Types
64 * @brief UART wake up from stop mode parameters
68 uint32_t WakeUpEvent; /*!< Specifies which event will activat the Wakeup from Stop mode flag (WUF).
69 This parameter can be a value of @ref UART_WakeUp_from_Stop_Selection.
70 If set to UART_WAKEUP_ON_ADDRESS, the two other fields below must
73 uint16_t AddressLength; /*!< Specifies whether the address is 4 or 7-bit long.
74 This parameter can be a value of @ref UART_WakeUp_Address_Length */
76 uint8_t Address; /*!< UART/USART node address (7-bit long max) */
81 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
83 /* Exported constants --------------------------------------------------------*/
84 /** @defgroup UARTEx_Exported_Constants UARTEx Exported Constants
88 /** @defgroup UARTEx_Word_Length UARTEx Word Length
91 #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
92 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
93 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
94 #define UART_WORDLENGTH_7B ((uint32_t)USART_CR1_M1)
95 #define UART_WORDLENGTH_8B ((uint32_t)0x00000000)
96 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M0)
97 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_7B) || \
98 ((LENGTH) == UART_WORDLENGTH_8B) || \
99 ((LENGTH) == UART_WORDLENGTH_9B))
101 #define UART_WORDLENGTH_8B ((uint32_t)0x00000000)
102 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
103 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
104 ((LENGTH) == UART_WORDLENGTH_9B))
105 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
106 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
107 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
112 /** @defgroup UARTEx_AutoBaud_Rate_Mode UARTEx Advanced Feature AutoBaud Rate Mode
115 #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
116 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
117 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
118 #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT ((uint32_t)0x0000)
119 #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0)
120 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME ((uint32_t)USART_CR2_ABRMODE_1)
121 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME ((uint32_t)USART_CR2_ABRMODE)
122 #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(MODE) (((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
123 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
124 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME) || \
125 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
127 #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT ((uint32_t)0x0000)
128 #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0)
129 #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(MODE) (((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
130 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE))
131 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
132 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
133 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
139 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
140 /** @defgroup UARTEx_LIN UARTEx Local Interconnection Network mode
143 #define UART_LIN_DISABLE ((uint32_t)0x00000000)
144 #define UART_LIN_ENABLE ((uint32_t)USART_CR2_LINEN)
145 #define IS_UART_LIN(LIN) (((LIN) == UART_LIN_DISABLE) || \
146 ((LIN) == UART_LIN_ENABLE))
151 /** @defgroup UARTEx_LIN_Break_Detection UARTEx LIN Break Detection
154 #define UART_LINBREAKDETECTLENGTH_10B ((uint32_t)0x00000000)
155 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL)
156 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
157 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
161 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
163 /** @defgroup UART_Flags UARTEx Status Flags
164 * Elements values convention: 0xXXXX
165 * - 0xXXXX : Flag mask in the ISR register
168 #define UART_FLAG_REACK ((uint32_t)0x00400000)
169 #define UART_FLAG_TEACK ((uint32_t)0x00200000)
170 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
171 #define UART_FLAG_WUF ((uint32_t)0x00100000)
172 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
173 #define UART_FLAG_RWU ((uint32_t)0x00080000)
174 #define UART_FLAG_SBKF ((uint32_t)0x00040000
175 #define UART_FLAG_CMF ((uint32_t)0x00020000)
176 #define UART_FLAG_BUSY ((uint32_t)0x00010000)
177 #define UART_FLAG_ABRF ((uint32_t)0x00008000)
178 #define UART_FLAG_ABRE ((uint32_t)0x00004000)
179 #if !defined(STM32F030x6) && !defined(STM32F030x8)
180 #define UART_FLAG_EOBF ((uint32_t)0x00001000)
181 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) */
182 #define UART_FLAG_RTOF ((uint32_t)0x00000800)
183 #define UART_FLAG_CTS ((uint32_t)0x00000400)
184 #define UART_FLAG_CTSIF ((uint32_t)0x00000200)
185 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
186 #define UART_FLAG_LBDF ((uint32_t)0x00000100)
187 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
188 #define UART_FLAG_TXE ((uint32_t)0x00000080)
189 #define UART_FLAG_TC ((uint32_t)0x00000040)
190 #define UART_FLAG_RXNE ((uint32_t)0x00000020)
191 #define UART_FLAG_IDLE ((uint32_t)0x00000010)
192 #define UART_FLAG_ORE ((uint32_t)0x00000008)
193 #define UART_FLAG_NE ((uint32_t)0x00000004)
194 #define UART_FLAG_FE ((uint32_t)0x00000002)
195 #define UART_FLAG_PE ((uint32_t)0x00000001)
200 /** @defgroup UART_Interrupt_definition UARTEx Interrupts Definition
201 * Elements values convention: 0000ZZZZZ0XXYYYYYb
202 * - YYYYY : Interrupt source position in the XX register (5bits)
203 * - XX : Interrupt source register (2bits)
207 * - ZZZZZ : Flag position in the ISR register(5bits)
210 #define UART_IT_PE ((uint16_t)0x0028)
211 #define UART_IT_TXE ((uint16_t)0x0727)
212 #define UART_IT_TC ((uint16_t)0x0626)
213 #define UART_IT_RXNE ((uint16_t)0x0525)
214 #define UART_IT_IDLE ((uint16_t)0x0424)
215 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
216 #define UART_IT_LBD ((uint16_t)0x0846)
217 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
218 #define UART_IT_CTS ((uint16_t)0x096A)
219 #define UART_IT_CM ((uint16_t)0x112E)
220 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
221 #define UART_IT_WUF ((uint16_t)0x1476)
222 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
228 /** @defgroup UART_IT_CLEAR_Flags UARTEx Interruption Clear Flags
231 #define UART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
232 #define UART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
233 #define UART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
234 #define UART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
235 #define UART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
236 #define UART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
237 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
238 #define UART_CLEAR_LBDF USART_ICR_LBDCF /*!< LIN Break Detection Clear Flag (not available on F030xx devices)*/
239 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
240 #define UART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
241 #define UART_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
242 #define UART_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
243 #define UART_CLEAR_CMF USART_ICR_CMCF /*!< Character Match Clear Flag */
244 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
245 #define UART_CLEAR_WUF USART_ICR_WUCF /*!< Wake Up from stop mode Clear Flag */
246 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
251 /** @defgroup UART_Request_Parameters UARTEx Request Parameters
254 #define UART_AUTOBAUD_REQUEST ((uint32_t)USART_RQR_ABRRQ) /*!< Auto-Baud Rate Request */
255 #define UART_SENDBREAK_REQUEST ((uint32_t)USART_RQR_SBKRQ) /*!< Send Break Request */
256 #define UART_MUTE_MODE_REQUEST ((uint32_t)USART_RQR_MMRQ) /*!< Mute Mode Request */
257 #define UART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
258 #if !defined(STM32F030x6) && !defined(STM32F030x8)
259 #define UART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
260 #define IS_UART_REQUEST_PARAMETER(PARAM) (((PARAM) == UART_AUTOBAUD_REQUEST) || \
261 ((PARAM) == UART_SENDBREAK_REQUEST) || \
262 ((PARAM) == UART_MUTE_MODE_REQUEST) || \
263 ((PARAM) == UART_RXDATA_FLUSH_REQUEST) || \
264 ((PARAM) == UART_TXDATA_FLUSH_REQUEST))
266 #define IS_UART_REQUEST_PARAMETER(PARAM) (((PARAM) == UART_AUTOBAUD_REQUEST) || \
267 ((PARAM) == UART_SENDBREAK_REQUEST) || \
268 ((PARAM) == UART_MUTE_MODE_REQUEST) || \
269 ((PARAM) == UART_RXDATA_FLUSH_REQUEST))
270 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) */
275 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
276 /** @defgroup UART_Stop_Mode_Enable UARTEx Advanced Feature Stop Mode Enable
279 #define UART_ADVFEATURE_STOPMODE_DISABLE ((uint32_t)0x00000000)
280 #define UART_ADVFEATURE_STOPMODE_ENABLE ((uint32_t)USART_CR1_UESM)
281 #define IS_UART_ADVFEATURE_STOPMODE(STOPMODE) (((STOPMODE) == UART_ADVFEATURE_STOPMODE_DISABLE) || \
282 ((STOPMODE) == UART_ADVFEATURE_STOPMODE_ENABLE))
287 /** @defgroup UART_WakeUp_from_Stop_Selection UART WakeUp From Stop Selection
290 #define UART_WAKEUP_ON_ADDRESS ((uint32_t)0x0000)
291 #define UART_WAKEUP_ON_STARTBIT ((uint32_t)USART_CR3_WUS_1)
292 #define UART_WAKEUP_ON_READDATA_NONEMPTY ((uint32_t)USART_CR3_WUS)
293 #define IS_UART_WAKEUP_SELECTION(WAKE) (((WAKE) == UART_WAKEUP_ON_ADDRESS) || \
294 ((WAKE) == UART_WAKEUP_ON_STARTBIT) || \
295 ((WAKE) == UART_WAKEUP_ON_READDATA_NONEMPTY))
299 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
305 /* Exported macro ------------------------------------------------------------*/
307 /** @defgroup UARTEx_Exported_Macros UARTEx Exported Macros
311 /** @brief Reports the UART clock source.
312 * @param __HANDLE__: specifies the UART Handle
313 * @param __CLOCKSOURCE__ : output variable
314 * @retval UART clocking source, written in __CLOCKSOURCE__.
318 #if defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx)
319 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
321 switch(__HAL_RCC_GET_USART1_SOURCE()) \
323 case RCC_USART1CLKSOURCE_PCLK1: \
324 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
326 case RCC_USART1CLKSOURCE_HSI: \
327 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
329 case RCC_USART1CLKSOURCE_SYSCLK: \
330 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
332 case RCC_USART1CLKSOURCE_LSE: \
333 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
336 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
340 #elif defined (STM32F030x8) || defined (STM32F070x6) || \
341 defined (STM32F042x6) || defined (STM32F048xx) || \
342 defined (STM32F051x8) || defined (STM32F058xx)
343 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
345 if((__HANDLE__)->Instance == USART1) \
347 switch(__HAL_RCC_GET_USART1_SOURCE()) \
349 case RCC_USART1CLKSOURCE_PCLK1: \
350 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
352 case RCC_USART1CLKSOURCE_HSI: \
353 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
355 case RCC_USART1CLKSOURCE_SYSCLK: \
356 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
358 case RCC_USART1CLKSOURCE_LSE: \
359 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
362 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
366 else if((__HANDLE__)->Instance == USART2) \
368 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
372 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
375 #elif defined(STM32F070xB)
376 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
378 if((__HANDLE__)->Instance == USART1) \
380 switch(__HAL_RCC_GET_USART1_SOURCE()) \
382 case RCC_USART1CLKSOURCE_PCLK1: \
383 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
385 case RCC_USART1CLKSOURCE_HSI: \
386 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
388 case RCC_USART1CLKSOURCE_SYSCLK: \
389 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
391 case RCC_USART1CLKSOURCE_LSE: \
392 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
395 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
399 else if((__HANDLE__)->Instance == USART2) \
401 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
403 else if((__HANDLE__)->Instance == USART3) \
405 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
407 else if((__HANDLE__)->Instance == USART4) \
409 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
413 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
416 #elif defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)
417 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
419 if((__HANDLE__)->Instance == USART1) \
421 switch(__HAL_RCC_GET_USART1_SOURCE()) \
423 case RCC_USART1CLKSOURCE_PCLK1: \
424 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
426 case RCC_USART1CLKSOURCE_HSI: \
427 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
429 case RCC_USART1CLKSOURCE_SYSCLK: \
430 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
432 case RCC_USART1CLKSOURCE_LSE: \
433 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
436 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
440 else if((__HANDLE__)->Instance == USART2) \
442 switch(__HAL_RCC_GET_USART2_SOURCE()) \
444 case RCC_USART2CLKSOURCE_PCLK1: \
445 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
447 case RCC_USART2CLKSOURCE_HSI: \
448 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
450 case RCC_USART2CLKSOURCE_SYSCLK: \
451 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
453 case RCC_USART2CLKSOURCE_LSE: \
454 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
457 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
461 else if((__HANDLE__)->Instance == USART3) \
463 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
465 else if((__HANDLE__)->Instance == USART4) \
467 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
471 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
474 #elif defined(STM32F091xC) || defined (STM32F098xx)
475 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
477 if((__HANDLE__)->Instance == USART1) \
479 switch(__HAL_RCC_GET_USART1_SOURCE()) \
481 case RCC_USART1CLKSOURCE_PCLK1: \
482 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
484 case RCC_USART1CLKSOURCE_HSI: \
485 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
487 case RCC_USART1CLKSOURCE_SYSCLK: \
488 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
490 case RCC_USART1CLKSOURCE_LSE: \
491 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
494 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
498 else if((__HANDLE__)->Instance == USART2) \
500 switch(__HAL_RCC_GET_USART2_SOURCE()) \
502 case RCC_USART2CLKSOURCE_PCLK1: \
503 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
505 case RCC_USART2CLKSOURCE_HSI: \
506 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
508 case RCC_USART2CLKSOURCE_SYSCLK: \
509 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
511 case RCC_USART2CLKSOURCE_LSE: \
512 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
515 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
519 else if((__HANDLE__)->Instance == USART3) \
521 switch(__HAL_RCC_GET_USART3_SOURCE()) \
523 case RCC_USART3CLKSOURCE_PCLK1: \
524 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
526 case RCC_USART3CLKSOURCE_HSI: \
527 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
529 case RCC_USART3CLKSOURCE_SYSCLK: \
530 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
532 case RCC_USART3CLKSOURCE_LSE: \
533 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
536 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
540 else if((__HANDLE__)->Instance == USART4) \
542 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
544 else if((__HANDLE__)->Instance == USART5) \
546 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
548 else if((__HANDLE__)->Instance == USART6) \
550 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
552 else if((__HANDLE__)->Instance == USART7) \
554 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
556 else if((__HANDLE__)->Instance == USART8) \
558 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
562 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
565 #elif defined(STM32F030xC)
566 #define __HAL_UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
568 if((__HANDLE__)->Instance == USART1) \
570 switch(__HAL_RCC_GET_USART1_SOURCE()) \
572 case RCC_USART1CLKSOURCE_PCLK1: \
573 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
575 case RCC_USART1CLKSOURCE_HSI: \
576 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
578 case RCC_USART1CLKSOURCE_SYSCLK: \
579 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
581 case RCC_USART1CLKSOURCE_LSE: \
582 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
585 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
589 else if((__HANDLE__)->Instance == USART2) \
591 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
593 else if((__HANDLE__)->Instance == USART3) \
595 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
597 else if((__HANDLE__)->Instance == USART4) \
599 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
601 else if((__HANDLE__)->Instance == USART5) \
603 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
605 else if((__HANDLE__)->Instance == USART6) \
607 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
611 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \
615 #endif /* defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx) */
618 /** @brief Computes the UART mask to apply to retrieve the received data
619 * according to the word length and to the parity bits activation.
620 * If PCE = 1, the parity bit is not included in the data extracted
621 * by the reception API().
622 * This masking operation is not carried out in the case of
624 * @param __HANDLE__: specifies the UART Handle
627 #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
628 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
629 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
630 #define __HAL_UART_MASK_COMPUTATION(__HANDLE__) \
632 if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B) \
634 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
636 (__HANDLE__)->Mask = 0x01FF ; \
640 (__HANDLE__)->Mask = 0x00FF ; \
643 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B) \
645 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
647 (__HANDLE__)->Mask = 0x00FF ; \
651 (__HANDLE__)->Mask = 0x007F ; \
654 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_7B) \
656 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
658 (__HANDLE__)->Mask = 0x007F ; \
662 (__HANDLE__)->Mask = 0x003F ; \
667 #define __HAL_UART_MASK_COMPUTATION(__HANDLE__) \
669 if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B) \
671 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
673 (__HANDLE__)->Mask = 0x01FF ; \
677 (__HANDLE__)->Mask = 0x00FF ; \
680 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B) \
682 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
684 (__HANDLE__)->Mask = 0x00FF ; \
688 (__HANDLE__)->Mask = 0x007F ; \
692 #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
693 defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
694 defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
699 /* Exported functions --------------------------------------------------------*/
700 /** @addtogroup UARTEx_Exported_Functions
704 /** @addtogroup UARTEx_Exported_Functions_Group1
705 * @brief Extended Initialization and Configuration Functions
708 /* Initialization and de-initialization functions ****************************/
709 #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
710 HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t UART_DEPolarity, uint32_t UART_DEAssertionTime, uint32_t UART_DEDeassertionTime);
711 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
712 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
717 /** @addtogroup UARTEx_Exported_Functions_Group2
718 * @brief Extended UART Interrupt handling function
722 /* IO operation functions ***************************************************/
723 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
725 #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
726 void HAL_UART_WakeupCallback(UART_HandleTypeDef *huart);
727 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
732 /** @addtogroup UARTEx_Exported_Functions_Group3
733 * @brief Extended Peripheral Control functions
737 /* Peripheral Control functions **********************************************/
738 HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength);
739 #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6) && !defined(STM32F030xC)
740 HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
741 HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart);
742 HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart);
743 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
744 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
748 /* Peripheral State functions ************************************************/
767 #endif /* __STM32F0xx_HAL_UART_EX_H */
769 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/