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