mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Aug 20 10:45:13 2015 +0100
Revision:
613:bc40b8d2aec4
Parent:
532:fe11edbda85c
Synchronized with git revision 92ca8c7b60a283b6bb60eb65b183dac1599f0ade

Full URL: https://github.com/mbedmicro/mbed/commit/92ca8c7b60a283b6bb60eb65b183dac1599f0ade/

Nordic: update application start address in GCC linker script

Who changed what in which revision?

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