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.
 
 
 

447 lines
22 KiB

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