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