Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
stm32l4xx_hal_usart_ex.h
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_usart_ex.h 00004 * @author MCD Application Team 00005 * @version V1.5.1 00006 * @date 31-May-2016 00007 * @brief Header file of USART HAL Extended module. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 /* Define to prevent recursive inclusion -------------------------------------*/ 00039 #ifndef __STM32L4xx_HAL_USART_EX_H 00040 #define __STM32L4xx_HAL_USART_EX_H 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 /* Includes ------------------------------------------------------------------*/ 00047 #include "stm32l4xx_hal_def.h" 00048 00049 /** @addtogroup STM32L4xx_HAL_Driver 00050 * @{ 00051 */ 00052 00053 /** @addtogroup USARTEx 00054 * @{ 00055 */ 00056 00057 /* Exported types ------------------------------------------------------------*/ 00058 /* Exported constants --------------------------------------------------------*/ 00059 /** @defgroup USARTEx_Exported_Constants USARTEx Exported Constants 00060 * @{ 00061 */ 00062 00063 /** @defgroup USARTEx_Word_Length USARTEx Word Length 00064 * @{ 00065 */ 00066 #define USART_WORDLENGTH_7B ((uint32_t)USART_CR1_M1) /*!< 7-bit long USART frame */ 00067 #define USART_WORDLENGTH_8B ((uint32_t)0x00000000) /*!< 8-bit long USART frame */ 00068 #define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M0) /*!< 9-bit long USART frame */ 00069 /** 00070 * @} 00071 */ 00072 00073 /** 00074 * @} 00075 */ 00076 00077 /* Exported functions --------------------------------------------------------*/ 00078 00079 /* Private macros ------------------------------------------------------------*/ 00080 /** @defgroup USARTEx_Private_Macros USARTEx Private Macros 00081 * @{ 00082 */ 00083 00084 /** @brief Report the USART clock source. 00085 * @param __HANDLE__: specifies the USART Handle. 00086 * @param __CLOCKSOURCE__: output variable. 00087 * @retval the USART clocking source, written in __CLOCKSOURCE__. 00088 */ 00089 #if defined (STM32L432xx) || defined (STM32L442xx) 00090 #define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ 00091 do { \ 00092 if((__HANDLE__)->Instance == USART1) \ 00093 { \ 00094 switch(__HAL_RCC_GET_USART1_SOURCE()) \ 00095 { \ 00096 case RCC_USART1CLKSOURCE_PCLK2: \ 00097 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK2; \ 00098 break; \ 00099 case RCC_USART1CLKSOURCE_HSI: \ 00100 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ 00101 break; \ 00102 case RCC_USART1CLKSOURCE_SYSCLK: \ 00103 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ 00104 break; \ 00105 case RCC_USART1CLKSOURCE_LSE: \ 00106 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ 00107 break; \ 00108 default: \ 00109 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ 00110 break; \ 00111 } \ 00112 } \ 00113 else if((__HANDLE__)->Instance == USART2) \ 00114 { \ 00115 switch(__HAL_RCC_GET_USART2_SOURCE()) \ 00116 { \ 00117 case RCC_USART2CLKSOURCE_PCLK1: \ 00118 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ 00119 break; \ 00120 case RCC_USART2CLKSOURCE_HSI: \ 00121 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ 00122 break; \ 00123 case RCC_USART2CLKSOURCE_SYSCLK: \ 00124 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ 00125 break; \ 00126 case RCC_USART2CLKSOURCE_LSE: \ 00127 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ 00128 break; \ 00129 default: \ 00130 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ 00131 break; \ 00132 } \ 00133 } \ 00134 } while(0) 00135 #else 00136 #define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \ 00137 do { \ 00138 if((__HANDLE__)->Instance == USART1) \ 00139 { \ 00140 switch(__HAL_RCC_GET_USART1_SOURCE()) \ 00141 { \ 00142 case RCC_USART1CLKSOURCE_PCLK2: \ 00143 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK2; \ 00144 break; \ 00145 case RCC_USART1CLKSOURCE_HSI: \ 00146 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ 00147 break; \ 00148 case RCC_USART1CLKSOURCE_SYSCLK: \ 00149 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ 00150 break; \ 00151 case RCC_USART1CLKSOURCE_LSE: \ 00152 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ 00153 break; \ 00154 default: \ 00155 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ 00156 break; \ 00157 } \ 00158 } \ 00159 else if((__HANDLE__)->Instance == USART2) \ 00160 { \ 00161 switch(__HAL_RCC_GET_USART2_SOURCE()) \ 00162 { \ 00163 case RCC_USART2CLKSOURCE_PCLK1: \ 00164 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ 00165 break; \ 00166 case RCC_USART2CLKSOURCE_HSI: \ 00167 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ 00168 break; \ 00169 case RCC_USART2CLKSOURCE_SYSCLK: \ 00170 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ 00171 break; \ 00172 case RCC_USART2CLKSOURCE_LSE: \ 00173 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ 00174 break; \ 00175 default: \ 00176 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ 00177 break; \ 00178 } \ 00179 } \ 00180 else if((__HANDLE__)->Instance == USART3) \ 00181 { \ 00182 switch(__HAL_RCC_GET_USART3_SOURCE()) \ 00183 { \ 00184 case RCC_USART3CLKSOURCE_PCLK1: \ 00185 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \ 00186 break; \ 00187 case RCC_USART3CLKSOURCE_HSI: \ 00188 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \ 00189 break; \ 00190 case RCC_USART3CLKSOURCE_SYSCLK: \ 00191 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \ 00192 break; \ 00193 case RCC_USART3CLKSOURCE_LSE: \ 00194 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \ 00195 break; \ 00196 default: \ 00197 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \ 00198 break; \ 00199 } \ 00200 } \ 00201 } while(0) 00202 #endif /* STM32L432xx || STM32L442xx */ 00203 00204 /** @brief Compute the USART mask to apply to retrieve the received data 00205 * according to the word length and to the parity bits activation. 00206 * @note If PCE = 1, the parity bit is not included in the data extracted 00207 * by the reception API(). 00208 * This masking operation is not carried out in the case of 00209 * DMA transfers. 00210 * @param __HANDLE__: specifies the USART Handle. 00211 * @retval None, the mask to apply to USART RDR register is stored in (__HANDLE__)->Mask field. 00212 */ 00213 #define USART_MASK_COMPUTATION(__HANDLE__) \ 00214 do { \ 00215 if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \ 00216 { \ 00217 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ 00218 { \ 00219 (__HANDLE__)->Mask = 0x01FF ; \ 00220 } \ 00221 else \ 00222 { \ 00223 (__HANDLE__)->Mask = 0x00FF ; \ 00224 } \ 00225 } \ 00226 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \ 00227 { \ 00228 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ 00229 { \ 00230 (__HANDLE__)->Mask = 0x00FF ; \ 00231 } \ 00232 else \ 00233 { \ 00234 (__HANDLE__)->Mask = 0x007F ; \ 00235 } \ 00236 } \ 00237 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_7B) \ 00238 { \ 00239 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ 00240 { \ 00241 (__HANDLE__)->Mask = 0x007F ; \ 00242 } \ 00243 else \ 00244 { \ 00245 (__HANDLE__)->Mask = 0x003F ; \ 00246 } \ 00247 } \ 00248 } while(0) 00249 00250 00251 /** 00252 * @brief Ensure that USART frame length is valid. 00253 * @param __LENGTH__: USART frame length. 00254 * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid) 00255 */ 00256 #define IS_USART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == USART_WORDLENGTH_7B) || \ 00257 ((__LENGTH__) == USART_WORDLENGTH_8B) || \ 00258 ((__LENGTH__) == USART_WORDLENGTH_9B)) 00259 00260 /** 00261 * @} 00262 */ 00263 00264 /* Exported functions --------------------------------------------------------*/ 00265 00266 /** 00267 * @} 00268 */ 00269 00270 /** 00271 * @} 00272 */ 00273 00274 #ifdef __cplusplus 00275 } 00276 #endif 00277 00278 #endif /* __STM32L4xx_HAL_USART_EX_H */ 00279 00280 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 10:59:59 by
