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