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