STM32F439xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f4xx_hal_usart.h 00004 * @author MCD Application Team 00005 * @brief Header file of USART HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 00036 /* Define to prevent recursive inclusion -------------------------------------*/ 00037 #ifndef __STM32F4xx_HAL_USART_H 00038 #define __STM32F4xx_HAL_USART_H 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 /* Includes ------------------------------------------------------------------*/ 00045 #include "stm32f4xx_hal_def.h" 00046 00047 /** @addtogroup STM32F4xx_HAL_Driver 00048 * @{ 00049 */ 00050 00051 /** @addtogroup USART 00052 * @{ 00053 */ 00054 00055 /* Exported types ------------------------------------------------------------*/ 00056 /** @defgroup USART_Exported_Types USART Exported Types 00057 * @{ 00058 */ 00059 00060 /** 00061 * @brief USART Init Structure definition 00062 */ 00063 typedef struct 00064 { 00065 uint32_t BaudRate; /*!< This member configures the Usart communication baud rate. 00066 The baud rate is computed using the following formula: 00067 - IntegerDivider = ((PCLKx) / (8 * (husart->Init.BaudRate))) 00068 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */ 00069 00070 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. 00071 This parameter can be a value of @ref USART_Word_Length */ 00072 00073 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted. 00074 This parameter can be a value of @ref USART_Stop_Bits */ 00075 00076 uint32_t Parity; /*!< Specifies the parity mode. 00077 This parameter can be a value of @ref USART_Parity 00078 @note When parity is enabled, the computed parity is inserted 00079 at the MSB position of the transmitted data (9th bit when 00080 the word length is set to 9 data bits; 8th bit when the 00081 word length is set to 8 data bits). */ 00082 00083 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled. 00084 This parameter can be a value of @ref USART_Mode */ 00085 00086 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock. 00087 This parameter can be a value of @ref USART_Clock_Polarity */ 00088 00089 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made. 00090 This parameter can be a value of @ref USART_Clock_Phase */ 00091 00092 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted 00093 data bit (MSB) has to be output on the SCLK pin in synchronous mode. 00094 This parameter can be a value of @ref USART_Last_Bit */ 00095 }USART_InitTypeDef; 00096 00097 /** 00098 * @brief HAL State structures definition 00099 */ 00100 typedef enum 00101 { 00102 HAL_USART_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized */ 00103 HAL_USART_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */ 00104 HAL_USART_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */ 00105 HAL_USART_STATE_BUSY_TX = 0x12U, /*!< Data Transmission process is ongoing */ 00106 HAL_USART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */ 00107 HAL_USART_STATE_BUSY_TX_RX = 0x32U, /*!< Data Transmission Reception process is ongoing */ 00108 HAL_USART_STATE_TIMEOUT = 0x03U, /*!< Timeout state */ 00109 HAL_USART_STATE_ERROR = 0x04U /*!< Error */ 00110 }HAL_USART_StateTypeDef; 00111 00112 /** 00113 * @brief USART handle Structure definition 00114 */ 00115 typedef struct 00116 { 00117 USART_TypeDef *Instance; /* USART registers base address */ 00118 00119 USART_InitTypeDef Init; /* Usart communication parameters */ 00120 00121 uint8_t *pTxBuffPtr; /* Pointer to Usart Tx transfer Buffer */ 00122 00123 uint16_t TxXferSize; /* Usart Tx Transfer size */ 00124 00125 __IO uint16_t TxXferCount; /* Usart Tx Transfer Counter */ 00126 00127 uint8_t *pRxBuffPtr; /* Pointer to Usart Rx transfer Buffer */ 00128 00129 uint16_t RxXferSize; /* Usart Rx Transfer size */ 00130 00131 __IO uint16_t RxXferCount; /* Usart Rx Transfer Counter */ 00132 00133 DMA_HandleTypeDef *hdmatx; /* Usart Tx DMA Handle parameters */ 00134 00135 DMA_HandleTypeDef *hdmarx; /* Usart Rx DMA Handle parameters */ 00136 00137 HAL_LockTypeDef Lock; /* Locking object */ 00138 00139 __IO HAL_USART_StateTypeDef State; /* Usart communication state */ 00140 00141 __IO uint32_t ErrorCode; /* USART Error code */ 00142 00143 }USART_HandleTypeDef; 00144 /** 00145 * @} 00146 */ 00147 00148 /* Exported constants --------------------------------------------------------*/ 00149 /** @defgroup USART_Exported_Constants USART Exported Constants 00150 * @{ 00151 */ 00152 00153 /** @defgroup USART_Error_Code USART Error Code 00154 * @brief USART Error Code 00155 * @{ 00156 */ 00157 #define HAL_USART_ERROR_NONE 0x00000000U /*!< No error */ 00158 #define HAL_USART_ERROR_PE 0x00000001U /*!< Parity error */ 00159 #define HAL_USART_ERROR_NE 0x00000002U /*!< Noise error */ 00160 #define HAL_USART_ERROR_FE 0x00000004U /*!< Frame error */ 00161 #define HAL_USART_ERROR_ORE 0x00000008U /*!< Overrun error */ 00162 #define HAL_USART_ERROR_DMA 0x00000010U /*!< DMA transfer error */ 00163 /** 00164 * @} 00165 */ 00166 00167 /** @defgroup USART_Word_Length USART Word Length 00168 * @{ 00169 */ 00170 #define USART_WORDLENGTH_8B 0x00000000U 00171 #define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M) 00172 /** 00173 * @} 00174 */ 00175 00176 /** @defgroup USART_Stop_Bits USART Number of Stop Bits 00177 * @{ 00178 */ 00179 #define USART_STOPBITS_1 0x00000000U 00180 #define USART_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0) 00181 #define USART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1) 00182 #define USART_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1)) 00183 /** 00184 * @} 00185 */ 00186 00187 /** @defgroup USART_Parity USART Parity 00188 * @{ 00189 */ 00190 #define USART_PARITY_NONE 0x00000000U 00191 #define USART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) 00192 #define USART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 00193 /** 00194 * @} 00195 */ 00196 00197 /** @defgroup USART_Mode USART Mode 00198 * @{ 00199 */ 00200 #define USART_MODE_RX ((uint32_t)USART_CR1_RE) 00201 #define USART_MODE_TX ((uint32_t)USART_CR1_TE) 00202 #define USART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) 00203 /** 00204 * @} 00205 */ 00206 00207 /** @defgroup USART_Clock USART Clock 00208 * @{ 00209 */ 00210 #define USART_CLOCK_DISABLE 0x00000000U 00211 #define USART_CLOCK_ENABLE ((uint32_t)USART_CR2_CLKEN) 00212 /** 00213 * @} 00214 */ 00215 00216 /** @defgroup USART_Clock_Polarity USART Clock Polarity 00217 * @{ 00218 */ 00219 #define USART_POLARITY_LOW 0x00000000U 00220 #define USART_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL) 00221 /** 00222 * @} 00223 */ 00224 00225 /** @defgroup USART_Clock_Phase USART Clock Phase 00226 * @{ 00227 */ 00228 #define USART_PHASE_1EDGE 0x00000000U 00229 #define USART_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA) 00230 /** 00231 * @} 00232 */ 00233 00234 /** @defgroup USART_Last_Bit USART Last Bit 00235 * @{ 00236 */ 00237 #define USART_LASTBIT_DISABLE 0x00000000U 00238 #define USART_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL) 00239 /** 00240 * @} 00241 */ 00242 00243 /** @defgroup USART_NACK_State USART NACK State 00244 * @{ 00245 */ 00246 #define USART_NACK_ENABLE ((uint32_t)USART_CR3_NACK) 00247 #define USART_NACK_DISABLE 0x00000000U 00248 /** 00249 * @} 00250 */ 00251 00252 /** @defgroup USART_Flags USART Flags 00253 * Elements values convention: 0xXXXX 00254 * - 0xXXXX : Flag mask in the SR register 00255 * @{ 00256 */ 00257 #define USART_FLAG_TXE 0x00000080U 00258 #define USART_FLAG_TC 0x00000040U 00259 #define USART_FLAG_RXNE 0x00000020U 00260 #define USART_FLAG_IDLE 0x00000010U 00261 #define USART_FLAG_ORE 0x00000008U 00262 #define USART_FLAG_NE 0x00000004U 00263 #define USART_FLAG_FE 0x00000002U 00264 #define USART_FLAG_PE 0x00000001U 00265 /** 00266 * @} 00267 */ 00268 00269 /** @defgroup USART_Interrupt_definition USART Interrupts Definition 00270 * Elements values convention: 0xY000XXXX 00271 * - XXXX : Interrupt mask in the XX register 00272 * - Y : Interrupt source register (2bits) 00273 * - 01: CR1 register 00274 * - 10: CR2 register 00275 * - 11: CR3 register 00276 * 00277 * @{ 00278 */ 00279 #define USART_IT_PE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_PEIE)) 00280 #define USART_IT_TXE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE)) 00281 #define USART_IT_TC ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_TCIE)) 00282 #define USART_IT_RXNE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE)) 00283 #define USART_IT_IDLE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE)) 00284 00285 #define USART_IT_LBD ((uint32_t)(USART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE)) 00286 00287 #define USART_IT_CTS ((uint32_t)(USART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE)) 00288 #define USART_IT_ERR ((uint32_t)(USART_CR3_REG_INDEX << 28U | USART_CR3_EIE)) 00289 /** 00290 * @} 00291 */ 00292 00293 /** 00294 * @} 00295 */ 00296 00297 /* Exported macro ------------------------------------------------------------*/ 00298 /** @defgroup USART_Exported_Macros USART Exported Macros 00299 * @{ 00300 */ 00301 00302 /** @brief Reset USART handle state 00303 * @param __HANDLE__ specifies the USART Handle. 00304 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral. 00305 * @retval None 00306 */ 00307 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET) 00308 00309 /** @brief Checks whether the specified Smartcard flag is set or not. 00310 * @param __HANDLE__ specifies the USART Handle. 00311 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral. 00312 * @param __FLAG__ specifies the flag to check. 00313 * This parameter can be one of the following values: 00314 * @arg USART_FLAG_TXE: Transmit data register empty flag 00315 * @arg USART_FLAG_TC: Transmission Complete flag 00316 * @arg USART_FLAG_RXNE: Receive data register not empty flag 00317 * @arg USART_FLAG_IDLE: Idle Line detection flag 00318 * @arg USART_FLAG_ORE: Overrun Error flag 00319 * @arg USART_FLAG_NE: Noise Error flag 00320 * @arg USART_FLAG_FE: Framing Error flag 00321 * @arg USART_FLAG_PE: Parity Error flag 00322 * @retval The new state of __FLAG__ (TRUE or FALSE). 00323 */ 00324 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 00325 00326 /** @brief Clears the specified Smartcard pending flags. 00327 * @param __HANDLE__ specifies the USART Handle. 00328 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral. 00329 * @param __FLAG__ specifies the flag to check. 00330 * This parameter can be any combination of the following values: 00331 * @arg USART_FLAG_TC: Transmission Complete flag. 00332 * @arg USART_FLAG_RXNE: Receive data register not empty flag. 00333 * 00334 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun 00335 * error) and IDLE (Idle line detected) flags are cleared by software 00336 * sequence: a read operation to USART_SR register followed by a read 00337 * operation to USART_DR register. 00338 * @note RXNE flag can be also cleared by a read to the USART_DR register. 00339 * @note TC flag can be also cleared by software sequence: a read operation to 00340 * USART_SR register followed by a write operation to USART_DR register. 00341 * @note TXE flag is cleared only by a write to the USART_DR register. 00342 * 00343 * @retval None 00344 */ 00345 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__)) 00346 00347 /** @brief Clear the USART PE pending flag. 00348 * @param __HANDLE__ specifies the USART Handle. 00349 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral. 00350 * @retval None 00351 */ 00352 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) \ 00353 do{ \ 00354 __IO uint32_t tmpreg = 0x00U; \ 00355 tmpreg = (__HANDLE__)->Instance->SR; \ 00356 tmpreg = (__HANDLE__)->Instance->DR; \ 00357 UNUSED(tmpreg); \ 00358 } while(0U) 00359 00360 /** @brief Clear the USART FE pending flag. 00361 * @param __HANDLE__ specifies the USART Handle. 00362 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral. 00363 * @retval None 00364 */ 00365 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__) 00366 00367 /** @brief Clear the USART NE pending flag. 00368 * @param __HANDLE__ specifies the USART Handle. 00369 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral. 00370 * @retval None 00371 */ 00372 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__) 00373 00374 /** @brief Clear the UART ORE pending flag. 00375 * @param __HANDLE__ specifies the USART Handle. 00376 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral. 00377 * @retval None 00378 */ 00379 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__) 00380 00381 /** @brief Clear the USART IDLE pending flag. 00382 * @param __HANDLE__ specifies the USART Handle. 00383 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral. 00384 * @retval None 00385 */ 00386 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__) 00387 00388 /** @brief Enables or disables the specified USART interrupts. 00389 * @param __HANDLE__ specifies the USART Handle. 00390 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral. 00391 * @param __INTERRUPT__ specifies the USART interrupt source to check. 00392 * This parameter can be one of the following values: 00393 * @arg USART_IT_TXE: Transmit Data Register empty interrupt 00394 * @arg USART_IT_TC: Transmission complete interrupt 00395 * @arg USART_IT_RXNE: Receive Data register not empty interrupt 00396 * @arg USART_IT_IDLE: Idle line detection interrupt 00397 * @arg USART_IT_PE: Parity Error interrupt 00398 * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) 00399 * This parameter can be: ENABLE or DISABLE. 00400 * @retval None 00401 */ 00402 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & USART_IT_MASK)): \ 00403 (((__INTERRUPT__) >> 28U) == 2U)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & USART_IT_MASK)): \ 00404 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & USART_IT_MASK))) 00405 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & USART_IT_MASK)): \ 00406 (((__INTERRUPT__) >> 28U) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & USART_IT_MASK)): \ 00407 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & USART_IT_MASK))) 00408 00409 /** @brief Checks whether the specified USART interrupt has occurred or not. 00410 * @param __HANDLE__ specifies the USART Handle. 00411 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral. 00412 * @param __IT__ specifies the USART interrupt source to check. 00413 * This parameter can be one of the following values: 00414 * @arg USART_IT_TXE: Transmit Data Register empty interrupt 00415 * @arg USART_IT_TC: Transmission complete interrupt 00416 * @arg USART_IT_RXNE: Receive Data register not empty interrupt 00417 * @arg USART_IT_IDLE: Idle line detection interrupt 00418 * @arg USART_IT_ERR: Error interrupt 00419 * @arg USART_IT_PE: Parity Error interrupt 00420 * @retval The new state of __IT__ (TRUE or FALSE). 00421 */ 00422 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == 1U)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == 2U)? \ 00423 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & USART_IT_MASK)) 00424 00425 /** @brief Macro to enable the USART's one bit sample method 00426 * @param __HANDLE__ specifies the USART Handle. 00427 * @retval None 00428 */ 00429 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT) 00430 00431 /** @brief Macro to disable the USART's one bit sample method 00432 * @param __HANDLE__ specifies the USART Handle. 00433 * @retval None 00434 */ 00435 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT)) 00436 00437 /** @brief Enable USART 00438 * @param __HANDLE__ specifies the USART Handle. 00439 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00440 * @retval None 00441 */ 00442 #define __HAL_USART_ENABLE(__HANDLE__) ( (__HANDLE__)->Instance->CR1 |= USART_CR1_UE) 00443 00444 /** @brief Disable USART 00445 * @param __HANDLE__ specifies the USART Handle. 00446 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device). 00447 * @retval None 00448 */ 00449 #define __HAL_USART_DISABLE(__HANDLE__) ( (__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE) 00450 00451 /** 00452 * @} 00453 */ 00454 /* Exported functions --------------------------------------------------------*/ 00455 /** @addtogroup USART_Exported_Functions 00456 * @{ 00457 */ 00458 00459 /** @addtogroup USART_Exported_Functions_Group1 00460 * @{ 00461 */ 00462 /* Initialization/de-initialization functions **********************************/ 00463 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart); 00464 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart); 00465 void HAL_USART_MspInit(USART_HandleTypeDef *husart); 00466 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart); 00467 /** 00468 * @} 00469 */ 00470 00471 /** @addtogroup USART_Exported_Functions_Group2 00472 * @{ 00473 */ 00474 /* IO operation functions *******************************************************/ 00475 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout); 00476 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout); 00477 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout); 00478 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size); 00479 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size); 00480 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size); 00481 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size); 00482 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size); 00483 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size); 00484 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart); 00485 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart); 00486 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart); 00487 /* Transfer Abort functions */ 00488 HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart); 00489 HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart); 00490 00491 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart); 00492 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart); 00493 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart); 00494 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart); 00495 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart); 00496 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart); 00497 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart); 00498 void HAL_USART_AbortCpltCallback (USART_HandleTypeDef *husart); 00499 /** 00500 * @} 00501 */ 00502 00503 /** @addtogroup USART_Exported_Functions_Group3 00504 * @{ 00505 */ 00506 /* Peripheral State functions ************************************************/ 00507 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart); 00508 uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart); 00509 /** 00510 * @} 00511 */ 00512 00513 /** 00514 * @} 00515 */ 00516 /* Private types -------------------------------------------------------------*/ 00517 /* Private variables ---------------------------------------------------------*/ 00518 /* Private constants ---------------------------------------------------------*/ 00519 /** @defgroup USART_Private_Constants USART Private Constants 00520 * @{ 00521 */ 00522 /** @brief USART interruptions flag mask 00523 * 00524 */ 00525 #define USART_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \ 00526 USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE ) 00527 00528 #define USART_CR1_REG_INDEX 1U 00529 #define USART_CR2_REG_INDEX 2U 00530 #define USART_CR3_REG_INDEX 3U 00531 /** 00532 * @} 00533 */ 00534 00535 /* Private macros ------------------------------------------------------------*/ 00536 /** @defgroup USART_Private_Macros USART Private Macros 00537 * @{ 00538 */ 00539 #define IS_USART_NACK_STATE(NACK) (((NACK) == USART_NACK_ENABLE) || \ 00540 ((NACK) == USART_NACK_DISABLE)) 00541 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LASTBIT_DISABLE) || \ 00542 ((LASTBIT) == USART_LASTBIT_ENABLE)) 00543 #define IS_USART_PHASE(CPHA) (((CPHA) == USART_PHASE_1EDGE) || ((CPHA) == USART_PHASE_2EDGE)) 00544 #define IS_USART_POLARITY(CPOL) (((CPOL) == USART_POLARITY_LOW) || ((CPOL) == USART_POLARITY_HIGH)) 00545 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_CLOCK_DISABLE) || \ 00546 ((CLOCK) == USART_CLOCK_ENABLE)) 00547 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WORDLENGTH_8B) || \ 00548 ((LENGTH) == USART_WORDLENGTH_9B)) 00549 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_STOPBITS_1) || \ 00550 ((STOPBITS) == USART_STOPBITS_0_5) || \ 00551 ((STOPBITS) == USART_STOPBITS_1_5) || \ 00552 ((STOPBITS) == USART_STOPBITS_2)) 00553 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_PARITY_NONE) || \ 00554 ((PARITY) == USART_PARITY_EVEN) || \ 00555 ((PARITY) == USART_PARITY_ODD)) 00556 #define IS_USART_MODE(MODE) ((((MODE) & 0xFFF3U) == 0x00U) && ((MODE) != 0x00U)) 00557 #define IS_USART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U) 00558 00559 #define USART_DIV(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(2U*(_BAUD_))) 00560 #define USART_DIVMANT(_PCLK_, _BAUD_) (USART_DIV((_PCLK_), (_BAUD_))/100U) 00561 #define USART_DIVFRAQ(_PCLK_, _BAUD_) (((USART_DIV((_PCLK_), (_BAUD_)) - (USART_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U) 00562 #define USART_BRR(_PCLK_, _BAUD_) ((USART_DIVMANT((_PCLK_), (_BAUD_)) << 4U)|(USART_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU)) 00563 /** 00564 * @} 00565 */ 00566 00567 /* Private functions ---------------------------------------------------------*/ 00568 /** @defgroup USART_Private_Functions USART Private Functions 00569 * @{ 00570 */ 00571 00572 /** 00573 * @} 00574 */ 00575 00576 /** 00577 * @} 00578 */ 00579 00580 /** 00581 * @} 00582 */ 00583 00584 #ifdef __cplusplus 00585 } 00586 #endif 00587 00588 #endif /* __STM32F4xx_HAL_USART_H */ 00589 00590 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/