mbed official / mbed

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

Committer:
Kojto
Date:
Fri Aug 12 13:04:35 2016 +0200
Revision:
123:b0220dba8be7
Release 123 of the mbed library

Changes:
- new targets: nucleo_f207zg, beetle, nrf51_dk, hexiwear,
nuvoton nuc472, vk rz a1h
- ST - fix timer interrupt handler, sleep api fix
- NXP - lpc15xx us ticker fix
- Nordic - analogin fixes, LF clock init addition, enable i2c async

Who changed what in which revision?

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