mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Nov 03 10:30:07 2014 +0000
Revision:
381:5460fc57b6e4
Synchronized with git revision 02478cd1f27fc7b9643486472635eb515b2bca81

Full URL: https://github.com/mbedmicro/mbed/commit/02478cd1f27fc7b9643486472635eb515b2bca81/

Target: LPC1549 - Fix serial interrupt issues (issue report #616)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 381:5460fc57b6e4 1 /**
mbed_official 381:5460fc57b6e4 2 ******************************************************************************
mbed_official 381:5460fc57b6e4 3 * @file stm32f3xx_hal_uart_ex.c
mbed_official 381:5460fc57b6e4 4 * @author MCD Application Team
mbed_official 381:5460fc57b6e4 5 * @version V1.1.0
mbed_official 381:5460fc57b6e4 6 * @date 12-Sept-2014
mbed_official 381:5460fc57b6e4 7 * @brief Extended UART HAL module driver.
mbed_official 381:5460fc57b6e4 8 *
mbed_official 381:5460fc57b6e4 9 * This file provides firmware functions to manage the following extended
mbed_official 381:5460fc57b6e4 10 * functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART).
mbed_official 381:5460fc57b6e4 11 * + Initialization and de-initialization functions
mbed_official 381:5460fc57b6e4 12 * + Peripheral Control functions
mbed_official 381:5460fc57b6e4 13 *
mbed_official 381:5460fc57b6e4 14 *
mbed_official 381:5460fc57b6e4 15 @verbatim
mbed_official 381:5460fc57b6e4 16 ===============================================================================
mbed_official 381:5460fc57b6e4 17 ##### How to use this driver #####
mbed_official 381:5460fc57b6e4 18 ===============================================================================
mbed_official 381:5460fc57b6e4 19 [..]
mbed_official 381:5460fc57b6e4 20 The UART HAL driver can be used as follows:
mbed_official 381:5460fc57b6e4 21
mbed_official 381:5460fc57b6e4 22 (#) Declare a UART_HandleTypeDef handle structure.
mbed_official 381:5460fc57b6e4 23
mbed_official 381:5460fc57b6e4 24 (#) For the UART RS485 Driver Enabled mode, initialize the UART registers
mbed_official 381:5460fc57b6e4 25 by calling the HAL_RS485Ex_Init() API.
mbed_official 381:5460fc57b6e4 26
mbed_official 381:5460fc57b6e4 27
mbed_official 381:5460fc57b6e4 28 @endverbatim
mbed_official 381:5460fc57b6e4 29 ******************************************************************************
mbed_official 381:5460fc57b6e4 30 * @attention
mbed_official 381:5460fc57b6e4 31 *
mbed_official 381:5460fc57b6e4 32 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 381:5460fc57b6e4 33 *
mbed_official 381:5460fc57b6e4 34 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 381:5460fc57b6e4 35 * are permitted provided that the following conditions are met:
mbed_official 381:5460fc57b6e4 36 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 381:5460fc57b6e4 37 * this list of conditions and the following disclaimer.
mbed_official 381:5460fc57b6e4 38 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 381:5460fc57b6e4 39 * this list of conditions and the following disclaimer in the documentation
mbed_official 381:5460fc57b6e4 40 * and/or other materials provided with the distribution.
mbed_official 381:5460fc57b6e4 41 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 381:5460fc57b6e4 42 * may be used to endorse or promote products derived from this software
mbed_official 381:5460fc57b6e4 43 * without specific prior written permission.
mbed_official 381:5460fc57b6e4 44 *
mbed_official 381:5460fc57b6e4 45 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 381:5460fc57b6e4 46 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 381:5460fc57b6e4 47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 381:5460fc57b6e4 48 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 381:5460fc57b6e4 49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 381:5460fc57b6e4 50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 381:5460fc57b6e4 51 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 381:5460fc57b6e4 52 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 381:5460fc57b6e4 53 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 381:5460fc57b6e4 54 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 381:5460fc57b6e4 55 *
mbed_official 381:5460fc57b6e4 56 ******************************************************************************
mbed_official 381:5460fc57b6e4 57 */
mbed_official 381:5460fc57b6e4 58
mbed_official 381:5460fc57b6e4 59 /* Includes ------------------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 60 #include "stm32f3xx_hal.h"
mbed_official 381:5460fc57b6e4 61
mbed_official 381:5460fc57b6e4 62 /** @addtogroup STM32F3xx_HAL_Driver
mbed_official 381:5460fc57b6e4 63 * @{
mbed_official 381:5460fc57b6e4 64 */
mbed_official 381:5460fc57b6e4 65
mbed_official 381:5460fc57b6e4 66 /** @defgroup UARTEx UART Extended HAL module driver
mbed_official 381:5460fc57b6e4 67 * @brief UART Extended HAL module driver
mbed_official 381:5460fc57b6e4 68 * @{
mbed_official 381:5460fc57b6e4 69 */
mbed_official 381:5460fc57b6e4 70 #ifdef HAL_UART_MODULE_ENABLED
mbed_official 381:5460fc57b6e4 71
mbed_official 381:5460fc57b6e4 72 /* Private typedef -----------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 73 /* Private define ------------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 74 /* Private macro -------------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 75 /* Private variables ---------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 76 /* Private function prototypes -----------------------------------------------*/
mbed_official 381:5460fc57b6e4 77 /* Exported functions --------------------------------------------------------*/
mbed_official 381:5460fc57b6e4 78
mbed_official 381:5460fc57b6e4 79 /** @defgroup UARTEx_Exported_Functions UART Extended Exported Functions
mbed_official 381:5460fc57b6e4 80 * @{
mbed_official 381:5460fc57b6e4 81 */
mbed_official 381:5460fc57b6e4 82
mbed_official 381:5460fc57b6e4 83 /** @defgroup UARTEx_Exported_Functions_Group1 Extended Initialization and de-initialization functions
mbed_official 381:5460fc57b6e4 84 * @brief Extended Initialization and Configuration Functions
mbed_official 381:5460fc57b6e4 85 *
mbed_official 381:5460fc57b6e4 86 @verbatim
mbed_official 381:5460fc57b6e4 87 ===============================================================================
mbed_official 381:5460fc57b6e4 88 ##### Initialization and Configuration functions #####
mbed_official 381:5460fc57b6e4 89 ===============================================================================
mbed_official 381:5460fc57b6e4 90 [..]
mbed_official 381:5460fc57b6e4 91 This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
mbed_official 381:5460fc57b6e4 92 in asynchronous mode.
mbed_official 381:5460fc57b6e4 93 (+) For the asynchronous mode only these parameters can be configured:
mbed_official 381:5460fc57b6e4 94 (++) Baud Rate
mbed_official 381:5460fc57b6e4 95 (++) Word Length
mbed_official 381:5460fc57b6e4 96 (++) Stop Bit
mbed_official 381:5460fc57b6e4 97 (++) Parity: If the parity is enabled, then the MSB bit of the data written
mbed_official 381:5460fc57b6e4 98 in the data register is transmitted but is changed by the parity bit.
mbed_official 381:5460fc57b6e4 99 Depending on the frame length defined by the M bit (8-bits or 9-bits)
mbed_official 381:5460fc57b6e4 100 or by the M1 and M0 bits (7-bit, 8-bit or 9-bit),
mbed_official 381:5460fc57b6e4 101 the possible UART frame formats are as listed in the following table:
mbed_official 381:5460fc57b6e4 102 +---------------------------------------------------------------+
mbed_official 381:5460fc57b6e4 103 | M bit | PCE bit | UART frame |
mbed_official 381:5460fc57b6e4 104 |-----------|-----------|---------------------------------------|
mbed_official 381:5460fc57b6e4 105 | 0 | 0 | | SB | 8-bit data | STB | |
mbed_official 381:5460fc57b6e4 106 |-----------|-----------|---------------------------------------|
mbed_official 381:5460fc57b6e4 107 | 0 | 1 | | SB | 7-bit data | PB | STB | |
mbed_official 381:5460fc57b6e4 108 |-----------|-----------|---------------------------------------|
mbed_official 381:5460fc57b6e4 109 | 1 | 0 | | SB | 9-bit data | STB | |
mbed_official 381:5460fc57b6e4 110 |-----------|-----------|---------------------------------------|
mbed_official 381:5460fc57b6e4 111 | 1 | 1 | | SB | 8-bit data | PB | STB | |
mbed_official 381:5460fc57b6e4 112 +---------------------------------------------------------------+
mbed_official 381:5460fc57b6e4 113 | M1M0 bits | PCE bit | UART frame |
mbed_official 381:5460fc57b6e4 114 |-----------------------|---------------------------------------|
mbed_official 381:5460fc57b6e4 115 | 10 | 0 | | SB | 7-bit data | STB | |
mbed_official 381:5460fc57b6e4 116 |-----------|-----------|---------------------------------------|
mbed_official 381:5460fc57b6e4 117 | 10 | 1 | | SB | 6-bit data | PB | STB | |
mbed_official 381:5460fc57b6e4 118 +---------------------------------------------------------------+
mbed_official 381:5460fc57b6e4 119 (++) Hardware flow control
mbed_official 381:5460fc57b6e4 120 (++) Receiver/transmitter modes
mbed_official 381:5460fc57b6e4 121 (++) Over Sampling Method
mbed_official 381:5460fc57b6e4 122 (++) One-Bit Sampling Method
mbed_official 381:5460fc57b6e4 123 (+) For the asynchronous mode, the following advanced features can be configured as well:
mbed_official 381:5460fc57b6e4 124 (++) TX and/or RX pin level inversion
mbed_official 381:5460fc57b6e4 125 (++) data logical level inversion
mbed_official 381:5460fc57b6e4 126 (++) RX and TX pins swap
mbed_official 381:5460fc57b6e4 127 (++) RX overrun detection disabling
mbed_official 381:5460fc57b6e4 128 (++) DMA disabling on RX error
mbed_official 381:5460fc57b6e4 129 (++) MSB first on communication line
mbed_official 381:5460fc57b6e4 130 (++) auto Baud rate detection
mbed_official 381:5460fc57b6e4 131 [..]
mbed_official 381:5460fc57b6e4 132 The HAL_RS485Ex_Init() API follows respectively the UART RS485 mode
mbed_official 381:5460fc57b6e4 133 configuration procedures (details for the procedures are available in reference manual).
mbed_official 381:5460fc57b6e4 134
mbed_official 381:5460fc57b6e4 135 @endverbatim
mbed_official 381:5460fc57b6e4 136 * @{
mbed_official 381:5460fc57b6e4 137 */
mbed_official 381:5460fc57b6e4 138
mbed_official 381:5460fc57b6e4 139
mbed_official 381:5460fc57b6e4 140 /**
mbed_official 381:5460fc57b6e4 141 * @brief Initializes the RS485 Driver enable feature according to the specified
mbed_official 381:5460fc57b6e4 142 * parameters in the UART_InitTypeDef and creates the associated handle .
mbed_official 381:5460fc57b6e4 143 * @param huart: uart handle
mbed_official 381:5460fc57b6e4 144 * @param UART_DEPolarity: select the driver enable polarity
mbed_official 381:5460fc57b6e4 145 * This parameter can be one of the following values:
mbed_official 381:5460fc57b6e4 146 * @arg UART_DE_POLARITY_HIGH: DE signal is active high
mbed_official 381:5460fc57b6e4 147 * @arg UART_DE_POLARITY_LOW: DE signal is active low
mbed_official 381:5460fc57b6e4 148 * @param UART_DEAssertionTime: Driver Enable assertion time
mbed_official 381:5460fc57b6e4 149 * 5-bit value defining the time between the activation of the DE (Driver Enable)
mbed_official 381:5460fc57b6e4 150 * signal and the beginning of the start bit. It is expressed in sample time
mbed_official 381:5460fc57b6e4 151 * units (1/8 or 1/16 bit time, depending on the oversampling rate)
mbed_official 381:5460fc57b6e4 152 * @param UART_DEDeassertionTime: Driver Enable deassertion time
mbed_official 381:5460fc57b6e4 153 * 5-bit value defining the time between the end of the last stop bit, in a
mbed_official 381:5460fc57b6e4 154 * transmitted message, and the de-activation of the DE (Driver Enable) signal.
mbed_official 381:5460fc57b6e4 155 * It is expressed in sample time units (1/8 or 1/16 bit time, depending on the
mbed_official 381:5460fc57b6e4 156 * oversampling rate).
mbed_official 381:5460fc57b6e4 157 * @retval HAL status
mbed_official 381:5460fc57b6e4 158 */
mbed_official 381:5460fc57b6e4 159 HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t UART_DEPolarity, uint32_t UART_DEAssertionTime, uint32_t UART_DEDeassertionTime)
mbed_official 381:5460fc57b6e4 160 {
mbed_official 381:5460fc57b6e4 161 uint32_t temp = 0x0;
mbed_official 381:5460fc57b6e4 162
mbed_official 381:5460fc57b6e4 163 /* Check the UART handle allocation */
mbed_official 381:5460fc57b6e4 164 if(huart == HAL_NULL)
mbed_official 381:5460fc57b6e4 165 {
mbed_official 381:5460fc57b6e4 166 return HAL_ERROR;
mbed_official 381:5460fc57b6e4 167 }
mbed_official 381:5460fc57b6e4 168 /* Check the Driver Enable UART instance */
mbed_official 381:5460fc57b6e4 169 assert_param(IS_UART_DRIVER_ENABLE_INSTANCE(huart->Instance));
mbed_official 381:5460fc57b6e4 170
mbed_official 381:5460fc57b6e4 171 /* Check the Driver Enable polarity */
mbed_official 381:5460fc57b6e4 172 assert_param(IS_UART_DE_POLARITY(UART_DEPolarity));
mbed_official 381:5460fc57b6e4 173
mbed_official 381:5460fc57b6e4 174 /* Check the Driver Enable assertion time */
mbed_official 381:5460fc57b6e4 175 assert_param(IS_UART_ASSERTIONTIME(UART_DEAssertionTime));
mbed_official 381:5460fc57b6e4 176
mbed_official 381:5460fc57b6e4 177 /* Check the Driver Enable deassertion time */
mbed_official 381:5460fc57b6e4 178 assert_param(IS_UART_DEASSERTIONTIME(UART_DEDeassertionTime));
mbed_official 381:5460fc57b6e4 179
mbed_official 381:5460fc57b6e4 180 if(huart->State == HAL_UART_STATE_RESET)
mbed_official 381:5460fc57b6e4 181 {
mbed_official 381:5460fc57b6e4 182 /* Init the low level hardware : GPIO, CLOCK */
mbed_official 381:5460fc57b6e4 183 HAL_UART_MspInit(huart);
mbed_official 381:5460fc57b6e4 184 }
mbed_official 381:5460fc57b6e4 185
mbed_official 381:5460fc57b6e4 186 huart->State = HAL_UART_STATE_BUSY;
mbed_official 381:5460fc57b6e4 187
mbed_official 381:5460fc57b6e4 188 /* Disable the Peripheral */
mbed_official 381:5460fc57b6e4 189 __HAL_UART_DISABLE(huart);
mbed_official 381:5460fc57b6e4 190
mbed_official 381:5460fc57b6e4 191 /* Set the UART Communication parameters */
mbed_official 381:5460fc57b6e4 192 if (UART_SetConfig(huart) == HAL_ERROR)
mbed_official 381:5460fc57b6e4 193 {
mbed_official 381:5460fc57b6e4 194 return HAL_ERROR;
mbed_official 381:5460fc57b6e4 195 }
mbed_official 381:5460fc57b6e4 196
mbed_official 381:5460fc57b6e4 197 if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
mbed_official 381:5460fc57b6e4 198 {
mbed_official 381:5460fc57b6e4 199 UART_AdvFeatureConfig(huart);
mbed_official 381:5460fc57b6e4 200 }
mbed_official 381:5460fc57b6e4 201
mbed_official 381:5460fc57b6e4 202 /* Enable the Driver Enable mode by setting the DEM bit in the CR3 register */
mbed_official 381:5460fc57b6e4 203 huart->Instance->CR3 |= USART_CR3_DEM;
mbed_official 381:5460fc57b6e4 204
mbed_official 381:5460fc57b6e4 205 /* Set the Driver Enable polarity */
mbed_official 381:5460fc57b6e4 206 MODIFY_REG(huart->Instance->CR3, USART_CR3_DEP, UART_DEPolarity);
mbed_official 381:5460fc57b6e4 207
mbed_official 381:5460fc57b6e4 208 /* Set the Driver Enable assertion and deassertion times */
mbed_official 381:5460fc57b6e4 209 temp = (UART_DEAssertionTime << UART_CR1_DEAT_ADDRESS_LSB_POS);
mbed_official 381:5460fc57b6e4 210 temp |= (UART_DEDeassertionTime << UART_CR1_DEDT_ADDRESS_LSB_POS);
mbed_official 381:5460fc57b6e4 211 MODIFY_REG(huart->Instance->CR1, (USART_CR1_DEDT|USART_CR1_DEAT), temp);
mbed_official 381:5460fc57b6e4 212
mbed_official 381:5460fc57b6e4 213 /* Enable the Peripheral */
mbed_official 381:5460fc57b6e4 214 __HAL_UART_ENABLE(huart);
mbed_official 381:5460fc57b6e4 215
mbed_official 381:5460fc57b6e4 216 /* TEACK and/or REACK to check before moving huart->State to Ready */
mbed_official 381:5460fc57b6e4 217 return (UART_CheckIdleState(huart));
mbed_official 381:5460fc57b6e4 218 }
mbed_official 381:5460fc57b6e4 219
mbed_official 381:5460fc57b6e4 220
mbed_official 381:5460fc57b6e4 221 /**
mbed_official 381:5460fc57b6e4 222 * @}
mbed_official 381:5460fc57b6e4 223 */
mbed_official 381:5460fc57b6e4 224
mbed_official 381:5460fc57b6e4 225 /** @defgroup UARTEx_Exported_Functions_Group2 Extended Peripheral Control functions
mbed_official 381:5460fc57b6e4 226 * @brief Extended Peripheral Control functions
mbed_official 381:5460fc57b6e4 227 *
mbed_official 381:5460fc57b6e4 228 @verbatim
mbed_official 381:5460fc57b6e4 229 ===============================================================================
mbed_official 381:5460fc57b6e4 230 ##### Peripheral Control functions #####
mbed_official 381:5460fc57b6e4 231 ===============================================================================
mbed_official 381:5460fc57b6e4 232 [..]
mbed_official 381:5460fc57b6e4 233 This subsection provides an extended function allowing to control the UART.
mbed_official 381:5460fc57b6e4 234 (+) HAL_MultiProcessorEx_AddressLength_Set() API optionally sets the UART node address
mbed_official 381:5460fc57b6e4 235 detection length to more than 4 bits for multiprocessor address mark wake up.
mbed_official 381:5460fc57b6e4 236 (+) HAL_UARTEx_StopModeWakeUpSourceConfig() configures the address for wake-up from
mbed_official 381:5460fc57b6e4 237 Stop mode based on address match
mbed_official 381:5460fc57b6e4 238 (+) HAL_UARTEx_EnableStopMode() API enables the UART to wake up the MCU from stop mode
mbed_official 381:5460fc57b6e4 239 (+) HAL_UARTEx_DisableStopMode() API disables the above functionality
mbed_official 381:5460fc57b6e4 240 @endverbatim
mbed_official 381:5460fc57b6e4 241 * @{
mbed_official 381:5460fc57b6e4 242 */
mbed_official 381:5460fc57b6e4 243
mbed_official 381:5460fc57b6e4 244
mbed_official 381:5460fc57b6e4 245
mbed_official 381:5460fc57b6e4 246 /**
mbed_official 381:5460fc57b6e4 247 * @brief By default in multiprocessor mode, when the wake up method is set
mbed_official 381:5460fc57b6e4 248 * to address mark, the UART handles only 4-bit long addresses detection.
mbed_official 381:5460fc57b6e4 249 * This API allows to enable longer addresses detection (6-, 7- or 8-bit
mbed_official 381:5460fc57b6e4 250 * long):
mbed_official 381:5460fc57b6e4 251 * - 6-bit address detection in 7-bit data mode
mbed_official 381:5460fc57b6e4 252 * - 7-bit address detection in 8-bit data mode
mbed_official 381:5460fc57b6e4 253 * - 8-bit address detection in 9-bit data mode
mbed_official 381:5460fc57b6e4 254 * @param huart: UART handle
mbed_official 381:5460fc57b6e4 255 * @param AddressLength: this parameter can be one of the following values:
mbed_official 381:5460fc57b6e4 256 * @arg UART_ADDRESS_DETECT_4B: 4-bit long address
mbed_official 381:5460fc57b6e4 257 * @arg UART_ADDRESS_DETECT_7B: 6-, 7- or 8-bit long address
mbed_official 381:5460fc57b6e4 258 * @retval HAL status
mbed_official 381:5460fc57b6e4 259 */
mbed_official 381:5460fc57b6e4 260 HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength)
mbed_official 381:5460fc57b6e4 261 {
mbed_official 381:5460fc57b6e4 262 /* Check the UART handle allocation */
mbed_official 381:5460fc57b6e4 263 if(huart == HAL_NULL)
mbed_official 381:5460fc57b6e4 264 {
mbed_official 381:5460fc57b6e4 265 return HAL_ERROR;
mbed_official 381:5460fc57b6e4 266 }
mbed_official 381:5460fc57b6e4 267
mbed_official 381:5460fc57b6e4 268 /* Check the address length parameter */
mbed_official 381:5460fc57b6e4 269 assert_param(IS_UART_ADDRESSLENGTH_DETECT(AddressLength));
mbed_official 381:5460fc57b6e4 270
mbed_official 381:5460fc57b6e4 271 huart->State = HAL_UART_STATE_BUSY;
mbed_official 381:5460fc57b6e4 272
mbed_official 381:5460fc57b6e4 273 /* Disable the Peripheral */
mbed_official 381:5460fc57b6e4 274 __HAL_UART_DISABLE(huart);
mbed_official 381:5460fc57b6e4 275
mbed_official 381:5460fc57b6e4 276 /* Set the address length */
mbed_official 381:5460fc57b6e4 277 MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, AddressLength);
mbed_official 381:5460fc57b6e4 278
mbed_official 381:5460fc57b6e4 279 /* Enable the Peripheral */
mbed_official 381:5460fc57b6e4 280 __HAL_UART_ENABLE(huart);
mbed_official 381:5460fc57b6e4 281
mbed_official 381:5460fc57b6e4 282 /* TEACK and/or REACK to check before moving huart->State to Ready */
mbed_official 381:5460fc57b6e4 283 return (UART_CheckIdleState(huart));
mbed_official 381:5460fc57b6e4 284 }
mbed_official 381:5460fc57b6e4 285
mbed_official 381:5460fc57b6e4 286
mbed_official 381:5460fc57b6e4 287 /**
mbed_official 381:5460fc57b6e4 288 * @brief Set Wakeup from Stop mode interrupt flag selection
mbed_official 381:5460fc57b6e4 289 * @param huart: uart handle,
mbed_official 381:5460fc57b6e4 290 * @param WakeUpSelection: address match, Start Bit detection or RXNE bit status.
mbed_official 381:5460fc57b6e4 291 * This parameter can be one of the following values:
mbed_official 381:5460fc57b6e4 292 * @arg UART_WAKEUP_ON_ADDRESS
mbed_official 381:5460fc57b6e4 293 * @arg UART_WAKEUP_ON_STARTBIT
mbed_official 381:5460fc57b6e4 294 * @arg UART_WAKEUP_ON_READDATA_NONEMPTY
mbed_official 381:5460fc57b6e4 295 * @retval HAL status
mbed_official 381:5460fc57b6e4 296 */
mbed_official 381:5460fc57b6e4 297 HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection)
mbed_official 381:5460fc57b6e4 298 {
mbed_official 381:5460fc57b6e4 299
mbed_official 381:5460fc57b6e4 300 /* check the wake-up from stop mode UART instance */
mbed_official 381:5460fc57b6e4 301 assert_param(IS_UART_WAKEUP_FROMSTOP_INSTANCE(huart->Instance));
mbed_official 381:5460fc57b6e4 302 /* check the wake-up selection parameter */
mbed_official 381:5460fc57b6e4 303 assert_param(IS_UART_WAKEUP_SELECTION(WakeUpSelection.WakeUpEvent));
mbed_official 381:5460fc57b6e4 304
mbed_official 381:5460fc57b6e4 305 /* Process Locked */
mbed_official 381:5460fc57b6e4 306 __HAL_LOCK(huart);
mbed_official 381:5460fc57b6e4 307
mbed_official 381:5460fc57b6e4 308 huart->State = HAL_UART_STATE_BUSY;
mbed_official 381:5460fc57b6e4 309
mbed_official 381:5460fc57b6e4 310 /* Disable the Peripheral */
mbed_official 381:5460fc57b6e4 311 __HAL_UART_DISABLE(huart);
mbed_official 381:5460fc57b6e4 312
mbed_official 381:5460fc57b6e4 313 /* Set the wake-up selection scheme */
mbed_official 381:5460fc57b6e4 314 MODIFY_REG(huart->Instance->CR3, USART_CR3_WUS, WakeUpSelection.WakeUpEvent);
mbed_official 381:5460fc57b6e4 315
mbed_official 381:5460fc57b6e4 316 if (WakeUpSelection.WakeUpEvent == UART_WAKEUP_ON_ADDRESS)
mbed_official 381:5460fc57b6e4 317 {
mbed_official 381:5460fc57b6e4 318 UART_Wakeup_AddressConfig(huart, WakeUpSelection);
mbed_official 381:5460fc57b6e4 319 }
mbed_official 381:5460fc57b6e4 320
mbed_official 381:5460fc57b6e4 321 /* Enable the Peripheral */
mbed_official 381:5460fc57b6e4 322 __HAL_UART_ENABLE(huart);
mbed_official 381:5460fc57b6e4 323
mbed_official 381:5460fc57b6e4 324 /* Wait until REACK flag is set */
mbed_official 381:5460fc57b6e4 325 if(UART_WaitOnFlagUntilTimeout(huart, USART_ISR_REACK, RESET, HAL_UART_TIMEOUT_VALUE) != HAL_OK)
mbed_official 381:5460fc57b6e4 326 {
mbed_official 381:5460fc57b6e4 327 return HAL_TIMEOUT;
mbed_official 381:5460fc57b6e4 328 }
mbed_official 381:5460fc57b6e4 329 else
mbed_official 381:5460fc57b6e4 330 {
mbed_official 381:5460fc57b6e4 331 /* Initialize the UART State */
mbed_official 381:5460fc57b6e4 332 huart->State= HAL_UART_STATE_READY;
mbed_official 381:5460fc57b6e4 333 /* Process Unlocked */
mbed_official 381:5460fc57b6e4 334 __HAL_UNLOCK(huart);
mbed_official 381:5460fc57b6e4 335 return HAL_OK;
mbed_official 381:5460fc57b6e4 336 }
mbed_official 381:5460fc57b6e4 337 }
mbed_official 381:5460fc57b6e4 338
mbed_official 381:5460fc57b6e4 339
mbed_official 381:5460fc57b6e4 340 /**
mbed_official 381:5460fc57b6e4 341 * @brief Enable UART Stop Mode
mbed_official 381:5460fc57b6e4 342 * The UART is able to wake up the MCU from Stop mode as long as UART clock is HSI or LSE
mbed_official 381:5460fc57b6e4 343 * @param huart: uart handle
mbed_official 381:5460fc57b6e4 344 * @retval HAL status
mbed_official 381:5460fc57b6e4 345 */
mbed_official 381:5460fc57b6e4 346 HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart)
mbed_official 381:5460fc57b6e4 347 {
mbed_official 381:5460fc57b6e4 348 /* Process Locked */
mbed_official 381:5460fc57b6e4 349 __HAL_LOCK(huart);
mbed_official 381:5460fc57b6e4 350
mbed_official 381:5460fc57b6e4 351 huart->State = HAL_UART_STATE_BUSY;
mbed_official 381:5460fc57b6e4 352
mbed_official 381:5460fc57b6e4 353 /* Set the USART UESM bit */
mbed_official 381:5460fc57b6e4 354 huart->Instance->CR1 |= USART_CR1_UESM;
mbed_official 381:5460fc57b6e4 355
mbed_official 381:5460fc57b6e4 356 huart->State = HAL_UART_STATE_READY;
mbed_official 381:5460fc57b6e4 357
mbed_official 381:5460fc57b6e4 358 /* Process Unlocked */
mbed_official 381:5460fc57b6e4 359 __HAL_UNLOCK(huart);
mbed_official 381:5460fc57b6e4 360
mbed_official 381:5460fc57b6e4 361 return HAL_OK;
mbed_official 381:5460fc57b6e4 362 }
mbed_official 381:5460fc57b6e4 363
mbed_official 381:5460fc57b6e4 364 /**
mbed_official 381:5460fc57b6e4 365 * @brief Disable UART Stop Mode
mbed_official 381:5460fc57b6e4 366 * @param huart: uart handle
mbed_official 381:5460fc57b6e4 367 * @retval HAL status
mbed_official 381:5460fc57b6e4 368 */
mbed_official 381:5460fc57b6e4 369 HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart)
mbed_official 381:5460fc57b6e4 370 {
mbed_official 381:5460fc57b6e4 371 /* Process Locked */
mbed_official 381:5460fc57b6e4 372 __HAL_LOCK(huart);
mbed_official 381:5460fc57b6e4 373
mbed_official 381:5460fc57b6e4 374 huart->State = HAL_UART_STATE_BUSY;
mbed_official 381:5460fc57b6e4 375
mbed_official 381:5460fc57b6e4 376 /* Clear USART UESM bit */
mbed_official 381:5460fc57b6e4 377 huart->Instance->CR1 &= ~(USART_CR1_UESM);
mbed_official 381:5460fc57b6e4 378
mbed_official 381:5460fc57b6e4 379 huart->State = HAL_UART_STATE_READY;
mbed_official 381:5460fc57b6e4 380
mbed_official 381:5460fc57b6e4 381 /* Process Unlocked */
mbed_official 381:5460fc57b6e4 382 __HAL_UNLOCK(huart);
mbed_official 381:5460fc57b6e4 383
mbed_official 381:5460fc57b6e4 384 return HAL_OK;
mbed_official 381:5460fc57b6e4 385 }
mbed_official 381:5460fc57b6e4 386
mbed_official 381:5460fc57b6e4 387
mbed_official 381:5460fc57b6e4 388 /**
mbed_official 381:5460fc57b6e4 389 * @}
mbed_official 381:5460fc57b6e4 390 */
mbed_official 381:5460fc57b6e4 391
mbed_official 381:5460fc57b6e4 392 /**
mbed_official 381:5460fc57b6e4 393 * @}
mbed_official 381:5460fc57b6e4 394 */
mbed_official 381:5460fc57b6e4 395
mbed_official 381:5460fc57b6e4 396 #endif /* HAL_UART_MODULE_ENABLED */
mbed_official 381:5460fc57b6e4 397 /**
mbed_official 381:5460fc57b6e4 398 * @}
mbed_official 381:5460fc57b6e4 399 */
mbed_official 381:5460fc57b6e4 400
mbed_official 381:5460fc57b6e4 401 /**
mbed_official 381:5460fc57b6e4 402 * @}
mbed_official 381:5460fc57b6e4 403 */
mbed_official 381:5460fc57b6e4 404
mbed_official 381:5460fc57b6e4 405 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/