2 ******************************************************************************
3 * @file stm32f3xx_hal_usart_ex.h
4 * @author MCD Application Team
7 * @brief Header file of USART HAL Extended 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 __STM32F3xx_HAL_USART_EX_H
40 #define __STM32F3xx_HAL_USART_EX_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f3xx_hal_def.h"
49 /** @addtogroup STM32F3xx_HAL_Driver
53 /** @defgroup USARTEx USART Extended HAL module driver
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /** @defgroup USARTEx_Exported_Constants USART Extended Exported Constants
63 /** @defgroup USARTEx_Word_Length USART Extended Word Length
66 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
67 defined(STM32F334x8) || \
68 defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
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 /* STM32F302xE || STM32F303xE || STM32F398xx || */
82 /* STM32F301x8 || STM32F302x8 || STM32F318xx */
94 /* Exported macro ------------------------------------------------------------*/
96 /** @defgroup USARTEx_Exported_Macros USART Extended Exported Macros
101 /** @brief Reports the USART clock source.
102 * @param __HANDLE__: specifies the USART Handle
103 * @param __CLOCKSOURCE__ : output variable
104 * @retval the USART clocking source, written in __CLOCKSOURCE__.
106 #if defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx)
107 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
109 if((__HANDLE__)->Instance == USART1) \
111 switch(__HAL_RCC_GET_USART1_SOURCE()) \
113 case RCC_USART1CLKSOURCE_PCLK1: \
114 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
116 case RCC_USART1CLKSOURCE_HSI: \
117 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
119 case RCC_USART1CLKSOURCE_SYSCLK: \
120 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
122 case RCC_USART1CLKSOURCE_LSE: \
123 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
127 else if((__HANDLE__)->Instance == USART2) \
129 switch(__HAL_RCC_GET_USART2_SOURCE()) \
131 case RCC_USART2CLKSOURCE_PCLK1: \
132 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
134 case RCC_USART2CLKSOURCE_HSI: \
135 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
137 case RCC_USART2CLKSOURCE_SYSCLK: \
138 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
140 case RCC_USART2CLKSOURCE_LSE: \
141 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
145 else if((__HANDLE__)->Instance == USART3) \
147 switch(__HAL_RCC_GET_USART3_SOURCE()) \
149 case RCC_USART3CLKSOURCE_PCLK1: \
150 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
152 case RCC_USART3CLKSOURCE_HSI: \
153 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
155 case RCC_USART3CLKSOURCE_SYSCLK: \
156 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
158 case RCC_USART3CLKSOURCE_LSE: \
159 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
165 #define __HAL_USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
167 if((__HANDLE__)->Instance == USART1) \
169 switch(__HAL_RCC_GET_USART1_SOURCE()) \
171 case RCC_USART1CLKSOURCE_PCLK2: \
172 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK2; \
174 case RCC_USART1CLKSOURCE_HSI: \
175 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
177 case RCC_USART1CLKSOURCE_SYSCLK: \
178 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
180 case RCC_USART1CLKSOURCE_LSE: \
181 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
185 else if((__HANDLE__)->Instance == USART2) \
187 switch(__HAL_RCC_GET_USART2_SOURCE()) \
189 case RCC_USART2CLKSOURCE_PCLK1: \
190 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
192 case RCC_USART2CLKSOURCE_HSI: \
193 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
195 case RCC_USART2CLKSOURCE_SYSCLK: \
196 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
198 case RCC_USART2CLKSOURCE_LSE: \
199 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
203 else if((__HANDLE__)->Instance == USART3) \
205 switch(__HAL_RCC_GET_USART3_SOURCE()) \
207 case RCC_USART3CLKSOURCE_PCLK1: \
208 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
210 case RCC_USART3CLKSOURCE_HSI: \
211 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
213 case RCC_USART3CLKSOURCE_SYSCLK: \
214 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
216 case RCC_USART3CLKSOURCE_LSE: \
217 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
222 #endif /* STM32F303x8 || STM32F334x8 || STM32F328xx */
224 /** @brief Computes the USART mask to apply to retrieve the received data
225 * according to the word length and to the parity bits activation.
226 * If PCE = 1, the parity bit is not included in the data extracted
227 * by the reception API().
228 * This masking operation is not carried out in the case of
230 * @param __HANDLE__: specifies the USART Handle
233 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
234 defined(STM32F334x8) || \
235 defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
236 #define __HAL_USART_MASK_COMPUTATION(__HANDLE__) \
238 if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \
240 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
242 (__HANDLE__)->Mask = 0x01FF ; \
246 (__HANDLE__)->Mask = 0x00FF ; \
249 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \
251 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
253 (__HANDLE__)->Mask = 0x00FF ; \
257 (__HANDLE__)->Mask = 0x007F ; \
260 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_7B) \
262 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
264 (__HANDLE__)->Mask = 0x007F ; \
268 (__HANDLE__)->Mask = 0x003F ; \
273 #define __HAL_USART_MASK_COMPUTATION(__HANDLE__) \
275 if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \
277 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
279 (__HANDLE__)->Mask = 0x01FF ; \
283 (__HANDLE__)->Mask = 0x00FF ; \
286 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \
288 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
290 (__HANDLE__)->Mask = 0x00FF ; \
294 (__HANDLE__)->Mask = 0x007F ; \
298 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
300 /* STM32F301x8 || STM32F302x8 || STM32F318xx */
305 /* Exported functions --------------------------------------------------------*/
306 /* Initialization and de-initialization functions ****************************/
307 /* IO operation functions *****************************************************/
308 /* Peripheral Control functions ***********************************************/
309 /* Peripheral State and Error functions ***************************************/
324 #endif /* __STM32F3xx_HAL_USART_EX_H */
326 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/