a1b4cd25ab5f77a2d81abf2a7c4852de174c2519
2 ******************************************************************************
3 * @file stm32f7xx_hal_uart_ex.h
4 * @author MCD Application Team
7 * @brief Header file of UART HAL Extension module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2016 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 __STM32F7xx_HAL_UART_EX_H
40 #define __STM32F7xx_HAL_UART_EX_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f7xx_hal_def.h"
49 /** @addtogroup STM32F7xx_HAL_Driver
53 /** @addtogroup UARTEx
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /** @defgroup UARTEx_Exported_Constants UARTEx Exported Constants
63 /** @defgroup UARTEx_Word_Length UARTEx Word Length
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))
78 /** @defgroup UARTEx_WakeUp_Address_Length UARTEx WakeUp Address Length
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))
94 /* Exported macro ------------------------------------------------------------*/
96 /** @defgroup UARTEx_Exported_Macros UARTEx Exported Macros
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__.
105 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
107 if((__HANDLE__)->Instance == USART1) \
109 switch(__HAL_RCC_GET_USART1_SOURCE()) \
111 case RCC_USART1CLKSOURCE_PCLK2: \
112 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \
114 case RCC_USART1CLKSOURCE_HSI: \
115 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
117 case RCC_USART1CLKSOURCE_SYSCLK: \
118 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
120 case RCC_USART1CLKSOURCE_LSE: \
121 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
127 else if((__HANDLE__)->Instance == USART2) \
129 switch(__HAL_RCC_GET_USART2_SOURCE()) \
131 case RCC_USART2CLKSOURCE_PCLK1: \
132 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
134 case RCC_USART2CLKSOURCE_HSI: \
135 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
137 case RCC_USART2CLKSOURCE_SYSCLK: \
138 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
140 case RCC_USART2CLKSOURCE_LSE: \
141 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
147 else if((__HANDLE__)->Instance == USART3) \
149 switch(__HAL_RCC_GET_USART3_SOURCE()) \
151 case RCC_USART3CLKSOURCE_PCLK1: \
152 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
154 case RCC_USART3CLKSOURCE_HSI: \
155 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
157 case RCC_USART3CLKSOURCE_SYSCLK: \
158 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
160 case RCC_USART3CLKSOURCE_LSE: \
161 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
167 else if((__HANDLE__)->Instance == UART4) \
169 switch(__HAL_RCC_GET_UART4_SOURCE()) \
171 case RCC_UART4CLKSOURCE_PCLK1: \
172 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
174 case RCC_UART4CLKSOURCE_HSI: \
175 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
177 case RCC_UART4CLKSOURCE_SYSCLK: \
178 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
180 case RCC_UART4CLKSOURCE_LSE: \
181 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
187 else if ((__HANDLE__)->Instance == UART5) \
189 switch(__HAL_RCC_GET_UART5_SOURCE()) \
191 case RCC_UART5CLKSOURCE_PCLK1: \
192 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
194 case RCC_UART5CLKSOURCE_HSI: \
195 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
197 case RCC_UART5CLKSOURCE_SYSCLK: \
198 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
200 case RCC_UART5CLKSOURCE_LSE: \
201 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
207 else if((__HANDLE__)->Instance == USART6) \
209 switch(__HAL_RCC_GET_USART6_SOURCE()) \
211 case RCC_USART6CLKSOURCE_PCLK2: \
212 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \
214 case RCC_USART6CLKSOURCE_HSI: \
215 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
217 case RCC_USART6CLKSOURCE_SYSCLK: \
218 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
220 case RCC_USART6CLKSOURCE_LSE: \
221 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
227 else if ((__HANDLE__)->Instance == UART7) \
229 switch(__HAL_RCC_GET_UART7_SOURCE()) \
231 case RCC_UART7CLKSOURCE_PCLK1: \
232 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
234 case RCC_UART7CLKSOURCE_HSI: \
235 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
237 case RCC_UART7CLKSOURCE_SYSCLK: \
238 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
240 case RCC_UART7CLKSOURCE_LSE: \
241 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
247 else if ((__HANDLE__)->Instance == UART8) \
249 switch(__HAL_RCC_GET_UART8_SOURCE()) \
251 case RCC_UART8CLKSOURCE_PCLK1: \
252 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
254 case RCC_UART8CLKSOURCE_HSI: \
255 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
257 case RCC_UART8CLKSOURCE_SYSCLK: \
258 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
260 case RCC_UART8CLKSOURCE_LSE: \
261 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
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
275 * @param __HANDLE__: specifies the UART Handle
276 * @retval mask to apply to UART RDR register value.
278 #define UART_MASK_COMPUTATION(__HANDLE__) \
280 if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B) \
282 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
284 (__HANDLE__)->Mask = 0x01FF ; \
288 (__HANDLE__)->Mask = 0x00FF ; \
291 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B) \
293 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
295 (__HANDLE__)->Mask = 0x00FF ; \
299 (__HANDLE__)->Mask = 0x007F ; \
302 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_7B) \
304 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
306 (__HANDLE__)->Mask = 0x007F ; \
310 (__HANDLE__)->Mask = 0x003F ; \
319 /* Exported functions --------------------------------------------------------*/
321 /** @addtogroup UARTEx_Exported_Functions
325 /** @addtogroup UARTEx_Exported_Functions_Group1
329 /* Initialization and de-initialization functions ****************************/
330 HAL_StatusTypeDef
HAL_RS485Ex_Init(UART_HandleTypeDef
*huart
, uint32_t Polarity
, uint32_t AssertionTime
, uint32_t DeassertionTime
);
340 /** @addtogroup UARTEx_Exported_Functions_Group3
344 /* Peripheral Control functions **********************************************/
345 HAL_StatusTypeDef
HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef
*huart
, uint32_t AddressLength
);
363 #endif /* __STM32F7xx_HAL_UART_EX_H */
365 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/