mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri May 30 15:30:09 2014 +0100
Revision:
218:44081b78fdc2
Parent:
205:c41fc65bcfb4
Synchronized with git revision d854859072d318241476ccc5f335965444d4c1d8

Full URL: https://github.com/mbedmicro/mbed/commit/d854859072d318241476ccc5f335965444d4c1d8/

[NUCLEO_F072RB] Update CubeF0 HAL driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 205:c41fc65bcfb4 1 /**
mbed_official 205:c41fc65bcfb4 2 ******************************************************************************
mbed_official 205:c41fc65bcfb4 3 * @file stm32f0xx_hal_usart.c
mbed_official 205:c41fc65bcfb4 4 * @author MCD Application Team
mbed_official 205:c41fc65bcfb4 5 * @version V1.0.0
mbed_official 218:44081b78fdc2 6 * @date 28-May-2014
mbed_official 205:c41fc65bcfb4 7 * @brief USART HAL module driver.
mbed_official 205:c41fc65bcfb4 8 *
mbed_official 205:c41fc65bcfb4 9 * This file provides firmware functions to manage the following
mbed_official 205:c41fc65bcfb4 10 * functionalities of the Universal Synchronous/Asynchronous Receiver Transmitter
mbed_official 205:c41fc65bcfb4 11 * Peripheral (USART).
mbed_official 205:c41fc65bcfb4 12 * + Initialization and de-initialization function
mbed_official 205:c41fc65bcfb4 13 * + IO operation function
mbed_official 205:c41fc65bcfb4 14 * + Peripheral Control function
mbed_official 205:c41fc65bcfb4 15 *
mbed_official 205:c41fc65bcfb4 16 @verbatim
mbed_official 205:c41fc65bcfb4 17 ===============================================================================
mbed_official 205:c41fc65bcfb4 18 ##### How to use this driver #####
mbed_official 205:c41fc65bcfb4 19 ===============================================================================
mbed_official 205:c41fc65bcfb4 20 [..]
mbed_official 205:c41fc65bcfb4 21 The USART HAL driver can be used as follows:
mbed_official 205:c41fc65bcfb4 22
mbed_official 205:c41fc65bcfb4 23 (#) Declare a USART_HandleTypeDef handle structure.
mbed_official 205:c41fc65bcfb4 24 (#) Initialize the USART low level resources by implement the HAL_USART_MspInit ()API:
mbed_official 205:c41fc65bcfb4 25 (##) Enable the USARTx interface clock.
mbed_official 205:c41fc65bcfb4 26 (##) USART pins configuration:
mbed_official 205:c41fc65bcfb4 27 (+) Enable the clock for the USART GPIOs.
mbed_official 205:c41fc65bcfb4 28 (+) Configure these USART pins as alternate function pull-up.
mbed_official 205:c41fc65bcfb4 29 (##) NVIC configuration if you need to use interrupt process (HAL_USART_Transmit_IT(),
mbed_official 205:c41fc65bcfb4 30 HAL_USART_Receive_IT() and HAL_USART_TransmitReceive_IT() APIs):
mbed_official 205:c41fc65bcfb4 31 (+) Configure the USARTx interrupt priority.
mbed_official 205:c41fc65bcfb4 32 (+) Enable the NVIC USART IRQ handle.
mbed_official 205:c41fc65bcfb4 33 (@) The specific USART interrupts (Transmission complete interrupt,
mbed_official 205:c41fc65bcfb4 34 RXNE interrupt and Error Interrupts) will be managed using the macros
mbed_official 205:c41fc65bcfb4 35 __HAL_USART_ENABLE_IT() and __HAL_USART_DISABLE_IT() inside the transmit and receive process.
mbed_official 205:c41fc65bcfb4 36 (##) DMA Configuration if you need to use DMA process (HAL_USART_Transmit_DMA()
mbed_official 205:c41fc65bcfb4 37 HAL_USART_Receive_IT() and HAL_USART_TransmitReceive_IT() APIs):
mbed_official 205:c41fc65bcfb4 38 (+) Declare a DMA handle structure for the Tx/Rx stream.
mbed_official 205:c41fc65bcfb4 39 (+) Enable the DMAx interface clock.
mbed_official 205:c41fc65bcfb4 40 (+) Configure the declared DMA handle structure with the required Tx/Rx parameters.
mbed_official 205:c41fc65bcfb4 41 (+) Configure the DMA Tx/Rx Stream.
mbed_official 205:c41fc65bcfb4 42 (+) Associate the initilalized DMA handle to the USART DMA Tx/Rx handle.
mbed_official 205:c41fc65bcfb4 43 (+) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx Stream.
mbed_official 205:c41fc65bcfb4 44
mbed_official 205:c41fc65bcfb4 45 (#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware
mbed_official 205:c41fc65bcfb4 46 flow control and Mode(Receiver/Transmitter) in the husart Init structure.
mbed_official 205:c41fc65bcfb4 47
mbed_official 205:c41fc65bcfb4 48 (#) Initialize the USART registers by calling the HAL_USART_Init() API:
mbed_official 205:c41fc65bcfb4 49 (+) These API's configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
mbed_official 205:c41fc65bcfb4 50 by calling the customed HAL_USART_MspInit(&husart) API.
mbed_official 205:c41fc65bcfb4 51
mbed_official 205:c41fc65bcfb4 52 @endverbatim
mbed_official 205:c41fc65bcfb4 53 ******************************************************************************
mbed_official 205:c41fc65bcfb4 54 * @attention
mbed_official 205:c41fc65bcfb4 55 *
mbed_official 205:c41fc65bcfb4 56 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 205:c41fc65bcfb4 57 *
mbed_official 205:c41fc65bcfb4 58 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 205:c41fc65bcfb4 59 * are permitted provided that the following conditions are met:
mbed_official 205:c41fc65bcfb4 60 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 205:c41fc65bcfb4 61 * this list of conditions and the following disclaimer.
mbed_official 205:c41fc65bcfb4 62 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 205:c41fc65bcfb4 63 * this list of conditions and the following disclaimer in the documentation
mbed_official 205:c41fc65bcfb4 64 * and/or other materials provided with the distribution.
mbed_official 205:c41fc65bcfb4 65 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 205:c41fc65bcfb4 66 * may be used to endorse or promote products derived from this software
mbed_official 205:c41fc65bcfb4 67 * without specific prior written permission.
mbed_official 205:c41fc65bcfb4 68 *
mbed_official 205:c41fc65bcfb4 69 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 205:c41fc65bcfb4 70 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 205:c41fc65bcfb4 71 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 205:c41fc65bcfb4 72 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 205:c41fc65bcfb4 73 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 205:c41fc65bcfb4 74 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 205:c41fc65bcfb4 75 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 205:c41fc65bcfb4 76 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 205:c41fc65bcfb4 77 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 205:c41fc65bcfb4 78 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 205:c41fc65bcfb4 79 *
mbed_official 205:c41fc65bcfb4 80 ******************************************************************************
mbed_official 205:c41fc65bcfb4 81 */
mbed_official 205:c41fc65bcfb4 82
mbed_official 205:c41fc65bcfb4 83 /* Includes ------------------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 84 #include "stm32f0xx_hal.h"
mbed_official 205:c41fc65bcfb4 85
mbed_official 205:c41fc65bcfb4 86 /** @addtogroup STM32F0xx_HAL_Driver
mbed_official 205:c41fc65bcfb4 87 * @{
mbed_official 205:c41fc65bcfb4 88 */
mbed_official 205:c41fc65bcfb4 89
mbed_official 205:c41fc65bcfb4 90 /** @defgroup USART
mbed_official 205:c41fc65bcfb4 91 * @brief HAL USART Synchronous module driver
mbed_official 205:c41fc65bcfb4 92 * @{
mbed_official 205:c41fc65bcfb4 93 */
mbed_official 205:c41fc65bcfb4 94 #ifdef HAL_USART_MODULE_ENABLED
mbed_official 205:c41fc65bcfb4 95 /* Private typedef -----------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 96 /* Private define ------------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 97 #define DUMMY_DATA ((uint16_t) 0xFFFF)
mbed_official 205:c41fc65bcfb4 98 #define TEACK_REACK_TIMEOUT ((uint32_t) 1000)
mbed_official 205:c41fc65bcfb4 99 #define HAL_USART_TXDMA_TIMEOUTVALUE 22000
mbed_official 205:c41fc65bcfb4 100 #define USART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | \
mbed_official 205:c41fc65bcfb4 101 USART_CR1_PS | USART_CR1_TE | USART_CR1_RE))
mbed_official 205:c41fc65bcfb4 102 #define USART_CR2_FIELDS ((uint32_t)(USART_CR2_CPHA | USART_CR2_CPOL | \
mbed_official 205:c41fc65bcfb4 103 USART_CR2_CLKEN | USART_CR2_LBCL | USART_CR2_STOP))
mbed_official 205:c41fc65bcfb4 104 /* Private macro -------------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 105 /* Private variables ---------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 106 /* Private function prototypes -----------------------------------------------*/
mbed_official 205:c41fc65bcfb4 107 static void USART_DMATransmitCplt(DMA_HandleTypeDef *hdma);
mbed_official 205:c41fc65bcfb4 108 static void USART_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
mbed_official 205:c41fc65bcfb4 109 static void USART_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
mbed_official 205:c41fc65bcfb4 110 static void USART_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
mbed_official 205:c41fc65bcfb4 111 static void USART_DMAError(DMA_HandleTypeDef *hdma);
mbed_official 205:c41fc65bcfb4 112 static HAL_StatusTypeDef USART_WaitOnFlagUntilTimeout(USART_HandleTypeDef *husart, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
mbed_official 205:c41fc65bcfb4 113 static HAL_StatusTypeDef USART_SetConfig(USART_HandleTypeDef *husart);
mbed_official 205:c41fc65bcfb4 114 static HAL_StatusTypeDef USART_CheckIdleState(USART_HandleTypeDef *husart);
mbed_official 205:c41fc65bcfb4 115 static HAL_StatusTypeDef USART_Transmit_IT(USART_HandleTypeDef *husart);
mbed_official 205:c41fc65bcfb4 116 static HAL_StatusTypeDef USART_Receive_IT(USART_HandleTypeDef *husart);
mbed_official 205:c41fc65bcfb4 117 static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart);
mbed_official 205:c41fc65bcfb4 118 /* Private functions ---------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 119
mbed_official 205:c41fc65bcfb4 120
mbed_official 205:c41fc65bcfb4 121 /** @defgroup USART_Private_Functions
mbed_official 205:c41fc65bcfb4 122 * @{
mbed_official 205:c41fc65bcfb4 123 */
mbed_official 205:c41fc65bcfb4 124
mbed_official 205:c41fc65bcfb4 125 /** @defgroup USART_Group1 USART Initialization/de-initialization function
mbed_official 205:c41fc65bcfb4 126 * @brief Initialization and Configuration functions
mbed_official 205:c41fc65bcfb4 127 *
mbed_official 205:c41fc65bcfb4 128 @verbatim
mbed_official 205:c41fc65bcfb4 129 ===============================================================================
mbed_official 205:c41fc65bcfb4 130 ##### Initialization and Configuration functions #####
mbed_official 205:c41fc65bcfb4 131 ===============================================================================
mbed_official 205:c41fc65bcfb4 132 [..]
mbed_official 205:c41fc65bcfb4 133 This subsection provides a set of functions allowing to initialize the USART
mbed_official 205:c41fc65bcfb4 134 in asynchronous and in synchronous modes.
mbed_official 205:c41fc65bcfb4 135 (+) For the asynchronous mode only these parameters can be configured:
mbed_official 205:c41fc65bcfb4 136 (++) Baud Rate
mbed_official 205:c41fc65bcfb4 137 (++) Word Length
mbed_official 205:c41fc65bcfb4 138 (++) Stop Bit
mbed_official 205:c41fc65bcfb4 139 (++) Parity: If the parity is enabled, then the MSB bit of the data written
mbed_official 205:c41fc65bcfb4 140 in the data register is transmitted but is changed by the parity bit.
mbed_official 205:c41fc65bcfb4 141 Depending on the frame length defined by the M bit (8-bits or 9-bits)
mbed_official 205:c41fc65bcfb4 142 or by the M1 and M0 bits (7-bit, 8-bit or 9-bit),
mbed_official 205:c41fc65bcfb4 143 the possible USART frame formats are as listed in the following table:
mbed_official 205:c41fc65bcfb4 144 +---------------------------------------------------------------+
mbed_official 205:c41fc65bcfb4 145 | M bit | PCE bit | USART frame |
mbed_official 205:c41fc65bcfb4 146 |-----------|-----------|---------------------------------------|
mbed_official 205:c41fc65bcfb4 147 | 0 | 0 | | SB | 8-bit data | STB | |
mbed_official 205:c41fc65bcfb4 148 |-----------|-----------|---------------------------------------|
mbed_official 205:c41fc65bcfb4 149 | 0 | 1 | | SB | 7-bit data | PB | STB | |
mbed_official 205:c41fc65bcfb4 150 |-----------|-----------|---------------------------------------|
mbed_official 205:c41fc65bcfb4 151 | 1 | 0 | | SB | 9-bit data | STB | |
mbed_official 205:c41fc65bcfb4 152 |-----------|-----------|---------------------------------------|
mbed_official 205:c41fc65bcfb4 153 | 1 | 1 | | SB | 8-bit data | PB | STB | |
mbed_official 205:c41fc65bcfb4 154 +---------------------------------------------------------------+
mbed_official 205:c41fc65bcfb4 155 | M1M0 bits | PCE bit | USART frame |
mbed_official 205:c41fc65bcfb4 156 |-----------------------|---------------------------------------|
mbed_official 205:c41fc65bcfb4 157 | 10 | 0 | | SB | 7-bit data | STB | |
mbed_official 205:c41fc65bcfb4 158 |-----------|-----------|---------------------------------------|
mbed_official 205:c41fc65bcfb4 159 | 10 | 1 | | SB | 6-bit data | PB | STB | |
mbed_official 205:c41fc65bcfb4 160 +---------------------------------------------------------------+
mbed_official 205:c41fc65bcfb4 161 (++) USART polarity
mbed_official 205:c41fc65bcfb4 162 (++) USART phase
mbed_official 205:c41fc65bcfb4 163 (++) USART LastBit
mbed_official 205:c41fc65bcfb4 164 (++) Receiver/transmitter modes
mbed_official 205:c41fc65bcfb4 165
mbed_official 205:c41fc65bcfb4 166 [..]
mbed_official 205:c41fc65bcfb4 167 The HAL_USART_Init() function follows the USART synchronous configuration
mbed_official 205:c41fc65bcfb4 168 procedure (details for the procedure are available in reference manual).
mbed_official 205:c41fc65bcfb4 169
mbed_official 205:c41fc65bcfb4 170 @endverbatim
mbed_official 205:c41fc65bcfb4 171 * @{
mbed_official 205:c41fc65bcfb4 172 */
mbed_official 205:c41fc65bcfb4 173
mbed_official 205:c41fc65bcfb4 174 /**
mbed_official 205:c41fc65bcfb4 175 * @brief Initializes the USART mode according to the specified
mbed_official 205:c41fc65bcfb4 176 * parameters in the USART_InitTypeDef and create the associated handle .
mbed_official 205:c41fc65bcfb4 177 * @param husart: usart handle
mbed_official 205:c41fc65bcfb4 178 * @retval HAL status
mbed_official 205:c41fc65bcfb4 179 */
mbed_official 205:c41fc65bcfb4 180 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 181 {
mbed_official 205:c41fc65bcfb4 182 /* Check the USART handle allocation */
mbed_official 205:c41fc65bcfb4 183 if(husart == NULL)
mbed_official 205:c41fc65bcfb4 184 {
mbed_official 205:c41fc65bcfb4 185 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 186 }
mbed_official 205:c41fc65bcfb4 187
mbed_official 205:c41fc65bcfb4 188 /* Check the parameters */
mbed_official 205:c41fc65bcfb4 189 assert_param(IS_USART_INSTANCE(husart->Instance));
mbed_official 205:c41fc65bcfb4 190
mbed_official 205:c41fc65bcfb4 191 if(husart->State == HAL_USART_STATE_RESET)
mbed_official 205:c41fc65bcfb4 192 {
mbed_official 205:c41fc65bcfb4 193 /* Init the low level hardware : GPIO, CLOCK */
mbed_official 205:c41fc65bcfb4 194 HAL_USART_MspInit(husart);
mbed_official 205:c41fc65bcfb4 195 }
mbed_official 205:c41fc65bcfb4 196
mbed_official 205:c41fc65bcfb4 197 husart->State = HAL_USART_STATE_BUSY;
mbed_official 205:c41fc65bcfb4 198
mbed_official 205:c41fc65bcfb4 199 /* Disable the Peripheral */
mbed_official 205:c41fc65bcfb4 200 __USART_DISABLE(husart);
mbed_official 205:c41fc65bcfb4 201
mbed_official 205:c41fc65bcfb4 202 /* Set the Usart Communication parameters */
mbed_official 205:c41fc65bcfb4 203 if (USART_SetConfig(husart) == HAL_ERROR)
mbed_official 205:c41fc65bcfb4 204 {
mbed_official 205:c41fc65bcfb4 205 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 206 }
mbed_official 205:c41fc65bcfb4 207
mbed_official 205:c41fc65bcfb4 208 /* In Synchronous mode, the following bits must be kept cleared:
mbed_official 205:c41fc65bcfb4 209 - LINEN bit in the USART_CR2 register
mbed_official 205:c41fc65bcfb4 210 - HDSEL, SCEN and IREN bits in the USART_CR3 register.*/
mbed_official 205:c41fc65bcfb4 211 husart->Instance->CR2 &= ~USART_CR2_LINEN;
mbed_official 205:c41fc65bcfb4 212 husart->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN);
mbed_official 205:c41fc65bcfb4 213
mbed_official 205:c41fc65bcfb4 214 /* Enable the Peripharal */
mbed_official 205:c41fc65bcfb4 215 __USART_ENABLE(husart);
mbed_official 205:c41fc65bcfb4 216
mbed_official 205:c41fc65bcfb4 217 /* TEACK and/or REACK to check before moving husart->State to Ready */
mbed_official 205:c41fc65bcfb4 218 return (USART_CheckIdleState(husart));
mbed_official 205:c41fc65bcfb4 219 }
mbed_official 205:c41fc65bcfb4 220
mbed_official 205:c41fc65bcfb4 221 /**
mbed_official 205:c41fc65bcfb4 222 * @brief DeInitializes the USART peripheral
mbed_official 205:c41fc65bcfb4 223 * @param husart: usart handle
mbed_official 205:c41fc65bcfb4 224 * @retval HAL status
mbed_official 205:c41fc65bcfb4 225 */
mbed_official 205:c41fc65bcfb4 226 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 227 {
mbed_official 205:c41fc65bcfb4 228 /* Check the USART handle allocation */
mbed_official 205:c41fc65bcfb4 229 if(husart == NULL)
mbed_official 205:c41fc65bcfb4 230 {
mbed_official 205:c41fc65bcfb4 231 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 232 }
mbed_official 205:c41fc65bcfb4 233
mbed_official 205:c41fc65bcfb4 234 /* Check the parameters */
mbed_official 205:c41fc65bcfb4 235 assert_param(IS_USART_INSTANCE(husart->Instance));
mbed_official 205:c41fc65bcfb4 236
mbed_official 205:c41fc65bcfb4 237 husart->State = HAL_USART_STATE_BUSY;
mbed_official 205:c41fc65bcfb4 238
mbed_official 205:c41fc65bcfb4 239 husart->Instance->CR1 = 0x0;
mbed_official 205:c41fc65bcfb4 240 husart->Instance->CR2 = 0x0;
mbed_official 205:c41fc65bcfb4 241 husart->Instance->CR3 = 0x0;
mbed_official 205:c41fc65bcfb4 242
mbed_official 205:c41fc65bcfb4 243 /* DeInit the low level hardware */
mbed_official 205:c41fc65bcfb4 244 HAL_USART_MspDeInit(husart);
mbed_official 205:c41fc65bcfb4 245
mbed_official 205:c41fc65bcfb4 246 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 247 husart->State = HAL_USART_STATE_RESET;
mbed_official 205:c41fc65bcfb4 248
mbed_official 205:c41fc65bcfb4 249 /* Process Unlock */
mbed_official 205:c41fc65bcfb4 250 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 251
mbed_official 205:c41fc65bcfb4 252 return HAL_OK;
mbed_official 205:c41fc65bcfb4 253 }
mbed_official 205:c41fc65bcfb4 254
mbed_official 205:c41fc65bcfb4 255 /**
mbed_official 205:c41fc65bcfb4 256 * @brief USART MSP Init
mbed_official 205:c41fc65bcfb4 257 * @param husart: usart handle
mbed_official 205:c41fc65bcfb4 258 * @retval None
mbed_official 205:c41fc65bcfb4 259 */
mbed_official 205:c41fc65bcfb4 260 __weak void HAL_USART_MspInit(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 261 {
mbed_official 205:c41fc65bcfb4 262 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 263 the HAL_USART_MspInit can be implemented in the user file
mbed_official 205:c41fc65bcfb4 264 */
mbed_official 205:c41fc65bcfb4 265 }
mbed_official 205:c41fc65bcfb4 266
mbed_official 205:c41fc65bcfb4 267 /**
mbed_official 205:c41fc65bcfb4 268 * @brief USART MSP DeInit
mbed_official 205:c41fc65bcfb4 269 * @param husart: usart handle
mbed_official 205:c41fc65bcfb4 270 * @retval None
mbed_official 205:c41fc65bcfb4 271 */
mbed_official 205:c41fc65bcfb4 272 __weak void HAL_USART_MspDeInit(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 273 {
mbed_official 205:c41fc65bcfb4 274 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 275 the HAL_USART_MspDeInit can be implemented in the user file
mbed_official 205:c41fc65bcfb4 276 */
mbed_official 205:c41fc65bcfb4 277 }
mbed_official 205:c41fc65bcfb4 278
mbed_official 205:c41fc65bcfb4 279 /**
mbed_official 205:c41fc65bcfb4 280 * @}
mbed_official 205:c41fc65bcfb4 281 */
mbed_official 205:c41fc65bcfb4 282
mbed_official 205:c41fc65bcfb4 283 /** @defgroup HAL_USART_Group2 IO operation function
mbed_official 205:c41fc65bcfb4 284 * @brief USART Transmit/Receive functions
mbed_official 205:c41fc65bcfb4 285 *
mbed_official 205:c41fc65bcfb4 286 @verbatim
mbed_official 205:c41fc65bcfb4 287 ===============================================================================
mbed_official 205:c41fc65bcfb4 288 ##### I/O operation function #####
mbed_official 205:c41fc65bcfb4 289 ===============================================================================
mbed_official 205:c41fc65bcfb4 290 This subsection provides a set of functions allowing to manage the USART synchronous
mbed_official 205:c41fc65bcfb4 291 data transfers.
mbed_official 205:c41fc65bcfb4 292
mbed_official 205:c41fc65bcfb4 293 [..] The USART supports master mode only: it cannot receive or send data related to an input
mbed_official 205:c41fc65bcfb4 294 clock (SCLK is always an output).
mbed_official 205:c41fc65bcfb4 295
mbed_official 205:c41fc65bcfb4 296 (#) There are two mode of transfer:
mbed_official 205:c41fc65bcfb4 297 (+) Blocking mode: The communication is performed in polling mode.
mbed_official 205:c41fc65bcfb4 298 The HAL status of all data processing is returned by the same function
mbed_official 205:c41fc65bcfb4 299 after finishing transfer.
mbed_official 205:c41fc65bcfb4 300 (+) No-Blocking mode: The communication is performed using Interrupts
mbed_official 205:c41fc65bcfb4 301 or DMA, These API's return the HAL status.
mbed_official 205:c41fc65bcfb4 302 The end of the data processing will be indicated through the
mbed_official 205:c41fc65bcfb4 303 dedicated USART IRQ when using Interrupt mode or the DMA IRQ when
mbed_official 205:c41fc65bcfb4 304 using DMA mode.
mbed_official 205:c41fc65bcfb4 305 The HAL_USART_TxCpltCallback(), HAL_USART_RxCpltCallback() and HAL_USART_TxRxCpltCallback() user callbacks
mbed_official 205:c41fc65bcfb4 306 will be executed respectivelly at the end of the transmit or Receive process
mbed_official 205:c41fc65bcfb4 307 The HAL_USART_ErrorCallback()user callback will be executed when a communication error is detected
mbed_official 205:c41fc65bcfb4 308
mbed_official 205:c41fc65bcfb4 309 (#) Blocking mode API's are :
mbed_official 205:c41fc65bcfb4 310 (+) HAL_USART_Transmit()in simplex mode
mbed_official 205:c41fc65bcfb4 311 (+) HAL_USART_Receive() in full duplex receive only
mbed_official 205:c41fc65bcfb4 312 (+) HAL_USART_TransmitReceive() in full duplex mode
mbed_official 205:c41fc65bcfb4 313
mbed_official 205:c41fc65bcfb4 314 (#) Non-Blocking mode API's with Interrupt are :
mbed_official 205:c41fc65bcfb4 315 (+) HAL_USART_Transmit_IT()in simplex mode
mbed_official 205:c41fc65bcfb4 316 (+) HAL_USART_Receive_IT() in full duplex receive only
mbed_official 205:c41fc65bcfb4 317 (+) HAL_USART_TransmitReceive_IT()in full duplex mode
mbed_official 205:c41fc65bcfb4 318 (+) HAL_USART_IRQHandler()
mbed_official 205:c41fc65bcfb4 319
mbed_official 205:c41fc65bcfb4 320 (#) No-Blocking mode functions with DMA are :
mbed_official 205:c41fc65bcfb4 321 (+) HAL_USART_Transmit_DMA()in simplex mode
mbed_official 205:c41fc65bcfb4 322 (+) HAL_USART_Receive_DMA() in full duplex receive only
mbed_official 205:c41fc65bcfb4 323 (+) HAL_USART_TransmitReceive_DMA() in full duplex mode
mbed_official 205:c41fc65bcfb4 324 (+) HAL_USART_DMAPause()
mbed_official 205:c41fc65bcfb4 325 (+) HAL_USART_DMAResume()
mbed_official 205:c41fc65bcfb4 326 (+) HAL_USART_DMAStop()
mbed_official 205:c41fc65bcfb4 327
mbed_official 205:c41fc65bcfb4 328 (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
mbed_official 205:c41fc65bcfb4 329 (+) HAL_USART_TxCpltCallback()
mbed_official 205:c41fc65bcfb4 330 (+) HAL_USART_RxCpltCallback()
mbed_official 205:c41fc65bcfb4 331 (+) HAL_USART_TxHalfCpltCallback()
mbed_official 205:c41fc65bcfb4 332 (+) HAL_USART_RxHalfCpltCallback()
mbed_official 205:c41fc65bcfb4 333 (+) HAL_USART_ErrorCallback()
mbed_official 205:c41fc65bcfb4 334 (+) HAL_USART_TxRxCpltCallback()
mbed_official 205:c41fc65bcfb4 335
mbed_official 205:c41fc65bcfb4 336 @endverbatim
mbed_official 205:c41fc65bcfb4 337 * @{
mbed_official 205:c41fc65bcfb4 338 */
mbed_official 205:c41fc65bcfb4 339
mbed_official 205:c41fc65bcfb4 340 /**
mbed_official 205:c41fc65bcfb4 341 * @brief Simplex Send an amount of data in blocking mode
mbed_official 205:c41fc65bcfb4 342 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 343 * @param pTxData: pointer to data buffer
mbed_official 205:c41fc65bcfb4 344 * @param Size: amount of data to be sent
mbed_official 205:c41fc65bcfb4 345 * @param Timeout : Timeout duration
mbed_official 205:c41fc65bcfb4 346 * @retval HAL status
mbed_official 205:c41fc65bcfb4 347 */
mbed_official 205:c41fc65bcfb4 348 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout)
mbed_official 205:c41fc65bcfb4 349 {
mbed_official 205:c41fc65bcfb4 350 uint16_t* tmp;
mbed_official 205:c41fc65bcfb4 351
mbed_official 205:c41fc65bcfb4 352 if(husart->State == HAL_USART_STATE_READY)
mbed_official 205:c41fc65bcfb4 353 {
mbed_official 205:c41fc65bcfb4 354 if((pTxData == NULL) || (Size == 0))
mbed_official 205:c41fc65bcfb4 355 {
mbed_official 205:c41fc65bcfb4 356 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 357 }
mbed_official 205:c41fc65bcfb4 358
mbed_official 205:c41fc65bcfb4 359 /* Process Locked */
mbed_official 205:c41fc65bcfb4 360 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 361
mbed_official 205:c41fc65bcfb4 362 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 363 husart->State = HAL_USART_STATE_BUSY_TX;
mbed_official 205:c41fc65bcfb4 364
mbed_official 205:c41fc65bcfb4 365 husart->TxXferSize = Size;
mbed_official 205:c41fc65bcfb4 366 husart->TxXferCount = Size;
mbed_official 205:c41fc65bcfb4 367
mbed_official 205:c41fc65bcfb4 368 /* Check the remaining data to be sent */
mbed_official 205:c41fc65bcfb4 369 while(husart->TxXferCount > 0)
mbed_official 205:c41fc65bcfb4 370 {
mbed_official 205:c41fc65bcfb4 371 husart->TxXferCount--;
mbed_official 205:c41fc65bcfb4 372 if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TXE, RESET, Timeout) != HAL_OK)
mbed_official 205:c41fc65bcfb4 373 {
mbed_official 205:c41fc65bcfb4 374 return HAL_TIMEOUT;
mbed_official 205:c41fc65bcfb4 375 }
mbed_official 205:c41fc65bcfb4 376 if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
mbed_official 205:c41fc65bcfb4 377 {
mbed_official 205:c41fc65bcfb4 378 tmp = (uint16_t*) pTxData;
mbed_official 205:c41fc65bcfb4 379 husart->Instance->TDR = (*tmp & (uint16_t)0x01FF);
mbed_official 205:c41fc65bcfb4 380 pTxData += 2;
mbed_official 205:c41fc65bcfb4 381 }
mbed_official 205:c41fc65bcfb4 382 else
mbed_official 205:c41fc65bcfb4 383 {
mbed_official 205:c41fc65bcfb4 384 husart->Instance->TDR = (*pTxData++ & (uint8_t)0xFF);
mbed_official 205:c41fc65bcfb4 385 }
mbed_official 205:c41fc65bcfb4 386 }
mbed_official 205:c41fc65bcfb4 387
mbed_official 205:c41fc65bcfb4 388 if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TC, RESET, Timeout) != HAL_OK)
mbed_official 205:c41fc65bcfb4 389 {
mbed_official 205:c41fc65bcfb4 390 return HAL_TIMEOUT;
mbed_official 205:c41fc65bcfb4 391 }
mbed_official 205:c41fc65bcfb4 392
mbed_official 205:c41fc65bcfb4 393 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 394
mbed_official 205:c41fc65bcfb4 395 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 396 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 397
mbed_official 205:c41fc65bcfb4 398 return HAL_OK;
mbed_official 205:c41fc65bcfb4 399 }
mbed_official 205:c41fc65bcfb4 400 else
mbed_official 205:c41fc65bcfb4 401 {
mbed_official 205:c41fc65bcfb4 402 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 403 }
mbed_official 205:c41fc65bcfb4 404 }
mbed_official 205:c41fc65bcfb4 405
mbed_official 205:c41fc65bcfb4 406 /**
mbed_official 205:c41fc65bcfb4 407 * @brief Receive an amount of data in blocking mode
mbed_official 205:c41fc65bcfb4 408 * To receive synchronous data, dummy data are simultaneously transmitted
mbed_official 205:c41fc65bcfb4 409 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 410 * @param pRxData: pointer to data buffer
mbed_official 205:c41fc65bcfb4 411 * @param Size: amount of data to be received
mbed_official 205:c41fc65bcfb4 412 * @param Timeout : Timeout duration
mbed_official 205:c41fc65bcfb4 413 * @retval HAL status
mbed_official 205:c41fc65bcfb4 414 */
mbed_official 205:c41fc65bcfb4 415 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
mbed_official 205:c41fc65bcfb4 416 {
mbed_official 205:c41fc65bcfb4 417 uint16_t* tmp;
mbed_official 205:c41fc65bcfb4 418 uint16_t uhMask;
mbed_official 205:c41fc65bcfb4 419
mbed_official 205:c41fc65bcfb4 420 if(husart->State == HAL_USART_STATE_READY)
mbed_official 205:c41fc65bcfb4 421 {
mbed_official 205:c41fc65bcfb4 422 if((pRxData == NULL) || (Size == 0))
mbed_official 205:c41fc65bcfb4 423 {
mbed_official 205:c41fc65bcfb4 424 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 425 }
mbed_official 205:c41fc65bcfb4 426 /* Process Locked */
mbed_official 205:c41fc65bcfb4 427 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 428
mbed_official 205:c41fc65bcfb4 429 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 430 husart->State = HAL_USART_STATE_BUSY_RX;
mbed_official 205:c41fc65bcfb4 431
mbed_official 205:c41fc65bcfb4 432 husart->RxXferSize = Size;
mbed_official 205:c41fc65bcfb4 433 husart->RxXferCount = Size;
mbed_official 205:c41fc65bcfb4 434
mbed_official 205:c41fc65bcfb4 435 /* Computation of UART mask to apply to RDR register */
mbed_official 205:c41fc65bcfb4 436 __HAL_USART_MASK_COMPUTATION(husart);
mbed_official 205:c41fc65bcfb4 437 uhMask = husart->Mask;
mbed_official 205:c41fc65bcfb4 438
mbed_official 205:c41fc65bcfb4 439 /* as long as data have to be received */
mbed_official 205:c41fc65bcfb4 440 while(husart->RxXferCount > 0)
mbed_official 205:c41fc65bcfb4 441 {
mbed_official 205:c41fc65bcfb4 442 husart->RxXferCount--;
mbed_official 205:c41fc65bcfb4 443
mbed_official 205:c41fc65bcfb4 444 /* Wait until TC flag is set to send dummy byte in order to generate the
mbed_official 205:c41fc65bcfb4 445 * clock for the slave to send data.
mbed_official 205:c41fc65bcfb4 446 * Whatever the frame length (7, 8 or 9-bit long), the same dummy value
mbed_official 205:c41fc65bcfb4 447 * can be written for all the cases. */
mbed_official 205:c41fc65bcfb4 448 if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TC, RESET, Timeout) != HAL_OK)
mbed_official 205:c41fc65bcfb4 449 {
mbed_official 205:c41fc65bcfb4 450 return HAL_TIMEOUT;
mbed_official 205:c41fc65bcfb4 451 }
mbed_official 205:c41fc65bcfb4 452 husart->Instance->TDR = (DUMMY_DATA & (uint16_t)0x0FF);
mbed_official 205:c41fc65bcfb4 453
mbed_official 205:c41fc65bcfb4 454 /* Wait for RXNE Flag */
mbed_official 205:c41fc65bcfb4 455 if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, Timeout) != HAL_OK)
mbed_official 205:c41fc65bcfb4 456 {
mbed_official 205:c41fc65bcfb4 457 return HAL_TIMEOUT;
mbed_official 205:c41fc65bcfb4 458 }
mbed_official 205:c41fc65bcfb4 459
mbed_official 205:c41fc65bcfb4 460 if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
mbed_official 205:c41fc65bcfb4 461 {
mbed_official 205:c41fc65bcfb4 462 tmp = (uint16_t*) pRxData ;
mbed_official 205:c41fc65bcfb4 463 *tmp = (uint16_t)(husart->Instance->RDR & uhMask);
mbed_official 205:c41fc65bcfb4 464 pRxData +=2;
mbed_official 205:c41fc65bcfb4 465 }
mbed_official 205:c41fc65bcfb4 466 else
mbed_official 205:c41fc65bcfb4 467 {
mbed_official 205:c41fc65bcfb4 468 *pRxData++ = (uint8_t)(husart->Instance->RDR & (uint8_t)uhMask);
mbed_official 205:c41fc65bcfb4 469 }
mbed_official 205:c41fc65bcfb4 470 }
mbed_official 205:c41fc65bcfb4 471
mbed_official 205:c41fc65bcfb4 472 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 473
mbed_official 205:c41fc65bcfb4 474 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 475 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 476
mbed_official 205:c41fc65bcfb4 477 return HAL_OK;
mbed_official 205:c41fc65bcfb4 478 }
mbed_official 205:c41fc65bcfb4 479 else
mbed_official 205:c41fc65bcfb4 480 {
mbed_official 205:c41fc65bcfb4 481 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 482 }
mbed_official 205:c41fc65bcfb4 483 }
mbed_official 205:c41fc65bcfb4 484
mbed_official 205:c41fc65bcfb4 485 /**
mbed_official 205:c41fc65bcfb4 486 * @brief Full-Duplex Send and Receive an amount of data in blocking mode
mbed_official 205:c41fc65bcfb4 487 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 488 * @param pTxData: pointer to TX data buffer
mbed_official 205:c41fc65bcfb4 489 * @param pRxData: pointer to RX data buffer
mbed_official 205:c41fc65bcfb4 490 * @param Size: amount of data to be sent (same amount to be received)
mbed_official 205:c41fc65bcfb4 491 * @param Timeout : Timeout duration
mbed_official 205:c41fc65bcfb4 492 * @retval HAL status
mbed_official 205:c41fc65bcfb4 493 */
mbed_official 205:c41fc65bcfb4 494 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
mbed_official 205:c41fc65bcfb4 495 {
mbed_official 205:c41fc65bcfb4 496 uint16_t* tmp;
mbed_official 205:c41fc65bcfb4 497 uint16_t uhMask;
mbed_official 205:c41fc65bcfb4 498
mbed_official 205:c41fc65bcfb4 499 if(husart->State == HAL_USART_STATE_READY)
mbed_official 205:c41fc65bcfb4 500 {
mbed_official 205:c41fc65bcfb4 501 if((pTxData == NULL) || (pRxData == NULL) || (Size == 0))
mbed_official 205:c41fc65bcfb4 502 {
mbed_official 205:c41fc65bcfb4 503 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 504 }
mbed_official 205:c41fc65bcfb4 505 /* Process Locked */
mbed_official 205:c41fc65bcfb4 506 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 507
mbed_official 205:c41fc65bcfb4 508 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 509 husart->State = HAL_USART_STATE_BUSY_RX;
mbed_official 205:c41fc65bcfb4 510
mbed_official 205:c41fc65bcfb4 511 husart->RxXferSize = Size;
mbed_official 205:c41fc65bcfb4 512 husart->TxXferSize = Size;
mbed_official 205:c41fc65bcfb4 513 husart->TxXferCount = Size;
mbed_official 205:c41fc65bcfb4 514 husart->RxXferCount = Size;
mbed_official 205:c41fc65bcfb4 515
mbed_official 205:c41fc65bcfb4 516 /* Computation of USART mask to apply to RDR register */
mbed_official 205:c41fc65bcfb4 517 __HAL_USART_MASK_COMPUTATION(husart);
mbed_official 205:c41fc65bcfb4 518 uhMask = husart->Mask;
mbed_official 205:c41fc65bcfb4 519
mbed_official 205:c41fc65bcfb4 520 /* Check the remain data to be sent */
mbed_official 205:c41fc65bcfb4 521 while(husart->TxXferCount > 0)
mbed_official 205:c41fc65bcfb4 522 {
mbed_official 205:c41fc65bcfb4 523 husart->TxXferCount--;
mbed_official 205:c41fc65bcfb4 524 husart->RxXferCount--;
mbed_official 205:c41fc65bcfb4 525
mbed_official 205:c41fc65bcfb4 526 /* Wait until TC flag is set to send data */
mbed_official 205:c41fc65bcfb4 527 if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TC, RESET, Timeout) != HAL_OK)
mbed_official 205:c41fc65bcfb4 528 {
mbed_official 205:c41fc65bcfb4 529 return HAL_TIMEOUT;
mbed_official 205:c41fc65bcfb4 530 }
mbed_official 205:c41fc65bcfb4 531 if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
mbed_official 205:c41fc65bcfb4 532 {
mbed_official 205:c41fc65bcfb4 533 tmp = (uint16_t*) pTxData;
mbed_official 205:c41fc65bcfb4 534 husart->Instance->TDR = (*tmp & uhMask);
mbed_official 205:c41fc65bcfb4 535 pTxData += 2;
mbed_official 205:c41fc65bcfb4 536 }
mbed_official 205:c41fc65bcfb4 537 else
mbed_official 205:c41fc65bcfb4 538 {
mbed_official 205:c41fc65bcfb4 539 husart->Instance->TDR = (*pTxData++ & (uint8_t)uhMask);
mbed_official 205:c41fc65bcfb4 540 }
mbed_official 205:c41fc65bcfb4 541
mbed_official 205:c41fc65bcfb4 542 /* Wait for RXNE Flag */
mbed_official 205:c41fc65bcfb4 543 if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_RXNE, RESET, Timeout) != HAL_OK)
mbed_official 205:c41fc65bcfb4 544 {
mbed_official 205:c41fc65bcfb4 545 return HAL_TIMEOUT;
mbed_official 205:c41fc65bcfb4 546 }
mbed_official 205:c41fc65bcfb4 547
mbed_official 205:c41fc65bcfb4 548 if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
mbed_official 205:c41fc65bcfb4 549 {
mbed_official 205:c41fc65bcfb4 550 tmp = (uint16_t*) pRxData ;
mbed_official 205:c41fc65bcfb4 551 *tmp = (uint16_t)(husart->Instance->RDR & uhMask);
mbed_official 205:c41fc65bcfb4 552 pRxData +=2;
mbed_official 205:c41fc65bcfb4 553 }
mbed_official 205:c41fc65bcfb4 554 else
mbed_official 205:c41fc65bcfb4 555 {
mbed_official 205:c41fc65bcfb4 556 *pRxData++ = (uint8_t)(husart->Instance->RDR & (uint8_t)uhMask);
mbed_official 205:c41fc65bcfb4 557 }
mbed_official 205:c41fc65bcfb4 558 }
mbed_official 205:c41fc65bcfb4 559
mbed_official 205:c41fc65bcfb4 560 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 561
mbed_official 205:c41fc65bcfb4 562 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 563 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 564
mbed_official 205:c41fc65bcfb4 565 return HAL_OK;
mbed_official 205:c41fc65bcfb4 566 }
mbed_official 205:c41fc65bcfb4 567 else
mbed_official 205:c41fc65bcfb4 568 {
mbed_official 205:c41fc65bcfb4 569 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 570 }
mbed_official 205:c41fc65bcfb4 571 }
mbed_official 205:c41fc65bcfb4 572
mbed_official 205:c41fc65bcfb4 573 /**
mbed_official 205:c41fc65bcfb4 574 * @brief Send an amount of data in interrupt mode
mbed_official 205:c41fc65bcfb4 575 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 576 * @param pTxData: pointer to data buffer
mbed_official 205:c41fc65bcfb4 577 * @param Size: amount of data to be sent
mbed_official 205:c41fc65bcfb4 578 * @retval HAL status
mbed_official 205:c41fc65bcfb4 579 */
mbed_official 205:c41fc65bcfb4 580 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size)
mbed_official 205:c41fc65bcfb4 581 {
mbed_official 205:c41fc65bcfb4 582 if(husart->State == HAL_USART_STATE_READY)
mbed_official 205:c41fc65bcfb4 583 {
mbed_official 205:c41fc65bcfb4 584 if((pTxData == NULL) || (Size == 0))
mbed_official 205:c41fc65bcfb4 585 {
mbed_official 205:c41fc65bcfb4 586 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 587 }
mbed_official 205:c41fc65bcfb4 588
mbed_official 205:c41fc65bcfb4 589 /* Process Locked */
mbed_official 205:c41fc65bcfb4 590 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 591
mbed_official 205:c41fc65bcfb4 592 husart->pTxBuffPtr = pTxData;
mbed_official 205:c41fc65bcfb4 593 husart->TxXferSize = Size;
mbed_official 205:c41fc65bcfb4 594 husart->TxXferCount = Size;
mbed_official 205:c41fc65bcfb4 595
mbed_official 205:c41fc65bcfb4 596 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 597 husart->State = HAL_USART_STATE_BUSY_TX;
mbed_official 205:c41fc65bcfb4 598
mbed_official 205:c41fc65bcfb4 599 /* The USART Error Interrupts: (Frame error, noise error, overrun error)
mbed_official 205:c41fc65bcfb4 600 are not managed by the USART Transmit Process to avoid the overrun interrupt
mbed_official 205:c41fc65bcfb4 601 when the usart mode is configured for transmit and receive "USART_MODE_TX_RX"
mbed_official 205:c41fc65bcfb4 602 to benefit for the frame error and noise interrupts the usart mode should be
mbed_official 205:c41fc65bcfb4 603 configured only for transmit "USART_MODE_TX" */
mbed_official 205:c41fc65bcfb4 604
mbed_official 205:c41fc65bcfb4 605 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 606 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 607
mbed_official 205:c41fc65bcfb4 608 /* Enable the USART Transmit Complete Interrupt */
mbed_official 205:c41fc65bcfb4 609 __HAL_USART_ENABLE_IT(husart, USART_IT_TC);
mbed_official 205:c41fc65bcfb4 610
mbed_official 205:c41fc65bcfb4 611 return HAL_OK;
mbed_official 205:c41fc65bcfb4 612 }
mbed_official 205:c41fc65bcfb4 613 else
mbed_official 205:c41fc65bcfb4 614 {
mbed_official 205:c41fc65bcfb4 615 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 616 }
mbed_official 205:c41fc65bcfb4 617 }
mbed_official 205:c41fc65bcfb4 618
mbed_official 205:c41fc65bcfb4 619 /**
mbed_official 205:c41fc65bcfb4 620 * @brief Receive an amount of data in blocking mode
mbed_official 205:c41fc65bcfb4 621 * To receive synchronous data, dummy data are simultaneously transmitted
mbed_official 205:c41fc65bcfb4 622 * @param husart: usart handle
mbed_official 205:c41fc65bcfb4 623 * @param pRxData: pointer to data buffer
mbed_official 205:c41fc65bcfb4 624 * @param Size: amount of data to be received
mbed_official 205:c41fc65bcfb4 625 * @retval HAL status
mbed_official 205:c41fc65bcfb4 626 */
mbed_official 205:c41fc65bcfb4 627 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size)
mbed_official 205:c41fc65bcfb4 628 {
mbed_official 205:c41fc65bcfb4 629 if(husart->State == HAL_USART_STATE_READY)
mbed_official 205:c41fc65bcfb4 630 {
mbed_official 205:c41fc65bcfb4 631 if((pRxData == NULL) || (Size == 0))
mbed_official 205:c41fc65bcfb4 632 {
mbed_official 205:c41fc65bcfb4 633 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 634 }
mbed_official 205:c41fc65bcfb4 635 /* Process Locked */
mbed_official 205:c41fc65bcfb4 636 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 637
mbed_official 205:c41fc65bcfb4 638 husart->pRxBuffPtr = pRxData;
mbed_official 205:c41fc65bcfb4 639 husart->RxXferSize = Size;
mbed_official 205:c41fc65bcfb4 640 husart->RxXferCount = Size;
mbed_official 205:c41fc65bcfb4 641
mbed_official 205:c41fc65bcfb4 642 __HAL_USART_MASK_COMPUTATION(husart);
mbed_official 205:c41fc65bcfb4 643
mbed_official 205:c41fc65bcfb4 644 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 645 husart->State = HAL_USART_STATE_BUSY_RX;
mbed_official 205:c41fc65bcfb4 646
mbed_official 205:c41fc65bcfb4 647 /* Enable the USART Parity Error Interrupt */
mbed_official 205:c41fc65bcfb4 648 __HAL_USART_ENABLE_IT(husart, USART_IT_PE);
mbed_official 205:c41fc65bcfb4 649
mbed_official 205:c41fc65bcfb4 650 /* Enable the USART Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 205:c41fc65bcfb4 651 __HAL_USART_ENABLE_IT(husart, USART_IT_ERR);
mbed_official 205:c41fc65bcfb4 652
mbed_official 205:c41fc65bcfb4 653 /* Enable the USART Data Register not empty Interrupt */
mbed_official 205:c41fc65bcfb4 654 __HAL_USART_ENABLE_IT(husart, USART_IT_RXNE);
mbed_official 205:c41fc65bcfb4 655
mbed_official 205:c41fc65bcfb4 656 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 657 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 658
mbed_official 205:c41fc65bcfb4 659
mbed_official 205:c41fc65bcfb4 660 /* Send dummy byte in order to generate the clock for the Slave to send the next data */
mbed_official 205:c41fc65bcfb4 661 if(husart->Init.WordLength == USART_WORDLENGTH_9B)
mbed_official 205:c41fc65bcfb4 662 {
mbed_official 205:c41fc65bcfb4 663 husart->Instance->TDR = (DUMMY_DATA & (uint16_t)0x01FF);
mbed_official 205:c41fc65bcfb4 664 }
mbed_official 205:c41fc65bcfb4 665 else
mbed_official 205:c41fc65bcfb4 666 {
mbed_official 205:c41fc65bcfb4 667 husart->Instance->TDR = (DUMMY_DATA & (uint16_t)0x00FF);
mbed_official 205:c41fc65bcfb4 668 }
mbed_official 205:c41fc65bcfb4 669
mbed_official 205:c41fc65bcfb4 670 return HAL_OK;
mbed_official 205:c41fc65bcfb4 671 }
mbed_official 205:c41fc65bcfb4 672 else
mbed_official 205:c41fc65bcfb4 673 {
mbed_official 205:c41fc65bcfb4 674 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 675 }
mbed_official 205:c41fc65bcfb4 676 }
mbed_official 205:c41fc65bcfb4 677
mbed_official 205:c41fc65bcfb4 678 /**
mbed_official 205:c41fc65bcfb4 679 * @brief Full-Duplex Send and Receive an amount of data in interrupt mode
mbed_official 205:c41fc65bcfb4 680 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 681 * @param pTxData: pointer to TX data buffer
mbed_official 205:c41fc65bcfb4 682 * @param pRxData: pointer to RX data buffer
mbed_official 205:c41fc65bcfb4 683 * @param Size: amount of data to be sent (same amount to be received)
mbed_official 205:c41fc65bcfb4 684 * @retval HAL status
mbed_official 205:c41fc65bcfb4 685 */
mbed_official 205:c41fc65bcfb4 686 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
mbed_official 205:c41fc65bcfb4 687 {
mbed_official 205:c41fc65bcfb4 688
mbed_official 205:c41fc65bcfb4 689 if(husart->State == HAL_USART_STATE_READY)
mbed_official 205:c41fc65bcfb4 690 {
mbed_official 205:c41fc65bcfb4 691 if((pTxData == NULL) || (pRxData == NULL) || (Size == 0))
mbed_official 205:c41fc65bcfb4 692 {
mbed_official 205:c41fc65bcfb4 693 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 694 }
mbed_official 205:c41fc65bcfb4 695 /* Process Locked */
mbed_official 205:c41fc65bcfb4 696 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 697
mbed_official 205:c41fc65bcfb4 698 husart->pRxBuffPtr = pRxData;
mbed_official 205:c41fc65bcfb4 699 husart->RxXferSize = Size;
mbed_official 205:c41fc65bcfb4 700 husart->RxXferCount = Size;
mbed_official 205:c41fc65bcfb4 701 husart->pTxBuffPtr = pTxData;
mbed_official 205:c41fc65bcfb4 702 husart->TxXferSize = Size;
mbed_official 205:c41fc65bcfb4 703 husart->TxXferCount = Size;
mbed_official 205:c41fc65bcfb4 704
mbed_official 205:c41fc65bcfb4 705 __HAL_USART_MASK_COMPUTATION(husart);
mbed_official 205:c41fc65bcfb4 706
mbed_official 205:c41fc65bcfb4 707 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 708 husart->State = HAL_USART_STATE_BUSY_TX_RX;
mbed_official 205:c41fc65bcfb4 709
mbed_official 205:c41fc65bcfb4 710 /* Enable the USART Data Register not empty Interrupt */
mbed_official 205:c41fc65bcfb4 711 __HAL_USART_ENABLE_IT(husart, USART_IT_RXNE);
mbed_official 205:c41fc65bcfb4 712
mbed_official 205:c41fc65bcfb4 713 /* Enable the USART Parity Error Interrupt */
mbed_official 205:c41fc65bcfb4 714 __HAL_USART_ENABLE_IT(husart, USART_IT_PE);
mbed_official 205:c41fc65bcfb4 715
mbed_official 205:c41fc65bcfb4 716 /* Enable the USART Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 205:c41fc65bcfb4 717 __HAL_USART_ENABLE_IT(husart, USART_IT_ERR);
mbed_official 205:c41fc65bcfb4 718
mbed_official 205:c41fc65bcfb4 719 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 720 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 721
mbed_official 205:c41fc65bcfb4 722 /* Enable the USART Transmit Complete Interrupt */
mbed_official 205:c41fc65bcfb4 723 __HAL_USART_ENABLE_IT(husart, USART_IT_TC);
mbed_official 205:c41fc65bcfb4 724
mbed_official 205:c41fc65bcfb4 725 return HAL_OK;
mbed_official 205:c41fc65bcfb4 726 }
mbed_official 205:c41fc65bcfb4 727 else
mbed_official 205:c41fc65bcfb4 728 {
mbed_official 205:c41fc65bcfb4 729 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 730 }
mbed_official 205:c41fc65bcfb4 731
mbed_official 205:c41fc65bcfb4 732 }
mbed_official 205:c41fc65bcfb4 733
mbed_official 205:c41fc65bcfb4 734 /**
mbed_official 205:c41fc65bcfb4 735 * @brief Send an amount of data in DMA mode
mbed_official 205:c41fc65bcfb4 736 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 737 * @param pTxData: pointer to data buffer
mbed_official 205:c41fc65bcfb4 738 * @param Size: amount of data to be sent
mbed_official 205:c41fc65bcfb4 739 * @retval HAL status
mbed_official 205:c41fc65bcfb4 740 */
mbed_official 205:c41fc65bcfb4 741 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size)
mbed_official 205:c41fc65bcfb4 742 {
mbed_official 205:c41fc65bcfb4 743 uint32_t *tmp;
mbed_official 205:c41fc65bcfb4 744
mbed_official 205:c41fc65bcfb4 745 if(husart->State == HAL_USART_STATE_READY)
mbed_official 205:c41fc65bcfb4 746 {
mbed_official 205:c41fc65bcfb4 747 if((pTxData == NULL) || (Size == 0))
mbed_official 205:c41fc65bcfb4 748 {
mbed_official 205:c41fc65bcfb4 749 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 750 }
mbed_official 205:c41fc65bcfb4 751 /* Process Locked */
mbed_official 205:c41fc65bcfb4 752 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 753
mbed_official 205:c41fc65bcfb4 754 husart->pTxBuffPtr = pTxData;
mbed_official 205:c41fc65bcfb4 755 husart->TxXferSize = Size;
mbed_official 205:c41fc65bcfb4 756 husart->TxXferCount = Size;
mbed_official 205:c41fc65bcfb4 757
mbed_official 205:c41fc65bcfb4 758 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 759 husart->State = HAL_USART_STATE_BUSY_TX;
mbed_official 205:c41fc65bcfb4 760
mbed_official 205:c41fc65bcfb4 761 /* Set the USART DMA transfert complete callback */
mbed_official 205:c41fc65bcfb4 762 husart->hdmatx->XferCpltCallback = USART_DMATransmitCplt;
mbed_official 205:c41fc65bcfb4 763
mbed_official 205:c41fc65bcfb4 764 /* Set the USART DMA Half transfer complete callback */
mbed_official 205:c41fc65bcfb4 765 husart->hdmatx->XferHalfCpltCallback = USART_DMATxHalfCplt;
mbed_official 205:c41fc65bcfb4 766
mbed_official 205:c41fc65bcfb4 767 /* Set the DMA error callback */
mbed_official 205:c41fc65bcfb4 768 husart->hdmatx->XferErrorCallback = USART_DMAError;
mbed_official 205:c41fc65bcfb4 769
mbed_official 205:c41fc65bcfb4 770 /* Enable the USART transmit DMA channel */
mbed_official 205:c41fc65bcfb4 771 tmp = (uint32_t*)&pTxData;
mbed_official 205:c41fc65bcfb4 772 HAL_DMA_Start_IT(husart->hdmatx, *(uint32_t*)tmp, (uint32_t)&husart->Instance->TDR, Size);
mbed_official 205:c41fc65bcfb4 773
mbed_official 205:c41fc65bcfb4 774 /* Enable the DMA transfer for transmit request by setting the DMAT bit
mbed_official 205:c41fc65bcfb4 775 in the USART CR3 register */
mbed_official 205:c41fc65bcfb4 776 husart->Instance->CR3 |= USART_CR3_DMAT;
mbed_official 205:c41fc65bcfb4 777
mbed_official 205:c41fc65bcfb4 778 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 779 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 780
mbed_official 205:c41fc65bcfb4 781 return HAL_OK;
mbed_official 205:c41fc65bcfb4 782 }
mbed_official 205:c41fc65bcfb4 783 else
mbed_official 205:c41fc65bcfb4 784 {
mbed_official 205:c41fc65bcfb4 785 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 786 }
mbed_official 205:c41fc65bcfb4 787 }
mbed_official 205:c41fc65bcfb4 788
mbed_official 205:c41fc65bcfb4 789 /**
mbed_official 205:c41fc65bcfb4 790 * @brief Receive an amount of data in DMA mode
mbed_official 205:c41fc65bcfb4 791 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 792 * @param pRxData: pointer to data buffer
mbed_official 205:c41fc65bcfb4 793 * @param Size: amount of data to be received
mbed_official 205:c41fc65bcfb4 794 * @note When the USART parity is enabled (PCE = 1), the received data contain
mbed_official 205:c41fc65bcfb4 795 * the parity bit (MSB position)
mbed_official 205:c41fc65bcfb4 796 * @retval HAL status
mbed_official 205:c41fc65bcfb4 797 * @note The USART DMA transmit stream must be configured in order to generate the clock for the slave.
mbed_official 205:c41fc65bcfb4 798 */
mbed_official 205:c41fc65bcfb4 799 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size)
mbed_official 205:c41fc65bcfb4 800 {
mbed_official 205:c41fc65bcfb4 801 uint32_t *tmp;
mbed_official 205:c41fc65bcfb4 802
mbed_official 205:c41fc65bcfb4 803 if(husart->State == HAL_USART_STATE_READY)
mbed_official 205:c41fc65bcfb4 804 {
mbed_official 205:c41fc65bcfb4 805 if((pRxData == NULL) || (Size == 0))
mbed_official 205:c41fc65bcfb4 806 {
mbed_official 205:c41fc65bcfb4 807 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 808 }
mbed_official 205:c41fc65bcfb4 809
mbed_official 205:c41fc65bcfb4 810 /* Process Locked */
mbed_official 205:c41fc65bcfb4 811 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 812
mbed_official 205:c41fc65bcfb4 813 husart->pRxBuffPtr = pRxData;
mbed_official 205:c41fc65bcfb4 814 husart->RxXferSize = Size;
mbed_official 205:c41fc65bcfb4 815 husart->pTxBuffPtr = pRxData;
mbed_official 205:c41fc65bcfb4 816 husart->TxXferSize = Size;
mbed_official 205:c41fc65bcfb4 817
mbed_official 205:c41fc65bcfb4 818 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 819 husart->State = HAL_USART_STATE_BUSY_RX;
mbed_official 205:c41fc65bcfb4 820
mbed_official 205:c41fc65bcfb4 821 /* Set the USART DMA Rx transfert complete callback */
mbed_official 205:c41fc65bcfb4 822 husart->hdmarx->XferCpltCallback = USART_DMAReceiveCplt;
mbed_official 205:c41fc65bcfb4 823
mbed_official 205:c41fc65bcfb4 824 /* Set the USART DMA Half transfer complete callback */
mbed_official 205:c41fc65bcfb4 825 husart->hdmarx->XferHalfCpltCallback = USART_DMARxHalfCplt;
mbed_official 205:c41fc65bcfb4 826
mbed_official 205:c41fc65bcfb4 827 /* Set the USART DMA Rx transfert error callback */
mbed_official 205:c41fc65bcfb4 828 husart->hdmarx->XferErrorCallback = USART_DMAError;
mbed_official 205:c41fc65bcfb4 829
mbed_official 205:c41fc65bcfb4 830 /* Enable the USART receive DMA channel */
mbed_official 205:c41fc65bcfb4 831 tmp = (uint32_t*)&pRxData;
mbed_official 205:c41fc65bcfb4 832 HAL_DMA_Start_IT(husart->hdmarx, (uint32_t)&husart->Instance->RDR, *(uint32_t*)tmp, Size);
mbed_official 205:c41fc65bcfb4 833
mbed_official 205:c41fc65bcfb4 834 /* Enable the USART transmit DMA channel: the transmit stream is used in order
mbed_official 205:c41fc65bcfb4 835 to generate in the non-blocking mode the clock to the slave device,
mbed_official 205:c41fc65bcfb4 836 this mode isn't a simplex receive mode but a full-duplex receive mode */
mbed_official 205:c41fc65bcfb4 837 tmp = (uint32_t*)&pRxData;
mbed_official 205:c41fc65bcfb4 838 HAL_DMA_Start_IT(husart->hdmatx, *(uint32_t*)tmp, (uint32_t)&husart->Instance->TDR, Size);
mbed_official 205:c41fc65bcfb4 839
mbed_official 205:c41fc65bcfb4 840 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
mbed_official 205:c41fc65bcfb4 841 in the USART CR3 register */
mbed_official 205:c41fc65bcfb4 842 husart->Instance->CR3 |= USART_CR3_DMAR;
mbed_official 205:c41fc65bcfb4 843
mbed_official 205:c41fc65bcfb4 844 /* Enable the DMA transfer for transmit request by setting the DMAT bit
mbed_official 205:c41fc65bcfb4 845 in the USART CR3 register */
mbed_official 205:c41fc65bcfb4 846 husart->Instance->CR3 |= USART_CR3_DMAT;
mbed_official 205:c41fc65bcfb4 847
mbed_official 205:c41fc65bcfb4 848 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 849 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 850
mbed_official 205:c41fc65bcfb4 851 return HAL_OK;
mbed_official 205:c41fc65bcfb4 852 }
mbed_official 205:c41fc65bcfb4 853 else
mbed_official 205:c41fc65bcfb4 854 {
mbed_official 205:c41fc65bcfb4 855 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 856 }
mbed_official 205:c41fc65bcfb4 857 }
mbed_official 205:c41fc65bcfb4 858
mbed_official 205:c41fc65bcfb4 859 /**
mbed_official 205:c41fc65bcfb4 860 * @brief Full-Duplex Transmit Receive an amount of data in non blocking mode
mbed_official 205:c41fc65bcfb4 861 * @param husart: usart handle
mbed_official 205:c41fc65bcfb4 862 * @param pTxData: pointer to TX data buffer
mbed_official 205:c41fc65bcfb4 863 * @param pRxData: pointer to RX data buffer
mbed_official 205:c41fc65bcfb4 864 * @param Size: amount of data to be received/sent
mbed_official 205:c41fc65bcfb4 865 * @retval HAL status
mbed_official 205:c41fc65bcfb4 866 */
mbed_official 205:c41fc65bcfb4 867 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
mbed_official 205:c41fc65bcfb4 868 {
mbed_official 205:c41fc65bcfb4 869 uint32_t *tmp;
mbed_official 205:c41fc65bcfb4 870
mbed_official 205:c41fc65bcfb4 871 if(husart->State == HAL_USART_STATE_READY)
mbed_official 205:c41fc65bcfb4 872 {
mbed_official 205:c41fc65bcfb4 873 if((pTxData == NULL) || (pRxData == NULL) || (Size == 0))
mbed_official 205:c41fc65bcfb4 874 {
mbed_official 205:c41fc65bcfb4 875 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 876 }
mbed_official 205:c41fc65bcfb4 877 /* Process Locked */
mbed_official 205:c41fc65bcfb4 878 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 879
mbed_official 205:c41fc65bcfb4 880 husart->pRxBuffPtr = pRxData;
mbed_official 205:c41fc65bcfb4 881 husart->RxXferSize = Size;
mbed_official 205:c41fc65bcfb4 882 husart->pTxBuffPtr = pTxData;
mbed_official 205:c41fc65bcfb4 883 husart->TxXferSize = Size;
mbed_official 205:c41fc65bcfb4 884
mbed_official 205:c41fc65bcfb4 885 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 886 husart->State = HAL_USART_STATE_BUSY_TX_RX;
mbed_official 205:c41fc65bcfb4 887
mbed_official 205:c41fc65bcfb4 888 /* Set the USART DMA Rx transfert complete callback */
mbed_official 205:c41fc65bcfb4 889 husart->hdmarx->XferCpltCallback = USART_DMAReceiveCplt;
mbed_official 205:c41fc65bcfb4 890
mbed_official 205:c41fc65bcfb4 891 /* Set the USART DMA Tx transfert complete callback */
mbed_official 205:c41fc65bcfb4 892 husart->hdmatx->XferCpltCallback = USART_DMATransmitCplt;
mbed_official 205:c41fc65bcfb4 893
mbed_official 205:c41fc65bcfb4 894 /* Set the USART DMA Tx transfert error callback */
mbed_official 205:c41fc65bcfb4 895 husart->hdmatx->XferErrorCallback = USART_DMAError;
mbed_official 205:c41fc65bcfb4 896
mbed_official 205:c41fc65bcfb4 897 /* Set the USART DMA Rx transfert error callback */
mbed_official 205:c41fc65bcfb4 898 husart->hdmarx->XferErrorCallback = USART_DMAError;
mbed_official 205:c41fc65bcfb4 899
mbed_official 205:c41fc65bcfb4 900 /* Enable the USART receive DMA channel */
mbed_official 205:c41fc65bcfb4 901 tmp = (uint32_t*)&pRxData;
mbed_official 205:c41fc65bcfb4 902 HAL_DMA_Start_IT(husart->hdmarx, (uint32_t)&husart->Instance->RDR, *(uint32_t*)tmp, Size);
mbed_official 205:c41fc65bcfb4 903
mbed_official 205:c41fc65bcfb4 904 /* Enable the USART transmit DMA channel */
mbed_official 205:c41fc65bcfb4 905 tmp = (uint32_t*)&pTxData;
mbed_official 205:c41fc65bcfb4 906 HAL_DMA_Start_IT(husart->hdmatx, *(uint32_t*)tmp, (uint32_t)&husart->Instance->TDR, Size);
mbed_official 205:c41fc65bcfb4 907
mbed_official 205:c41fc65bcfb4 908 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
mbed_official 205:c41fc65bcfb4 909 in the USART CR3 register */
mbed_official 205:c41fc65bcfb4 910 husart->Instance->CR3 |= USART_CR3_DMAR;
mbed_official 205:c41fc65bcfb4 911
mbed_official 205:c41fc65bcfb4 912 /* Enable the DMA transfer for transmit request by setting the DMAT bit
mbed_official 205:c41fc65bcfb4 913 in the USART CR3 register */
mbed_official 205:c41fc65bcfb4 914 husart->Instance->CR3 |= USART_CR3_DMAT;
mbed_official 205:c41fc65bcfb4 915
mbed_official 205:c41fc65bcfb4 916 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 917 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 918
mbed_official 205:c41fc65bcfb4 919 return HAL_OK;
mbed_official 205:c41fc65bcfb4 920 }
mbed_official 205:c41fc65bcfb4 921 else
mbed_official 205:c41fc65bcfb4 922 {
mbed_official 205:c41fc65bcfb4 923 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 924 }
mbed_official 205:c41fc65bcfb4 925 }
mbed_official 205:c41fc65bcfb4 926
mbed_official 205:c41fc65bcfb4 927 /**
mbed_official 205:c41fc65bcfb4 928 * @brief Pauses the DMA Transfer.
mbed_official 205:c41fc65bcfb4 929 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 930 * @retval None
mbed_official 205:c41fc65bcfb4 931 */
mbed_official 205:c41fc65bcfb4 932 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 933 {
mbed_official 205:c41fc65bcfb4 934 /* Process Locked */
mbed_official 205:c41fc65bcfb4 935 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 936
mbed_official 205:c41fc65bcfb4 937 if(husart->State == HAL_USART_STATE_BUSY_TX)
mbed_official 205:c41fc65bcfb4 938 {
mbed_official 205:c41fc65bcfb4 939 /* Disable the USART DMA Tx request */
mbed_official 205:c41fc65bcfb4 940 husart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
mbed_official 205:c41fc65bcfb4 941 }
mbed_official 205:c41fc65bcfb4 942 else if(husart->State == HAL_USART_STATE_BUSY_RX)
mbed_official 205:c41fc65bcfb4 943 {
mbed_official 205:c41fc65bcfb4 944 /* Disable the USART DMA Rx request */
mbed_official 205:c41fc65bcfb4 945 husart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
mbed_official 205:c41fc65bcfb4 946 }
mbed_official 205:c41fc65bcfb4 947 else if(husart->State == HAL_USART_STATE_BUSY_TX_RX)
mbed_official 205:c41fc65bcfb4 948 {
mbed_official 205:c41fc65bcfb4 949 /* Disable the USART DMA Tx request */
mbed_official 205:c41fc65bcfb4 950 husart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
mbed_official 205:c41fc65bcfb4 951 /* Disable the USART DMA Rx request */
mbed_official 205:c41fc65bcfb4 952 husart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
mbed_official 205:c41fc65bcfb4 953 }
mbed_official 205:c41fc65bcfb4 954
mbed_official 205:c41fc65bcfb4 955 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 956 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 957
mbed_official 205:c41fc65bcfb4 958 return HAL_OK;
mbed_official 205:c41fc65bcfb4 959 }
mbed_official 205:c41fc65bcfb4 960
mbed_official 205:c41fc65bcfb4 961 /**
mbed_official 205:c41fc65bcfb4 962 * @brief Resumes the DMA Transfer.
mbed_official 205:c41fc65bcfb4 963 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 964 * @retval None
mbed_official 205:c41fc65bcfb4 965 */
mbed_official 205:c41fc65bcfb4 966 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 967 {
mbed_official 205:c41fc65bcfb4 968 /* Process Locked */
mbed_official 205:c41fc65bcfb4 969 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 970
mbed_official 205:c41fc65bcfb4 971 if(husart->State == HAL_USART_STATE_BUSY_TX)
mbed_official 205:c41fc65bcfb4 972 {
mbed_official 205:c41fc65bcfb4 973 /* Enable the USART DMA Tx request */
mbed_official 205:c41fc65bcfb4 974 husart->Instance->CR3 |= USART_CR3_DMAT;
mbed_official 205:c41fc65bcfb4 975 }
mbed_official 205:c41fc65bcfb4 976 else if(husart->State == HAL_USART_STATE_BUSY_RX)
mbed_official 205:c41fc65bcfb4 977 {
mbed_official 205:c41fc65bcfb4 978 /* Enable the USART DMA Rx request */
mbed_official 205:c41fc65bcfb4 979 husart->Instance->CR3 |= USART_CR3_DMAR;
mbed_official 205:c41fc65bcfb4 980 }
mbed_official 205:c41fc65bcfb4 981 else if(husart->State == HAL_USART_STATE_BUSY_TX_RX)
mbed_official 205:c41fc65bcfb4 982 {
mbed_official 205:c41fc65bcfb4 983 /* Enable the USART DMA Rx request before the DMA Tx request */
mbed_official 205:c41fc65bcfb4 984 husart->Instance->CR3 |= USART_CR3_DMAR;
mbed_official 205:c41fc65bcfb4 985 /* Enable the USART DMA Tx request */
mbed_official 205:c41fc65bcfb4 986 husart->Instance->CR3 |= USART_CR3_DMAT;
mbed_official 205:c41fc65bcfb4 987 }
mbed_official 205:c41fc65bcfb4 988
mbed_official 205:c41fc65bcfb4 989 /* If the USART peripheral is still not enabled, enable it */
mbed_official 205:c41fc65bcfb4 990 if ((husart->Instance->CR1 & USART_CR1_UE) == 0)
mbed_official 205:c41fc65bcfb4 991 {
mbed_official 205:c41fc65bcfb4 992 /* Enable USART peripheral */
mbed_official 205:c41fc65bcfb4 993 __USART_ENABLE(husart);
mbed_official 205:c41fc65bcfb4 994 }
mbed_official 205:c41fc65bcfb4 995
mbed_official 205:c41fc65bcfb4 996 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 997 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 998
mbed_official 205:c41fc65bcfb4 999 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1000 }
mbed_official 205:c41fc65bcfb4 1001
mbed_official 205:c41fc65bcfb4 1002 /**
mbed_official 205:c41fc65bcfb4 1003 * @brief Stops the DMA Transfer.
mbed_official 205:c41fc65bcfb4 1004 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1005 * @retval None
mbed_official 205:c41fc65bcfb4 1006 */
mbed_official 205:c41fc65bcfb4 1007 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1008 {
mbed_official 205:c41fc65bcfb4 1009 /* Process Locked */
mbed_official 205:c41fc65bcfb4 1010 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 1011
mbed_official 205:c41fc65bcfb4 1012 /* Disable the USART Tx/Rx DMA requests */
mbed_official 205:c41fc65bcfb4 1013 husart->Instance->CR3 &= ~USART_CR3_DMAT;
mbed_official 205:c41fc65bcfb4 1014 husart->Instance->CR3 &= ~USART_CR3_DMAR;
mbed_official 205:c41fc65bcfb4 1015
mbed_official 205:c41fc65bcfb4 1016 /* Abort the USART DMA tx Stream */
mbed_official 205:c41fc65bcfb4 1017 if(husart->hdmatx != NULL)
mbed_official 205:c41fc65bcfb4 1018 {
mbed_official 205:c41fc65bcfb4 1019 HAL_DMA_Abort(husart->hdmatx);
mbed_official 205:c41fc65bcfb4 1020 }
mbed_official 205:c41fc65bcfb4 1021 /* Abort the USART DMA rx Stream */
mbed_official 205:c41fc65bcfb4 1022 if(husart->hdmarx != NULL)
mbed_official 205:c41fc65bcfb4 1023 {
mbed_official 205:c41fc65bcfb4 1024 HAL_DMA_Abort(husart->hdmarx);
mbed_official 205:c41fc65bcfb4 1025 }
mbed_official 205:c41fc65bcfb4 1026
mbed_official 205:c41fc65bcfb4 1027 /* Disable USART peripheral */
mbed_official 205:c41fc65bcfb4 1028 __USART_DISABLE(husart);
mbed_official 205:c41fc65bcfb4 1029
mbed_official 205:c41fc65bcfb4 1030 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1031
mbed_official 205:c41fc65bcfb4 1032 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 1033 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 1034
mbed_official 205:c41fc65bcfb4 1035 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1036 }
mbed_official 205:c41fc65bcfb4 1037
mbed_official 205:c41fc65bcfb4 1038 /**
mbed_official 205:c41fc65bcfb4 1039 * @brief This function handles USART interrupt request.
mbed_official 205:c41fc65bcfb4 1040 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1041 * @retval None
mbed_official 205:c41fc65bcfb4 1042 */
mbed_official 205:c41fc65bcfb4 1043 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1044 {
mbed_official 205:c41fc65bcfb4 1045
mbed_official 205:c41fc65bcfb4 1046 /* USART parity error interrupt occured ------------------------------------*/
mbed_official 205:c41fc65bcfb4 1047 if((__HAL_USART_GET_IT(husart, USART_IT_PE) != RESET) && (__HAL_USART_GET_IT_SOURCE(husart, USART_IT_PE) != RESET))
mbed_official 205:c41fc65bcfb4 1048 {
mbed_official 205:c41fc65bcfb4 1049 __HAL_USART_CLEAR_IT(husart, USART_IT_PE);
mbed_official 205:c41fc65bcfb4 1050 husart->ErrorCode |= HAL_USART_ERROR_PE;
mbed_official 205:c41fc65bcfb4 1051 /* Set the USART state ready to be able to start again the process */
mbed_official 205:c41fc65bcfb4 1052 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1053 }
mbed_official 205:c41fc65bcfb4 1054
mbed_official 205:c41fc65bcfb4 1055 /* USART frame error interrupt occured -------------------------------------*/
mbed_official 205:c41fc65bcfb4 1056 if((__HAL_USART_GET_IT(husart, USART_IT_FE) != RESET) && (__HAL_USART_GET_IT_SOURCE(husart, USART_IT_ERR) != RESET))
mbed_official 205:c41fc65bcfb4 1057 {
mbed_official 205:c41fc65bcfb4 1058 __HAL_USART_CLEAR_IT(husart, USART_IT_FE);
mbed_official 205:c41fc65bcfb4 1059 husart->ErrorCode |= HAL_USART_ERROR_FE;
mbed_official 205:c41fc65bcfb4 1060 /* Set the USART state ready to be able to start again the process */
mbed_official 205:c41fc65bcfb4 1061 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1062 }
mbed_official 205:c41fc65bcfb4 1063
mbed_official 205:c41fc65bcfb4 1064 /* USART noise error interrupt occured -------------------------------------*/
mbed_official 205:c41fc65bcfb4 1065 if((__HAL_USART_GET_IT(husart, USART_IT_NE) != RESET) && (__HAL_USART_GET_IT_SOURCE(husart, USART_IT_ERR) != RESET))
mbed_official 205:c41fc65bcfb4 1066 {
mbed_official 205:c41fc65bcfb4 1067 __HAL_USART_CLEAR_IT(husart, USART_IT_NE);
mbed_official 205:c41fc65bcfb4 1068 husart->ErrorCode |= HAL_USART_ERROR_NE;
mbed_official 205:c41fc65bcfb4 1069 /* Set the USART state ready to be able to start again the process */
mbed_official 205:c41fc65bcfb4 1070 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1071 }
mbed_official 205:c41fc65bcfb4 1072
mbed_official 205:c41fc65bcfb4 1073 /* USART Over-Run interrupt occured ----------------------------------------*/
mbed_official 205:c41fc65bcfb4 1074 if((__HAL_USART_GET_IT(husart, USART_IT_ORE) != RESET) && (__HAL_USART_GET_IT_SOURCE(husart, USART_IT_ERR) != RESET))
mbed_official 205:c41fc65bcfb4 1075 {
mbed_official 205:c41fc65bcfb4 1076 __HAL_USART_CLEAR_IT(husart, USART_IT_ORE);
mbed_official 205:c41fc65bcfb4 1077 husart->ErrorCode |= HAL_USART_ERROR_ORE;
mbed_official 205:c41fc65bcfb4 1078 /* Set the USART state ready to be able to start again the process */
mbed_official 205:c41fc65bcfb4 1079 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1080 }
mbed_official 205:c41fc65bcfb4 1081
mbed_official 205:c41fc65bcfb4 1082 /* Call USART Error Call back function if need be --------------------------*/
mbed_official 205:c41fc65bcfb4 1083 if(husart->ErrorCode != HAL_USART_ERROR_NONE)
mbed_official 205:c41fc65bcfb4 1084 {
mbed_official 205:c41fc65bcfb4 1085 HAL_USART_ErrorCallback(husart);
mbed_official 205:c41fc65bcfb4 1086 }
mbed_official 205:c41fc65bcfb4 1087
mbed_official 205:c41fc65bcfb4 1088 /* USART in mode Receiver --------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 1089 if((__HAL_USART_GET_IT(husart, USART_IT_RXNE) != RESET) && (__HAL_USART_GET_IT_SOURCE(husart, USART_IT_RXNE) != RESET))
mbed_official 205:c41fc65bcfb4 1090 {
mbed_official 205:c41fc65bcfb4 1091 if(husart->State == HAL_USART_STATE_BUSY_RX)
mbed_official 205:c41fc65bcfb4 1092 {
mbed_official 205:c41fc65bcfb4 1093 USART_Receive_IT(husart);
mbed_official 205:c41fc65bcfb4 1094 }
mbed_official 205:c41fc65bcfb4 1095 else
mbed_official 205:c41fc65bcfb4 1096 {
mbed_official 205:c41fc65bcfb4 1097 USART_TransmitReceive_IT(husart);
mbed_official 205:c41fc65bcfb4 1098 }
mbed_official 205:c41fc65bcfb4 1099 }
mbed_official 205:c41fc65bcfb4 1100
mbed_official 205:c41fc65bcfb4 1101 /* USART in mode Transmitter -----------------------------------------------*/
mbed_official 205:c41fc65bcfb4 1102 if((__HAL_USART_GET_IT(husart, USART_IT_TC) != RESET) &&(__HAL_USART_GET_IT_SOURCE(husart, USART_IT_TC) != RESET))
mbed_official 205:c41fc65bcfb4 1103 {
mbed_official 205:c41fc65bcfb4 1104 if(husart->State == HAL_USART_STATE_BUSY_TX)
mbed_official 205:c41fc65bcfb4 1105 {
mbed_official 205:c41fc65bcfb4 1106 USART_Transmit_IT(husart);
mbed_official 205:c41fc65bcfb4 1107 }
mbed_official 205:c41fc65bcfb4 1108 else
mbed_official 205:c41fc65bcfb4 1109 {
mbed_official 205:c41fc65bcfb4 1110 USART_TransmitReceive_IT(husart);
mbed_official 205:c41fc65bcfb4 1111 }
mbed_official 205:c41fc65bcfb4 1112 }
mbed_official 205:c41fc65bcfb4 1113
mbed_official 205:c41fc65bcfb4 1114 }
mbed_official 205:c41fc65bcfb4 1115
mbed_official 205:c41fc65bcfb4 1116
mbed_official 205:c41fc65bcfb4 1117 /**
mbed_official 205:c41fc65bcfb4 1118 * @brief This function handles USART Communication Timeout.
mbed_official 205:c41fc65bcfb4 1119 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1120 * @param Flag: specifies the USART flag to check.
mbed_official 205:c41fc65bcfb4 1121 * @param Status: The new Flag status (SET or RESET).
mbed_official 205:c41fc65bcfb4 1122 * @param Timeout: Timeout duration
mbed_official 205:c41fc65bcfb4 1123 * @retval HAL status
mbed_official 205:c41fc65bcfb4 1124 */
mbed_official 205:c41fc65bcfb4 1125 static HAL_StatusTypeDef USART_WaitOnFlagUntilTimeout(USART_HandleTypeDef *husart, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
mbed_official 205:c41fc65bcfb4 1126 {
mbed_official 205:c41fc65bcfb4 1127 uint32_t tickstart = HAL_GetTick();
mbed_official 205:c41fc65bcfb4 1128
mbed_official 205:c41fc65bcfb4 1129 /* Wait until flag is set */
mbed_official 205:c41fc65bcfb4 1130 if(Status == RESET)
mbed_official 205:c41fc65bcfb4 1131 {
mbed_official 205:c41fc65bcfb4 1132 while(__HAL_USART_GET_FLAG(husart, Flag) == RESET)
mbed_official 205:c41fc65bcfb4 1133 {
mbed_official 205:c41fc65bcfb4 1134 /* Check for the Timeout */
mbed_official 205:c41fc65bcfb4 1135 if(Timeout != HAL_MAX_DELAY)
mbed_official 205:c41fc65bcfb4 1136 {
mbed_official 205:c41fc65bcfb4 1137 if((HAL_GetTick() - tickstart) >= Timeout)
mbed_official 205:c41fc65bcfb4 1138 {
mbed_official 205:c41fc65bcfb4 1139 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
mbed_official 205:c41fc65bcfb4 1140 __HAL_USART_DISABLE_IT(husart, USART_IT_TXE);
mbed_official 205:c41fc65bcfb4 1141 __HAL_USART_DISABLE_IT(husart, USART_IT_RXNE);
mbed_official 205:c41fc65bcfb4 1142 __HAL_USART_DISABLE_IT(husart, USART_IT_PE);
mbed_official 205:c41fc65bcfb4 1143 __HAL_USART_DISABLE_IT(husart, USART_IT_ERR);
mbed_official 205:c41fc65bcfb4 1144
mbed_official 205:c41fc65bcfb4 1145 husart->State= HAL_USART_STATE_TIMEOUT;
mbed_official 205:c41fc65bcfb4 1146
mbed_official 205:c41fc65bcfb4 1147 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 1148 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 1149
mbed_official 205:c41fc65bcfb4 1150 return HAL_TIMEOUT;
mbed_official 205:c41fc65bcfb4 1151 }
mbed_official 205:c41fc65bcfb4 1152 }
mbed_official 205:c41fc65bcfb4 1153 }
mbed_official 205:c41fc65bcfb4 1154 }
mbed_official 205:c41fc65bcfb4 1155 else
mbed_official 205:c41fc65bcfb4 1156 {
mbed_official 205:c41fc65bcfb4 1157 while(__HAL_USART_GET_FLAG(husart, Flag) != RESET)
mbed_official 205:c41fc65bcfb4 1158 {
mbed_official 205:c41fc65bcfb4 1159 /* Check for the Timeout */
mbed_official 205:c41fc65bcfb4 1160 if(Timeout != HAL_MAX_DELAY)
mbed_official 205:c41fc65bcfb4 1161 {
mbed_official 205:c41fc65bcfb4 1162 if((HAL_GetTick() - tickstart) >= Timeout)
mbed_official 205:c41fc65bcfb4 1163 {
mbed_official 205:c41fc65bcfb4 1164 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
mbed_official 205:c41fc65bcfb4 1165 __HAL_USART_DISABLE_IT(husart, USART_IT_TXE);
mbed_official 205:c41fc65bcfb4 1166 __HAL_USART_DISABLE_IT(husart, USART_IT_RXNE);
mbed_official 205:c41fc65bcfb4 1167 __HAL_USART_DISABLE_IT(husart, USART_IT_PE);
mbed_official 205:c41fc65bcfb4 1168 __HAL_USART_DISABLE_IT(husart, USART_IT_ERR);
mbed_official 205:c41fc65bcfb4 1169
mbed_official 205:c41fc65bcfb4 1170 husart->State= HAL_USART_STATE_TIMEOUT;
mbed_official 205:c41fc65bcfb4 1171
mbed_official 205:c41fc65bcfb4 1172 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 1173 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 1174
mbed_official 205:c41fc65bcfb4 1175 return HAL_TIMEOUT;
mbed_official 205:c41fc65bcfb4 1176 }
mbed_official 205:c41fc65bcfb4 1177 }
mbed_official 205:c41fc65bcfb4 1178 }
mbed_official 205:c41fc65bcfb4 1179 }
mbed_official 205:c41fc65bcfb4 1180 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1181 }
mbed_official 205:c41fc65bcfb4 1182
mbed_official 205:c41fc65bcfb4 1183
mbed_official 205:c41fc65bcfb4 1184 /**
mbed_official 205:c41fc65bcfb4 1185 * @brief DMA USART transmit process complete callback
mbed_official 205:c41fc65bcfb4 1186 * @param hdma : DMA handle
mbed_official 205:c41fc65bcfb4 1187 * @retval None
mbed_official 205:c41fc65bcfb4 1188 */
mbed_official 205:c41fc65bcfb4 1189 static void USART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
mbed_official 205:c41fc65bcfb4 1190 {
mbed_official 205:c41fc65bcfb4 1191 USART_HandleTypeDef* husart = ( USART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 205:c41fc65bcfb4 1192
mbed_official 205:c41fc65bcfb4 1193 husart->TxXferCount = 0;
mbed_official 205:c41fc65bcfb4 1194
mbed_official 205:c41fc65bcfb4 1195 if(husart->State == HAL_USART_STATE_BUSY_TX)
mbed_official 205:c41fc65bcfb4 1196 {
mbed_official 205:c41fc65bcfb4 1197 /* Wait for USART TC Flag */
mbed_official 205:c41fc65bcfb4 1198 if(USART_WaitOnFlagUntilTimeout(husart, USART_FLAG_TC, RESET, HAL_USART_TXDMA_TIMEOUTVALUE) != HAL_OK)
mbed_official 205:c41fc65bcfb4 1199 {
mbed_official 205:c41fc65bcfb4 1200 /* Timeout Occured */
mbed_official 205:c41fc65bcfb4 1201 husart->State = HAL_USART_STATE_TIMEOUT;
mbed_official 205:c41fc65bcfb4 1202 HAL_USART_ErrorCallback(husart);
mbed_official 205:c41fc65bcfb4 1203 }
mbed_official 205:c41fc65bcfb4 1204 else
mbed_official 205:c41fc65bcfb4 1205 {
mbed_official 205:c41fc65bcfb4 1206 /* No Timeout */
mbed_official 205:c41fc65bcfb4 1207 /* Disable the DMA transfer for transmit request by setting the DMAT bit
mbed_official 205:c41fc65bcfb4 1208 in the USART CR3 register */
mbed_official 205:c41fc65bcfb4 1209 husart->Instance->CR3 &= ~(USART_CR3_DMAT);
mbed_official 205:c41fc65bcfb4 1210 husart->State= HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1211 }
mbed_official 205:c41fc65bcfb4 1212 }
mbed_official 205:c41fc65bcfb4 1213 /* the usart state is HAL_USART_STATE_BUSY_TX_RX*/
mbed_official 205:c41fc65bcfb4 1214 else
mbed_official 205:c41fc65bcfb4 1215 {
mbed_official 205:c41fc65bcfb4 1216 husart->State= HAL_USART_STATE_BUSY_RX;
mbed_official 205:c41fc65bcfb4 1217 HAL_USART_TxCpltCallback(husart);
mbed_official 205:c41fc65bcfb4 1218 }
mbed_official 205:c41fc65bcfb4 1219 }
mbed_official 205:c41fc65bcfb4 1220
mbed_official 205:c41fc65bcfb4 1221
mbed_official 205:c41fc65bcfb4 1222 /**
mbed_official 205:c41fc65bcfb4 1223 * @brief DMA USART transmit process half complete callback
mbed_official 205:c41fc65bcfb4 1224 * @param hdma : DMA handle
mbed_official 205:c41fc65bcfb4 1225 * @retval None
mbed_official 205:c41fc65bcfb4 1226 */
mbed_official 205:c41fc65bcfb4 1227 static void USART_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
mbed_official 205:c41fc65bcfb4 1228 {
mbed_official 205:c41fc65bcfb4 1229 USART_HandleTypeDef* husart = (USART_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
mbed_official 205:c41fc65bcfb4 1230
mbed_official 205:c41fc65bcfb4 1231 HAL_USART_TxHalfCpltCallback(husart);
mbed_official 205:c41fc65bcfb4 1232 }
mbed_official 205:c41fc65bcfb4 1233
mbed_official 205:c41fc65bcfb4 1234 /**
mbed_official 205:c41fc65bcfb4 1235 * @brief DMA USART receive process complete callback
mbed_official 205:c41fc65bcfb4 1236 * @param hdma : DMA handle
mbed_official 205:c41fc65bcfb4 1237 * @retval None
mbed_official 205:c41fc65bcfb4 1238 */
mbed_official 205:c41fc65bcfb4 1239 static void USART_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
mbed_official 205:c41fc65bcfb4 1240 {
mbed_official 205:c41fc65bcfb4 1241 USART_HandleTypeDef* husart = ( USART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 205:c41fc65bcfb4 1242
mbed_official 205:c41fc65bcfb4 1243 husart->RxXferCount = 0;
mbed_official 205:c41fc65bcfb4 1244
mbed_official 205:c41fc65bcfb4 1245 /* Disable the DMA RX transfer for the receiver request by resetting the DMAR bit
mbed_official 205:c41fc65bcfb4 1246 in USART CR3 register */
mbed_official 205:c41fc65bcfb4 1247 husart->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAR);
mbed_official 205:c41fc65bcfb4 1248 /* similarly, disable the DMA TX transfer that was started to provide the
mbed_official 205:c41fc65bcfb4 1249 clock to the slave device */
mbed_official 205:c41fc65bcfb4 1250 husart->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_DMAT);
mbed_official 205:c41fc65bcfb4 1251
mbed_official 205:c41fc65bcfb4 1252 husart->State= HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1253
mbed_official 205:c41fc65bcfb4 1254 HAL_USART_RxCpltCallback(husart);
mbed_official 205:c41fc65bcfb4 1255 }
mbed_official 205:c41fc65bcfb4 1256
mbed_official 205:c41fc65bcfb4 1257 /**
mbed_official 205:c41fc65bcfb4 1258 * @brief DMA USART receive process half complete callback
mbed_official 205:c41fc65bcfb4 1259 * @param hdma : DMA handle
mbed_official 205:c41fc65bcfb4 1260 * @retval None
mbed_official 205:c41fc65bcfb4 1261 */
mbed_official 205:c41fc65bcfb4 1262 static void USART_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
mbed_official 205:c41fc65bcfb4 1263 {
mbed_official 205:c41fc65bcfb4 1264 USART_HandleTypeDef* husart = (USART_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
mbed_official 205:c41fc65bcfb4 1265
mbed_official 205:c41fc65bcfb4 1266 HAL_USART_RxHalfCpltCallback(husart);
mbed_official 205:c41fc65bcfb4 1267 }
mbed_official 205:c41fc65bcfb4 1268
mbed_official 205:c41fc65bcfb4 1269 /**
mbed_official 205:c41fc65bcfb4 1270 * @brief DMA USART communication error callback
mbed_official 205:c41fc65bcfb4 1271 * @param hdma : DMA handle
mbed_official 205:c41fc65bcfb4 1272 * @retval None
mbed_official 205:c41fc65bcfb4 1273 */
mbed_official 205:c41fc65bcfb4 1274 static void USART_DMAError(DMA_HandleTypeDef *hdma)
mbed_official 205:c41fc65bcfb4 1275 {
mbed_official 205:c41fc65bcfb4 1276 USART_HandleTypeDef* husart = ( USART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 205:c41fc65bcfb4 1277
mbed_official 205:c41fc65bcfb4 1278 husart->RxXferCount = 0;
mbed_official 205:c41fc65bcfb4 1279 husart->TxXferCount = 0;
mbed_official 205:c41fc65bcfb4 1280 husart->ErrorCode |= HAL_USART_ERROR_DMA;
mbed_official 205:c41fc65bcfb4 1281 husart->State= HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1282
mbed_official 205:c41fc65bcfb4 1283 HAL_USART_ErrorCallback(husart);
mbed_official 205:c41fc65bcfb4 1284 }
mbed_official 205:c41fc65bcfb4 1285
mbed_official 205:c41fc65bcfb4 1286 /**
mbed_official 205:c41fc65bcfb4 1287 * @brief Tx Transfer completed callbacks
mbed_official 205:c41fc65bcfb4 1288 * @param husart: usart handle
mbed_official 205:c41fc65bcfb4 1289 * @retval None
mbed_official 205:c41fc65bcfb4 1290 */
mbed_official 205:c41fc65bcfb4 1291 __weak void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1292 {
mbed_official 205:c41fc65bcfb4 1293 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 1294 the HAL_USART_TxCpltCallback can be implemented in the user file
mbed_official 205:c41fc65bcfb4 1295 */
mbed_official 205:c41fc65bcfb4 1296 }
mbed_official 205:c41fc65bcfb4 1297
mbed_official 205:c41fc65bcfb4 1298 /**
mbed_official 205:c41fc65bcfb4 1299 * @brief Tx Half Transfer completed callbacks.
mbed_official 205:c41fc65bcfb4 1300 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1301 * @retval None
mbed_official 205:c41fc65bcfb4 1302 */
mbed_official 205:c41fc65bcfb4 1303 __weak void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1304 {
mbed_official 205:c41fc65bcfb4 1305 /* NOTE: This function should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 1306 the HAL_USART_TxHalfCpltCallback can be implemented in the user file
mbed_official 205:c41fc65bcfb4 1307 */
mbed_official 205:c41fc65bcfb4 1308 }
mbed_official 205:c41fc65bcfb4 1309
mbed_official 205:c41fc65bcfb4 1310 /**
mbed_official 205:c41fc65bcfb4 1311 * @brief Rx Transfer completed callbacks.
mbed_official 205:c41fc65bcfb4 1312 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1313 * @retval None
mbed_official 205:c41fc65bcfb4 1314 */
mbed_official 205:c41fc65bcfb4 1315 __weak void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1316 {
mbed_official 205:c41fc65bcfb4 1317 /* NOTE: This function should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 1318 the HAL_USART_RxCpltCallback can be implemented in the user file
mbed_official 205:c41fc65bcfb4 1319 */
mbed_official 205:c41fc65bcfb4 1320 }
mbed_official 205:c41fc65bcfb4 1321
mbed_official 205:c41fc65bcfb4 1322 /**
mbed_official 205:c41fc65bcfb4 1323 * @brief Rx Half Transfer completed callbacks
mbed_official 205:c41fc65bcfb4 1324 * @param husart: usart handle
mbed_official 205:c41fc65bcfb4 1325 * @retval None
mbed_official 205:c41fc65bcfb4 1326 */
mbed_official 205:c41fc65bcfb4 1327 __weak void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1328 {
mbed_official 205:c41fc65bcfb4 1329 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 1330 the HAL_USART_RxHalfCpltCallback can be implemented in the user file
mbed_official 205:c41fc65bcfb4 1331 */
mbed_official 205:c41fc65bcfb4 1332 }
mbed_official 205:c41fc65bcfb4 1333
mbed_official 205:c41fc65bcfb4 1334 /**
mbed_official 205:c41fc65bcfb4 1335 * @brief Tx/Rx Transfers completed callback for the non-blocking process
mbed_official 205:c41fc65bcfb4 1336 * @param husart: usart handle
mbed_official 205:c41fc65bcfb4 1337 * @retval None
mbed_official 205:c41fc65bcfb4 1338 */
mbed_official 205:c41fc65bcfb4 1339 __weak void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1340 {
mbed_official 205:c41fc65bcfb4 1341 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 1342 the HAL_USART_TxRxCpltCallback can be implemented in the user file
mbed_official 205:c41fc65bcfb4 1343 */
mbed_official 205:c41fc65bcfb4 1344 }
mbed_official 205:c41fc65bcfb4 1345
mbed_official 205:c41fc65bcfb4 1346 /**
mbed_official 205:c41fc65bcfb4 1347 * @brief USART error callbacks
mbed_official 205:c41fc65bcfb4 1348 * @param husart: usart handle
mbed_official 205:c41fc65bcfb4 1349 * @retval None
mbed_official 205:c41fc65bcfb4 1350 */
mbed_official 205:c41fc65bcfb4 1351 __weak void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1352 {
mbed_official 205:c41fc65bcfb4 1353 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 1354 the HAL_USART_ErrorCallback can be implemented in the user file
mbed_official 205:c41fc65bcfb4 1355 */
mbed_official 205:c41fc65bcfb4 1356 }
mbed_official 205:c41fc65bcfb4 1357
mbed_official 205:c41fc65bcfb4 1358
mbed_official 205:c41fc65bcfb4 1359 /**
mbed_official 205:c41fc65bcfb4 1360 * @brief Simplex Send an amount of data in non-blocking mode.
mbed_official 205:c41fc65bcfb4 1361 * Function called under interruption only, once
mbed_official 205:c41fc65bcfb4 1362 * interruptions have been enabled by HAL_USART_Transmit_IT()
mbed_official 205:c41fc65bcfb4 1363 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1364 * @retval HAL status
mbed_official 205:c41fc65bcfb4 1365 * @note The USART errors are not managed to avoid the overrun error.
mbed_official 205:c41fc65bcfb4 1366 */
mbed_official 205:c41fc65bcfb4 1367 static HAL_StatusTypeDef USART_Transmit_IT(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1368 {
mbed_official 205:c41fc65bcfb4 1369 uint16_t* tmp;
mbed_official 205:c41fc65bcfb4 1370
mbed_official 205:c41fc65bcfb4 1371 if (husart->State == HAL_USART_STATE_BUSY_TX)
mbed_official 205:c41fc65bcfb4 1372 {
mbed_official 205:c41fc65bcfb4 1373 /* Process Locked */
mbed_official 205:c41fc65bcfb4 1374 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 1375
mbed_official 205:c41fc65bcfb4 1376 if(husart->TxXferCount == 0)
mbed_official 205:c41fc65bcfb4 1377 {
mbed_official 205:c41fc65bcfb4 1378 /* Disable the USART Transmit Complete Interrupt */
mbed_official 205:c41fc65bcfb4 1379 __HAL_USART_DISABLE_IT(husart, USART_IT_TC);
mbed_official 205:c41fc65bcfb4 1380
mbed_official 205:c41fc65bcfb4 1381 /* Disable the USART Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 205:c41fc65bcfb4 1382 __HAL_USART_DISABLE_IT(husart, USART_IT_ERR);
mbed_official 205:c41fc65bcfb4 1383
mbed_official 205:c41fc65bcfb4 1384 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1385
mbed_official 205:c41fc65bcfb4 1386 /* Call the Process Unlocked before calling the Tx call back API to give the possibiity to
mbed_official 205:c41fc65bcfb4 1387 start again the Transmission under the Tx call back API */
mbed_official 205:c41fc65bcfb4 1388 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 1389
mbed_official 205:c41fc65bcfb4 1390 HAL_USART_TxCpltCallback(husart);
mbed_official 205:c41fc65bcfb4 1391
mbed_official 205:c41fc65bcfb4 1392 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1393 }
mbed_official 205:c41fc65bcfb4 1394 else
mbed_official 205:c41fc65bcfb4 1395 {
mbed_official 205:c41fc65bcfb4 1396 if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
mbed_official 205:c41fc65bcfb4 1397 {
mbed_official 205:c41fc65bcfb4 1398 tmp = (uint16_t*) husart->pTxBuffPtr;
mbed_official 205:c41fc65bcfb4 1399 husart->Instance->TDR = (*tmp & (uint16_t)0x01FF);
mbed_official 205:c41fc65bcfb4 1400 husart->pTxBuffPtr += 2;
mbed_official 205:c41fc65bcfb4 1401 }
mbed_official 205:c41fc65bcfb4 1402 else
mbed_official 205:c41fc65bcfb4 1403 {
mbed_official 205:c41fc65bcfb4 1404 husart->Instance->TDR = (uint8_t)(*husart->pTxBuffPtr++ & (uint8_t)0xFF);
mbed_official 205:c41fc65bcfb4 1405 }
mbed_official 205:c41fc65bcfb4 1406
mbed_official 205:c41fc65bcfb4 1407 husart->TxXferCount--;
mbed_official 205:c41fc65bcfb4 1408
mbed_official 205:c41fc65bcfb4 1409 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 1410 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 1411
mbed_official 205:c41fc65bcfb4 1412 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1413 }
mbed_official 205:c41fc65bcfb4 1414 }
mbed_official 205:c41fc65bcfb4 1415 else
mbed_official 205:c41fc65bcfb4 1416 {
mbed_official 205:c41fc65bcfb4 1417 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 1418 }
mbed_official 205:c41fc65bcfb4 1419 }
mbed_official 205:c41fc65bcfb4 1420
mbed_official 205:c41fc65bcfb4 1421 /**
mbed_official 205:c41fc65bcfb4 1422 * @brief Simplex Receive an amount of data in non-blocking mode.
mbed_official 205:c41fc65bcfb4 1423 * Function called under interruption only, once
mbed_official 205:c41fc65bcfb4 1424 * interruptions have been enabled by HAL_USART_Receive_IT()
mbed_official 205:c41fc65bcfb4 1425 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1426 * @retval HAL status
mbed_official 205:c41fc65bcfb4 1427 */
mbed_official 205:c41fc65bcfb4 1428 static HAL_StatusTypeDef USART_Receive_IT(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1429 {
mbed_official 205:c41fc65bcfb4 1430 uint16_t* tmp;
mbed_official 205:c41fc65bcfb4 1431 uint16_t uhMask = husart->Mask;
mbed_official 205:c41fc65bcfb4 1432
mbed_official 205:c41fc65bcfb4 1433 if(husart->State == HAL_USART_STATE_BUSY_RX)
mbed_official 205:c41fc65bcfb4 1434 {
mbed_official 205:c41fc65bcfb4 1435 /* Process Locked */
mbed_official 205:c41fc65bcfb4 1436 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 1437
mbed_official 205:c41fc65bcfb4 1438 if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
mbed_official 205:c41fc65bcfb4 1439 {
mbed_official 205:c41fc65bcfb4 1440 tmp = (uint16_t*) husart->pRxBuffPtr ;
mbed_official 205:c41fc65bcfb4 1441 *tmp = (uint16_t)(husart->Instance->RDR & uhMask);
mbed_official 205:c41fc65bcfb4 1442 husart->pRxBuffPtr += 2;
mbed_official 205:c41fc65bcfb4 1443 }
mbed_official 205:c41fc65bcfb4 1444 else
mbed_official 205:c41fc65bcfb4 1445 {
mbed_official 205:c41fc65bcfb4 1446 *husart->pRxBuffPtr++ = (uint8_t)(husart->Instance->RDR & (uint8_t)uhMask);
mbed_official 205:c41fc65bcfb4 1447 }
mbed_official 205:c41fc65bcfb4 1448 /* Send dummy byte in order to generate the clock for the Slave to Send the next data */
mbed_official 205:c41fc65bcfb4 1449 husart->Instance->TDR = (DUMMY_DATA & (uint16_t)0x00FF);
mbed_official 205:c41fc65bcfb4 1450
mbed_official 205:c41fc65bcfb4 1451 if(--husart->RxXferCount == 0)
mbed_official 205:c41fc65bcfb4 1452 {
mbed_official 205:c41fc65bcfb4 1453 __HAL_USART_DISABLE_IT(husart, USART_IT_RXNE);
mbed_official 205:c41fc65bcfb4 1454
mbed_official 205:c41fc65bcfb4 1455 /* Disable the USART Parity Error Interrupt */
mbed_official 205:c41fc65bcfb4 1456 __HAL_USART_DISABLE_IT(husart, USART_IT_PE);
mbed_official 205:c41fc65bcfb4 1457
mbed_official 205:c41fc65bcfb4 1458 /* Disable the USART Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 205:c41fc65bcfb4 1459 __HAL_USART_DISABLE_IT(husart, USART_IT_ERR);
mbed_official 205:c41fc65bcfb4 1460
mbed_official 205:c41fc65bcfb4 1461 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1462
mbed_official 205:c41fc65bcfb4 1463 /* Call the Process Unlocked before calling the Rx call back API to give the possibility to
mbed_official 205:c41fc65bcfb4 1464 start again the reception under the Rx call back API */
mbed_official 205:c41fc65bcfb4 1465 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 1466
mbed_official 205:c41fc65bcfb4 1467 HAL_USART_RxCpltCallback(husart);
mbed_official 205:c41fc65bcfb4 1468
mbed_official 205:c41fc65bcfb4 1469 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1470 }
mbed_official 205:c41fc65bcfb4 1471
mbed_official 205:c41fc65bcfb4 1472 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 1473 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 1474
mbed_official 205:c41fc65bcfb4 1475 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1476 }
mbed_official 205:c41fc65bcfb4 1477 else
mbed_official 205:c41fc65bcfb4 1478 {
mbed_official 205:c41fc65bcfb4 1479 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 1480 }
mbed_official 205:c41fc65bcfb4 1481 }
mbed_official 205:c41fc65bcfb4 1482
mbed_official 205:c41fc65bcfb4 1483 /**
mbed_official 205:c41fc65bcfb4 1484 * @brief Full-Duplex Send receive an amount of data in full-duplex mode (non-blocking).
mbed_official 205:c41fc65bcfb4 1485 * Function called under interruption only, once
mbed_official 205:c41fc65bcfb4 1486 * interruptions have been enabled by HAL_USART_TransmitReceive_IT()
mbed_official 205:c41fc65bcfb4 1487 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1488 * @retval HAL status
mbed_official 205:c41fc65bcfb4 1489 */
mbed_official 205:c41fc65bcfb4 1490 static HAL_StatusTypeDef USART_TransmitReceive_IT(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1491 {
mbed_official 205:c41fc65bcfb4 1492 uint16_t* tmp;
mbed_official 205:c41fc65bcfb4 1493 uint16_t uhMask = husart->Mask;
mbed_official 205:c41fc65bcfb4 1494
mbed_official 205:c41fc65bcfb4 1495 if(husart->State == HAL_USART_STATE_BUSY_TX_RX)
mbed_official 205:c41fc65bcfb4 1496 {
mbed_official 205:c41fc65bcfb4 1497 /* Process Locked */
mbed_official 205:c41fc65bcfb4 1498 __HAL_LOCK(husart);
mbed_official 205:c41fc65bcfb4 1499 if(husart->TxXferCount != 0x00)
mbed_official 205:c41fc65bcfb4 1500 {
mbed_official 205:c41fc65bcfb4 1501 if(__HAL_USART_GET_FLAG(husart, USART_FLAG_TC) != RESET)
mbed_official 205:c41fc65bcfb4 1502 {
mbed_official 205:c41fc65bcfb4 1503 if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
mbed_official 205:c41fc65bcfb4 1504 {
mbed_official 205:c41fc65bcfb4 1505 tmp = (uint16_t*) husart->pTxBuffPtr;
mbed_official 205:c41fc65bcfb4 1506 husart->Instance->TDR = (uint16_t)(*tmp & uhMask);
mbed_official 205:c41fc65bcfb4 1507 husart->pTxBuffPtr += 2;
mbed_official 205:c41fc65bcfb4 1508 }
mbed_official 205:c41fc65bcfb4 1509 else
mbed_official 205:c41fc65bcfb4 1510 {
mbed_official 205:c41fc65bcfb4 1511 husart->Instance->TDR = (uint8_t)(*husart->pTxBuffPtr++ & (uint8_t)uhMask);
mbed_official 205:c41fc65bcfb4 1512 }
mbed_official 205:c41fc65bcfb4 1513 husart->TxXferCount--;
mbed_official 205:c41fc65bcfb4 1514
mbed_official 205:c41fc65bcfb4 1515 /* Check the latest data transmitted */
mbed_official 205:c41fc65bcfb4 1516 if(husart->TxXferCount == 0)
mbed_official 205:c41fc65bcfb4 1517 {
mbed_official 205:c41fc65bcfb4 1518 __HAL_USART_DISABLE_IT(husart, USART_IT_TC);
mbed_official 205:c41fc65bcfb4 1519 }
mbed_official 205:c41fc65bcfb4 1520 }
mbed_official 205:c41fc65bcfb4 1521 }
mbed_official 205:c41fc65bcfb4 1522
mbed_official 205:c41fc65bcfb4 1523 if(husart->RxXferCount != 0x00)
mbed_official 205:c41fc65bcfb4 1524 {
mbed_official 205:c41fc65bcfb4 1525 if(__HAL_USART_GET_FLAG(husart, USART_FLAG_RXNE) != RESET)
mbed_official 205:c41fc65bcfb4 1526 {
mbed_official 205:c41fc65bcfb4 1527 if ((husart->Init.WordLength == USART_WORDLENGTH_9B) && (husart->Init.Parity == USART_PARITY_NONE))
mbed_official 205:c41fc65bcfb4 1528 {
mbed_official 205:c41fc65bcfb4 1529 tmp = (uint16_t*) husart->pRxBuffPtr ;
mbed_official 205:c41fc65bcfb4 1530 *tmp = (uint16_t)(husart->Instance->RDR & uhMask);
mbed_official 205:c41fc65bcfb4 1531 husart->pRxBuffPtr += 2;
mbed_official 205:c41fc65bcfb4 1532 }
mbed_official 205:c41fc65bcfb4 1533 else
mbed_official 205:c41fc65bcfb4 1534 {
mbed_official 205:c41fc65bcfb4 1535 *husart->pRxBuffPtr++ = (uint8_t)(husart->Instance->RDR & (uint8_t)uhMask);
mbed_official 205:c41fc65bcfb4 1536 }
mbed_official 205:c41fc65bcfb4 1537 husart->RxXferCount--;
mbed_official 205:c41fc65bcfb4 1538 }
mbed_official 205:c41fc65bcfb4 1539 }
mbed_official 205:c41fc65bcfb4 1540
mbed_official 205:c41fc65bcfb4 1541 /* Check the latest data received */
mbed_official 205:c41fc65bcfb4 1542 if(husart->RxXferCount == 0)
mbed_official 205:c41fc65bcfb4 1543 {
mbed_official 205:c41fc65bcfb4 1544 __HAL_USART_DISABLE_IT(husart, USART_IT_RXNE);
mbed_official 205:c41fc65bcfb4 1545
mbed_official 205:c41fc65bcfb4 1546 /* Disable the USART Parity Error Interrupt */
mbed_official 205:c41fc65bcfb4 1547 __HAL_USART_DISABLE_IT(husart, USART_IT_PE);
mbed_official 205:c41fc65bcfb4 1548
mbed_official 205:c41fc65bcfb4 1549 /* Disable the USART Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 205:c41fc65bcfb4 1550 __HAL_USART_DISABLE_IT(husart, USART_IT_ERR);
mbed_official 205:c41fc65bcfb4 1551
mbed_official 205:c41fc65bcfb4 1552 husart->State = HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1553
mbed_official 205:c41fc65bcfb4 1554 /* Call the Process Unlocked before calling the Tx\Rx call back API to give the possibility to
mbed_official 205:c41fc65bcfb4 1555 start again the Transmission\reception under the Tx\Rx call back API */
mbed_official 205:c41fc65bcfb4 1556 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 1557
mbed_official 205:c41fc65bcfb4 1558 HAL_USART_TxRxCpltCallback(husart);
mbed_official 205:c41fc65bcfb4 1559
mbed_official 205:c41fc65bcfb4 1560 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1561 }
mbed_official 205:c41fc65bcfb4 1562
mbed_official 205:c41fc65bcfb4 1563 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 1564 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 1565
mbed_official 205:c41fc65bcfb4 1566 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1567 }
mbed_official 205:c41fc65bcfb4 1568 else
mbed_official 205:c41fc65bcfb4 1569 {
mbed_official 205:c41fc65bcfb4 1570 return HAL_BUSY;
mbed_official 205:c41fc65bcfb4 1571 }
mbed_official 205:c41fc65bcfb4 1572 }
mbed_official 205:c41fc65bcfb4 1573
mbed_official 205:c41fc65bcfb4 1574 /**
mbed_official 205:c41fc65bcfb4 1575 * @}
mbed_official 205:c41fc65bcfb4 1576 */
mbed_official 205:c41fc65bcfb4 1577
mbed_official 205:c41fc65bcfb4 1578 /** @defgroup HAL_USART_Group3 Peripheral Control function
mbed_official 205:c41fc65bcfb4 1579 * @brief USART control functions
mbed_official 205:c41fc65bcfb4 1580 *
mbed_official 205:c41fc65bcfb4 1581 @verbatim
mbed_official 205:c41fc65bcfb4 1582 ===============================================================================
mbed_official 205:c41fc65bcfb4 1583 ##### Peripheral Control function #####
mbed_official 205:c41fc65bcfb4 1584 ===============================================================================
mbed_official 205:c41fc65bcfb4 1585 [..]
mbed_official 205:c41fc65bcfb4 1586 This subsection provides a set of functions allowing to control the USART.
mbed_official 205:c41fc65bcfb4 1587 (+) HAL_USART_GetState() API can be helpful to check in run-time the state of the USART peripheral.
mbed_official 205:c41fc65bcfb4 1588 (+) USART_SetConfig() API is used to set the USART communication parameters.
mbed_official 205:c41fc65bcfb4 1589 (+) USART_CheckIdleState() APi ensures that TEACK and/or REACK bits are set after initialization
mbed_official 205:c41fc65bcfb4 1590
mbed_official 205:c41fc65bcfb4 1591 @endverbatim
mbed_official 205:c41fc65bcfb4 1592 * @{
mbed_official 205:c41fc65bcfb4 1593 */
mbed_official 205:c41fc65bcfb4 1594
mbed_official 205:c41fc65bcfb4 1595
mbed_official 205:c41fc65bcfb4 1596
mbed_official 205:c41fc65bcfb4 1597 /**
mbed_official 205:c41fc65bcfb4 1598 * @brief return the USART state
mbed_official 205:c41fc65bcfb4 1599 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1600 * @retval HAL state
mbed_official 205:c41fc65bcfb4 1601 */
mbed_official 205:c41fc65bcfb4 1602 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1603 {
mbed_official 205:c41fc65bcfb4 1604 return husart->State;
mbed_official 205:c41fc65bcfb4 1605 }
mbed_official 205:c41fc65bcfb4 1606
mbed_official 205:c41fc65bcfb4 1607 /**
mbed_official 205:c41fc65bcfb4 1608 * @brief Return the USART error code
mbed_official 205:c41fc65bcfb4 1609 * @param husart : pointer to a USART_HandleTypeDef structure that contains
mbed_official 205:c41fc65bcfb4 1610 * the configuration information for the specified USART.
mbed_official 205:c41fc65bcfb4 1611 * @retval USART Error Code
mbed_official 205:c41fc65bcfb4 1612 */
mbed_official 205:c41fc65bcfb4 1613 uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1614 {
mbed_official 205:c41fc65bcfb4 1615 return husart->ErrorCode;
mbed_official 205:c41fc65bcfb4 1616 }
mbed_official 205:c41fc65bcfb4 1617
mbed_official 205:c41fc65bcfb4 1618 /**
mbed_official 205:c41fc65bcfb4 1619 * @brief Configure the USART peripheral
mbed_official 205:c41fc65bcfb4 1620 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1621 * @retval None
mbed_official 205:c41fc65bcfb4 1622 */
mbed_official 205:c41fc65bcfb4 1623 static HAL_StatusTypeDef USART_SetConfig(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1624 {
mbed_official 205:c41fc65bcfb4 1625 uint32_t tmpreg = 0x0;
mbed_official 205:c41fc65bcfb4 1626 USART_ClockSourceTypeDef clocksource = USART_CLOCKSOURCE_UNDEFINED;
mbed_official 205:c41fc65bcfb4 1627 HAL_StatusTypeDef ret = HAL_OK;
mbed_official 205:c41fc65bcfb4 1628
mbed_official 205:c41fc65bcfb4 1629 /* Check the parameters */
mbed_official 205:c41fc65bcfb4 1630 assert_param(IS_USART_POLARITY(husart->Init.CLKPolarity));
mbed_official 205:c41fc65bcfb4 1631 assert_param(IS_USART_PHASE(husart->Init.CLKPhase));
mbed_official 205:c41fc65bcfb4 1632 assert_param(IS_USART_LASTBIT(husart->Init.CLKLastBit));
mbed_official 205:c41fc65bcfb4 1633 assert_param(IS_USART_BAUDRATE(husart->Init.BaudRate));
mbed_official 205:c41fc65bcfb4 1634 assert_param(IS_USART_WORD_LENGTH(husart->Init.WordLength));
mbed_official 205:c41fc65bcfb4 1635 assert_param(IS_USART_STOPBITS(husart->Init.StopBits));
mbed_official 205:c41fc65bcfb4 1636 assert_param(IS_USART_PARITY(husart->Init.Parity));
mbed_official 205:c41fc65bcfb4 1637 assert_param(IS_USART_MODE(husart->Init.Mode));
mbed_official 205:c41fc65bcfb4 1638
mbed_official 205:c41fc65bcfb4 1639
mbed_official 205:c41fc65bcfb4 1640 /*-------------------------- USART CR1 Configuration -----------------------*/
mbed_official 205:c41fc65bcfb4 1641 /* Clear M, PCE, PS, TE and RE bits and configure
mbed_official 205:c41fc65bcfb4 1642 * the USART Word Length, Parity, Mode and oversampling:
mbed_official 205:c41fc65bcfb4 1643 * set the M bits according to husart->Init.WordLength value
mbed_official 205:c41fc65bcfb4 1644 * set PCE and PS bits according to husart->Init.Parity value
mbed_official 205:c41fc65bcfb4 1645 * set TE and RE bits according to husart->Init.Mode value */
mbed_official 205:c41fc65bcfb4 1646 tmpreg = (uint32_t)husart->Init.WordLength | husart->Init.Parity | husart->Init.Mode ;
mbed_official 205:c41fc65bcfb4 1647 MODIFY_REG(husart->Instance->CR1, USART_CR1_FIELDS, tmpreg);
mbed_official 205:c41fc65bcfb4 1648
mbed_official 205:c41fc65bcfb4 1649 /*---------------------------- USART CR2 Configuration ---------------------*/
mbed_official 205:c41fc65bcfb4 1650 /* Clear and configure the USART Clock, CPOL, CPHA, LBCL and STOP bits:
mbed_official 205:c41fc65bcfb4 1651 * set CPOL bit according to husart->Init.CLKPolarity value
mbed_official 205:c41fc65bcfb4 1652 * set CPHA bit according to husart->Init.CLKPhase value
mbed_official 205:c41fc65bcfb4 1653 * set LBCL bit according to husart->Init.CLKLastBit value
mbed_official 205:c41fc65bcfb4 1654 * set STOP[13:12] bits according to husart->Init.StopBits value */
mbed_official 205:c41fc65bcfb4 1655 tmpreg = (uint32_t)(USART_CLOCK_ENABLED);
mbed_official 205:c41fc65bcfb4 1656 tmpreg |= (uint32_t)(husart->Init.CLKPolarity | husart->Init.CLKPhase);
mbed_official 205:c41fc65bcfb4 1657 tmpreg |= (uint32_t)(husart->Init.CLKLastBit | husart->Init.StopBits);
mbed_official 205:c41fc65bcfb4 1658 MODIFY_REG(husart->Instance->CR2, USART_CR2_FIELDS, tmpreg);
mbed_official 205:c41fc65bcfb4 1659
mbed_official 205:c41fc65bcfb4 1660 /*-------------------------- USART CR3 Configuration -----------------------*/
mbed_official 205:c41fc65bcfb4 1661 /* no CR3 register configuration */
mbed_official 205:c41fc65bcfb4 1662
mbed_official 205:c41fc65bcfb4 1663 /*-------------------------- USART BRR Configuration -----------------------*/
mbed_official 205:c41fc65bcfb4 1664 __HAL_USART_GETCLOCKSOURCE(husart, clocksource);
mbed_official 205:c41fc65bcfb4 1665 switch (clocksource)
mbed_official 205:c41fc65bcfb4 1666 {
mbed_official 205:c41fc65bcfb4 1667 case USART_CLOCKSOURCE_PCLK1:
mbed_official 205:c41fc65bcfb4 1668 husart->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK1Freq() / husart->Init.BaudRate);
mbed_official 205:c41fc65bcfb4 1669 break;
mbed_official 205:c41fc65bcfb4 1670 case USART_CLOCKSOURCE_HSI:
mbed_official 205:c41fc65bcfb4 1671 husart->Instance->BRR = (uint16_t)(HSI_VALUE / husart->Init.BaudRate);
mbed_official 205:c41fc65bcfb4 1672 break;
mbed_official 205:c41fc65bcfb4 1673 case USART_CLOCKSOURCE_SYSCLK:
mbed_official 205:c41fc65bcfb4 1674 husart->Instance->BRR = (uint16_t)(HAL_RCC_GetSysClockFreq() / husart->Init.BaudRate);
mbed_official 205:c41fc65bcfb4 1675 break;
mbed_official 205:c41fc65bcfb4 1676 case USART_CLOCKSOURCE_LSE:
mbed_official 205:c41fc65bcfb4 1677 husart->Instance->BRR = (uint16_t)(LSE_VALUE / husart->Init.BaudRate);
mbed_official 205:c41fc65bcfb4 1678 break;
mbed_official 205:c41fc65bcfb4 1679 case USART_CLOCKSOURCE_UNDEFINED:
mbed_official 205:c41fc65bcfb4 1680 default:
mbed_official 205:c41fc65bcfb4 1681 ret = HAL_ERROR;
mbed_official 205:c41fc65bcfb4 1682 break;
mbed_official 205:c41fc65bcfb4 1683 }
mbed_official 205:c41fc65bcfb4 1684
mbed_official 205:c41fc65bcfb4 1685 return ret;
mbed_official 205:c41fc65bcfb4 1686 }
mbed_official 205:c41fc65bcfb4 1687
mbed_official 205:c41fc65bcfb4 1688
mbed_official 205:c41fc65bcfb4 1689
mbed_official 205:c41fc65bcfb4 1690 /**
mbed_official 205:c41fc65bcfb4 1691 * @brief Check the USART Idle State
mbed_official 205:c41fc65bcfb4 1692 * @param husart: USART handle
mbed_official 205:c41fc65bcfb4 1693 * @retval HAL status
mbed_official 205:c41fc65bcfb4 1694 */
mbed_official 205:c41fc65bcfb4 1695 static HAL_StatusTypeDef USART_CheckIdleState(USART_HandleTypeDef *husart)
mbed_official 205:c41fc65bcfb4 1696 {
mbed_official 205:c41fc65bcfb4 1697 /* Initialize the USART ErrorCode */
mbed_official 205:c41fc65bcfb4 1698 husart->ErrorCode = HAL_USART_ERROR_NONE;
mbed_official 205:c41fc65bcfb4 1699
mbed_official 205:c41fc65bcfb4 1700 /* Check if the Transmitter is enabled */
mbed_official 205:c41fc65bcfb4 1701 if((husart->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
mbed_official 205:c41fc65bcfb4 1702 {
mbed_official 205:c41fc65bcfb4 1703 /* Wait until TEACK flag is set */
mbed_official 205:c41fc65bcfb4 1704 if(USART_WaitOnFlagUntilTimeout(husart, USART_ISR_TEACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK)
mbed_official 205:c41fc65bcfb4 1705 {
mbed_official 205:c41fc65bcfb4 1706 husart->State= HAL_USART_STATE_TIMEOUT;
mbed_official 205:c41fc65bcfb4 1707 return HAL_TIMEOUT;
mbed_official 205:c41fc65bcfb4 1708 }
mbed_official 205:c41fc65bcfb4 1709 }
mbed_official 205:c41fc65bcfb4 1710 /* Check if the Receiver is enabled */
mbed_official 205:c41fc65bcfb4 1711 if((husart->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
mbed_official 205:c41fc65bcfb4 1712 {
mbed_official 205:c41fc65bcfb4 1713 /* Wait until REACK flag is set */
mbed_official 205:c41fc65bcfb4 1714 if(USART_WaitOnFlagUntilTimeout(husart, USART_ISR_REACK, RESET, TEACK_REACK_TIMEOUT) != HAL_OK)
mbed_official 205:c41fc65bcfb4 1715 {
mbed_official 205:c41fc65bcfb4 1716 husart->State= HAL_USART_STATE_TIMEOUT;
mbed_official 205:c41fc65bcfb4 1717 return HAL_TIMEOUT;
mbed_official 205:c41fc65bcfb4 1718 }
mbed_official 205:c41fc65bcfb4 1719 }
mbed_official 205:c41fc65bcfb4 1720
mbed_official 205:c41fc65bcfb4 1721 /* Initialize the USART state*/
mbed_official 205:c41fc65bcfb4 1722 husart->State= HAL_USART_STATE_READY;
mbed_official 205:c41fc65bcfb4 1723 /* Process Unlocked */
mbed_official 205:c41fc65bcfb4 1724 __HAL_UNLOCK(husart);
mbed_official 205:c41fc65bcfb4 1725
mbed_official 205:c41fc65bcfb4 1726 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1727 }
mbed_official 205:c41fc65bcfb4 1728
mbed_official 205:c41fc65bcfb4 1729 /**
mbed_official 205:c41fc65bcfb4 1730 * @}
mbed_official 205:c41fc65bcfb4 1731 */
mbed_official 205:c41fc65bcfb4 1732
mbed_official 205:c41fc65bcfb4 1733 /**
mbed_official 205:c41fc65bcfb4 1734 * @}
mbed_official 205:c41fc65bcfb4 1735 */
mbed_official 205:c41fc65bcfb4 1736
mbed_official 205:c41fc65bcfb4 1737 #endif /* HAL_USART_MODULE_ENABLED */
mbed_official 205:c41fc65bcfb4 1738 /**
mbed_official 205:c41fc65bcfb4 1739 * @}
mbed_official 205:c41fc65bcfb4 1740 */
mbed_official 205:c41fc65bcfb4 1741
mbed_official 205:c41fc65bcfb4 1742 /**
mbed_official 205:c41fc65bcfb4 1743 * @}
mbed_official 205:c41fc65bcfb4 1744 */
mbed_official 205:c41fc65bcfb4 1745
mbed_official 205:c41fc65bcfb4 1746 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/