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