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