mbed(SerialHalfDuplex入り)

Fork of mbed by mbed official

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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 93:e188a91d3eaa 1 /**
Kojto 93:e188a91d3eaa 2 ******************************************************************************
Kojto 93:e188a91d3eaa 3 * @file stm32f4xx_hal_uart.h
Kojto 93:e188a91d3eaa 4 * @author MCD Application Team
Kojto 93:e188a91d3eaa 5 * @version V1.1.0
Kojto 93:e188a91d3eaa 6 * @date 19-June-2014
Kojto 93:e188a91d3eaa 7 * @brief Header file of UART HAL module.
Kojto 93:e188a91d3eaa 8 ******************************************************************************
Kojto 93:e188a91d3eaa 9 * @attention
Kojto 93:e188a91d3eaa 10 *
Kojto 93:e188a91d3eaa 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Kojto 93:e188a91d3eaa 12 *
Kojto 93:e188a91d3eaa 13 * Redistribution and use in source and binary forms, with or without modification,
Kojto 93:e188a91d3eaa 14 * are permitted provided that the following conditions are met:
Kojto 93:e188a91d3eaa 15 * 1. Redistributions of source code must retain the above copyright notice,
Kojto 93:e188a91d3eaa 16 * this list of conditions and the following disclaimer.
Kojto 93:e188a91d3eaa 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Kojto 93:e188a91d3eaa 18 * this list of conditions and the following disclaimer in the documentation
Kojto 93:e188a91d3eaa 19 * and/or other materials provided with the distribution.
Kojto 93:e188a91d3eaa 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Kojto 93:e188a91d3eaa 21 * may be used to endorse or promote products derived from this software
Kojto 93:e188a91d3eaa 22 * without specific prior written permission.
Kojto 93:e188a91d3eaa 23 *
Kojto 93:e188a91d3eaa 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Kojto 93:e188a91d3eaa 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Kojto 93:e188a91d3eaa 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 93:e188a91d3eaa 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Kojto 93:e188a91d3eaa 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Kojto 93:e188a91d3eaa 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Kojto 93:e188a91d3eaa 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Kojto 93:e188a91d3eaa 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Kojto 93:e188a91d3eaa 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 93:e188a91d3eaa 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 93:e188a91d3eaa 34 *
Kojto 93:e188a91d3eaa 35 ******************************************************************************
Kojto 93:e188a91d3eaa 36 */
Kojto 93:e188a91d3eaa 37
Kojto 93:e188a91d3eaa 38 /* Define to prevent recursive inclusion -------------------------------------*/
Kojto 93:e188a91d3eaa 39 #ifndef __STM32F4xx_HAL_UART_H
Kojto 93:e188a91d3eaa 40 #define __STM32F4xx_HAL_UART_H
Kojto 93:e188a91d3eaa 41
Kojto 93:e188a91d3eaa 42 #ifdef __cplusplus
Kojto 93:e188a91d3eaa 43 extern "C" {
Kojto 93:e188a91d3eaa 44 #endif
Kojto 93:e188a91d3eaa 45
Kojto 93:e188a91d3eaa 46 /* Includes ------------------------------------------------------------------*/
Kojto 93:e188a91d3eaa 47 #include "stm32f4xx_hal_def.h"
Kojto 93:e188a91d3eaa 48
Kojto 93:e188a91d3eaa 49 /** @addtogroup STM32F4xx_HAL_Driver
Kojto 93:e188a91d3eaa 50 * @{
Kojto 93:e188a91d3eaa 51 */
Kojto 93:e188a91d3eaa 52
Kojto 93:e188a91d3eaa 53 /** @addtogroup UART
Kojto 93:e188a91d3eaa 54 * @{
Kojto 93:e188a91d3eaa 55 */
Kojto 93:e188a91d3eaa 56
Kojto 93:e188a91d3eaa 57 /* Exported types ------------------------------------------------------------*/
Kojto 93:e188a91d3eaa 58
Kojto 93:e188a91d3eaa 59 /**
Kojto 93:e188a91d3eaa 60 * @brief UART Init Structure definition
Kojto 93:e188a91d3eaa 61 */
Kojto 93:e188a91d3eaa 62 typedef struct
Kojto 93:e188a91d3eaa 63 {
Kojto 93:e188a91d3eaa 64 uint32_t BaudRate; /*!< This member configures the UART communication baud rate.
Kojto 93:e188a91d3eaa 65 The baud rate is computed using the following formula:
Kojto 93:e188a91d3eaa 66 - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (huart->Init.BaudRate)))
Kojto 93:e188a91d3eaa 67 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8 * (OVR8+1)) + 0.5
Kojto 93:e188a91d3eaa 68 Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */
Kojto 93:e188a91d3eaa 69
Kojto 93:e188a91d3eaa 70 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
Kojto 93:e188a91d3eaa 71 This parameter can be a value of @ref UART_Word_Length */
Kojto 93:e188a91d3eaa 72
Kojto 93:e188a91d3eaa 73 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
Kojto 93:e188a91d3eaa 74 This parameter can be a value of @ref UART_Stop_Bits */
Kojto 93:e188a91d3eaa 75
Kojto 93:e188a91d3eaa 76 uint32_t Parity; /*!< Specifies the parity mode.
Kojto 93:e188a91d3eaa 77 This parameter can be a value of @ref UART_Parity
Kojto 93:e188a91d3eaa 78 @note When parity is enabled, the computed parity is inserted
Kojto 93:e188a91d3eaa 79 at the MSB position of the transmitted data (9th bit when
Kojto 93:e188a91d3eaa 80 the word length is set to 9 data bits; 8th bit when the
Kojto 93:e188a91d3eaa 81 word length is set to 8 data bits). */
Kojto 93:e188a91d3eaa 82
Kojto 93:e188a91d3eaa 83 uint32_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
Kojto 93:e188a91d3eaa 84 This parameter can be a value of @ref UART_Mode */
Kojto 93:e188a91d3eaa 85
Kojto 93:e188a91d3eaa 86 uint32_t HwFlowCtl; /*!< Specifies wether the hardware flow control mode is enabled
Kojto 93:e188a91d3eaa 87 or disabled.
Kojto 93:e188a91d3eaa 88 This parameter can be a value of @ref UART_Hardware_Flow_Control */
Kojto 93:e188a91d3eaa 89
Kojto 93:e188a91d3eaa 90 uint32_t OverSampling; /*!< Specifies wether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
Kojto 93:e188a91d3eaa 91 This parameter can be a value of @ref UART_Over_Sampling */
Kojto 93:e188a91d3eaa 92 }UART_InitTypeDef;
Kojto 93:e188a91d3eaa 93
Kojto 93:e188a91d3eaa 94 /**
Kojto 93:e188a91d3eaa 95 * @brief HAL UART State structures definition
Kojto 93:e188a91d3eaa 96 */
Kojto 93:e188a91d3eaa 97 typedef enum
Kojto 93:e188a91d3eaa 98 {
Kojto 93:e188a91d3eaa 99 HAL_UART_STATE_RESET = 0x00, /*!< Peripheral is not yet Initialized */
Kojto 93:e188a91d3eaa 100 HAL_UART_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
Kojto 93:e188a91d3eaa 101 HAL_UART_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
Kojto 93:e188a91d3eaa 102 HAL_UART_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
Kojto 93:e188a91d3eaa 103 HAL_UART_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
Kojto 93:e188a91d3eaa 104 HAL_UART_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
Kojto 93:e188a91d3eaa 105 HAL_UART_STATE_TIMEOUT = 0x03, /*!< Timeout state */
Kojto 93:e188a91d3eaa 106 HAL_UART_STATE_ERROR = 0x04 /*!< Error */
Kojto 93:e188a91d3eaa 107 }HAL_UART_StateTypeDef;
Kojto 93:e188a91d3eaa 108
Kojto 93:e188a91d3eaa 109 /**
Kojto 93:e188a91d3eaa 110 * @brief HAL UART Error Code structure definition
Kojto 93:e188a91d3eaa 111 */
Kojto 93:e188a91d3eaa 112 typedef enum
Kojto 93:e188a91d3eaa 113 {
Kojto 93:e188a91d3eaa 114 HAL_UART_ERROR_NONE = 0x00, /*!< No error */
Kojto 93:e188a91d3eaa 115 HAL_UART_ERROR_PE = 0x01, /*!< Parity error */
Kojto 93:e188a91d3eaa 116 HAL_UART_ERROR_NE = 0x02, /*!< Noise error */
Kojto 93:e188a91d3eaa 117 HAL_UART_ERROR_FE = 0x04, /*!< frame error */
Kojto 93:e188a91d3eaa 118 HAL_UART_ERROR_ORE = 0x08, /*!< Overrun error */
Kojto 93:e188a91d3eaa 119 HAL_UART_ERROR_DMA = 0x10 /*!< DMA transfer error */
Kojto 93:e188a91d3eaa 120 }HAL_UART_ErrorTypeDef;
Kojto 93:e188a91d3eaa 121
Kojto 93:e188a91d3eaa 122 /**
Kojto 93:e188a91d3eaa 123 * @brief UART handle Structure definition
Kojto 93:e188a91d3eaa 124 */
Kojto 93:e188a91d3eaa 125 typedef struct
Kojto 93:e188a91d3eaa 126 {
Kojto 93:e188a91d3eaa 127 USART_TypeDef *Instance; /* UART registers base address */
Kojto 93:e188a91d3eaa 128
Kojto 93:e188a91d3eaa 129 UART_InitTypeDef Init; /* UART communication parameters */
Kojto 93:e188a91d3eaa 130
Kojto 93:e188a91d3eaa 131 uint8_t *pTxBuffPtr; /* Pointer to UART Tx transfer Buffer */
Kojto 93:e188a91d3eaa 132
Kojto 93:e188a91d3eaa 133 uint16_t TxXferSize; /* UART Tx Transfer size */
Kojto 93:e188a91d3eaa 134
Kojto 93:e188a91d3eaa 135 uint16_t TxXferCount; /* UART Tx Transfer Counter */
Kojto 93:e188a91d3eaa 136
Kojto 93:e188a91d3eaa 137 uint8_t *pRxBuffPtr; /* Pointer to UART Rx transfer Buffer */
Kojto 93:e188a91d3eaa 138
Kojto 93:e188a91d3eaa 139 uint16_t RxXferSize; /* UART Rx Transfer size */
Kojto 93:e188a91d3eaa 140
Kojto 93:e188a91d3eaa 141 uint16_t RxXferCount; /* UART Rx Transfer Counter */
Kojto 93:e188a91d3eaa 142
Kojto 93:e188a91d3eaa 143 DMA_HandleTypeDef *hdmatx; /* UART Tx DMA Handle parameters */
Kojto 93:e188a91d3eaa 144
Kojto 93:e188a91d3eaa 145 DMA_HandleTypeDef *hdmarx; /* UART Rx DMA Handle parameters */
Kojto 93:e188a91d3eaa 146
Kojto 93:e188a91d3eaa 147 HAL_LockTypeDef Lock; /* Locking object */
Kojto 93:e188a91d3eaa 148
Kojto 93:e188a91d3eaa 149 __IO HAL_UART_StateTypeDef State; /* UART communication state */
Kojto 93:e188a91d3eaa 150
Kojto 93:e188a91d3eaa 151 __IO HAL_UART_ErrorTypeDef ErrorCode; /* UART Error code */
Kojto 93:e188a91d3eaa 152
Kojto 93:e188a91d3eaa 153 }UART_HandleTypeDef;
Kojto 93:e188a91d3eaa 154
Kojto 93:e188a91d3eaa 155 /* Exported constants --------------------------------------------------------*/
Kojto 93:e188a91d3eaa 156 /** @defgroup UART_Exported_Constants
Kojto 93:e188a91d3eaa 157 * @{
Kojto 93:e188a91d3eaa 158 */
Kojto 93:e188a91d3eaa 159
Kojto 93:e188a91d3eaa 160 /** @defgroup UART_Word_Length
Kojto 93:e188a91d3eaa 161 * @{
Kojto 93:e188a91d3eaa 162 */
Kojto 93:e188a91d3eaa 163 #define UART_WORDLENGTH_8B ((uint32_t)0x00000000)
Kojto 93:e188a91d3eaa 164 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
Kojto 93:e188a91d3eaa 165 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
Kojto 93:e188a91d3eaa 166 ((LENGTH) == UART_WORDLENGTH_9B))
Kojto 93:e188a91d3eaa 167 /**
Kojto 93:e188a91d3eaa 168 * @}
Kojto 93:e188a91d3eaa 169 */
Kojto 93:e188a91d3eaa 170
Kojto 93:e188a91d3eaa 171 /** @defgroup UART_Stop_Bits
Kojto 93:e188a91d3eaa 172 * @{
Kojto 93:e188a91d3eaa 173 */
Kojto 93:e188a91d3eaa 174 #define UART_STOPBITS_1 ((uint32_t)0x00000000)
Kojto 93:e188a91d3eaa 175 #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
Kojto 93:e188a91d3eaa 176 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
Kojto 93:e188a91d3eaa 177 ((STOPBITS) == UART_STOPBITS_2))
Kojto 93:e188a91d3eaa 178 /**
Kojto 93:e188a91d3eaa 179 * @}
Kojto 93:e188a91d3eaa 180 */
Kojto 93:e188a91d3eaa 181
Kojto 93:e188a91d3eaa 182 /** @defgroup UART_Parity
Kojto 93:e188a91d3eaa 183 * @{
Kojto 93:e188a91d3eaa 184 */
Kojto 93:e188a91d3eaa 185 #define UART_PARITY_NONE ((uint32_t)0x00000000)
Kojto 93:e188a91d3eaa 186 #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
Kojto 93:e188a91d3eaa 187 #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
Kojto 93:e188a91d3eaa 188 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
Kojto 93:e188a91d3eaa 189 ((PARITY) == UART_PARITY_EVEN) || \
Kojto 93:e188a91d3eaa 190 ((PARITY) == UART_PARITY_ODD))
Kojto 93:e188a91d3eaa 191 /**
Kojto 93:e188a91d3eaa 192 * @}
Kojto 93:e188a91d3eaa 193 */
Kojto 93:e188a91d3eaa 194
Kojto 93:e188a91d3eaa 195 /** @defgroup UART_Hardware_Flow_Control
Kojto 93:e188a91d3eaa 196 * @{
Kojto 93:e188a91d3eaa 197 */
Kojto 93:e188a91d3eaa 198 #define UART_HWCONTROL_NONE ((uint32_t)0x00000000)
Kojto 93:e188a91d3eaa 199 #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE)
Kojto 93:e188a91d3eaa 200 #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE)
Kojto 93:e188a91d3eaa 201 #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
Kojto 93:e188a91d3eaa 202 #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
Kojto 93:e188a91d3eaa 203 (((CONTROL) == UART_HWCONTROL_NONE) || \
Kojto 93:e188a91d3eaa 204 ((CONTROL) == UART_HWCONTROL_RTS) || \
Kojto 93:e188a91d3eaa 205 ((CONTROL) == UART_HWCONTROL_CTS) || \
Kojto 93:e188a91d3eaa 206 ((CONTROL) == UART_HWCONTROL_RTS_CTS))
Kojto 93:e188a91d3eaa 207 /**
Kojto 93:e188a91d3eaa 208 * @}
Kojto 93:e188a91d3eaa 209 */
Kojto 93:e188a91d3eaa 210
Kojto 93:e188a91d3eaa 211 /** @defgroup UART_Mode
Kojto 93:e188a91d3eaa 212 * @{
Kojto 93:e188a91d3eaa 213 */
Kojto 93:e188a91d3eaa 214 #define UART_MODE_RX ((uint32_t)USART_CR1_RE)
Kojto 93:e188a91d3eaa 215 #define UART_MODE_TX ((uint32_t)USART_CR1_TE)
Kojto 93:e188a91d3eaa 216 #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
Kojto 93:e188a91d3eaa 217 #define IS_UART_MODE(MODE) ((((MODE) & (uint32_t)0x0000FFF3) == 0x00) && ((MODE) != (uint32_t)0x000000))
Kojto 93:e188a91d3eaa 218 /**
Kojto 93:e188a91d3eaa 219 * @}
Kojto 93:e188a91d3eaa 220 */
Kojto 93:e188a91d3eaa 221
Kojto 93:e188a91d3eaa 222 /** @defgroup UART_State
Kojto 93:e188a91d3eaa 223 * @{
Kojto 93:e188a91d3eaa 224 */
Kojto 93:e188a91d3eaa 225 #define UART_STATE_DISABLE ((uint32_t)0x00000000)
Kojto 93:e188a91d3eaa 226 #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE)
Kojto 93:e188a91d3eaa 227 #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
Kojto 93:e188a91d3eaa 228 ((STATE) == UART_STATE_ENABLE))
Kojto 93:e188a91d3eaa 229 /**
Kojto 93:e188a91d3eaa 230 * @}
Kojto 93:e188a91d3eaa 231 */
Kojto 93:e188a91d3eaa 232
Kojto 93:e188a91d3eaa 233 /** @defgroup UART_Over_Sampling
Kojto 93:e188a91d3eaa 234 * @{
Kojto 93:e188a91d3eaa 235 */
Kojto 93:e188a91d3eaa 236 #define UART_OVERSAMPLING_16 ((uint32_t)0x00000000)
Kojto 93:e188a91d3eaa 237 #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8)
Kojto 93:e188a91d3eaa 238 #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
Kojto 93:e188a91d3eaa 239 ((SAMPLING) == UART_OVERSAMPLING_8))
Kojto 93:e188a91d3eaa 240 /**
Kojto 93:e188a91d3eaa 241 * @}
Kojto 93:e188a91d3eaa 242 */
Kojto 93:e188a91d3eaa 243
Kojto 93:e188a91d3eaa 244 /** @defgroup UART_LIN_Break_Detection_Length
Kojto 93:e188a91d3eaa 245 * @{
Kojto 93:e188a91d3eaa 246 */
Kojto 93:e188a91d3eaa 247 #define UART_LINBREAKDETECTLENGTH_10B ((uint32_t)0x00000000)
Kojto 93:e188a91d3eaa 248 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)0x00000020)
Kojto 93:e188a91d3eaa 249 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
Kojto 93:e188a91d3eaa 250 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
Kojto 93:e188a91d3eaa 251 /**
Kojto 93:e188a91d3eaa 252 * @}
Kojto 93:e188a91d3eaa 253 */
Kojto 93:e188a91d3eaa 254
Kojto 93:e188a91d3eaa 255 /** @defgroup UART_WakeUp_functions
Kojto 93:e188a91d3eaa 256 * @{
Kojto 93:e188a91d3eaa 257 */
Kojto 93:e188a91d3eaa 258 #define UART_WAKEUPMETHODE_IDLELINE ((uint32_t)0x00000000)
Kojto 93:e188a91d3eaa 259 #define UART_WAKEUPMETHODE_ADDRESSMARK ((uint32_t)0x00000800)
Kojto 93:e188a91d3eaa 260 #define IS_UART_WAKEUPMETHODE(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHODE_IDLELINE) || \
Kojto 93:e188a91d3eaa 261 ((WAKEUP) == UART_WAKEUPMETHODE_ADDRESSMARK))
Kojto 93:e188a91d3eaa 262 /**
Kojto 93:e188a91d3eaa 263 * @}
Kojto 93:e188a91d3eaa 264 */
Kojto 93:e188a91d3eaa 265
Kojto 93:e188a91d3eaa 266 /** @defgroup UART_Flags
Kojto 93:e188a91d3eaa 267 * Elements values convention: 0xXXXX
Kojto 93:e188a91d3eaa 268 * - 0xXXXX : Flag mask in the SR register
Kojto 93:e188a91d3eaa 269 * @{
Kojto 93:e188a91d3eaa 270 */
Kojto 93:e188a91d3eaa 271 #define UART_FLAG_CTS ((uint32_t)0x00000200)
Kojto 93:e188a91d3eaa 272 #define UART_FLAG_LBD ((uint32_t)0x00000100)
Kojto 93:e188a91d3eaa 273 #define UART_FLAG_TXE ((uint32_t)0x00000080)
Kojto 93:e188a91d3eaa 274 #define UART_FLAG_TC ((uint32_t)0x00000040)
Kojto 93:e188a91d3eaa 275 #define UART_FLAG_RXNE ((uint32_t)0x00000020)
Kojto 93:e188a91d3eaa 276 #define UART_FLAG_IDLE ((uint32_t)0x00000010)
Kojto 93:e188a91d3eaa 277 #define UART_FLAG_ORE ((uint32_t)0x00000008)
Kojto 93:e188a91d3eaa 278 #define UART_FLAG_NE ((uint32_t)0x00000004)
Kojto 93:e188a91d3eaa 279 #define UART_FLAG_FE ((uint32_t)0x00000002)
Kojto 93:e188a91d3eaa 280 #define UART_FLAG_PE ((uint32_t)0x00000001)
Kojto 93:e188a91d3eaa 281 /**
Kojto 93:e188a91d3eaa 282 * @}
Kojto 93:e188a91d3eaa 283 */
Kojto 93:e188a91d3eaa 284
Kojto 93:e188a91d3eaa 285 /** @defgroup UART_Interrupt_definition
Kojto 93:e188a91d3eaa 286 * Elements values convention: 0xY000XXXX
Kojto 93:e188a91d3eaa 287 * - XXXX : Interrupt mask in the XX register
Kojto 93:e188a91d3eaa 288 * - Y : Interrupt source register (2bits)
Kojto 93:e188a91d3eaa 289 * - 01: CR1 register
Kojto 93:e188a91d3eaa 290 * - 10: CR2 register
Kojto 93:e188a91d3eaa 291 * - 11: CR3 register
Kojto 93:e188a91d3eaa 292 *
Kojto 93:e188a91d3eaa 293 * @{
Kojto 93:e188a91d3eaa 294 */
Kojto 93:e188a91d3eaa 295 #define UART_IT_PE ((uint32_t)0x10000100)
Kojto 93:e188a91d3eaa 296 #define UART_IT_TXE ((uint32_t)0x10000080)
Kojto 93:e188a91d3eaa 297 #define UART_IT_TC ((uint32_t)0x10000040)
Kojto 93:e188a91d3eaa 298 #define UART_IT_RXNE ((uint32_t)0x10000020)
Kojto 93:e188a91d3eaa 299 #define UART_IT_IDLE ((uint32_t)0x10000010)
Kojto 93:e188a91d3eaa 300
Kojto 93:e188a91d3eaa 301 #define UART_IT_LBD ((uint32_t)0x20000040)
Kojto 93:e188a91d3eaa 302 #define UART_IT_CTS ((uint32_t)0x30000400)
Kojto 93:e188a91d3eaa 303
Kojto 93:e188a91d3eaa 304 #define UART_IT_ERR ((uint32_t)0x30000001)
Kojto 93:e188a91d3eaa 305
Kojto 93:e188a91d3eaa 306 /**
Kojto 93:e188a91d3eaa 307 * @}
Kojto 93:e188a91d3eaa 308 */
Kojto 93:e188a91d3eaa 309
Kojto 93:e188a91d3eaa 310 /**
Kojto 93:e188a91d3eaa 311 * @}
Kojto 93:e188a91d3eaa 312 */
Kojto 93:e188a91d3eaa 313
Kojto 93:e188a91d3eaa 314 /* Exported macro ------------------------------------------------------------*/
Kojto 93:e188a91d3eaa 315
Kojto 93:e188a91d3eaa 316 /** @brief Reset UART handle state
Kojto 93:e188a91d3eaa 317 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 318 * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 93:e188a91d3eaa 319 * UART peripheral.
Kojto 93:e188a91d3eaa 320 * @retval None
Kojto 93:e188a91d3eaa 321 */
Kojto 93:e188a91d3eaa 322 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_UART_STATE_RESET)
Kojto 93:e188a91d3eaa 323
Kojto 93:e188a91d3eaa 324 /** @brief Flushs the UART DR register
Kojto 93:e188a91d3eaa 325 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 326 */
Kojto 93:e188a91d3eaa 327 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
Kojto 93:e188a91d3eaa 328
Kojto 93:e188a91d3eaa 329 /** @brief Checks whether the specified UART flag is set or not.
Kojto 93:e188a91d3eaa 330 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 331 * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 93:e188a91d3eaa 332 * UART peripheral.
Kojto 93:e188a91d3eaa 333 * @param __FLAG__: specifies the flag to check.
Kojto 93:e188a91d3eaa 334 * This parameter can be one of the following values:
Kojto 93:e188a91d3eaa 335 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
Kojto 93:e188a91d3eaa 336 * @arg UART_FLAG_LBD: LIN Break detection flag
Kojto 93:e188a91d3eaa 337 * @arg UART_FLAG_TXE: Transmit data register empty flag
Kojto 93:e188a91d3eaa 338 * @arg UART_FLAG_TC: Transmission Complete flag
Kojto 93:e188a91d3eaa 339 * @arg UART_FLAG_RXNE: Receive data register not empty flag
Kojto 93:e188a91d3eaa 340 * @arg UART_FLAG_IDLE: Idle Line detection flag
Kojto 93:e188a91d3eaa 341 * @arg UART_FLAG_ORE: OverRun Error flag
Kojto 93:e188a91d3eaa 342 * @arg UART_FLAG_NE: Noise Error flag
Kojto 93:e188a91d3eaa 343 * @arg UART_FLAG_FE: Framing Error flag
Kojto 93:e188a91d3eaa 344 * @arg UART_FLAG_PE: Parity Error flag
Kojto 93:e188a91d3eaa 345 * @retval The new state of __FLAG__ (TRUE or FALSE).
Kojto 93:e188a91d3eaa 346 */
Kojto 93:e188a91d3eaa 347
Kojto 93:e188a91d3eaa 348 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
Kojto 93:e188a91d3eaa 349
Kojto 93:e188a91d3eaa 350 /** @brief Clears the specified UART pending flag.
Kojto 93:e188a91d3eaa 351 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 352 * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 93:e188a91d3eaa 353 * UART peripheral.
Kojto 93:e188a91d3eaa 354 * @param __FLAG__: specifies the flag to check.
Kojto 93:e188a91d3eaa 355 * This parameter can be any combination of the following values:
Kojto 93:e188a91d3eaa 356 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5).
Kojto 93:e188a91d3eaa 357 * @arg UART_FLAG_LBD: LIN Break detection flag.
Kojto 93:e188a91d3eaa 358 * @arg UART_FLAG_TC: Transmission Complete flag.
Kojto 93:e188a91d3eaa 359 * @arg UART_FLAG_RXNE: Receive data register not empty flag.
Kojto 93:e188a91d3eaa 360 *
Kojto 93:e188a91d3eaa 361 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
Kojto 93:e188a91d3eaa 362 * error) and IDLE (Idle line detected) flags are cleared by software
Kojto 93:e188a91d3eaa 363 * sequence: a read operation to USART_SR register followed by a read
Kojto 93:e188a91d3eaa 364 * operation to USART_DR register.
Kojto 93:e188a91d3eaa 365 * @note RXNE flag can be also cleared by a read to the USART_DR register.
Kojto 93:e188a91d3eaa 366 * @note TC flag can be also cleared by software sequence: a read operation to
Kojto 93:e188a91d3eaa 367 * USART_SR register followed by a write operation to USART_DR register.
Kojto 93:e188a91d3eaa 368 * @note TXE flag is cleared only by a write to the USART_DR register.
Kojto 93:e188a91d3eaa 369 *
Kojto 93:e188a91d3eaa 370 * @retval None
Kojto 93:e188a91d3eaa 371 */
Kojto 93:e188a91d3eaa 372 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
Kojto 93:e188a91d3eaa 373
Kojto 93:e188a91d3eaa 374 /** @brief Clear the UART PE pending flag.
Kojto 93:e188a91d3eaa 375 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 376 * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 93:e188a91d3eaa 377 * UART peripheral.
Kojto 93:e188a91d3eaa 378 * @retval None
Kojto 93:e188a91d3eaa 379 */
Kojto 93:e188a91d3eaa 380 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) do{(__HANDLE__)->Instance->SR;\
Kojto 93:e188a91d3eaa 381 (__HANDLE__)->Instance->DR;}while(0)
Kojto 93:e188a91d3eaa 382 /** @brief Clear the UART FE pending flag.
Kojto 93:e188a91d3eaa 383 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 384 * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 93:e188a91d3eaa 385 * UART peripheral.
Kojto 93:e188a91d3eaa 386 * @retval None
Kojto 93:e188a91d3eaa 387 */
Kojto 93:e188a91d3eaa 388 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
Kojto 93:e188a91d3eaa 389
Kojto 93:e188a91d3eaa 390 /** @brief Clear the UART NE pending flag.
Kojto 93:e188a91d3eaa 391 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 392 * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 93:e188a91d3eaa 393 * UART peripheral.
Kojto 93:e188a91d3eaa 394 * @retval None
Kojto 93:e188a91d3eaa 395 */
Kojto 93:e188a91d3eaa 396 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
Kojto 93:e188a91d3eaa 397
Kojto 93:e188a91d3eaa 398 /** @brief Clear the UART ORE pending flag.
Kojto 93:e188a91d3eaa 399 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 400 * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 93:e188a91d3eaa 401 * UART peripheral.
Kojto 93:e188a91d3eaa 402 * @retval None
Kojto 93:e188a91d3eaa 403 */
Kojto 93:e188a91d3eaa 404 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
Kojto 93:e188a91d3eaa 405
Kojto 93:e188a91d3eaa 406 /** @brief Clear the UART IDLE pending flag.
Kojto 93:e188a91d3eaa 407 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 408 * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 93:e188a91d3eaa 409 * UART peripheral.
Kojto 93:e188a91d3eaa 410 * @retval None
Kojto 93:e188a91d3eaa 411 */
Kojto 93:e188a91d3eaa 412 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
Kojto 93:e188a91d3eaa 413
Kojto 93:e188a91d3eaa 414 /** @brief Enables or disables the specified UART interrupt.
Kojto 93:e188a91d3eaa 415 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 416 * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 93:e188a91d3eaa 417 * UART peripheral.
Kojto 93:e188a91d3eaa 418 * @param __INTERRUPT__: specifies the UART interrupt source to check.
Kojto 93:e188a91d3eaa 419 * This parameter can be one of the following values:
Kojto 93:e188a91d3eaa 420 * @arg UART_IT_CTS: CTS change interrupt
Kojto 93:e188a91d3eaa 421 * @arg UART_IT_LBD: LIN Break detection interrupt
Kojto 93:e188a91d3eaa 422 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
Kojto 93:e188a91d3eaa 423 * @arg UART_IT_TC: Transmission complete interrupt
Kojto 93:e188a91d3eaa 424 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
Kojto 93:e188a91d3eaa 425 * @arg UART_IT_IDLE: Idle line detection interrupt
Kojto 93:e188a91d3eaa 426 * @arg UART_IT_PE: Parity Error interrupt
Kojto 93:e188a91d3eaa 427 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
Kojto 93:e188a91d3eaa 428 * @param NewState: new state of the specified UART interrupt.
Kojto 93:e188a91d3eaa 429 * This parameter can be: ENABLE or DISABLE.
Kojto 93:e188a91d3eaa 430 * @retval None
Kojto 93:e188a91d3eaa 431 */
Kojto 93:e188a91d3eaa 432 #define UART_IT_MASK ((uint32_t)0x0000FFFF)
Kojto 93:e188a91d3eaa 433 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \
Kojto 93:e188a91d3eaa 434 (((__INTERRUPT__) >> 28) == 2)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & UART_IT_MASK)): \
Kojto 93:e188a91d3eaa 435 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))
Kojto 93:e188a91d3eaa 436 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
Kojto 93:e188a91d3eaa 437 (((__INTERRUPT__) >> 28) == 2)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
Kojto 93:e188a91d3eaa 438 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK)))
Kojto 93:e188a91d3eaa 439
Kojto 93:e188a91d3eaa 440 /** @brief Checks whether the specified UART interrupt has occurred or not.
Kojto 93:e188a91d3eaa 441 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 442 * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
Kojto 93:e188a91d3eaa 443 * UART peripheral.
Kojto 93:e188a91d3eaa 444 * @param __IT__: specifies the UART interrupt source to check.
Kojto 93:e188a91d3eaa 445 * This parameter can be one of the following values:
Kojto 93:e188a91d3eaa 446 * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
Kojto 93:e188a91d3eaa 447 * @arg UART_IT_LBD: LIN Break detection interrupt
Kojto 93:e188a91d3eaa 448 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
Kojto 93:e188a91d3eaa 449 * @arg UART_IT_TC: Transmission complete interrupt
Kojto 93:e188a91d3eaa 450 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
Kojto 93:e188a91d3eaa 451 * @arg UART_IT_IDLE: Idle line detection interrupt
Kojto 93:e188a91d3eaa 452 * @arg USART_IT_ERR: Error interrupt
Kojto 93:e188a91d3eaa 453 * @retval The new state of __IT__ (TRUE or FALSE).
Kojto 93:e188a91d3eaa 454 */
Kojto 93:e188a91d3eaa 455 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28) == 1)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28) == 2)? \
Kojto 93:e188a91d3eaa 456 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK))
Kojto 93:e188a91d3eaa 457
Kojto 93:e188a91d3eaa 458 /** @brief Enable CTS flow control
Kojto 93:e188a91d3eaa 459 * This macro allows to enable CTS hardware flow control for a given UART instance,
Kojto 93:e188a91d3eaa 460 * without need to call HAL_UART_Init() function.
Kojto 93:e188a91d3eaa 461 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
Kojto 93:e188a91d3eaa 462 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
Kojto 93:e188a91d3eaa 463 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
Kojto 93:e188a91d3eaa 464 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
Kojto 93:e188a91d3eaa 465 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
Kojto 93:e188a91d3eaa 466 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
Kojto 93:e188a91d3eaa 467 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 468 * The Handle Instance can be USART1, USART2 or LPUART.
Kojto 93:e188a91d3eaa 469 * @retval None
Kojto 93:e188a91d3eaa 470 */
Kojto 93:e188a91d3eaa 471 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
Kojto 93:e188a91d3eaa 472 do{ \
Kojto 93:e188a91d3eaa 473 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
Kojto 93:e188a91d3eaa 474 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
Kojto 93:e188a91d3eaa 475 } while(0)
Kojto 93:e188a91d3eaa 476
Kojto 93:e188a91d3eaa 477 /** @brief Disable CTS flow control
Kojto 93:e188a91d3eaa 478 * This macro allows to disable CTS hardware flow control for a given UART instance,
Kojto 93:e188a91d3eaa 479 * without need to call HAL_UART_Init() function.
Kojto 93:e188a91d3eaa 480 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
Kojto 93:e188a91d3eaa 481 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
Kojto 93:e188a91d3eaa 482 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
Kojto 93:e188a91d3eaa 483 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
Kojto 93:e188a91d3eaa 484 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
Kojto 93:e188a91d3eaa 485 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
Kojto 93:e188a91d3eaa 486 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 487 * The Handle Instance can be USART1, USART2 or LPUART.
Kojto 93:e188a91d3eaa 488 * @retval None
Kojto 93:e188a91d3eaa 489 */
Kojto 93:e188a91d3eaa 490 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
Kojto 93:e188a91d3eaa 491 do{ \
Kojto 93:e188a91d3eaa 492 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
Kojto 93:e188a91d3eaa 493 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
Kojto 93:e188a91d3eaa 494 } while(0)
Kojto 93:e188a91d3eaa 495
Kojto 93:e188a91d3eaa 496 /** @brief Enable RTS flow control
Kojto 93:e188a91d3eaa 497 * This macro allows to enable RTS hardware flow control for a given UART instance,
Kojto 93:e188a91d3eaa 498 * without need to call HAL_UART_Init() function.
Kojto 93:e188a91d3eaa 499 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
Kojto 93:e188a91d3eaa 500 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
Kojto 93:e188a91d3eaa 501 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
Kojto 93:e188a91d3eaa 502 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
Kojto 93:e188a91d3eaa 503 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
Kojto 93:e188a91d3eaa 504 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
Kojto 93:e188a91d3eaa 505 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 506 * The Handle Instance can be USART1, USART2 or LPUART.
Kojto 93:e188a91d3eaa 507 * @retval None
Kojto 93:e188a91d3eaa 508 */
Kojto 93:e188a91d3eaa 509 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
Kojto 93:e188a91d3eaa 510 do{ \
Kojto 93:e188a91d3eaa 511 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
Kojto 93:e188a91d3eaa 512 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
Kojto 93:e188a91d3eaa 513 } while(0)
Kojto 93:e188a91d3eaa 514
Kojto 93:e188a91d3eaa 515 /** @brief Disable RTS flow control
Kojto 93:e188a91d3eaa 516 * This macro allows to disable RTS hardware flow control for a given UART instance,
Kojto 93:e188a91d3eaa 517 * without need to call HAL_UART_Init() function.
Kojto 93:e188a91d3eaa 518 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
Kojto 93:e188a91d3eaa 519 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
Kojto 93:e188a91d3eaa 520 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
Kojto 93:e188a91d3eaa 521 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
Kojto 93:e188a91d3eaa 522 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
Kojto 93:e188a91d3eaa 523 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
Kojto 93:e188a91d3eaa 524 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 525 * The Handle Instance can be USART1, USART2 or LPUART.
Kojto 93:e188a91d3eaa 526 * @retval None
Kojto 93:e188a91d3eaa 527 */
Kojto 93:e188a91d3eaa 528 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
Kojto 93:e188a91d3eaa 529 do{ \
Kojto 93:e188a91d3eaa 530 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
Kojto 93:e188a91d3eaa 531 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
Kojto 93:e188a91d3eaa 532 } while(0)
Kojto 93:e188a91d3eaa 533
Kojto 93:e188a91d3eaa 534 /** @brief macros to enables or disables the UART's one bit sampling method
Kojto 93:e188a91d3eaa 535 * @param __HANDLE__: specifies the UART Handle.
Kojto 93:e188a91d3eaa 536 * @retval None
Kojto 93:e188a91d3eaa 537 */
Kojto 93:e188a91d3eaa 538 #define __HAL_UART_ONEBIT_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
Kojto 93:e188a91d3eaa 539 #define __HAL_UART_ONEBIT_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
Kojto 93:e188a91d3eaa 540
Kojto 93:e188a91d3eaa 541 #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
Kojto 93:e188a91d3eaa 542 #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
Kojto 93:e188a91d3eaa 543
Kojto 93:e188a91d3eaa 544 #define __DIV_SAMPLING16(_PCLK_, _BAUD_) (((_PCLK_)*25)/(4*(_BAUD_)))
Kojto 93:e188a91d3eaa 545 #define __DIVMANT_SAMPLING16(_PCLK_, _BAUD_) (__DIV_SAMPLING16((_PCLK_), (_BAUD_))/100)
Kojto 93:e188a91d3eaa 546 #define __DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_) (((__DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (__DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100)) * 16 + 50) / 100)
Kojto 93:e188a91d3eaa 547 #define __UART_BRR_SAMPLING16(_PCLK_, _BAUD_) ((__DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4)|(__DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0F))
Kojto 93:e188a91d3eaa 548
Kojto 93:e188a91d3eaa 549 #define __DIV_SAMPLING8(_PCLK_, _BAUD_) (((_PCLK_)*25)/(2*(_BAUD_)))
Kojto 93:e188a91d3eaa 550 #define __DIVMANT_SAMPLING8(_PCLK_, _BAUD_) (__DIV_SAMPLING8((_PCLK_), (_BAUD_))/100)
Kojto 93:e188a91d3eaa 551 #define __DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_) (((__DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (__DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100)) * 16 + 50) / 100)
Kojto 93:e188a91d3eaa 552 #define __UART_BRR_SAMPLING8(_PCLK_, _BAUD_) ((__DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4)|(__DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x0F))
Kojto 93:e188a91d3eaa 553
Kojto 93:e188a91d3eaa 554 #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001)
Kojto 93:e188a91d3eaa 555 #define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
Kojto 93:e188a91d3eaa 556
Kojto 93:e188a91d3eaa 557 /* Exported functions --------------------------------------------------------*/
Kojto 93:e188a91d3eaa 558 /* Initialization/de-initialization functions **********************************/
Kojto 93:e188a91d3eaa 559 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 560 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 561 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
Kojto 93:e188a91d3eaa 562 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethode);
Kojto 93:e188a91d3eaa 563 HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 564 void HAL_UART_MspInit(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 565 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 566
Kojto 93:e188a91d3eaa 567 /* IO operation functions *******************************************************/
Kojto 93:e188a91d3eaa 568 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
Kojto 93:e188a91d3eaa 569 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
Kojto 93:e188a91d3eaa 570 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
Kojto 93:e188a91d3eaa 571 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
Kojto 93:e188a91d3eaa 572 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
Kojto 93:e188a91d3eaa 573 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
Kojto 93:e188a91d3eaa 574 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 575 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 576 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 577 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 578 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 579 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 580 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 581 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 582 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 583
Kojto 93:e188a91d3eaa 584 /* Peripheral Control functions ************************************************/
Kojto 93:e188a91d3eaa 585 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 586 HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 587 HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 588 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 589 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 590
Kojto 93:e188a91d3eaa 591 /* Peripheral State functions **************************************************/
Kojto 93:e188a91d3eaa 592 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 593 uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
Kojto 93:e188a91d3eaa 594
Kojto 93:e188a91d3eaa 595 /**
Kojto 93:e188a91d3eaa 596 * @}
Kojto 93:e188a91d3eaa 597 */
Kojto 93:e188a91d3eaa 598
Kojto 93:e188a91d3eaa 599 /**
Kojto 93:e188a91d3eaa 600 * @}
Kojto 93:e188a91d3eaa 601 */
Kojto 93:e188a91d3eaa 602
Kojto 93:e188a91d3eaa 603 #ifdef __cplusplus
Kojto 93:e188a91d3eaa 604 }
Kojto 93:e188a91d3eaa 605 #endif
Kojto 93:e188a91d3eaa 606
Kojto 93:e188a91d3eaa 607 #endif /* __STM32F4xx_HAL_UART_H */
Kojto 93:e188a91d3eaa 608
Kojto 93:e188a91d3eaa 609 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/