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