a1b4cd25ab5f77a2d81abf2a7c4852de174c2519
[mTask.git] / int / com / lib / STM32F7xx_HAL_Driver / Inc / stm32f7xx_hal_uart_ex.h
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_hal_uart_ex.h
4 * @author MCD Application Team
5 * @version V1.1.0
6 * @date 22-April-2016
7 * @brief Header file of UART HAL Extension module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2016 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 __STM32F7xx_HAL_UART_EX_H
40 #define __STM32F7xx_HAL_UART_EX_H
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f7xx_hal_def.h"
48
49 /** @addtogroup STM32F7xx_HAL_Driver
50 * @{
51 */
52
53 /** @addtogroup UARTEx
54 * @{
55 */
56
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /** @defgroup UARTEx_Exported_Constants UARTEx Exported Constants
60 * @{
61 */
62
63 /** @defgroup UARTEx_Word_Length UARTEx Word Length
64 * @{
65 */
66 #define UART_WORDLENGTH_7B ((uint32_t)USART_CR1_M_1)
67 #define UART_WORDLENGTH_8B ((uint32_t)0x0000U)
68 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M_0)
69 #define IS_UART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == UART_WORDLENGTH_7B) || \
70 ((__LENGTH__) == UART_WORDLENGTH_8B) || \
71 ((__LENGTH__) == UART_WORDLENGTH_9B))
72 #define IS_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B))
73 /**
74 * @}
75 */
76
77
78 /** @defgroup UARTEx_WakeUp_Address_Length UARTEx WakeUp Address Length
79 * @{
80 */
81 #define UART_ADDRESS_DETECT_4B ((uint32_t)0x00000000U)
82 #define UART_ADDRESS_DETECT_7B ((uint32_t)USART_CR2_ADDM7)
83 #define IS_UART_ADDRESSLENGTH_DETECT(__ADDRESS__) (((__ADDRESS__) == UART_ADDRESS_DETECT_4B) || \
84 ((__ADDRESS__) == UART_ADDRESS_DETECT_7B))
85 /**
86 * @}
87 */
88
89
90 /**
91 * @}
92 */
93
94 /* Exported macro ------------------------------------------------------------*/
95
96 /** @defgroup UARTEx_Exported_Macros UARTEx Exported Macros
97 * @{
98 */
99
100 /** @brief Reports the UART clock source.
101 * @param __HANDLE__: specifies the UART Handle
102 * @param __CLOCKSOURCE__: output variable
103 * @retval UART clocking source, written in __CLOCKSOURCE__.
104 */
105 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
106 do { \
107 if((__HANDLE__)->Instance == USART1) \
108 { \
109 switch(__HAL_RCC_GET_USART1_SOURCE()) \
110 { \
111 case RCC_USART1CLKSOURCE_PCLK2: \
112 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \
113 break; \
114 case RCC_USART1CLKSOURCE_HSI: \
115 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
116 break; \
117 case RCC_USART1CLKSOURCE_SYSCLK: \
118 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
119 break; \
120 case RCC_USART1CLKSOURCE_LSE: \
121 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
122 break; \
123 default: \
124 break; \
125 } \
126 } \
127 else if((__HANDLE__)->Instance == USART2) \
128 { \
129 switch(__HAL_RCC_GET_USART2_SOURCE()) \
130 { \
131 case RCC_USART2CLKSOURCE_PCLK1: \
132 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
133 break; \
134 case RCC_USART2CLKSOURCE_HSI: \
135 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
136 break; \
137 case RCC_USART2CLKSOURCE_SYSCLK: \
138 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
139 break; \
140 case RCC_USART2CLKSOURCE_LSE: \
141 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
142 break; \
143 default: \
144 break; \
145 } \
146 } \
147 else if((__HANDLE__)->Instance == USART3) \
148 { \
149 switch(__HAL_RCC_GET_USART3_SOURCE()) \
150 { \
151 case RCC_USART3CLKSOURCE_PCLK1: \
152 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
153 break; \
154 case RCC_USART3CLKSOURCE_HSI: \
155 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
156 break; \
157 case RCC_USART3CLKSOURCE_SYSCLK: \
158 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
159 break; \
160 case RCC_USART3CLKSOURCE_LSE: \
161 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
162 break; \
163 default: \
164 break; \
165 } \
166 } \
167 else if((__HANDLE__)->Instance == UART4) \
168 { \
169 switch(__HAL_RCC_GET_UART4_SOURCE()) \
170 { \
171 case RCC_UART4CLKSOURCE_PCLK1: \
172 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
173 break; \
174 case RCC_UART4CLKSOURCE_HSI: \
175 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
176 break; \
177 case RCC_UART4CLKSOURCE_SYSCLK: \
178 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
179 break; \
180 case RCC_UART4CLKSOURCE_LSE: \
181 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
182 break; \
183 default: \
184 break; \
185 } \
186 } \
187 else if ((__HANDLE__)->Instance == UART5) \
188 { \
189 switch(__HAL_RCC_GET_UART5_SOURCE()) \
190 { \
191 case RCC_UART5CLKSOURCE_PCLK1: \
192 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
193 break; \
194 case RCC_UART5CLKSOURCE_HSI: \
195 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
196 break; \
197 case RCC_UART5CLKSOURCE_SYSCLK: \
198 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
199 break; \
200 case RCC_UART5CLKSOURCE_LSE: \
201 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
202 break; \
203 default: \
204 break; \
205 } \
206 } \
207 else if((__HANDLE__)->Instance == USART6) \
208 { \
209 switch(__HAL_RCC_GET_USART6_SOURCE()) \
210 { \
211 case RCC_USART6CLKSOURCE_PCLK2: \
212 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \
213 break; \
214 case RCC_USART6CLKSOURCE_HSI: \
215 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
216 break; \
217 case RCC_USART6CLKSOURCE_SYSCLK: \
218 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
219 break; \
220 case RCC_USART6CLKSOURCE_LSE: \
221 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
222 break; \
223 default: \
224 break; \
225 } \
226 } \
227 else if ((__HANDLE__)->Instance == UART7) \
228 { \
229 switch(__HAL_RCC_GET_UART7_SOURCE()) \
230 { \
231 case RCC_UART7CLKSOURCE_PCLK1: \
232 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
233 break; \
234 case RCC_UART7CLKSOURCE_HSI: \
235 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
236 break; \
237 case RCC_UART7CLKSOURCE_SYSCLK: \
238 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
239 break; \
240 case RCC_UART7CLKSOURCE_LSE: \
241 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
242 break; \
243 default: \
244 break; \
245 } \
246 } \
247 else if ((__HANDLE__)->Instance == UART8) \
248 { \
249 switch(__HAL_RCC_GET_UART8_SOURCE()) \
250 { \
251 case RCC_UART8CLKSOURCE_PCLK1: \
252 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
253 break; \
254 case RCC_UART8CLKSOURCE_HSI: \
255 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
256 break; \
257 case RCC_UART8CLKSOURCE_SYSCLK: \
258 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
259 break; \
260 case RCC_UART8CLKSOURCE_LSE: \
261 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
262 break; \
263 default: \
264 break; \
265 } \
266 } \
267 } while(0)
268
269 /** @brief Reports the UART mask to apply to retrieve the received data
270 * according to the word length and to the parity bits activation.
271 * If PCE = 1, the parity bit is not included in the data extracted
272 * by the reception API().
273 * This masking operation is not carried out in the case of
274 * DMA transfers.
275 * @param __HANDLE__: specifies the UART Handle
276 * @retval mask to apply to UART RDR register value.
277 */
278 #define UART_MASK_COMPUTATION(__HANDLE__) \
279 do { \
280 if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B) \
281 { \
282 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
283 { \
284 (__HANDLE__)->Mask = 0x01FF ; \
285 } \
286 else \
287 { \
288 (__HANDLE__)->Mask = 0x00FF ; \
289 } \
290 } \
291 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B) \
292 { \
293 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
294 { \
295 (__HANDLE__)->Mask = 0x00FF ; \
296 } \
297 else \
298 { \
299 (__HANDLE__)->Mask = 0x007F ; \
300 } \
301 } \
302 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_7B) \
303 { \
304 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
305 { \
306 (__HANDLE__)->Mask = 0x007F ; \
307 } \
308 else \
309 { \
310 (__HANDLE__)->Mask = 0x003F ; \
311 } \
312 } \
313 } while(0)
314
315 /**
316 * @}
317 */
318
319 /* Exported functions --------------------------------------------------------*/
320
321 /** @addtogroup UARTEx_Exported_Functions
322 * @{
323 */
324
325 /** @addtogroup UARTEx_Exported_Functions_Group1
326 * @{
327 */
328
329 /* Initialization and de-initialization functions ****************************/
330 HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime, uint32_t DeassertionTime);
331
332 /**
333 * @}
334 */
335
336 /**
337 * @}
338 */
339
340 /** @addtogroup UARTEx_Exported_Functions_Group3
341 * @{
342 */
343
344 /* Peripheral Control functions **********************************************/
345 HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength);
346
347 /**
348 * @}
349 */
350
351 /**
352 * @}
353 */
354
355 /**
356 * @}
357 */
358
359 #ifdef __cplusplus
360 }
361 #endif
362
363 #endif /* __STM32F7xx_HAL_UART_EX_H */
364
365 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/