2 ******************************************************************************
3 * @file stm32l0xx_hal_uart_ex.h
4 * @author MCD Application Team
6 * @date 06-February-2015
7 * @brief Header file of UART HAL Extension module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2015 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 __STM32L0xx_HAL_UART_EX_H
40 #define __STM32L0xx_HAL_UART_EX_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32l0xx_hal_def.h"
49 /** @addtogroup STM32L0xx_HAL_Driver
53 /** @defgroup UARTEx UARTEx Extended HAL module driver
57 /******************************************************************************/
58 /* Exported types ------------------------------------------------------------*/
59 /******************************************************************************/
61 /** @defgroup UARTEx_Exported_Types UARTEx Exported Types
65 /** @defgroup UARTEx_Init_Configuration Extended initialization configuration structure
69 * @brief UART wake up from stop mode parameters
73 uint32_t WakeUpEvent; /*!< Specifies which event will activat the Wakeup from Stop mode flag (WUF).
74 This parameter can be a value of @ref UART_WakeUp_from_Stop_Selection.
75 If set to UART_WAKEUP_ON_ADDRESS, the two other fields below must
78 uint16_t AddressLength; /*!< Specifies whether the address is 4 or 7-bit long.
79 This parameter can be a value of @ref UARTEx_WakeUp_Address_Length */
81 uint8_t Address; /*!< UART/USART node address (7-bit long max) */
91 /* Exported constants --------------------------------------------------------*/
92 /** @defgroup UARTEx_Extended_Exported_Constants UARTEx Exported Constants
96 /** @defgroup UARTEx_Word_Length Word length definition
99 #define UART_WORDLENGTH_7B ((uint32_t)USART_CR1_M_1)
100 #define UART_WORDLENGTH_8B ((uint32_t)0x0000)
101 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M_0)
102 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_7B) || \
103 ((LENGTH) == UART_WORDLENGTH_8B) || \
104 ((LENGTH) == UART_WORDLENGTH_9B))
109 /** @defgroup UARTEx_AutoBaud_Rate_Mode Auto baud rate mode definition
112 #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT ((uint32_t)0x0000)
113 #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0)
114 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME ((uint32_t)USART_CR2_ABRMODE_1)
115 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME ((uint32_t)USART_CR2_ABRMODE)
116 #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(MODE) (((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
117 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
118 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME) || \
119 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
124 /** @defgroup UARTEx_WakeUp_Address_Length WakeUp address length definition
127 #define UART_ADDRESS_DETECT_4B ((uint32_t)0x00000000)
128 #define UART_ADDRESS_DETECT_7B ((uint32_t)USART_CR2_ADDM7)
129 #define IS_UART_ADDRESSLENGTH_DETECT(ADDRESS) (((ADDRESS) == UART_ADDRESS_DETECT_4B) || \
130 ((ADDRESS) == UART_ADDRESS_DETECT_7B))
136 /** @defgroup UARTEx_WakeUp_Methods Wakeup methods definition
139 #define UART_WAKEUPMETHOD_IDLELINE ((uint32_t)0x00000000)
140 #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE)
141 #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
142 ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
151 /* Exported macro ------------------------------------------------------------*/
153 /** @defgroup UARTEx_Extended_Exported_Macros UARTEx Exported Macros
157 /** @brief Reports the UART clock source.
158 * @param __HANDLE__: specifies the UART Handle
159 * @param __CLOCKSOURCE__ : output variable
160 * @retval UART clocking source, written in __CLOCKSOURCE__.
162 #if defined (STM32L031xx) || defined (STM32L041xx)
163 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
165 if((__HANDLE__)->Instance == USART2) \
167 switch(__HAL_RCC_GET_USART2_SOURCE()) \
169 case RCC_USART2CLKSOURCE_PCLK1: \
170 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
172 case RCC_USART2CLKSOURCE_HSI: \
173 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
175 case RCC_USART2CLKSOURCE_SYSCLK: \
176 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
178 case RCC_USART2CLKSOURCE_LSE: \
179 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
185 else if((__HANDLE__)->Instance == LPUART1) \
187 switch(__HAL_RCC_GET_LPUART1_SOURCE()) \
189 case RCC_LPUART1CLKSOURCE_PCLK1: \
190 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
192 case RCC_LPUART1CLKSOURCE_HSI: \
193 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
195 case RCC_LPUART1CLKSOURCE_SYSCLK: \
196 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
198 case RCC_LPUART1CLKSOURCE_LSE: \
199 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
207 #else /* (STM32L031xx) || defined (STM32L041xx) */
209 #define UART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
211 if((__HANDLE__)->Instance == USART1) \
213 switch(__HAL_RCC_GET_USART1_SOURCE()) \
215 case RCC_USART1CLKSOURCE_PCLK2: \
216 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK2; \
218 case RCC_USART1CLKSOURCE_HSI: \
219 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
221 case RCC_USART1CLKSOURCE_SYSCLK: \
222 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
224 case RCC_USART1CLKSOURCE_LSE: \
225 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
231 else if((__HANDLE__)->Instance == USART2) \
233 switch(__HAL_RCC_GET_USART2_SOURCE()) \
235 case RCC_USART2CLKSOURCE_PCLK1: \
236 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
238 case RCC_USART2CLKSOURCE_HSI: \
239 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
241 case RCC_USART2CLKSOURCE_SYSCLK: \
242 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
244 case RCC_USART2CLKSOURCE_LSE: \
245 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
251 else if((__HANDLE__)->Instance == LPUART1) \
253 switch(__HAL_RCC_GET_LPUART1_SOURCE()) \
255 case RCC_LPUART1CLKSOURCE_PCLK1: \
256 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_PCLK1; \
258 case RCC_LPUART1CLKSOURCE_HSI: \
259 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_HSI; \
261 case RCC_LPUART1CLKSOURCE_SYSCLK: \
262 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_SYSCLK; \
264 case RCC_LPUART1CLKSOURCE_LSE: \
265 (__CLOCKSOURCE__) = UART_CLOCKSOURCE_LSE; \
272 #endif /* (STM32L031xx) || (STM32L041xx) */
274 /** @brief Reports the UART mask to apply to retrieve the received data
275 * according to the word length and to the parity bits activation.
276 * If PCE = 1, the parity bit is not included in the data extracted
277 * by the reception API().
278 * This masking operation is not carried out in the case of
280 * @param __HANDLE__: specifies the UART Handle
281 * @retval mask to apply to UART RDR register value.
283 #define UART_MASK_COMPUTATION(__HANDLE__) \
285 if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_9B) \
287 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
289 (__HANDLE__)->Mask = 0x01FF ; \
293 (__HANDLE__)->Mask = 0x00FF ; \
296 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_8B) \
298 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
300 (__HANDLE__)->Mask = 0x00FF ; \
304 (__HANDLE__)->Mask = 0x007F ; \
307 else if ((__HANDLE__)->Init.WordLength == UART_WORDLENGTH_7B) \
309 if ((__HANDLE__)->Init.Parity == UART_PARITY_NONE) \
311 (__HANDLE__)->Mask = 0x007F ; \
315 (__HANDLE__)->Mask = 0x003F ; \
324 /* Exported functions --------------------------------------------------------*/
325 /** @defgroup UARTEx_Exported_Functions UARTEx Exported Functions
328 /* Exported functions --------------------------------------------------------*/
329 /* Initialization/de-initialization functions ********************************/
330 /** @defgroup UARTEx_Exported_Functions_Group1 Extended Initialization function
333 HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime, uint32_t DeassertionTime);
337 /* IO operation functions *****************************************************/
338 /* Peripheral Control functions **********************************************/
339 /** @defgroup UARTEx_Exported_Functions_Group2 Peripheral Control functions
342 HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
343 HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart);
344 HAL_StatusTypeDef HAL_UARTEx_EnableClockStopMode(UART_HandleTypeDef *huart);
345 HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart);
346 HAL_StatusTypeDef HAL_UARTEx_DisableClockStopMode(UART_HandleTypeDef *huart);
347 void HAL_UARTEx_WakeupCallback(UART_HandleTypeDef *huart);
349 /* Peripheral State functions ************************************************/
350 HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength);
375 #endif /* __STM32L0xx_HAL_UART_EX_H */
377 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/