1 /** 2 ****************************************************************************** 3 * @file stm32wbxx_hal_uart_ex.h 4 * @author MCD Application Team 5 * @brief Header file of UART HAL Extended module. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© Copyright (c) 2019 STMicroelectronics. 10 * All rights reserved.</center></h2> 11 * 12 * This software component is licensed by ST under BSD 3-Clause license, 13 * the "License"; You may not use this file except in compliance with the 14 * License. You may obtain a copy of the License at: 15 * opensource.org/licenses/BSD-3-Clause 16 * 17 ****************************************************************************** 18 */ 19 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef STM32WBxx_HAL_UART_EX_H 22 #define STM32WBxx_HAL_UART_EX_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32wbxx_hal_def.h" 30 31 /** @addtogroup STM32WBxx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup UARTEx 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /** @defgroup UARTEx_Exported_Types UARTEx Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief UART wake up from stop mode parameters 46 */ 47 typedef struct 48 { 49 uint32_t WakeUpEvent; /*!< Specifies which event will activate the Wakeup from Stop mode flag (WUF). 50 This parameter can be a value of @ref UART_WakeUp_from_Stop_Selection. 51 If set to UART_WAKEUP_ON_ADDRESS, the two other fields below must 52 be filled up. */ 53 54 uint16_t AddressLength; /*!< Specifies whether the address is 4 or 7-bit long. 55 This parameter can be a value of @ref UARTEx_WakeUp_Address_Length. */ 56 57 uint8_t Address; /*!< UART/USART node address (7-bit long max). */ 58 } UART_WakeUpTypeDef; 59 60 /** 61 * @} 62 */ 63 64 /* Exported constants --------------------------------------------------------*/ 65 /** @defgroup UARTEx_Exported_Constants UARTEx Exported Constants 66 * @{ 67 */ 68 69 /** @defgroup UARTEx_Word_Length UARTEx Word Length 70 * @{ 71 */ 72 #define UART_WORDLENGTH_7B USART_CR1_M1 /*!< 7-bit long UART frame */ 73 #define UART_WORDLENGTH_8B 0x00000000U /*!< 8-bit long UART frame */ 74 #define UART_WORDLENGTH_9B USART_CR1_M0 /*!< 9-bit long UART frame */ 75 /** 76 * @} 77 */ 78 79 /** @defgroup UARTEx_WakeUp_Address_Length UARTEx WakeUp Address Length 80 * @{ 81 */ 82 #define UART_ADDRESS_DETECT_4B 0x00000000U /*!< 4-bit long wake-up address */ 83 #define UART_ADDRESS_DETECT_7B USART_CR2_ADDM7 /*!< 7-bit long wake-up address */ 84 /** 85 * @} 86 */ 87 88 /** @defgroup UARTEx_FIFO_mode UARTEx FIFO mode 89 * @brief UART FIFO mode 90 * @{ 91 */ 92 #define UART_FIFOMODE_DISABLE 0x00000000U /*!< FIFO mode disable */ 93 #define UART_FIFOMODE_ENABLE USART_CR1_FIFOEN /*!< FIFO mode enable */ 94 /** 95 * @} 96 */ 97 98 /** @defgroup UARTEx_TXFIFO_threshold_level UARTEx TXFIFO threshold level 99 * @brief UART TXFIFO threshold level 100 * @{ 101 */ 102 #define UART_TXFIFO_THRESHOLD_1_8 0x00000000U /*!< TXFIFO reaches 1/8 of its depth */ 103 #define UART_TXFIFO_THRESHOLD_1_4 USART_CR3_TXFTCFG_0 /*!< TXFIFO reaches 1/4 of its depth */ 104 #define UART_TXFIFO_THRESHOLD_1_2 USART_CR3_TXFTCFG_1 /*!< TXFIFO reaches 1/2 of its depth */ 105 #define UART_TXFIFO_THRESHOLD_3_4 (USART_CR3_TXFTCFG_0|USART_CR3_TXFTCFG_1) /*!< TXFIFO reaches 3/4 of its depth */ 106 #define UART_TXFIFO_THRESHOLD_7_8 USART_CR3_TXFTCFG_2 /*!< TXFIFO reaches 7/8 of its depth */ 107 #define UART_TXFIFO_THRESHOLD_8_8 (USART_CR3_TXFTCFG_2|USART_CR3_TXFTCFG_0) /*!< TXFIFO becomes empty */ 108 /** 109 * @} 110 */ 111 112 /** @defgroup UARTEx_RXFIFO_threshold_level UARTEx RXFIFO threshold level 113 * @brief UART RXFIFO threshold level 114 * @{ 115 */ 116 #define UART_RXFIFO_THRESHOLD_1_8 0x00000000U /*!< RXFIFO FIFO reaches 1/8 of its depth */ 117 #define UART_RXFIFO_THRESHOLD_1_4 USART_CR3_RXFTCFG_0 /*!< RXFIFO FIFO reaches 1/4 of its depth */ 118 #define UART_RXFIFO_THRESHOLD_1_2 USART_CR3_RXFTCFG_1 /*!< RXFIFO FIFO reaches 1/2 of its depth */ 119 #define UART_RXFIFO_THRESHOLD_3_4 (USART_CR3_RXFTCFG_0|USART_CR3_RXFTCFG_1) /*!< RXFIFO FIFO reaches 3/4 of its depth */ 120 #define UART_RXFIFO_THRESHOLD_7_8 USART_CR3_RXFTCFG_2 /*!< RXFIFO FIFO reaches 7/8 of its depth */ 121 #define UART_RXFIFO_THRESHOLD_8_8 (USART_CR3_RXFTCFG_2|USART_CR3_RXFTCFG_0) /*!< RXFIFO FIFO becomes full */ 122 /** 123 * @} 124 */ 125 126 /** 127 * @} 128 */ 129 130 /* Exported macros -----------------------------------------------------------*/ 131 /* Exported functions --------------------------------------------------------*/ 132 /** @addtogroup UARTEx_Exported_Functions 133 * @{ 134 */ 135 136 /** @addtogroup UARTEx_Exported_Functions_Group1 137 * @{ 138 */ 139 140 /* Initialization and de-initialization functions ****************************/ 141 HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime, 142 uint32_t DeassertionTime); 143 144 /** 145 * @} 146 */ 147 148 /** @addtogroup UARTEx_Exported_Functions_Group2 149 * @{ 150 */ 151 152 void HAL_UARTEx_WakeupCallback(UART_HandleTypeDef *huart); 153 154 void HAL_UARTEx_RxFifoFullCallback(UART_HandleTypeDef *huart); 155 void HAL_UARTEx_TxFifoEmptyCallback(UART_HandleTypeDef *huart); 156 157 /** 158 * @} 159 */ 160 161 /** @addtogroup UARTEx_Exported_Functions_Group3 162 * @{ 163 */ 164 165 /* Peripheral Control functions **********************************************/ 166 HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection); 167 HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart); 168 HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart); 169 170 HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength); 171 172 HAL_StatusTypeDef HAL_UARTEx_EnableFifoMode(UART_HandleTypeDef *huart); 173 HAL_StatusTypeDef HAL_UARTEx_DisableFifoMode(UART_HandleTypeDef *huart); 174 HAL_StatusTypeDef HAL_UARTEx_SetTxFifoThreshold(UART_HandleTypeDef *huart, uint32_t Threshold); 175 HAL_StatusTypeDef HAL_UARTEx_SetRxFifoThreshold(UART_HandleTypeDef *huart, uint32_t Threshold); 176 177 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint16_t *RxLen, uint32_t Timeout); 178 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); 179 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); 180 181 182 /** 183 * @} 184 */ 185 186 /** 187 * @} 188 */ 189 190 /* Private macros ------------------------------------------------------------*/ 191 /** @defgroup UARTEx_Private_Macros UARTEx Private Macros 192 * @{ 193 */ 194 195 /** @brief Report the UART clock source. 196 * @param __HANDLE__ specifies the UART Handle. 197 * @param __CLOCKSOURCE__ output variable. 198 * @retval UART clocking source, written in __CLOCKSOURCE__. 199 */ 200 #if defined (LPUART1) 201 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ 202 do { \ 203 if((__HANDLE__)->Instance == USART1) \ 204 { \ 205 switch(__HAL_RCC_GET_USART1_SOURCE()) \ 206 { \ 207 case RCC_USART1CLKSOURCE_PCLK2: \ 208 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \ 209 break; \ 210 case RCC_USART1CLKSOURCE_HSI: \ 211 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ 212 break; \ 213 case RCC_USART1CLKSOURCE_SYSCLK: \ 214 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ 215 break; \ 216 case RCC_USART1CLKSOURCE_LSE: \ 217 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ 218 break; \ 219 default: \ 220 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \ 221 break; \ 222 } \ 223 } \ 224 else if((__HANDLE__)->Instance == LPUART1) \ 225 { \ 226 switch(__HAL_RCC_GET_LPUART1_SOURCE()) \ 227 { \ 228 case RCC_LPUART1CLKSOURCE_PCLK1: \ 229 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \ 230 break; \ 231 case RCC_LPUART1CLKSOURCE_HSI: \ 232 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ 233 break; \ 234 case RCC_LPUART1CLKSOURCE_SYSCLK: \ 235 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ 236 break; \ 237 case RCC_LPUART1CLKSOURCE_LSE: \ 238 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ 239 break; \ 240 default: \ 241 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \ 242 break; \ 243 } \ 244 } \ 245 else \ 246 { \ 247 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \ 248 } \ 249 } while(0U) 250 #else 251 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ 252 do { \ 253 if((__HANDLE__)->Instance == USART1) \ 254 { \ 255 switch(__HAL_RCC_GET_USART1_SOURCE()) \ 256 { \ 257 case RCC_USART1CLKSOURCE_PCLK2: \ 258 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \ 259 break; \ 260 case RCC_USART1CLKSOURCE_HSI: \ 261 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \ 262 break; \ 263 case RCC_USART1CLKSOURCE_SYSCLK: \ 264 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \ 265 break; \ 266 case RCC_USART1CLKSOURCE_LSE: \ 267 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \ 268 break; \ 269 default: \ 270 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \ 271 break; \ 272 } \ 273 } \ 274 else \ 275 { \ 276 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_UNDEFINED; \ 277 } \ 278 } while(0U) 279 #endif /* LPUART1 */ 280 281 /** @brief Report the UART mask to apply to retrieve the received data 282 * according to the word length and to the parity bits activation. 283 * @note If PCE = 1, the parity bit is not included in the data extracted 284 * by the reception API(). 285 * This masking operation is not carried out in the case of 286 * DMA transfers. 287 * @param __HANDLE__ specifies the UART Handle. 288 * @retval None, the mask to apply to UART RDR register is stored in (__HANDLE__)->Mask field. 289 */ 290 #define UART_MASK_COMPUTATION(__HANDLE__) \ 291 do { \ 292 if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B) \ 293 { \ 294 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \ 295 { \ 296 (__HANDLE__)->Mask = 0x01FFU ; \ 297 } \ 298 else \ 299 { \ 300 (__HANDLE__)->Mask = 0x00FFU ; \ 301 } \ 302 } \ 303 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B) \ 304 { \ 305 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \ 306 { \ 307 (__HANDLE__)->Mask = 0x00FFU ; \ 308 } \ 309 else \ 310 { \ 311 (__HANDLE__)->Mask = 0x007FU ; \ 312 } \ 313 } \ 314 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_7B) \ 315 { \ 316 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \ 317 { \ 318 (__HANDLE__)->Mask = 0x007FU ; \ 319 } \ 320 else \ 321 { \ 322 (__HANDLE__)->Mask = 0x003FU ; \ 323 } \ 324 } \ 325 else \ 326 { \ 327 (__HANDLE__)->Mask = 0x0000U; \ 328 } \ 329 } while(0U) 330 331 /** 332 * @brief Ensure that UART frame length is valid. 333 * @param __LENGTH__ UART frame length. 334 * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid) 335 */ 336 #define IS_UART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == UART_WORDLENGTH_7B) || \ 337 ((__LENGTH__) == UART_WORDLENGTH_8B) || \ 338 ((__LENGTH__) == UART_WORDLENGTH_9B)) 339 340 /** 341 * @brief Ensure that UART wake-up address length is valid. 342 * @param __ADDRESS__ UART wake-up address length. 343 * @retval SET (__ADDRESS__ is valid) or RESET (__ADDRESS__ is invalid) 344 */ 345 #define IS_UART_ADDRESSLENGTH_DETECT(__ADDRESS__) (((__ADDRESS__) == UART_ADDRESS_DETECT_4B) || \ 346 ((__ADDRESS__) == UART_ADDRESS_DETECT_7B)) 347 348 /** 349 * @brief Ensure that UART TXFIFO threshold level is valid. 350 * @param __THRESHOLD__ UART TXFIFO threshold level. 351 * @retval SET (__THRESHOLD__ is valid) or RESET (__THRESHOLD__ is invalid) 352 */ 353 #define IS_UART_TXFIFO_THRESHOLD(__THRESHOLD__) (((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_1_8) || \ 354 ((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_1_4) || \ 355 ((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_1_2) || \ 356 ((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_3_4) || \ 357 ((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_7_8) || \ 358 ((__THRESHOLD__) == UART_TXFIFO_THRESHOLD_8_8)) 359 360 /** 361 * @brief Ensure that UART RXFIFO threshold level is valid. 362 * @param __THRESHOLD__ UART RXFIFO threshold level. 363 * @retval SET (__THRESHOLD__ is valid) or RESET (__THRESHOLD__ is invalid) 364 */ 365 #define IS_UART_RXFIFO_THRESHOLD(__THRESHOLD__) (((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_1_8) || \ 366 ((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_1_4) || \ 367 ((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_1_2) || \ 368 ((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_3_4) || \ 369 ((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_7_8) || \ 370 ((__THRESHOLD__) == UART_RXFIFO_THRESHOLD_8_8)) 371 372 /** 373 * @} 374 */ 375 376 /* Private functions ---------------------------------------------------------*/ 377 378 /** 379 * @} 380 */ 381 382 /** 383 * @} 384 */ 385 386 #ifdef __cplusplus 387 } 388 #endif 389 390 #endif /* STM32WBxx_HAL_UART_EX_H */ 391 392 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 393