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