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

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
<>
Date:
Wed Apr 12 16:07:08 2017 +0100
Revision:
140:97feb9bacc10
Parent:
128:9bcdf88f62b0
Child:
145:64910690c574
Release 140 of the mbed library

Ports for Upcoming Targets

3841: Add nRf52840 target https://github.com/ARMmbed/mbed-os/pull/3841
3992: Introducing UBLOX_C030 platform. https://github.com/ARMmbed/mbed-os/pull/3992

Fixes and Changes

3951: [NUCLEO_F303ZE] Correct ARDUINO pin https://github.com/ARMmbed/mbed-os/pull/3951
4021: Fixing a macro to detect when RTOS was in use for the NRF52840_DK https://github.com/ARMmbed/mbed-os/pull/4021
3979: KW24D: Add missing SPI defines and Arduino connector definitions https://github.com/ARMmbed/mbed-os/pull/3979
3990: UBLOX_C027: construct a ticker-based wait, rather than calling wait_ms(), in the https://github.com/ARMmbed/mbed-os/pull/3990
4003: Fixed OBOE in async serial tx for NRF52 target, fixes #4002 https://github.com/ARMmbed/mbed-os/pull/4003
4012: STM32: Correct I2C master error handling https://github.com/ARMmbed/mbed-os/pull/4012
4020: NUCLEO_L011K4 remove unsupported tool chain files https://github.com/ARMmbed/mbed-os/pull/4020
4065: K66F: Move bss section to m_data_2 Section https://github.com/ARMmbed/mbed-os/pull/4065
4014: Issue 3763: Reduce heap allocation in the GCC linker file https://github.com/ARMmbed/mbed-os/pull/4014
4030: [STM32L0] reduce IAR heap and stack size for small targets https://github.com/ARMmbed/mbed-os/pull/4030
4109: NUCLEO_L476RG : minor serial pin update https://github.com/ARMmbed/mbed-os/pull/4109
3982: Ticker - kl25z bugfix for handling events in the past https://github.com/ARMmbed/mbed-os/pull/3982

Who changed what in which revision?

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