mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F334R8/stm32f3xx_hal_uart.c@237:f3da66175598, 2014-06-24 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Jun 24 14:45:08 2014 +0100
- Revision:
- 237:f3da66175598
- Child:
- 375:3d36234a1087
Synchronized with git revision 8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7
Full URL: https://github.com/mbedmicro/mbed/commit/8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7/
[NUCLEO_F334R8] Add platform files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 237:f3da66175598 | 1 | /** |
mbed_official | 237:f3da66175598 | 2 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 3 | * @file stm32f3xx_hal_uart.c |
mbed_official | 237:f3da66175598 | 4 | * @author MCD Application Team |
mbed_official | 237:f3da66175598 | 5 | * @version V1.0.1 |
mbed_official | 237:f3da66175598 | 6 | * @date 18-June-2014 |
mbed_official | 237:f3da66175598 | 7 | * @brief UART HAL module driver. |
mbed_official | 237:f3da66175598 | 8 | * |
mbed_official | 237:f3da66175598 | 9 | * This file provides firmware functions to manage the following |
mbed_official | 237:f3da66175598 | 10 | * functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART). |
mbed_official | 237:f3da66175598 | 11 | * + Initialization and de-initialization functions |
mbed_official | 237:f3da66175598 | 12 | * + IO operation functions |
mbed_official | 237:f3da66175598 | 13 | * + Peripheral Control functions |
mbed_official | 237:f3da66175598 | 14 | * |
mbed_official | 237:f3da66175598 | 15 | * |
mbed_official | 237:f3da66175598 | 16 | @verbatim |
mbed_official | 237:f3da66175598 | 17 | =============================================================================== |
mbed_official | 237:f3da66175598 | 18 | ##### How to use this driver ##### |
mbed_official | 237:f3da66175598 | 19 | =============================================================================== |
mbed_official | 237:f3da66175598 | 20 | [..] |
mbed_official | 237:f3da66175598 | 21 | The UART HAL driver can be used as follows: |
mbed_official | 237:f3da66175598 | 22 | |
mbed_official | 237:f3da66175598 | 23 | (#) Declare a UART_HandleTypeDef handle structure. |
mbed_official | 237:f3da66175598 | 24 | (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit ()API: |
mbed_official | 237:f3da66175598 | 25 | (##) Enable the USARTx interface clock. |
mbed_official | 237:f3da66175598 | 26 | (##) UART pins configuration: |
mbed_official | 237:f3da66175598 | 27 | (+) Enable the clock for the UART GPIOs. |
mbed_official | 237:f3da66175598 | 28 | (+) Configure these UART pins as alternate function pull-up. |
mbed_official | 237:f3da66175598 | 29 | (##) NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT() |
mbed_official | 237:f3da66175598 | 30 | and HAL_UART_Receive_IT() APIs): |
mbed_official | 237:f3da66175598 | 31 | (+) Configure the USARTx interrupt priority. |
mbed_official | 237:f3da66175598 | 32 | (+) Enable the NVIC USART IRQ handle. |
mbed_official | 237:f3da66175598 | 33 | (@) The specific UART interrupts (Transmission complete interrupt, |
mbed_official | 237:f3da66175598 | 34 | RXNE interrupt and Error Interrupts) will be managed using the macros |
mbed_official | 237:f3da66175598 | 35 | __HAL_UART_ENABLE_IT() and __HAL_UART_DISABLE_IT() inside the transmit and receive process. |
mbed_official | 237:f3da66175598 | 36 | (##) DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA() |
mbed_official | 237:f3da66175598 | 37 | and HAL_UART_Receive_DMA() APIs): |
mbed_official | 237:f3da66175598 | 38 | (+) Declare a DMA handle structure for the Tx/Rx channel. |
mbed_official | 237:f3da66175598 | 39 | (+) Enable the DMAx interface clock. |
mbed_official | 237:f3da66175598 | 40 | (+) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
mbed_official | 237:f3da66175598 | 41 | (+) Configure the DMA Tx/Rx channel. |
mbed_official | 237:f3da66175598 | 42 | (+) Associate the initilalized DMA handle to the UART DMA Tx/Rx handle. |
mbed_official | 237:f3da66175598 | 43 | (+) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel. |
mbed_official | 237:f3da66175598 | 44 | |
mbed_official | 237:f3da66175598 | 45 | (#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware |
mbed_official | 237:f3da66175598 | 46 | flow control and Mode(Receiver/Transmitter) in the huart Init structure. |
mbed_official | 237:f3da66175598 | 47 | |
mbed_official | 237:f3da66175598 | 48 | (#) If required, program UART advanced features (TX/RX pins swap, auto Baud rate detection,...) |
mbed_official | 237:f3da66175598 | 49 | in the huart AdvancedInit structure. |
mbed_official | 237:f3da66175598 | 50 | |
mbed_official | 237:f3da66175598 | 51 | (#) For the UART asynchronous mode, initialize the UART registers by calling |
mbed_official | 237:f3da66175598 | 52 | the HAL_UART_Init() API. |
mbed_official | 237:f3da66175598 | 53 | |
mbed_official | 237:f3da66175598 | 54 | (#) For the UART Half duplex mode, initialize the UART registers by calling |
mbed_official | 237:f3da66175598 | 55 | the HAL_HalfDuplex_Init() API. |
mbed_official | 237:f3da66175598 | 56 | |
mbed_official | 237:f3da66175598 | 57 | (#) For the UART LIN (Local Interconnection Network) mode, initialize the UART registers |
mbed_official | 237:f3da66175598 | 58 | by calling the HAL_LIN_Init() API. |
mbed_official | 237:f3da66175598 | 59 | |
mbed_official | 237:f3da66175598 | 60 | (#) For the UART Multiprocessor mode, initialize the UART registers |
mbed_official | 237:f3da66175598 | 61 | by calling the HAL_MultiProcessor_Init() API. |
mbed_official | 237:f3da66175598 | 62 | |
mbed_official | 237:f3da66175598 | 63 | (#) For the UART RS485 Driver Enabled mode, initialize the UART registers |
mbed_official | 237:f3da66175598 | 64 | by calling the HAL_RS485Ex_Init() API. |
mbed_official | 237:f3da66175598 | 65 | |
mbed_official | 237:f3da66175598 | 66 | (@) These API's(HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init(), HAL_MultiProcessor_Init(), |
mbed_official | 237:f3da66175598 | 67 | also configure also the low level Hardware GPIO, CLOCK, CORTEX...etc) by |
mbed_official | 237:f3da66175598 | 68 | calling the customized HAL_UART_MspInit() API. |
mbed_official | 237:f3da66175598 | 69 | |
mbed_official | 237:f3da66175598 | 70 | @endverbatim |
mbed_official | 237:f3da66175598 | 71 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 72 | * @attention |
mbed_official | 237:f3da66175598 | 73 | * |
mbed_official | 237:f3da66175598 | 74 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 237:f3da66175598 | 75 | * |
mbed_official | 237:f3da66175598 | 76 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 237:f3da66175598 | 77 | * are permitted provided that the following conditions are met: |
mbed_official | 237:f3da66175598 | 78 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 237:f3da66175598 | 79 | * this list of conditions and the following disclaimer. |
mbed_official | 237:f3da66175598 | 80 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 237:f3da66175598 | 81 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 237:f3da66175598 | 82 | * and/or other materials provided with the distribution. |
mbed_official | 237:f3da66175598 | 83 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 237:f3da66175598 | 84 | * may be used to endorse or promote products derived from this software |
mbed_official | 237:f3da66175598 | 85 | * without specific prior written permission. |
mbed_official | 237:f3da66175598 | 86 | * |
mbed_official | 237:f3da66175598 | 87 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 237:f3da66175598 | 88 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 237:f3da66175598 | 89 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 237:f3da66175598 | 90 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 237:f3da66175598 | 91 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 237:f3da66175598 | 92 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 237:f3da66175598 | 93 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 237:f3da66175598 | 94 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 237:f3da66175598 | 95 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 237:f3da66175598 | 96 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 237:f3da66175598 | 97 | * |
mbed_official | 237:f3da66175598 | 98 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 99 | */ |
mbed_official | 237:f3da66175598 | 100 | |
mbed_official | 237:f3da66175598 | 101 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 102 | #include "stm32f3xx_hal.h" |
mbed_official | 237:f3da66175598 | 103 | |
mbed_official | 237:f3da66175598 | 104 | /** @addtogroup STM32F3xx_HAL_Driver |
mbed_official | 237:f3da66175598 | 105 | * @{ |
mbed_official | 237:f3da66175598 | 106 | */ |
mbed_official | 237:f3da66175598 | 107 | |
mbed_official | 237:f3da66175598 | 108 | /** @defgroup UART |
mbed_official | 237:f3da66175598 | 109 | * @brief HAL UART module driver |
mbed_official | 237:f3da66175598 | 110 | * @{ |
mbed_official | 237:f3da66175598 | 111 | */ |
mbed_official | 237:f3da66175598 | 112 | #ifdef HAL_UART_MODULE_ENABLED |
mbed_official | 237:f3da66175598 | 113 | |
mbed_official | 237:f3da66175598 | 114 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 115 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 116 | #define HAL_UART_TXDMA_TIMEOUTVALUE 22000 |
mbed_official | 237:f3da66175598 | 117 | #define UART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | \ |
mbed_official | 237:f3da66175598 | 118 | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8)) |
mbed_official | 237:f3da66175598 | 119 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 120 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 121 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 122 | static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 123 | static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 124 | static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 125 | static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 126 | static void UART_DMAError(DMA_HandleTypeDef *hdma); |
mbed_official | 237:f3da66175598 | 127 | static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart); |
mbed_official | 237:f3da66175598 | 128 | static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart); |
mbed_official | 237:f3da66175598 | 129 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 130 | |
mbed_official | 237:f3da66175598 | 131 | /** @defgroup UART_Private_Functions |
mbed_official | 237:f3da66175598 | 132 | * @{ |
mbed_official | 237:f3da66175598 | 133 | */ |
mbed_official | 237:f3da66175598 | 134 | |
mbed_official | 237:f3da66175598 | 135 | /** @defgroup HAL_UART_Group1 Initialization/de-initialization functions |
mbed_official | 237:f3da66175598 | 136 | * @brief Initialization and Configuration functions |
mbed_official | 237:f3da66175598 | 137 | * |
mbed_official | 237:f3da66175598 | 138 | @verbatim |
mbed_official | 237:f3da66175598 | 139 | =============================================================================== |
mbed_official | 237:f3da66175598 | 140 | ##### Initialization and Configuration functions ##### |
mbed_official | 237:f3da66175598 | 141 | =============================================================================== |
mbed_official | 237:f3da66175598 | 142 | [..] |
mbed_official | 237:f3da66175598 | 143 | This subsection provides a set of functions allowing to initialize the USARTx or the UARTy |
mbed_official | 237:f3da66175598 | 144 | in asynchronous mode. |
mbed_official | 237:f3da66175598 | 145 | (+) For the asynchronous mode the parameters below can be configured: |
mbed_official | 237:f3da66175598 | 146 | (++) Baud Rate |
mbed_official | 237:f3da66175598 | 147 | (++) Word Length |
mbed_official | 237:f3da66175598 | 148 | (++) Stop Bit |
mbed_official | 237:f3da66175598 | 149 | (++) Parity: If the parity is enabled, then the MSB bit of the data written |
mbed_official | 237:f3da66175598 | 150 | in the data register is transmitted but is changed by the parity bit. |
mbed_official | 237:f3da66175598 | 151 | Depending on the frame length defined by the M bit (8-bits or 9-bits) |
mbed_official | 237:f3da66175598 | 152 | or by the M1 and M0 bits (7-bit, 8-bit or 9-bit), |
mbed_official | 237:f3da66175598 | 153 | the possible UART frame formats are as listed in the following table: |
mbed_official | 237:f3da66175598 | 154 | +---------------------------------------------------------------+ |
mbed_official | 237:f3da66175598 | 155 | | M bit | PCE bit | UART frame | |
mbed_official | 237:f3da66175598 | 156 | |-----------|-----------|---------------------------------------| |
mbed_official | 237:f3da66175598 | 157 | | 0 | 0 | | SB | 8-bit data | STB | | |
mbed_official | 237:f3da66175598 | 158 | |-----------|-----------|---------------------------------------| |
mbed_official | 237:f3da66175598 | 159 | | 0 | 1 | | SB | 7-bit data | PB | STB | | |
mbed_official | 237:f3da66175598 | 160 | |-----------|-----------|---------------------------------------| |
mbed_official | 237:f3da66175598 | 161 | | 1 | 0 | | SB | 9-bit data | STB | | |
mbed_official | 237:f3da66175598 | 162 | |-----------|-----------|---------------------------------------| |
mbed_official | 237:f3da66175598 | 163 | | 1 | 1 | | SB | 8-bit data | PB | STB | | |
mbed_official | 237:f3da66175598 | 164 | +---------------------------------------------------------------+ |
mbed_official | 237:f3da66175598 | 165 | | M1M0 bits | PCE bit | UART frame | |
mbed_official | 237:f3da66175598 | 166 | |-----------------------|---------------------------------------| |
mbed_official | 237:f3da66175598 | 167 | | 10 | 0 | | SB | 7-bit data | STB | | |
mbed_official | 237:f3da66175598 | 168 | |-----------|-----------|---------------------------------------| |
mbed_official | 237:f3da66175598 | 169 | | 10 | 1 | | SB | 6-bit data | PB | STB | | |
mbed_official | 237:f3da66175598 | 170 | +---------------------------------------------------------------+ |
mbed_official | 237:f3da66175598 | 171 | (++) Hardware flow control |
mbed_official | 237:f3da66175598 | 172 | (++) Receiver/transmitter modes |
mbed_official | 237:f3da66175598 | 173 | (++) Over Sampling Method |
mbed_official | 237:f3da66175598 | 174 | (++) One-Bit Sampling Method |
mbed_official | 237:f3da66175598 | 175 | (+) For the asynchronous mode, the following advanced features can be configured as well: |
mbed_official | 237:f3da66175598 | 176 | (++) TX and/or RX pin level inversion |
mbed_official | 237:f3da66175598 | 177 | (++) data logical level inversion |
mbed_official | 237:f3da66175598 | 178 | (++) RX and TX pins swap |
mbed_official | 237:f3da66175598 | 179 | (++) RX overrun detection disabling |
mbed_official | 237:f3da66175598 | 180 | (++) DMA disabling on RX error |
mbed_official | 237:f3da66175598 | 181 | (++) MSB first on communication line |
mbed_official | 237:f3da66175598 | 182 | (++) auto Baud rate detection |
mbed_official | 237:f3da66175598 | 183 | [..] |
mbed_official | 237:f3da66175598 | 184 | The HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init() and HAL_MultiProcessor_Init() |
mbed_official | 237:f3da66175598 | 185 | API follow respectively the UART asynchronous, UART Half duplex, UART LIN mode and |
mbed_official | 237:f3da66175598 | 186 | multiprocessor configuration procedures (details for the procedures are available in reference manual). |
mbed_official | 237:f3da66175598 | 187 | |
mbed_official | 237:f3da66175598 | 188 | @endverbatim |
mbed_official | 237:f3da66175598 | 189 | * @{ |
mbed_official | 237:f3da66175598 | 190 | */ |
mbed_official | 237:f3da66175598 | 191 | |
mbed_official | 237:f3da66175598 | 192 | /** |
mbed_official | 237:f3da66175598 | 193 | * @brief Initializes the UART mode according to the specified |
mbed_official | 237:f3da66175598 | 194 | * parameters in the UART_InitTypeDef and creates the associated handle . |
mbed_official | 237:f3da66175598 | 195 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 196 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 197 | */ |
mbed_official | 237:f3da66175598 | 198 | HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 199 | { |
mbed_official | 237:f3da66175598 | 200 | /* Check the UART handle allocation */ |
mbed_official | 237:f3da66175598 | 201 | if(huart == NULL) |
mbed_official | 237:f3da66175598 | 202 | { |
mbed_official | 237:f3da66175598 | 203 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 204 | } |
mbed_official | 237:f3da66175598 | 205 | |
mbed_official | 237:f3da66175598 | 206 | if(huart->Init.HwFlowCtl != UART_HWCONTROL_NONE) |
mbed_official | 237:f3da66175598 | 207 | { |
mbed_official | 237:f3da66175598 | 208 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 209 | assert_param(IS_UART_HWFLOW_INSTANCE(huart->Instance)); |
mbed_official | 237:f3da66175598 | 210 | } |
mbed_official | 237:f3da66175598 | 211 | else |
mbed_official | 237:f3da66175598 | 212 | { |
mbed_official | 237:f3da66175598 | 213 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 214 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
mbed_official | 237:f3da66175598 | 215 | } |
mbed_official | 237:f3da66175598 | 216 | |
mbed_official | 237:f3da66175598 | 217 | if(huart->State == HAL_UART_STATE_RESET) |
mbed_official | 237:f3da66175598 | 218 | { |
mbed_official | 237:f3da66175598 | 219 | /* Init the low level hardware : GPIO, CLOCK */ |
mbed_official | 237:f3da66175598 | 220 | HAL_UART_MspInit(huart); |
mbed_official | 237:f3da66175598 | 221 | } |
mbed_official | 237:f3da66175598 | 222 | |
mbed_official | 237:f3da66175598 | 223 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 224 | |
mbed_official | 237:f3da66175598 | 225 | /* Disable the Peripheral */ |
mbed_official | 237:f3da66175598 | 226 | __HAL_UART_DISABLE(huart); |
mbed_official | 237:f3da66175598 | 227 | |
mbed_official | 237:f3da66175598 | 228 | /* Set the UART Communication parameters */ |
mbed_official | 237:f3da66175598 | 229 | if (UART_SetConfig(huart) == HAL_ERROR) |
mbed_official | 237:f3da66175598 | 230 | { |
mbed_official | 237:f3da66175598 | 231 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 232 | } |
mbed_official | 237:f3da66175598 | 233 | |
mbed_official | 237:f3da66175598 | 234 | if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT) |
mbed_official | 237:f3da66175598 | 235 | { |
mbed_official | 237:f3da66175598 | 236 | UART_AdvFeatureConfig(huart); |
mbed_official | 237:f3da66175598 | 237 | } |
mbed_official | 237:f3da66175598 | 238 | |
mbed_official | 237:f3da66175598 | 239 | /* In asynchronous mode, the following bits must be kept cleared: |
mbed_official | 237:f3da66175598 | 240 | - LINEN and CLKEN bits in the USART_CR2 register, |
mbed_official | 237:f3da66175598 | 241 | - SCEN, HDSEL and IREN bits in the USART_CR3 register.*/ |
mbed_official | 237:f3da66175598 | 242 | huart->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN); |
mbed_official | 237:f3da66175598 | 243 | huart->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN); |
mbed_official | 237:f3da66175598 | 244 | |
mbed_official | 237:f3da66175598 | 245 | /* Enable the Peripheral */ |
mbed_official | 237:f3da66175598 | 246 | __HAL_UART_ENABLE(huart); |
mbed_official | 237:f3da66175598 | 247 | |
mbed_official | 237:f3da66175598 | 248 | /* TEACK and/or REACK to check before moving huart->State to Ready */ |
mbed_official | 237:f3da66175598 | 249 | return (UART_CheckIdleState(huart)); |
mbed_official | 237:f3da66175598 | 250 | } |
mbed_official | 237:f3da66175598 | 251 | |
mbed_official | 237:f3da66175598 | 252 | /** |
mbed_official | 237:f3da66175598 | 253 | * @brief Initializes the half-duplex mode according to the specified |
mbed_official | 237:f3da66175598 | 254 | * parameters in the UART_InitTypeDef and creates the associated handle . |
mbed_official | 237:f3da66175598 | 255 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 256 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 257 | */ |
mbed_official | 237:f3da66175598 | 258 | HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 259 | { |
mbed_official | 237:f3da66175598 | 260 | /* Check the UART handle allocation */ |
mbed_official | 237:f3da66175598 | 261 | if(huart == NULL) |
mbed_official | 237:f3da66175598 | 262 | { |
mbed_official | 237:f3da66175598 | 263 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 264 | } |
mbed_official | 237:f3da66175598 | 265 | |
mbed_official | 237:f3da66175598 | 266 | /* Check UART instance */ |
mbed_official | 237:f3da66175598 | 267 | assert_param(IS_UART_HALFDUPLEX_INSTANCE(huart->Instance)); |
mbed_official | 237:f3da66175598 | 268 | |
mbed_official | 237:f3da66175598 | 269 | if(huart->State == HAL_UART_STATE_RESET) |
mbed_official | 237:f3da66175598 | 270 | { |
mbed_official | 237:f3da66175598 | 271 | /* Init the low level hardware : GPIO, CLOCK */ |
mbed_official | 237:f3da66175598 | 272 | HAL_UART_MspInit(huart); |
mbed_official | 237:f3da66175598 | 273 | } |
mbed_official | 237:f3da66175598 | 274 | |
mbed_official | 237:f3da66175598 | 275 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 276 | |
mbed_official | 237:f3da66175598 | 277 | /* Disable the Peripheral */ |
mbed_official | 237:f3da66175598 | 278 | __HAL_UART_DISABLE(huart); |
mbed_official | 237:f3da66175598 | 279 | |
mbed_official | 237:f3da66175598 | 280 | /* Set the UART Communication parameters */ |
mbed_official | 237:f3da66175598 | 281 | if (UART_SetConfig(huart) == HAL_ERROR) |
mbed_official | 237:f3da66175598 | 282 | { |
mbed_official | 237:f3da66175598 | 283 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 284 | } |
mbed_official | 237:f3da66175598 | 285 | |
mbed_official | 237:f3da66175598 | 286 | if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT) |
mbed_official | 237:f3da66175598 | 287 | { |
mbed_official | 237:f3da66175598 | 288 | UART_AdvFeatureConfig(huart); |
mbed_official | 237:f3da66175598 | 289 | } |
mbed_official | 237:f3da66175598 | 290 | |
mbed_official | 237:f3da66175598 | 291 | /* In half-duplex mode, the following bits must be kept cleared: |
mbed_official | 237:f3da66175598 | 292 | - LINEN and CLKEN bits in the USART_CR2 register, |
mbed_official | 237:f3da66175598 | 293 | - SCEN and IREN bits in the USART_CR3 register.*/ |
mbed_official | 237:f3da66175598 | 294 | huart->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN); |
mbed_official | 237:f3da66175598 | 295 | huart->Instance->CR3 &= ~(USART_CR3_IREN | USART_CR3_SCEN); |
mbed_official | 237:f3da66175598 | 296 | |
mbed_official | 237:f3da66175598 | 297 | /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */ |
mbed_official | 237:f3da66175598 | 298 | huart->Instance->CR3 |= USART_CR3_HDSEL; |
mbed_official | 237:f3da66175598 | 299 | |
mbed_official | 237:f3da66175598 | 300 | /* Enable the Peripheral */ |
mbed_official | 237:f3da66175598 | 301 | __HAL_UART_ENABLE(huart); |
mbed_official | 237:f3da66175598 | 302 | |
mbed_official | 237:f3da66175598 | 303 | /* TEACK and/or REACK to check before moving huart->State to Ready */ |
mbed_official | 237:f3da66175598 | 304 | return (UART_CheckIdleState(huart)); |
mbed_official | 237:f3da66175598 | 305 | } |
mbed_official | 237:f3da66175598 | 306 | |
mbed_official | 237:f3da66175598 | 307 | |
mbed_official | 237:f3da66175598 | 308 | /** |
mbed_official | 237:f3da66175598 | 309 | * @brief Initializes the LIN mode according to the specified |
mbed_official | 237:f3da66175598 | 310 | * parameters in the UART_InitTypeDef and creates the associated handle . |
mbed_official | 237:f3da66175598 | 311 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 312 | * @param BreakDetectLength: specifies the LIN break detection length. |
mbed_official | 237:f3da66175598 | 313 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 314 | * @arg UART_LINBREAKDETECTLENGTH_10B: 10-bit break detection |
mbed_official | 237:f3da66175598 | 315 | * @arg UART_LINBREAKDETECTLENGTH_11B: 11-bit break detection |
mbed_official | 237:f3da66175598 | 316 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 317 | */ |
mbed_official | 237:f3da66175598 | 318 | HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength) |
mbed_official | 237:f3da66175598 | 319 | { |
mbed_official | 237:f3da66175598 | 320 | /* Check the UART handle allocation */ |
mbed_official | 237:f3da66175598 | 321 | if(huart == NULL) |
mbed_official | 237:f3da66175598 | 322 | { |
mbed_official | 237:f3da66175598 | 323 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 324 | } |
mbed_official | 237:f3da66175598 | 325 | |
mbed_official | 237:f3da66175598 | 326 | /* Check the LIN UART instance */ |
mbed_official | 237:f3da66175598 | 327 | assert_param(IS_UART_LIN_INSTANCE(huart->Instance)); |
mbed_official | 237:f3da66175598 | 328 | /* Check the Break detection length parameter */ |
mbed_official | 237:f3da66175598 | 329 | assert_param(IS_UART_LIN_BREAK_DETECT_LENGTH(BreakDetectLength)); |
mbed_official | 237:f3da66175598 | 330 | |
mbed_official | 237:f3da66175598 | 331 | /* LIN mode limited to 16-bit oversampling only */ |
mbed_official | 237:f3da66175598 | 332 | if(huart->Init.OverSampling == UART_OVERSAMPLING_8) |
mbed_official | 237:f3da66175598 | 333 | { |
mbed_official | 237:f3da66175598 | 334 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 335 | } |
mbed_official | 237:f3da66175598 | 336 | |
mbed_official | 237:f3da66175598 | 337 | if(huart->State == HAL_UART_STATE_RESET) |
mbed_official | 237:f3da66175598 | 338 | { |
mbed_official | 237:f3da66175598 | 339 | /* Init the low level hardware : GPIO, CLOCK */ |
mbed_official | 237:f3da66175598 | 340 | HAL_UART_MspInit(huart); |
mbed_official | 237:f3da66175598 | 341 | } |
mbed_official | 237:f3da66175598 | 342 | |
mbed_official | 237:f3da66175598 | 343 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 344 | |
mbed_official | 237:f3da66175598 | 345 | /* Disable the Peripheral */ |
mbed_official | 237:f3da66175598 | 346 | __HAL_UART_DISABLE(huart); |
mbed_official | 237:f3da66175598 | 347 | |
mbed_official | 237:f3da66175598 | 348 | /* Set the UART Communication parameters */ |
mbed_official | 237:f3da66175598 | 349 | if (UART_SetConfig(huart) == HAL_ERROR) |
mbed_official | 237:f3da66175598 | 350 | { |
mbed_official | 237:f3da66175598 | 351 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 352 | } |
mbed_official | 237:f3da66175598 | 353 | |
mbed_official | 237:f3da66175598 | 354 | if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT) |
mbed_official | 237:f3da66175598 | 355 | { |
mbed_official | 237:f3da66175598 | 356 | UART_AdvFeatureConfig(huart); |
mbed_official | 237:f3da66175598 | 357 | } |
mbed_official | 237:f3da66175598 | 358 | |
mbed_official | 237:f3da66175598 | 359 | /* In LIN mode, the following bits must be kept cleared: |
mbed_official | 237:f3da66175598 | 360 | - LINEN and CLKEN bits in the USART_CR2 register, |
mbed_official | 237:f3da66175598 | 361 | - SCEN and IREN bits in the USART_CR3 register.*/ |
mbed_official | 237:f3da66175598 | 362 | huart->Instance->CR2 &= ~(USART_CR2_CLKEN); |
mbed_official | 237:f3da66175598 | 363 | huart->Instance->CR3 &= ~(USART_CR3_HDSEL | USART_CR3_IREN | USART_CR3_SCEN); |
mbed_official | 237:f3da66175598 | 364 | |
mbed_official | 237:f3da66175598 | 365 | /* Enable the LIN mode by setting the LINEN bit in the CR2 register */ |
mbed_official | 237:f3da66175598 | 366 | huart->Instance->CR2 |= USART_CR2_LINEN; |
mbed_official | 237:f3da66175598 | 367 | |
mbed_official | 237:f3da66175598 | 368 | /* Set the USART LIN Break detection length. */ |
mbed_official | 237:f3da66175598 | 369 | MODIFY_REG(huart->Instance->CR2, USART_CR2_LBDL, BreakDetectLength); |
mbed_official | 237:f3da66175598 | 370 | |
mbed_official | 237:f3da66175598 | 371 | /* Enable the Peripheral */ |
mbed_official | 237:f3da66175598 | 372 | __HAL_UART_ENABLE(huart); |
mbed_official | 237:f3da66175598 | 373 | |
mbed_official | 237:f3da66175598 | 374 | /* TEACK and/or REACK to check before moving huart->State to Ready */ |
mbed_official | 237:f3da66175598 | 375 | return (UART_CheckIdleState(huart)); |
mbed_official | 237:f3da66175598 | 376 | } |
mbed_official | 237:f3da66175598 | 377 | |
mbed_official | 237:f3da66175598 | 378 | |
mbed_official | 237:f3da66175598 | 379 | |
mbed_official | 237:f3da66175598 | 380 | /** |
mbed_official | 237:f3da66175598 | 381 | * @brief Initializes the multiprocessor mode according to the specified |
mbed_official | 237:f3da66175598 | 382 | * parameters in the UART_InitTypeDef and creates the associated handle. |
mbed_official | 237:f3da66175598 | 383 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 384 | * @param Address: UART node address (4-, 6-, 7- or 8-bit long) |
mbed_official | 237:f3da66175598 | 385 | * @param WakeUpMethod: specifies the UART wakeup method. |
mbed_official | 237:f3da66175598 | 386 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 387 | * @arg UART_WAKEUPMETHOD_IDLELINE: WakeUp by an idle line detection |
mbed_official | 237:f3da66175598 | 388 | * @arg UART_WAKEUPMETHOD_ADDRESSMARK: WakeUp by an address mark |
mbed_official | 237:f3da66175598 | 389 | * @note If the user resorts to idle line detection wake up, the Address parameter |
mbed_official | 237:f3da66175598 | 390 | * is useless and ignored by the initialization function. |
mbed_official | 237:f3da66175598 | 391 | * @note If the user resorts to address mark wake up, the address length detection |
mbed_official | 237:f3da66175598 | 392 | * is configured by default to 4 bits only. For the UART to be able to |
mbed_official | 237:f3da66175598 | 393 | * manage 6-, 7- or 8-bit long addresses detection, the API |
mbed_official | 237:f3da66175598 | 394 | * HAL_MultiProcessorEx_AddressLength_Set() must be called after |
mbed_official | 237:f3da66175598 | 395 | * HAL_MultiProcessor_Init(). |
mbed_official | 237:f3da66175598 | 396 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 397 | */ |
mbed_official | 237:f3da66175598 | 398 | HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod) |
mbed_official | 237:f3da66175598 | 399 | { |
mbed_official | 237:f3da66175598 | 400 | /* Check the UART handle allocation */ |
mbed_official | 237:f3da66175598 | 401 | if(huart == NULL) |
mbed_official | 237:f3da66175598 | 402 | { |
mbed_official | 237:f3da66175598 | 403 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 404 | } |
mbed_official | 237:f3da66175598 | 405 | |
mbed_official | 237:f3da66175598 | 406 | /* Check the wake up method parameter */ |
mbed_official | 237:f3da66175598 | 407 | assert_param(IS_UART_WAKEUPMETHOD(WakeUpMethod)); |
mbed_official | 237:f3da66175598 | 408 | |
mbed_official | 237:f3da66175598 | 409 | if(huart->State == HAL_UART_STATE_RESET) |
mbed_official | 237:f3da66175598 | 410 | { |
mbed_official | 237:f3da66175598 | 411 | /* Init the low level hardware : GPIO, CLOCK */ |
mbed_official | 237:f3da66175598 | 412 | HAL_UART_MspInit(huart); |
mbed_official | 237:f3da66175598 | 413 | } |
mbed_official | 237:f3da66175598 | 414 | |
mbed_official | 237:f3da66175598 | 415 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 416 | |
mbed_official | 237:f3da66175598 | 417 | /* Disable the Peripheral */ |
mbed_official | 237:f3da66175598 | 418 | __HAL_UART_DISABLE(huart); |
mbed_official | 237:f3da66175598 | 419 | |
mbed_official | 237:f3da66175598 | 420 | /* Set the UART Communication parameters */ |
mbed_official | 237:f3da66175598 | 421 | if (UART_SetConfig(huart) == HAL_ERROR) |
mbed_official | 237:f3da66175598 | 422 | { |
mbed_official | 237:f3da66175598 | 423 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 424 | } |
mbed_official | 237:f3da66175598 | 425 | |
mbed_official | 237:f3da66175598 | 426 | if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT) |
mbed_official | 237:f3da66175598 | 427 | { |
mbed_official | 237:f3da66175598 | 428 | UART_AdvFeatureConfig(huart); |
mbed_official | 237:f3da66175598 | 429 | } |
mbed_official | 237:f3da66175598 | 430 | |
mbed_official | 237:f3da66175598 | 431 | /* In multiprocessor mode, the following bits must be kept cleared: |
mbed_official | 237:f3da66175598 | 432 | - LINEN and CLKEN bits in the USART_CR2 register, |
mbed_official | 237:f3da66175598 | 433 | - SCEN, HDSEL and IREN bits in the USART_CR3 register. */ |
mbed_official | 237:f3da66175598 | 434 | huart->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN); |
mbed_official | 237:f3da66175598 | 435 | huart->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN); |
mbed_official | 237:f3da66175598 | 436 | |
mbed_official | 237:f3da66175598 | 437 | if (WakeUpMethod == UART_WAKEUPMETHOD_ADDRESSMARK) |
mbed_official | 237:f3da66175598 | 438 | { |
mbed_official | 237:f3da66175598 | 439 | /* If address mark wake up method is chosen, set the USART address node */ |
mbed_official | 237:f3da66175598 | 440 | MODIFY_REG(huart->Instance->CR2, USART_CR2_ADD, ((uint32_t)Address << UART_CR2_ADDRESS_LSB_POS)); |
mbed_official | 237:f3da66175598 | 441 | } |
mbed_official | 237:f3da66175598 | 442 | |
mbed_official | 237:f3da66175598 | 443 | /* Set the wake up method by setting the WAKE bit in the CR1 register */ |
mbed_official | 237:f3da66175598 | 444 | MODIFY_REG(huart->Instance->CR1, USART_CR1_WAKE, WakeUpMethod); |
mbed_official | 237:f3da66175598 | 445 | |
mbed_official | 237:f3da66175598 | 446 | /* Enable the Peripheral */ |
mbed_official | 237:f3da66175598 | 447 | __HAL_UART_ENABLE(huart); |
mbed_official | 237:f3da66175598 | 448 | |
mbed_official | 237:f3da66175598 | 449 | /* TEACK and/or REACK to check before moving huart->State to Ready */ |
mbed_official | 237:f3da66175598 | 450 | return (UART_CheckIdleState(huart)); |
mbed_official | 237:f3da66175598 | 451 | } |
mbed_official | 237:f3da66175598 | 452 | |
mbed_official | 237:f3da66175598 | 453 | |
mbed_official | 237:f3da66175598 | 454 | |
mbed_official | 237:f3da66175598 | 455 | |
mbed_official | 237:f3da66175598 | 456 | /** |
mbed_official | 237:f3da66175598 | 457 | * @brief DeInitializes the UART peripheral |
mbed_official | 237:f3da66175598 | 458 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 459 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 460 | */ |
mbed_official | 237:f3da66175598 | 461 | HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 462 | { |
mbed_official | 237:f3da66175598 | 463 | /* Check the UART handle allocation */ |
mbed_official | 237:f3da66175598 | 464 | if(huart == NULL) |
mbed_official | 237:f3da66175598 | 465 | { |
mbed_official | 237:f3da66175598 | 466 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 467 | } |
mbed_official | 237:f3da66175598 | 468 | |
mbed_official | 237:f3da66175598 | 469 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 470 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
mbed_official | 237:f3da66175598 | 471 | |
mbed_official | 237:f3da66175598 | 472 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 473 | |
mbed_official | 237:f3da66175598 | 474 | /* Disable the Peripheral */ |
mbed_official | 237:f3da66175598 | 475 | __HAL_UART_DISABLE(huart); |
mbed_official | 237:f3da66175598 | 476 | |
mbed_official | 237:f3da66175598 | 477 | huart->Instance->CR1 = 0x0; |
mbed_official | 237:f3da66175598 | 478 | huart->Instance->CR2 = 0x0; |
mbed_official | 237:f3da66175598 | 479 | huart->Instance->CR3 = 0x0; |
mbed_official | 237:f3da66175598 | 480 | |
mbed_official | 237:f3da66175598 | 481 | /* DeInit the low level hardware */ |
mbed_official | 237:f3da66175598 | 482 | HAL_UART_MspDeInit(huart); |
mbed_official | 237:f3da66175598 | 483 | |
mbed_official | 237:f3da66175598 | 484 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 485 | huart->State = HAL_UART_STATE_RESET; |
mbed_official | 237:f3da66175598 | 486 | |
mbed_official | 237:f3da66175598 | 487 | /* Process Unlock */ |
mbed_official | 237:f3da66175598 | 488 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 489 | |
mbed_official | 237:f3da66175598 | 490 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 491 | } |
mbed_official | 237:f3da66175598 | 492 | |
mbed_official | 237:f3da66175598 | 493 | /** |
mbed_official | 237:f3da66175598 | 494 | * @brief UART MSP Init |
mbed_official | 237:f3da66175598 | 495 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 496 | * @retval None |
mbed_official | 237:f3da66175598 | 497 | */ |
mbed_official | 237:f3da66175598 | 498 | __weak void HAL_UART_MspInit(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 499 | { |
mbed_official | 237:f3da66175598 | 500 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 501 | the HAL_UART_MspInit can be implemented in the user file |
mbed_official | 237:f3da66175598 | 502 | */ |
mbed_official | 237:f3da66175598 | 503 | } |
mbed_official | 237:f3da66175598 | 504 | |
mbed_official | 237:f3da66175598 | 505 | /** |
mbed_official | 237:f3da66175598 | 506 | * @brief UART MSP DeInit |
mbed_official | 237:f3da66175598 | 507 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 508 | * @retval None |
mbed_official | 237:f3da66175598 | 509 | */ |
mbed_official | 237:f3da66175598 | 510 | __weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 511 | { |
mbed_official | 237:f3da66175598 | 512 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 513 | the HAL_UART_MspDeInit can be implemented in the user file |
mbed_official | 237:f3da66175598 | 514 | */ |
mbed_official | 237:f3da66175598 | 515 | } |
mbed_official | 237:f3da66175598 | 516 | |
mbed_official | 237:f3da66175598 | 517 | /** |
mbed_official | 237:f3da66175598 | 518 | * @} |
mbed_official | 237:f3da66175598 | 519 | */ |
mbed_official | 237:f3da66175598 | 520 | |
mbed_official | 237:f3da66175598 | 521 | /** @defgroup HAL_UART_Group2 IO operation functions |
mbed_official | 237:f3da66175598 | 522 | * @brief UART Transmit/Receive functions |
mbed_official | 237:f3da66175598 | 523 | * |
mbed_official | 237:f3da66175598 | 524 | @verbatim |
mbed_official | 237:f3da66175598 | 525 | =============================================================================== |
mbed_official | 237:f3da66175598 | 526 | ##### I/O operation functions ##### |
mbed_official | 237:f3da66175598 | 527 | =============================================================================== |
mbed_official | 237:f3da66175598 | 528 | This subsection provides a set of functions allowing to manage the UART asynchronous |
mbed_official | 237:f3da66175598 | 529 | and Half duplex data transfers. |
mbed_official | 237:f3da66175598 | 530 | |
mbed_official | 237:f3da66175598 | 531 | (#) There are two mode of transfer: |
mbed_official | 237:f3da66175598 | 532 | (+) Blocking mode: The communication is performed in polling mode. |
mbed_official | 237:f3da66175598 | 533 | The HAL status of all data processing is returned by the same function |
mbed_official | 237:f3da66175598 | 534 | after finishing transfer. |
mbed_official | 237:f3da66175598 | 535 | (+) No-Blocking mode: The communication is performed using Interrupts |
mbed_official | 237:f3da66175598 | 536 | or DMA, These API's return the HAL status. |
mbed_official | 237:f3da66175598 | 537 | The end of the data processing will be indicated through the |
mbed_official | 237:f3da66175598 | 538 | dedicated UART IRQ when using Interrupt mode or the DMA IRQ when |
mbed_official | 237:f3da66175598 | 539 | using DMA mode. |
mbed_official | 237:f3da66175598 | 540 | The HAL_UART_TxCpltCallback(), HAL_UART_RxCpltCallback() user callbacks |
mbed_official | 237:f3da66175598 | 541 | will be executed respectivelly at the end of the transmit or Receive process |
mbed_official | 237:f3da66175598 | 542 | The HAL_UART_ErrorCallback()user callback will be executed when a communication error is detected |
mbed_official | 237:f3da66175598 | 543 | |
mbed_official | 237:f3da66175598 | 544 | (#) Blocking mode API's are : |
mbed_official | 237:f3da66175598 | 545 | (+) HAL_UART_Transmit() |
mbed_official | 237:f3da66175598 | 546 | (+) HAL_UART_Receive() |
mbed_official | 237:f3da66175598 | 547 | |
mbed_official | 237:f3da66175598 | 548 | (#) Non-Blocking mode API's with Interrupt are : |
mbed_official | 237:f3da66175598 | 549 | (+) HAL_UART_Transmit_IT() |
mbed_official | 237:f3da66175598 | 550 | (+) HAL_UART_Receive_IT() |
mbed_official | 237:f3da66175598 | 551 | (+) HAL_UART_IRQHandler() |
mbed_official | 237:f3da66175598 | 552 | (+) UART_Transmit_IT() |
mbed_official | 237:f3da66175598 | 553 | (+) UART_Receive_IT() |
mbed_official | 237:f3da66175598 | 554 | |
mbed_official | 237:f3da66175598 | 555 | (#) No-Blocking mode API's with DMA are : |
mbed_official | 237:f3da66175598 | 556 | (+) HAL_UART_Transmit_DMA() |
mbed_official | 237:f3da66175598 | 557 | (+) HAL_UART_Receive_DMA() |
mbed_official | 237:f3da66175598 | 558 | (+) HAL_UART_DMAPause() |
mbed_official | 237:f3da66175598 | 559 | (+) HAL_UART_DMAResume() |
mbed_official | 237:f3da66175598 | 560 | (+) HAL_UART_DMAStop() |
mbed_official | 237:f3da66175598 | 561 | |
mbed_official | 237:f3da66175598 | 562 | (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode: |
mbed_official | 237:f3da66175598 | 563 | (+) HAL_UART_TxHalfCpltCallback() |
mbed_official | 237:f3da66175598 | 564 | (+) HAL_UART_TxCpltCallback() |
mbed_official | 237:f3da66175598 | 565 | (+) HAL_UART_RxHalfCpltCallback() |
mbed_official | 237:f3da66175598 | 566 | (+) HAL_UART_RxCpltCallback() |
mbed_official | 237:f3da66175598 | 567 | (+) HAL_UART_ErrorCallback() |
mbed_official | 237:f3da66175598 | 568 | |
mbed_official | 237:f3da66175598 | 569 | |
mbed_official | 237:f3da66175598 | 570 | -@- In the Half duplex communication, it is forbidden to run the transmit |
mbed_official | 237:f3da66175598 | 571 | and receive process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX can't be useful. |
mbed_official | 237:f3da66175598 | 572 | |
mbed_official | 237:f3da66175598 | 573 | @endverbatim |
mbed_official | 237:f3da66175598 | 574 | * @{ |
mbed_official | 237:f3da66175598 | 575 | */ |
mbed_official | 237:f3da66175598 | 576 | |
mbed_official | 237:f3da66175598 | 577 | /** |
mbed_official | 237:f3da66175598 | 578 | * @brief Send an amount of data in blocking mode |
mbed_official | 237:f3da66175598 | 579 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 580 | * @param pData: pointer to data buffer |
mbed_official | 237:f3da66175598 | 581 | * @param Size: amount of data to be sent |
mbed_official | 237:f3da66175598 | 582 | * @param Timeout : Timeout duration |
mbed_official | 237:f3da66175598 | 583 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 584 | */ |
mbed_official | 237:f3da66175598 | 585 | HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 586 | { |
mbed_official | 237:f3da66175598 | 587 | uint16_t* tmp; |
mbed_official | 237:f3da66175598 | 588 | |
mbed_official | 237:f3da66175598 | 589 | if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_RX)) |
mbed_official | 237:f3da66175598 | 590 | { |
mbed_official | 237:f3da66175598 | 591 | if((pData == NULL ) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 592 | { |
mbed_official | 237:f3da66175598 | 593 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 594 | } |
mbed_official | 237:f3da66175598 | 595 | |
mbed_official | 237:f3da66175598 | 596 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 597 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 598 | |
mbed_official | 237:f3da66175598 | 599 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 600 | /* Check if a non-blocking receive process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 601 | if(huart->State == HAL_UART_STATE_BUSY_RX) |
mbed_official | 237:f3da66175598 | 602 | { |
mbed_official | 237:f3da66175598 | 603 | huart->State = HAL_UART_STATE_BUSY_TX_RX; |
mbed_official | 237:f3da66175598 | 604 | } |
mbed_official | 237:f3da66175598 | 605 | else |
mbed_official | 237:f3da66175598 | 606 | { |
mbed_official | 237:f3da66175598 | 607 | huart->State = HAL_UART_STATE_BUSY_TX; |
mbed_official | 237:f3da66175598 | 608 | } |
mbed_official | 237:f3da66175598 | 609 | |
mbed_official | 237:f3da66175598 | 610 | huart->TxXferSize = Size; |
mbed_official | 237:f3da66175598 | 611 | huart->TxXferCount = Size; |
mbed_official | 237:f3da66175598 | 612 | while(huart->TxXferCount > 0) |
mbed_official | 237:f3da66175598 | 613 | { |
mbed_official | 237:f3da66175598 | 614 | huart->TxXferCount--; |
mbed_official | 237:f3da66175598 | 615 | if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, Timeout) != HAL_OK) |
mbed_official | 237:f3da66175598 | 616 | { |
mbed_official | 237:f3da66175598 | 617 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 618 | } |
mbed_official | 237:f3da66175598 | 619 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
mbed_official | 237:f3da66175598 | 620 | { |
mbed_official | 237:f3da66175598 | 621 | tmp = (uint16_t*) pData; |
mbed_official | 237:f3da66175598 | 622 | huart->Instance->TDR = (*tmp & (uint16_t)0x01FF); |
mbed_official | 237:f3da66175598 | 623 | pData += 2; |
mbed_official | 237:f3da66175598 | 624 | } |
mbed_official | 237:f3da66175598 | 625 | else |
mbed_official | 237:f3da66175598 | 626 | { |
mbed_official | 237:f3da66175598 | 627 | huart->Instance->TDR = (*pData++ & (uint8_t)0xFF); |
mbed_official | 237:f3da66175598 | 628 | } |
mbed_official | 237:f3da66175598 | 629 | } |
mbed_official | 237:f3da66175598 | 630 | if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, Timeout) != HAL_OK) |
mbed_official | 237:f3da66175598 | 631 | { |
mbed_official | 237:f3da66175598 | 632 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 633 | } |
mbed_official | 237:f3da66175598 | 634 | /* Check if a non-blocking receive Process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 635 | if(huart->State == HAL_UART_STATE_BUSY_TX_RX) |
mbed_official | 237:f3da66175598 | 636 | { |
mbed_official | 237:f3da66175598 | 637 | huart->State = HAL_UART_STATE_BUSY_RX; |
mbed_official | 237:f3da66175598 | 638 | } |
mbed_official | 237:f3da66175598 | 639 | else |
mbed_official | 237:f3da66175598 | 640 | { |
mbed_official | 237:f3da66175598 | 641 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 642 | } |
mbed_official | 237:f3da66175598 | 643 | |
mbed_official | 237:f3da66175598 | 644 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 645 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 646 | |
mbed_official | 237:f3da66175598 | 647 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 648 | } |
mbed_official | 237:f3da66175598 | 649 | else |
mbed_official | 237:f3da66175598 | 650 | { |
mbed_official | 237:f3da66175598 | 651 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 652 | } |
mbed_official | 237:f3da66175598 | 653 | } |
mbed_official | 237:f3da66175598 | 654 | |
mbed_official | 237:f3da66175598 | 655 | /** |
mbed_official | 237:f3da66175598 | 656 | * @brief Receive an amount of data in blocking mode |
mbed_official | 237:f3da66175598 | 657 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 658 | * @param pData: pointer to data buffer |
mbed_official | 237:f3da66175598 | 659 | * @param Size: amount of data to be received |
mbed_official | 237:f3da66175598 | 660 | * @param Timeout : Timeout duration |
mbed_official | 237:f3da66175598 | 661 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 662 | */ |
mbed_official | 237:f3da66175598 | 663 | HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 664 | { |
mbed_official | 237:f3da66175598 | 665 | uint16_t* tmp; |
mbed_official | 237:f3da66175598 | 666 | uint16_t uhMask; |
mbed_official | 237:f3da66175598 | 667 | |
mbed_official | 237:f3da66175598 | 668 | if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_TX)) |
mbed_official | 237:f3da66175598 | 669 | { |
mbed_official | 237:f3da66175598 | 670 | if((pData == NULL ) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 671 | { |
mbed_official | 237:f3da66175598 | 672 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 673 | } |
mbed_official | 237:f3da66175598 | 674 | |
mbed_official | 237:f3da66175598 | 675 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 676 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 677 | |
mbed_official | 237:f3da66175598 | 678 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 679 | /* Check if a non-blocking transmit process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 680 | if(huart->State == HAL_UART_STATE_BUSY_TX) |
mbed_official | 237:f3da66175598 | 681 | { |
mbed_official | 237:f3da66175598 | 682 | huart->State = HAL_UART_STATE_BUSY_TX_RX; |
mbed_official | 237:f3da66175598 | 683 | } |
mbed_official | 237:f3da66175598 | 684 | else |
mbed_official | 237:f3da66175598 | 685 | { |
mbed_official | 237:f3da66175598 | 686 | huart->State = HAL_UART_STATE_BUSY_RX; |
mbed_official | 237:f3da66175598 | 687 | } |
mbed_official | 237:f3da66175598 | 688 | |
mbed_official | 237:f3da66175598 | 689 | huart->RxXferSize = Size; |
mbed_official | 237:f3da66175598 | 690 | huart->RxXferCount = Size; |
mbed_official | 237:f3da66175598 | 691 | |
mbed_official | 237:f3da66175598 | 692 | /* Computation of UART mask to apply to RDR register */ |
mbed_official | 237:f3da66175598 | 693 | __HAL_UART_MASK_COMPUTATION(huart); |
mbed_official | 237:f3da66175598 | 694 | uhMask = huart->Mask; |
mbed_official | 237:f3da66175598 | 695 | |
mbed_official | 237:f3da66175598 | 696 | /* as long as data have to be received */ |
mbed_official | 237:f3da66175598 | 697 | while(huart->RxXferCount > 0) |
mbed_official | 237:f3da66175598 | 698 | { |
mbed_official | 237:f3da66175598 | 699 | huart->RxXferCount--; |
mbed_official | 237:f3da66175598 | 700 | if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, Timeout) != HAL_OK) |
mbed_official | 237:f3da66175598 | 701 | { |
mbed_official | 237:f3da66175598 | 702 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 703 | } |
mbed_official | 237:f3da66175598 | 704 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
mbed_official | 237:f3da66175598 | 705 | { |
mbed_official | 237:f3da66175598 | 706 | tmp = (uint16_t*) pData ; |
mbed_official | 237:f3da66175598 | 707 | *tmp = (uint16_t)(huart->Instance->RDR & uhMask); |
mbed_official | 237:f3da66175598 | 708 | pData +=2; |
mbed_official | 237:f3da66175598 | 709 | } |
mbed_official | 237:f3da66175598 | 710 | else |
mbed_official | 237:f3da66175598 | 711 | { |
mbed_official | 237:f3da66175598 | 712 | *pData++ = (uint8_t)(huart->Instance->RDR & (uint8_t)uhMask); |
mbed_official | 237:f3da66175598 | 713 | } |
mbed_official | 237:f3da66175598 | 714 | } |
mbed_official | 237:f3da66175598 | 715 | |
mbed_official | 237:f3da66175598 | 716 | /* Check if a non-blocking transmit Process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 717 | if(huart->State == HAL_UART_STATE_BUSY_TX_RX) |
mbed_official | 237:f3da66175598 | 718 | { |
mbed_official | 237:f3da66175598 | 719 | huart->State = HAL_UART_STATE_BUSY_TX; |
mbed_official | 237:f3da66175598 | 720 | } |
mbed_official | 237:f3da66175598 | 721 | else |
mbed_official | 237:f3da66175598 | 722 | { |
mbed_official | 237:f3da66175598 | 723 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 724 | } |
mbed_official | 237:f3da66175598 | 725 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 726 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 727 | |
mbed_official | 237:f3da66175598 | 728 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 729 | } |
mbed_official | 237:f3da66175598 | 730 | else |
mbed_official | 237:f3da66175598 | 731 | { |
mbed_official | 237:f3da66175598 | 732 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 733 | } |
mbed_official | 237:f3da66175598 | 734 | } |
mbed_official | 237:f3da66175598 | 735 | |
mbed_official | 237:f3da66175598 | 736 | /** |
mbed_official | 237:f3da66175598 | 737 | * @brief Send an amount of data in interrupt mode |
mbed_official | 237:f3da66175598 | 738 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 739 | * @param pData: pointer to data buffer |
mbed_official | 237:f3da66175598 | 740 | * @param Size: amount of data to be sent |
mbed_official | 237:f3da66175598 | 741 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 742 | */ |
mbed_official | 237:f3da66175598 | 743 | HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
mbed_official | 237:f3da66175598 | 744 | { |
mbed_official | 237:f3da66175598 | 745 | if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_RX)) |
mbed_official | 237:f3da66175598 | 746 | { |
mbed_official | 237:f3da66175598 | 747 | if((pData == NULL ) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 748 | { |
mbed_official | 237:f3da66175598 | 749 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 750 | } |
mbed_official | 237:f3da66175598 | 751 | |
mbed_official | 237:f3da66175598 | 752 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 753 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 754 | |
mbed_official | 237:f3da66175598 | 755 | huart->pTxBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 756 | huart->TxXferSize = Size; |
mbed_official | 237:f3da66175598 | 757 | huart->TxXferCount = Size; |
mbed_official | 237:f3da66175598 | 758 | |
mbed_official | 237:f3da66175598 | 759 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 760 | /* Check if a receive process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 761 | if(huart->State == HAL_UART_STATE_BUSY_RX) |
mbed_official | 237:f3da66175598 | 762 | { |
mbed_official | 237:f3da66175598 | 763 | huart->State = HAL_UART_STATE_BUSY_TX_RX; |
mbed_official | 237:f3da66175598 | 764 | } |
mbed_official | 237:f3da66175598 | 765 | else |
mbed_official | 237:f3da66175598 | 766 | { |
mbed_official | 237:f3da66175598 | 767 | huart->State = HAL_UART_STATE_BUSY_TX; |
mbed_official | 237:f3da66175598 | 768 | } |
mbed_official | 237:f3da66175598 | 769 | |
mbed_official | 237:f3da66175598 | 770 | /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 237:f3da66175598 | 771 | __HAL_UART_ENABLE_IT(huart, UART_IT_ERR); |
mbed_official | 237:f3da66175598 | 772 | |
mbed_official | 237:f3da66175598 | 773 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 774 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 775 | |
mbed_official | 237:f3da66175598 | 776 | /* Enable the UART Transmit Data Register Empty Interrupt */ |
mbed_official | 237:f3da66175598 | 777 | __HAL_UART_ENABLE_IT(huart, UART_IT_TXE); |
mbed_official | 237:f3da66175598 | 778 | |
mbed_official | 237:f3da66175598 | 779 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 780 | } |
mbed_official | 237:f3da66175598 | 781 | else |
mbed_official | 237:f3da66175598 | 782 | { |
mbed_official | 237:f3da66175598 | 783 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 784 | } |
mbed_official | 237:f3da66175598 | 785 | } |
mbed_official | 237:f3da66175598 | 786 | |
mbed_official | 237:f3da66175598 | 787 | /** |
mbed_official | 237:f3da66175598 | 788 | * @brief Receive an amount of data in interrupt mode |
mbed_official | 237:f3da66175598 | 789 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 790 | * @param pData: pointer to data buffer |
mbed_official | 237:f3da66175598 | 791 | * @param Size: amount of data to be received |
mbed_official | 237:f3da66175598 | 792 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 793 | */ |
mbed_official | 237:f3da66175598 | 794 | HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
mbed_official | 237:f3da66175598 | 795 | { |
mbed_official | 237:f3da66175598 | 796 | if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_TX)) |
mbed_official | 237:f3da66175598 | 797 | { |
mbed_official | 237:f3da66175598 | 798 | if((pData == NULL ) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 799 | { |
mbed_official | 237:f3da66175598 | 800 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 801 | } |
mbed_official | 237:f3da66175598 | 802 | |
mbed_official | 237:f3da66175598 | 803 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 804 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 805 | |
mbed_official | 237:f3da66175598 | 806 | huart->pRxBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 807 | huart->RxXferSize = Size; |
mbed_official | 237:f3da66175598 | 808 | huart->RxXferCount = Size; |
mbed_official | 237:f3da66175598 | 809 | |
mbed_official | 237:f3da66175598 | 810 | /* Computation of UART mask to apply to RDR register */ |
mbed_official | 237:f3da66175598 | 811 | __HAL_UART_MASK_COMPUTATION(huart); |
mbed_official | 237:f3da66175598 | 812 | |
mbed_official | 237:f3da66175598 | 813 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 814 | /* Check if a transmit process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 815 | if(huart->State == HAL_UART_STATE_BUSY_TX) |
mbed_official | 237:f3da66175598 | 816 | { |
mbed_official | 237:f3da66175598 | 817 | huart->State = HAL_UART_STATE_BUSY_TX_RX; |
mbed_official | 237:f3da66175598 | 818 | } |
mbed_official | 237:f3da66175598 | 819 | else |
mbed_official | 237:f3da66175598 | 820 | { |
mbed_official | 237:f3da66175598 | 821 | huart->State = HAL_UART_STATE_BUSY_RX; |
mbed_official | 237:f3da66175598 | 822 | } |
mbed_official | 237:f3da66175598 | 823 | |
mbed_official | 237:f3da66175598 | 824 | /* Enable the UART Parity Error Interrupt */ |
mbed_official | 237:f3da66175598 | 825 | __HAL_UART_ENABLE_IT(huart, UART_IT_PE); |
mbed_official | 237:f3da66175598 | 826 | |
mbed_official | 237:f3da66175598 | 827 | /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 237:f3da66175598 | 828 | __HAL_UART_ENABLE_IT(huart, UART_IT_ERR); |
mbed_official | 237:f3da66175598 | 829 | |
mbed_official | 237:f3da66175598 | 830 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 831 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 832 | |
mbed_official | 237:f3da66175598 | 833 | /* Enable the UART Data Register not empty Interrupt */ |
mbed_official | 237:f3da66175598 | 834 | __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE); |
mbed_official | 237:f3da66175598 | 835 | |
mbed_official | 237:f3da66175598 | 836 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 837 | } |
mbed_official | 237:f3da66175598 | 838 | else |
mbed_official | 237:f3da66175598 | 839 | { |
mbed_official | 237:f3da66175598 | 840 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 841 | } |
mbed_official | 237:f3da66175598 | 842 | } |
mbed_official | 237:f3da66175598 | 843 | |
mbed_official | 237:f3da66175598 | 844 | /** |
mbed_official | 237:f3da66175598 | 845 | * @brief Send an amount of data in DMA mode |
mbed_official | 237:f3da66175598 | 846 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 847 | * @param pData: pointer to data buffer |
mbed_official | 237:f3da66175598 | 848 | * @param Size: amount of data to be sent |
mbed_official | 237:f3da66175598 | 849 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 850 | */ |
mbed_official | 237:f3da66175598 | 851 | HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
mbed_official | 237:f3da66175598 | 852 | { |
mbed_official | 237:f3da66175598 | 853 | uint32_t *tmp; |
mbed_official | 237:f3da66175598 | 854 | |
mbed_official | 237:f3da66175598 | 855 | if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_RX)) |
mbed_official | 237:f3da66175598 | 856 | { |
mbed_official | 237:f3da66175598 | 857 | if((pData == NULL ) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 858 | { |
mbed_official | 237:f3da66175598 | 859 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 860 | } |
mbed_official | 237:f3da66175598 | 861 | |
mbed_official | 237:f3da66175598 | 862 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 863 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 864 | |
mbed_official | 237:f3da66175598 | 865 | huart->pTxBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 866 | huart->TxXferSize = Size; |
mbed_official | 237:f3da66175598 | 867 | huart->TxXferCount = Size; |
mbed_official | 237:f3da66175598 | 868 | |
mbed_official | 237:f3da66175598 | 869 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 870 | /* Check if a receive process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 871 | if(huart->State == HAL_UART_STATE_BUSY_RX) |
mbed_official | 237:f3da66175598 | 872 | { |
mbed_official | 237:f3da66175598 | 873 | huart->State = HAL_UART_STATE_BUSY_TX_RX; |
mbed_official | 237:f3da66175598 | 874 | } |
mbed_official | 237:f3da66175598 | 875 | else |
mbed_official | 237:f3da66175598 | 876 | { |
mbed_official | 237:f3da66175598 | 877 | huart->State = HAL_UART_STATE_BUSY_TX; |
mbed_official | 237:f3da66175598 | 878 | } |
mbed_official | 237:f3da66175598 | 879 | |
mbed_official | 237:f3da66175598 | 880 | /* Set the UART DMA transfer complete callback */ |
mbed_official | 237:f3da66175598 | 881 | huart->hdmatx->XferCpltCallback = UART_DMATransmitCplt; |
mbed_official | 237:f3da66175598 | 882 | |
mbed_official | 237:f3da66175598 | 883 | /* Set the UART DMA Half transfer complete callback */ |
mbed_official | 237:f3da66175598 | 884 | huart->hdmatx->XferHalfCpltCallback = UART_DMATxHalfCplt; |
mbed_official | 237:f3da66175598 | 885 | |
mbed_official | 237:f3da66175598 | 886 | /* Set the DMA error callback */ |
mbed_official | 237:f3da66175598 | 887 | huart->hdmatx->XferErrorCallback = UART_DMAError; |
mbed_official | 237:f3da66175598 | 888 | |
mbed_official | 237:f3da66175598 | 889 | /* Enable the UART transmit DMA channel */ |
mbed_official | 237:f3da66175598 | 890 | tmp = (uint32_t*)&pData; |
mbed_official | 237:f3da66175598 | 891 | HAL_DMA_Start_IT(huart->hdmatx, *(uint32_t*)tmp, (uint32_t)&huart->Instance->TDR, Size); |
mbed_official | 237:f3da66175598 | 892 | |
mbed_official | 237:f3da66175598 | 893 | /* Enable the DMA transfer for transmit request by setting the DMAT bit |
mbed_official | 237:f3da66175598 | 894 | in the UART CR3 register */ |
mbed_official | 237:f3da66175598 | 895 | huart->Instance->CR3 |= USART_CR3_DMAT; |
mbed_official | 237:f3da66175598 | 896 | |
mbed_official | 237:f3da66175598 | 897 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 898 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 899 | |
mbed_official | 237:f3da66175598 | 900 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 901 | } |
mbed_official | 237:f3da66175598 | 902 | else |
mbed_official | 237:f3da66175598 | 903 | { |
mbed_official | 237:f3da66175598 | 904 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 905 | } |
mbed_official | 237:f3da66175598 | 906 | } |
mbed_official | 237:f3da66175598 | 907 | |
mbed_official | 237:f3da66175598 | 908 | /** |
mbed_official | 237:f3da66175598 | 909 | * @brief Receive an amount of data in DMA mode |
mbed_official | 237:f3da66175598 | 910 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 911 | * @param pData: pointer to data buffer |
mbed_official | 237:f3da66175598 | 912 | * @param Size: amount of data to be received |
mbed_official | 237:f3da66175598 | 913 | * @note When the UART parity is enabled (PCE = 1), the received data contain |
mbed_official | 237:f3da66175598 | 914 | * the parity bit (MSB position) |
mbed_official | 237:f3da66175598 | 915 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 916 | */ |
mbed_official | 237:f3da66175598 | 917 | HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) |
mbed_official | 237:f3da66175598 | 918 | { |
mbed_official | 237:f3da66175598 | 919 | uint32_t *tmp; |
mbed_official | 237:f3da66175598 | 920 | |
mbed_official | 237:f3da66175598 | 921 | if((huart->State == HAL_UART_STATE_READY) || (huart->State == HAL_UART_STATE_BUSY_TX)) |
mbed_official | 237:f3da66175598 | 922 | { |
mbed_official | 237:f3da66175598 | 923 | if((pData == NULL ) || (Size == 0)) |
mbed_official | 237:f3da66175598 | 924 | { |
mbed_official | 237:f3da66175598 | 925 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 926 | } |
mbed_official | 237:f3da66175598 | 927 | |
mbed_official | 237:f3da66175598 | 928 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 929 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 930 | |
mbed_official | 237:f3da66175598 | 931 | huart->pRxBuffPtr = pData; |
mbed_official | 237:f3da66175598 | 932 | huart->RxXferSize = Size; |
mbed_official | 237:f3da66175598 | 933 | |
mbed_official | 237:f3da66175598 | 934 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 935 | /* Check if a transmit process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 936 | if(huart->State == HAL_UART_STATE_BUSY_TX) |
mbed_official | 237:f3da66175598 | 937 | { |
mbed_official | 237:f3da66175598 | 938 | huart->State = HAL_UART_STATE_BUSY_TX_RX; |
mbed_official | 237:f3da66175598 | 939 | } |
mbed_official | 237:f3da66175598 | 940 | else |
mbed_official | 237:f3da66175598 | 941 | { |
mbed_official | 237:f3da66175598 | 942 | huart->State = HAL_UART_STATE_BUSY_RX; |
mbed_official | 237:f3da66175598 | 943 | } |
mbed_official | 237:f3da66175598 | 944 | |
mbed_official | 237:f3da66175598 | 945 | /* Set the UART DMA transfer complete callback */ |
mbed_official | 237:f3da66175598 | 946 | huart->hdmarx->XferCpltCallback = UART_DMAReceiveCplt; |
mbed_official | 237:f3da66175598 | 947 | |
mbed_official | 237:f3da66175598 | 948 | /* Set the UART DMA Half transfer complete callback */ |
mbed_official | 237:f3da66175598 | 949 | huart->hdmarx->XferHalfCpltCallback = UART_DMARxHalfCplt; |
mbed_official | 237:f3da66175598 | 950 | |
mbed_official | 237:f3da66175598 | 951 | /* Set the DMA error callback */ |
mbed_official | 237:f3da66175598 | 952 | huart->hdmarx->XferErrorCallback = UART_DMAError; |
mbed_official | 237:f3da66175598 | 953 | |
mbed_official | 237:f3da66175598 | 954 | /* Enable the DMA channel */ |
mbed_official | 237:f3da66175598 | 955 | tmp = (uint32_t*)&pData; |
mbed_official | 237:f3da66175598 | 956 | HAL_DMA_Start_IT(huart->hdmarx, (uint32_t)&huart->Instance->RDR, *(uint32_t*)tmp, Size); |
mbed_official | 237:f3da66175598 | 957 | |
mbed_official | 237:f3da66175598 | 958 | /* Enable the DMA transfer for the receiver request by setting the DMAR bit |
mbed_official | 237:f3da66175598 | 959 | in the UART CR3 register */ |
mbed_official | 237:f3da66175598 | 960 | huart->Instance->CR3 |= USART_CR3_DMAR; |
mbed_official | 237:f3da66175598 | 961 | |
mbed_official | 237:f3da66175598 | 962 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 963 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 964 | |
mbed_official | 237:f3da66175598 | 965 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 966 | } |
mbed_official | 237:f3da66175598 | 967 | else |
mbed_official | 237:f3da66175598 | 968 | { |
mbed_official | 237:f3da66175598 | 969 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 970 | } |
mbed_official | 237:f3da66175598 | 971 | } |
mbed_official | 237:f3da66175598 | 972 | |
mbed_official | 237:f3da66175598 | 973 | /** |
mbed_official | 237:f3da66175598 | 974 | * @brief Pauses the DMA Transfer. |
mbed_official | 237:f3da66175598 | 975 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 976 | * @retval None |
mbed_official | 237:f3da66175598 | 977 | */ |
mbed_official | 237:f3da66175598 | 978 | HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 979 | { |
mbed_official | 237:f3da66175598 | 980 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 981 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 982 | |
mbed_official | 237:f3da66175598 | 983 | if(huart->State == HAL_UART_STATE_BUSY_TX) |
mbed_official | 237:f3da66175598 | 984 | { |
mbed_official | 237:f3da66175598 | 985 | /* Disable the UART DMA Tx request */ |
mbed_official | 237:f3da66175598 | 986 | huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT); |
mbed_official | 237:f3da66175598 | 987 | } |
mbed_official | 237:f3da66175598 | 988 | else if(huart->State == HAL_UART_STATE_BUSY_RX) |
mbed_official | 237:f3da66175598 | 989 | { |
mbed_official | 237:f3da66175598 | 990 | /* Disable the UART DMA Rx request */ |
mbed_official | 237:f3da66175598 | 991 | huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR); |
mbed_official | 237:f3da66175598 | 992 | } |
mbed_official | 237:f3da66175598 | 993 | else if(huart->State == HAL_UART_STATE_BUSY_TX_RX) |
mbed_official | 237:f3da66175598 | 994 | { |
mbed_official | 237:f3da66175598 | 995 | /* Disable the UART DMA Tx request */ |
mbed_official | 237:f3da66175598 | 996 | huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT); |
mbed_official | 237:f3da66175598 | 997 | /* Disable the UART DMA Rx request */ |
mbed_official | 237:f3da66175598 | 998 | huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR); |
mbed_official | 237:f3da66175598 | 999 | } |
mbed_official | 237:f3da66175598 | 1000 | |
mbed_official | 237:f3da66175598 | 1001 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1002 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 1003 | |
mbed_official | 237:f3da66175598 | 1004 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1005 | } |
mbed_official | 237:f3da66175598 | 1006 | |
mbed_official | 237:f3da66175598 | 1007 | /** |
mbed_official | 237:f3da66175598 | 1008 | * @brief Resumes the DMA Transfer. |
mbed_official | 237:f3da66175598 | 1009 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1010 | * @retval None |
mbed_official | 237:f3da66175598 | 1011 | */ |
mbed_official | 237:f3da66175598 | 1012 | HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1013 | { |
mbed_official | 237:f3da66175598 | 1014 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 1015 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 1016 | |
mbed_official | 237:f3da66175598 | 1017 | if(huart->State == HAL_UART_STATE_BUSY_TX) |
mbed_official | 237:f3da66175598 | 1018 | { |
mbed_official | 237:f3da66175598 | 1019 | /* Enable the UART DMA Tx request */ |
mbed_official | 237:f3da66175598 | 1020 | huart->Instance->CR3 |= USART_CR3_DMAT; |
mbed_official | 237:f3da66175598 | 1021 | } |
mbed_official | 237:f3da66175598 | 1022 | else if(huart->State == HAL_UART_STATE_BUSY_RX) |
mbed_official | 237:f3da66175598 | 1023 | { |
mbed_official | 237:f3da66175598 | 1024 | /* Enable the UART DMA Rx request */ |
mbed_official | 237:f3da66175598 | 1025 | huart->Instance->CR3 |= USART_CR3_DMAR; |
mbed_official | 237:f3da66175598 | 1026 | } |
mbed_official | 237:f3da66175598 | 1027 | else if(huart->State == HAL_UART_STATE_BUSY_TX_RX) |
mbed_official | 237:f3da66175598 | 1028 | { |
mbed_official | 237:f3da66175598 | 1029 | /* Enable the UART DMA Rx request before the DMA Tx request */ |
mbed_official | 237:f3da66175598 | 1030 | huart->Instance->CR3 |= USART_CR3_DMAR; |
mbed_official | 237:f3da66175598 | 1031 | /* Enable the UART DMA Tx request */ |
mbed_official | 237:f3da66175598 | 1032 | huart->Instance->CR3 |= USART_CR3_DMAT; |
mbed_official | 237:f3da66175598 | 1033 | } |
mbed_official | 237:f3da66175598 | 1034 | |
mbed_official | 237:f3da66175598 | 1035 | /* If the UART peripheral is still not enabled, enable it */ |
mbed_official | 237:f3da66175598 | 1036 | if ((huart->Instance->CR1 & USART_CR1_UE) == 0) |
mbed_official | 237:f3da66175598 | 1037 | { |
mbed_official | 237:f3da66175598 | 1038 | /* Enable UART peripheral */ |
mbed_official | 237:f3da66175598 | 1039 | __HAL_UART_ENABLE(huart); |
mbed_official | 237:f3da66175598 | 1040 | } |
mbed_official | 237:f3da66175598 | 1041 | |
mbed_official | 237:f3da66175598 | 1042 | /* TEACK and/or REACK to check before moving huart->State to Ready */ |
mbed_official | 237:f3da66175598 | 1043 | return (UART_CheckIdleState(huart)); |
mbed_official | 237:f3da66175598 | 1044 | } |
mbed_official | 237:f3da66175598 | 1045 | |
mbed_official | 237:f3da66175598 | 1046 | /** |
mbed_official | 237:f3da66175598 | 1047 | * @brief Stops the DMA Transfer. |
mbed_official | 237:f3da66175598 | 1048 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1049 | * @retval None |
mbed_official | 237:f3da66175598 | 1050 | */ |
mbed_official | 237:f3da66175598 | 1051 | HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1052 | { |
mbed_official | 237:f3da66175598 | 1053 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 1054 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 1055 | |
mbed_official | 237:f3da66175598 | 1056 | /* Disable the UART Tx/Rx DMA requests */ |
mbed_official | 237:f3da66175598 | 1057 | huart->Instance->CR3 &= ~USART_CR3_DMAT; |
mbed_official | 237:f3da66175598 | 1058 | huart->Instance->CR3 &= ~USART_CR3_DMAR; |
mbed_official | 237:f3da66175598 | 1059 | |
mbed_official | 237:f3da66175598 | 1060 | /* Abort the UART DMA tx channel */ |
mbed_official | 237:f3da66175598 | 1061 | if(huart->hdmatx != NULL) |
mbed_official | 237:f3da66175598 | 1062 | { |
mbed_official | 237:f3da66175598 | 1063 | HAL_DMA_Abort(huart->hdmatx); |
mbed_official | 237:f3da66175598 | 1064 | } |
mbed_official | 237:f3da66175598 | 1065 | /* Abort the UART DMA rx channel */ |
mbed_official | 237:f3da66175598 | 1066 | if(huart->hdmarx != NULL) |
mbed_official | 237:f3da66175598 | 1067 | { |
mbed_official | 237:f3da66175598 | 1068 | HAL_DMA_Abort(huart->hdmarx); |
mbed_official | 237:f3da66175598 | 1069 | } |
mbed_official | 237:f3da66175598 | 1070 | |
mbed_official | 237:f3da66175598 | 1071 | /* Disable UART peripheral */ |
mbed_official | 237:f3da66175598 | 1072 | __HAL_UART_DISABLE(huart); |
mbed_official | 237:f3da66175598 | 1073 | |
mbed_official | 237:f3da66175598 | 1074 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1075 | |
mbed_official | 237:f3da66175598 | 1076 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1077 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 1078 | |
mbed_official | 237:f3da66175598 | 1079 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1080 | } |
mbed_official | 237:f3da66175598 | 1081 | |
mbed_official | 237:f3da66175598 | 1082 | /** |
mbed_official | 237:f3da66175598 | 1083 | * @brief This function handles UART interrupt request. |
mbed_official | 237:f3da66175598 | 1084 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1085 | * @retval None |
mbed_official | 237:f3da66175598 | 1086 | */ |
mbed_official | 237:f3da66175598 | 1087 | void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1088 | { |
mbed_official | 237:f3da66175598 | 1089 | /* UART parity error interrupt occurred -------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1090 | if((__HAL_UART_GET_IT(huart, UART_IT_PE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_PE) != RESET)) |
mbed_official | 237:f3da66175598 | 1091 | { |
mbed_official | 237:f3da66175598 | 1092 | __HAL_UART_CLEAR_IT(huart, UART_CLEAR_PEF); |
mbed_official | 237:f3da66175598 | 1093 | |
mbed_official | 237:f3da66175598 | 1094 | huart->ErrorCode |= HAL_UART_ERROR_PE; |
mbed_official | 237:f3da66175598 | 1095 | /* Set the UART state ready to be able to start again the process */ |
mbed_official | 237:f3da66175598 | 1096 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1097 | } |
mbed_official | 237:f3da66175598 | 1098 | |
mbed_official | 237:f3da66175598 | 1099 | /* UART frame error interrupt occured --------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1100 | if((__HAL_UART_GET_IT(huart, UART_IT_FE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR) != RESET)) |
mbed_official | 237:f3da66175598 | 1101 | { |
mbed_official | 237:f3da66175598 | 1102 | __HAL_UART_CLEAR_IT(huart, UART_CLEAR_FEF); |
mbed_official | 237:f3da66175598 | 1103 | |
mbed_official | 237:f3da66175598 | 1104 | huart->ErrorCode |= HAL_UART_ERROR_FE; |
mbed_official | 237:f3da66175598 | 1105 | /* Set the UART state ready to be able to start again the process */ |
mbed_official | 237:f3da66175598 | 1106 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1107 | } |
mbed_official | 237:f3da66175598 | 1108 | |
mbed_official | 237:f3da66175598 | 1109 | /* UART noise error interrupt occured --------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1110 | if((__HAL_UART_GET_IT(huart, UART_IT_NE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR) != RESET)) |
mbed_official | 237:f3da66175598 | 1111 | { |
mbed_official | 237:f3da66175598 | 1112 | __HAL_UART_CLEAR_IT(huart, UART_CLEAR_NEF); |
mbed_official | 237:f3da66175598 | 1113 | |
mbed_official | 237:f3da66175598 | 1114 | huart->ErrorCode |= HAL_UART_ERROR_NE; |
mbed_official | 237:f3da66175598 | 1115 | /* Set the UART state ready to be able to start again the process */ |
mbed_official | 237:f3da66175598 | 1116 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1117 | } |
mbed_official | 237:f3da66175598 | 1118 | |
mbed_official | 237:f3da66175598 | 1119 | /* UART Over-Run interrupt occured -----------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1120 | if((__HAL_UART_GET_IT(huart, UART_IT_ORE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR) != RESET)) |
mbed_official | 237:f3da66175598 | 1121 | { |
mbed_official | 237:f3da66175598 | 1122 | __HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF); |
mbed_official | 237:f3da66175598 | 1123 | |
mbed_official | 237:f3da66175598 | 1124 | huart->ErrorCode |= HAL_UART_ERROR_ORE; |
mbed_official | 237:f3da66175598 | 1125 | /* Set the UART state ready to be able to start again the process */ |
mbed_official | 237:f3da66175598 | 1126 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1127 | } |
mbed_official | 237:f3da66175598 | 1128 | |
mbed_official | 237:f3da66175598 | 1129 | /* Call UART Error Call back function if need be --------------------------*/ |
mbed_official | 237:f3da66175598 | 1130 | if(huart->ErrorCode != HAL_UART_ERROR_NONE) |
mbed_official | 237:f3da66175598 | 1131 | { |
mbed_official | 237:f3da66175598 | 1132 | HAL_UART_ErrorCallback(huart); |
mbed_official | 237:f3da66175598 | 1133 | } |
mbed_official | 237:f3da66175598 | 1134 | |
mbed_official | 237:f3da66175598 | 1135 | /* UART wakeup from Stop mode interrupt occurred -------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1136 | if((__HAL_UART_GET_IT(huart, UART_IT_WUF) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_WUF) != RESET)) |
mbed_official | 237:f3da66175598 | 1137 | { |
mbed_official | 237:f3da66175598 | 1138 | __HAL_UART_CLEAR_IT(huart, UART_CLEAR_WUF); |
mbed_official | 237:f3da66175598 | 1139 | /* Set the UART state ready to be able to start again the process */ |
mbed_official | 237:f3da66175598 | 1140 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1141 | HAL_UART_WakeupCallback(huart); |
mbed_official | 237:f3da66175598 | 1142 | } |
mbed_official | 237:f3da66175598 | 1143 | |
mbed_official | 237:f3da66175598 | 1144 | /* UART in mode Receiver ---------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1145 | if((__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE) != RESET)) |
mbed_official | 237:f3da66175598 | 1146 | { |
mbed_official | 237:f3da66175598 | 1147 | UART_Receive_IT(huart); |
mbed_official | 237:f3da66175598 | 1148 | /* Clear RXNE interrupt flag */ |
mbed_official | 237:f3da66175598 | 1149 | __HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST); |
mbed_official | 237:f3da66175598 | 1150 | } |
mbed_official | 237:f3da66175598 | 1151 | |
mbed_official | 237:f3da66175598 | 1152 | |
mbed_official | 237:f3da66175598 | 1153 | /* UART in mode Transmitter ------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 1154 | if((__HAL_UART_GET_IT(huart, UART_IT_TXE) != RESET) &&(__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE) != RESET)) |
mbed_official | 237:f3da66175598 | 1155 | { |
mbed_official | 237:f3da66175598 | 1156 | UART_Transmit_IT(huart); |
mbed_official | 237:f3da66175598 | 1157 | } |
mbed_official | 237:f3da66175598 | 1158 | |
mbed_official | 237:f3da66175598 | 1159 | } |
mbed_official | 237:f3da66175598 | 1160 | |
mbed_official | 237:f3da66175598 | 1161 | |
mbed_official | 237:f3da66175598 | 1162 | /** |
mbed_official | 237:f3da66175598 | 1163 | * @brief This function handles UART Communication Timeout. |
mbed_official | 237:f3da66175598 | 1164 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1165 | * @param Flag: specifies the UART flag to check. |
mbed_official | 237:f3da66175598 | 1166 | * @param Status: The new Flag status (SET or RESET). |
mbed_official | 237:f3da66175598 | 1167 | * @param Timeout: Timeout duration |
mbed_official | 237:f3da66175598 | 1168 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1169 | */ |
mbed_official | 237:f3da66175598 | 1170 | HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Timeout) |
mbed_official | 237:f3da66175598 | 1171 | { |
mbed_official | 237:f3da66175598 | 1172 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 237:f3da66175598 | 1173 | |
mbed_official | 237:f3da66175598 | 1174 | /* Wait until flag is set */ |
mbed_official | 237:f3da66175598 | 1175 | if(Status == RESET) |
mbed_official | 237:f3da66175598 | 1176 | { |
mbed_official | 237:f3da66175598 | 1177 | while(__HAL_UART_GET_FLAG(huart, Flag) == RESET) |
mbed_official | 237:f3da66175598 | 1178 | { |
mbed_official | 237:f3da66175598 | 1179 | /* Check for the Timeout */ |
mbed_official | 237:f3da66175598 | 1180 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 237:f3da66175598 | 1181 | { |
mbed_official | 237:f3da66175598 | 1182 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
mbed_official | 237:f3da66175598 | 1183 | { |
mbed_official | 237:f3da66175598 | 1184 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
mbed_official | 237:f3da66175598 | 1185 | __HAL_UART_DISABLE_IT(huart, UART_IT_TXE); |
mbed_official | 237:f3da66175598 | 1186 | __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE); |
mbed_official | 237:f3da66175598 | 1187 | __HAL_UART_DISABLE_IT(huart, UART_IT_PE); |
mbed_official | 237:f3da66175598 | 1188 | __HAL_UART_DISABLE_IT(huart, UART_IT_ERR); |
mbed_official | 237:f3da66175598 | 1189 | |
mbed_official | 237:f3da66175598 | 1190 | huart->State = HAL_UART_STATE_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1191 | |
mbed_official | 237:f3da66175598 | 1192 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1193 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 1194 | |
mbed_official | 237:f3da66175598 | 1195 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1196 | } |
mbed_official | 237:f3da66175598 | 1197 | } |
mbed_official | 237:f3da66175598 | 1198 | } |
mbed_official | 237:f3da66175598 | 1199 | } |
mbed_official | 237:f3da66175598 | 1200 | else |
mbed_official | 237:f3da66175598 | 1201 | { |
mbed_official | 237:f3da66175598 | 1202 | while(__HAL_UART_GET_FLAG(huart, Flag) != RESET) |
mbed_official | 237:f3da66175598 | 1203 | { |
mbed_official | 237:f3da66175598 | 1204 | /* Check for the Timeout */ |
mbed_official | 237:f3da66175598 | 1205 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 237:f3da66175598 | 1206 | { |
mbed_official | 237:f3da66175598 | 1207 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
mbed_official | 237:f3da66175598 | 1208 | { |
mbed_official | 237:f3da66175598 | 1209 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
mbed_official | 237:f3da66175598 | 1210 | __HAL_UART_DISABLE_IT(huart, UART_IT_TXE); |
mbed_official | 237:f3da66175598 | 1211 | __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE); |
mbed_official | 237:f3da66175598 | 1212 | __HAL_UART_DISABLE_IT(huart, UART_IT_PE); |
mbed_official | 237:f3da66175598 | 1213 | __HAL_UART_DISABLE_IT(huart, UART_IT_ERR); |
mbed_official | 237:f3da66175598 | 1214 | |
mbed_official | 237:f3da66175598 | 1215 | huart->State = HAL_UART_STATE_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1216 | |
mbed_official | 237:f3da66175598 | 1217 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1218 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 1219 | |
mbed_official | 237:f3da66175598 | 1220 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1221 | } |
mbed_official | 237:f3da66175598 | 1222 | } |
mbed_official | 237:f3da66175598 | 1223 | } |
mbed_official | 237:f3da66175598 | 1224 | } |
mbed_official | 237:f3da66175598 | 1225 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1226 | } |
mbed_official | 237:f3da66175598 | 1227 | |
mbed_official | 237:f3da66175598 | 1228 | |
mbed_official | 237:f3da66175598 | 1229 | |
mbed_official | 237:f3da66175598 | 1230 | /** |
mbed_official | 237:f3da66175598 | 1231 | * @brief DMA UART transmit process complete callback |
mbed_official | 237:f3da66175598 | 1232 | * @param hdma: DMA handle |
mbed_official | 237:f3da66175598 | 1233 | * @retval None |
mbed_official | 237:f3da66175598 | 1234 | */ |
mbed_official | 237:f3da66175598 | 1235 | static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 1236 | { |
mbed_official | 237:f3da66175598 | 1237 | UART_HandleTypeDef* huart = ( UART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 237:f3da66175598 | 1238 | huart->TxXferCount = 0; |
mbed_official | 237:f3da66175598 | 1239 | |
mbed_official | 237:f3da66175598 | 1240 | /* Disable the DMA transfer for transmit request by setting the DMAT bit |
mbed_official | 237:f3da66175598 | 1241 | in the UART CR3 register */ |
mbed_official | 237:f3da66175598 | 1242 | huart->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DMAT); |
mbed_official | 237:f3da66175598 | 1243 | |
mbed_official | 237:f3da66175598 | 1244 | /* Wait for UART TC Flag */ |
mbed_official | 237:f3da66175598 | 1245 | if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, HAL_UART_TXDMA_TIMEOUTVALUE) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1246 | { |
mbed_official | 237:f3da66175598 | 1247 | /* Timeout Occured */ |
mbed_official | 237:f3da66175598 | 1248 | huart->State = HAL_UART_STATE_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1249 | HAL_UART_ErrorCallback(huart); |
mbed_official | 237:f3da66175598 | 1250 | } |
mbed_official | 237:f3da66175598 | 1251 | else |
mbed_official | 237:f3da66175598 | 1252 | { |
mbed_official | 237:f3da66175598 | 1253 | /* No Timeout */ |
mbed_official | 237:f3da66175598 | 1254 | /* Check if a receive process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 1255 | if(huart->State == HAL_UART_STATE_BUSY_TX_RX) |
mbed_official | 237:f3da66175598 | 1256 | { |
mbed_official | 237:f3da66175598 | 1257 | huart->State = HAL_UART_STATE_BUSY_RX; |
mbed_official | 237:f3da66175598 | 1258 | } |
mbed_official | 237:f3da66175598 | 1259 | else |
mbed_official | 237:f3da66175598 | 1260 | { |
mbed_official | 237:f3da66175598 | 1261 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1262 | } |
mbed_official | 237:f3da66175598 | 1263 | HAL_UART_TxCpltCallback(huart); |
mbed_official | 237:f3da66175598 | 1264 | } |
mbed_official | 237:f3da66175598 | 1265 | } |
mbed_official | 237:f3da66175598 | 1266 | |
mbed_official | 237:f3da66175598 | 1267 | /** |
mbed_official | 237:f3da66175598 | 1268 | * @brief DMA UART transmit process half complete callback |
mbed_official | 237:f3da66175598 | 1269 | * @param hdma : DMA handle |
mbed_official | 237:f3da66175598 | 1270 | * @retval None |
mbed_official | 237:f3da66175598 | 1271 | */ |
mbed_official | 237:f3da66175598 | 1272 | static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 1273 | { |
mbed_official | 237:f3da66175598 | 1274 | UART_HandleTypeDef* huart = (UART_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 237:f3da66175598 | 1275 | |
mbed_official | 237:f3da66175598 | 1276 | HAL_UART_TxHalfCpltCallback(huart); |
mbed_official | 237:f3da66175598 | 1277 | } |
mbed_official | 237:f3da66175598 | 1278 | |
mbed_official | 237:f3da66175598 | 1279 | /** |
mbed_official | 237:f3da66175598 | 1280 | * @brief DMA UART receive process complete callback |
mbed_official | 237:f3da66175598 | 1281 | * @param hdma: DMA handle |
mbed_official | 237:f3da66175598 | 1282 | * @retval None |
mbed_official | 237:f3da66175598 | 1283 | */ |
mbed_official | 237:f3da66175598 | 1284 | static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 1285 | { |
mbed_official | 237:f3da66175598 | 1286 | UART_HandleTypeDef* huart = ( UART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 237:f3da66175598 | 1287 | huart->RxXferCount = 0; |
mbed_official | 237:f3da66175598 | 1288 | |
mbed_official | 237:f3da66175598 | 1289 | /* Disable the DMA transfer for the receiver request by setting the DMAR bit |
mbed_official | 237:f3da66175598 | 1290 | in the UART CR3 register */ |
mbed_official | 237:f3da66175598 | 1291 | huart->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DMAR); |
mbed_official | 237:f3da66175598 | 1292 | |
mbed_official | 237:f3da66175598 | 1293 | /* Check if a transmit Process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 1294 | if(huart->State == HAL_UART_STATE_BUSY_TX_RX) |
mbed_official | 237:f3da66175598 | 1295 | { |
mbed_official | 237:f3da66175598 | 1296 | huart->State = HAL_UART_STATE_BUSY_TX; |
mbed_official | 237:f3da66175598 | 1297 | } |
mbed_official | 237:f3da66175598 | 1298 | else |
mbed_official | 237:f3da66175598 | 1299 | { |
mbed_official | 237:f3da66175598 | 1300 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1301 | } |
mbed_official | 237:f3da66175598 | 1302 | HAL_UART_RxCpltCallback(huart); |
mbed_official | 237:f3da66175598 | 1303 | } |
mbed_official | 237:f3da66175598 | 1304 | |
mbed_official | 237:f3da66175598 | 1305 | /** |
mbed_official | 237:f3da66175598 | 1306 | * @brief DMA UART receive process half complete callback |
mbed_official | 237:f3da66175598 | 1307 | * @param hdma : DMA handle |
mbed_official | 237:f3da66175598 | 1308 | * @retval None |
mbed_official | 237:f3da66175598 | 1309 | */ |
mbed_official | 237:f3da66175598 | 1310 | static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 1311 | { |
mbed_official | 237:f3da66175598 | 1312 | UART_HandleTypeDef* huart = (UART_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 237:f3da66175598 | 1313 | |
mbed_official | 237:f3da66175598 | 1314 | HAL_UART_RxHalfCpltCallback(huart); |
mbed_official | 237:f3da66175598 | 1315 | } |
mbed_official | 237:f3da66175598 | 1316 | |
mbed_official | 237:f3da66175598 | 1317 | /** |
mbed_official | 237:f3da66175598 | 1318 | * @brief DMA UART communication error callback |
mbed_official | 237:f3da66175598 | 1319 | * @param hdma: DMA handle |
mbed_official | 237:f3da66175598 | 1320 | * @retval None |
mbed_official | 237:f3da66175598 | 1321 | */ |
mbed_official | 237:f3da66175598 | 1322 | static void UART_DMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 237:f3da66175598 | 1323 | { |
mbed_official | 237:f3da66175598 | 1324 | UART_HandleTypeDef* huart = ( UART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 237:f3da66175598 | 1325 | huart->RxXferCount = 0; |
mbed_official | 237:f3da66175598 | 1326 | huart->TxXferCount = 0; |
mbed_official | 237:f3da66175598 | 1327 | huart->State= HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1328 | huart->ErrorCode |= HAL_UART_ERROR_DMA; |
mbed_official | 237:f3da66175598 | 1329 | HAL_UART_ErrorCallback(huart); |
mbed_official | 237:f3da66175598 | 1330 | } |
mbed_official | 237:f3da66175598 | 1331 | |
mbed_official | 237:f3da66175598 | 1332 | /** |
mbed_official | 237:f3da66175598 | 1333 | * @brief Tx Transfer completed callbacks |
mbed_official | 237:f3da66175598 | 1334 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1335 | * @retval None |
mbed_official | 237:f3da66175598 | 1336 | */ |
mbed_official | 237:f3da66175598 | 1337 | __weak void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1338 | { |
mbed_official | 237:f3da66175598 | 1339 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1340 | the HAL_UART_TxCpltCallback can be implemented in the user file |
mbed_official | 237:f3da66175598 | 1341 | */ |
mbed_official | 237:f3da66175598 | 1342 | } |
mbed_official | 237:f3da66175598 | 1343 | |
mbed_official | 237:f3da66175598 | 1344 | /** |
mbed_official | 237:f3da66175598 | 1345 | * @brief Tx Half Transfer completed callbacks. |
mbed_official | 237:f3da66175598 | 1346 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1347 | * @retval None |
mbed_official | 237:f3da66175598 | 1348 | */ |
mbed_official | 237:f3da66175598 | 1349 | __weak void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1350 | { |
mbed_official | 237:f3da66175598 | 1351 | /* NOTE: This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1352 | the HAL_UART_TxHalfCpltCallback can be implemented in the user file |
mbed_official | 237:f3da66175598 | 1353 | */ |
mbed_official | 237:f3da66175598 | 1354 | } |
mbed_official | 237:f3da66175598 | 1355 | |
mbed_official | 237:f3da66175598 | 1356 | /** |
mbed_official | 237:f3da66175598 | 1357 | * @brief Rx Transfer completed callbacks |
mbed_official | 237:f3da66175598 | 1358 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1359 | * @retval None |
mbed_official | 237:f3da66175598 | 1360 | */ |
mbed_official | 237:f3da66175598 | 1361 | __weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1362 | { |
mbed_official | 237:f3da66175598 | 1363 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1364 | the HAL_UART_RxCpltCallback can be implemented in the user file |
mbed_official | 237:f3da66175598 | 1365 | */ |
mbed_official | 237:f3da66175598 | 1366 | } |
mbed_official | 237:f3da66175598 | 1367 | |
mbed_official | 237:f3da66175598 | 1368 | /** |
mbed_official | 237:f3da66175598 | 1369 | * @brief Rx Half Transfer completed callbacks. |
mbed_official | 237:f3da66175598 | 1370 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1371 | * @retval None |
mbed_official | 237:f3da66175598 | 1372 | */ |
mbed_official | 237:f3da66175598 | 1373 | __weak void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1374 | { |
mbed_official | 237:f3da66175598 | 1375 | /* NOTE: This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1376 | the HAL_UART_RxHalfCpltCallback can be implemented in the user file |
mbed_official | 237:f3da66175598 | 1377 | */ |
mbed_official | 237:f3da66175598 | 1378 | } |
mbed_official | 237:f3da66175598 | 1379 | |
mbed_official | 237:f3da66175598 | 1380 | /** |
mbed_official | 237:f3da66175598 | 1381 | * @brief UART error callbacks |
mbed_official | 237:f3da66175598 | 1382 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1383 | * @retval None |
mbed_official | 237:f3da66175598 | 1384 | */ |
mbed_official | 237:f3da66175598 | 1385 | __weak void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1386 | { |
mbed_official | 237:f3da66175598 | 1387 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1388 | the HAL_UART_ErrorCallback can be implemented in the user file |
mbed_official | 237:f3da66175598 | 1389 | */ |
mbed_official | 237:f3da66175598 | 1390 | } |
mbed_official | 237:f3da66175598 | 1391 | |
mbed_official | 237:f3da66175598 | 1392 | /** |
mbed_official | 237:f3da66175598 | 1393 | * @brief UART wakeup from Stop mode callback |
mbed_official | 237:f3da66175598 | 1394 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1395 | * @retval None |
mbed_official | 237:f3da66175598 | 1396 | */ |
mbed_official | 237:f3da66175598 | 1397 | __weak void HAL_UART_WakeupCallback(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1398 | { |
mbed_official | 237:f3da66175598 | 1399 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 1400 | the HAL_UART_WakeupCallback can be implemented in the user file |
mbed_official | 237:f3da66175598 | 1401 | */ |
mbed_official | 237:f3da66175598 | 1402 | } |
mbed_official | 237:f3da66175598 | 1403 | |
mbed_official | 237:f3da66175598 | 1404 | |
mbed_official | 237:f3da66175598 | 1405 | /** |
mbed_official | 237:f3da66175598 | 1406 | * @brief Send an amount of data in interrupt mode |
mbed_official | 237:f3da66175598 | 1407 | * Function called under interruption only, once |
mbed_official | 237:f3da66175598 | 1408 | * interruptions have been enabled by HAL_UART_Transmit_IT() |
mbed_official | 237:f3da66175598 | 1409 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1410 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1411 | */ |
mbed_official | 237:f3da66175598 | 1412 | static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1413 | { |
mbed_official | 237:f3da66175598 | 1414 | uint16_t* tmp; |
mbed_official | 237:f3da66175598 | 1415 | |
mbed_official | 237:f3da66175598 | 1416 | if ((huart->State == HAL_UART_STATE_BUSY_TX) || (huart->State == HAL_UART_STATE_BUSY_TX_RX)) |
mbed_official | 237:f3da66175598 | 1417 | { |
mbed_official | 237:f3da66175598 | 1418 | |
mbed_official | 237:f3da66175598 | 1419 | if(huart->TxXferCount == 0) |
mbed_official | 237:f3da66175598 | 1420 | { |
mbed_official | 237:f3da66175598 | 1421 | /* Disable the UART Transmit Data Register Empty Interrupt */ |
mbed_official | 237:f3da66175598 | 1422 | __HAL_UART_DISABLE_IT(huart, UART_IT_TXE); |
mbed_official | 237:f3da66175598 | 1423 | |
mbed_official | 237:f3da66175598 | 1424 | /* Check if a receive Process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 1425 | if(huart->State == HAL_UART_STATE_BUSY_TX_RX) |
mbed_official | 237:f3da66175598 | 1426 | { |
mbed_official | 237:f3da66175598 | 1427 | huart->State = HAL_UART_STATE_BUSY_RX; |
mbed_official | 237:f3da66175598 | 1428 | } |
mbed_official | 237:f3da66175598 | 1429 | else |
mbed_official | 237:f3da66175598 | 1430 | { |
mbed_official | 237:f3da66175598 | 1431 | /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 237:f3da66175598 | 1432 | __HAL_UART_DISABLE_IT(huart, UART_IT_ERR); |
mbed_official | 237:f3da66175598 | 1433 | |
mbed_official | 237:f3da66175598 | 1434 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1435 | } |
mbed_official | 237:f3da66175598 | 1436 | |
mbed_official | 237:f3da66175598 | 1437 | /* Wait on TC flag to be able to start a second transfer */ |
mbed_official | 237:f3da66175598 | 1438 | if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, HAL_UART_TIMEOUT_VALUE) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1439 | { |
mbed_official | 237:f3da66175598 | 1440 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1441 | } |
mbed_official | 237:f3da66175598 | 1442 | |
mbed_official | 237:f3da66175598 | 1443 | HAL_UART_TxCpltCallback(huart); |
mbed_official | 237:f3da66175598 | 1444 | |
mbed_official | 237:f3da66175598 | 1445 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1446 | } |
mbed_official | 237:f3da66175598 | 1447 | else |
mbed_official | 237:f3da66175598 | 1448 | { |
mbed_official | 237:f3da66175598 | 1449 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
mbed_official | 237:f3da66175598 | 1450 | { |
mbed_official | 237:f3da66175598 | 1451 | tmp = (uint16_t*) huart->pTxBuffPtr; |
mbed_official | 237:f3da66175598 | 1452 | huart->Instance->TDR = (*tmp & (uint16_t)0x01FF); |
mbed_official | 237:f3da66175598 | 1453 | huart->pTxBuffPtr += 2; |
mbed_official | 237:f3da66175598 | 1454 | } |
mbed_official | 237:f3da66175598 | 1455 | else |
mbed_official | 237:f3da66175598 | 1456 | { |
mbed_official | 237:f3da66175598 | 1457 | huart->Instance->TDR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0xFF); |
mbed_official | 237:f3da66175598 | 1458 | } |
mbed_official | 237:f3da66175598 | 1459 | |
mbed_official | 237:f3da66175598 | 1460 | huart->TxXferCount--; |
mbed_official | 237:f3da66175598 | 1461 | |
mbed_official | 237:f3da66175598 | 1462 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1463 | } |
mbed_official | 237:f3da66175598 | 1464 | } |
mbed_official | 237:f3da66175598 | 1465 | else |
mbed_official | 237:f3da66175598 | 1466 | { |
mbed_official | 237:f3da66175598 | 1467 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 1468 | } |
mbed_official | 237:f3da66175598 | 1469 | } |
mbed_official | 237:f3da66175598 | 1470 | |
mbed_official | 237:f3da66175598 | 1471 | /** |
mbed_official | 237:f3da66175598 | 1472 | * @brief Receive an amount of data in interrupt mode |
mbed_official | 237:f3da66175598 | 1473 | * Function called under interruption only, once |
mbed_official | 237:f3da66175598 | 1474 | * interruptions have been enabled by HAL_UART_Receive_IT() |
mbed_official | 237:f3da66175598 | 1475 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1476 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1477 | */ |
mbed_official | 237:f3da66175598 | 1478 | static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1479 | { |
mbed_official | 237:f3da66175598 | 1480 | uint16_t* tmp; |
mbed_official | 237:f3da66175598 | 1481 | uint16_t uhMask = huart->Mask; |
mbed_official | 237:f3da66175598 | 1482 | |
mbed_official | 237:f3da66175598 | 1483 | if((huart->State == HAL_UART_STATE_BUSY_RX) || (huart->State == HAL_UART_STATE_BUSY_TX_RX)) |
mbed_official | 237:f3da66175598 | 1484 | { |
mbed_official | 237:f3da66175598 | 1485 | |
mbed_official | 237:f3da66175598 | 1486 | if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) |
mbed_official | 237:f3da66175598 | 1487 | { |
mbed_official | 237:f3da66175598 | 1488 | tmp = (uint16_t*) huart->pRxBuffPtr ; |
mbed_official | 237:f3da66175598 | 1489 | *tmp = (uint16_t)(huart->Instance->RDR & uhMask); |
mbed_official | 237:f3da66175598 | 1490 | huart->pRxBuffPtr +=2; |
mbed_official | 237:f3da66175598 | 1491 | } |
mbed_official | 237:f3da66175598 | 1492 | else |
mbed_official | 237:f3da66175598 | 1493 | { |
mbed_official | 237:f3da66175598 | 1494 | *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->RDR & (uint8_t)uhMask); |
mbed_official | 237:f3da66175598 | 1495 | } |
mbed_official | 237:f3da66175598 | 1496 | |
mbed_official | 237:f3da66175598 | 1497 | if(--huart->RxXferCount == 0) |
mbed_official | 237:f3da66175598 | 1498 | { |
mbed_official | 237:f3da66175598 | 1499 | __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE); |
mbed_official | 237:f3da66175598 | 1500 | |
mbed_official | 237:f3da66175598 | 1501 | /* Check if a transmit Process is ongoing or not */ |
mbed_official | 237:f3da66175598 | 1502 | if(huart->State == HAL_UART_STATE_BUSY_TX_RX) |
mbed_official | 237:f3da66175598 | 1503 | { |
mbed_official | 237:f3da66175598 | 1504 | huart->State = HAL_UART_STATE_BUSY_TX; |
mbed_official | 237:f3da66175598 | 1505 | } |
mbed_official | 237:f3da66175598 | 1506 | else |
mbed_official | 237:f3da66175598 | 1507 | { |
mbed_official | 237:f3da66175598 | 1508 | /* Disable the UART Parity Error Interrupt */ |
mbed_official | 237:f3da66175598 | 1509 | __HAL_UART_DISABLE_IT(huart, UART_IT_PE); |
mbed_official | 237:f3da66175598 | 1510 | |
mbed_official | 237:f3da66175598 | 1511 | /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
mbed_official | 237:f3da66175598 | 1512 | __HAL_UART_DISABLE_IT(huart, UART_IT_ERR); |
mbed_official | 237:f3da66175598 | 1513 | |
mbed_official | 237:f3da66175598 | 1514 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1515 | } |
mbed_official | 237:f3da66175598 | 1516 | |
mbed_official | 237:f3da66175598 | 1517 | HAL_UART_RxCpltCallback(huart); |
mbed_official | 237:f3da66175598 | 1518 | |
mbed_official | 237:f3da66175598 | 1519 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1520 | } |
mbed_official | 237:f3da66175598 | 1521 | |
mbed_official | 237:f3da66175598 | 1522 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1523 | } |
mbed_official | 237:f3da66175598 | 1524 | else |
mbed_official | 237:f3da66175598 | 1525 | { |
mbed_official | 237:f3da66175598 | 1526 | return HAL_BUSY; |
mbed_official | 237:f3da66175598 | 1527 | } |
mbed_official | 237:f3da66175598 | 1528 | } |
mbed_official | 237:f3da66175598 | 1529 | |
mbed_official | 237:f3da66175598 | 1530 | /** |
mbed_official | 237:f3da66175598 | 1531 | * @} |
mbed_official | 237:f3da66175598 | 1532 | */ |
mbed_official | 237:f3da66175598 | 1533 | |
mbed_official | 237:f3da66175598 | 1534 | /** @defgroup HAL_UART_Group3 Peripheral Control functions |
mbed_official | 237:f3da66175598 | 1535 | * @brief UART control functions |
mbed_official | 237:f3da66175598 | 1536 | * |
mbed_official | 237:f3da66175598 | 1537 | @verbatim |
mbed_official | 237:f3da66175598 | 1538 | =============================================================================== |
mbed_official | 237:f3da66175598 | 1539 | ##### Peripheral Control functions ##### |
mbed_official | 237:f3da66175598 | 1540 | =============================================================================== |
mbed_official | 237:f3da66175598 | 1541 | [..] |
mbed_official | 237:f3da66175598 | 1542 | This subsection provides a set of functions allowing to control the UART. |
mbed_official | 237:f3da66175598 | 1543 | (+) HAL_UART_GetState() API is helpful to check in run-time the state of the UART peripheral. |
mbed_official | 237:f3da66175598 | 1544 | (+) HAL_MultiProcessor_EnableMuteMode() API enables mute mode |
mbed_official | 237:f3da66175598 | 1545 | (+) HAL_MultiProcessor_DisableMuteMode() API disables mute mode |
mbed_official | 237:f3da66175598 | 1546 | (+) HAL_MultiProcessor_EnterMuteMode() API enters mute mode |
mbed_official | 237:f3da66175598 | 1547 | (+) HAL_MultiProcessor_EnableMuteMode() API enables mute mode |
mbed_official | 237:f3da66175598 | 1548 | (+) UART_SetConfig() API configures the UART peripheral |
mbed_official | 237:f3da66175598 | 1549 | (+) UART_AdvFeatureConfig() API optionally configures the UART advanced features |
mbed_official | 237:f3da66175598 | 1550 | (+) UART_CheckIdleState() API ensures that TEACK and/or REACK are set after initialization |
mbed_official | 237:f3da66175598 | 1551 | (+) UART_Wakeup_AddressConfig() API configures the wake-up from stop mode parameters |
mbed_official | 237:f3da66175598 | 1552 | (+) HAL_HalfDuplex_EnableTransmitter() API disables receiver and enables transmitter |
mbed_official | 237:f3da66175598 | 1553 | (+) HAL_HalfDuplex_EnableReceiver() API disables transmitter and enables receiver |
mbed_official | 237:f3da66175598 | 1554 | (+) HAL_LIN_SendBreak() API transmits the break characters |
mbed_official | 237:f3da66175598 | 1555 | @endverbatim |
mbed_official | 237:f3da66175598 | 1556 | * @{ |
mbed_official | 237:f3da66175598 | 1557 | */ |
mbed_official | 237:f3da66175598 | 1558 | |
mbed_official | 237:f3da66175598 | 1559 | /** |
mbed_official | 237:f3da66175598 | 1560 | * @brief Enable UART in mute mode (doesn't mean UART enters mute mode; |
mbed_official | 237:f3da66175598 | 1561 | * to enter mute mode, HAL_MultiProcessor_EnterMuteMode() API must be called) |
mbed_official | 237:f3da66175598 | 1562 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1563 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1564 | */ |
mbed_official | 237:f3da66175598 | 1565 | HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1566 | { |
mbed_official | 237:f3da66175598 | 1567 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 1568 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 1569 | |
mbed_official | 237:f3da66175598 | 1570 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 1571 | |
mbed_official | 237:f3da66175598 | 1572 | /* Enable USART mute mode by setting the MME bit in the CR1 register */ |
mbed_official | 237:f3da66175598 | 1573 | huart->Instance->CR1 |= USART_CR1_MME; |
mbed_official | 237:f3da66175598 | 1574 | |
mbed_official | 237:f3da66175598 | 1575 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1576 | |
mbed_official | 237:f3da66175598 | 1577 | return (UART_CheckIdleState(huart)); |
mbed_official | 237:f3da66175598 | 1578 | } |
mbed_official | 237:f3da66175598 | 1579 | |
mbed_official | 237:f3da66175598 | 1580 | /** |
mbed_official | 237:f3da66175598 | 1581 | * @brief Disable UART mute mode (doesn't mean it actually wakes up the software, |
mbed_official | 237:f3da66175598 | 1582 | * as it may not have been in mute mode at this very moment). |
mbed_official | 237:f3da66175598 | 1583 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1584 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1585 | */ |
mbed_official | 237:f3da66175598 | 1586 | HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1587 | { |
mbed_official | 237:f3da66175598 | 1588 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 1589 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 1590 | |
mbed_official | 237:f3da66175598 | 1591 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 1592 | |
mbed_official | 237:f3da66175598 | 1593 | /* Disable USART mute mode by clearing the MME bit in the CR1 register */ |
mbed_official | 237:f3da66175598 | 1594 | huart->Instance->CR1 &= ~(USART_CR1_MME); |
mbed_official | 237:f3da66175598 | 1595 | |
mbed_official | 237:f3da66175598 | 1596 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1597 | |
mbed_official | 237:f3da66175598 | 1598 | return (UART_CheckIdleState(huart)); |
mbed_official | 237:f3da66175598 | 1599 | } |
mbed_official | 237:f3da66175598 | 1600 | |
mbed_official | 237:f3da66175598 | 1601 | /** |
mbed_official | 237:f3da66175598 | 1602 | * @brief Enter UART mute mode (means UART actually enters mute mode). |
mbed_official | 237:f3da66175598 | 1603 | * To exit from mute mode, HAL_MultiProcessor_DisableMuteMode() API must be called. |
mbed_official | 237:f3da66175598 | 1604 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1605 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1606 | */ |
mbed_official | 237:f3da66175598 | 1607 | void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1608 | { |
mbed_official | 237:f3da66175598 | 1609 | __HAL_UART_SEND_REQ(huart, UART_MUTE_MODE_REQUEST); |
mbed_official | 237:f3da66175598 | 1610 | } |
mbed_official | 237:f3da66175598 | 1611 | |
mbed_official | 237:f3da66175598 | 1612 | |
mbed_official | 237:f3da66175598 | 1613 | |
mbed_official | 237:f3da66175598 | 1614 | /** |
mbed_official | 237:f3da66175598 | 1615 | * @brief return the UART state |
mbed_official | 237:f3da66175598 | 1616 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1617 | * @retval HAL state |
mbed_official | 237:f3da66175598 | 1618 | */ |
mbed_official | 237:f3da66175598 | 1619 | HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1620 | { |
mbed_official | 237:f3da66175598 | 1621 | return huart->State; |
mbed_official | 237:f3da66175598 | 1622 | } |
mbed_official | 237:f3da66175598 | 1623 | |
mbed_official | 237:f3da66175598 | 1624 | /** |
mbed_official | 237:f3da66175598 | 1625 | * @brief Return the UART error code |
mbed_official | 237:f3da66175598 | 1626 | * @param huart : pointer to a UART_HandleTypeDef structure that contains |
mbed_official | 237:f3da66175598 | 1627 | * the configuration information for the specified UART. |
mbed_official | 237:f3da66175598 | 1628 | * @retval UART Error Code |
mbed_official | 237:f3da66175598 | 1629 | */ |
mbed_official | 237:f3da66175598 | 1630 | uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1631 | { |
mbed_official | 237:f3da66175598 | 1632 | return huart->ErrorCode; |
mbed_official | 237:f3da66175598 | 1633 | } |
mbed_official | 237:f3da66175598 | 1634 | |
mbed_official | 237:f3da66175598 | 1635 | /** |
mbed_official | 237:f3da66175598 | 1636 | * @brief Configure the UART peripheral |
mbed_official | 237:f3da66175598 | 1637 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1638 | * @retval None |
mbed_official | 237:f3da66175598 | 1639 | */ |
mbed_official | 237:f3da66175598 | 1640 | HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1641 | { |
mbed_official | 237:f3da66175598 | 1642 | uint32_t tmpreg = 0x00000000; |
mbed_official | 237:f3da66175598 | 1643 | UART_ClockSourceTypeDef clocksource = UART_CLOCKSOURCE_UNDEFINED; |
mbed_official | 237:f3da66175598 | 1644 | uint16_t brrtemp = 0x0000; |
mbed_official | 237:f3da66175598 | 1645 | uint16_t usartdiv = 0x0000; |
mbed_official | 237:f3da66175598 | 1646 | HAL_StatusTypeDef ret = HAL_OK; |
mbed_official | 237:f3da66175598 | 1647 | |
mbed_official | 237:f3da66175598 | 1648 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 1649 | assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1650 | assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength)); |
mbed_official | 237:f3da66175598 | 1651 | assert_param(IS_UART_STOPBITS(huart->Init.StopBits)); |
mbed_official | 237:f3da66175598 | 1652 | assert_param(IS_UART_PARITY(huart->Init.Parity)); |
mbed_official | 237:f3da66175598 | 1653 | assert_param(IS_UART_MODE(huart->Init.Mode)); |
mbed_official | 237:f3da66175598 | 1654 | assert_param(IS_UART_HARDWARE_FLOW_CONTROL(huart->Init.HwFlowCtl)); |
mbed_official | 237:f3da66175598 | 1655 | assert_param(IS_UART_ONEBIT_SAMPLING(huart->Init.OneBitSampling)); |
mbed_official | 237:f3da66175598 | 1656 | assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling)); |
mbed_official | 237:f3da66175598 | 1657 | |
mbed_official | 237:f3da66175598 | 1658 | |
mbed_official | 237:f3da66175598 | 1659 | /*-------------------------- USART CR1 Configuration -----------------------*/ |
mbed_official | 237:f3da66175598 | 1660 | /* Clear M, PCE, PS, TE, RE and OVER8 bits and configure |
mbed_official | 237:f3da66175598 | 1661 | * the UART Word Length, Parity, Mode and oversampling: |
mbed_official | 237:f3da66175598 | 1662 | * set the M bits according to huart->Init.WordLength value |
mbed_official | 237:f3da66175598 | 1663 | * set PCE and PS bits according to huart->Init.Parity value |
mbed_official | 237:f3da66175598 | 1664 | * set TE and RE bits according to huart->Init.Mode value |
mbed_official | 237:f3da66175598 | 1665 | * set OVER8 bit according to huart->Init.OverSampling value */ |
mbed_official | 237:f3da66175598 | 1666 | tmpreg = (uint32_t)huart->Init.WordLength | huart->Init.Parity | huart->Init.Mode | huart->Init.OverSampling ; |
mbed_official | 237:f3da66175598 | 1667 | MODIFY_REG(huart->Instance->CR1, UART_CR1_FIELDS, tmpreg); |
mbed_official | 237:f3da66175598 | 1668 | |
mbed_official | 237:f3da66175598 | 1669 | /*-------------------------- USART CR2 Configuration -----------------------*/ |
mbed_official | 237:f3da66175598 | 1670 | /* Configure the UART Stop Bits: Set STOP[13:12] bits according |
mbed_official | 237:f3da66175598 | 1671 | * to huart->Init.StopBits value */ |
mbed_official | 237:f3da66175598 | 1672 | MODIFY_REG(huart->Instance->CR2, USART_CR2_STOP, huart->Init.StopBits); |
mbed_official | 237:f3da66175598 | 1673 | |
mbed_official | 237:f3da66175598 | 1674 | /*-------------------------- USART CR3 Configuration -----------------------*/ |
mbed_official | 237:f3da66175598 | 1675 | /* Configure |
mbed_official | 237:f3da66175598 | 1676 | * - UART HardWare Flow Control: set CTSE and RTSE bits according |
mbed_official | 237:f3da66175598 | 1677 | * to huart->Init.HwFlowCtl value |
mbed_official | 237:f3da66175598 | 1678 | * - one-bit sampling method versus three samples' majority rule according |
mbed_official | 237:f3da66175598 | 1679 | * to huart->Init.OneBitSampling */ |
mbed_official | 237:f3da66175598 | 1680 | tmpreg = (uint32_t)huart->Init.HwFlowCtl | huart->Init.OneBitSampling ; |
mbed_official | 237:f3da66175598 | 1681 | MODIFY_REG(huart->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE | USART_CR3_ONEBIT), tmpreg); |
mbed_official | 237:f3da66175598 | 1682 | |
mbed_official | 237:f3da66175598 | 1683 | /*-------------------------- USART BRR Configuration -----------------------*/ |
mbed_official | 237:f3da66175598 | 1684 | __HAL_UART_GETCLOCKSOURCE(huart, clocksource); |
mbed_official | 237:f3da66175598 | 1685 | |
mbed_official | 237:f3da66175598 | 1686 | /* Check the Over Sampling to set Baud Rate Register */ |
mbed_official | 237:f3da66175598 | 1687 | if (huart->Init.OverSampling == UART_OVERSAMPLING_8) |
mbed_official | 237:f3da66175598 | 1688 | { |
mbed_official | 237:f3da66175598 | 1689 | switch (clocksource) |
mbed_official | 237:f3da66175598 | 1690 | { |
mbed_official | 237:f3da66175598 | 1691 | case UART_CLOCKSOURCE_PCLK1: |
mbed_official | 237:f3da66175598 | 1692 | usartdiv = (uint16_t)(__DIV_SAMPLING8(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1693 | break; |
mbed_official | 237:f3da66175598 | 1694 | case UART_CLOCKSOURCE_PCLK2: |
mbed_official | 237:f3da66175598 | 1695 | usartdiv = (uint16_t)(__DIV_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1696 | break; |
mbed_official | 237:f3da66175598 | 1697 | case UART_CLOCKSOURCE_HSI: |
mbed_official | 237:f3da66175598 | 1698 | usartdiv = (uint16_t)(__DIV_SAMPLING8(HSI_VALUE, huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1699 | break; |
mbed_official | 237:f3da66175598 | 1700 | case UART_CLOCKSOURCE_SYSCLK: |
mbed_official | 237:f3da66175598 | 1701 | usartdiv = (uint16_t)(__DIV_SAMPLING8(HAL_RCC_GetSysClockFreq(), huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1702 | break; |
mbed_official | 237:f3da66175598 | 1703 | case UART_CLOCKSOURCE_LSE: |
mbed_official | 237:f3da66175598 | 1704 | usartdiv = (uint16_t)(__DIV_SAMPLING8(LSE_VALUE, huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1705 | break; |
mbed_official | 237:f3da66175598 | 1706 | case UART_CLOCKSOURCE_UNDEFINED: |
mbed_official | 237:f3da66175598 | 1707 | default: |
mbed_official | 237:f3da66175598 | 1708 | ret = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1709 | break; |
mbed_official | 237:f3da66175598 | 1710 | } |
mbed_official | 237:f3da66175598 | 1711 | |
mbed_official | 237:f3da66175598 | 1712 | brrtemp = usartdiv & 0xFFF0; |
mbed_official | 237:f3da66175598 | 1713 | brrtemp |= (uint16_t)((usartdiv & (uint16_t)0x000F) >> 1U); |
mbed_official | 237:f3da66175598 | 1714 | huart->Instance->BRR = brrtemp; |
mbed_official | 237:f3da66175598 | 1715 | } |
mbed_official | 237:f3da66175598 | 1716 | else |
mbed_official | 237:f3da66175598 | 1717 | { |
mbed_official | 237:f3da66175598 | 1718 | switch (clocksource) |
mbed_official | 237:f3da66175598 | 1719 | { |
mbed_official | 237:f3da66175598 | 1720 | case UART_CLOCKSOURCE_PCLK1: |
mbed_official | 237:f3da66175598 | 1721 | huart->Instance->BRR = (uint16_t)(__DIV_SAMPLING16(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1722 | break; |
mbed_official | 237:f3da66175598 | 1723 | case UART_CLOCKSOURCE_PCLK2: |
mbed_official | 237:f3da66175598 | 1724 | huart->Instance->BRR = (uint16_t)(__DIV_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1725 | break; |
mbed_official | 237:f3da66175598 | 1726 | case UART_CLOCKSOURCE_HSI: |
mbed_official | 237:f3da66175598 | 1727 | huart->Instance->BRR = (uint16_t)(__DIV_SAMPLING16(HSI_VALUE, huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1728 | break; |
mbed_official | 237:f3da66175598 | 1729 | case UART_CLOCKSOURCE_SYSCLK: |
mbed_official | 237:f3da66175598 | 1730 | huart->Instance->BRR = (uint16_t)(__DIV_SAMPLING16(HAL_RCC_GetSysClockFreq(), huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1731 | break; |
mbed_official | 237:f3da66175598 | 1732 | case UART_CLOCKSOURCE_LSE: |
mbed_official | 237:f3da66175598 | 1733 | huart->Instance->BRR = (uint16_t)(__DIV_SAMPLING16(LSE_VALUE, huart->Init.BaudRate)); |
mbed_official | 237:f3da66175598 | 1734 | break; |
mbed_official | 237:f3da66175598 | 1735 | case UART_CLOCKSOURCE_UNDEFINED: |
mbed_official | 237:f3da66175598 | 1736 | default: |
mbed_official | 237:f3da66175598 | 1737 | ret = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 1738 | break; |
mbed_official | 237:f3da66175598 | 1739 | } |
mbed_official | 237:f3da66175598 | 1740 | } |
mbed_official | 237:f3da66175598 | 1741 | |
mbed_official | 237:f3da66175598 | 1742 | return ret; |
mbed_official | 237:f3da66175598 | 1743 | |
mbed_official | 237:f3da66175598 | 1744 | } |
mbed_official | 237:f3da66175598 | 1745 | |
mbed_official | 237:f3da66175598 | 1746 | |
mbed_official | 237:f3da66175598 | 1747 | /** |
mbed_official | 237:f3da66175598 | 1748 | * @brief Configure the UART peripheral advanced feautures |
mbed_official | 237:f3da66175598 | 1749 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1750 | * @retval None |
mbed_official | 237:f3da66175598 | 1751 | */ |
mbed_official | 237:f3da66175598 | 1752 | void UART_AdvFeatureConfig(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1753 | { |
mbed_official | 237:f3da66175598 | 1754 | /* Check whether the set of advanced features to configure is properly set */ |
mbed_official | 237:f3da66175598 | 1755 | assert_param(IS_UART_ADVFEATURE_INIT(huart->AdvancedInit.AdvFeatureInit)); |
mbed_official | 237:f3da66175598 | 1756 | |
mbed_official | 237:f3da66175598 | 1757 | /* if required, configure TX pin active level inversion */ |
mbed_official | 237:f3da66175598 | 1758 | if (HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_TXINVERT_INIT)) |
mbed_official | 237:f3da66175598 | 1759 | { |
mbed_official | 237:f3da66175598 | 1760 | assert_param(IS_UART_ADVFEATURE_TXINV(huart->AdvancedInit.TxPinLevelInvert)); |
mbed_official | 237:f3da66175598 | 1761 | MODIFY_REG(huart->Instance->CR2, USART_CR2_TXINV, huart->AdvancedInit.TxPinLevelInvert); |
mbed_official | 237:f3da66175598 | 1762 | } |
mbed_official | 237:f3da66175598 | 1763 | |
mbed_official | 237:f3da66175598 | 1764 | /* if required, configure RX pin active level inversion */ |
mbed_official | 237:f3da66175598 | 1765 | if (HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_RXINVERT_INIT)) |
mbed_official | 237:f3da66175598 | 1766 | { |
mbed_official | 237:f3da66175598 | 1767 | assert_param(IS_UART_ADVFEATURE_RXINV(huart->AdvancedInit.RxPinLevelInvert)); |
mbed_official | 237:f3da66175598 | 1768 | MODIFY_REG(huart->Instance->CR2, USART_CR2_RXINV, huart->AdvancedInit.RxPinLevelInvert); |
mbed_official | 237:f3da66175598 | 1769 | } |
mbed_official | 237:f3da66175598 | 1770 | |
mbed_official | 237:f3da66175598 | 1771 | /* if required, configure data inversion */ |
mbed_official | 237:f3da66175598 | 1772 | if (HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_DATAINVERT_INIT)) |
mbed_official | 237:f3da66175598 | 1773 | { |
mbed_official | 237:f3da66175598 | 1774 | assert_param(IS_UART_ADVFEATURE_DATAINV(huart->AdvancedInit.DataInvert)); |
mbed_official | 237:f3da66175598 | 1775 | MODIFY_REG(huart->Instance->CR2, USART_CR2_DATAINV, huart->AdvancedInit.DataInvert); |
mbed_official | 237:f3da66175598 | 1776 | } |
mbed_official | 237:f3da66175598 | 1777 | |
mbed_official | 237:f3da66175598 | 1778 | /* if required, configure RX/TX pins swap */ |
mbed_official | 237:f3da66175598 | 1779 | if (HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_SWAP_INIT)) |
mbed_official | 237:f3da66175598 | 1780 | { |
mbed_official | 237:f3da66175598 | 1781 | assert_param(IS_UART_ADVFEATURE_SWAP(huart->AdvancedInit.Swap)); |
mbed_official | 237:f3da66175598 | 1782 | MODIFY_REG(huart->Instance->CR2, USART_CR2_SWAP, huart->AdvancedInit.Swap); |
mbed_official | 237:f3da66175598 | 1783 | } |
mbed_official | 237:f3da66175598 | 1784 | |
mbed_official | 237:f3da66175598 | 1785 | /* if required, configure RX overrun detection disabling */ |
mbed_official | 237:f3da66175598 | 1786 | if (HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_RXOVERRUNDISABLE_INIT)) |
mbed_official | 237:f3da66175598 | 1787 | { |
mbed_official | 237:f3da66175598 | 1788 | assert_param(IS_UART_OVERRUN(huart->AdvancedInit.OverrunDisable)); |
mbed_official | 237:f3da66175598 | 1789 | MODIFY_REG(huart->Instance->CR3, USART_CR3_OVRDIS, huart->AdvancedInit.OverrunDisable); |
mbed_official | 237:f3da66175598 | 1790 | } |
mbed_official | 237:f3da66175598 | 1791 | |
mbed_official | 237:f3da66175598 | 1792 | /* if required, configure DMA disabling on reception error */ |
mbed_official | 237:f3da66175598 | 1793 | if (HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_DMADISABLEONERROR_INIT)) |
mbed_official | 237:f3da66175598 | 1794 | { |
mbed_official | 237:f3da66175598 | 1795 | assert_param(IS_UART_ADVFEATURE_DMAONRXERROR(huart->AdvancedInit.DMADisableonRxError)); |
mbed_official | 237:f3da66175598 | 1796 | MODIFY_REG(huart->Instance->CR3, USART_CR3_DDRE, huart->AdvancedInit.DMADisableonRxError); |
mbed_official | 237:f3da66175598 | 1797 | } |
mbed_official | 237:f3da66175598 | 1798 | |
mbed_official | 237:f3da66175598 | 1799 | /* if required, configure auto Baud rate detection scheme */ |
mbed_official | 237:f3da66175598 | 1800 | if (HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_AUTOBAUDRATE_INIT)) |
mbed_official | 237:f3da66175598 | 1801 | { |
mbed_official | 237:f3da66175598 | 1802 | assert_param(IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(huart->Instance)); |
mbed_official | 237:f3da66175598 | 1803 | assert_param(IS_UART_ADVFEATURE_AUTOBAUDRATE(huart->AdvancedInit.AutoBaudRateEnable)); |
mbed_official | 237:f3da66175598 | 1804 | MODIFY_REG(huart->Instance->CR2, USART_CR2_ABREN, huart->AdvancedInit.AutoBaudRateEnable); |
mbed_official | 237:f3da66175598 | 1805 | /* set auto Baudrate detection parameters if detection is enabled */ |
mbed_official | 237:f3da66175598 | 1806 | if (huart->AdvancedInit.AutoBaudRateEnable == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE) |
mbed_official | 237:f3da66175598 | 1807 | { |
mbed_official | 237:f3da66175598 | 1808 | assert_param(IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(huart->AdvancedInit.AutoBaudRateMode)); |
mbed_official | 237:f3da66175598 | 1809 | MODIFY_REG(huart->Instance->CR2, USART_CR2_ABRMODE, huart->AdvancedInit.AutoBaudRateMode); |
mbed_official | 237:f3da66175598 | 1810 | } |
mbed_official | 237:f3da66175598 | 1811 | } |
mbed_official | 237:f3da66175598 | 1812 | |
mbed_official | 237:f3da66175598 | 1813 | /* if required, configure MSB first on communication line */ |
mbed_official | 237:f3da66175598 | 1814 | if (HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_MSBFIRST_INIT)) |
mbed_official | 237:f3da66175598 | 1815 | { |
mbed_official | 237:f3da66175598 | 1816 | assert_param(IS_UART_ADVFEATURE_MSBFIRST(huart->AdvancedInit.MSBFirst)); |
mbed_official | 237:f3da66175598 | 1817 | MODIFY_REG(huart->Instance->CR2, USART_CR2_MSBFIRST, huart->AdvancedInit.MSBFirst); |
mbed_official | 237:f3da66175598 | 1818 | } |
mbed_official | 237:f3da66175598 | 1819 | } |
mbed_official | 237:f3da66175598 | 1820 | |
mbed_official | 237:f3da66175598 | 1821 | |
mbed_official | 237:f3da66175598 | 1822 | |
mbed_official | 237:f3da66175598 | 1823 | /** |
mbed_official | 237:f3da66175598 | 1824 | * @brief Check the UART Idle State |
mbed_official | 237:f3da66175598 | 1825 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1826 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1827 | */ |
mbed_official | 237:f3da66175598 | 1828 | HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1829 | { |
mbed_official | 237:f3da66175598 | 1830 | /* Initialize the UART ErrorCode */ |
mbed_official | 237:f3da66175598 | 1831 | huart->ErrorCode = HAL_UART_ERROR_NONE; |
mbed_official | 237:f3da66175598 | 1832 | |
mbed_official | 237:f3da66175598 | 1833 | /* Check if the Transmitter is enabled */ |
mbed_official | 237:f3da66175598 | 1834 | if((huart->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE) |
mbed_official | 237:f3da66175598 | 1835 | { |
mbed_official | 237:f3da66175598 | 1836 | /* Wait until TEACK flag is set */ |
mbed_official | 237:f3da66175598 | 1837 | if(UART_WaitOnFlagUntilTimeout(huart, USART_ISR_TEACK, RESET, HAL_UART_TIMEOUT_VALUE) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1838 | { |
mbed_official | 237:f3da66175598 | 1839 | /* Timeout Occured */ |
mbed_official | 237:f3da66175598 | 1840 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1841 | } |
mbed_official | 237:f3da66175598 | 1842 | } |
mbed_official | 237:f3da66175598 | 1843 | /* Check if the Receiver is enabled */ |
mbed_official | 237:f3da66175598 | 1844 | if((huart->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE) |
mbed_official | 237:f3da66175598 | 1845 | { |
mbed_official | 237:f3da66175598 | 1846 | /* Wait until REACK flag is set */ |
mbed_official | 237:f3da66175598 | 1847 | if(UART_WaitOnFlagUntilTimeout(huart, USART_ISR_REACK, RESET, HAL_UART_TIMEOUT_VALUE) != HAL_OK) |
mbed_official | 237:f3da66175598 | 1848 | { |
mbed_official | 237:f3da66175598 | 1849 | /* Timeout Occured */ |
mbed_official | 237:f3da66175598 | 1850 | return HAL_TIMEOUT; |
mbed_official | 237:f3da66175598 | 1851 | } |
mbed_official | 237:f3da66175598 | 1852 | } |
mbed_official | 237:f3da66175598 | 1853 | |
mbed_official | 237:f3da66175598 | 1854 | /* Initialize the UART State */ |
mbed_official | 237:f3da66175598 | 1855 | huart->State= HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1856 | |
mbed_official | 237:f3da66175598 | 1857 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1858 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 1859 | |
mbed_official | 237:f3da66175598 | 1860 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1861 | } |
mbed_official | 237:f3da66175598 | 1862 | |
mbed_official | 237:f3da66175598 | 1863 | |
mbed_official | 237:f3da66175598 | 1864 | |
mbed_official | 237:f3da66175598 | 1865 | |
mbed_official | 237:f3da66175598 | 1866 | /** |
mbed_official | 237:f3da66175598 | 1867 | * @brief Initializes the UART wake-up from stop mode parameters when triggered by address detection. |
mbed_official | 237:f3da66175598 | 1868 | * @param huart: uart handle |
mbed_official | 237:f3da66175598 | 1869 | * @param WakeUpSelection: UART wake up from stop mode parameters |
mbed_official | 237:f3da66175598 | 1870 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1871 | */ |
mbed_official | 237:f3da66175598 | 1872 | void UART_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection) |
mbed_official | 237:f3da66175598 | 1873 | { |
mbed_official | 237:f3da66175598 | 1874 | assert_param(IS_UART_ADDRESSLENGTH_DETECT(WakeUpSelection.AddressLength)); |
mbed_official | 237:f3da66175598 | 1875 | |
mbed_official | 237:f3da66175598 | 1876 | /* Set the USART address length */ |
mbed_official | 237:f3da66175598 | 1877 | MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, WakeUpSelection.AddressLength); |
mbed_official | 237:f3da66175598 | 1878 | |
mbed_official | 237:f3da66175598 | 1879 | /* Set the USART address node */ |
mbed_official | 237:f3da66175598 | 1880 | MODIFY_REG(huart->Instance->CR2, USART_CR2_ADD, ((uint32_t)WakeUpSelection.Address << UART_CR2_ADDRESS_LSB_POS)); |
mbed_official | 237:f3da66175598 | 1881 | } |
mbed_official | 237:f3da66175598 | 1882 | |
mbed_official | 237:f3da66175598 | 1883 | /** |
mbed_official | 237:f3da66175598 | 1884 | * @brief Enables the UART transmitter and disables the UART receiver. |
mbed_official | 237:f3da66175598 | 1885 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1886 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1887 | * @retval None |
mbed_official | 237:f3da66175598 | 1888 | */ |
mbed_official | 237:f3da66175598 | 1889 | HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1890 | { |
mbed_official | 237:f3da66175598 | 1891 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 1892 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 1893 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 1894 | |
mbed_official | 237:f3da66175598 | 1895 | /* Clear TE and RE bits */ |
mbed_official | 237:f3da66175598 | 1896 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TE | USART_CR1_RE)); |
mbed_official | 237:f3da66175598 | 1897 | /* Enable the USART's transmit interface by setting the TE bit in the USART CR1 register */ |
mbed_official | 237:f3da66175598 | 1898 | SET_BIT(huart->Instance->CR1, USART_CR1_TE); |
mbed_official | 237:f3da66175598 | 1899 | |
mbed_official | 237:f3da66175598 | 1900 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1901 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1902 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 1903 | |
mbed_official | 237:f3da66175598 | 1904 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1905 | } |
mbed_official | 237:f3da66175598 | 1906 | |
mbed_official | 237:f3da66175598 | 1907 | /** |
mbed_official | 237:f3da66175598 | 1908 | * @brief Enables the UART receiver and disables the UART transmitter. |
mbed_official | 237:f3da66175598 | 1909 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1910 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1911 | */ |
mbed_official | 237:f3da66175598 | 1912 | HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1913 | { |
mbed_official | 237:f3da66175598 | 1914 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 1915 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 1916 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 1917 | |
mbed_official | 237:f3da66175598 | 1918 | /* Clear TE and RE bits */ |
mbed_official | 237:f3da66175598 | 1919 | CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TE | USART_CR1_RE)); |
mbed_official | 237:f3da66175598 | 1920 | /* Enable the USART's receive interface by setting the RE bit in the USART CR1 register */ |
mbed_official | 237:f3da66175598 | 1921 | SET_BIT(huart->Instance->CR1, USART_CR1_RE); |
mbed_official | 237:f3da66175598 | 1922 | |
mbed_official | 237:f3da66175598 | 1923 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1924 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1925 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 1926 | |
mbed_official | 237:f3da66175598 | 1927 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1928 | } |
mbed_official | 237:f3da66175598 | 1929 | |
mbed_official | 237:f3da66175598 | 1930 | |
mbed_official | 237:f3da66175598 | 1931 | /** |
mbed_official | 237:f3da66175598 | 1932 | * @brief Transmits break characters. |
mbed_official | 237:f3da66175598 | 1933 | * @param huart: UART handle |
mbed_official | 237:f3da66175598 | 1934 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 1935 | */ |
mbed_official | 237:f3da66175598 | 1936 | HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart) |
mbed_official | 237:f3da66175598 | 1937 | { |
mbed_official | 237:f3da66175598 | 1938 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 1939 | assert_param(IS_UART_INSTANCE(huart->Instance)); |
mbed_official | 237:f3da66175598 | 1940 | |
mbed_official | 237:f3da66175598 | 1941 | /* Process Locked */ |
mbed_official | 237:f3da66175598 | 1942 | __HAL_LOCK(huart); |
mbed_official | 237:f3da66175598 | 1943 | |
mbed_official | 237:f3da66175598 | 1944 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 1945 | |
mbed_official | 237:f3da66175598 | 1946 | /* Send break characters */ |
mbed_official | 237:f3da66175598 | 1947 | huart->Instance->RQR |= UART_SENDBREAK_REQUEST; |
mbed_official | 237:f3da66175598 | 1948 | |
mbed_official | 237:f3da66175598 | 1949 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 237:f3da66175598 | 1950 | |
mbed_official | 237:f3da66175598 | 1951 | /* Process Unlocked */ |
mbed_official | 237:f3da66175598 | 1952 | __HAL_UNLOCK(huart); |
mbed_official | 237:f3da66175598 | 1953 | |
mbed_official | 237:f3da66175598 | 1954 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 1955 | } |
mbed_official | 237:f3da66175598 | 1956 | |
mbed_official | 237:f3da66175598 | 1957 | |
mbed_official | 237:f3da66175598 | 1958 | /** |
mbed_official | 237:f3da66175598 | 1959 | * @} |
mbed_official | 237:f3da66175598 | 1960 | */ |
mbed_official | 237:f3da66175598 | 1961 | |
mbed_official | 237:f3da66175598 | 1962 | /** |
mbed_official | 237:f3da66175598 | 1963 | * @} |
mbed_official | 237:f3da66175598 | 1964 | */ |
mbed_official | 237:f3da66175598 | 1965 | |
mbed_official | 237:f3da66175598 | 1966 | #endif /* HAL_UART_MODULE_ENABLED */ |
mbed_official | 237:f3da66175598 | 1967 | /** |
mbed_official | 237:f3da66175598 | 1968 | * @} |
mbed_official | 237:f3da66175598 | 1969 | */ |
mbed_official | 237:f3da66175598 | 1970 | |
mbed_official | 237:f3da66175598 | 1971 | /** |
mbed_official | 237:f3da66175598 | 1972 | * @} |
mbed_official | 237:f3da66175598 | 1973 | */ |
mbed_official | 237:f3da66175598 | 1974 | |
mbed_official | 237:f3da66175598 | 1975 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |