TUKS MCU Introductory course / TUKS-COURSE-THERMOMETER

Fork of TUKS-COURSE-TIMER by TUKS MCU Introductory course

Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elmot 1:d0dfbce63a89 1 /**
elmot 1:d0dfbce63a89 2 ******************************************************************************
elmot 1:d0dfbce63a89 3 * @file stm32l4xx_hal_usart.h
elmot 1:d0dfbce63a89 4 * @author MCD Application Team
elmot 1:d0dfbce63a89 5 * @version V1.5.1
elmot 1:d0dfbce63a89 6 * @date 31-May-2016
elmot 1:d0dfbce63a89 7 * @brief Header file of USART HAL module.
elmot 1:d0dfbce63a89 8 ******************************************************************************
elmot 1:d0dfbce63a89 9 * @attention
elmot 1:d0dfbce63a89 10 *
elmot 1:d0dfbce63a89 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
elmot 1:d0dfbce63a89 12 *
elmot 1:d0dfbce63a89 13 * Redistribution and use in source and binary forms, with or without modification,
elmot 1:d0dfbce63a89 14 * are permitted provided that the following conditions are met:
elmot 1:d0dfbce63a89 15 * 1. Redistributions of source code must retain the above copyright notice,
elmot 1:d0dfbce63a89 16 * this list of conditions and the following disclaimer.
elmot 1:d0dfbce63a89 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
elmot 1:d0dfbce63a89 18 * this list of conditions and the following disclaimer in the documentation
elmot 1:d0dfbce63a89 19 * and/or other materials provided with the distribution.
elmot 1:d0dfbce63a89 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
elmot 1:d0dfbce63a89 21 * may be used to endorse or promote products derived from this software
elmot 1:d0dfbce63a89 22 * without specific prior written permission.
elmot 1:d0dfbce63a89 23 *
elmot 1:d0dfbce63a89 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
elmot 1:d0dfbce63a89 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
elmot 1:d0dfbce63a89 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
elmot 1:d0dfbce63a89 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
elmot 1:d0dfbce63a89 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
elmot 1:d0dfbce63a89 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
elmot 1:d0dfbce63a89 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
elmot 1:d0dfbce63a89 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
elmot 1:d0dfbce63a89 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
elmot 1:d0dfbce63a89 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
elmot 1:d0dfbce63a89 34 *
elmot 1:d0dfbce63a89 35 ******************************************************************************
elmot 1:d0dfbce63a89 36 */
elmot 1:d0dfbce63a89 37
elmot 1:d0dfbce63a89 38 /* Define to prevent recursive inclusion -------------------------------------*/
elmot 1:d0dfbce63a89 39 #ifndef __STM32L4xx_HAL_USART_H
elmot 1:d0dfbce63a89 40 #define __STM32L4xx_HAL_USART_H
elmot 1:d0dfbce63a89 41
elmot 1:d0dfbce63a89 42 #ifdef __cplusplus
elmot 1:d0dfbce63a89 43 extern "C" {
elmot 1:d0dfbce63a89 44 #endif
elmot 1:d0dfbce63a89 45
elmot 1:d0dfbce63a89 46 /* Includes ------------------------------------------------------------------*/
elmot 1:d0dfbce63a89 47 #include "stm32l4xx_hal_def.h"
elmot 1:d0dfbce63a89 48
elmot 1:d0dfbce63a89 49 /** @addtogroup STM32L4xx_HAL_Driver
elmot 1:d0dfbce63a89 50 * @{
elmot 1:d0dfbce63a89 51 */
elmot 1:d0dfbce63a89 52
elmot 1:d0dfbce63a89 53 /** @addtogroup USART
elmot 1:d0dfbce63a89 54 * @{
elmot 1:d0dfbce63a89 55 */
elmot 1:d0dfbce63a89 56
elmot 1:d0dfbce63a89 57 /* Exported types ------------------------------------------------------------*/
elmot 1:d0dfbce63a89 58 /** @defgroup USART_Exported_Types USART Exported Types
elmot 1:d0dfbce63a89 59 * @{
elmot 1:d0dfbce63a89 60 */
elmot 1:d0dfbce63a89 61
elmot 1:d0dfbce63a89 62 /**
elmot 1:d0dfbce63a89 63 * @brief USART Init Structure definition
elmot 1:d0dfbce63a89 64 */
elmot 1:d0dfbce63a89 65 typedef struct
elmot 1:d0dfbce63a89 66 {
elmot 1:d0dfbce63a89 67 uint32_t BaudRate; /*!< This member configures the Usart communication baud rate.
elmot 1:d0dfbce63a89 68 The baud rate is computed using the following formula:
elmot 1:d0dfbce63a89 69 Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate))). */
elmot 1:d0dfbce63a89 70
elmot 1:d0dfbce63a89 71 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
elmot 1:d0dfbce63a89 72 This parameter can be a value of @ref USARTEx_Word_Length. */
elmot 1:d0dfbce63a89 73
elmot 1:d0dfbce63a89 74 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
elmot 1:d0dfbce63a89 75 This parameter can be a value of @ref USART_Stop_Bits. */
elmot 1:d0dfbce63a89 76
elmot 1:d0dfbce63a89 77 uint32_t Parity; /*!< Specifies the parity mode.
elmot 1:d0dfbce63a89 78 This parameter can be a value of @ref USART_Parity
elmot 1:d0dfbce63a89 79 @note When parity is enabled, the computed parity is inserted
elmot 1:d0dfbce63a89 80 at the MSB position of the transmitted data (9th bit when
elmot 1:d0dfbce63a89 81 the word length is set to 9 data bits; 8th bit when the
elmot 1:d0dfbce63a89 82 word length is set to 8 data bits). */
elmot 1:d0dfbce63a89 83
elmot 1:d0dfbce63a89 84 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
elmot 1:d0dfbce63a89 85 This parameter can be a value of @ref USART_Mode. */
elmot 1:d0dfbce63a89 86
elmot 1:d0dfbce63a89 87 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
elmot 1:d0dfbce63a89 88 This parameter can be a value of @ref USART_Clock_Polarity. */
elmot 1:d0dfbce63a89 89
elmot 1:d0dfbce63a89 90 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
elmot 1:d0dfbce63a89 91 This parameter can be a value of @ref USART_Clock_Phase. */
elmot 1:d0dfbce63a89 92
elmot 1:d0dfbce63a89 93 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
elmot 1:d0dfbce63a89 94 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
elmot 1:d0dfbce63a89 95 This parameter can be a value of @ref USART_Last_Bit. */
elmot 1:d0dfbce63a89 96 }USART_InitTypeDef;
elmot 1:d0dfbce63a89 97
elmot 1:d0dfbce63a89 98 /**
elmot 1:d0dfbce63a89 99 * @brief HAL USART State structures definition
elmot 1:d0dfbce63a89 100 */
elmot 1:d0dfbce63a89 101 typedef enum
elmot 1:d0dfbce63a89 102 {
elmot 1:d0dfbce63a89 103 HAL_USART_STATE_RESET = 0x00, /*!< Peripheral is not initialized */
elmot 1:d0dfbce63a89 104 HAL_USART_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
elmot 1:d0dfbce63a89 105 HAL_USART_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
elmot 1:d0dfbce63a89 106 HAL_USART_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
elmot 1:d0dfbce63a89 107 HAL_USART_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
elmot 1:d0dfbce63a89 108 HAL_USART_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission Reception process is ongoing */
elmot 1:d0dfbce63a89 109 HAL_USART_STATE_TIMEOUT = 0x03, /*!< Timeout state */
elmot 1:d0dfbce63a89 110 HAL_USART_STATE_ERROR = 0x04 /*!< Error */
elmot 1:d0dfbce63a89 111 }HAL_USART_StateTypeDef;
elmot 1:d0dfbce63a89 112
elmot 1:d0dfbce63a89 113 /**
elmot 1:d0dfbce63a89 114 * @brief HAL USART Error Code structure definition
elmot 1:d0dfbce63a89 115 */
elmot 1:d0dfbce63a89 116 typedef enum
elmot 1:d0dfbce63a89 117 {
elmot 1:d0dfbce63a89 118 HAL_USART_ERROR_NONE = 0x00, /*!< No error */
elmot 1:d0dfbce63a89 119 HAL_USART_ERROR_PE = 0x01, /*!< Parity error */
elmot 1:d0dfbce63a89 120 HAL_USART_ERROR_NE = 0x02, /*!< Noise error */
elmot 1:d0dfbce63a89 121 HAL_USART_ERROR_FE = 0x04, /*!< frame error */
elmot 1:d0dfbce63a89 122 HAL_USART_ERROR_ORE = 0x08, /*!< Overrun error */
elmot 1:d0dfbce63a89 123 HAL_USART_ERROR_DMA = 0x10 /*!< DMA transfer error */
elmot 1:d0dfbce63a89 124 }HAL_USART_ErrorTypeDef;
elmot 1:d0dfbce63a89 125
elmot 1:d0dfbce63a89 126 /**
elmot 1:d0dfbce63a89 127 * @brief USART clock sources definitions
elmot 1:d0dfbce63a89 128 */
elmot 1:d0dfbce63a89 129 typedef enum
elmot 1:d0dfbce63a89 130 {
elmot 1:d0dfbce63a89 131 USART_CLOCKSOURCE_PCLK1 = 0x00, /*!< PCLK1 clock source */
elmot 1:d0dfbce63a89 132 USART_CLOCKSOURCE_PCLK2 = 0x01, /*!< PCLK2 clock source */
elmot 1:d0dfbce63a89 133 USART_CLOCKSOURCE_HSI = 0x02, /*!< HSI clock source */
elmot 1:d0dfbce63a89 134 USART_CLOCKSOURCE_SYSCLK = 0x04, /*!< SYSCLK clock source */
elmot 1:d0dfbce63a89 135 USART_CLOCKSOURCE_LSE = 0x08, /*!< LSE clock source */
elmot 1:d0dfbce63a89 136 USART_CLOCKSOURCE_UNDEFINED = 0x10 /*!< Undefined clock source */
elmot 1:d0dfbce63a89 137 }USART_ClockSourceTypeDef;
elmot 1:d0dfbce63a89 138
elmot 1:d0dfbce63a89 139
elmot 1:d0dfbce63a89 140 /**
elmot 1:d0dfbce63a89 141 * @brief USART handle Structure definition
elmot 1:d0dfbce63a89 142 */
elmot 1:d0dfbce63a89 143 typedef struct
elmot 1:d0dfbce63a89 144 {
elmot 1:d0dfbce63a89 145 USART_TypeDef *Instance; /*!< USART registers base address */
elmot 1:d0dfbce63a89 146
elmot 1:d0dfbce63a89 147 USART_InitTypeDef Init; /*!< USART communication parameters */
elmot 1:d0dfbce63a89 148
elmot 1:d0dfbce63a89 149 uint8_t *pTxBuffPtr; /*!< Pointer to USART Tx transfer Buffer */
elmot 1:d0dfbce63a89 150
elmot 1:d0dfbce63a89 151 uint16_t TxXferSize; /*!< USART Tx Transfer size */
elmot 1:d0dfbce63a89 152
elmot 1:d0dfbce63a89 153 uint16_t TxXferCount; /*!< USART Tx Transfer Counter */
elmot 1:d0dfbce63a89 154
elmot 1:d0dfbce63a89 155 uint8_t *pRxBuffPtr; /*!< Pointer to USART Rx transfer Buffer */
elmot 1:d0dfbce63a89 156
elmot 1:d0dfbce63a89 157 uint16_t RxXferSize; /*!< USART Rx Transfer size */
elmot 1:d0dfbce63a89 158
elmot 1:d0dfbce63a89 159 uint16_t RxXferCount; /*!< USART Rx Transfer Counter */
elmot 1:d0dfbce63a89 160
elmot 1:d0dfbce63a89 161 uint16_t Mask; /*!< USART Rx RDR register mask */
elmot 1:d0dfbce63a89 162
elmot 1:d0dfbce63a89 163 DMA_HandleTypeDef *hdmatx; /*!< USART Tx DMA Handle parameters */
elmot 1:d0dfbce63a89 164
elmot 1:d0dfbce63a89 165 DMA_HandleTypeDef *hdmarx; /*!< USART Rx DMA Handle parameters */
elmot 1:d0dfbce63a89 166
elmot 1:d0dfbce63a89 167 HAL_LockTypeDef Lock; /*!< Locking object */
elmot 1:d0dfbce63a89 168
elmot 1:d0dfbce63a89 169 __IO HAL_USART_StateTypeDef State; /*!< USART communication state */
elmot 1:d0dfbce63a89 170
elmot 1:d0dfbce63a89 171 __IO uint32_t ErrorCode; /*!< USART Error code */
elmot 1:d0dfbce63a89 172
elmot 1:d0dfbce63a89 173 }USART_HandleTypeDef;
elmot 1:d0dfbce63a89 174
elmot 1:d0dfbce63a89 175 /**
elmot 1:d0dfbce63a89 176 * @}
elmot 1:d0dfbce63a89 177 */
elmot 1:d0dfbce63a89 178
elmot 1:d0dfbce63a89 179 /* Exported constants --------------------------------------------------------*/
elmot 1:d0dfbce63a89 180 /** @defgroup USART_Exported_Constants USART Exported Constants
elmot 1:d0dfbce63a89 181 * @{
elmot 1:d0dfbce63a89 182 */
elmot 1:d0dfbce63a89 183
elmot 1:d0dfbce63a89 184 /** @defgroup USART_Stop_Bits USART Number of Stop Bits
elmot 1:d0dfbce63a89 185 * @{
elmot 1:d0dfbce63a89 186 */
elmot 1:d0dfbce63a89 187 #define USART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< USART frame with 0.5 stop bit */
elmot 1:d0dfbce63a89 188 #define USART_STOPBITS_1 ((uint32_t)0x00000000) /*!< USART frame with 1 stop bit */
elmot 1:d0dfbce63a89 189 #define USART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< USART frame with 1.5 stop bits */
elmot 1:d0dfbce63a89 190 #define USART_STOPBITS_2 USART_CR2_STOP_1 /*!< USART frame with 2 stop bits */
elmot 1:d0dfbce63a89 191 /**
elmot 1:d0dfbce63a89 192 * @}
elmot 1:d0dfbce63a89 193 */
elmot 1:d0dfbce63a89 194
elmot 1:d0dfbce63a89 195 /** @defgroup USART_Parity USART Parity
elmot 1:d0dfbce63a89 196 * @{
elmot 1:d0dfbce63a89 197 */
elmot 1:d0dfbce63a89 198 #define USART_PARITY_NONE ((uint32_t)0x00000000) /*!< No parity */
elmot 1:d0dfbce63a89 199 #define USART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) /*!< Even parity */
elmot 1:d0dfbce63a89 200 #define USART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) /*!< Odd parity */
elmot 1:d0dfbce63a89 201 /**
elmot 1:d0dfbce63a89 202 * @}
elmot 1:d0dfbce63a89 203 */
elmot 1:d0dfbce63a89 204
elmot 1:d0dfbce63a89 205 /** @defgroup USART_Mode USART Mode
elmot 1:d0dfbce63a89 206 * @{
elmot 1:d0dfbce63a89 207 */
elmot 1:d0dfbce63a89 208 #define USART_MODE_RX ((uint32_t)USART_CR1_RE) /*!< RX mode */
elmot 1:d0dfbce63a89 209 #define USART_MODE_TX ((uint32_t)USART_CR1_TE) /*!< TX mode */
elmot 1:d0dfbce63a89 210 #define USART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) /*!< RX and TX mode */
elmot 1:d0dfbce63a89 211 /**
elmot 1:d0dfbce63a89 212 * @}
elmot 1:d0dfbce63a89 213 */
elmot 1:d0dfbce63a89 214
elmot 1:d0dfbce63a89 215 /** @defgroup USART_Over_Sampling USART Over Sampling
elmot 1:d0dfbce63a89 216 * @{
elmot 1:d0dfbce63a89 217 */
elmot 1:d0dfbce63a89 218 #define USART_OVERSAMPLING_16 ((uint32_t)0x00000000) /*!< Oversampling by 16 */
elmot 1:d0dfbce63a89 219 #define USART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8) /*!< Oversampling by 8 */
elmot 1:d0dfbce63a89 220 /**
elmot 1:d0dfbce63a89 221 * @}
elmot 1:d0dfbce63a89 222 */
elmot 1:d0dfbce63a89 223
elmot 1:d0dfbce63a89 224 /** @defgroup USART_Clock USART Clock
elmot 1:d0dfbce63a89 225 * @{
elmot 1:d0dfbce63a89 226 */
elmot 1:d0dfbce63a89 227 #define USART_CLOCK_DISABLE ((uint32_t)0x00000000) /*!< USART clock disable */
elmot 1:d0dfbce63a89 228 #define USART_CLOCK_ENABLE ((uint32_t)USART_CR2_CLKEN) /*!< USART clock enable */
elmot 1:d0dfbce63a89 229 /**
elmot 1:d0dfbce63a89 230 * @}
elmot 1:d0dfbce63a89 231 */
elmot 1:d0dfbce63a89 232
elmot 1:d0dfbce63a89 233 /** @defgroup USART_Clock_Polarity USART Clock Polarity
elmot 1:d0dfbce63a89 234 * @{
elmot 1:d0dfbce63a89 235 */
elmot 1:d0dfbce63a89 236 #define USART_POLARITY_LOW ((uint32_t)0x00000000) /*!< Driver enable signal is active high */
elmot 1:d0dfbce63a89 237 #define USART_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL) /*!< Driver enable signal is active low */
elmot 1:d0dfbce63a89 238 /**
elmot 1:d0dfbce63a89 239 * @}
elmot 1:d0dfbce63a89 240 */
elmot 1:d0dfbce63a89 241
elmot 1:d0dfbce63a89 242 /** @defgroup USART_Clock_Phase USART Clock Phase
elmot 1:d0dfbce63a89 243 * @{
elmot 1:d0dfbce63a89 244 */
elmot 1:d0dfbce63a89 245 #define USART_PHASE_1EDGE ((uint32_t)0x00000000) /*!< USART frame phase on first clock transition */
elmot 1:d0dfbce63a89 246 #define USART_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA) /*!< USART frame phase on second clock transition */
elmot 1:d0dfbce63a89 247 /**
elmot 1:d0dfbce63a89 248 * @}
elmot 1:d0dfbce63a89 249 */
elmot 1:d0dfbce63a89 250
elmot 1:d0dfbce63a89 251 /** @defgroup USART_Last_Bit USART Last Bit
elmot 1:d0dfbce63a89 252 * @{
elmot 1:d0dfbce63a89 253 */
elmot 1:d0dfbce63a89 254 #define USART_LASTBIT_DISABLE ((uint32_t)0x00000000) /*!< USART frame last data bit clock pulse not output to SCLK pin */
elmot 1:d0dfbce63a89 255 #define USART_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL) /*!< USART frame last data bit clock pulse output to SCLK pin */
elmot 1:d0dfbce63a89 256 /**
elmot 1:d0dfbce63a89 257 * @}
elmot 1:d0dfbce63a89 258 */
elmot 1:d0dfbce63a89 259
elmot 1:d0dfbce63a89 260 /** @defgroup USART_Request_Parameters USART Request Parameters
elmot 1:d0dfbce63a89 261 * @{
elmot 1:d0dfbce63a89 262 */
elmot 1:d0dfbce63a89 263 #define USART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
elmot 1:d0dfbce63a89 264 #define USART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
elmot 1:d0dfbce63a89 265 /**
elmot 1:d0dfbce63a89 266 * @}
elmot 1:d0dfbce63a89 267 */
elmot 1:d0dfbce63a89 268
elmot 1:d0dfbce63a89 269 /** @defgroup USART_Flags USART Flags
elmot 1:d0dfbce63a89 270 * Elements values convention: 0xXXXX
elmot 1:d0dfbce63a89 271 * - 0xXXXX : Flag mask in the ISR register
elmot 1:d0dfbce63a89 272 * @{
elmot 1:d0dfbce63a89 273 */
elmot 1:d0dfbce63a89 274 #define USART_FLAG_REACK ((uint32_t)0x00400000) /*!< USART receive enable acknowledge flag */
elmot 1:d0dfbce63a89 275 #define USART_FLAG_TEACK ((uint32_t)0x00200000) /*!< USART transmit enable acknowledge flag */
elmot 1:d0dfbce63a89 276 #define USART_FLAG_BUSY ((uint32_t)0x00010000) /*!< USART busy flag */
elmot 1:d0dfbce63a89 277 #define USART_FLAG_CTS ((uint32_t)0x00000400) /*!< USART clear to send flag */
elmot 1:d0dfbce63a89 278 #define USART_FLAG_CTSIF ((uint32_t)0x00000200) /*!< USART clear to send interrupt flag */
elmot 1:d0dfbce63a89 279 #define USART_FLAG_LBDF ((uint32_t)0x00000100) /*!< USART LIN break detection flag */
elmot 1:d0dfbce63a89 280 #define USART_FLAG_TXE ((uint32_t)0x00000080) /*!< USART transmit data register empty */
elmot 1:d0dfbce63a89 281 #define USART_FLAG_TC ((uint32_t)0x00000040) /*!< USART transmission complete */
elmot 1:d0dfbce63a89 282 #define USART_FLAG_RXNE ((uint32_t)0x00000020) /*!< USART read data register not empty */
elmot 1:d0dfbce63a89 283 #define USART_FLAG_IDLE ((uint32_t)0x00000010) /*!< USART idle flag */
elmot 1:d0dfbce63a89 284 #define USART_FLAG_ORE ((uint32_t)0x00000008) /*!< USART overrun error */
elmot 1:d0dfbce63a89 285 #define USART_FLAG_NE ((uint32_t)0x00000004) /*!< USART noise error */
elmot 1:d0dfbce63a89 286 #define USART_FLAG_FE ((uint32_t)0x00000002) /*!< USART frame error */
elmot 1:d0dfbce63a89 287 #define USART_FLAG_PE ((uint32_t)0x00000001) /*!< USART parity error */
elmot 1:d0dfbce63a89 288 /**
elmot 1:d0dfbce63a89 289 * @}
elmot 1:d0dfbce63a89 290 */
elmot 1:d0dfbce63a89 291
elmot 1:d0dfbce63a89 292 /** @defgroup USART_Interrupt_definition USART Interrupts Definition
elmot 1:d0dfbce63a89 293 * Elements values convention: 0000ZZZZ0XXYYYYYb
elmot 1:d0dfbce63a89 294 * - YYYYY : Interrupt source position in the XX register (5bits)
elmot 1:d0dfbce63a89 295 * - XX : Interrupt source register (2bits)
elmot 1:d0dfbce63a89 296 * - 01: CR1 register
elmot 1:d0dfbce63a89 297 * - 10: CR2 register
elmot 1:d0dfbce63a89 298 * - 11: CR3 register
elmot 1:d0dfbce63a89 299 * - ZZZZ : Flag position in the ISR register(4bits)
elmot 1:d0dfbce63a89 300 * @{
elmot 1:d0dfbce63a89 301 */
elmot 1:d0dfbce63a89 302
elmot 1:d0dfbce63a89 303 #define USART_IT_PE ((uint16_t)0x0028) /*!< USART parity error interruption */
elmot 1:d0dfbce63a89 304 #define USART_IT_TXE ((uint16_t)0x0727) /*!< USART transmit data register empty interruption */
elmot 1:d0dfbce63a89 305 #define USART_IT_TC ((uint16_t)0x0626) /*!< USART transmission complete interruption */
elmot 1:d0dfbce63a89 306 #define USART_IT_RXNE ((uint16_t)0x0525) /*!< USART read data register not empty interruption */
elmot 1:d0dfbce63a89 307 #define USART_IT_IDLE ((uint16_t)0x0424) /*!< USART idle interruption */
elmot 1:d0dfbce63a89 308 #define USART_IT_ERR ((uint16_t)0x0060) /*!< USART error interruption */
elmot 1:d0dfbce63a89 309 #define USART_IT_ORE ((uint16_t)0x0300) /*!< USART overrun error interruption */
elmot 1:d0dfbce63a89 310 #define USART_IT_NE ((uint16_t)0x0200) /*!< USART noise error interruption */
elmot 1:d0dfbce63a89 311 #define USART_IT_FE ((uint16_t)0x0100) /*!< USART frame error interruption */
elmot 1:d0dfbce63a89 312 /**
elmot 1:d0dfbce63a89 313 * @}
elmot 1:d0dfbce63a89 314 */
elmot 1:d0dfbce63a89 315
elmot 1:d0dfbce63a89 316 /** @defgroup USART_IT_CLEAR_Flags USART Interruption Clear Flags
elmot 1:d0dfbce63a89 317 * @{
elmot 1:d0dfbce63a89 318 */
elmot 1:d0dfbce63a89 319 #define USART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
elmot 1:d0dfbce63a89 320 #define USART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
elmot 1:d0dfbce63a89 321 #define USART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
elmot 1:d0dfbce63a89 322 #define USART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
elmot 1:d0dfbce63a89 323 #define USART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
elmot 1:d0dfbce63a89 324 #define USART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
elmot 1:d0dfbce63a89 325 /**
elmot 1:d0dfbce63a89 326 * @}
elmot 1:d0dfbce63a89 327 */
elmot 1:d0dfbce63a89 328
elmot 1:d0dfbce63a89 329 /** @defgroup USART_Interruption_Mask USART Interruption Flags Mask
elmot 1:d0dfbce63a89 330 * @{
elmot 1:d0dfbce63a89 331 */
elmot 1:d0dfbce63a89 332 #define USART_IT_MASK ((uint16_t)0x001F) /*!< USART interruptions flags mask */
elmot 1:d0dfbce63a89 333 /**
elmot 1:d0dfbce63a89 334 * @}
elmot 1:d0dfbce63a89 335 */
elmot 1:d0dfbce63a89 336
elmot 1:d0dfbce63a89 337 /**
elmot 1:d0dfbce63a89 338 * @}
elmot 1:d0dfbce63a89 339 */
elmot 1:d0dfbce63a89 340
elmot 1:d0dfbce63a89 341 /* Exported macros -----------------------------------------------------------*/
elmot 1:d0dfbce63a89 342 /** @defgroup USART_Exported_Macros USART Exported Macros
elmot 1:d0dfbce63a89 343 * @{
elmot 1:d0dfbce63a89 344 */
elmot 1:d0dfbce63a89 345
elmot 1:d0dfbce63a89 346 /** @brief Reset USART handle state.
elmot 1:d0dfbce63a89 347 * @param __HANDLE__: USART handle.
elmot 1:d0dfbce63a89 348 * @retval None
elmot 1:d0dfbce63a89 349 */
elmot 1:d0dfbce63a89 350 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
elmot 1:d0dfbce63a89 351
elmot 1:d0dfbce63a89 352 /** @brief Check whether the specified USART flag is set or not.
elmot 1:d0dfbce63a89 353 * @param __HANDLE__: specifies the USART Handle
elmot 1:d0dfbce63a89 354 * @param __FLAG__: specifies the flag to check.
elmot 1:d0dfbce63a89 355 * This parameter can be one of the following values:
elmot 1:d0dfbce63a89 356 * @arg @ref USART_FLAG_REACK Receive enable acknowledge flag
elmot 1:d0dfbce63a89 357 * @arg @ref USART_FLAG_TEACK Transmit enable acknowledge flag
elmot 1:d0dfbce63a89 358 * @arg @ref USART_FLAG_BUSY Busy flag
elmot 1:d0dfbce63a89 359 * @arg @ref USART_FLAG_CTS CTS Change flag
elmot 1:d0dfbce63a89 360 * @arg @ref USART_FLAG_TXE Transmit data register empty flag
elmot 1:d0dfbce63a89 361 * @arg @ref USART_FLAG_TC Transmission Complete flag
elmot 1:d0dfbce63a89 362 * @arg @ref USART_FLAG_RXNE Receive data register not empty flag
elmot 1:d0dfbce63a89 363 * @arg @ref USART_FLAG_IDLE Idle Line detection flag
elmot 1:d0dfbce63a89 364 * @arg @ref USART_FLAG_ORE OverRun Error flag
elmot 1:d0dfbce63a89 365 * @arg @ref USART_FLAG_NE Noise Error flag
elmot 1:d0dfbce63a89 366 * @arg @ref USART_FLAG_FE Framing Error flag
elmot 1:d0dfbce63a89 367 * @arg @ref USART_FLAG_PE Parity Error flag
elmot 1:d0dfbce63a89 368 * @retval The new state of __FLAG__ (TRUE or FALSE).
elmot 1:d0dfbce63a89 369 */
elmot 1:d0dfbce63a89 370 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
elmot 1:d0dfbce63a89 371
elmot 1:d0dfbce63a89 372 /** @brief Clear the specified USART pending flag.
elmot 1:d0dfbce63a89 373 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 374 * @param __FLAG__: specifies the flag to check.
elmot 1:d0dfbce63a89 375 * This parameter can be any combination of the following values:
elmot 1:d0dfbce63a89 376 * @arg @ref USART_CLEAR_PEF
elmot 1:d0dfbce63a89 377 * @arg @ref USART_CLEAR_FEF
elmot 1:d0dfbce63a89 378 * @arg @ref USART_CLEAR_NEF
elmot 1:d0dfbce63a89 379 * @arg @ref USART_CLEAR_OREF
elmot 1:d0dfbce63a89 380 * @arg @ref USART_CLEAR_IDLEF
elmot 1:d0dfbce63a89 381 * @arg @ref USART_CLEAR_TCF
elmot 1:d0dfbce63a89 382 * @retval None
elmot 1:d0dfbce63a89 383 */
elmot 1:d0dfbce63a89 384 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
elmot 1:d0dfbce63a89 385
elmot 1:d0dfbce63a89 386 /** @brief Clear the USART PE pending flag.
elmot 1:d0dfbce63a89 387 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 388 * @retval None
elmot 1:d0dfbce63a89 389 */
elmot 1:d0dfbce63a89 390 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_PEF)
elmot 1:d0dfbce63a89 391
elmot 1:d0dfbce63a89 392 /** @brief Clear the USART FE pending flag.
elmot 1:d0dfbce63a89 393 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 394 * @retval None
elmot 1:d0dfbce63a89 395 */
elmot 1:d0dfbce63a89 396 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_FEF)
elmot 1:d0dfbce63a89 397
elmot 1:d0dfbce63a89 398 /** @brief Clear the USART NE pending flag.
elmot 1:d0dfbce63a89 399 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 400 * @retval None
elmot 1:d0dfbce63a89 401 */
elmot 1:d0dfbce63a89 402 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_NEF)
elmot 1:d0dfbce63a89 403
elmot 1:d0dfbce63a89 404 /** @brief Clear the USART ORE pending flag.
elmot 1:d0dfbce63a89 405 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 406 * @retval None
elmot 1:d0dfbce63a89 407 */
elmot 1:d0dfbce63a89 408 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_OREF)
elmot 1:d0dfbce63a89 409
elmot 1:d0dfbce63a89 410 /** @brief Clear the USART IDLE pending flag.
elmot 1:d0dfbce63a89 411 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 412 * @retval None
elmot 1:d0dfbce63a89 413 */
elmot 1:d0dfbce63a89 414 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_IDLEF)
elmot 1:d0dfbce63a89 415
elmot 1:d0dfbce63a89 416 /** @brief Enable the specified USART interrupt.
elmot 1:d0dfbce63a89 417 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 418 * @param __INTERRUPT__: specifies the USART interrupt source to enable.
elmot 1:d0dfbce63a89 419 * This parameter can be one of the following values:
elmot 1:d0dfbce63a89 420 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
elmot 1:d0dfbce63a89 421 * @arg @ref USART_IT_TC Transmission complete interrupt
elmot 1:d0dfbce63a89 422 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
elmot 1:d0dfbce63a89 423 * @arg @ref USART_IT_IDLE Idle line detection interrupt
elmot 1:d0dfbce63a89 424 * @arg @ref USART_IT_PE Parity Error interrupt
elmot 1:d0dfbce63a89 425 * @arg @ref USART_IT_ERR Error interrupt(Frame error, noise error, overrun error)
elmot 1:d0dfbce63a89 426 * @retval None
elmot 1:d0dfbce63a89 427 */
elmot 1:d0dfbce63a89 428 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
elmot 1:d0dfbce63a89 429 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
elmot 1:d0dfbce63a89 430 ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))))
elmot 1:d0dfbce63a89 431
elmot 1:d0dfbce63a89 432 /** @brief Disable the specified USART interrupt.
elmot 1:d0dfbce63a89 433 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 434 * @param __INTERRUPT__: specifies the USART interrupt source to disable.
elmot 1:d0dfbce63a89 435 * This parameter can be one of the following values:
elmot 1:d0dfbce63a89 436 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
elmot 1:d0dfbce63a89 437 * @arg @ref USART_IT_TC Transmission complete interrupt
elmot 1:d0dfbce63a89 438 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
elmot 1:d0dfbce63a89 439 * @arg @ref USART_IT_IDLE Idle line detection interrupt
elmot 1:d0dfbce63a89 440 * @arg @ref USART_IT_PE Parity Error interrupt
elmot 1:d0dfbce63a89 441 * @arg @ref USART_IT_ERR Error interrupt(Frame error, noise error, overrun error)
elmot 1:d0dfbce63a89 442 * @retval None
elmot 1:d0dfbce63a89 443 */
elmot 1:d0dfbce63a89 444 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
elmot 1:d0dfbce63a89 445 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
elmot 1:d0dfbce63a89 446 ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))))
elmot 1:d0dfbce63a89 447
elmot 1:d0dfbce63a89 448
elmot 1:d0dfbce63a89 449 /** @brief Check whether the specified USART interrupt has occurred or not.
elmot 1:d0dfbce63a89 450 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 451 * @param __IT__: specifies the USART interrupt source to check.
elmot 1:d0dfbce63a89 452 * This parameter can be one of the following values:
elmot 1:d0dfbce63a89 453 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
elmot 1:d0dfbce63a89 454 * @arg @ref USART_IT_TC Transmission complete interrupt
elmot 1:d0dfbce63a89 455 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
elmot 1:d0dfbce63a89 456 * @arg @ref USART_IT_IDLE Idle line detection interrupt
elmot 1:d0dfbce63a89 457 * @arg @ref USART_IT_ORE OverRun Error interrupt
elmot 1:d0dfbce63a89 458 * @arg @ref USART_IT_NE Noise Error interrupt
elmot 1:d0dfbce63a89 459 * @arg @ref USART_IT_FE Framing Error interrupt
elmot 1:d0dfbce63a89 460 * @arg @ref USART_IT_PE Parity Error interrupt
elmot 1:d0dfbce63a89 461 * @retval The new state of __IT__ (TRUE or FALSE).
elmot 1:d0dfbce63a89 462 */
elmot 1:d0dfbce63a89 463 #define __HAL_USART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
elmot 1:d0dfbce63a89 464
elmot 1:d0dfbce63a89 465 /** @brief Check whether the specified USART interrupt source is enabled or not.
elmot 1:d0dfbce63a89 466 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 467 * @param __IT__: specifies the USART interrupt source to check.
elmot 1:d0dfbce63a89 468 * This parameter can be one of the following values:
elmot 1:d0dfbce63a89 469 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
elmot 1:d0dfbce63a89 470 * @arg @ref USART_IT_TC Transmission complete interrupt
elmot 1:d0dfbce63a89 471 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
elmot 1:d0dfbce63a89 472 * @arg @ref USART_IT_IDLE Idle line detection interrupt
elmot 1:d0dfbce63a89 473 * @arg @ref USART_IT_ORE OverRun Error interrupt
elmot 1:d0dfbce63a89 474 * @arg @ref USART_IT_NE Noise Error interrupt
elmot 1:d0dfbce63a89 475 * @arg @ref USART_IT_FE Framing Error interrupt
elmot 1:d0dfbce63a89 476 * @arg @ref USART_IT_PE Parity Error interrupt
elmot 1:d0dfbce63a89 477 * @retval The new state of __IT__ (TRUE or FALSE).
elmot 1:d0dfbce63a89 478 */
elmot 1:d0dfbce63a89 479 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5) == 2)? \
elmot 1:d0dfbce63a89 480 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << \
elmot 1:d0dfbce63a89 481 (((uint16_t)(__IT__)) & USART_IT_MASK)))
elmot 1:d0dfbce63a89 482
elmot 1:d0dfbce63a89 483
elmot 1:d0dfbce63a89 484 /** @brief Clear the specified USART ISR flag, in setting the proper ICR register flag.
elmot 1:d0dfbce63a89 485 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 486 * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
elmot 1:d0dfbce63a89 487 * to clear the corresponding interrupt.
elmot 1:d0dfbce63a89 488 * This parameter can be one of the following values:
elmot 1:d0dfbce63a89 489 * @arg @ref USART_CLEAR_PEF Parity Error Clear Flag
elmot 1:d0dfbce63a89 490 * @arg @ref USART_CLEAR_FEF Framing Error Clear Flag
elmot 1:d0dfbce63a89 491 * @arg @ref USART_CLEAR_NEF Noise detected Clear Flag
elmot 1:d0dfbce63a89 492 * @arg @ref USART_CLEAR_OREF OverRun Error Clear Flag
elmot 1:d0dfbce63a89 493 * @arg @ref USART_CLEAR_IDLEF IDLE line detected Clear Flag
elmot 1:d0dfbce63a89 494 * @arg @ref USART_CLEAR_TCF Transmission Complete Clear Flag
elmot 1:d0dfbce63a89 495 * @retval None
elmot 1:d0dfbce63a89 496 */
elmot 1:d0dfbce63a89 497 #define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
elmot 1:d0dfbce63a89 498
elmot 1:d0dfbce63a89 499 /** @brief Set a specific USART request flag.
elmot 1:d0dfbce63a89 500 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 501 * @param __REQ__: specifies the request flag to set.
elmot 1:d0dfbce63a89 502 * This parameter can be one of the following values:
elmot 1:d0dfbce63a89 503 * @arg @ref USART_RXDATA_FLUSH_REQUEST Receive Data flush Request
elmot 1:d0dfbce63a89 504 * @arg @ref USART_TXDATA_FLUSH_REQUEST Transmit data flush Request
elmot 1:d0dfbce63a89 505 *
elmot 1:d0dfbce63a89 506 * @retval None
elmot 1:d0dfbce63a89 507 */
elmot 1:d0dfbce63a89 508 #define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (__REQ__))
elmot 1:d0dfbce63a89 509
elmot 1:d0dfbce63a89 510 /** @brief Enable the USART one bit sample method.
elmot 1:d0dfbce63a89 511 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 512 * @retval None
elmot 1:d0dfbce63a89 513 */
elmot 1:d0dfbce63a89 514 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
elmot 1:d0dfbce63a89 515
elmot 1:d0dfbce63a89 516 /** @brief Disable the USART one bit sample method.
elmot 1:d0dfbce63a89 517 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 518 * @retval None
elmot 1:d0dfbce63a89 519 */
elmot 1:d0dfbce63a89 520 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
elmot 1:d0dfbce63a89 521
elmot 1:d0dfbce63a89 522 /** @brief Enable USART.
elmot 1:d0dfbce63a89 523 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 524 * @retval None
elmot 1:d0dfbce63a89 525 */
elmot 1:d0dfbce63a89 526 #define __HAL_USART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
elmot 1:d0dfbce63a89 527
elmot 1:d0dfbce63a89 528 /** @brief Disable USART.
elmot 1:d0dfbce63a89 529 * @param __HANDLE__: specifies the USART Handle.
elmot 1:d0dfbce63a89 530 * @retval None
elmot 1:d0dfbce63a89 531 */
elmot 1:d0dfbce63a89 532 #define __HAL_USART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
elmot 1:d0dfbce63a89 533
elmot 1:d0dfbce63a89 534 /**
elmot 1:d0dfbce63a89 535 * @}
elmot 1:d0dfbce63a89 536 */
elmot 1:d0dfbce63a89 537
elmot 1:d0dfbce63a89 538 /* Private macros --------------------------------------------------------*/
elmot 1:d0dfbce63a89 539 /** @defgroup USART_Private_Macros USART Private Macros
elmot 1:d0dfbce63a89 540 * @{
elmot 1:d0dfbce63a89 541 */
elmot 1:d0dfbce63a89 542
elmot 1:d0dfbce63a89 543 /** @brief Check USART Baud rate.
elmot 1:d0dfbce63a89 544 * @param __BAUDRATE__: Baudrate specified by the user.
elmot 1:d0dfbce63a89 545 * The maximum Baud Rate is derived from the maximum clock on L4 (i.e. 80 MHz)
elmot 1:d0dfbce63a89 546 * divided by the smallest oversampling used on the USART (i.e. 8).
elmot 1:d0dfbce63a89 547 * @retval Test result (TRUE or FALSE).
elmot 1:d0dfbce63a89 548 */
elmot 1:d0dfbce63a89 549 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 10000001)
elmot 1:d0dfbce63a89 550
elmot 1:d0dfbce63a89 551 /**
elmot 1:d0dfbce63a89 552 * @brief Ensure that USART frame number of stop bits is valid.
elmot 1:d0dfbce63a89 553 * @param __STOPBITS__: USART frame number of stop bits.
elmot 1:d0dfbce63a89 554 * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
elmot 1:d0dfbce63a89 555 */
elmot 1:d0dfbce63a89 556 #define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_0_5) || \
elmot 1:d0dfbce63a89 557 ((__STOPBITS__) == USART_STOPBITS_1) || \
elmot 1:d0dfbce63a89 558 ((__STOPBITS__) == USART_STOPBITS_1_5) || \
elmot 1:d0dfbce63a89 559 ((__STOPBITS__) == USART_STOPBITS_2))
elmot 1:d0dfbce63a89 560
elmot 1:d0dfbce63a89 561 /**
elmot 1:d0dfbce63a89 562 * @brief Ensure that USART frame parity is valid.
elmot 1:d0dfbce63a89 563 * @param __PARITY__: USART frame parity.
elmot 1:d0dfbce63a89 564 * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
elmot 1:d0dfbce63a89 565 */
elmot 1:d0dfbce63a89 566 #define IS_USART_PARITY(__PARITY__) (((__PARITY__) == USART_PARITY_NONE) || \
elmot 1:d0dfbce63a89 567 ((__PARITY__) == USART_PARITY_EVEN) || \
elmot 1:d0dfbce63a89 568 ((__PARITY__) == USART_PARITY_ODD))
elmot 1:d0dfbce63a89 569
elmot 1:d0dfbce63a89 570 /**
elmot 1:d0dfbce63a89 571 * @brief Ensure that USART communication mode is valid.
elmot 1:d0dfbce63a89 572 * @param __MODE__: USART communication mode.
elmot 1:d0dfbce63a89 573 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
elmot 1:d0dfbce63a89 574 */
elmot 1:d0dfbce63a89 575 #define IS_USART_MODE(__MODE__) ((((__MODE__) & (uint32_t)0xFFFFFFF3) == 0x00) && ((__MODE__) != (uint32_t)0x00))
elmot 1:d0dfbce63a89 576
elmot 1:d0dfbce63a89 577 /**
elmot 1:d0dfbce63a89 578 * @brief Ensure that USART oversampling is valid.
elmot 1:d0dfbce63a89 579 * @param __SAMPLING__: USART oversampling.
elmot 1:d0dfbce63a89 580 * @retval SET (__SAMPLING__ is valid) or RESET (__SAMPLING__ is invalid)
elmot 1:d0dfbce63a89 581 */
elmot 1:d0dfbce63a89 582 #define IS_USART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == USART_OVERSAMPLING_16) || \
elmot 1:d0dfbce63a89 583 ((__SAMPLING__) == USART_OVERSAMPLING_8))
elmot 1:d0dfbce63a89 584
elmot 1:d0dfbce63a89 585 /**
elmot 1:d0dfbce63a89 586 * @brief Ensure that USART clock state is valid.
elmot 1:d0dfbce63a89 587 * @param __CLOCK__: USART clock state.
elmot 1:d0dfbce63a89 588 * @retval SET (__CLOCK__ is valid) or RESET (__CLOCK__ is invalid)
elmot 1:d0dfbce63a89 589 */
elmot 1:d0dfbce63a89 590 #define IS_USART_CLOCK(__CLOCK__) (((__CLOCK__) == USART_CLOCK_DISABLE) || \
elmot 1:d0dfbce63a89 591 ((__CLOCK__) == USART_CLOCK_ENABLE))
elmot 1:d0dfbce63a89 592
elmot 1:d0dfbce63a89 593 /**
elmot 1:d0dfbce63a89 594 * @brief Ensure that USART frame polarity is valid.
elmot 1:d0dfbce63a89 595 * @param __CPOL__: USART frame polarity.
elmot 1:d0dfbce63a89 596 * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
elmot 1:d0dfbce63a89 597 */
elmot 1:d0dfbce63a89 598 #define IS_USART_POLARITY(__CPOL__) (((__CPOL__) == USART_POLARITY_LOW) || ((__CPOL__) == USART_POLARITY_HIGH))
elmot 1:d0dfbce63a89 599
elmot 1:d0dfbce63a89 600 /**
elmot 1:d0dfbce63a89 601 * @brief Ensure that USART frame phase is valid.
elmot 1:d0dfbce63a89 602 * @param __CPHA__: USART frame phase.
elmot 1:d0dfbce63a89 603 * @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid)
elmot 1:d0dfbce63a89 604 */
elmot 1:d0dfbce63a89 605 #define IS_USART_PHASE(__CPHA__) (((__CPHA__) == USART_PHASE_1EDGE) || ((__CPHA__) == USART_PHASE_2EDGE))
elmot 1:d0dfbce63a89 606
elmot 1:d0dfbce63a89 607 /**
elmot 1:d0dfbce63a89 608 * @brief Ensure that USART frame last bit clock pulse setting is valid.
elmot 1:d0dfbce63a89 609 * @param __LASTBIT__: USART frame last bit clock pulse setting.
elmot 1:d0dfbce63a89 610 * @retval SET (__LASTBIT__ is valid) or RESET (__LASTBIT__ is invalid)
elmot 1:d0dfbce63a89 611 */
elmot 1:d0dfbce63a89 612 #define IS_USART_LASTBIT(__LASTBIT__) (((__LASTBIT__) == USART_LASTBIT_DISABLE) || \
elmot 1:d0dfbce63a89 613 ((__LASTBIT__) == USART_LASTBIT_ENABLE))
elmot 1:d0dfbce63a89 614
elmot 1:d0dfbce63a89 615 /**
elmot 1:d0dfbce63a89 616 * @brief Ensure that USART request parameter is valid.
elmot 1:d0dfbce63a89 617 * @param __PARAM__: USART request parameter.
elmot 1:d0dfbce63a89 618 * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
elmot 1:d0dfbce63a89 619 */
elmot 1:d0dfbce63a89 620 #define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \
elmot 1:d0dfbce63a89 621 ((__PARAM__) == USART_TXDATA_FLUSH_REQUEST))
elmot 1:d0dfbce63a89 622
elmot 1:d0dfbce63a89 623 /**
elmot 1:d0dfbce63a89 624 * @}
elmot 1:d0dfbce63a89 625 */
elmot 1:d0dfbce63a89 626
elmot 1:d0dfbce63a89 627 /* Include USART HAL Extended module */
elmot 1:d0dfbce63a89 628 #include "stm32l4xx_hal_usart_ex.h"
elmot 1:d0dfbce63a89 629
elmot 1:d0dfbce63a89 630 /* Exported functions --------------------------------------------------------*/
elmot 1:d0dfbce63a89 631 /** @addtogroup USART_Exported_Functions USART Exported Functions
elmot 1:d0dfbce63a89 632 * @{
elmot 1:d0dfbce63a89 633 */
elmot 1:d0dfbce63a89 634
elmot 1:d0dfbce63a89 635 /** @addtogroup USART_Exported_Functions_Group1 Initialization and de-initialization functions
elmot 1:d0dfbce63a89 636 * @{
elmot 1:d0dfbce63a89 637 */
elmot 1:d0dfbce63a89 638
elmot 1:d0dfbce63a89 639 /* Initialization and de-initialization functions ****************************/
elmot 1:d0dfbce63a89 640 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 641 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 642 void HAL_USART_MspInit(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 643 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 644
elmot 1:d0dfbce63a89 645 /**
elmot 1:d0dfbce63a89 646 * @}
elmot 1:d0dfbce63a89 647 */
elmot 1:d0dfbce63a89 648
elmot 1:d0dfbce63a89 649 /** @addtogroup USART_Exported_Functions_Group2 IO operation functions
elmot 1:d0dfbce63a89 650 * @{
elmot 1:d0dfbce63a89 651 */
elmot 1:d0dfbce63a89 652
elmot 1:d0dfbce63a89 653 /* IO operation functions *****************************************************/
elmot 1:d0dfbce63a89 654 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
elmot 1:d0dfbce63a89 655 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
elmot 1:d0dfbce63a89 656 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
elmot 1:d0dfbce63a89 657 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
elmot 1:d0dfbce63a89 658 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
elmot 1:d0dfbce63a89 659 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
elmot 1:d0dfbce63a89 660 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
elmot 1:d0dfbce63a89 661 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
elmot 1:d0dfbce63a89 662 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
elmot 1:d0dfbce63a89 663 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 664 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 665 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 666 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 667 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 668 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 669 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 670 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 671 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 672 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 673
elmot 1:d0dfbce63a89 674 /**
elmot 1:d0dfbce63a89 675 * @}
elmot 1:d0dfbce63a89 676 */
elmot 1:d0dfbce63a89 677
elmot 1:d0dfbce63a89 678 /* Peripheral Control functions ***********************************************/
elmot 1:d0dfbce63a89 679
elmot 1:d0dfbce63a89 680 /** @addtogroup USART_Exported_Functions_Group4 Peripheral State and Error functions
elmot 1:d0dfbce63a89 681 * @{
elmot 1:d0dfbce63a89 682 */
elmot 1:d0dfbce63a89 683
elmot 1:d0dfbce63a89 684 /* Peripheral State and Error functions ***************************************/
elmot 1:d0dfbce63a89 685 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 686 uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart);
elmot 1:d0dfbce63a89 687
elmot 1:d0dfbce63a89 688 /**
elmot 1:d0dfbce63a89 689 * @}
elmot 1:d0dfbce63a89 690 */
elmot 1:d0dfbce63a89 691
elmot 1:d0dfbce63a89 692 /**
elmot 1:d0dfbce63a89 693 * @}
elmot 1:d0dfbce63a89 694 */
elmot 1:d0dfbce63a89 695
elmot 1:d0dfbce63a89 696 /**
elmot 1:d0dfbce63a89 697 * @}
elmot 1:d0dfbce63a89 698 */
elmot 1:d0dfbce63a89 699
elmot 1:d0dfbce63a89 700 /**
elmot 1:d0dfbce63a89 701 * @}
elmot 1:d0dfbce63a89 702 */
elmot 1:d0dfbce63a89 703
elmot 1:d0dfbce63a89 704 #ifdef __cplusplus
elmot 1:d0dfbce63a89 705 }
elmot 1:d0dfbce63a89 706 #endif
elmot 1:d0dfbce63a89 707
elmot 1:d0dfbce63a89 708 #endif /* __STM32L4xx_HAL_USART_H */
elmot 1:d0dfbce63a89 709
elmot 1:d0dfbce63a89 710 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/