mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

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