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