mbed(SerialHalfDuplex入り)

Fork of mbed by mbed official

Committer:
yusuke_kyo
Date:
Wed Apr 08 08:04:18 2015 +0000
Revision:
98:01a414ca7d6d
Parent:
96:487b796308b0
remove SerialHalfDuplex.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 96:487b796308b0 1 /**
Kojto 96:487b796308b0 2 ******************************************************************************
Kojto 96:487b796308b0 3 * @file stm32f1xx_hal_uart.h
Kojto 96:487b796308b0 4 * @author MCD Application Team
Kojto 96:487b796308b0 5 * @version V1.0.0
Kojto 96:487b796308b0 6 * @date 15-December-2014
Kojto 96:487b796308b0 7 * @brief Header file of UART HAL module.
Kojto 96:487b796308b0 8 ******************************************************************************
Kojto 96:487b796308b0 9 * @attention
Kojto 96:487b796308b0 10 *
Kojto 96:487b796308b0 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Kojto 96:487b796308b0 12 *
Kojto 96:487b796308b0 13 * Redistribution and use in source and binary forms, with or without modification,
Kojto 96:487b796308b0 14 * are permitted provided that the following conditions are met:
Kojto 96:487b796308b0 15 * 1. Redistributions of source code must retain the above copyright notice,
Kojto 96:487b796308b0 16 * this list of conditions and the following disclaimer.
Kojto 96:487b796308b0 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Kojto 96:487b796308b0 18 * this list of conditions and the following disclaimer in the documentation
Kojto 96:487b796308b0 19 * and/or other materials provided with the distribution.
Kojto 96:487b796308b0 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Kojto 96:487b796308b0 21 * may be used to endorse or promote products derived from this software
Kojto 96:487b796308b0 22 * without specific prior written permission.
Kojto 96:487b796308b0 23 *
Kojto 96:487b796308b0 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Kojto 96:487b796308b0 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Kojto 96:487b796308b0 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 96:487b796308b0 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Kojto 96:487b796308b0 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Kojto 96:487b796308b0 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Kojto 96:487b796308b0 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Kojto 96:487b796308b0 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Kojto 96:487b796308b0 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 96:487b796308b0 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 96:487b796308b0 34 *
Kojto 96:487b796308b0 35 ******************************************************************************
Kojto 96:487b796308b0 36 */
Kojto 96:487b796308b0 37
Kojto 96:487b796308b0 38 /* Define to prevent recursive inclusion -------------------------------------*/
Kojto 96:487b796308b0 39 #ifndef __STM32F1xx_HAL_UART_H
Kojto 96:487b796308b0 40 #define __STM32F1xx_HAL_UART_H
Kojto 96:487b796308b0 41
Kojto 96:487b796308b0 42 #ifdef __cplusplus
Kojto 96:487b796308b0 43 extern "C" {
Kojto 96:487b796308b0 44 #endif
Kojto 96:487b796308b0 45
Kojto 96:487b796308b0 46 /* Includes ------------------------------------------------------------------*/
Kojto 96:487b796308b0 47 #include "stm32f1xx_hal_def.h"
Kojto 96:487b796308b0 48
Kojto 96:487b796308b0 49 /** @addtogroup STM32F1xx_HAL_Driver
Kojto 96:487b796308b0 50 * @{
Kojto 96:487b796308b0 51 */
Kojto 96:487b796308b0 52
Kojto 96:487b796308b0 53 /** @addtogroup UART
Kojto 96:487b796308b0 54 * @{
Kojto 96:487b796308b0 55 */
Kojto 96:487b796308b0 56
Kojto 96:487b796308b0 57 /* Exported types ------------------------------------------------------------*/
Kojto 96:487b796308b0 58 /** @defgroup UART_Exported_Types UART Exported Types
Kojto 96:487b796308b0 59 * @{
Kojto 96:487b796308b0 60 */
Kojto 96:487b796308b0 61
Kojto 96:487b796308b0 62
Kojto 96:487b796308b0 63 /**
Kojto 96:487b796308b0 64 * @brief UART Init Structure definition
Kojto 96:487b796308b0 65 */
Kojto 96:487b796308b0 66 typedef struct
Kojto 96:487b796308b0 67 {
Kojto 96:487b796308b0 68 uint32_t BaudRate; /*!< This member configures the UART communication baud rate.
Kojto 96:487b796308b0 69 The baud rate is computed using the following formula:
Kojto 96:487b796308b0 70 - IntegerDivider = ((PCLKx) / (16 * (huart->Init.BaudRate)))
Kojto 96:487b796308b0 71 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */
Kojto 96:487b796308b0 72
Kojto 96:487b796308b0 73 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
Kojto 96:487b796308b0 74 This parameter can be a value of @ref UART_Word_Length */
Kojto 96:487b796308b0 75
Kojto 96:487b796308b0 76 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
Kojto 96:487b796308b0 77 This parameter can be a value of @ref UART_Stop_Bits */
Kojto 96:487b796308b0 78
Kojto 96:487b796308b0 79 uint32_t Parity; /*!< Specifies the parity mode.
Kojto 96:487b796308b0 80 This parameter can be a value of @ref UART_Parity
Kojto 96:487b796308b0 81 @note When parity is enabled, the computed parity is inserted
Kojto 96:487b796308b0 82 at the MSB position of the transmitted data (9th bit when
Kojto 96:487b796308b0 83 the word length is set to 9 data bits; 8th bit when the
Kojto 96:487b796308b0 84 word length is set to 8 data bits). */
Kojto 96:487b796308b0 85
Kojto 96:487b796308b0 86 uint32_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
Kojto 96:487b796308b0 87 This parameter can be a value of @ref UART_Mode */
Kojto 96:487b796308b0 88
Kojto 96:487b796308b0 89 uint32_t HwFlowCtl; /*!< Specifies wether the hardware flow control mode is enabled
Kojto 96:487b796308b0 90 or disabled.
Kojto 96:487b796308b0 91 This parameter can be a value of @ref UART_Hardware_Flow_Control */
Kojto 96:487b796308b0 92
Kojto 96:487b796308b0 93 uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
Kojto 96:487b796308b0 94 This parameter can be a value of @ref UART_Over_Sampling. This feature is not available
Kojto 96:487b796308b0 95 on STM32F1xx family, so OverSampling parameter should always be set to 16. */
Kojto 96:487b796308b0 96 }UART_InitTypeDef;
Kojto 96:487b796308b0 97
Kojto 96:487b796308b0 98 /**
Kojto 96:487b796308b0 99 * @brief HAL UART State structures definition
Kojto 96:487b796308b0 100 */
Kojto 96:487b796308b0 101 typedef enum
Kojto 96:487b796308b0 102 {
Kojto 96:487b796308b0 103 HAL_UART_STATE_RESET = 0x00, /*!< Peripheral is not initialized */
Kojto 96:487b796308b0 104 HAL_UART_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
Kojto 96:487b796308b0 105 HAL_UART_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
Kojto 96:487b796308b0 106 HAL_UART_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
Kojto 96:487b796308b0 107 HAL_UART_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
Kojto 96:487b796308b0 108 HAL_UART_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
Kojto 96:487b796308b0 109 HAL_UART_STATE_TIMEOUT = 0x03, /*!< Timeout state */
Kojto 96:487b796308b0 110 HAL_UART_STATE_ERROR = 0x04 /*!< Error */
Kojto 96:487b796308b0 111 }HAL_UART_StateTypeDef;
Kojto 96:487b796308b0 112
Kojto 96:487b796308b0 113
Kojto 96:487b796308b0 114 /**
Kojto 96:487b796308b0 115 * @brief UART handle Structure definition
Kojto 96:487b796308b0 116 */
Kojto 96:487b796308b0 117 typedef struct
Kojto 96:487b796308b0 118 {
Kojto 96:487b796308b0 119 USART_TypeDef *Instance; /*!< UART registers base address */
Kojto 96:487b796308b0 120
Kojto 96:487b796308b0 121 UART_InitTypeDef Init; /*!< UART communication parameters */
Kojto 96:487b796308b0 122
Kojto 96:487b796308b0 123 uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */
Kojto 96:487b796308b0 124
Kojto 96:487b796308b0 125 uint16_t TxXferSize; /*!< UART Tx Transfer size */
Kojto 96:487b796308b0 126
Kojto 96:487b796308b0 127 uint16_t TxXferCount; /*!< UART Tx Transfer Counter */
Kojto 96:487b796308b0 128
Kojto 96:487b796308b0 129 uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */
Kojto 96:487b796308b0 130
Kojto 96:487b796308b0 131 uint16_t RxXferSize; /*!< UART Rx Transfer size */
Kojto 96:487b796308b0 132
Kojto 96:487b796308b0 133 uint16_t RxXferCount; /*!< UART Rx Transfer Counter */
Kojto 96:487b796308b0 134
Kojto 96:487b796308b0 135 DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */
Kojto 96:487b796308b0 136
Kojto 96:487b796308b0 137 DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */
Kojto 96:487b796308b0 138
Kojto 96:487b796308b0 139 HAL_LockTypeDef Lock; /*!< Locking object */
Kojto 96:487b796308b0 140
Kojto 96:487b796308b0 141 __IO HAL_UART_StateTypeDef State; /*!< UART communication state */
Kojto 96:487b796308b0 142
Kojto 96:487b796308b0 143 __IO uint32_t ErrorCode; /*!< UART Error code */
Kojto 96:487b796308b0 144
Kojto 96:487b796308b0 145 }UART_HandleTypeDef;
Kojto 96:487b796308b0 146
Kojto 96:487b796308b0 147 /**
Kojto 96:487b796308b0 148 * @}
Kojto 96:487b796308b0 149 */
Kojto 96:487b796308b0 150
Kojto 96:487b796308b0 151 /* Exported constants --------------------------------------------------------*/
Kojto 96:487b796308b0 152 /** @defgroup UART_Exported_Constants UART Exported constants
Kojto 96:487b796308b0 153 * @{
Kojto 96:487b796308b0 154 */
Kojto 96:487b796308b0 155
Kojto 96:487b796308b0 156 /** @defgroup UART_Error_Codes UART Error Codes
Kojto 96:487b796308b0 157 * @{
Kojto 96:487b796308b0 158 */
Kojto 96:487b796308b0 159
Kojto 96:487b796308b0 160 #define HAL_UART_ERROR_NONE ((uint32_t)0x00) /*!< No error */
Kojto 96:487b796308b0 161 #define HAL_UART_ERROR_PE ((uint32_t)0x01) /*!< Parity error */
Kojto 96:487b796308b0 162 #define HAL_UART_ERROR_NE ((uint32_t)0x02) /*!< Noise error */
Kojto 96:487b796308b0 163 #define HAL_UART_ERROR_FE ((uint32_t)0x04) /*!< frame error */
Kojto 96:487b796308b0 164 #define HAL_UART_ERROR_ORE ((uint32_t)0x08) /*!< Overrun error */
Kojto 96:487b796308b0 165 #define HAL_UART_ERROR_DMA ((uint32_t)0x10) /*!< DMA transfer error */
Kojto 96:487b796308b0 166
Kojto 96:487b796308b0 167 /**
Kojto 96:487b796308b0 168 * @}
Kojto 96:487b796308b0 169 */
Kojto 96:487b796308b0 170
Kojto 96:487b796308b0 171
Kojto 96:487b796308b0 172
Kojto 96:487b796308b0 173
Kojto 96:487b796308b0 174 /** @defgroup UART_Word_Length UART Word Length
Kojto 96:487b796308b0 175 * @{
Kojto 96:487b796308b0 176 */
Kojto 96:487b796308b0 177 #define UART_WORDLENGTH_8B ((uint32_t)0x00000000)
Kojto 96:487b796308b0 178 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
Kojto 96:487b796308b0 179 /**
Kojto 96:487b796308b0 180 * @}
Kojto 96:487b796308b0 181 */
Kojto 96:487b796308b0 182
Kojto 96:487b796308b0 183 /** @defgroup UART_Stop_Bits UART Number of Stop Bits
Kojto 96:487b796308b0 184 * @{
Kojto 96:487b796308b0 185 */
Kojto 96:487b796308b0 186 #define UART_STOPBITS_1 ((uint32_t)0x00000000)
Kojto 96:487b796308b0 187 #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
Kojto 96:487b796308b0 188 /**
Kojto 96:487b796308b0 189 * @}
Kojto 96:487b796308b0 190 */
Kojto 96:487b796308b0 191
Kojto 96:487b796308b0 192 /** @defgroup UART_Parity UART Parity
Kojto 96:487b796308b0 193 * @{
Kojto 96:487b796308b0 194 */
Kojto 96:487b796308b0 195 #define UART_PARITY_NONE ((uint32_t)0x00000000)
Kojto 96:487b796308b0 196 #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
Kojto 96:487b796308b0 197 #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
Kojto 96:487b796308b0 198 /**
Kojto 96:487b796308b0 199 * @}
Kojto 96:487b796308b0 200 */
Kojto 96:487b796308b0 201
Kojto 96:487b796308b0 202 /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
Kojto 96:487b796308b0 203 * @{
Kojto 96:487b796308b0 204 */
Kojto 96:487b796308b0 205 #define UART_HWCONTROL_NONE ((uint32_t)0x00000000)
Kojto 96:487b796308b0 206 #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE)
Kojto 96:487b796308b0 207 #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE)
Kojto 96:487b796308b0 208 #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
Kojto 96:487b796308b0 209 /**
Kojto 96:487b796308b0 210 * @}
Kojto 96:487b796308b0 211 */
Kojto 96:487b796308b0 212
Kojto 96:487b796308b0 213 /** @defgroup UART_Mode UART Transfer Mode
Kojto 96:487b796308b0 214 * @{
Kojto 96:487b796308b0 215 */
Kojto 96:487b796308b0 216 #define UART_MODE_RX ((uint32_t)USART_CR1_RE)
Kojto 96:487b796308b0 217 #define UART_MODE_TX ((uint32_t)USART_CR1_TE)
Kojto 96:487b796308b0 218 #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
Kojto 96:487b796308b0 219
Kojto 96:487b796308b0 220 /**
Kojto 96:487b796308b0 221 * @}
Kojto 96:487b796308b0 222 */
Kojto 96:487b796308b0 223
Kojto 96:487b796308b0 224 /** @defgroup UART_State UART State
Kojto 96:487b796308b0 225 * @{
Kojto 96:487b796308b0 226 */
Kojto 96:487b796308b0 227 #define UART_STATE_DISABLE ((uint32_t)0x00000000)
Kojto 96:487b796308b0 228 #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE)
Kojto 96:487b796308b0 229 /**
Kojto 96:487b796308b0 230 * @}
Kojto 96:487b796308b0 231 */
Kojto 96:487b796308b0 232
Kojto 96:487b796308b0 233 /** @defgroup UART_Over_Sampling UART Over Sampling
Kojto 96:487b796308b0 234 * @{
Kojto 96:487b796308b0 235 */
Kojto 96:487b796308b0 236 #define UART_OVERSAMPLING_16 ((uint32_t)0x00000000)
Kojto 96:487b796308b0 237 /**
Kojto 96:487b796308b0 238 * @}
Kojto 96:487b796308b0 239 */
Kojto 96:487b796308b0 240
Kojto 96:487b796308b0 241 /** @defgroup UART_LIN_Break_Detection_Length UART LIN Break Detection Length
Kojto 96:487b796308b0 242 * @{
Kojto 96:487b796308b0 243 */
Kojto 96:487b796308b0 244 #define UART_LINBREAKDETECTLENGTH_10B ((uint32_t)0x00000000)
Kojto 96:487b796308b0 245 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL)
Kojto 96:487b796308b0 246 /**
Kojto 96:487b796308b0 247 * @}
Kojto 96:487b796308b0 248 */
Kojto 96:487b796308b0 249
Kojto 96:487b796308b0 250 /** @defgroup UART_WakeUp_functions UART Wakeup Functions
Kojto 96:487b796308b0 251 * @{
Kojto 96:487b796308b0 252 */
Kojto 96:487b796308b0 253 #define UART_WAKEUPMETHOD_IDLELINE ((uint32_t)0x00000000)
Kojto 96:487b796308b0 254 #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE)
Kojto 96:487b796308b0 255 /**
Kojto 96:487b796308b0 256 * @}
Kojto 96:487b796308b0 257 */
Kojto 96:487b796308b0 258
Kojto 96:487b796308b0 259 /** @defgroup UART_Flags UART FLags
Kojto 96:487b796308b0 260 * Elements values convention: 0xXXXX
Kojto 96:487b796308b0 261 * - 0xXXXX : Flag mask in the SR register
Kojto 96:487b796308b0 262 * @{
Kojto 96:487b796308b0 263 */
Kojto 96:487b796308b0 264 #define UART_FLAG_CTS ((uint32_t)USART_SR_CTS)
Kojto 96:487b796308b0 265 #define UART_FLAG_LBD ((uint32_t)USART_SR_LBD)
Kojto 96:487b796308b0 266 #define UART_FLAG_TXE ((uint32_t)USART_SR_TXE)
Kojto 96:487b796308b0 267 #define UART_FLAG_TC ((uint32_t)USART_SR_TC)
Kojto 96:487b796308b0 268 #define UART_FLAG_RXNE ((uint32_t)USART_SR_RXNE)
Kojto 96:487b796308b0 269 #define UART_FLAG_IDLE ((uint32_t)USART_SR_IDLE)
Kojto 96:487b796308b0 270 #define UART_FLAG_ORE ((uint32_t)USART_SR_ORE)
Kojto 96:487b796308b0 271 #define UART_FLAG_NE ((uint32_t)USART_SR_NE)
Kojto 96:487b796308b0 272 #define UART_FLAG_FE ((uint32_t)USART_SR_FE)
Kojto 96:487b796308b0 273 #define UART_FLAG_PE ((uint32_t)USART_SR_PE)
Kojto 96:487b796308b0 274 /**
Kojto 96:487b796308b0 275 * @}
Kojto 96:487b796308b0 276 */
Kojto 96:487b796308b0 277
Kojto 96:487b796308b0 278 /** @defgroup UART_Interrupt_definition UART Interrupt Definitions
Kojto 96:487b796308b0 279 * Elements values convention: 0xY000XXXX
Kojto 96:487b796308b0 280 * - XXXX : Interrupt mask (16 bits) in the Y register
Kojto 96:487b796308b0 281 * - Y : Interrupt source register (2bits)
Kojto 96:487b796308b0 282 * - 0001: CR1 register
Kojto 96:487b796308b0 283 * - 0010: CR2 register
Kojto 96:487b796308b0 284 * - 0011: CR3 register
Kojto 96:487b796308b0 285 *
Kojto 96:487b796308b0 286 * @{
Kojto 96:487b796308b0 287 */
Kojto 96:487b796308b0 288
Kojto 96:487b796308b0 289 #define UART_IT_PE ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_PEIE))
Kojto 96:487b796308b0 290 #define UART_IT_TXE ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_TXEIE))
Kojto 96:487b796308b0 291 #define UART_IT_TC ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_TCIE))
Kojto 96:487b796308b0 292 #define UART_IT_RXNE ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_RXNEIE))
Kojto 96:487b796308b0 293 #define UART_IT_IDLE ((uint32_t)(UART_CR1_REG_INDEX << 28 | USART_CR1_IDLEIE))
Kojto 96:487b796308b0 294
Kojto 96:487b796308b0 295 #define UART_IT_LBD ((uint32_t)(UART_CR2_REG_INDEX << 28 | USART_CR2_LBDIE))
Kojto 96:487b796308b0 296
Kojto 96:487b796308b0 297 #define UART_IT_CTS ((uint32_t)(UART_CR3_REG_INDEX << 28 | USART_CR3_CTSIE))
Kojto 96:487b796308b0 298 #define UART_IT_ERR ((uint32_t)(UART_CR3_REG_INDEX << 28 | USART_CR3_EIE))
Kojto 96:487b796308b0 299
Kojto 96:487b796308b0 300 /**
Kojto 96:487b796308b0 301 * @}
Kojto 96:487b796308b0 302 */
Kojto 96:487b796308b0 303
Kojto 96:487b796308b0 304 /**
Kojto 96:487b796308b0 305 * @}
Kojto 96:487b796308b0 306 */
Kojto 96:487b796308b0 307
Kojto 96:487b796308b0 308
Kojto 96:487b796308b0 309 /* Exported macro ------------------------------------------------------------*/
Kojto 96:487b796308b0 310 /** @defgroup UART_Exported_Macros UART Exported Macros
Kojto 96:487b796308b0 311 * @{
Kojto 96:487b796308b0 312 */
Kojto 96:487b796308b0 313
Kojto 96:487b796308b0 314
Kojto 96:487b796308b0 315 /** @brief Reset UART handle state
Kojto 96:487b796308b0 316 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 317 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 318 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 319 * @retval None
Kojto 96:487b796308b0 320 */
Kojto 96:487b796308b0 321 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_UART_STATE_RESET)
Kojto 96:487b796308b0 322
Kojto 96:487b796308b0 323 /** @brief Flush the UART DR register
Kojto 96:487b796308b0 324 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 325 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 326 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 327 */
Kojto 96:487b796308b0 328 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
Kojto 96:487b796308b0 329
Kojto 96:487b796308b0 330 /** @brief Check whether the specified UART flag is set or not.
Kojto 96:487b796308b0 331 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 332 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 333 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 334 * @param __FLAG__: specifies the flag to check.
Kojto 96:487b796308b0 335 * This parameter can be one of the following values:
Kojto 96:487b796308b0 336 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
Kojto 96:487b796308b0 337 * @arg UART_FLAG_LBD: LIN Break detection flag
Kojto 96:487b796308b0 338 * @arg UART_FLAG_TXE: Transmit data register empty flag
Kojto 96:487b796308b0 339 * @arg UART_FLAG_TC: Transmission Complete flag
Kojto 96:487b796308b0 340 * @arg UART_FLAG_RXNE: Receive data register not empty flag
Kojto 96:487b796308b0 341 * @arg UART_FLAG_IDLE: Idle Line detection flag
Kojto 96:487b796308b0 342 * @arg UART_FLAG_ORE: OverRun Error flag
Kojto 96:487b796308b0 343 * @arg UART_FLAG_NE: Noise Error flag
Kojto 96:487b796308b0 344 * @arg UART_FLAG_FE: Framing Error flag
Kojto 96:487b796308b0 345 * @arg UART_FLAG_PE: Parity Error flag
Kojto 96:487b796308b0 346 * @retval The new state of __FLAG__ (TRUE or FALSE).
Kojto 96:487b796308b0 347 */
Kojto 96:487b796308b0 348 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
Kojto 96:487b796308b0 349
Kojto 96:487b796308b0 350 /** @brief Clear the specified UART pending flag.
Kojto 96:487b796308b0 351 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 352 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 353 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 354 * @param __FLAG__: specifies the flag to check.
Kojto 96:487b796308b0 355 * This parameter can be any combination of the following values:
Kojto 96:487b796308b0 356 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5).
Kojto 96:487b796308b0 357 * @arg UART_FLAG_LBD: LIN Break detection flag.
Kojto 96:487b796308b0 358 * @arg UART_FLAG_TC: Transmission Complete flag.
Kojto 96:487b796308b0 359 * @arg UART_FLAG_RXNE: Receive data register not empty flag.
Kojto 96:487b796308b0 360 *
Kojto 96:487b796308b0 361 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
Kojto 96:487b796308b0 362 * error) and IDLE (Idle line detected) flags are cleared by software
Kojto 96:487b796308b0 363 * sequence: a read operation to USART_SR register followed by a read
Kojto 96:487b796308b0 364 * operation to USART_DR register.
Kojto 96:487b796308b0 365 * @note RXNE flag can be also cleared by a read to the USART_DR register.
Kojto 96:487b796308b0 366 * @note TC flag can be also cleared by software sequence: a read operation to
Kojto 96:487b796308b0 367 * USART_SR register followed by a write operation to USART_DR register.
Kojto 96:487b796308b0 368 * @note TXE flag is cleared only by a write to the USART_DR register.
Kojto 96:487b796308b0 369 *
Kojto 96:487b796308b0 370 * @retval None
Kojto 96:487b796308b0 371 */
Kojto 96:487b796308b0 372 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
Kojto 96:487b796308b0 373
Kojto 96:487b796308b0 374 /** @brief Clear the UART PE pending flag.
Kojto 96:487b796308b0 375 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 376 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 377 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 378 * @retval None
Kojto 96:487b796308b0 379 */
Kojto 96:487b796308b0 380 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) \
Kojto 96:487b796308b0 381 do{ \
Kojto 96:487b796308b0 382 __IO uint32_t tmpreg; \
Kojto 96:487b796308b0 383 tmpreg = (__HANDLE__)->Instance->SR; \
Kojto 96:487b796308b0 384 tmpreg = (__HANDLE__)->Instance->DR; \
Kojto 96:487b796308b0 385 UNUSED(tmpreg); \
Kojto 96:487b796308b0 386 }while(0)
Kojto 96:487b796308b0 387
Kojto 96:487b796308b0 388
Kojto 96:487b796308b0 389
Kojto 96:487b796308b0 390 /** @brief Clear the UART FE pending flag.
Kojto 96:487b796308b0 391 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 392 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 393 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 394 * @retval None
Kojto 96:487b796308b0 395 */
Kojto 96:487b796308b0 396 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
Kojto 96:487b796308b0 397
Kojto 96:487b796308b0 398 /** @brief Clear the UART NE pending flag.
Kojto 96:487b796308b0 399 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 400 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 401 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 402 * @retval None
Kojto 96:487b796308b0 403 */
Kojto 96:487b796308b0 404 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
Kojto 96:487b796308b0 405
Kojto 96:487b796308b0 406 /** @brief Clear the UART ORE pending flag.
Kojto 96:487b796308b0 407 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 408 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 409 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 410 * @retval None
Kojto 96:487b796308b0 411 */
Kojto 96:487b796308b0 412 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
Kojto 96:487b796308b0 413
Kojto 96:487b796308b0 414 /** @brief Clear the UART IDLE pending flag.
Kojto 96:487b796308b0 415 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 416 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 417 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 418 * @retval None
Kojto 96:487b796308b0 419 */
Kojto 96:487b796308b0 420 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
Kojto 96:487b796308b0 421
Kojto 96:487b796308b0 422 /** @brief Enable the specified UART interrupt.
Kojto 96:487b796308b0 423 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 424 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 425 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 426 * @param __INTERRUPT__: specifies the UART interrupt source to enable.
Kojto 96:487b796308b0 427 * This parameter can be one of the following values:
Kojto 96:487b796308b0 428 * @arg UART_IT_CTS: CTS change interrupt
Kojto 96:487b796308b0 429 * @arg UART_IT_LBD: LIN Break detection interrupt
Kojto 96:487b796308b0 430 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
Kojto 96:487b796308b0 431 * @arg UART_IT_TC: Transmission complete interrupt
Kojto 96:487b796308b0 432 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
Kojto 96:487b796308b0 433 * @arg UART_IT_IDLE: Idle line detection interrupt
Kojto 96:487b796308b0 434 * @arg UART_IT_PE: Parity Error interrupt
Kojto 96:487b796308b0 435 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
Kojto 96:487b796308b0 436 * @retval None
Kojto 96:487b796308b0 437 */
Kojto 96:487b796308b0 438 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \
Kojto 96:487b796308b0 439 (((__INTERRUPT__) >> 28) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & UART_IT_MASK)): \
Kojto 96:487b796308b0 440 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))
Kojto 96:487b796308b0 441
Kojto 96:487b796308b0 442
Kojto 96:487b796308b0 443 /** @brief Disable the specified UART interrupt.
Kojto 96:487b796308b0 444 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 445 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 446 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 447 * @param __INTERRUPT__: specifies the UART interrupt source to disable.
Kojto 96:487b796308b0 448 * This parameter can be one of the following values:
Kojto 96:487b796308b0 449 * @arg UART_IT_CTS: CTS change interrupt
Kojto 96:487b796308b0 450 * @arg UART_IT_LBD: LIN Break detection interrupt
Kojto 96:487b796308b0 451 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
Kojto 96:487b796308b0 452 * @arg UART_IT_TC: Transmission complete interrupt
Kojto 96:487b796308b0 453 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
Kojto 96:487b796308b0 454 * @arg UART_IT_IDLE: Idle line detection interrupt
Kojto 96:487b796308b0 455 * @arg UART_IT_PE: Parity Error interrupt
Kojto 96:487b796308b0 456 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
Kojto 96:487b796308b0 457 * @retval None
Kojto 96:487b796308b0 458 */
Kojto 96:487b796308b0 459 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
Kojto 96:487b796308b0 460 (((__INTERRUPT__) >> 28) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
Kojto 96:487b796308b0 461 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK)))
Kojto 96:487b796308b0 462
Kojto 96:487b796308b0 463 /** @brief Check whether the specified UART interrupt has occurred or not.
Kojto 96:487b796308b0 464 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 465 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 466 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 467 * @param __IT__: specifies the UART interrupt source to check.
Kojto 96:487b796308b0 468 * This parameter can be one of the following values:
Kojto 96:487b796308b0 469 * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
Kojto 96:487b796308b0 470 * @arg UART_IT_LBD: LIN Break detection interrupt
Kojto 96:487b796308b0 471 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
Kojto 96:487b796308b0 472 * @arg UART_IT_TC: Transmission complete interrupt
Kojto 96:487b796308b0 473 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
Kojto 96:487b796308b0 474 * @arg UART_IT_IDLE: Idle line detection interrupt
Kojto 96:487b796308b0 475 * @arg UART_IT_ERR: Error interrupt
Kojto 96:487b796308b0 476 * @retval The new state of __IT__ (TRUE or FALSE).
Kojto 96:487b796308b0 477 */
Kojto 96:487b796308b0 478 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28) == UART_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28) == UART_CR2_REG_INDEX)? \
Kojto 96:487b796308b0 479 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK))
Kojto 96:487b796308b0 480
Kojto 96:487b796308b0 481 /** @brief Enable CTS flow control
Kojto 96:487b796308b0 482 * This macro allows to enable CTS hardware flow control for a given UART instance,
Kojto 96:487b796308b0 483 * without need to call HAL_UART_Init() function.
Kojto 96:487b796308b0 484 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
Kojto 96:487b796308b0 485 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
Kojto 96:487b796308b0 486 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
Kojto 96:487b796308b0 487 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
Kojto 96:487b796308b0 488 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
Kojto 96:487b796308b0 489 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
Kojto 96:487b796308b0 490 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 491 * This parameter can be any USARTx (supporting the HW Flow control feature).
Kojto 96:487b796308b0 492 * It is used to select the USART peripheral (USART availability and x value depending on device).
Kojto 96:487b796308b0 493 * @retval None
Kojto 96:487b796308b0 494 */
Kojto 96:487b796308b0 495 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
Kojto 96:487b796308b0 496 do{ \
Kojto 96:487b796308b0 497 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
Kojto 96:487b796308b0 498 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
Kojto 96:487b796308b0 499 } while(0)
Kojto 96:487b796308b0 500
Kojto 96:487b796308b0 501 /** @brief Disable CTS flow control
Kojto 96:487b796308b0 502 * This macro allows to disable CTS hardware flow control for a given UART instance,
Kojto 96:487b796308b0 503 * without need to call HAL_UART_Init() function.
Kojto 96:487b796308b0 504 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
Kojto 96:487b796308b0 505 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
Kojto 96:487b796308b0 506 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
Kojto 96:487b796308b0 507 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
Kojto 96:487b796308b0 508 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
Kojto 96:487b796308b0 509 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
Kojto 96:487b796308b0 510 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 511 * This parameter can be any USARTx (supporting the HW Flow control feature).
Kojto 96:487b796308b0 512 * It is used to select the USART peripheral (USART availability and x value depending on device).
Kojto 96:487b796308b0 513 * @retval None
Kojto 96:487b796308b0 514 */
Kojto 96:487b796308b0 515 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
Kojto 96:487b796308b0 516 do{ \
Kojto 96:487b796308b0 517 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
Kojto 96:487b796308b0 518 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
Kojto 96:487b796308b0 519 } while(0)
Kojto 96:487b796308b0 520
Kojto 96:487b796308b0 521 /** @brief Enable RTS flow control
Kojto 96:487b796308b0 522 * This macro allows to enable RTS hardware flow control for a given UART instance,
Kojto 96:487b796308b0 523 * without need to call HAL_UART_Init() function.
Kojto 96:487b796308b0 524 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
Kojto 96:487b796308b0 525 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
Kojto 96:487b796308b0 526 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
Kojto 96:487b796308b0 527 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
Kojto 96:487b796308b0 528 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
Kojto 96:487b796308b0 529 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
Kojto 96:487b796308b0 530 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 531 * This parameter can be any USARTx (supporting the HW Flow control feature).
Kojto 96:487b796308b0 532 * It is used to select the USART peripheral (USART availability and x value depending on device).
Kojto 96:487b796308b0 533 * @retval None
Kojto 96:487b796308b0 534 */
Kojto 96:487b796308b0 535 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
Kojto 96:487b796308b0 536 do{ \
Kojto 96:487b796308b0 537 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
Kojto 96:487b796308b0 538 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
Kojto 96:487b796308b0 539 } while(0)
Kojto 96:487b796308b0 540
Kojto 96:487b796308b0 541 /** @brief Disable RTS flow control
Kojto 96:487b796308b0 542 * This macro allows to disable RTS hardware flow control for a given UART instance,
Kojto 96:487b796308b0 543 * without need to call HAL_UART_Init() function.
Kojto 96:487b796308b0 544 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
Kojto 96:487b796308b0 545 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
Kojto 96:487b796308b0 546 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
Kojto 96:487b796308b0 547 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
Kojto 96:487b796308b0 548 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
Kojto 96:487b796308b0 549 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
Kojto 96:487b796308b0 550 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 551 * This parameter can be any USARTx (supporting the HW Flow control feature).
Kojto 96:487b796308b0 552 * It is used to select the USART peripheral (USART availability and x value depending on device).
Kojto 96:487b796308b0 553 * @retval None
Kojto 96:487b796308b0 554 */
Kojto 96:487b796308b0 555 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
Kojto 96:487b796308b0 556 do{ \
Kojto 96:487b796308b0 557 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
Kojto 96:487b796308b0 558 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
Kojto 96:487b796308b0 559 } while(0)
Kojto 96:487b796308b0 560
Kojto 96:487b796308b0 561
Kojto 96:487b796308b0 562 /** @brief Enable UART
Kojto 96:487b796308b0 563 * @param __HANDLE__: specifies the UART Handle.
Kojto 96:487b796308b0 564 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 565 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 566 * @retval None
Kojto 96:487b796308b0 567 */
Kojto 96:487b796308b0 568 #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
Kojto 96:487b796308b0 569
Kojto 96:487b796308b0 570 /** @brief Disable UART
Kojto 96:487b796308b0 571 * UART Handle selects the USARTx or UARTy peripheral
Kojto 96:487b796308b0 572 * (USART,UART availability and x,y values depending on device).
Kojto 96:487b796308b0 573 * @retval None
Kojto 96:487b796308b0 574 */
Kojto 96:487b796308b0 575 #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
Kojto 96:487b796308b0 576
Kojto 96:487b796308b0 577 /**
Kojto 96:487b796308b0 578 * @}
Kojto 96:487b796308b0 579 */
Kojto 96:487b796308b0 580
Kojto 96:487b796308b0 581
Kojto 96:487b796308b0 582 /* Private macros --------------------------------------------------------*/
Kojto 96:487b796308b0 583 /** @defgroup UART_Private_Macros UART Private Macros
Kojto 96:487b796308b0 584 * @{
Kojto 96:487b796308b0 585 */
Kojto 96:487b796308b0 586
Kojto 96:487b796308b0 587 #define UART_CR1_REG_INDEX 1
Kojto 96:487b796308b0 588 #define UART_CR2_REG_INDEX 2
Kojto 96:487b796308b0 589 #define UART_CR3_REG_INDEX 3
Kojto 96:487b796308b0 590
Kojto 96:487b796308b0 591 #define UART_DIV_SAMPLING16(_PCLK_, _BAUD_) (((_PCLK_)*25)/(4*(_BAUD_)))
Kojto 96:487b796308b0 592 #define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_) (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100)
Kojto 96:487b796308b0 593 #define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_) (((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100)) * 16 + 50) / 100)
Kojto 96:487b796308b0 594 #define UART_BRR_SAMPLING16(_PCLK_, _BAUD_) ((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4)|(UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0F))
Kojto 96:487b796308b0 595
Kojto 96:487b796308b0 596 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
Kojto 96:487b796308b0 597 ((LENGTH) == UART_WORDLENGTH_9B))
Kojto 96:487b796308b0 598 #define IS_UART_LIN_WORD_LENGTH(LENGTH) ((LENGTH) == UART_WORDLENGTH_8B)
Kojto 96:487b796308b0 599
Kojto 96:487b796308b0 600 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
Kojto 96:487b796308b0 601 ((STOPBITS) == UART_STOPBITS_2))
Kojto 96:487b796308b0 602
Kojto 96:487b796308b0 603 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
Kojto 96:487b796308b0 604 ((PARITY) == UART_PARITY_EVEN) || \
Kojto 96:487b796308b0 605 ((PARITY) == UART_PARITY_ODD))
Kojto 96:487b796308b0 606
Kojto 96:487b796308b0 607 #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
Kojto 96:487b796308b0 608 (((CONTROL) == UART_HWCONTROL_NONE) || \
Kojto 96:487b796308b0 609 ((CONTROL) == UART_HWCONTROL_RTS) || \
Kojto 96:487b796308b0 610 ((CONTROL) == UART_HWCONTROL_CTS) || \
Kojto 96:487b796308b0 611 ((CONTROL) == UART_HWCONTROL_RTS_CTS))
Kojto 96:487b796308b0 612
Kojto 96:487b796308b0 613 #define IS_UART_MODE(MODE) ((((MODE) & (~((uint32_t)UART_MODE_TX_RX))) == 0x00) && \
Kojto 96:487b796308b0 614 ((MODE) != (uint32_t)0x00000000))
Kojto 96:487b796308b0 615
Kojto 96:487b796308b0 616 #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
Kojto 96:487b796308b0 617 ((STATE) == UART_STATE_ENABLE))
Kojto 96:487b796308b0 618
Kojto 96:487b796308b0 619 #define IS_UART_OVERSAMPLING(SAMPLING) ((SAMPLING) == UART_OVERSAMPLING_16)
Kojto 96:487b796308b0 620 #define IS_UART_LIN_OVERSAMPLING(SAMPLING) ((SAMPLING) == UART_OVERSAMPLING_16)
Kojto 96:487b796308b0 621
Kojto 96:487b796308b0 622 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
Kojto 96:487b796308b0 623 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
Kojto 96:487b796308b0 624
Kojto 96:487b796308b0 625 #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
Kojto 96:487b796308b0 626 ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
Kojto 96:487b796308b0 627
Kojto 96:487b796308b0 628
Kojto 96:487b796308b0 629 /** Check UART Baud rate
Kojto 96:487b796308b0 630 * __BAUDRATE__: Baudrate specified by the user
Kojto 96:487b796308b0 631 * The maximum Baud Rate is derived from the maximum clock on APB (i.e. 72 MHz)
Kojto 96:487b796308b0 632 * divided by the smallest oversampling used on the USART (i.e. 16)
Kojto 96:487b796308b0 633 * Retrun : TRUE or FALSE
Kojto 96:487b796308b0 634 */
Kojto 96:487b796308b0 635 #define IS_UART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 4500001)
Kojto 96:487b796308b0 636
Kojto 96:487b796308b0 637 /** Check UART Node Address
Kojto 96:487b796308b0 638 * __ADDRESS__: UART Node address specified by the user
Kojto 96:487b796308b0 639 * UART Node address is used in Multi processor communication for wakeup
Kojto 96:487b796308b0 640 * with address mark detection.
Kojto 96:487b796308b0 641 * This parameter must be a number between Min_Data = 0 and Max_Data = 15
Kojto 96:487b796308b0 642 * Return : TRUE or FALSE
Kojto 96:487b796308b0 643 */
Kojto 96:487b796308b0 644 #define IS_UART_ADDRESS(__ADDRESS__) ((__ADDRESS__) <= 0xF)
Kojto 96:487b796308b0 645
Kojto 96:487b796308b0 646 /** UART interruptions flag mask
Kojto 96:487b796308b0 647 */
Kojto 96:487b796308b0 648 #define UART_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
Kojto 96:487b796308b0 649 USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE )
Kojto 96:487b796308b0 650
Kojto 96:487b796308b0 651 /**
Kojto 96:487b796308b0 652 * @}
Kojto 96:487b796308b0 653 */
Kojto 96:487b796308b0 654
Kojto 96:487b796308b0 655 /* Exported functions --------------------------------------------------------*/
Kojto 96:487b796308b0 656
Kojto 96:487b796308b0 657 /** @addtogroup UART_Exported_Functions UART Exported Functions
Kojto 96:487b796308b0 658 * @{
Kojto 96:487b796308b0 659 */
Kojto 96:487b796308b0 660
Kojto 96:487b796308b0 661 /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
Kojto 96:487b796308b0 662 * @{
Kojto 96:487b796308b0 663 */
Kojto 96:487b796308b0 664
Kojto 96:487b796308b0 665 /* Initialization and de-initialization functions ****************************/
Kojto 96:487b796308b0 666 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 667 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 668 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
Kojto 96:487b796308b0 669 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
Kojto 96:487b796308b0 670 HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 671 void HAL_UART_MspInit(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 672 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 673
Kojto 96:487b796308b0 674 /**
Kojto 96:487b796308b0 675 * @}
Kojto 96:487b796308b0 676 */
Kojto 96:487b796308b0 677
Kojto 96:487b796308b0 678 /** @addtogroup UART_Exported_Functions_Group2 IO operation functions
Kojto 96:487b796308b0 679 * @{
Kojto 96:487b796308b0 680 */
Kojto 96:487b796308b0 681
Kojto 96:487b796308b0 682 /* IO operation functions *****************************************************/
Kojto 96:487b796308b0 683 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
Kojto 96:487b796308b0 684 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
Kojto 96:487b796308b0 685 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
Kojto 96:487b796308b0 686 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
Kojto 96:487b796308b0 687 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
Kojto 96:487b796308b0 688 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
Kojto 96:487b796308b0 689 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 690 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 691 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 692 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 693 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 694 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 695 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 696 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 697 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 698
Kojto 96:487b796308b0 699 /**
Kojto 96:487b796308b0 700 * @}
Kojto 96:487b796308b0 701 */
Kojto 96:487b796308b0 702
Kojto 96:487b796308b0 703 /** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions
Kojto 96:487b796308b0 704 * @{
Kojto 96:487b796308b0 705 */
Kojto 96:487b796308b0 706
Kojto 96:487b796308b0 707 /* Peripheral Control functions ************************************************/
Kojto 96:487b796308b0 708 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 709 HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 710 HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 711 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 712 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 713
Kojto 96:487b796308b0 714 /**
Kojto 96:487b796308b0 715 * @}
Kojto 96:487b796308b0 716 */
Kojto 96:487b796308b0 717
Kojto 96:487b796308b0 718 /** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Errors functions
Kojto 96:487b796308b0 719 * @{
Kojto 96:487b796308b0 720 */
Kojto 96:487b796308b0 721
Kojto 96:487b796308b0 722 /* Peripheral State and Errors functions **************************************************/
Kojto 96:487b796308b0 723 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 724 uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
Kojto 96:487b796308b0 725
Kojto 96:487b796308b0 726 /**
Kojto 96:487b796308b0 727 * @}
Kojto 96:487b796308b0 728 */
Kojto 96:487b796308b0 729
Kojto 96:487b796308b0 730 /**
Kojto 96:487b796308b0 731 * @}
Kojto 96:487b796308b0 732 */
Kojto 96:487b796308b0 733
Kojto 96:487b796308b0 734 /**
Kojto 96:487b796308b0 735 * @}
Kojto 96:487b796308b0 736 */
Kojto 96:487b796308b0 737
Kojto 96:487b796308b0 738 /**
Kojto 96:487b796308b0 739 * @}
Kojto 96:487b796308b0 740 */
Kojto 96:487b796308b0 741
Kojto 96:487b796308b0 742 #ifdef __cplusplus
Kojto 96:487b796308b0 743 }
Kojto 96:487b796308b0 744 #endif
Kojto 96:487b796308b0 745
Kojto 96:487b796308b0 746 #endif /* __STM32F1xx_HAL_UART_H */
Kojto 96:487b796308b0 747
Kojto 96:487b796308b0 748 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/