mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

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

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

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

Import librarymbed

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

Committer:
mbed_official
Date:
Mon Sep 28 20:15:09 2015 +0100
Revision:
634:ac7d6880524d
Parent:
632:7687fb9c4f91
Synchronized with git revision 9b7d23d47153c298a6d24de9a415202705889d11

Full URL: https://github.com/mbedmicro/mbed/commit/9b7d23d47153c298a6d24de9a415202705889d11/

Revert "[NUCLEO_F303K8] add support of the STM32F303K8"

Who changed what in which revision?

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