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