inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NYX 0:85b3fd62ea1a 1 /**
NYX 0:85b3fd62ea1a 2 ******************************************************************************
NYX 0:85b3fd62ea1a 3 * @file stm32f4xx_hal_usart.h
NYX 0:85b3fd62ea1a 4 * @author MCD Application Team
NYX 0:85b3fd62ea1a 5 * @version V1.7.1
NYX 0:85b3fd62ea1a 6 * @date 14-April-2017
NYX 0:85b3fd62ea1a 7 * @brief Header file of USART HAL module.
NYX 0:85b3fd62ea1a 8 ******************************************************************************
NYX 0:85b3fd62ea1a 9 * @attention
NYX 0:85b3fd62ea1a 10 *
NYX 0:85b3fd62ea1a 11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
NYX 0:85b3fd62ea1a 12 *
NYX 0:85b3fd62ea1a 13 * Redistribution and use in source and binary forms, with or without modification,
NYX 0:85b3fd62ea1a 14 * are permitted provided that the following conditions are met:
NYX 0:85b3fd62ea1a 15 * 1. Redistributions of source code must retain the above copyright notice,
NYX 0:85b3fd62ea1a 16 * this list of conditions and the following disclaimer.
NYX 0:85b3fd62ea1a 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
NYX 0:85b3fd62ea1a 18 * this list of conditions and the following disclaimer in the documentation
NYX 0:85b3fd62ea1a 19 * and/or other materials provided with the distribution.
NYX 0:85b3fd62ea1a 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
NYX 0:85b3fd62ea1a 21 * may be used to endorse or promote products derived from this software
NYX 0:85b3fd62ea1a 22 * without specific prior written permission.
NYX 0:85b3fd62ea1a 23 *
NYX 0:85b3fd62ea1a 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
NYX 0:85b3fd62ea1a 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NYX 0:85b3fd62ea1a 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NYX 0:85b3fd62ea1a 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
NYX 0:85b3fd62ea1a 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NYX 0:85b3fd62ea1a 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
NYX 0:85b3fd62ea1a 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
NYX 0:85b3fd62ea1a 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
NYX 0:85b3fd62ea1a 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
NYX 0:85b3fd62ea1a 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NYX 0:85b3fd62ea1a 34 *
NYX 0:85b3fd62ea1a 35 ******************************************************************************
NYX 0:85b3fd62ea1a 36 */
NYX 0:85b3fd62ea1a 37
NYX 0:85b3fd62ea1a 38 /* Define to prevent recursive inclusion -------------------------------------*/
NYX 0:85b3fd62ea1a 39 #ifndef __STM32F4xx_HAL_USART_H
NYX 0:85b3fd62ea1a 40 #define __STM32F4xx_HAL_USART_H
NYX 0:85b3fd62ea1a 41
NYX 0:85b3fd62ea1a 42 #ifdef __cplusplus
NYX 0:85b3fd62ea1a 43 extern "C" {
NYX 0:85b3fd62ea1a 44 #endif
NYX 0:85b3fd62ea1a 45
NYX 0:85b3fd62ea1a 46 /* Includes ------------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 47 #include "stm32f4xx_hal_def.h"
NYX 0:85b3fd62ea1a 48
NYX 0:85b3fd62ea1a 49 /** @addtogroup STM32F4xx_HAL_Driver
NYX 0:85b3fd62ea1a 50 * @{
NYX 0:85b3fd62ea1a 51 */
NYX 0:85b3fd62ea1a 52
NYX 0:85b3fd62ea1a 53 /** @addtogroup USART
NYX 0:85b3fd62ea1a 54 * @{
NYX 0:85b3fd62ea1a 55 */
NYX 0:85b3fd62ea1a 56
NYX 0:85b3fd62ea1a 57 /* Exported types ------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 58 /** @defgroup USART_Exported_Types USART Exported Types
NYX 0:85b3fd62ea1a 59 * @{
NYX 0:85b3fd62ea1a 60 */
NYX 0:85b3fd62ea1a 61
NYX 0:85b3fd62ea1a 62 /**
NYX 0:85b3fd62ea1a 63 * @brief USART Init Structure definition
NYX 0:85b3fd62ea1a 64 */
NYX 0:85b3fd62ea1a 65 typedef struct
NYX 0:85b3fd62ea1a 66 {
NYX 0:85b3fd62ea1a 67 uint32_t BaudRate; /*!< This member configures the Usart communication baud rate.
NYX 0:85b3fd62ea1a 68 The baud rate is computed using the following formula:
NYX 0:85b3fd62ea1a 69 - IntegerDivider = ((PCLKx) / (8 * (husart->Init.BaudRate)))
NYX 0:85b3fd62ea1a 70 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
NYX 0:85b3fd62ea1a 71
NYX 0:85b3fd62ea1a 72 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
NYX 0:85b3fd62ea1a 73 This parameter can be a value of @ref USART_Word_Length */
NYX 0:85b3fd62ea1a 74
NYX 0:85b3fd62ea1a 75 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
NYX 0:85b3fd62ea1a 76 This parameter can be a value of @ref USART_Stop_Bits */
NYX 0:85b3fd62ea1a 77
NYX 0:85b3fd62ea1a 78 uint32_t Parity; /*!< Specifies the parity mode.
NYX 0:85b3fd62ea1a 79 This parameter can be a value of @ref USART_Parity
NYX 0:85b3fd62ea1a 80 @note When parity is enabled, the computed parity is inserted
NYX 0:85b3fd62ea1a 81 at the MSB position of the transmitted data (9th bit when
NYX 0:85b3fd62ea1a 82 the word length is set to 9 data bits; 8th bit when the
NYX 0:85b3fd62ea1a 83 word length is set to 8 data bits). */
NYX 0:85b3fd62ea1a 84
NYX 0:85b3fd62ea1a 85 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
NYX 0:85b3fd62ea1a 86 This parameter can be a value of @ref USART_Mode */
NYX 0:85b3fd62ea1a 87
NYX 0:85b3fd62ea1a 88 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
NYX 0:85b3fd62ea1a 89 This parameter can be a value of @ref USART_Clock_Polarity */
NYX 0:85b3fd62ea1a 90
NYX 0:85b3fd62ea1a 91 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
NYX 0:85b3fd62ea1a 92 This parameter can be a value of @ref USART_Clock_Phase */
NYX 0:85b3fd62ea1a 93
NYX 0:85b3fd62ea1a 94 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
NYX 0:85b3fd62ea1a 95 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
NYX 0:85b3fd62ea1a 96 This parameter can be a value of @ref USART_Last_Bit */
NYX 0:85b3fd62ea1a 97 }USART_InitTypeDef;
NYX 0:85b3fd62ea1a 98
NYX 0:85b3fd62ea1a 99 /**
NYX 0:85b3fd62ea1a 100 * @brief HAL State structures definition
NYX 0:85b3fd62ea1a 101 */
NYX 0:85b3fd62ea1a 102 typedef enum
NYX 0:85b3fd62ea1a 103 {
NYX 0:85b3fd62ea1a 104 HAL_USART_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized */
NYX 0:85b3fd62ea1a 105 HAL_USART_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
NYX 0:85b3fd62ea1a 106 HAL_USART_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
NYX 0:85b3fd62ea1a 107 HAL_USART_STATE_BUSY_TX = 0x12U, /*!< Data Transmission process is ongoing */
NYX 0:85b3fd62ea1a 108 HAL_USART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
NYX 0:85b3fd62ea1a 109 HAL_USART_STATE_BUSY_TX_RX = 0x32U, /*!< Data Transmission Reception process is ongoing */
NYX 0:85b3fd62ea1a 110 HAL_USART_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
NYX 0:85b3fd62ea1a 111 HAL_USART_STATE_ERROR = 0x04U /*!< Error */
NYX 0:85b3fd62ea1a 112 }HAL_USART_StateTypeDef;
NYX 0:85b3fd62ea1a 113
NYX 0:85b3fd62ea1a 114 /**
NYX 0:85b3fd62ea1a 115 * @brief USART handle Structure definition
NYX 0:85b3fd62ea1a 116 */
NYX 0:85b3fd62ea1a 117 typedef struct
NYX 0:85b3fd62ea1a 118 {
NYX 0:85b3fd62ea1a 119 USART_TypeDef *Instance; /* USART registers base address */
NYX 0:85b3fd62ea1a 120
NYX 0:85b3fd62ea1a 121 USART_InitTypeDef Init; /* Usart communication parameters */
NYX 0:85b3fd62ea1a 122
NYX 0:85b3fd62ea1a 123 uint8_t *pTxBuffPtr; /* Pointer to Usart Tx transfer Buffer */
NYX 0:85b3fd62ea1a 124
NYX 0:85b3fd62ea1a 125 uint16_t TxXferSize; /* Usart Tx Transfer size */
NYX 0:85b3fd62ea1a 126
NYX 0:85b3fd62ea1a 127 __IO uint16_t TxXferCount; /* Usart Tx Transfer Counter */
NYX 0:85b3fd62ea1a 128
NYX 0:85b3fd62ea1a 129 uint8_t *pRxBuffPtr; /* Pointer to Usart Rx transfer Buffer */
NYX 0:85b3fd62ea1a 130
NYX 0:85b3fd62ea1a 131 uint16_t RxXferSize; /* Usart Rx Transfer size */
NYX 0:85b3fd62ea1a 132
NYX 0:85b3fd62ea1a 133 __IO uint16_t RxXferCount; /* Usart Rx Transfer Counter */
NYX 0:85b3fd62ea1a 134
NYX 0:85b3fd62ea1a 135 DMA_HandleTypeDef *hdmatx; /* Usart Tx DMA Handle parameters */
NYX 0:85b3fd62ea1a 136
NYX 0:85b3fd62ea1a 137 DMA_HandleTypeDef *hdmarx; /* Usart Rx DMA Handle parameters */
NYX 0:85b3fd62ea1a 138
NYX 0:85b3fd62ea1a 139 HAL_LockTypeDef Lock; /* Locking object */
NYX 0:85b3fd62ea1a 140
NYX 0:85b3fd62ea1a 141 __IO HAL_USART_StateTypeDef State; /* Usart communication state */
NYX 0:85b3fd62ea1a 142
NYX 0:85b3fd62ea1a 143 __IO uint32_t ErrorCode; /* USART Error code */
NYX 0:85b3fd62ea1a 144
NYX 0:85b3fd62ea1a 145 }USART_HandleTypeDef;
NYX 0:85b3fd62ea1a 146 /**
NYX 0:85b3fd62ea1a 147 * @}
NYX 0:85b3fd62ea1a 148 */
NYX 0:85b3fd62ea1a 149
NYX 0:85b3fd62ea1a 150 /* Exported constants --------------------------------------------------------*/
NYX 0:85b3fd62ea1a 151 /** @defgroup USART_Exported_Constants USART Exported Constants
NYX 0:85b3fd62ea1a 152 * @{
NYX 0:85b3fd62ea1a 153 */
NYX 0:85b3fd62ea1a 154
NYX 0:85b3fd62ea1a 155 /** @defgroup USART_Error_Code USART Error Code
NYX 0:85b3fd62ea1a 156 * @brief USART Error Code
NYX 0:85b3fd62ea1a 157 * @{
NYX 0:85b3fd62ea1a 158 */
NYX 0:85b3fd62ea1a 159 #define HAL_USART_ERROR_NONE 0x00000000U /*!< No error */
NYX 0:85b3fd62ea1a 160 #define HAL_USART_ERROR_PE 0x00000001U /*!< Parity error */
NYX 0:85b3fd62ea1a 161 #define HAL_USART_ERROR_NE 0x00000002U /*!< Noise error */
NYX 0:85b3fd62ea1a 162 #define HAL_USART_ERROR_FE 0x00000004U /*!< Frame error */
NYX 0:85b3fd62ea1a 163 #define HAL_USART_ERROR_ORE 0x00000008U /*!< Overrun error */
NYX 0:85b3fd62ea1a 164 #define HAL_USART_ERROR_DMA 0x00000010U /*!< DMA transfer error */
NYX 0:85b3fd62ea1a 165 /**
NYX 0:85b3fd62ea1a 166 * @}
NYX 0:85b3fd62ea1a 167 */
NYX 0:85b3fd62ea1a 168
NYX 0:85b3fd62ea1a 169 /** @defgroup USART_Word_Length USART Word Length
NYX 0:85b3fd62ea1a 170 * @{
NYX 0:85b3fd62ea1a 171 */
NYX 0:85b3fd62ea1a 172 #define USART_WORDLENGTH_8B 0x00000000U
NYX 0:85b3fd62ea1a 173 #define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
NYX 0:85b3fd62ea1a 174 /**
NYX 0:85b3fd62ea1a 175 * @}
NYX 0:85b3fd62ea1a 176 */
NYX 0:85b3fd62ea1a 177
NYX 0:85b3fd62ea1a 178 /** @defgroup USART_Stop_Bits USART Number of Stop Bits
NYX 0:85b3fd62ea1a 179 * @{
NYX 0:85b3fd62ea1a 180 */
NYX 0:85b3fd62ea1a 181 #define USART_STOPBITS_1 0x00000000U
NYX 0:85b3fd62ea1a 182 #define USART_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0)
NYX 0:85b3fd62ea1a 183 #define USART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
NYX 0:85b3fd62ea1a 184 #define USART_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
NYX 0:85b3fd62ea1a 185 /**
NYX 0:85b3fd62ea1a 186 * @}
NYX 0:85b3fd62ea1a 187 */
NYX 0:85b3fd62ea1a 188
NYX 0:85b3fd62ea1a 189 /** @defgroup USART_Parity USART Parity
NYX 0:85b3fd62ea1a 190 * @{
NYX 0:85b3fd62ea1a 191 */
NYX 0:85b3fd62ea1a 192 #define USART_PARITY_NONE 0x00000000U
NYX 0:85b3fd62ea1a 193 #define USART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
NYX 0:85b3fd62ea1a 194 #define USART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
NYX 0:85b3fd62ea1a 195 /**
NYX 0:85b3fd62ea1a 196 * @}
NYX 0:85b3fd62ea1a 197 */
NYX 0:85b3fd62ea1a 198
NYX 0:85b3fd62ea1a 199 /** @defgroup USART_Mode USART Mode
NYX 0:85b3fd62ea1a 200 * @{
NYX 0:85b3fd62ea1a 201 */
NYX 0:85b3fd62ea1a 202 #define USART_MODE_RX ((uint32_t)USART_CR1_RE)
NYX 0:85b3fd62ea1a 203 #define USART_MODE_TX ((uint32_t)USART_CR1_TE)
NYX 0:85b3fd62ea1a 204 #define USART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
NYX 0:85b3fd62ea1a 205 /**
NYX 0:85b3fd62ea1a 206 * @}
NYX 0:85b3fd62ea1a 207 */
NYX 0:85b3fd62ea1a 208
NYX 0:85b3fd62ea1a 209 /** @defgroup USART_Clock USART Clock
NYX 0:85b3fd62ea1a 210 * @{
NYX 0:85b3fd62ea1a 211 */
NYX 0:85b3fd62ea1a 212 #define USART_CLOCK_DISABLE 0x00000000U
NYX 0:85b3fd62ea1a 213 #define USART_CLOCK_ENABLE ((uint32_t)USART_CR2_CLKEN)
NYX 0:85b3fd62ea1a 214 /**
NYX 0:85b3fd62ea1a 215 * @}
NYX 0:85b3fd62ea1a 216 */
NYX 0:85b3fd62ea1a 217
NYX 0:85b3fd62ea1a 218 /** @defgroup USART_Clock_Polarity USART Clock Polarity
NYX 0:85b3fd62ea1a 219 * @{
NYX 0:85b3fd62ea1a 220 */
NYX 0:85b3fd62ea1a 221 #define USART_POLARITY_LOW 0x00000000U
NYX 0:85b3fd62ea1a 222 #define USART_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
NYX 0:85b3fd62ea1a 223 /**
NYX 0:85b3fd62ea1a 224 * @}
NYX 0:85b3fd62ea1a 225 */
NYX 0:85b3fd62ea1a 226
NYX 0:85b3fd62ea1a 227 /** @defgroup USART_Clock_Phase USART Clock Phase
NYX 0:85b3fd62ea1a 228 * @{
NYX 0:85b3fd62ea1a 229 */
NYX 0:85b3fd62ea1a 230 #define USART_PHASE_1EDGE 0x00000000U
NYX 0:85b3fd62ea1a 231 #define USART_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
NYX 0:85b3fd62ea1a 232 /**
NYX 0:85b3fd62ea1a 233 * @}
NYX 0:85b3fd62ea1a 234 */
NYX 0:85b3fd62ea1a 235
NYX 0:85b3fd62ea1a 236 /** @defgroup USART_Last_Bit USART Last Bit
NYX 0:85b3fd62ea1a 237 * @{
NYX 0:85b3fd62ea1a 238 */
NYX 0:85b3fd62ea1a 239 #define USART_LASTBIT_DISABLE 0x00000000U
NYX 0:85b3fd62ea1a 240 #define USART_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
NYX 0:85b3fd62ea1a 241 /**
NYX 0:85b3fd62ea1a 242 * @}
NYX 0:85b3fd62ea1a 243 */
NYX 0:85b3fd62ea1a 244
NYX 0:85b3fd62ea1a 245 /** @defgroup USART_NACK_State USART NACK State
NYX 0:85b3fd62ea1a 246 * @{
NYX 0:85b3fd62ea1a 247 */
NYX 0:85b3fd62ea1a 248 #define USART_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
NYX 0:85b3fd62ea1a 249 #define USART_NACK_DISABLE 0x00000000U
NYX 0:85b3fd62ea1a 250 /**
NYX 0:85b3fd62ea1a 251 * @}
NYX 0:85b3fd62ea1a 252 */
NYX 0:85b3fd62ea1a 253
NYX 0:85b3fd62ea1a 254 /** @defgroup USART_Flags USART Flags
NYX 0:85b3fd62ea1a 255 * Elements values convention: 0xXXXX
NYX 0:85b3fd62ea1a 256 * - 0xXXXX : Flag mask in the SR register
NYX 0:85b3fd62ea1a 257 * @{
NYX 0:85b3fd62ea1a 258 */
NYX 0:85b3fd62ea1a 259 #define USART_FLAG_TXE 0x00000080U
NYX 0:85b3fd62ea1a 260 #define USART_FLAG_TC 0x00000040U
NYX 0:85b3fd62ea1a 261 #define USART_FLAG_RXNE 0x00000020U
NYX 0:85b3fd62ea1a 262 #define USART_FLAG_IDLE 0x00000010U
NYX 0:85b3fd62ea1a 263 #define USART_FLAG_ORE 0x00000008U
NYX 0:85b3fd62ea1a 264 #define USART_FLAG_NE 0x00000004U
NYX 0:85b3fd62ea1a 265 #define USART_FLAG_FE 0x00000002U
NYX 0:85b3fd62ea1a 266 #define USART_FLAG_PE 0x00000001U
NYX 0:85b3fd62ea1a 267 /**
NYX 0:85b3fd62ea1a 268 * @}
NYX 0:85b3fd62ea1a 269 */
NYX 0:85b3fd62ea1a 270
NYX 0:85b3fd62ea1a 271 /** @defgroup USART_Interrupt_definition USART Interrupts Definition
NYX 0:85b3fd62ea1a 272 * Elements values convention: 0xY000XXXX
NYX 0:85b3fd62ea1a 273 * - XXXX : Interrupt mask in the XX register
NYX 0:85b3fd62ea1a 274 * - Y : Interrupt source register (2bits)
NYX 0:85b3fd62ea1a 275 * - 01: CR1 register
NYX 0:85b3fd62ea1a 276 * - 10: CR2 register
NYX 0:85b3fd62ea1a 277 * - 11: CR3 register
NYX 0:85b3fd62ea1a 278 *
NYX 0:85b3fd62ea1a 279 * @{
NYX 0:85b3fd62ea1a 280 */
NYX 0:85b3fd62ea1a 281 #define USART_IT_PE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
NYX 0:85b3fd62ea1a 282 #define USART_IT_TXE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
NYX 0:85b3fd62ea1a 283 #define USART_IT_TC ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
NYX 0:85b3fd62ea1a 284 #define USART_IT_RXNE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
NYX 0:85b3fd62ea1a 285 #define USART_IT_IDLE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
NYX 0:85b3fd62ea1a 286
NYX 0:85b3fd62ea1a 287 #define USART_IT_LBD ((uint32_t)(USART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
NYX 0:85b3fd62ea1a 288
NYX 0:85b3fd62ea1a 289 #define USART_IT_CTS ((uint32_t)(USART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
NYX 0:85b3fd62ea1a 290 #define USART_IT_ERR ((uint32_t)(USART_CR3_REG_INDEX << 28U | USART_CR3_EIE))
NYX 0:85b3fd62ea1a 291 /**
NYX 0:85b3fd62ea1a 292 * @}
NYX 0:85b3fd62ea1a 293 */
NYX 0:85b3fd62ea1a 294
NYX 0:85b3fd62ea1a 295 /**
NYX 0:85b3fd62ea1a 296 * @}
NYX 0:85b3fd62ea1a 297 */
NYX 0:85b3fd62ea1a 298
NYX 0:85b3fd62ea1a 299 /* Exported macro ------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 300 /** @defgroup USART_Exported_Macros USART Exported Macros
NYX 0:85b3fd62ea1a 301 * @{
NYX 0:85b3fd62ea1a 302 */
NYX 0:85b3fd62ea1a 303
NYX 0:85b3fd62ea1a 304 /** @brief Reset USART handle state
NYX 0:85b3fd62ea1a 305 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 306 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
NYX 0:85b3fd62ea1a 307 * @retval None
NYX 0:85b3fd62ea1a 308 */
NYX 0:85b3fd62ea1a 309 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
NYX 0:85b3fd62ea1a 310
NYX 0:85b3fd62ea1a 311 /** @brief Checks whether the specified Smartcard flag is set or not.
NYX 0:85b3fd62ea1a 312 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 313 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
NYX 0:85b3fd62ea1a 314 * @param __FLAG__: specifies the flag to check.
NYX 0:85b3fd62ea1a 315 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 316 * @arg USART_FLAG_TXE: Transmit data register empty flag
NYX 0:85b3fd62ea1a 317 * @arg USART_FLAG_TC: Transmission Complete flag
NYX 0:85b3fd62ea1a 318 * @arg USART_FLAG_RXNE: Receive data register not empty flag
NYX 0:85b3fd62ea1a 319 * @arg USART_FLAG_IDLE: Idle Line detection flag
NYX 0:85b3fd62ea1a 320 * @arg USART_FLAG_ORE: Overrun Error flag
NYX 0:85b3fd62ea1a 321 * @arg USART_FLAG_NE: Noise Error flag
NYX 0:85b3fd62ea1a 322 * @arg USART_FLAG_FE: Framing Error flag
NYX 0:85b3fd62ea1a 323 * @arg USART_FLAG_PE: Parity Error flag
NYX 0:85b3fd62ea1a 324 * @retval The new state of __FLAG__ (TRUE or FALSE).
NYX 0:85b3fd62ea1a 325 */
NYX 0:85b3fd62ea1a 326 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
NYX 0:85b3fd62ea1a 327
NYX 0:85b3fd62ea1a 328 /** @brief Clears the specified Smartcard pending flags.
NYX 0:85b3fd62ea1a 329 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 330 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
NYX 0:85b3fd62ea1a 331 * @param __FLAG__: specifies the flag to check.
NYX 0:85b3fd62ea1a 332 * This parameter can be any combination of the following values:
NYX 0:85b3fd62ea1a 333 * @arg USART_FLAG_TC: Transmission Complete flag.
NYX 0:85b3fd62ea1a 334 * @arg USART_FLAG_RXNE: Receive data register not empty flag.
NYX 0:85b3fd62ea1a 335 *
NYX 0:85b3fd62ea1a 336 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun
NYX 0:85b3fd62ea1a 337 * error) and IDLE (Idle line detected) flags are cleared by software
NYX 0:85b3fd62ea1a 338 * sequence: a read operation to USART_SR register followed by a read
NYX 0:85b3fd62ea1a 339 * operation to USART_DR register.
NYX 0:85b3fd62ea1a 340 * @note RXNE flag can be also cleared by a read to the USART_DR register.
NYX 0:85b3fd62ea1a 341 * @note TC flag can be also cleared by software sequence: a read operation to
NYX 0:85b3fd62ea1a 342 * USART_SR register followed by a write operation to USART_DR register.
NYX 0:85b3fd62ea1a 343 * @note TXE flag is cleared only by a write to the USART_DR register.
NYX 0:85b3fd62ea1a 344 *
NYX 0:85b3fd62ea1a 345 * @retval None
NYX 0:85b3fd62ea1a 346 */
NYX 0:85b3fd62ea1a 347 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
NYX 0:85b3fd62ea1a 348
NYX 0:85b3fd62ea1a 349 /** @brief Clear the USART PE pending flag.
NYX 0:85b3fd62ea1a 350 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 351 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
NYX 0:85b3fd62ea1a 352 * @retval None
NYX 0:85b3fd62ea1a 353 */
NYX 0:85b3fd62ea1a 354 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) \
NYX 0:85b3fd62ea1a 355 do{ \
NYX 0:85b3fd62ea1a 356 __IO uint32_t tmpreg = 0x00U; \
NYX 0:85b3fd62ea1a 357 tmpreg = (__HANDLE__)->Instance->SR; \
NYX 0:85b3fd62ea1a 358 tmpreg = (__HANDLE__)->Instance->DR; \
NYX 0:85b3fd62ea1a 359 UNUSED(tmpreg); \
NYX 0:85b3fd62ea1a 360 } while(0U)
NYX 0:85b3fd62ea1a 361
NYX 0:85b3fd62ea1a 362 /** @brief Clear the USART FE pending flag.
NYX 0:85b3fd62ea1a 363 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 364 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
NYX 0:85b3fd62ea1a 365 * @retval None
NYX 0:85b3fd62ea1a 366 */
NYX 0:85b3fd62ea1a 367 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
NYX 0:85b3fd62ea1a 368
NYX 0:85b3fd62ea1a 369 /** @brief Clear the USART NE pending flag.
NYX 0:85b3fd62ea1a 370 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 371 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
NYX 0:85b3fd62ea1a 372 * @retval None
NYX 0:85b3fd62ea1a 373 */
NYX 0:85b3fd62ea1a 374 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
NYX 0:85b3fd62ea1a 375
NYX 0:85b3fd62ea1a 376 /** @brief Clear the UART ORE pending flag.
NYX 0:85b3fd62ea1a 377 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 378 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
NYX 0:85b3fd62ea1a 379 * @retval None
NYX 0:85b3fd62ea1a 380 */
NYX 0:85b3fd62ea1a 381 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
NYX 0:85b3fd62ea1a 382
NYX 0:85b3fd62ea1a 383 /** @brief Clear the USART IDLE pending flag.
NYX 0:85b3fd62ea1a 384 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 385 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
NYX 0:85b3fd62ea1a 386 * @retval None
NYX 0:85b3fd62ea1a 387 */
NYX 0:85b3fd62ea1a 388 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
NYX 0:85b3fd62ea1a 389
NYX 0:85b3fd62ea1a 390 /** @brief Enables or disables the specified USART interrupts.
NYX 0:85b3fd62ea1a 391 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 392 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
NYX 0:85b3fd62ea1a 393 * @param __INTERRUPT__: specifies the USART interrupt source to check.
NYX 0:85b3fd62ea1a 394 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 395 * @arg USART_IT_TXE: Transmit Data Register empty interrupt
NYX 0:85b3fd62ea1a 396 * @arg USART_IT_TC: Transmission complete interrupt
NYX 0:85b3fd62ea1a 397 * @arg USART_IT_RXNE: Receive Data register not empty interrupt
NYX 0:85b3fd62ea1a 398 * @arg USART_IT_IDLE: Idle line detection interrupt
NYX 0:85b3fd62ea1a 399 * @arg USART_IT_PE: Parity Error interrupt
NYX 0:85b3fd62ea1a 400 * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
NYX 0:85b3fd62ea1a 401 * This parameter can be: ENABLE or DISABLE.
NYX 0:85b3fd62ea1a 402 * @retval None
NYX 0:85b3fd62ea1a 403 */
NYX 0:85b3fd62ea1a 404 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & USART_IT_MASK)): \
NYX 0:85b3fd62ea1a 405 (((__INTERRUPT__) >> 28U) == 2U)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & USART_IT_MASK)): \
NYX 0:85b3fd62ea1a 406 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & USART_IT_MASK)))
NYX 0:85b3fd62ea1a 407 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & USART_IT_MASK)): \
NYX 0:85b3fd62ea1a 408 (((__INTERRUPT__) >> 28U) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & USART_IT_MASK)): \
NYX 0:85b3fd62ea1a 409 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & USART_IT_MASK)))
NYX 0:85b3fd62ea1a 410
NYX 0:85b3fd62ea1a 411 /** @brief Checks whether the specified USART interrupt has occurred or not.
NYX 0:85b3fd62ea1a 412 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 413 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
NYX 0:85b3fd62ea1a 414 * @param __IT__: specifies the USART interrupt source to check.
NYX 0:85b3fd62ea1a 415 * This parameter can be one of the following values:
NYX 0:85b3fd62ea1a 416 * @arg USART_IT_TXE: Transmit Data Register empty interrupt
NYX 0:85b3fd62ea1a 417 * @arg USART_IT_TC: Transmission complete interrupt
NYX 0:85b3fd62ea1a 418 * @arg USART_IT_RXNE: Receive Data register not empty interrupt
NYX 0:85b3fd62ea1a 419 * @arg USART_IT_IDLE: Idle line detection interrupt
NYX 0:85b3fd62ea1a 420 * @arg USART_IT_ERR: Error interrupt
NYX 0:85b3fd62ea1a 421 * @arg USART_IT_PE: Parity Error interrupt
NYX 0:85b3fd62ea1a 422 * @retval The new state of __IT__ (TRUE or FALSE).
NYX 0:85b3fd62ea1a 423 */
NYX 0:85b3fd62ea1a 424 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == 1U)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == 2U)? \
NYX 0:85b3fd62ea1a 425 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & USART_IT_MASK))
NYX 0:85b3fd62ea1a 426
NYX 0:85b3fd62ea1a 427 /** @brief Macro to enable the USART's one bit sample method
NYX 0:85b3fd62ea1a 428 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 429 * @retval None
NYX 0:85b3fd62ea1a 430 */
NYX 0:85b3fd62ea1a 431 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
NYX 0:85b3fd62ea1a 432
NYX 0:85b3fd62ea1a 433 /** @brief Macro to disable the USART's one bit sample method
NYX 0:85b3fd62ea1a 434 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 435 * @retval None
NYX 0:85b3fd62ea1a 436 */
NYX 0:85b3fd62ea1a 437 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
NYX 0:85b3fd62ea1a 438
NYX 0:85b3fd62ea1a 439 /** @brief Enable USART
NYX 0:85b3fd62ea1a 440 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 441 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
NYX 0:85b3fd62ea1a 442 * @retval None
NYX 0:85b3fd62ea1a 443 */
NYX 0:85b3fd62ea1a 444 #define __HAL_USART_ENABLE(__HANDLE__) ( (__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
NYX 0:85b3fd62ea1a 445
NYX 0:85b3fd62ea1a 446 /** @brief Disable USART
NYX 0:85b3fd62ea1a 447 * @param __HANDLE__: specifies the USART Handle.
NYX 0:85b3fd62ea1a 448 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
NYX 0:85b3fd62ea1a 449 * @retval None
NYX 0:85b3fd62ea1a 450 */
NYX 0:85b3fd62ea1a 451 #define __HAL_USART_DISABLE(__HANDLE__) ( (__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
NYX 0:85b3fd62ea1a 452
NYX 0:85b3fd62ea1a 453 /**
NYX 0:85b3fd62ea1a 454 * @}
NYX 0:85b3fd62ea1a 455 */
NYX 0:85b3fd62ea1a 456 /* Exported functions --------------------------------------------------------*/
NYX 0:85b3fd62ea1a 457 /** @addtogroup USART_Exported_Functions
NYX 0:85b3fd62ea1a 458 * @{
NYX 0:85b3fd62ea1a 459 */
NYX 0:85b3fd62ea1a 460
NYX 0:85b3fd62ea1a 461 /** @addtogroup USART_Exported_Functions_Group1
NYX 0:85b3fd62ea1a 462 * @{
NYX 0:85b3fd62ea1a 463 */
NYX 0:85b3fd62ea1a 464 /* Initialization/de-initialization functions **********************************/
NYX 0:85b3fd62ea1a 465 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 466 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 467 void HAL_USART_MspInit(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 468 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 469 /**
NYX 0:85b3fd62ea1a 470 * @}
NYX 0:85b3fd62ea1a 471 */
NYX 0:85b3fd62ea1a 472
NYX 0:85b3fd62ea1a 473 /** @addtogroup USART_Exported_Functions_Group2
NYX 0:85b3fd62ea1a 474 * @{
NYX 0:85b3fd62ea1a 475 */
NYX 0:85b3fd62ea1a 476 /* IO operation functions *******************************************************/
NYX 0:85b3fd62ea1a 477 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
NYX 0:85b3fd62ea1a 478 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
NYX 0:85b3fd62ea1a 479 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
NYX 0:85b3fd62ea1a 480 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
NYX 0:85b3fd62ea1a 481 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
NYX 0:85b3fd62ea1a 482 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
NYX 0:85b3fd62ea1a 483 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
NYX 0:85b3fd62ea1a 484 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
NYX 0:85b3fd62ea1a 485 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
NYX 0:85b3fd62ea1a 486 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 487 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 488 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 489 /* Transfer Abort functions */
NYX 0:85b3fd62ea1a 490 HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 491 HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 492
NYX 0:85b3fd62ea1a 493 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 494 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 495 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 496 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 497 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 498 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 499 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 500 void HAL_USART_AbortCpltCallback (USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 501 /**
NYX 0:85b3fd62ea1a 502 * @}
NYX 0:85b3fd62ea1a 503 */
NYX 0:85b3fd62ea1a 504
NYX 0:85b3fd62ea1a 505 /** @addtogroup USART_Exported_Functions_Group3
NYX 0:85b3fd62ea1a 506 * @{
NYX 0:85b3fd62ea1a 507 */
NYX 0:85b3fd62ea1a 508 /* Peripheral State functions ************************************************/
NYX 0:85b3fd62ea1a 509 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 510 uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart);
NYX 0:85b3fd62ea1a 511 /**
NYX 0:85b3fd62ea1a 512 * @}
NYX 0:85b3fd62ea1a 513 */
NYX 0:85b3fd62ea1a 514
NYX 0:85b3fd62ea1a 515 /**
NYX 0:85b3fd62ea1a 516 * @}
NYX 0:85b3fd62ea1a 517 */
NYX 0:85b3fd62ea1a 518 /* Private types -------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 519 /* Private variables ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 520 /* Private constants ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 521 /** @defgroup USART_Private_Constants USART Private Constants
NYX 0:85b3fd62ea1a 522 * @{
NYX 0:85b3fd62ea1a 523 */
NYX 0:85b3fd62ea1a 524 /** @brief USART interruptions flag mask
NYX 0:85b3fd62ea1a 525 *
NYX 0:85b3fd62ea1a 526 */
NYX 0:85b3fd62ea1a 527 #define USART_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
NYX 0:85b3fd62ea1a 528 USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE )
NYX 0:85b3fd62ea1a 529
NYX 0:85b3fd62ea1a 530 #define USART_CR1_REG_INDEX 1U
NYX 0:85b3fd62ea1a 531 #define USART_CR2_REG_INDEX 2U
NYX 0:85b3fd62ea1a 532 #define USART_CR3_REG_INDEX 3U
NYX 0:85b3fd62ea1a 533 /**
NYX 0:85b3fd62ea1a 534 * @}
NYX 0:85b3fd62ea1a 535 */
NYX 0:85b3fd62ea1a 536
NYX 0:85b3fd62ea1a 537 /* Private macros ------------------------------------------------------------*/
NYX 0:85b3fd62ea1a 538 /** @defgroup USART_Private_Macros USART Private Macros
NYX 0:85b3fd62ea1a 539 * @{
NYX 0:85b3fd62ea1a 540 */
NYX 0:85b3fd62ea1a 541 #define IS_USART_NACK_STATE(NACK) (((NACK) == USART_NACK_ENABLE) || \
NYX 0:85b3fd62ea1a 542 ((NACK) == USART_NACK_DISABLE))
NYX 0:85b3fd62ea1a 543 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LASTBIT_DISABLE) || \
NYX 0:85b3fd62ea1a 544 ((LASTBIT) == USART_LASTBIT_ENABLE))
NYX 0:85b3fd62ea1a 545 #define IS_USART_PHASE(CPHA) (((CPHA) == USART_PHASE_1EDGE) || ((CPHA) == USART_PHASE_2EDGE))
NYX 0:85b3fd62ea1a 546 #define IS_USART_POLARITY(CPOL) (((CPOL) == USART_POLARITY_LOW) || ((CPOL) == USART_POLARITY_HIGH))
NYX 0:85b3fd62ea1a 547 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_CLOCK_DISABLE) || \
NYX 0:85b3fd62ea1a 548 ((CLOCK) == USART_CLOCK_ENABLE))
NYX 0:85b3fd62ea1a 549 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WORDLENGTH_8B) || \
NYX 0:85b3fd62ea1a 550 ((LENGTH) == USART_WORDLENGTH_9B))
NYX 0:85b3fd62ea1a 551 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_STOPBITS_1) || \
NYX 0:85b3fd62ea1a 552 ((STOPBITS) == USART_STOPBITS_0_5) || \
NYX 0:85b3fd62ea1a 553 ((STOPBITS) == USART_STOPBITS_1_5) || \
NYX 0:85b3fd62ea1a 554 ((STOPBITS) == USART_STOPBITS_2))
NYX 0:85b3fd62ea1a 555 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_PARITY_NONE) || \
NYX 0:85b3fd62ea1a 556 ((PARITY) == USART_PARITY_EVEN) || \
NYX 0:85b3fd62ea1a 557 ((PARITY) == USART_PARITY_ODD))
NYX 0:85b3fd62ea1a 558 #define IS_USART_MODE(MODE) ((((MODE) & 0xFFF3U) == 0x00U) && ((MODE) != 0x00U))
NYX 0:85b3fd62ea1a 559 #define IS_USART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U)
NYX 0:85b3fd62ea1a 560
NYX 0:85b3fd62ea1a 561 #define USART_DIV(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(2U*(_BAUD_)))
NYX 0:85b3fd62ea1a 562 #define USART_DIVMANT(_PCLK_, _BAUD_) (USART_DIV((_PCLK_), (_BAUD_))/100U)
NYX 0:85b3fd62ea1a 563 #define USART_DIVFRAQ(_PCLK_, _BAUD_) (((USART_DIV((_PCLK_), (_BAUD_)) - (USART_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
NYX 0:85b3fd62ea1a 564 #define USART_BRR(_PCLK_, _BAUD_) ((USART_DIVMANT((_PCLK_), (_BAUD_)) << 4U)|(USART_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))
NYX 0:85b3fd62ea1a 565 /**
NYX 0:85b3fd62ea1a 566 * @}
NYX 0:85b3fd62ea1a 567 */
NYX 0:85b3fd62ea1a 568
NYX 0:85b3fd62ea1a 569 /* Private functions ---------------------------------------------------------*/
NYX 0:85b3fd62ea1a 570 /** @defgroup USART_Private_Functions USART Private Functions
NYX 0:85b3fd62ea1a 571 * @{
NYX 0:85b3fd62ea1a 572 */
NYX 0:85b3fd62ea1a 573
NYX 0:85b3fd62ea1a 574 /**
NYX 0:85b3fd62ea1a 575 * @}
NYX 0:85b3fd62ea1a 576 */
NYX 0:85b3fd62ea1a 577
NYX 0:85b3fd62ea1a 578 /**
NYX 0:85b3fd62ea1a 579 * @}
NYX 0:85b3fd62ea1a 580 */
NYX 0:85b3fd62ea1a 581
NYX 0:85b3fd62ea1a 582 /**
NYX 0:85b3fd62ea1a 583 * @}
NYX 0:85b3fd62ea1a 584 */
NYX 0:85b3fd62ea1a 585
NYX 0:85b3fd62ea1a 586 #ifdef __cplusplus
NYX 0:85b3fd62ea1a 587 }
NYX 0:85b3fd62ea1a 588 #endif
NYX 0:85b3fd62ea1a 589
NYX 0:85b3fd62ea1a 590 #endif /* __STM32F4xx_HAL_USART_H */
NYX 0:85b3fd62ea1a 591
NYX 0:85b3fd62ea1a 592 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/