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.
stm32f1xx_hal_usart.h
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f1xx_hal_usart.h 00004 * @author MCD Application Team 00005 * @version V1.0.4 00006 * @date 29-April-2016 00007 * @brief Header file of USART HAL 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 __STM32F1xx_HAL_USART_H 00040 #define __STM32F1xx_HAL_USART_H 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 /* Includes ------------------------------------------------------------------*/ 00047 #include "stm32f1xx_hal_def.h" 00048 00049 /** @addtogroup STM32F1xx_HAL_Driver 00050 * @{ 00051 */ 00052 00053 /** @addtogroup USART 00054 * @{ 00055 */ 00056 00057 /* Exported types ------------------------------------------------------------*/ 00058 /** @defgroup USART_Exported_Types USART Exported Types 00059 * @{ 00060 */ 00061 00062 00063 /** 00064 * @brief USART Init Structure definition 00065 */ 00066 typedef struct 00067 { 00068 uint32_t BaudRate; /*!< This member configures the Usart communication baud rate. 00069 The baud rate is computed using the following formula: 00070 - IntegerDivider = ((PCLKx) / (16 * (husart->Init.BaudRate))) 00071 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */ 00072 00073 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. 00074 This parameter can be a value of @ref USART_Word_Length */ 00075 00076 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted. 00077 This parameter can be a value of @ref USART_Stop_Bits */ 00078 00079 uint32_t Parity; /*!< Specifies the parity mode. 00080 This parameter can be a value of @ref USART_Parity 00081 @note When parity is enabled, the computed parity is inserted 00082 at the MSB position of the transmitted data (9th bit when 00083 the word length is set to 9 data bits; 8th bit when the 00084 word length is set to 8 data bits). */ 00085 00086 uint32_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled. 00087 This parameter can be a value of @ref USART_Mode */ 00088 00089 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock. 00090 This parameter can be a value of @ref USART_Clock_Polarity */ 00091 00092 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made. 00093 This parameter can be a value of @ref USART_Clock_Phase */ 00094 00095 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted 00096 data bit (MSB) has to be output on the SCLK pin in synchronous mode. 00097 This parameter can be a value of @ref USART_Last_Bit */ 00098 }USART_InitTypeDef; 00099 00100 /** 00101 * @brief HAL State structures definition 00102 */ 00103 typedef enum 00104 { 00105 HAL_USART_STATE_RESET = 0x00, /*!< Peripheral is not initialized */ 00106 HAL_USART_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */ 00107 HAL_USART_STATE_BUSY = 0x02, /*!< an internal process is ongoing */ 00108 HAL_USART_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */ 00109 HAL_USART_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */ 00110 HAL_USART_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission Reception process is ongoing */ 00111 HAL_USART_STATE_TIMEOUT = 0x03, /*!< Timeout state */ 00112 HAL_USART_STATE_ERROR = 0x04 /*!< Error */ 00113 }HAL_USART_StateTypeDef; 00114 00115 00116 /** 00117 * @brief USART handle Structure definition 00118 */ 00119 typedef struct 00120 { 00121 USART_TypeDef *Instance; /*!< USART registers base address */ 00122 00123 USART_InitTypeDef Init; /*!< Usart communication parameters */ 00124 00125 uint8_t *pTxBuffPtr; /*!< Pointer to Usart Tx transfer Buffer */ 00126 00127 uint16_t TxXferSize; /*!< Usart Tx Transfer size */ 00128 00129 __IO uint16_t TxXferCount; /*!< Usart Tx Transfer Counter */ 00130 00131 uint8_t *pRxBuffPtr; /*!< Pointer to Usart Rx transfer Buffer */ 00132 00133 uint16_t RxXferSize; /*!< Usart Rx Transfer size */ 00134 00135 __IO uint16_t RxXferCount; /*!< Usart Rx Transfer Counter */ 00136 00137 DMA_HandleTypeDef *hdmatx; /*!< Usart Tx DMA Handle parameters */ 00138 00139 DMA_HandleTypeDef *hdmarx; /*!< Usart Rx DMA Handle parameters */ 00140 00141 HAL_LockTypeDef Lock; /*!< Locking object */ 00142 00143 __IO HAL_USART_StateTypeDef State; /*!< Usart communication state */ 00144 00145 __IO uint32_t ErrorCode; /*!< USART Error code */ 00146 00147 }USART_HandleTypeDef; 00148 00149 /** 00150 * @} 00151 */ 00152 00153 /* Exported constants --------------------------------------------------------*/ 00154 /** @defgroup USART_Exported_Constants USART Exported constants 00155 * @{ 00156 */ 00157 00158 /** @defgroup USART_Error_Codes USART Error Codes 00159 * @{ 00160 */ 00161 #define HAL_USART_ERROR_NONE ((uint32_t)0x00) /*!< No error */ 00162 #define HAL_USART_ERROR_PE ((uint32_t)0x01) /*!< Parity error */ 00163 #define HAL_USART_ERROR_NE ((uint32_t)0x02) /*!< Noise error */ 00164 #define HAL_USART_ERROR_FE ((uint32_t)0x04) /*!< frame error */ 00165 #define HAL_USART_ERROR_ORE ((uint32_t)0x08) /*!< Overrun error */ 00166 #define HAL_USART_ERROR_DMA ((uint32_t)0x10) /*!< DMA transfer error */ 00167 /** 00168 * @} 00169 */ 00170 00171 /** @defgroup USART_Word_Length USART Word Length 00172 * @{ 00173 */ 00174 #define USART_WORDLENGTH_8B ((uint32_t)0x00000000) 00175 #define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M) 00176 /** 00177 * @} 00178 */ 00179 00180 /** @defgroup USART_Stop_Bits USART Number of Stop Bits 00181 * @{ 00182 */ 00183 #define USART_STOPBITS_1 ((uint32_t)0x00000000) 00184 #define USART_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0) 00185 #define USART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1) 00186 #define USART_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1)) 00187 /** 00188 * @} 00189 */ 00190 00191 /** @defgroup USART_Parity USART Parity 00192 * @{ 00193 */ 00194 #define USART_PARITY_NONE ((uint32_t)0x00000000) 00195 #define USART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) 00196 #define USART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 00197 /** 00198 * @} 00199 */ 00200 00201 /** @defgroup USART_Mode USART Mode 00202 * @{ 00203 */ 00204 #define USART_MODE_RX ((uint32_t)USART_CR1_RE) 00205 #define USART_MODE_TX ((uint32_t)USART_CR1_TE) 00206 #define USART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) 00207 00208 /** 00209 * @} 00210 */ 00211 00212 /** @defgroup USART_Clock USART Clock 00213 * @{ 00214 */ 00215 #define USART_CLOCK_DISABLE ((uint32_t)0x00000000) 00216 #define USART_CLOCK_ENABLE ((uint32_t)USART_CR2_CLKEN) 00217 /** 00218 * @} 00219 */ 00220 00221 /** @defgroup USART_Clock_Polarity USART Clock Polarity 00222 * @{ 00223 */ 00224 #define USART_POLARITY_LOW ((uint32_t)0x00000000) 00225 #define USART_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL) 00226 /** 00227 * @} 00228 */ 00229 00230 /** @defgroup USART_Clock_Phase USART Clock Phase 00231 * @{ 00232 */ 00233 #define USART_PHASE_1EDGE ((uint32_t)0x00000000) 00234 #define USART_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA) 00235 /** 00236 * @} 00237 */ 00238 00239 /** @defgroup USART_Last_Bit USART Last Bit 00240 * @{ 00241 */ 00242 #define USART_LASTBIT_DISABLE ((uint32_t)0x00000000) 00243 #define USART_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL) 00244 /** 00245 * @} 00246 */ 00247 00248 /** @defgroup USART_NACK_State USART NACK State 00249 * @{ 00250 */ 00251 #define USART_NACK_ENABLE ((uint32_t)USART_CR3_NACK) 00252 #define USART_NACK_DISABLE ((uint32_t)0x00000000) 00253 /** 00254 * @} 00255 */ 00256 00257 /** @defgroup USART_Flags USART Flags 00258 * Elements values convention: 0xXXXX 00259 * - 0xXXXX : Flag mask in the SR register 00260 * @{ 00261 */ 00262 00263 #define USART_FLAG_CTS ((uint32_t)USART_SR_CTS) 00264 #define USART_FLAG_LBD ((uint32_t)USART_SR_LBD) 00265 #define USART_FLAG_TXE ((uint32_t)USART_SR_TXE) 00266 #define USART_FLAG_TC ((uint32_t)USART_SR_TC) 00267 #define USART_FLAG_RXNE ((uint32_t)USART_SR_RXNE) 00268 #define USART_FLAG_IDLE ((uint32_t)USART_SR_IDLE) 00269 #define USART_FLAG_ORE ((uint32_t)USART_SR_ORE) 00270 #define USART_FLAG_NE ((uint32_t)USART_SR_NE) 00271 #define USART_FLAG_FE ((uint32_t)USART_SR_FE) 00272 #define USART_FLAG_PE ((uint32_t)USART_SR_PE) 00273 /** 00274 * @} 00275 */ 00276 00277 /** @defgroup USART_Interrupt_definition USART Interrupts Definition 00278 * Elements values convention: 0xY000XXXX 00279 * - XXXX : Interrupt mask (16 bits) in the Y register 00280 * - Y : Interrupt source register (4bits) 00281 * - 0001: CR1 register 00282 * - 0010: CR2 register 00283 * - 0011: CR3 register 00284 * 00285 * @{ 00286 */ 00287 00288 #define USART_IT_PE ((uint32_t)(USART_CR1_REG_INDEX << 28 | USART_CR1_PEIE)) 00289 #define USART_IT_TXE ((uint32_t)(USART_CR1_REG_INDEX << 28 | USART_CR1_TXEIE)) 00290 #define USART_IT_TC ((uint32_t)(USART_CR1_REG_INDEX << 28 | USART_CR1_TCIE)) 00291 #define USART_IT_RXNE ((uint32_t)(USART_CR1_REG_INDEX << 28 | USART_CR1_RXNEIE)) 00292 #define USART_IT_IDLE ((uint32_t)(USART_CR1_REG_INDEX << 28 | USART_CR1_IDLEIE)) 00293 00294 #define USART_IT_LBD ((uint32_t)(USART_CR2_REG_INDEX << 28 | USART_CR2_LBDIE)) 00295 00296 #define USART_IT_CTS ((uint32_t)(USART_CR3_REG_INDEX << 28 | USART_CR3_CTSIE)) 00297 #define USART_IT_ERR ((uint32_t)(USART_CR3_REG_INDEX << 28 | USART_CR3_EIE)) 00298 00299 00300 /** 00301 * @} 00302 */ 00303 00304 /** 00305 * @} 00306 */ 00307 00308 00309 /* Exported macro ------------------------------------------------------------*/ 00310 /** @defgroup USART_Exported_Macros USART Exported Macros 00311 * @{ 00312 */ 00313 00314 00315 /** @brief Reset USART handle state 00316 * @param __HANDLE__: specifies the USART Handle. 00317 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00318 * @retval None 00319 */ 00320 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET) 00321 00322 /** @brief Check whether the specified USART flag is set or not. 00323 * @param __HANDLE__: specifies the USART Handle. 00324 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00325 * @param __FLAG__: specifies the flag to check. 00326 * This parameter can be one of the following values: 00327 * @arg USART_FLAG_TXE: Transmit data register empty flag 00328 * @arg USART_FLAG_TC: Transmission Complete flag 00329 * @arg USART_FLAG_RXNE: Receive data register not empty flag 00330 * @arg USART_FLAG_IDLE: Idle Line detection flag 00331 * @arg USART_FLAG_ORE: OverRun Error flag 00332 * @arg USART_FLAG_NE: Noise Error flag 00333 * @arg USART_FLAG_FE: Framing Error flag 00334 * @arg USART_FLAG_PE: Parity Error flag 00335 * @retval The new state of __FLAG__ (TRUE or FALSE). 00336 */ 00337 00338 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 00339 00340 /** @brief Clear the specified USART pending flags. 00341 * @param __HANDLE__: specifies the USART Handle. 00342 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00343 * @param __FLAG__: specifies the flag to check. 00344 * This parameter can be any combination of the following values: 00345 * @arg USART_FLAG_TC: Transmission Complete flag. 00346 * @arg USART_FLAG_RXNE: Receive data register not empty flag. 00347 * 00348 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun 00349 * error) and IDLE (Idle line detected) flags are cleared by software 00350 * sequence: a read operation to USART_SR register followed by a read 00351 * operation to USART_DR register. 00352 * @note RXNE flag can be also cleared by a read to the USART_DR register. 00353 * @note TC flag can be also cleared by software sequence: a read operation to 00354 * USART_SR register followed by a write operation to USART_DR register. 00355 * @note TXE flag is cleared only by a write to the USART_DR register. 00356 * 00357 * @retval None 00358 */ 00359 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__)) 00360 00361 /** @brief Clear the USART PE pending flag. 00362 * @param __HANDLE__: specifies the USART Handle. 00363 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00364 * @retval None 00365 */ 00366 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) \ 00367 do{ \ 00368 __IO uint32_t tmpreg; \ 00369 tmpreg = (__HANDLE__)->Instance->SR; \ 00370 tmpreg = (__HANDLE__)->Instance->DR; \ 00371 UNUSED(tmpreg); \ 00372 }while(0) 00373 00374 00375 /** @brief Clear the USART FE pending flag. 00376 * @param __HANDLE__: specifies the USART Handle. 00377 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00378 * @retval None 00379 */ 00380 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__) 00381 00382 /** @brief Clear the USART NE pending flag. 00383 * @param __HANDLE__: specifies the USART Handle. 00384 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00385 * @retval None 00386 */ 00387 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__) 00388 00389 /** @brief Clear the USART ORE pending flag. 00390 * @param __HANDLE__: specifies the USART Handle. 00391 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00392 * @retval None 00393 */ 00394 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__) 00395 00396 /** @brief Clear the USART IDLE pending flag. 00397 * @param __HANDLE__: specifies the USART Handle. 00398 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00399 * @retval None 00400 */ 00401 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__) 00402 00403 /** @brief Enable the specified Usart interrupts. 00404 * @param __HANDLE__: specifies the USART Handle. 00405 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00406 * @param __INTERRUPT__: specifies the USART interrupt source to enable. 00407 * This parameter can be one of the following values: 00408 * @arg USART_IT_TXE: Transmit Data Register empty interrupt 00409 * @arg USART_IT_TC: Transmission complete interrupt 00410 * @arg USART_IT_RXNE: Receive Data register not empty interrupt 00411 * @arg USART_IT_IDLE: Idle line detection interrupt 00412 * @arg USART_IT_PE: Parity Error interrupt 00413 * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) 00414 * @retval None 00415 */ 00416 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28) == USART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & USART_IT_MASK)): \ 00417 (((__INTERRUPT__) >> 28) == USART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & USART_IT_MASK)): \ 00418 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & USART_IT_MASK))) 00419 00420 00421 /** @brief Disable the specified Usart interrupts. 00422 * @param __HANDLE__: specifies the USART Handle. 00423 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00424 * @param __INTERRUPT__: specifies the USART interrupt source to disable. 00425 * This parameter can be one of the following values: 00426 * @arg USART_IT_TXE: Transmit Data Register empty interrupt 00427 * @arg USART_IT_TC: Transmission complete interrupt 00428 * @arg USART_IT_RXNE: Receive Data register not empty interrupt 00429 * @arg USART_IT_IDLE: Idle line detection interrupt 00430 * @arg USART_IT_PE: Parity Error interrupt 00431 * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) 00432 * @retval None 00433 */ 00434 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28) == USART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & USART_IT_MASK)): \ 00435 (((__INTERRUPT__) >> 28) == USART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & USART_IT_MASK)): \ 00436 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & USART_IT_MASK))) 00437 00438 00439 00440 /** @brief Check whether the specified Usart interrupt has occurred or not. 00441 * @param __HANDLE__: specifies the USART Handle. 00442 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00443 * @param __IT__: specifies the USART interrupt source to check. 00444 * This parameter can be one of the following values: 00445 * @arg USART_IT_TXE: Transmit Data Register empty interrupt 00446 * @arg USART_IT_TC: Transmission complete interrupt 00447 * @arg USART_IT_RXNE: Receive Data register not empty interrupt 00448 * @arg USART_IT_IDLE: Idle line detection interrupt 00449 * @arg USART_IT_ERR: Error interrupt 00450 * @arg USART_IT_PE: Parity Error interrupt 00451 * @retval The new state of __IT__ (TRUE or FALSE). 00452 */ 00453 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28) == USART_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28) == USART_CR2_REG_INDEX)? \ 00454 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & USART_IT_MASK)) 00455 00456 /** @brief Enable USART 00457 * @param __HANDLE__: specifies the USART Handle. 00458 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00459 * @retval None 00460 */ 00461 #define __HAL_USART_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR1,(USART_CR1_UE)) 00462 00463 /** @brief Disable USART 00464 * @param __HANDLE__: specifies the USART Handle. 00465 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00466 * @retval None 00467 */ 00468 #define __HAL_USART_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR1,(USART_CR1_UE)) 00469 00470 00471 /** 00472 * @} 00473 */ 00474 00475 00476 /* Private macros --------------------------------------------------------*/ 00477 /** @defgroup USART_Private_Macros USART Private Macros 00478 * @{ 00479 */ 00480 00481 #define USART_CR1_REG_INDEX 1 00482 #define USART_CR2_REG_INDEX 2 00483 #define USART_CR3_REG_INDEX 3 00484 00485 #define USART_DIV(__PCLK__, __BAUD__) (((__PCLK__)*25)/(4*(__BAUD__))) 00486 #define USART_DIVMANT(__PCLK__, __BAUD__) (USART_DIV((__PCLK__), (__BAUD__))/100) 00487 #define USART_DIVFRAQ(__PCLK__, __BAUD__) (((USART_DIV((__PCLK__), (__BAUD__)) - (USART_DIVMANT((__PCLK__), (__BAUD__)) * 100)) * 16 + 50) / 100) 00488 #define USART_BRR(__PCLK__, __BAUD__) ((USART_DIVMANT((__PCLK__), (__BAUD__)) << 4)|(USART_DIVFRAQ((__PCLK__), (__BAUD__)) & 0x0F)) 00489 00490 /** Check USART Baud rate 00491 * __BAUDRATE__: Baudrate specified by the user 00492 * The maximum Baud Rate is derived from the maximum clock on APB (i.e. 72 MHz) 00493 * divided by the smallest oversampling used on the USART (i.e. 16) 00494 * return : TRUE or FALSE 00495 */ 00496 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 4500001) 00497 00498 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WORDLENGTH_8B) || \ 00499 ((LENGTH) == USART_WORDLENGTH_9B)) 00500 00501 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_STOPBITS_1) || \ 00502 ((STOPBITS) == USART_STOPBITS_0_5) || \ 00503 ((STOPBITS) == USART_STOPBITS_1_5) || \ 00504 ((STOPBITS) == USART_STOPBITS_2)) 00505 00506 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_PARITY_NONE) || \ 00507 ((PARITY) == USART_PARITY_EVEN) || \ 00508 ((PARITY) == USART_PARITY_ODD)) 00509 00510 #define IS_USART_MODE(MODE) ((((MODE) & (~((uint32_t)USART_MODE_TX_RX))) == 0x00) && ((MODE) != (uint32_t)0x00000000)) 00511 00512 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_CLOCK_DISABLE) || \ 00513 ((CLOCK) == USART_CLOCK_ENABLE)) 00514 00515 #define IS_USART_POLARITY(CPOL) (((CPOL) == USART_POLARITY_LOW) || ((CPOL) == USART_POLARITY_HIGH)) 00516 00517 #define IS_USART_PHASE(CPHA) (((CPHA) == USART_PHASE_1EDGE) || ((CPHA) == USART_PHASE_2EDGE)) 00518 00519 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LASTBIT_DISABLE) || \ 00520 ((LASTBIT) == USART_LASTBIT_ENABLE)) 00521 00522 #define IS_USART_NACK_STATE(NACK) (((NACK) == USART_NACK_ENABLE) || \ 00523 ((NACK) == USART_NACK_DISABLE)) 00524 00525 /** USART interruptions flag mask 00526 * 00527 */ 00528 #define USART_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \ 00529 USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE ) 00530 00531 /** 00532 * @} 00533 */ 00534 00535 00536 /* Exported functions --------------------------------------------------------*/ 00537 00538 /** @addtogroup USART_Exported_Functions USART Exported Functions 00539 * @{ 00540 */ 00541 00542 /** @addtogroup USART_Exported_Functions_Group1 Initialization and de-initialization functions 00543 * @{ 00544 */ 00545 00546 /* Initialization and de-initialization functions ******************************/ 00547 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart); 00548 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart); 00549 void HAL_USART_MspInit(USART_HandleTypeDef *husart); 00550 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart); 00551 00552 /** 00553 * @} 00554 */ 00555 00556 /** @addtogroup USART_Exported_Functions_Group2 IO operation functions 00557 * @{ 00558 */ 00559 00560 /* IO operation functions *******************************************************/ 00561 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout); 00562 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout); 00563 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout); 00564 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size); 00565 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size); 00566 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size); 00567 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size); 00568 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size); 00569 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size); 00570 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart); 00571 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart); 00572 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart); 00573 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart); 00574 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart); 00575 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart); 00576 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart); 00577 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart); 00578 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart); 00579 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart); 00580 00581 /** 00582 * @} 00583 */ 00584 00585 /* Peripheral Control functions ***********************************************/ 00586 00587 /** @addtogroup USART_Exported_Functions_Group3 Peripheral State and Errors functions 00588 * @{ 00589 */ 00590 00591 /* Peripheral State and Error functions ***************************************/ 00592 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart); 00593 uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart); 00594 00595 /** 00596 * @} 00597 */ 00598 00599 /** 00600 * @} 00601 */ 00602 00603 /** 00604 * @} 00605 */ 00606 00607 /** 00608 * @} 00609 */ 00610 00611 #ifdef __cplusplus 00612 } 00613 #endif 00614 00615 #endif /* __STM32F1xx_HAL_USART_H */ 00616 00617 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 15:37:24 by
