Dataloger
TARGET_NUCLEO_F072RB/stm32f0xx_hal_uart.h@0:666850d06c9f, 2015-08-20 (annotated)
- Committer:
- jhon309
- Date:
- Thu Aug 20 00:37:14 2015 +0000
- Revision:
- 0:666850d06c9f
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhon309 | 0:666850d06c9f | 1 | /** |
jhon309 | 0:666850d06c9f | 2 | ****************************************************************************** |
jhon309 | 0:666850d06c9f | 3 | * @file stm32f0xx_hal_uart.h |
jhon309 | 0:666850d06c9f | 4 | * @author MCD Application Team |
jhon309 | 0:666850d06c9f | 5 | * @version V1.2.0 |
jhon309 | 0:666850d06c9f | 6 | * @date 11-December-2014 |
jhon309 | 0:666850d06c9f | 7 | * @brief Header file of UART HAL module. |
jhon309 | 0:666850d06c9f | 8 | ****************************************************************************** |
jhon309 | 0:666850d06c9f | 9 | * @attention |
jhon309 | 0:666850d06c9f | 10 | * |
jhon309 | 0:666850d06c9f | 11 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
jhon309 | 0:666850d06c9f | 12 | * |
jhon309 | 0:666850d06c9f | 13 | * Redistribution and use in source and binary forms, with or without modification, |
jhon309 | 0:666850d06c9f | 14 | * are permitted provided that the following conditions are met: |
jhon309 | 0:666850d06c9f | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
jhon309 | 0:666850d06c9f | 16 | * this list of conditions and the following disclaimer. |
jhon309 | 0:666850d06c9f | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
jhon309 | 0:666850d06c9f | 18 | * this list of conditions and the following disclaimer in the documentation |
jhon309 | 0:666850d06c9f | 19 | * and/or other materials provided with the distribution. |
jhon309 | 0:666850d06c9f | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
jhon309 | 0:666850d06c9f | 21 | * may be used to endorse or promote products derived from this software |
jhon309 | 0:666850d06c9f | 22 | * without specific prior written permission. |
jhon309 | 0:666850d06c9f | 23 | * |
jhon309 | 0:666850d06c9f | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
jhon309 | 0:666850d06c9f | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
jhon309 | 0:666850d06c9f | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
jhon309 | 0:666850d06c9f | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
jhon309 | 0:666850d06c9f | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
jhon309 | 0:666850d06c9f | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
jhon309 | 0:666850d06c9f | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
jhon309 | 0:666850d06c9f | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
jhon309 | 0:666850d06c9f | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
jhon309 | 0:666850d06c9f | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
jhon309 | 0:666850d06c9f | 34 | * |
jhon309 | 0:666850d06c9f | 35 | ****************************************************************************** |
jhon309 | 0:666850d06c9f | 36 | */ |
jhon309 | 0:666850d06c9f | 37 | |
jhon309 | 0:666850d06c9f | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ |
jhon309 | 0:666850d06c9f | 39 | #ifndef __STM32F0xx_HAL_UART_H |
jhon309 | 0:666850d06c9f | 40 | #define __STM32F0xx_HAL_UART_H |
jhon309 | 0:666850d06c9f | 41 | |
jhon309 | 0:666850d06c9f | 42 | #ifdef __cplusplus |
jhon309 | 0:666850d06c9f | 43 | extern "C" { |
jhon309 | 0:666850d06c9f | 44 | #endif |
jhon309 | 0:666850d06c9f | 45 | |
jhon309 | 0:666850d06c9f | 46 | /* Includes ------------------------------------------------------------------*/ |
jhon309 | 0:666850d06c9f | 47 | #include "stm32f0xx_hal_def.h" |
jhon309 | 0:666850d06c9f | 48 | |
jhon309 | 0:666850d06c9f | 49 | /** @addtogroup STM32F0xx_HAL_Driver |
jhon309 | 0:666850d06c9f | 50 | * @{ |
jhon309 | 0:666850d06c9f | 51 | */ |
jhon309 | 0:666850d06c9f | 52 | |
jhon309 | 0:666850d06c9f | 53 | /** @addtogroup UART |
jhon309 | 0:666850d06c9f | 54 | * @{ |
jhon309 | 0:666850d06c9f | 55 | */ |
jhon309 | 0:666850d06c9f | 56 | |
jhon309 | 0:666850d06c9f | 57 | /* Exported types ------------------------------------------------------------*/ |
jhon309 | 0:666850d06c9f | 58 | /** @defgroup UART_Exported_Types UART Exported Types |
jhon309 | 0:666850d06c9f | 59 | * @{ |
jhon309 | 0:666850d06c9f | 60 | */ |
jhon309 | 0:666850d06c9f | 61 | |
jhon309 | 0:666850d06c9f | 62 | |
jhon309 | 0:666850d06c9f | 63 | /** |
jhon309 | 0:666850d06c9f | 64 | * @brief UART Init Structure definition |
jhon309 | 0:666850d06c9f | 65 | */ |
jhon309 | 0:666850d06c9f | 66 | typedef struct |
jhon309 | 0:666850d06c9f | 67 | { |
jhon309 | 0:666850d06c9f | 68 | uint32_t BaudRate; /*!< This member configures the UART communication baud rate. |
jhon309 | 0:666850d06c9f | 69 | The baud rate register is computed using the following formula: |
jhon309 | 0:666850d06c9f | 70 | - If oversampling is 16 or in LIN mode (LIN mode not available on F030xx devices), |
jhon309 | 0:666850d06c9f | 71 | Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate))) |
jhon309 | 0:666850d06c9f | 72 | - If oversampling is 8, |
jhon309 | 0:666850d06c9f | 73 | Baud Rate Register[15:4] = ((2 * PCLKx) / ((huart->Init.BaudRate)))[15:4] |
jhon309 | 0:666850d06c9f | 74 | Baud Rate Register[3] = 0 |
jhon309 | 0:666850d06c9f | 75 | Baud Rate Register[2:0] = (((2 * PCLKx) / ((huart->Init.BaudRate)))[3:0]) >> 1 */ |
jhon309 | 0:666850d06c9f | 76 | |
jhon309 | 0:666850d06c9f | 77 | uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. |
jhon309 | 0:666850d06c9f | 78 | This parameter can be a value of @ref UARTEx_Word_Length */ |
jhon309 | 0:666850d06c9f | 79 | |
jhon309 | 0:666850d06c9f | 80 | uint32_t StopBits; /*!< Specifies the number of stop bits transmitted. |
jhon309 | 0:666850d06c9f | 81 | This parameter can be a value of @ref UART_Stop_Bits */ |
jhon309 | 0:666850d06c9f | 82 | |
jhon309 | 0:666850d06c9f | 83 | uint32_t Parity; /*!< Specifies the parity mode. |
jhon309 | 0:666850d06c9f | 84 | This parameter can be a value of @ref UART_Parity |
jhon309 | 0:666850d06c9f | 85 | @note When parity is enabled, the computed parity is inserted |
jhon309 | 0:666850d06c9f | 86 | at the MSB position of the transmitted data (9th bit when |
jhon309 | 0:666850d06c9f | 87 | the word length is set to 9 data bits; 8th bit when the |
jhon309 | 0:666850d06c9f | 88 | word length is set to 8 data bits). */ |
jhon309 | 0:666850d06c9f | 89 | |
jhon309 | 0:666850d06c9f | 90 | uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled. |
jhon309 | 0:666850d06c9f | 91 | This parameter can be a value of @ref UART_Mode */ |
jhon309 | 0:666850d06c9f | 92 | |
jhon309 | 0:666850d06c9f | 93 | uint32_t HwFlowCtl; /*!< Specifies whether the hardware flow control mode is enabled |
jhon309 | 0:666850d06c9f | 94 | or disabled. |
jhon309 | 0:666850d06c9f | 95 | This parameter can be a value of @ref UART_Hardware_Flow_Control */ |
jhon309 | 0:666850d06c9f | 96 | |
jhon309 | 0:666850d06c9f | 97 | uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8). |
jhon309 | 0:666850d06c9f | 98 | This parameter can be a value of @ref UART_Over_Sampling */ |
jhon309 | 0:666850d06c9f | 99 | |
jhon309 | 0:666850d06c9f | 100 | uint32_t OneBitSampling; /*!< Specifies whether a single sample or three samples' majority vote is selected. |
jhon309 | 0:666850d06c9f | 101 | Selecting the single sample method increases the receiver tolerance to clock |
jhon309 | 0:666850d06c9f | 102 | deviations. This parameter can be a value of @ref UART_OneBit_Sampling. */ |
jhon309 | 0:666850d06c9f | 103 | }UART_InitTypeDef; |
jhon309 | 0:666850d06c9f | 104 | |
jhon309 | 0:666850d06c9f | 105 | /** |
jhon309 | 0:666850d06c9f | 106 | * @brief UART Advanced Features initalization structure definition |
jhon309 | 0:666850d06c9f | 107 | */ |
jhon309 | 0:666850d06c9f | 108 | typedef struct |
jhon309 | 0:666850d06c9f | 109 | { |
jhon309 | 0:666850d06c9f | 110 | uint32_t AdvFeatureInit; /*!< Specifies which advanced UART features is initialized. Several |
jhon309 | 0:666850d06c9f | 111 | Advanced Features may be initialized at the same time . |
jhon309 | 0:666850d06c9f | 112 | This parameter can be a value of @ref UART_Advanced_Features_Initialization_Type */ |
jhon309 | 0:666850d06c9f | 113 | |
jhon309 | 0:666850d06c9f | 114 | uint32_t TxPinLevelInvert; /*!< Specifies whether the TX pin active level is inverted. |
jhon309 | 0:666850d06c9f | 115 | This parameter can be a value of @ref UART_Tx_Inv */ |
jhon309 | 0:666850d06c9f | 116 | |
jhon309 | 0:666850d06c9f | 117 | uint32_t RxPinLevelInvert; /*!< Specifies whether the RX pin active level is inverted. |
jhon309 | 0:666850d06c9f | 118 | This parameter can be a value of @ref UART_Rx_Inv */ |
jhon309 | 0:666850d06c9f | 119 | |
jhon309 | 0:666850d06c9f | 120 | uint32_t DataInvert; /*!< Specifies whether data are inverted (positive/direct logic |
jhon309 | 0:666850d06c9f | 121 | vs negative/inverted logic). |
jhon309 | 0:666850d06c9f | 122 | This parameter can be a value of @ref UART_Data_Inv */ |
jhon309 | 0:666850d06c9f | 123 | |
jhon309 | 0:666850d06c9f | 124 | uint32_t Swap; /*!< Specifies whether TX and RX pins are swapped. |
jhon309 | 0:666850d06c9f | 125 | This parameter can be a value of @ref UART_Rx_Tx_Swap */ |
jhon309 | 0:666850d06c9f | 126 | |
jhon309 | 0:666850d06c9f | 127 | uint32_t OverrunDisable; /*!< Specifies whether the reception overrun detection is disabled. |
jhon309 | 0:666850d06c9f | 128 | This parameter can be a value of @ref UART_Overrun_Disable */ |
jhon309 | 0:666850d06c9f | 129 | |
jhon309 | 0:666850d06c9f | 130 | uint32_t DMADisableonRxError; /*!< Specifies whether the DMA is disabled in case of reception error. |
jhon309 | 0:666850d06c9f | 131 | This parameter can be a value of @ref UART_DMA_Disable_on_Rx_Error */ |
jhon309 | 0:666850d06c9f | 132 | |
jhon309 | 0:666850d06c9f | 133 | uint32_t AutoBaudRateEnable; /*!< Specifies whether auto Baud rate detection is enabled. |
jhon309 | 0:666850d06c9f | 134 | This parameter can be a value of @ref UART_AutoBaudRate_Enable */ |
jhon309 | 0:666850d06c9f | 135 | |
jhon309 | 0:666850d06c9f | 136 | uint32_t AutoBaudRateMode; /*!< If auto Baud rate detection is enabled, specifies how the rate |
jhon309 | 0:666850d06c9f | 137 | detection is carried out. |
jhon309 | 0:666850d06c9f | 138 | This parameter can be a value of @ref UARTEx_AutoBaud_Rate_Mode */ |
jhon309 | 0:666850d06c9f | 139 | |
jhon309 | 0:666850d06c9f | 140 | uint32_t MSBFirst; /*!< Specifies whether MSB is sent first on UART line. |
jhon309 | 0:666850d06c9f | 141 | This parameter can be a value of @ref UART_MSB_First */ |
jhon309 | 0:666850d06c9f | 142 | } UART_AdvFeatureInitTypeDef; |
jhon309 | 0:666850d06c9f | 143 | |
jhon309 | 0:666850d06c9f | 144 | /** |
jhon309 | 0:666850d06c9f | 145 | * @brief HAL UART State structures definition |
jhon309 | 0:666850d06c9f | 146 | */ |
jhon309 | 0:666850d06c9f | 147 | typedef enum |
jhon309 | 0:666850d06c9f | 148 | { |
jhon309 | 0:666850d06c9f | 149 | HAL_UART_STATE_RESET = 0x00, /*!< Peripheral is not initialized */ |
jhon309 | 0:666850d06c9f | 150 | HAL_UART_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */ |
jhon309 | 0:666850d06c9f | 151 | HAL_UART_STATE_BUSY = 0x02, /*!< an internal process is ongoing */ |
jhon309 | 0:666850d06c9f | 152 | HAL_UART_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */ |
jhon309 | 0:666850d06c9f | 153 | HAL_UART_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */ |
jhon309 | 0:666850d06c9f | 154 | HAL_UART_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */ |
jhon309 | 0:666850d06c9f | 155 | HAL_UART_STATE_TIMEOUT = 0x03, /*!< Timeout state */ |
jhon309 | 0:666850d06c9f | 156 | HAL_UART_STATE_ERROR = 0x04 /*!< Error */ |
jhon309 | 0:666850d06c9f | 157 | }HAL_UART_StateTypeDef; |
jhon309 | 0:666850d06c9f | 158 | |
jhon309 | 0:666850d06c9f | 159 | /** |
jhon309 | 0:666850d06c9f | 160 | * @brief UART clock sources definition |
jhon309 | 0:666850d06c9f | 161 | */ |
jhon309 | 0:666850d06c9f | 162 | typedef enum |
jhon309 | 0:666850d06c9f | 163 | { |
jhon309 | 0:666850d06c9f | 164 | UART_CLOCKSOURCE_PCLK1 = 0x00, /*!< PCLK1 clock source */ |
jhon309 | 0:666850d06c9f | 165 | UART_CLOCKSOURCE_HSI = 0x02, /*!< HSI clock source */ |
jhon309 | 0:666850d06c9f | 166 | UART_CLOCKSOURCE_SYSCLK = 0x04, /*!< SYSCLK clock source */ |
jhon309 | 0:666850d06c9f | 167 | UART_CLOCKSOURCE_LSE = 0x08, /*!< LSE clock source */ |
jhon309 | 0:666850d06c9f | 168 | UART_CLOCKSOURCE_UNDEFINED = 0x10 /*!< undefined clock source */ |
jhon309 | 0:666850d06c9f | 169 | }UART_ClockSourceTypeDef; |
jhon309 | 0:666850d06c9f | 170 | |
jhon309 | 0:666850d06c9f | 171 | /** |
jhon309 | 0:666850d06c9f | 172 | * @brief UART handle Structure definition |
jhon309 | 0:666850d06c9f | 173 | */ |
jhon309 | 0:666850d06c9f | 174 | typedef struct |
jhon309 | 0:666850d06c9f | 175 | { |
jhon309 | 0:666850d06c9f | 176 | USART_TypeDef *Instance; /*!< UART registers base address */ |
jhon309 | 0:666850d06c9f | 177 | |
jhon309 | 0:666850d06c9f | 178 | UART_InitTypeDef Init; /*!< UART communication parameters */ |
jhon309 | 0:666850d06c9f | 179 | |
jhon309 | 0:666850d06c9f | 180 | UART_AdvFeatureInitTypeDef AdvancedInit; /*!< UART Advanced Features initialization parameters */ |
jhon309 | 0:666850d06c9f | 181 | |
jhon309 | 0:666850d06c9f | 182 | uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */ |
jhon309 | 0:666850d06c9f | 183 | |
jhon309 | 0:666850d06c9f | 184 | uint16_t TxXferSize; /*!< UART Tx Transfer size */ |
jhon309 | 0:666850d06c9f | 185 | |
jhon309 | 0:666850d06c9f | 186 | uint16_t TxXferCount; /*!< UART Tx Transfer Counter */ |
jhon309 | 0:666850d06c9f | 187 | |
jhon309 | 0:666850d06c9f | 188 | uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */ |
jhon309 | 0:666850d06c9f | 189 | |
jhon309 | 0:666850d06c9f | 190 | uint16_t RxXferSize; /*!< UART Rx Transfer size */ |
jhon309 | 0:666850d06c9f | 191 | |
jhon309 | 0:666850d06c9f | 192 | uint16_t RxXferCount; /*!< UART Rx Transfer Counter */ |
jhon309 | 0:666850d06c9f | 193 | |
jhon309 | 0:666850d06c9f | 194 | uint16_t Mask; /*!< UART Rx RDR register mask */ |
jhon309 | 0:666850d06c9f | 195 | |
jhon309 | 0:666850d06c9f | 196 | DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */ |
jhon309 | 0:666850d06c9f | 197 | |
jhon309 | 0:666850d06c9f | 198 | DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */ |
jhon309 | 0:666850d06c9f | 199 | |
jhon309 | 0:666850d06c9f | 200 | HAL_LockTypeDef Lock; /*!< Locking object */ |
jhon309 | 0:666850d06c9f | 201 | |
jhon309 | 0:666850d06c9f | 202 | HAL_UART_StateTypeDef State; /*!< UART communication state */ |
jhon309 | 0:666850d06c9f | 203 | |
jhon309 | 0:666850d06c9f | 204 | __IO uint32_t ErrorCode; /*!< UART Error code |
jhon309 | 0:666850d06c9f | 205 | This parameter can be a value of @ref UART_Error */ |
jhon309 | 0:666850d06c9f | 206 | |
jhon309 | 0:666850d06c9f | 207 | }UART_HandleTypeDef; |
jhon309 | 0:666850d06c9f | 208 | |
jhon309 | 0:666850d06c9f | 209 | /** |
jhon309 | 0:666850d06c9f | 210 | * @} |
jhon309 | 0:666850d06c9f | 211 | */ |
jhon309 | 0:666850d06c9f | 212 | |
jhon309 | 0:666850d06c9f | 213 | /* Exported constants --------------------------------------------------------*/ |
jhon309 | 0:666850d06c9f | 214 | /** @defgroup UART_Exported_Constants UART Exported constants |
jhon309 | 0:666850d06c9f | 215 | * @{ |
jhon309 | 0:666850d06c9f | 216 | */ |
jhon309 | 0:666850d06c9f | 217 | |
jhon309 | 0:666850d06c9f | 218 | /** @defgroup UART_Error UART Error |
jhon309 | 0:666850d06c9f | 219 | * @{ |
jhon309 | 0:666850d06c9f | 220 | */ |
jhon309 | 0:666850d06c9f | 221 | #define HAL_UART_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */ |
jhon309 | 0:666850d06c9f | 222 | #define HAL_UART_ERROR_PE ((uint32_t)0x00000001) /*!< Parity error */ |
jhon309 | 0:666850d06c9f | 223 | #define HAL_UART_ERROR_NE ((uint32_t)0x00000002) /*!< Noise error */ |
jhon309 | 0:666850d06c9f | 224 | #define HAL_UART_ERROR_FE ((uint32_t)0x00000004) /*!< frame error */ |
jhon309 | 0:666850d06c9f | 225 | #define HAL_UART_ERROR_ORE ((uint32_t)0x00000008) /*!< Overrun error */ |
jhon309 | 0:666850d06c9f | 226 | #define HAL_UART_ERROR_DMA ((uint32_t)0x00000010) /*!< DMA transfer error */ |
jhon309 | 0:666850d06c9f | 227 | /** |
jhon309 | 0:666850d06c9f | 228 | * @} |
jhon309 | 0:666850d06c9f | 229 | */ |
jhon309 | 0:666850d06c9f | 230 | |
jhon309 | 0:666850d06c9f | 231 | /** @defgroup UART_Stop_Bits UART Number of Stop Bits |
jhon309 | 0:666850d06c9f | 232 | * @{ |
jhon309 | 0:666850d06c9f | 233 | */ |
jhon309 | 0:666850d06c9f | 234 | #define UART_STOPBITS_1 ((uint32_t)0x0000) |
jhon309 | 0:666850d06c9f | 235 | #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1) |
jhon309 | 0:666850d06c9f | 236 | #define UART_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1)) |
jhon309 | 0:666850d06c9f | 237 | #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \ |
jhon309 | 0:666850d06c9f | 238 | ((STOPBITS) == UART_STOPBITS_2) || \ |
jhon309 | 0:666850d06c9f | 239 | ((STOPBITS) == UART_STOPBITS_1_5)) |
jhon309 | 0:666850d06c9f | 240 | /** |
jhon309 | 0:666850d06c9f | 241 | * @} |
jhon309 | 0:666850d06c9f | 242 | */ |
jhon309 | 0:666850d06c9f | 243 | |
jhon309 | 0:666850d06c9f | 244 | /** @defgroup UART_Parity UART Parity |
jhon309 | 0:666850d06c9f | 245 | * @{ |
jhon309 | 0:666850d06c9f | 246 | */ |
jhon309 | 0:666850d06c9f | 247 | #define UART_PARITY_NONE ((uint32_t)0x0000) |
jhon309 | 0:666850d06c9f | 248 | #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) |
jhon309 | 0:666850d06c9f | 249 | #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) |
jhon309 | 0:666850d06c9f | 250 | #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \ |
jhon309 | 0:666850d06c9f | 251 | ((PARITY) == UART_PARITY_EVEN) || \ |
jhon309 | 0:666850d06c9f | 252 | ((PARITY) == UART_PARITY_ODD)) |
jhon309 | 0:666850d06c9f | 253 | /** |
jhon309 | 0:666850d06c9f | 254 | * @} |
jhon309 | 0:666850d06c9f | 255 | */ |
jhon309 | 0:666850d06c9f | 256 | |
jhon309 | 0:666850d06c9f | 257 | /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control |
jhon309 | 0:666850d06c9f | 258 | * @{ |
jhon309 | 0:666850d06c9f | 259 | */ |
jhon309 | 0:666850d06c9f | 260 | #define UART_HWCONTROL_NONE ((uint32_t)0x0000) |
jhon309 | 0:666850d06c9f | 261 | #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE) |
jhon309 | 0:666850d06c9f | 262 | #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE) |
jhon309 | 0:666850d06c9f | 263 | #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE)) |
jhon309 | 0:666850d06c9f | 264 | #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\ |
jhon309 | 0:666850d06c9f | 265 | (((CONTROL) == UART_HWCONTROL_NONE) || \ |
jhon309 | 0:666850d06c9f | 266 | ((CONTROL) == UART_HWCONTROL_RTS) || \ |
jhon309 | 0:666850d06c9f | 267 | ((CONTROL) == UART_HWCONTROL_CTS) || \ |
jhon309 | 0:666850d06c9f | 268 | ((CONTROL) == UART_HWCONTROL_RTS_CTS)) |
jhon309 | 0:666850d06c9f | 269 | /** |
jhon309 | 0:666850d06c9f | 270 | * @} |
jhon309 | 0:666850d06c9f | 271 | */ |
jhon309 | 0:666850d06c9f | 272 | |
jhon309 | 0:666850d06c9f | 273 | /** @defgroup UART_Mode UART Transfer Mode |
jhon309 | 0:666850d06c9f | 274 | * @{ |
jhon309 | 0:666850d06c9f | 275 | */ |
jhon309 | 0:666850d06c9f | 276 | #define UART_MODE_RX ((uint32_t)USART_CR1_RE) |
jhon309 | 0:666850d06c9f | 277 | #define UART_MODE_TX ((uint32_t)USART_CR1_TE) |
jhon309 | 0:666850d06c9f | 278 | #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) |
jhon309 | 0:666850d06c9f | 279 | #define IS_UART_MODE(MODE) ((((MODE) & (~((uint32_t)(UART_MODE_TX_RX)))) == (uint32_t)0x00) && ((MODE) != (uint32_t)0x00)) |
jhon309 | 0:666850d06c9f | 280 | /** |
jhon309 | 0:666850d06c9f | 281 | * @} |
jhon309 | 0:666850d06c9f | 282 | */ |
jhon309 | 0:666850d06c9f | 283 | |
jhon309 | 0:666850d06c9f | 284 | /** @defgroup UART_State UART State |
jhon309 | 0:666850d06c9f | 285 | * @{ |
jhon309 | 0:666850d06c9f | 286 | */ |
jhon309 | 0:666850d06c9f | 287 | #define UART_STATE_DISABLE ((uint32_t)0x0000) |
jhon309 | 0:666850d06c9f | 288 | #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE) |
jhon309 | 0:666850d06c9f | 289 | #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 290 | ((STATE) == UART_STATE_ENABLE)) |
jhon309 | 0:666850d06c9f | 291 | /** |
jhon309 | 0:666850d06c9f | 292 | * @} |
jhon309 | 0:666850d06c9f | 293 | */ |
jhon309 | 0:666850d06c9f | 294 | |
jhon309 | 0:666850d06c9f | 295 | /** @defgroup UART_Over_Sampling UART Over Sampling |
jhon309 | 0:666850d06c9f | 296 | * @{ |
jhon309 | 0:666850d06c9f | 297 | */ |
jhon309 | 0:666850d06c9f | 298 | #define UART_OVERSAMPLING_16 ((uint32_t)0x0000) |
jhon309 | 0:666850d06c9f | 299 | #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8) |
jhon309 | 0:666850d06c9f | 300 | #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \ |
jhon309 | 0:666850d06c9f | 301 | ((SAMPLING) == UART_OVERSAMPLING_8)) |
jhon309 | 0:666850d06c9f | 302 | /** |
jhon309 | 0:666850d06c9f | 303 | * @} |
jhon309 | 0:666850d06c9f | 304 | */ |
jhon309 | 0:666850d06c9f | 305 | |
jhon309 | 0:666850d06c9f | 306 | /** @defgroup UART_OneBit_Sampling UART One Bit Sampling Method |
jhon309 | 0:666850d06c9f | 307 | * @{ |
jhon309 | 0:666850d06c9f | 308 | */ |
jhon309 | 0:666850d06c9f | 309 | #define UART_ONEBIT_SAMPLING_DISABLED ((uint32_t)0x0000) |
jhon309 | 0:666850d06c9f | 310 | #define UART_ONEBIT_SAMPLING_ENABLED ((uint32_t)USART_CR3_ONEBIT) |
jhon309 | 0:666850d06c9f | 311 | #define IS_UART_ONEBIT_SAMPLING(ONEBIT) (((ONEBIT) == UART_ONEBIT_SAMPLING_DISABLED) || \ |
jhon309 | 0:666850d06c9f | 312 | ((ONEBIT) == UART_ONEBIT_SAMPLING_ENABLED)) |
jhon309 | 0:666850d06c9f | 313 | /** |
jhon309 | 0:666850d06c9f | 314 | * @} |
jhon309 | 0:666850d06c9f | 315 | */ |
jhon309 | 0:666850d06c9f | 316 | |
jhon309 | 0:666850d06c9f | 317 | |
jhon309 | 0:666850d06c9f | 318 | /** @defgroup UART_Receiver_TimeOut UART Receiver TimeOut |
jhon309 | 0:666850d06c9f | 319 | * @{ |
jhon309 | 0:666850d06c9f | 320 | */ |
jhon309 | 0:666850d06c9f | 321 | #define UART_RECEIVER_TIMEOUT_DISABLE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 322 | #define UART_RECEIVER_TIMEOUT_ENABLE ((uint32_t)USART_CR2_RTOEN) |
jhon309 | 0:666850d06c9f | 323 | #define IS_UART_RECEIVER_TIMEOUT(TIMEOUT) (((TIMEOUT) == UART_RECEIVER_TIMEOUT_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 324 | ((TIMEOUT) == UART_RECEIVER_TIMEOUT_ENABLE)) |
jhon309 | 0:666850d06c9f | 325 | /** |
jhon309 | 0:666850d06c9f | 326 | * @} |
jhon309 | 0:666850d06c9f | 327 | */ |
jhon309 | 0:666850d06c9f | 328 | |
jhon309 | 0:666850d06c9f | 329 | /** @defgroup UART_One_Bit UART One Bit sampling |
jhon309 | 0:666850d06c9f | 330 | * @{ |
jhon309 | 0:666850d06c9f | 331 | */ |
jhon309 | 0:666850d06c9f | 332 | #define UART_ONE_BIT_SAMPLE_DISABLED ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 333 | #define UART_ONE_BIT_SAMPLE_ENABLED ((uint32_t)USART_CR3_ONEBIT) |
jhon309 | 0:666850d06c9f | 334 | #define IS_UART_ONEBIT_SAMPLE(ONEBIT) (((ONEBIT) == UART_ONE_BIT_SAMPLE_DISABLED) || \ |
jhon309 | 0:666850d06c9f | 335 | ((ONEBIT) == UART_ONE_BIT_SAMPLE_ENABLED)) |
jhon309 | 0:666850d06c9f | 336 | /** |
jhon309 | 0:666850d06c9f | 337 | * @} |
jhon309 | 0:666850d06c9f | 338 | */ |
jhon309 | 0:666850d06c9f | 339 | |
jhon309 | 0:666850d06c9f | 340 | /** @defgroup UART_DMA_Tx UART DMA Tx |
jhon309 | 0:666850d06c9f | 341 | * @{ |
jhon309 | 0:666850d06c9f | 342 | */ |
jhon309 | 0:666850d06c9f | 343 | #define UART_DMA_TX_DISABLE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 344 | #define UART_DMA_TX_ENABLE ((uint32_t)USART_CR3_DMAT) |
jhon309 | 0:666850d06c9f | 345 | #define IS_UART_DMA_TX(DMATX) (((DMATX) == UART_DMA_TX_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 346 | ((DMATX) == UART_DMA_TX_ENABLE)) |
jhon309 | 0:666850d06c9f | 347 | /** |
jhon309 | 0:666850d06c9f | 348 | * @} |
jhon309 | 0:666850d06c9f | 349 | */ |
jhon309 | 0:666850d06c9f | 350 | |
jhon309 | 0:666850d06c9f | 351 | /** @defgroup UART_DMA_Rx UART DMA Rx |
jhon309 | 0:666850d06c9f | 352 | * @{ |
jhon309 | 0:666850d06c9f | 353 | */ |
jhon309 | 0:666850d06c9f | 354 | #define UART_DMA_RX_DISABLE ((uint32_t)0x0000) |
jhon309 | 0:666850d06c9f | 355 | #define UART_DMA_RX_ENABLE ((uint32_t)USART_CR3_DMAR) |
jhon309 | 0:666850d06c9f | 356 | #define IS_UART_DMA_RX(DMARX) (((DMARX) == UART_DMA_RX_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 357 | ((DMARX) == UART_DMA_RX_ENABLE)) |
jhon309 | 0:666850d06c9f | 358 | /** |
jhon309 | 0:666850d06c9f | 359 | * @} |
jhon309 | 0:666850d06c9f | 360 | */ |
jhon309 | 0:666850d06c9f | 361 | |
jhon309 | 0:666850d06c9f | 362 | /** @defgroup UART_Half_Duplex_Selection UART Half Duplex Selection |
jhon309 | 0:666850d06c9f | 363 | * @{ |
jhon309 | 0:666850d06c9f | 364 | */ |
jhon309 | 0:666850d06c9f | 365 | #define UART_HALF_DUPLEX_DISABLE ((uint32_t)0x0000) |
jhon309 | 0:666850d06c9f | 366 | #define UART_HALF_DUPLEX_ENABLE ((uint32_t)USART_CR3_HDSEL) |
jhon309 | 0:666850d06c9f | 367 | #define IS_UART_HALF_DUPLEX(HDSEL) (((HDSEL) == UART_HALF_DUPLEX_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 368 | ((HDSEL) == UART_HALF_DUPLEX_ENABLE)) |
jhon309 | 0:666850d06c9f | 369 | /** |
jhon309 | 0:666850d06c9f | 370 | * @} |
jhon309 | 0:666850d06c9f | 371 | */ |
jhon309 | 0:666850d06c9f | 372 | |
jhon309 | 0:666850d06c9f | 373 | /** @defgroup UART_WakeUp_Address_Length UART WakeUp Address Length |
jhon309 | 0:666850d06c9f | 374 | * @{ |
jhon309 | 0:666850d06c9f | 375 | */ |
jhon309 | 0:666850d06c9f | 376 | #define UART_ADDRESS_DETECT_4B ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 377 | #define UART_ADDRESS_DETECT_7B ((uint32_t)USART_CR2_ADDM7) |
jhon309 | 0:666850d06c9f | 378 | #define IS_UART_ADDRESSLENGTH_DETECT(ADDRESS) (((ADDRESS) == UART_ADDRESS_DETECT_4B) || \ |
jhon309 | 0:666850d06c9f | 379 | ((ADDRESS) == UART_ADDRESS_DETECT_7B)) |
jhon309 | 0:666850d06c9f | 380 | /** |
jhon309 | 0:666850d06c9f | 381 | * @} |
jhon309 | 0:666850d06c9f | 382 | */ |
jhon309 | 0:666850d06c9f | 383 | |
jhon309 | 0:666850d06c9f | 384 | /** @defgroup UART_WakeUp_Methods UART WakeUp Methods |
jhon309 | 0:666850d06c9f | 385 | * @{ |
jhon309 | 0:666850d06c9f | 386 | */ |
jhon309 | 0:666850d06c9f | 387 | #define UART_WAKEUPMETHOD_IDLELINE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 388 | #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE) |
jhon309 | 0:666850d06c9f | 389 | #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \ |
jhon309 | 0:666850d06c9f | 390 | ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK)) |
jhon309 | 0:666850d06c9f | 391 | /** |
jhon309 | 0:666850d06c9f | 392 | * @} |
jhon309 | 0:666850d06c9f | 393 | */ |
jhon309 | 0:666850d06c9f | 394 | |
jhon309 | 0:666850d06c9f | 395 | /** @defgroup UART_IT UART IT |
jhon309 | 0:666850d06c9f | 396 | * Elements values convention: 000000000XXYYYYYb |
jhon309 | 0:666850d06c9f | 397 | * - YYYYY : Interrupt source position in the XX register (5bits) |
jhon309 | 0:666850d06c9f | 398 | * - XX : Interrupt source register (2bits) |
jhon309 | 0:666850d06c9f | 399 | * - 01: CR1 register |
jhon309 | 0:666850d06c9f | 400 | * - 10: CR2 register |
jhon309 | 0:666850d06c9f | 401 | * - 11: CR3 register |
jhon309 | 0:666850d06c9f | 402 | * @{ |
jhon309 | 0:666850d06c9f | 403 | */ |
jhon309 | 0:666850d06c9f | 404 | #define UART_IT_ERR ((uint16_t)0x0060) |
jhon309 | 0:666850d06c9f | 405 | |
jhon309 | 0:666850d06c9f | 406 | /** Elements values convention: 0000ZZZZ00000000b |
jhon309 | 0:666850d06c9f | 407 | * - ZZZZ : Flag position in the ISR register(4bits) |
jhon309 | 0:666850d06c9f | 408 | */ |
jhon309 | 0:666850d06c9f | 409 | #define UART_IT_ORE ((uint16_t)0x0300) |
jhon309 | 0:666850d06c9f | 410 | #define UART_IT_NE ((uint16_t)0x0200) |
jhon309 | 0:666850d06c9f | 411 | #define UART_IT_FE ((uint16_t)0x0100) |
jhon309 | 0:666850d06c9f | 412 | /** |
jhon309 | 0:666850d06c9f | 413 | * @} |
jhon309 | 0:666850d06c9f | 414 | */ |
jhon309 | 0:666850d06c9f | 415 | |
jhon309 | 0:666850d06c9f | 416 | /** @defgroup UART_Advanced_Features_Initialization_Type UART Advanced Feature Initialization Type |
jhon309 | 0:666850d06c9f | 417 | * @{ |
jhon309 | 0:666850d06c9f | 418 | */ |
jhon309 | 0:666850d06c9f | 419 | #define UART_ADVFEATURE_NO_INIT ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 420 | #define UART_ADVFEATURE_TXINVERT_INIT ((uint32_t)0x00000001) |
jhon309 | 0:666850d06c9f | 421 | #define UART_ADVFEATURE_RXINVERT_INIT ((uint32_t)0x00000002) |
jhon309 | 0:666850d06c9f | 422 | #define UART_ADVFEATURE_DATAINVERT_INIT ((uint32_t)0x00000004) |
jhon309 | 0:666850d06c9f | 423 | #define UART_ADVFEATURE_SWAP_INIT ((uint32_t)0x00000008) |
jhon309 | 0:666850d06c9f | 424 | #define UART_ADVFEATURE_RXOVERRUNDISABLE_INIT ((uint32_t)0x00000010) |
jhon309 | 0:666850d06c9f | 425 | #define UART_ADVFEATURE_DMADISABLEONERROR_INIT ((uint32_t)0x00000020) |
jhon309 | 0:666850d06c9f | 426 | #define UART_ADVFEATURE_AUTOBAUDRATE_INIT ((uint32_t)0x00000040) |
jhon309 | 0:666850d06c9f | 427 | #define UART_ADVFEATURE_MSBFIRST_INIT ((uint32_t)0x00000080) |
jhon309 | 0:666850d06c9f | 428 | #define IS_UART_ADVFEATURE_INIT(INIT) ((INIT) <= (UART_ADVFEATURE_NO_INIT | \ |
jhon309 | 0:666850d06c9f | 429 | UART_ADVFEATURE_TXINVERT_INIT | \ |
jhon309 | 0:666850d06c9f | 430 | UART_ADVFEATURE_RXINVERT_INIT | \ |
jhon309 | 0:666850d06c9f | 431 | UART_ADVFEATURE_DATAINVERT_INIT | \ |
jhon309 | 0:666850d06c9f | 432 | UART_ADVFEATURE_SWAP_INIT | \ |
jhon309 | 0:666850d06c9f | 433 | UART_ADVFEATURE_RXOVERRUNDISABLE_INIT | \ |
jhon309 | 0:666850d06c9f | 434 | UART_ADVFEATURE_DMADISABLEONERROR_INIT | \ |
jhon309 | 0:666850d06c9f | 435 | UART_ADVFEATURE_AUTOBAUDRATE_INIT | \ |
jhon309 | 0:666850d06c9f | 436 | UART_ADVFEATURE_MSBFIRST_INIT)) |
jhon309 | 0:666850d06c9f | 437 | /** |
jhon309 | 0:666850d06c9f | 438 | * @} |
jhon309 | 0:666850d06c9f | 439 | */ |
jhon309 | 0:666850d06c9f | 440 | |
jhon309 | 0:666850d06c9f | 441 | /** @defgroup UART_Tx_Inv UART Advanced Feature TX Pin Active Level Inversion |
jhon309 | 0:666850d06c9f | 442 | * @{ |
jhon309 | 0:666850d06c9f | 443 | */ |
jhon309 | 0:666850d06c9f | 444 | #define UART_ADVFEATURE_TXINV_DISABLE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 445 | #define UART_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV) |
jhon309 | 0:666850d06c9f | 446 | #define IS_UART_ADVFEATURE_TXINV(TXINV) (((TXINV) == UART_ADVFEATURE_TXINV_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 447 | ((TXINV) == UART_ADVFEATURE_TXINV_ENABLE)) |
jhon309 | 0:666850d06c9f | 448 | /** |
jhon309 | 0:666850d06c9f | 449 | * @} |
jhon309 | 0:666850d06c9f | 450 | */ |
jhon309 | 0:666850d06c9f | 451 | |
jhon309 | 0:666850d06c9f | 452 | /** @defgroup UART_Rx_Inv UART Advanced Feature RX Pin Active Level Inversion |
jhon309 | 0:666850d06c9f | 453 | * @{ |
jhon309 | 0:666850d06c9f | 454 | */ |
jhon309 | 0:666850d06c9f | 455 | #define UART_ADVFEATURE_RXINV_DISABLE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 456 | #define UART_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV) |
jhon309 | 0:666850d06c9f | 457 | #define IS_UART_ADVFEATURE_RXINV(RXINV) (((RXINV) == UART_ADVFEATURE_RXINV_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 458 | ((RXINV) == UART_ADVFEATURE_RXINV_ENABLE)) |
jhon309 | 0:666850d06c9f | 459 | /** |
jhon309 | 0:666850d06c9f | 460 | * @} |
jhon309 | 0:666850d06c9f | 461 | */ |
jhon309 | 0:666850d06c9f | 462 | |
jhon309 | 0:666850d06c9f | 463 | /** @defgroup UART_Data_Inv UART Advanced Feature Binary Data Inversion |
jhon309 | 0:666850d06c9f | 464 | * @{ |
jhon309 | 0:666850d06c9f | 465 | */ |
jhon309 | 0:666850d06c9f | 466 | #define UART_ADVFEATURE_DATAINV_DISABLE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 467 | #define UART_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV) |
jhon309 | 0:666850d06c9f | 468 | #define IS_UART_ADVFEATURE_DATAINV(DATAINV) (((DATAINV) == UART_ADVFEATURE_DATAINV_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 469 | ((DATAINV) == UART_ADVFEATURE_DATAINV_ENABLE)) |
jhon309 | 0:666850d06c9f | 470 | /** |
jhon309 | 0:666850d06c9f | 471 | * @} |
jhon309 | 0:666850d06c9f | 472 | */ |
jhon309 | 0:666850d06c9f | 473 | |
jhon309 | 0:666850d06c9f | 474 | /** @defgroup UART_Rx_Tx_Swap UART Advanced Feature RX TX Pins Swap |
jhon309 | 0:666850d06c9f | 475 | * @{ |
jhon309 | 0:666850d06c9f | 476 | */ |
jhon309 | 0:666850d06c9f | 477 | #define UART_ADVFEATURE_SWAP_DISABLE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 478 | #define UART_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP) |
jhon309 | 0:666850d06c9f | 479 | #define IS_UART_ADVFEATURE_SWAP(SWAP) (((SWAP) == UART_ADVFEATURE_SWAP_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 480 | ((SWAP) == UART_ADVFEATURE_SWAP_ENABLE)) |
jhon309 | 0:666850d06c9f | 481 | /** |
jhon309 | 0:666850d06c9f | 482 | * @} |
jhon309 | 0:666850d06c9f | 483 | */ |
jhon309 | 0:666850d06c9f | 484 | |
jhon309 | 0:666850d06c9f | 485 | /** @defgroup UART_Overrun_Disable UART Advanced Feature Overrun Disable |
jhon309 | 0:666850d06c9f | 486 | * @{ |
jhon309 | 0:666850d06c9f | 487 | */ |
jhon309 | 0:666850d06c9f | 488 | #define UART_ADVFEATURE_OVERRUN_ENABLE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 489 | #define UART_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS) |
jhon309 | 0:666850d06c9f | 490 | #define IS_UART_OVERRUN(OVERRUN) (((OVERRUN) == UART_ADVFEATURE_OVERRUN_ENABLE) || \ |
jhon309 | 0:666850d06c9f | 491 | ((OVERRUN) == UART_ADVFEATURE_OVERRUN_DISABLE)) |
jhon309 | 0:666850d06c9f | 492 | /** |
jhon309 | 0:666850d06c9f | 493 | * @} |
jhon309 | 0:666850d06c9f | 494 | */ |
jhon309 | 0:666850d06c9f | 495 | |
jhon309 | 0:666850d06c9f | 496 | /** @defgroup UART_AutoBaudRate_Enable UART Advanced Feature Auto BaudRate Enable |
jhon309 | 0:666850d06c9f | 497 | * @{ |
jhon309 | 0:666850d06c9f | 498 | */ |
jhon309 | 0:666850d06c9f | 499 | #define UART_ADVFEATURE_AUTOBAUDRATE_DISABLE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 500 | #define UART_ADVFEATURE_AUTOBAUDRATE_ENABLE ((uint32_t)USART_CR2_ABREN) |
jhon309 | 0:666850d06c9f | 501 | #define IS_UART_ADVFEATURE_AUTOBAUDRATE(AUTOBAUDRATE) (((AUTOBAUDRATE) == UART_ADVFEATURE_AUTOBAUDRATE_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 502 | ((AUTOBAUDRATE) == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE)) |
jhon309 | 0:666850d06c9f | 503 | /** |
jhon309 | 0:666850d06c9f | 504 | * @} |
jhon309 | 0:666850d06c9f | 505 | */ |
jhon309 | 0:666850d06c9f | 506 | |
jhon309 | 0:666850d06c9f | 507 | /** @defgroup UART_DMA_Disable_on_Rx_Error UART Advanced Feature DMA Disable On Rx Error |
jhon309 | 0:666850d06c9f | 508 | * @{ |
jhon309 | 0:666850d06c9f | 509 | */ |
jhon309 | 0:666850d06c9f | 510 | #define UART_ADVFEATURE_DMA_ENABLEONRXERROR ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 511 | #define UART_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE) |
jhon309 | 0:666850d06c9f | 512 | #define IS_UART_ADVFEATURE_DMAONRXERROR(DMA) (((DMA) == UART_ADVFEATURE_DMA_ENABLEONRXERROR) || \ |
jhon309 | 0:666850d06c9f | 513 | ((DMA) == UART_ADVFEATURE_DMA_DISABLEONRXERROR)) |
jhon309 | 0:666850d06c9f | 514 | /** |
jhon309 | 0:666850d06c9f | 515 | * @} |
jhon309 | 0:666850d06c9f | 516 | */ |
jhon309 | 0:666850d06c9f | 517 | |
jhon309 | 0:666850d06c9f | 518 | /** @defgroup UART_MSB_First UART Advanced Feature MSB First |
jhon309 | 0:666850d06c9f | 519 | * @{ |
jhon309 | 0:666850d06c9f | 520 | */ |
jhon309 | 0:666850d06c9f | 521 | #define UART_ADVFEATURE_MSBFIRST_DISABLE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 522 | #define UART_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST) |
jhon309 | 0:666850d06c9f | 523 | #define IS_UART_ADVFEATURE_MSBFIRST(MSBFIRST) (((MSBFIRST) == UART_ADVFEATURE_MSBFIRST_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 524 | ((MSBFIRST) == UART_ADVFEATURE_MSBFIRST_ENABLE)) |
jhon309 | 0:666850d06c9f | 525 | /** |
jhon309 | 0:666850d06c9f | 526 | * @} |
jhon309 | 0:666850d06c9f | 527 | */ |
jhon309 | 0:666850d06c9f | 528 | |
jhon309 | 0:666850d06c9f | 529 | /** @defgroup UART_Mute_Mode UART Advanced Feature Mute Mode Enable |
jhon309 | 0:666850d06c9f | 530 | * @{ |
jhon309 | 0:666850d06c9f | 531 | */ |
jhon309 | 0:666850d06c9f | 532 | #define UART_ADVFEATURE_MUTEMODE_DISABLE ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 533 | #define UART_ADVFEATURE_MUTEMODE_ENABLE ((uint32_t)USART_CR1_MME) |
jhon309 | 0:666850d06c9f | 534 | #define IS_UART_MUTE_MODE(MUTE) (((MUTE) == UART_ADVFEATURE_MUTEMODE_DISABLE) || \ |
jhon309 | 0:666850d06c9f | 535 | ((MUTE) == UART_ADVFEATURE_MUTEMODE_ENABLE)) |
jhon309 | 0:666850d06c9f | 536 | /** |
jhon309 | 0:666850d06c9f | 537 | * @} |
jhon309 | 0:666850d06c9f | 538 | */ |
jhon309 | 0:666850d06c9f | 539 | |
jhon309 | 0:666850d06c9f | 540 | /** @defgroup UART_CR2_ADDRESS_LSB_POS UART Address-matching LSB Position In CR2 Register |
jhon309 | 0:666850d06c9f | 541 | * @{ |
jhon309 | 0:666850d06c9f | 542 | */ |
jhon309 | 0:666850d06c9f | 543 | #define UART_CR2_ADDRESS_LSB_POS ((uint32_t) 24) |
jhon309 | 0:666850d06c9f | 544 | /** |
jhon309 | 0:666850d06c9f | 545 | * @} |
jhon309 | 0:666850d06c9f | 546 | */ |
jhon309 | 0:666850d06c9f | 547 | |
jhon309 | 0:666850d06c9f | 548 | /** @defgroup UART_DriverEnable_Polarity UART DriverEnable Polarity |
jhon309 | 0:666850d06c9f | 549 | * @{ |
jhon309 | 0:666850d06c9f | 550 | */ |
jhon309 | 0:666850d06c9f | 551 | #define UART_DE_POLARITY_HIGH ((uint32_t)0x00000000) |
jhon309 | 0:666850d06c9f | 552 | #define UART_DE_POLARITY_LOW ((uint32_t)USART_CR3_DEP) |
jhon309 | 0:666850d06c9f | 553 | #define IS_UART_DE_POLARITY(POLARITY) (((POLARITY) == UART_DE_POLARITY_HIGH) || \ |
jhon309 | 0:666850d06c9f | 554 | ((POLARITY) == UART_DE_POLARITY_LOW)) |
jhon309 | 0:666850d06c9f | 555 | /** |
jhon309 | 0:666850d06c9f | 556 | * @} |
jhon309 | 0:666850d06c9f | 557 | */ |
jhon309 | 0:666850d06c9f | 558 | |
jhon309 | 0:666850d06c9f | 559 | /** @defgroup UART_CR1_DEAT_ADDRESS_LSB_POS UART Driver Enable Assertion Time LSB Position In CR1 Register |
jhon309 | 0:666850d06c9f | 560 | * @{ |
jhon309 | 0:666850d06c9f | 561 | */ |
jhon309 | 0:666850d06c9f | 562 | #define UART_CR1_DEAT_ADDRESS_LSB_POS ((uint32_t) 21) |
jhon309 | 0:666850d06c9f | 563 | /** |
jhon309 | 0:666850d06c9f | 564 | * @} |
jhon309 | 0:666850d06c9f | 565 | */ |
jhon309 | 0:666850d06c9f | 566 | |
jhon309 | 0:666850d06c9f | 567 | /** @defgroup UART_CR1_DEDT_ADDRESS_LSB_POS UART Driver Enable DeAssertion Time LSB Position In CR1 Register |
jhon309 | 0:666850d06c9f | 568 | * @{ |
jhon309 | 0:666850d06c9f | 569 | */ |
jhon309 | 0:666850d06c9f | 570 | #define UART_CR1_DEDT_ADDRESS_LSB_POS ((uint32_t) 16) |
jhon309 | 0:666850d06c9f | 571 | /** |
jhon309 | 0:666850d06c9f | 572 | * @} |
jhon309 | 0:666850d06c9f | 573 | */ |
jhon309 | 0:666850d06c9f | 574 | |
jhon309 | 0:666850d06c9f | 575 | /** @defgroup UART_Interruption_Mask UART Interruptions Flag Mask |
jhon309 | 0:666850d06c9f | 576 | * @{ |
jhon309 | 0:666850d06c9f | 577 | */ |
jhon309 | 0:666850d06c9f | 578 | #define UART_IT_MASK ((uint32_t)0x001F) |
jhon309 | 0:666850d06c9f | 579 | /** |
jhon309 | 0:666850d06c9f | 580 | * @} |
jhon309 | 0:666850d06c9f | 581 | */ |
jhon309 | 0:666850d06c9f | 582 | |
jhon309 | 0:666850d06c9f | 583 | /** @defgroup UART_TimeOut_Value UART polling-based communications time-out value |
jhon309 | 0:666850d06c9f | 584 | * @{ |
jhon309 | 0:666850d06c9f | 585 | */ |
jhon309 | 0:666850d06c9f | 586 | #define HAL_UART_TIMEOUT_VALUE 0x1FFFFFF |
jhon309 | 0:666850d06c9f | 587 | /** |
jhon309 | 0:666850d06c9f | 588 | * @} |
jhon309 | 0:666850d06c9f | 589 | */ |
jhon309 | 0:666850d06c9f | 590 | |
jhon309 | 0:666850d06c9f | 591 | /** |
jhon309 | 0:666850d06c9f | 592 | * @} |
jhon309 | 0:666850d06c9f | 593 | */ |
jhon309 | 0:666850d06c9f | 594 | |
jhon309 | 0:666850d06c9f | 595 | /* Exported macro ------------------------------------------------------------*/ |
jhon309 | 0:666850d06c9f | 596 | /** @defgroup UART_Exported_Macros UART Exported Macros |
jhon309 | 0:666850d06c9f | 597 | * @{ |
jhon309 | 0:666850d06c9f | 598 | */ |
jhon309 | 0:666850d06c9f | 599 | |
jhon309 | 0:666850d06c9f | 600 | /** @brief Reset UART handle state |
jhon309 | 0:666850d06c9f | 601 | * @param __HANDLE__: UART handle. |
jhon309 | 0:666850d06c9f | 602 | * @retval None |
jhon309 | 0:666850d06c9f | 603 | */ |
jhon309 | 0:666850d06c9f | 604 | #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_UART_STATE_RESET) |
jhon309 | 0:666850d06c9f | 605 | |
jhon309 | 0:666850d06c9f | 606 | /** @brief Checks whether the specified UART flag is set or not. |
jhon309 | 0:666850d06c9f | 607 | * @param __HANDLE__: specifies the UART Handle. |
jhon309 | 0:666850d06c9f | 608 | * This parameter can be UARTx where x: 1, 2, 3 or 4 to select the USART or |
jhon309 | 0:666850d06c9f | 609 | * UART peripheral (datasheet: up to four USART/UARTs) |
jhon309 | 0:666850d06c9f | 610 | * @param __FLAG__: specifies the flag to check. |
jhon309 | 0:666850d06c9f | 611 | * This parameter can be one of the following values: |
jhon309 | 0:666850d06c9f | 612 | * @arg UART_FLAG_REACK: Receive enable ackowledge flag |
jhon309 | 0:666850d06c9f | 613 | * @arg UART_FLAG_TEACK: Transmit enable ackowledge flag |
jhon309 | 0:666850d06c9f | 614 | * @arg UART_FLAG_WUF: Wake up from stop mode flag (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 615 | * @arg UART_FLAG_RWU: Receiver wake up flag (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 616 | * @arg UART_FLAG_SBKF: Send Break flag |
jhon309 | 0:666850d06c9f | 617 | * @arg UART_FLAG_CMF: Character match flag |
jhon309 | 0:666850d06c9f | 618 | * @arg UART_FLAG_BUSY: Busy flag |
jhon309 | 0:666850d06c9f | 619 | * @arg UART_FLAG_ABRF: Auto Baud rate detection flag |
jhon309 | 0:666850d06c9f | 620 | * @arg UART_FLAG_ABRE: Auto Baud rate detection error flag |
jhon309 | 0:666850d06c9f | 621 | * @arg UART_FLAG_EOBF: End of block flag (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 622 | * @arg UART_FLAG_RTOF: Receiver timeout flag |
jhon309 | 0:666850d06c9f | 623 | * @arg UART_FLAG_CTS: CTS Change flag |
jhon309 | 0:666850d06c9f | 624 | * @arg UART_FLAG_LBD: LIN Break detection flag (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 625 | * @arg UART_FLAG_TXE: Transmit data register empty flag |
jhon309 | 0:666850d06c9f | 626 | * @arg UART_FLAG_TC: Transmission Complete flag |
jhon309 | 0:666850d06c9f | 627 | * @arg UART_FLAG_RXNE: Receive data register not empty flag |
jhon309 | 0:666850d06c9f | 628 | * @arg UART_FLAG_IDLE: Idle Line detection flag |
jhon309 | 0:666850d06c9f | 629 | * @arg UART_FLAG_ORE: OverRun Error flag |
jhon309 | 0:666850d06c9f | 630 | * @arg UART_FLAG_NE: Noise Error flag |
jhon309 | 0:666850d06c9f | 631 | * @arg UART_FLAG_FE: Framing Error flag |
jhon309 | 0:666850d06c9f | 632 | * @arg UART_FLAG_PE: Parity Error flag |
jhon309 | 0:666850d06c9f | 633 | * @retval The new state of __FLAG__ (TRUE or FALSE). |
jhon309 | 0:666850d06c9f | 634 | */ |
jhon309 | 0:666850d06c9f | 635 | #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__)) |
jhon309 | 0:666850d06c9f | 636 | |
jhon309 | 0:666850d06c9f | 637 | /** @brief Enables the specified UART interrupt. |
jhon309 | 0:666850d06c9f | 638 | * @param __HANDLE__: specifies the UART Handle. |
jhon309 | 0:666850d06c9f | 639 | * This parameter can be UARTx where x: 1, 2, 3 or 4 to select the USART or |
jhon309 | 0:666850d06c9f | 640 | * UART peripheral. (datasheet: up to four USART/UARTs) |
jhon309 | 0:666850d06c9f | 641 | * @param __INTERRUPT__: specifies the UART interrupt source to enable. |
jhon309 | 0:666850d06c9f | 642 | * This parameter can be one of the following values: |
jhon309 | 0:666850d06c9f | 643 | * @arg UART_IT_WUF: Wakeup from stop mode interrupt (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 644 | * @arg UART_IT_CM: Character match interrupt |
jhon309 | 0:666850d06c9f | 645 | * @arg UART_IT_CTS: CTS change interrupt |
jhon309 | 0:666850d06c9f | 646 | * @arg UART_IT_LBD: LIN Break detection interrupt (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 647 | * @arg UART_IT_TXE: Transmit Data Register empty interrupt |
jhon309 | 0:666850d06c9f | 648 | * @arg UART_IT_TC: Transmission complete interrupt |
jhon309 | 0:666850d06c9f | 649 | * @arg UART_IT_RXNE: Receive Data register not empty interrupt |
jhon309 | 0:666850d06c9f | 650 | * @arg UART_IT_IDLE: Idle line detection interrupt |
jhon309 | 0:666850d06c9f | 651 | * @arg UART_IT_PE: Parity Error interrupt |
jhon309 | 0:666850d06c9f | 652 | * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) |
jhon309 | 0:666850d06c9f | 653 | * @retval None |
jhon309 | 0:666850d06c9f | 654 | */ |
jhon309 | 0:666850d06c9f | 655 | #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \ |
jhon309 | 0:666850d06c9f | 656 | ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \ |
jhon309 | 0:666850d06c9f | 657 | ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & UART_IT_MASK)))) |
jhon309 | 0:666850d06c9f | 658 | |
jhon309 | 0:666850d06c9f | 659 | |
jhon309 | 0:666850d06c9f | 660 | /** @brief Disables the specified UART interrupt. |
jhon309 | 0:666850d06c9f | 661 | * @param __HANDLE__: specifies the UART Handle. |
jhon309 | 0:666850d06c9f | 662 | * This parameter can be UARTx where x: 1, 2, 3 or 4 to select the USART or |
jhon309 | 0:666850d06c9f | 663 | * UART peripheral. (datasheet: up to four USART/UARTs) |
jhon309 | 0:666850d06c9f | 664 | * @param __INTERRUPT__: specifies the UART interrupt source to disable. |
jhon309 | 0:666850d06c9f | 665 | * This parameter can be one of the following values: |
jhon309 | 0:666850d06c9f | 666 | * @arg UART_IT_WUF: Wakeup from stop mode interrupt (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 667 | * @arg UART_IT_CM: Character match interrupt |
jhon309 | 0:666850d06c9f | 668 | * @arg UART_IT_CTS: CTS change interrupt |
jhon309 | 0:666850d06c9f | 669 | * @arg UART_IT_LBD: LIN Break detection interrupt (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 670 | * @arg UART_IT_TXE: Transmit Data Register empty interrupt |
jhon309 | 0:666850d06c9f | 671 | * @arg UART_IT_TC: Transmission complete interrupt |
jhon309 | 0:666850d06c9f | 672 | * @arg UART_IT_RXNE: Receive Data register not empty interrupt |
jhon309 | 0:666850d06c9f | 673 | * @arg UART_IT_IDLE: Idle line detection interrupt |
jhon309 | 0:666850d06c9f | 674 | * @arg UART_IT_PE: Parity Error interrupt |
jhon309 | 0:666850d06c9f | 675 | * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) |
jhon309 | 0:666850d06c9f | 676 | * @retval None |
jhon309 | 0:666850d06c9f | 677 | */ |
jhon309 | 0:666850d06c9f | 678 | #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \ |
jhon309 | 0:666850d06c9f | 679 | ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \ |
jhon309 | 0:666850d06c9f | 680 | ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK)))) |
jhon309 | 0:666850d06c9f | 681 | |
jhon309 | 0:666850d06c9f | 682 | /** @brief Checks whether the specified UART interrupt has occurred or not. |
jhon309 | 0:666850d06c9f | 683 | * @param __HANDLE__: specifies the UART Handle. |
jhon309 | 0:666850d06c9f | 684 | * This parameter can be UARTx where x: 1, 2, 3 or 4 to select the USART or |
jhon309 | 0:666850d06c9f | 685 | * UART peripheral. (datasheet: up to four USART/UARTs) |
jhon309 | 0:666850d06c9f | 686 | * @param __IT__: specifies the UART interrupt to check. |
jhon309 | 0:666850d06c9f | 687 | * This parameter can be one of the following values: |
jhon309 | 0:666850d06c9f | 688 | * @arg UART_IT_WUF: Wakeup from stop mode interrupt (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 689 | * @arg UART_IT_CM: Character match interrupt |
jhon309 | 0:666850d06c9f | 690 | * @arg UART_IT_CTS: CTS change interrupt |
jhon309 | 0:666850d06c9f | 691 | * @arg UART_IT_LBD: LIN Break detection interrupt (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 692 | * @arg UART_IT_TXE: Transmit Data Register empty interrupt |
jhon309 | 0:666850d06c9f | 693 | * @arg UART_IT_TC: Transmission complete interrupt |
jhon309 | 0:666850d06c9f | 694 | * @arg UART_IT_RXNE: Receive Data register not empty interrupt |
jhon309 | 0:666850d06c9f | 695 | * @arg UART_IT_IDLE: Idle line detection interrupt |
jhon309 | 0:666850d06c9f | 696 | * @arg UART_IT_ORE: OverRun Error interrupt |
jhon309 | 0:666850d06c9f | 697 | * @arg UART_IT_NE: Noise Error interrupt |
jhon309 | 0:666850d06c9f | 698 | * @arg UART_IT_FE: Framing Error interrupt |
jhon309 | 0:666850d06c9f | 699 | * @arg UART_IT_PE: Parity Error interrupt |
jhon309 | 0:666850d06c9f | 700 | * @retval The new state of __IT__ (TRUE or FALSE). |
jhon309 | 0:666850d06c9f | 701 | */ |
jhon309 | 0:666850d06c9f | 702 | #define __HAL_UART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08))) |
jhon309 | 0:666850d06c9f | 703 | |
jhon309 | 0:666850d06c9f | 704 | /** @brief Checks whether the specified UART interrupt source is enabled. |
jhon309 | 0:666850d06c9f | 705 | * @param __HANDLE__: specifies the UART Handle. |
jhon309 | 0:666850d06c9f | 706 | * This parameter can be UARTx where x: 1, 2, 3 or 4 to select the USART or |
jhon309 | 0:666850d06c9f | 707 | * UART peripheral. (datasheet: up to four USART/UARTs) |
jhon309 | 0:666850d06c9f | 708 | * @param __IT__: specifies the UART interrupt source to check. |
jhon309 | 0:666850d06c9f | 709 | * This parameter can be one of the following values: |
jhon309 | 0:666850d06c9f | 710 | * @arg UART_IT_WUF: Wakeup from stop mode interrupt (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 711 | * @arg UART_IT_CM: Character match interrupt |
jhon309 | 0:666850d06c9f | 712 | * @arg UART_IT_CTS: CTS change interrupt |
jhon309 | 0:666850d06c9f | 713 | * @arg UART_IT_LBD: LIN Break detection interrupt (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 714 | * @arg UART_IT_TXE: Transmit Data Register empty interrupt |
jhon309 | 0:666850d06c9f | 715 | * @arg UART_IT_TC: Transmission complete interrupt |
jhon309 | 0:666850d06c9f | 716 | * @arg UART_IT_RXNE: Receive Data register not empty interrupt |
jhon309 | 0:666850d06c9f | 717 | * @arg UART_IT_IDLE: Idle line detection interrupt |
jhon309 | 0:666850d06c9f | 718 | * @arg UART_IT_ORE: OverRun Error interrupt |
jhon309 | 0:666850d06c9f | 719 | * @arg UART_IT_NE: Noise Error interrupt |
jhon309 | 0:666850d06c9f | 720 | * @arg UART_IT_FE: Framing Error interrupt |
jhon309 | 0:666850d06c9f | 721 | * @arg UART_IT_PE: Parity Error interrupt |
jhon309 | 0:666850d06c9f | 722 | * @retval The new state of __IT__ (TRUE or FALSE). |
jhon309 | 0:666850d06c9f | 723 | */ |
jhon309 | 0:666850d06c9f | 724 | #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2)? \ |
jhon309 | 0:666850d06c9f | 725 | (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & UART_IT_MASK))) |
jhon309 | 0:666850d06c9f | 726 | |
jhon309 | 0:666850d06c9f | 727 | /** @brief Clears the specified UART ISR flag, in setting the proper ICR register flag. |
jhon309 | 0:666850d06c9f | 728 | * @param __HANDLE__: specifies the UART Handle. |
jhon309 | 0:666850d06c9f | 729 | * This parameter can be UARTx where x: 1, 2, 3 or 4 to select the USART or |
jhon309 | 0:666850d06c9f | 730 | * UART peripheral. (datasheet: up to four USART/UARTs) |
jhon309 | 0:666850d06c9f | 731 | * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set |
jhon309 | 0:666850d06c9f | 732 | * to clear the corresponding interrupt |
jhon309 | 0:666850d06c9f | 733 | * This parameter can be one of the following values: |
jhon309 | 0:666850d06c9f | 734 | * @arg UART_CLEAR_PEF: Parity Error Clear Flag |
jhon309 | 0:666850d06c9f | 735 | * @arg UART_CLEAR_FEF: Framing Error Clear Flag |
jhon309 | 0:666850d06c9f | 736 | * @arg UART_CLEAR_NEF: Noise detected Clear Flag |
jhon309 | 0:666850d06c9f | 737 | * @arg UART_CLEAR_OREF: OverRun Error Clear Flag |
jhon309 | 0:666850d06c9f | 738 | * @arg UART_CLEAR_IDLEF: IDLE line detected Clear Flag |
jhon309 | 0:666850d06c9f | 739 | * @arg UART_CLEAR_TCF: Transmission Complete Clear Flag |
jhon309 | 0:666850d06c9f | 740 | * @arg UART_CLEAR_LBDF: LIN Break Detection Clear Flag (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 741 | * @arg UART_CLEAR_CTSF: CTS Interrupt Clear Flag |
jhon309 | 0:666850d06c9f | 742 | * @arg UART_CLEAR_RTOF: Receiver Time Out Clear Flag |
jhon309 | 0:666850d06c9f | 743 | * @arg UART_CLEAR_EOBF: End Of Block Clear Flag (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 744 | * @arg UART_CLEAR_CMF: Character Match Clear Flag |
jhon309 | 0:666850d06c9f | 745 | * @arg UART_CLEAR_WUF: Wake Up from stop mode Clear Flag (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 746 | * @retval None |
jhon309 | 0:666850d06c9f | 747 | */ |
jhon309 | 0:666850d06c9f | 748 | #define __HAL_UART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__)) |
jhon309 | 0:666850d06c9f | 749 | |
jhon309 | 0:666850d06c9f | 750 | /** @brief Set a specific UART request flag. |
jhon309 | 0:666850d06c9f | 751 | * @param __HANDLE__: specifies the UART Handle. |
jhon309 | 0:666850d06c9f | 752 | * This parameter can be UARTx where x: 1, 2, 3 or 4 to select the USART or |
jhon309 | 0:666850d06c9f | 753 | * UART peripheral. (datasheet: up to four USART/UARTs) |
jhon309 | 0:666850d06c9f | 754 | * @param __REQ__: specifies the request flag to set |
jhon309 | 0:666850d06c9f | 755 | * This parameter can be one of the following values: |
jhon309 | 0:666850d06c9f | 756 | * @arg UART_AUTOBAUD_REQUEST: Auto-Baud Rate Request |
jhon309 | 0:666850d06c9f | 757 | * @arg UART_SENDBREAK_REQUEST: Send Break Request |
jhon309 | 0:666850d06c9f | 758 | * @arg UART_MUTE_MODE_REQUEST: Mute Mode Request |
jhon309 | 0:666850d06c9f | 759 | * @arg UART_RXDATA_FLUSH_REQUEST: Receive Data flush Request |
jhon309 | 0:666850d06c9f | 760 | * @arg UART_TXDATA_FLUSH_REQUEST: Transmit data flush Request (not available on F030xx devices) |
jhon309 | 0:666850d06c9f | 761 | * @retval None |
jhon309 | 0:666850d06c9f | 762 | */ |
jhon309 | 0:666850d06c9f | 763 | #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__)) |
jhon309 | 0:666850d06c9f | 764 | |
jhon309 | 0:666850d06c9f | 765 | /** @brief Enable UART |
jhon309 | 0:666850d06c9f | 766 | * @param __HANDLE__: specifies the UART Handle. |
jhon309 | 0:666850d06c9f | 767 | * The Handle Instance can be UARTx where x: 1, 2, 3, 4 or 5 to select the UART peripheral |
jhon309 | 0:666850d06c9f | 768 | * @retval None |
jhon309 | 0:666850d06c9f | 769 | */ |
jhon309 | 0:666850d06c9f | 770 | #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE) |
jhon309 | 0:666850d06c9f | 771 | |
jhon309 | 0:666850d06c9f | 772 | /** @brief Disable UART |
jhon309 | 0:666850d06c9f | 773 | * @param __HANDLE__: specifies the UART Handle. |
jhon309 | 0:666850d06c9f | 774 | * The Handle Instance can be UARTx where x: 1, 2, 3, 4 or 5 to select the UART peripheral |
jhon309 | 0:666850d06c9f | 775 | * @retval None |
jhon309 | 0:666850d06c9f | 776 | */ |
jhon309 | 0:666850d06c9f | 777 | #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE) |
jhon309 | 0:666850d06c9f | 778 | |
jhon309 | 0:666850d06c9f | 779 | /** |
jhon309 | 0:666850d06c9f | 780 | * @} |
jhon309 | 0:666850d06c9f | 781 | */ |
jhon309 | 0:666850d06c9f | 782 | |
jhon309 | 0:666850d06c9f | 783 | /* Private macros --------------------------------------------------------*/ |
jhon309 | 0:666850d06c9f | 784 | /** @defgroup UART_Private_Macros UART Private Macros |
jhon309 | 0:666850d06c9f | 785 | * @{ |
jhon309 | 0:666850d06c9f | 786 | */ |
jhon309 | 0:666850d06c9f | 787 | |
jhon309 | 0:666850d06c9f | 788 | /** @brief BRR division operation to set BRR register in 8-bit oversampling mode |
jhon309 | 0:666850d06c9f | 789 | * @param _PCLK_: UART clock |
jhon309 | 0:666850d06c9f | 790 | * @param _BAUD_: Baud rate set by the user |
jhon309 | 0:666850d06c9f | 791 | * @retval Division result |
jhon309 | 0:666850d06c9f | 792 | */ |
jhon309 | 0:666850d06c9f | 793 | #define __DIV_SAMPLING8(_PCLK_, _BAUD_) (((_PCLK_)*2)/((_BAUD_))) |
jhon309 | 0:666850d06c9f | 794 | |
jhon309 | 0:666850d06c9f | 795 | /** @brief BRR division operation to set BRR register in 16-bit oversampling mode |
jhon309 | 0:666850d06c9f | 796 | * @param _PCLK_: UART clock |
jhon309 | 0:666850d06c9f | 797 | * @param _BAUD_: Baud rate set by the user |
jhon309 | 0:666850d06c9f | 798 | * @retval Division result |
jhon309 | 0:666850d06c9f | 799 | */ |
jhon309 | 0:666850d06c9f | 800 | #define __DIV_SAMPLING16(_PCLK_, _BAUD_) (((_PCLK_))/((_BAUD_))) |
jhon309 | 0:666850d06c9f | 801 | |
jhon309 | 0:666850d06c9f | 802 | /** @brief Check UART Baud rate |
jhon309 | 0:666850d06c9f | 803 | * @param BAUDRATE: Baudrate specified by the user |
jhon309 | 0:666850d06c9f | 804 | * The maximum Baud Rate is derived from the maximum clock on F0 (i.e. 48 MHz) |
jhon309 | 0:666850d06c9f | 805 | * divided by the smallest oversampling used on the USART (i.e. 8) |
jhon309 | 0:666850d06c9f | 806 | * @retval Test result (TRUE or FALSE). |
jhon309 | 0:666850d06c9f | 807 | */ |
jhon309 | 0:666850d06c9f | 808 | #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 9000001) |
jhon309 | 0:666850d06c9f | 809 | |
jhon309 | 0:666850d06c9f | 810 | /** @brief Check UART assertion time |
jhon309 | 0:666850d06c9f | 811 | * @param TIME: 5-bit value assertion time |
jhon309 | 0:666850d06c9f | 812 | * @retval Test result (TRUE or FALSE). |
jhon309 | 0:666850d06c9f | 813 | */ |
jhon309 | 0:666850d06c9f | 814 | #define IS_UART_ASSERTIONTIME(TIME) ((TIME) <= 0x1F) |
jhon309 | 0:666850d06c9f | 815 | |
jhon309 | 0:666850d06c9f | 816 | /** @brief Check UART deassertion time |
jhon309 | 0:666850d06c9f | 817 | * @param TIME: 5-bit value deassertion time |
jhon309 | 0:666850d06c9f | 818 | * @retval Test result (TRUE or FALSE). |
jhon309 | 0:666850d06c9f | 819 | */ |
jhon309 | 0:666850d06c9f | 820 | #define IS_UART_DEASSERTIONTIME(TIME) ((TIME) <= 0x1F) |
jhon309 | 0:666850d06c9f | 821 | |
jhon309 | 0:666850d06c9f | 822 | /** |
jhon309 | 0:666850d06c9f | 823 | * @} |
jhon309 | 0:666850d06c9f | 824 | */ |
jhon309 | 0:666850d06c9f | 825 | |
jhon309 | 0:666850d06c9f | 826 | /* Include UART HAL Extension module */ |
jhon309 | 0:666850d06c9f | 827 | #include "stm32f0xx_hal_uart_ex.h" |
jhon309 | 0:666850d06c9f | 828 | |
jhon309 | 0:666850d06c9f | 829 | /* Exported functions --------------------------------------------------------*/ |
jhon309 | 0:666850d06c9f | 830 | |
jhon309 | 0:666850d06c9f | 831 | /** @addtogroup UART_Exported_Functions UART Exported Functions |
jhon309 | 0:666850d06c9f | 832 | * @{ |
jhon309 | 0:666850d06c9f | 833 | */ |
jhon309 | 0:666850d06c9f | 834 | |
jhon309 | 0:666850d06c9f | 835 | /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions |
jhon309 | 0:666850d06c9f | 836 | * @{ |
jhon309 | 0:666850d06c9f | 837 | */ |
jhon309 | 0:666850d06c9f | 838 | |
jhon309 | 0:666850d06c9f | 839 | /* Initialization and de-initialization functions ****************************/ |
jhon309 | 0:666850d06c9f | 840 | HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 841 | HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 842 | HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod); |
jhon309 | 0:666850d06c9f | 843 | HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 844 | void HAL_UART_MspInit(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 845 | void HAL_UART_MspDeInit(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 846 | |
jhon309 | 0:666850d06c9f | 847 | /** |
jhon309 | 0:666850d06c9f | 848 | * @} |
jhon309 | 0:666850d06c9f | 849 | */ |
jhon309 | 0:666850d06c9f | 850 | |
jhon309 | 0:666850d06c9f | 851 | /** @addtogroup UART_Exported_Functions_Group2 IO operation functions |
jhon309 | 0:666850d06c9f | 852 | * @{ |
jhon309 | 0:666850d06c9f | 853 | */ |
jhon309 | 0:666850d06c9f | 854 | |
jhon309 | 0:666850d06c9f | 855 | /* IO operation functions *****************************************************/ |
jhon309 | 0:666850d06c9f | 856 | HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
jhon309 | 0:666850d06c9f | 857 | HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
jhon309 | 0:666850d06c9f | 858 | HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
jhon309 | 0:666850d06c9f | 859 | HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
jhon309 | 0:666850d06c9f | 860 | HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
jhon309 | 0:666850d06c9f | 861 | HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
jhon309 | 0:666850d06c9f | 862 | HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 863 | HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 864 | HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 865 | void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 866 | void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 867 | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 868 | void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 869 | void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 870 | |
jhon309 | 0:666850d06c9f | 871 | /** |
jhon309 | 0:666850d06c9f | 872 | * @} |
jhon309 | 0:666850d06c9f | 873 | */ |
jhon309 | 0:666850d06c9f | 874 | |
jhon309 | 0:666850d06c9f | 875 | /** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions |
jhon309 | 0:666850d06c9f | 876 | * @{ |
jhon309 | 0:666850d06c9f | 877 | */ |
jhon309 | 0:666850d06c9f | 878 | |
jhon309 | 0:666850d06c9f | 879 | /* Peripheral Control functions ***********************************************/ |
jhon309 | 0:666850d06c9f | 880 | void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 881 | HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 882 | HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 883 | HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 884 | HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 885 | |
jhon309 | 0:666850d06c9f | 886 | /** |
jhon309 | 0:666850d06c9f | 887 | * @} |
jhon309 | 0:666850d06c9f | 888 | */ |
jhon309 | 0:666850d06c9f | 889 | |
jhon309 | 0:666850d06c9f | 890 | /** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Errors functions |
jhon309 | 0:666850d06c9f | 891 | * @{ |
jhon309 | 0:666850d06c9f | 892 | */ |
jhon309 | 0:666850d06c9f | 893 | |
jhon309 | 0:666850d06c9f | 894 | /* Peripheral State and Errors functions **************************************************/ |
jhon309 | 0:666850d06c9f | 895 | HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 896 | uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 897 | |
jhon309 | 0:666850d06c9f | 898 | /** |
jhon309 | 0:666850d06c9f | 899 | * @} |
jhon309 | 0:666850d06c9f | 900 | */ |
jhon309 | 0:666850d06c9f | 901 | |
jhon309 | 0:666850d06c9f | 902 | /** |
jhon309 | 0:666850d06c9f | 903 | * @} |
jhon309 | 0:666850d06c9f | 904 | */ |
jhon309 | 0:666850d06c9f | 905 | |
jhon309 | 0:666850d06c9f | 906 | /** @addtogroup UART_Private_Functions |
jhon309 | 0:666850d06c9f | 907 | * @{ |
jhon309 | 0:666850d06c9f | 908 | */ |
jhon309 | 0:666850d06c9f | 909 | void UART_AdvFeatureConfig(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 910 | HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 911 | HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 912 | HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 913 | HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart); |
jhon309 | 0:666850d06c9f | 914 | HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Timeout); |
jhon309 | 0:666850d06c9f | 915 | /** |
jhon309 | 0:666850d06c9f | 916 | * @} |
jhon309 | 0:666850d06c9f | 917 | */ |
jhon309 | 0:666850d06c9f | 918 | |
jhon309 | 0:666850d06c9f | 919 | /** |
jhon309 | 0:666850d06c9f | 920 | * @} |
jhon309 | 0:666850d06c9f | 921 | */ |
jhon309 | 0:666850d06c9f | 922 | |
jhon309 | 0:666850d06c9f | 923 | /** |
jhon309 | 0:666850d06c9f | 924 | * @} |
jhon309 | 0:666850d06c9f | 925 | */ |
jhon309 | 0:666850d06c9f | 926 | |
jhon309 | 0:666850d06c9f | 927 | #ifdef __cplusplus |
jhon309 | 0:666850d06c9f | 928 | } |
jhon309 | 0:666850d06c9f | 929 | #endif |
jhon309 | 0:666850d06c9f | 930 | |
jhon309 | 0:666850d06c9f | 931 | #endif /* __STM32F0xx_HAL_UART_H */ |
jhon309 | 0:666850d06c9f | 932 | |
jhon309 | 0:666850d06c9f | 933 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
jhon309 | 0:666850d06c9f | 934 |