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