You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

586 lines
33 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_usart_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of USART HAL Extended module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F0xx_HAL_USART_EX_H
  37. #define __STM32F0xx_HAL_USART_EX_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f0xx_hal_def.h"
  43. /** @addtogroup STM32F0xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup USARTEx
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /* Exported constants --------------------------------------------------------*/
  51. /** @defgroup USARTEx_Exported_Constants USARTEx Exported Constants
  52. * @{
  53. */
  54. /** @defgroup USARTEx_Word_Length USARTEx Word Length
  55. * @{
  56. */
  57. #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
  58. defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
  59. defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
  60. #define USART_WORDLENGTH_7B ((uint32_t)USART_CR1_M1) /*!< 7-bit long USART frame */
  61. #define USART_WORDLENGTH_8B (0x00000000U) /*!< 8-bit long USART frame */
  62. #define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M0) /*!< 9-bit long USART frame */
  63. #else
  64. #define USART_WORDLENGTH_8B (0x00000000U) /*!< 8-bit long USART frame */
  65. #define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M) /*!< 9-bit long USART frame */
  66. #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || defined (STM32F070xB) || \
  67. defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
  68. defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
  69. /**
  70. * @}
  71. */
  72. /** @defgroup USART_Request_Parameters USARTEx Request Parameters
  73. * @{
  74. */
  75. #define USART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
  76. #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
  77. #define USART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
  78. #else
  79. #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
  80. /**
  81. * @}
  82. */
  83. /** @defgroup USART_Flags USART Flags
  84. * Elements values convention: 0xXXXX
  85. * - 0xXXXX : Flag mask in the ISR register
  86. * @{
  87. */
  88. #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
  89. #define USART_FLAG_REACK (0x00400000U) /*!< USART receive enable acknowledge flag */
  90. #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
  91. #define USART_FLAG_TEACK (0x00200000U) /*!< USART transmit enable acknowledge flag */
  92. #define USART_FLAG_BUSY (0x00010000U) /*!< USART busy flag */
  93. #define USART_FLAG_CTS (0x00000400U) /*!< USART clear to send flag */
  94. #define USART_FLAG_CTSIF (0x00000200U) /*!< USART clear to send interrupt flag */
  95. #define USART_FLAG_TXE (0x00000080U) /*!< USART transmit data register empty */
  96. #define USART_FLAG_TC (0x00000040U) /*!< USART transmission complete */
  97. #define USART_FLAG_RXNE (0x00000020U) /*!< USART read data register not empty */
  98. #define USART_FLAG_IDLE (0x00000010U) /*!< USART idle flag */
  99. #define USART_FLAG_ORE (0x00000008U) /*!< USART overrun error */
  100. #define USART_FLAG_NE (0x00000004U) /*!< USART noise error */
  101. #define USART_FLAG_FE (0x00000002U) /*!< USART frame error */
  102. #define USART_FLAG_PE (0x00000001U) /*!< USART parity error */
  103. /**
  104. * @}
  105. */
  106. /**
  107. * @}
  108. */
  109. /* Exported macros ------------------------------------------------------------*/
  110. /** @defgroup USARTEx_Exported_Macros USARTEx Exported Macros
  111. * @{
  112. */
  113. /** @brief Flush the USART Data registers.
  114. * @param __HANDLE__ specifies the USART Handle.
  115. * @retval None
  116. */
  117. #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
  118. #define __HAL_USART_FLUSH_DRREGISTER(__HANDLE__) \
  119. do{ \
  120. SET_BIT((__HANDLE__)->Instance->RQR, USART_RXDATA_FLUSH_REQUEST); \
  121. SET_BIT((__HANDLE__)->Instance->RQR, USART_TXDATA_FLUSH_REQUEST); \
  122. } while(0)
  123. #else
  124. #define __HAL_USART_FLUSH_DRREGISTER(__HANDLE__) \
  125. do{ \
  126. SET_BIT((__HANDLE__)->Instance->RQR, USART_RXDATA_FLUSH_REQUEST); \
  127. } while(0)
  128. #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
  129. /**
  130. * @}
  131. */
  132. /* Private macros ------------------------------------------------------------*/
  133. /** @defgroup USARTEx_Private_Macros USARTEx Private Macros
  134. * @{
  135. */
  136. /** @brief Report the USART clock source.
  137. * @param __HANDLE__ specifies the USART Handle.
  138. * @param __CLOCKSOURCE__ output variable.
  139. * @retval the USART clocking source, written in __CLOCKSOURCE__.
  140. */
  141. #if defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx)
  142. #define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  143. do { \
  144. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  145. { \
  146. case RCC_USART1CLKSOURCE_PCLK1: \
  147. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  148. break; \
  149. case RCC_USART1CLKSOURCE_HSI: \
  150. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  151. break; \
  152. case RCC_USART1CLKSOURCE_SYSCLK: \
  153. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  154. break; \
  155. case RCC_USART1CLKSOURCE_LSE: \
  156. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  157. break; \
  158. default: \
  159. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  160. break; \
  161. } \
  162. } while(0)
  163. #elif defined (STM32F030x8) || defined (STM32F070x6) || \
  164. defined (STM32F042x6) || defined (STM32F048xx) || \
  165. defined (STM32F051x8) || defined (STM32F058xx)
  166. #define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  167. do { \
  168. if((__HANDLE__)->Instance == USART1) \
  169. { \
  170. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  171. { \
  172. case RCC_USART1CLKSOURCE_PCLK1: \
  173. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  174. break; \
  175. case RCC_USART1CLKSOURCE_HSI: \
  176. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  177. break; \
  178. case RCC_USART1CLKSOURCE_SYSCLK: \
  179. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  180. break; \
  181. case RCC_USART1CLKSOURCE_LSE: \
  182. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  183. break; \
  184. default: \
  185. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  186. break; \
  187. } \
  188. } \
  189. else if((__HANDLE__)->Instance == USART2) \
  190. { \
  191. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  192. } \
  193. else \
  194. { \
  195. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  196. } \
  197. } while(0)
  198. #elif defined (STM32F070xB)
  199. #define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  200. do { \
  201. if((__HANDLE__)->Instance == USART1) \
  202. { \
  203. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  204. { \
  205. case RCC_USART1CLKSOURCE_PCLK1: \
  206. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  207. break; \
  208. case RCC_USART1CLKSOURCE_HSI: \
  209. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  210. break; \
  211. case RCC_USART1CLKSOURCE_SYSCLK: \
  212. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  213. break; \
  214. case RCC_USART1CLKSOURCE_LSE: \
  215. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  216. break; \
  217. default: \
  218. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  219. break; \
  220. } \
  221. } \
  222. else if((__HANDLE__)->Instance == USART2) \
  223. { \
  224. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  225. } \
  226. else if((__HANDLE__)->Instance == USART3) \
  227. { \
  228. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  229. } \
  230. else if((__HANDLE__)->Instance == USART4) \
  231. { \
  232. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  233. } \
  234. else \
  235. { \
  236. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  237. } \
  238. } while(0)
  239. #elif defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)
  240. #define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  241. do { \
  242. if((__HANDLE__)->Instance == USART1) \
  243. { \
  244. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  245. { \
  246. case RCC_USART1CLKSOURCE_PCLK1: \
  247. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  248. break; \
  249. case RCC_USART1CLKSOURCE_HSI: \
  250. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  251. break; \
  252. case RCC_USART1CLKSOURCE_SYSCLK: \
  253. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  254. break; \
  255. case RCC_USART1CLKSOURCE_LSE: \
  256. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  257. break; \
  258. default: \
  259. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  260. break; \
  261. } \
  262. } \
  263. else if((__HANDLE__)->Instance == USART2) \
  264. { \
  265. switch(__HAL_RCC_GET_USART2_SOURCE()) \
  266. { \
  267. case RCC_USART2CLKSOURCE_PCLK1: \
  268. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  269. break; \
  270. case RCC_USART2CLKSOURCE_HSI: \
  271. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  272. break; \
  273. case RCC_USART2CLKSOURCE_SYSCLK: \
  274. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  275. break; \
  276. case RCC_USART2CLKSOURCE_LSE: \
  277. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  278. break; \
  279. default: \
  280. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  281. break; \
  282. } \
  283. } \
  284. else if((__HANDLE__)->Instance == USART3) \
  285. { \
  286. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  287. } \
  288. else if((__HANDLE__)->Instance == USART4) \
  289. { \
  290. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  291. } \
  292. else \
  293. { \
  294. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  295. } \
  296. } while(0)
  297. #elif defined(STM32F091xC) || defined (STM32F098xx)
  298. #define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  299. do { \
  300. if((__HANDLE__)->Instance == USART1) \
  301. { \
  302. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  303. { \
  304. case RCC_USART1CLKSOURCE_PCLK1: \
  305. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  306. break; \
  307. case RCC_USART1CLKSOURCE_HSI: \
  308. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  309. break; \
  310. case RCC_USART1CLKSOURCE_SYSCLK: \
  311. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  312. break; \
  313. case RCC_USART1CLKSOURCE_LSE: \
  314. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  315. break; \
  316. default: \
  317. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  318. break; \
  319. } \
  320. } \
  321. else if((__HANDLE__)->Instance == USART2) \
  322. { \
  323. switch(__HAL_RCC_GET_USART2_SOURCE()) \
  324. { \
  325. case RCC_USART2CLKSOURCE_PCLK1: \
  326. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  327. break; \
  328. case RCC_USART2CLKSOURCE_HSI: \
  329. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  330. break; \
  331. case RCC_USART2CLKSOURCE_SYSCLK: \
  332. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  333. break; \
  334. case RCC_USART2CLKSOURCE_LSE: \
  335. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  336. break; \
  337. default: \
  338. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  339. break; \
  340. } \
  341. } \
  342. else if((__HANDLE__)->Instance == USART3) \
  343. { \
  344. switch(__HAL_RCC_GET_USART3_SOURCE()) \
  345. { \
  346. case RCC_USART3CLKSOURCE_PCLK1: \
  347. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  348. break; \
  349. case RCC_USART3CLKSOURCE_HSI: \
  350. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  351. break; \
  352. case RCC_USART3CLKSOURCE_SYSCLK: \
  353. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  354. break; \
  355. case RCC_USART3CLKSOURCE_LSE: \
  356. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  357. break; \
  358. default: \
  359. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  360. break; \
  361. } \
  362. } \
  363. else if((__HANDLE__)->Instance == USART4) \
  364. { \
  365. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  366. } \
  367. else if((__HANDLE__)->Instance == USART5) \
  368. { \
  369. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  370. } \
  371. else if((__HANDLE__)->Instance == USART6) \
  372. { \
  373. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  374. } \
  375. else if((__HANDLE__)->Instance == USART7) \
  376. { \
  377. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  378. } \
  379. else if((__HANDLE__)->Instance == USART8) \
  380. { \
  381. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  382. } \
  383. else \
  384. { \
  385. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  386. } \
  387. } while(0)
  388. #elif defined(STM32F030xC)
  389. #define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
  390. do { \
  391. if((__HANDLE__)->Instance == USART1) \
  392. { \
  393. switch(__HAL_RCC_GET_USART1_SOURCE()) \
  394. { \
  395. case RCC_USART1CLKSOURCE_PCLK1: \
  396. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  397. break; \
  398. case RCC_USART1CLKSOURCE_HSI: \
  399. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
  400. break; \
  401. case RCC_USART1CLKSOURCE_SYSCLK: \
  402. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
  403. break; \
  404. case RCC_USART1CLKSOURCE_LSE: \
  405. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
  406. break; \
  407. default: \
  408. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  409. break; \
  410. } \
  411. } \
  412. else if((__HANDLE__)->Instance == USART2) \
  413. { \
  414. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  415. } \
  416. else if((__HANDLE__)->Instance == USART3) \
  417. { \
  418. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  419. } \
  420. else if((__HANDLE__)->Instance == USART4) \
  421. { \
  422. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  423. } \
  424. else if((__HANDLE__)->Instance == USART5) \
  425. { \
  426. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  427. } \
  428. else if((__HANDLE__)->Instance == USART6) \
  429. { \
  430. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
  431. } \
  432. else \
  433. { \
  434. (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
  435. } \
  436. } while(0)
  437. #endif /* defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx) */
  438. /** @brief Compute the USART mask to apply to retrieve the received data
  439. * according to the word length and to the parity bits activation.
  440. * @note If PCE = 1, the parity bit is not included in the data extracted
  441. * by the reception API().
  442. * This masking operation is not carried out in the case of
  443. * DMA transfers.
  444. * @param __HANDLE__ specifies the USART Handle.
  445. * @retval None, the mask to apply to USART RDR register is stored in (__HANDLE__)->Mask field.
  446. */
  447. #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
  448. defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
  449. defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
  450. #define USART_MASK_COMPUTATION(__HANDLE__) \
  451. do { \
  452. if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \
  453. { \
  454. if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
  455. { \
  456. (__HANDLE__)->Mask = 0x01FFU; \
  457. } \
  458. else \
  459. { \
  460. (__HANDLE__)->Mask = 0x00FFU; \
  461. } \
  462. } \
  463. else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \
  464. { \
  465. if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
  466. { \
  467. (__HANDLE__)->Mask = 0x00FFU; \
  468. } \
  469. else \
  470. { \
  471. (__HANDLE__)->Mask = 0x007FU; \
  472. } \
  473. } \
  474. else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_7B) \
  475. { \
  476. if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
  477. { \
  478. (__HANDLE__)->Mask = 0x007FU; \
  479. } \
  480. else \
  481. { \
  482. (__HANDLE__)->Mask = 0x003FU; \
  483. } \
  484. } \
  485. } while(0)
  486. #else
  487. #define USART_MASK_COMPUTATION(__HANDLE__) \
  488. do { \
  489. if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \
  490. { \
  491. if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
  492. { \
  493. (__HANDLE__)->Mask = 0x01FFU; \
  494. } \
  495. else \
  496. { \
  497. (__HANDLE__)->Mask = 0x00FFU; \
  498. } \
  499. } \
  500. else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \
  501. { \
  502. if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \
  503. { \
  504. (__HANDLE__)->Mask = 0x00FFU; \
  505. } \
  506. else \
  507. { \
  508. (__HANDLE__)->Mask = 0x007FU; \
  509. } \
  510. } \
  511. } while(0)
  512. #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
  513. defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
  514. defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
  515. /**
  516. * @brief Ensure that USART frame length is valid.
  517. * @param __LENGTH__ USART frame length.
  518. * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
  519. */
  520. #if defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || \
  521. defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || defined (STM32F070xB) || \
  522. defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC)
  523. #define IS_USART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == USART_WORDLENGTH_7B) || \
  524. ((__LENGTH__) == USART_WORDLENGTH_8B) || \
  525. ((__LENGTH__) == USART_WORDLENGTH_9B))
  526. #else
  527. #define IS_USART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == USART_WORDLENGTH_8B) || \
  528. ((__LENGTH__) == USART_WORDLENGTH_9B))
  529. #endif /* defined (STM32F042x6) || defined (STM32F048xx) || defined (STM32F070x6) || defined (STM32F070xB) || \
  530. defined (STM32F071xB) || defined (STM32F072xB) || defined (STM32F078xx) || \
  531. defined (STM32F091xC) || defined (STM32F098xx) || defined (STM32F030xC) */
  532. /**
  533. * @brief Ensure that USART request parameter is valid.
  534. * @param __PARAM__ USART request parameter.
  535. * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
  536. */
  537. #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
  538. #define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \
  539. ((__PARAM__) == USART_TXDATA_FLUSH_REQUEST))
  540. #else
  541. #define IS_USART_REQUEST_PARAMETER(__PARAM__) ((__PARAM__) == USART_RXDATA_FLUSH_REQUEST)
  542. #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
  543. /**
  544. * @}
  545. */
  546. /* Exported functions --------------------------------------------------------*/
  547. /**
  548. * @}
  549. */
  550. /**
  551. * @}
  552. */
  553. #ifdef __cplusplus
  554. }
  555. #endif
  556. #endif /* __STM32F0xx_HAL_USART_EX_H */
  557. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/