mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F072RB/stm32f0xx_hal_uart_ex.c@218:44081b78fdc2, 2014-05-30 (annotated)
- Committer:
- mbed_official
- Date:
- Fri May 30 15:30:09 2014 +0100
- Revision:
- 218:44081b78fdc2
- Parent:
- 205:c41fc65bcfb4
Synchronized with git revision d854859072d318241476ccc5f335965444d4c1d8
Full URL: https://github.com/mbedmicro/mbed/commit/d854859072d318241476ccc5f335965444d4c1d8/
[NUCLEO_F072RB] Update CubeF0 HAL driver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 205:c41fc65bcfb4 | 1 | /** |
mbed_official | 205:c41fc65bcfb4 | 2 | ****************************************************************************** |
mbed_official | 205:c41fc65bcfb4 | 3 | * @file stm32f0xx_hal_uart_ex.c |
mbed_official | 205:c41fc65bcfb4 | 4 | * @author MCD Application Team |
mbed_official | 205:c41fc65bcfb4 | 5 | * @version V1.0.0 |
mbed_official | 218:44081b78fdc2 | 6 | * @date 28-May-2014 |
mbed_official | 205:c41fc65bcfb4 | 7 | * @brief Extended UART HAL module driver. |
mbed_official | 205:c41fc65bcfb4 | 8 | * |
mbed_official | 205:c41fc65bcfb4 | 9 | * This file provides firmware functions to manage the following extended |
mbed_official | 205:c41fc65bcfb4 | 10 | * functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART). |
mbed_official | 205:c41fc65bcfb4 | 11 | * + Initialization and de-initialization functions |
mbed_official | 205:c41fc65bcfb4 | 12 | * + Peripheral Control functions |
mbed_official | 205:c41fc65bcfb4 | 13 | * |
mbed_official | 205:c41fc65bcfb4 | 14 | * |
mbed_official | 205:c41fc65bcfb4 | 15 | @verbatim |
mbed_official | 205:c41fc65bcfb4 | 16 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 17 | ##### How to use this driver ##### |
mbed_official | 205:c41fc65bcfb4 | 18 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 19 | [..] |
mbed_official | 205:c41fc65bcfb4 | 20 | The UART HAL driver can be used as follows: |
mbed_official | 205:c41fc65bcfb4 | 21 | |
mbed_official | 205:c41fc65bcfb4 | 22 | (#) Declare a UART_HandleTypeDef handle structure. |
mbed_official | 205:c41fc65bcfb4 | 23 | |
mbed_official | 205:c41fc65bcfb4 | 24 | (#) For the UART RS485 Driver Enabled mode, initialize the UART registers |
mbed_official | 205:c41fc65bcfb4 | 25 | by calling the HAL_RS485Ex_Init() API. |
mbed_official | 205:c41fc65bcfb4 | 26 | |
mbed_official | 205:c41fc65bcfb4 | 27 | |
mbed_official | 205:c41fc65bcfb4 | 28 | @endverbatim |
mbed_official | 205:c41fc65bcfb4 | 29 | ****************************************************************************** |
mbed_official | 205:c41fc65bcfb4 | 30 | * @attention |
mbed_official | 205:c41fc65bcfb4 | 31 | * |
mbed_official | 205:c41fc65bcfb4 | 32 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 205:c41fc65bcfb4 | 33 | * |
mbed_official | 205:c41fc65bcfb4 | 34 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 205:c41fc65bcfb4 | 35 | * are permitted provided that the following conditions are met: |
mbed_official | 205:c41fc65bcfb4 | 36 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 205:c41fc65bcfb4 | 37 | * this list of conditions and the following disclaimer. |
mbed_official | 205:c41fc65bcfb4 | 38 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 205:c41fc65bcfb4 | 39 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 205:c41fc65bcfb4 | 40 | * and/or other materials provided with the distribution. |
mbed_official | 205:c41fc65bcfb4 | 41 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 205:c41fc65bcfb4 | 42 | * may be used to endorse or promote products derived from this software |
mbed_official | 205:c41fc65bcfb4 | 43 | * without specific prior written permission. |
mbed_official | 205:c41fc65bcfb4 | 44 | * |
mbed_official | 205:c41fc65bcfb4 | 45 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 205:c41fc65bcfb4 | 46 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 205:c41fc65bcfb4 | 47 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 205:c41fc65bcfb4 | 48 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 205:c41fc65bcfb4 | 49 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 205:c41fc65bcfb4 | 50 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 205:c41fc65bcfb4 | 51 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 205:c41fc65bcfb4 | 52 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 205:c41fc65bcfb4 | 53 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 205:c41fc65bcfb4 | 54 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 205:c41fc65bcfb4 | 55 | * |
mbed_official | 205:c41fc65bcfb4 | 56 | ****************************************************************************** |
mbed_official | 205:c41fc65bcfb4 | 57 | */ |
mbed_official | 205:c41fc65bcfb4 | 58 | |
mbed_official | 205:c41fc65bcfb4 | 59 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 60 | #include "stm32f0xx_hal.h" |
mbed_official | 205:c41fc65bcfb4 | 61 | |
mbed_official | 205:c41fc65bcfb4 | 62 | /** @addtogroup STM32F0xx_HAL_Driver |
mbed_official | 205:c41fc65bcfb4 | 63 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 64 | */ |
mbed_official | 205:c41fc65bcfb4 | 65 | |
mbed_official | 205:c41fc65bcfb4 | 66 | #ifdef HAL_UART_MODULE_ENABLED |
mbed_official | 205:c41fc65bcfb4 | 67 | |
mbed_official | 205:c41fc65bcfb4 | 68 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 69 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 70 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 71 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 72 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 73 | #if !defined(STM32F030x6) && !defined(STM32F030x8) |
mbed_official | 205:c41fc65bcfb4 | 74 | static void UART_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection); |
mbed_official | 205:c41fc65bcfb4 | 75 | #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) */ |
mbed_official | 205:c41fc65bcfb4 | 76 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 77 | |
mbed_official | 205:c41fc65bcfb4 | 78 | /** @addtogroup UART |
mbed_official | 205:c41fc65bcfb4 | 79 | * @brief UART HAL module driver |
mbed_official | 205:c41fc65bcfb4 | 80 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 81 | */ |
mbed_official | 205:c41fc65bcfb4 | 82 | |
mbed_official | 205:c41fc65bcfb4 | 83 | /** @addtogroup UART_Private_Functions |
mbed_official | 205:c41fc65bcfb4 | 84 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 85 | */ |
mbed_official | 205:c41fc65bcfb4 | 86 | |
mbed_official | 205:c41fc65bcfb4 | 87 | /** @defgroup UART_Group4 Extended IO operation function |
mbed_official | 205:c41fc65bcfb4 | 88 | * @brief UART Interrupt handling function |
mbed_official | 205:c41fc65bcfb4 | 89 | * |
mbed_official | 205:c41fc65bcfb4 | 90 | @verbatim |
mbed_official | 205:c41fc65bcfb4 | 91 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 92 | ##### I/O operation function ##### |
mbed_official | 205:c41fc65bcfb4 | 93 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 94 | This subsection provides functions allowing to manage the UART interrupts |
mbed_official | 205:c41fc65bcfb4 | 95 | and to handle Wake up interrupt call-back. |
mbed_official | 205:c41fc65bcfb4 | 96 | |
mbed_official | 205:c41fc65bcfb4 | 97 | (#) Non-Blocking mode API with Interrupt is : |
mbed_official | 205:c41fc65bcfb4 | 98 | (+) HAL_UART_IRQHandler() |
mbed_official | 205:c41fc65bcfb4 | 99 | |
mbed_official | 205:c41fc65bcfb4 | 100 | (#) Callback provided in No_Blocking mode: |
mbed_official | 205:c41fc65bcfb4 | 101 | (+) HAL_UART_WakeupCallback() |
mbed_official | 205:c41fc65bcfb4 | 102 | |
mbed_official | 205:c41fc65bcfb4 | 103 | |
mbed_official | 205:c41fc65bcfb4 | 104 | @endverbatim |
mbed_official | 205:c41fc65bcfb4 | 105 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 106 | */ |
mbed_official | 205:c41fc65bcfb4 | 107 | |
mbed_official | 205:c41fc65bcfb4 | 108 | |
mbed_official | 205:c41fc65bcfb4 | 109 | /** |
mbed_official | 205:c41fc65bcfb4 | 110 | * @brief This function handles UART interrupt request. |
mbed_official | 205:c41fc65bcfb4 | 111 | * @param huart: uart handle |
mbed_official | 205:c41fc65bcfb4 | 112 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 113 | */ |
mbed_official | 205:c41fc65bcfb4 | 114 | void HAL_UART_IRQHandler(UART_HandleTypeDef *huart) |
mbed_official | 205:c41fc65bcfb4 | 115 | { |
mbed_official | 205:c41fc65bcfb4 | 116 | /* UART parity error interrupt occurred -------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 117 | if((__HAL_UART_GET_IT(huart, UART_IT_PE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_PE) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 118 | { |
mbed_official | 205:c41fc65bcfb4 | 119 | __HAL_UART_CLEAR_IT(huart, UART_CLEAR_PEF); |
mbed_official | 205:c41fc65bcfb4 | 120 | |
mbed_official | 205:c41fc65bcfb4 | 121 | huart->ErrorCode |= HAL_UART_ERROR_PE; |
mbed_official | 205:c41fc65bcfb4 | 122 | /* Set the UART state ready to be able to start again the process */ |
mbed_official | 205:c41fc65bcfb4 | 123 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 124 | } |
mbed_official | 205:c41fc65bcfb4 | 125 | |
mbed_official | 205:c41fc65bcfb4 | 126 | /* UART frame error interrupt occured --------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 127 | if((__HAL_UART_GET_IT(huart, UART_IT_FE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 128 | { |
mbed_official | 205:c41fc65bcfb4 | 129 | __HAL_UART_CLEAR_IT(huart, UART_CLEAR_FEF); |
mbed_official | 205:c41fc65bcfb4 | 130 | |
mbed_official | 205:c41fc65bcfb4 | 131 | huart->ErrorCode |= HAL_UART_ERROR_FE; |
mbed_official | 205:c41fc65bcfb4 | 132 | /* Set the UART state ready to be able to start again the process */ |
mbed_official | 205:c41fc65bcfb4 | 133 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 134 | } |
mbed_official | 205:c41fc65bcfb4 | 135 | |
mbed_official | 205:c41fc65bcfb4 | 136 | /* UART noise error interrupt occured --------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 137 | if((__HAL_UART_GET_IT(huart, UART_IT_NE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 138 | { |
mbed_official | 205:c41fc65bcfb4 | 139 | __HAL_UART_CLEAR_IT(huart, UART_CLEAR_NEF); |
mbed_official | 205:c41fc65bcfb4 | 140 | |
mbed_official | 205:c41fc65bcfb4 | 141 | huart->ErrorCode |= HAL_UART_ERROR_NE; |
mbed_official | 205:c41fc65bcfb4 | 142 | /* Set the UART state ready to be able to start again the process */ |
mbed_official | 205:c41fc65bcfb4 | 143 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 144 | } |
mbed_official | 205:c41fc65bcfb4 | 145 | |
mbed_official | 205:c41fc65bcfb4 | 146 | /* UART Over-Run interrupt occured -----------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 147 | if((__HAL_UART_GET_IT(huart, UART_IT_ORE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 148 | { |
mbed_official | 205:c41fc65bcfb4 | 149 | __HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF); |
mbed_official | 205:c41fc65bcfb4 | 150 | |
mbed_official | 205:c41fc65bcfb4 | 151 | huart->ErrorCode |= HAL_UART_ERROR_ORE; |
mbed_official | 205:c41fc65bcfb4 | 152 | /* Set the UART state ready to be able to start again the process */ |
mbed_official | 205:c41fc65bcfb4 | 153 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 154 | } |
mbed_official | 205:c41fc65bcfb4 | 155 | |
mbed_official | 205:c41fc65bcfb4 | 156 | /* Call UART Error Call back function if need be --------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 157 | if(huart->ErrorCode != HAL_UART_ERROR_NONE) |
mbed_official | 205:c41fc65bcfb4 | 158 | { |
mbed_official | 205:c41fc65bcfb4 | 159 | HAL_UART_ErrorCallback(huart); |
mbed_official | 205:c41fc65bcfb4 | 160 | } |
mbed_official | 205:c41fc65bcfb4 | 161 | |
mbed_official | 205:c41fc65bcfb4 | 162 | #if !defined(STM32F030x6) && !defined(STM32F030x8) |
mbed_official | 205:c41fc65bcfb4 | 163 | /* UART wakeup from Stop mode interrupt occurred -------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 164 | if((__HAL_UART_GET_IT(huart, UART_IT_WUF) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_WUF) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 165 | { |
mbed_official | 205:c41fc65bcfb4 | 166 | __HAL_UART_CLEAR_IT(huart, UART_CLEAR_WUF); |
mbed_official | 205:c41fc65bcfb4 | 167 | /* Set the UART state ready to be able to start again the process */ |
mbed_official | 205:c41fc65bcfb4 | 168 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 169 | HAL_UART_WakeupCallback(huart); |
mbed_official | 205:c41fc65bcfb4 | 170 | } |
mbed_official | 205:c41fc65bcfb4 | 171 | #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) */ |
mbed_official | 205:c41fc65bcfb4 | 172 | |
mbed_official | 205:c41fc65bcfb4 | 173 | /* UART in mode Receiver ---------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 174 | if((__HAL_UART_GET_IT(huart, UART_IT_RXNE) != RESET) && (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 175 | { |
mbed_official | 205:c41fc65bcfb4 | 176 | UART_Receive_IT(huart); |
mbed_official | 205:c41fc65bcfb4 | 177 | /* Clear RXNE interrupt flag */ |
mbed_official | 205:c41fc65bcfb4 | 178 | __HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST); |
mbed_official | 205:c41fc65bcfb4 | 179 | } |
mbed_official | 205:c41fc65bcfb4 | 180 | |
mbed_official | 205:c41fc65bcfb4 | 181 | |
mbed_official | 205:c41fc65bcfb4 | 182 | /* UART in mode Transmitter ------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 183 | if((__HAL_UART_GET_IT(huart, UART_IT_TC) != RESET) &&(__HAL_UART_GET_IT_SOURCE(huart, UART_IT_TC) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 184 | { |
mbed_official | 205:c41fc65bcfb4 | 185 | UART_Transmit_IT(huart); |
mbed_official | 205:c41fc65bcfb4 | 186 | } |
mbed_official | 205:c41fc65bcfb4 | 187 | |
mbed_official | 205:c41fc65bcfb4 | 188 | } |
mbed_official | 205:c41fc65bcfb4 | 189 | |
mbed_official | 205:c41fc65bcfb4 | 190 | #if !defined(STM32F030x6) && !defined(STM32F030x8) |
mbed_official | 205:c41fc65bcfb4 | 191 | /** |
mbed_official | 205:c41fc65bcfb4 | 192 | * @brief UART wakeup from Stop mode callback |
mbed_official | 205:c41fc65bcfb4 | 193 | * @param huart: uart handle |
mbed_official | 205:c41fc65bcfb4 | 194 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 195 | */ |
mbed_official | 205:c41fc65bcfb4 | 196 | __weak void HAL_UART_WakeupCallback(UART_HandleTypeDef *huart) |
mbed_official | 205:c41fc65bcfb4 | 197 | { |
mbed_official | 205:c41fc65bcfb4 | 198 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 205:c41fc65bcfb4 | 199 | the HAL_UART_WakeupCallback can be implemented in the user file |
mbed_official | 205:c41fc65bcfb4 | 200 | */ |
mbed_official | 205:c41fc65bcfb4 | 201 | } |
mbed_official | 205:c41fc65bcfb4 | 202 | #endif /*!defined(STM32F030x6) && !defined(STM32F030x8)*/ |
mbed_official | 205:c41fc65bcfb4 | 203 | |
mbed_official | 205:c41fc65bcfb4 | 204 | /** |
mbed_official | 205:c41fc65bcfb4 | 205 | * @} |
mbed_official | 205:c41fc65bcfb4 | 206 | */ |
mbed_official | 205:c41fc65bcfb4 | 207 | |
mbed_official | 205:c41fc65bcfb4 | 208 | /** |
mbed_official | 205:c41fc65bcfb4 | 209 | * @} |
mbed_official | 205:c41fc65bcfb4 | 210 | */ |
mbed_official | 205:c41fc65bcfb4 | 211 | |
mbed_official | 205:c41fc65bcfb4 | 212 | /** |
mbed_official | 205:c41fc65bcfb4 | 213 | * @} |
mbed_official | 205:c41fc65bcfb4 | 214 | */ |
mbed_official | 205:c41fc65bcfb4 | 215 | |
mbed_official | 205:c41fc65bcfb4 | 216 | /** @defgroup UARTEx |
mbed_official | 205:c41fc65bcfb4 | 217 | * @brief UART Extended HAL module driver |
mbed_official | 205:c41fc65bcfb4 | 218 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 219 | */ |
mbed_official | 205:c41fc65bcfb4 | 220 | |
mbed_official | 205:c41fc65bcfb4 | 221 | /** @defgroup UARTEx_Private_Functions |
mbed_official | 205:c41fc65bcfb4 | 222 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 223 | */ |
mbed_official | 205:c41fc65bcfb4 | 224 | |
mbed_official | 205:c41fc65bcfb4 | 225 | /** @defgroup UARTEx_Group1 Extended Initialization/de-initialization functions |
mbed_official | 205:c41fc65bcfb4 | 226 | * @brief Extended Initialization and Configuration Functions |
mbed_official | 205:c41fc65bcfb4 | 227 | * |
mbed_official | 205:c41fc65bcfb4 | 228 | @verbatim |
mbed_official | 205:c41fc65bcfb4 | 229 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 230 | ##### Initialization and Configuration functions ##### |
mbed_official | 205:c41fc65bcfb4 | 231 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 232 | [..] |
mbed_official | 205:c41fc65bcfb4 | 233 | This subsection provides a set of functions allowing to initialize the USARTx or the UARTy |
mbed_official | 205:c41fc65bcfb4 | 234 | in asynchronous mode. |
mbed_official | 205:c41fc65bcfb4 | 235 | (+) For the asynchronous mode only these parameters can be configured: |
mbed_official | 205:c41fc65bcfb4 | 236 | (++) Baud Rate |
mbed_official | 205:c41fc65bcfb4 | 237 | (++) Word Length |
mbed_official | 205:c41fc65bcfb4 | 238 | (++) Stop Bit |
mbed_official | 205:c41fc65bcfb4 | 239 | (++) Parity: If the parity is enabled, then the MSB bit of the data written |
mbed_official | 205:c41fc65bcfb4 | 240 | in the data register is transmitted but is changed by the parity bit. |
mbed_official | 205:c41fc65bcfb4 | 241 | Depending on the frame length defined by the M bit (8-bits or 9-bits), |
mbed_official | 205:c41fc65bcfb4 | 242 | the possible UART frame formats are as listed in the following table: |
mbed_official | 205:c41fc65bcfb4 | 243 | |-----------|-----------|---------------------------------------| |
mbed_official | 205:c41fc65bcfb4 | 244 | | M1M0 bits | PCE bit | UART frame | |
mbed_official | 205:c41fc65bcfb4 | 245 | |-----------------------|---------------------------------------| |
mbed_official | 205:c41fc65bcfb4 | 246 | | 00 | 0 | | SB | 8-bit data | STB | | |
mbed_official | 205:c41fc65bcfb4 | 247 | |-----------|-----------|---------------------------------------| |
mbed_official | 205:c41fc65bcfb4 | 248 | | 00 | 1 | | SB | 7-bit data | PB | STB | | |
mbed_official | 205:c41fc65bcfb4 | 249 | |-----------|-----------|---------------------------------------| |
mbed_official | 205:c41fc65bcfb4 | 250 | | 01 | 0 | | SB | 9-bit data | STB | | |
mbed_official | 205:c41fc65bcfb4 | 251 | |-----------|-----------|---------------------------------------| |
mbed_official | 205:c41fc65bcfb4 | 252 | | 01 | 1 | | SB | 8-bit data | PB | STB | | |
mbed_official | 205:c41fc65bcfb4 | 253 | +---------------------------------------------------------------+ |
mbed_official | 205:c41fc65bcfb4 | 254 | | 10 | 0 | | SB | 7-bit data | STB | | |
mbed_official | 205:c41fc65bcfb4 | 255 | |-----------|-----------|---------------------------------------| |
mbed_official | 205:c41fc65bcfb4 | 256 | | 10 | 1 | | SB | 6-bit data | PB | STB | | |
mbed_official | 205:c41fc65bcfb4 | 257 | +---------------------------------------------------------------+ |
mbed_official | 205:c41fc65bcfb4 | 258 | (++) Hardware flow control |
mbed_official | 205:c41fc65bcfb4 | 259 | (++) Receiver/transmitter modes |
mbed_official | 205:c41fc65bcfb4 | 260 | (++) Over Sampling Method |
mbed_official | 205:c41fc65bcfb4 | 261 | (++) One-Bit Sampling Method |
mbed_official | 205:c41fc65bcfb4 | 262 | (+) For the asynchronous mode, the following advanced features can be configured as well: |
mbed_official | 205:c41fc65bcfb4 | 263 | (++) TX and/or RX pin level inversion |
mbed_official | 205:c41fc65bcfb4 | 264 | (++) data logical level inversion |
mbed_official | 205:c41fc65bcfb4 | 265 | (++) RX and TX pins swap |
mbed_official | 205:c41fc65bcfb4 | 266 | (++) RX overrun detection disabling |
mbed_official | 205:c41fc65bcfb4 | 267 | (++) DMA disabling on RX error |
mbed_official | 205:c41fc65bcfb4 | 268 | (++) MSB first on communication line |
mbed_official | 205:c41fc65bcfb4 | 269 | (++) auto Baud rate detection |
mbed_official | 205:c41fc65bcfb4 | 270 | [..] |
mbed_official | 205:c41fc65bcfb4 | 271 | The HAL_LIN_Init() and HAL_RS485Ex_Init() APIs follows respectively the LIN and |
mbed_official | 205:c41fc65bcfb4 | 272 | the UART RS485 mode configuration procedures (details for the procedures are |
mbed_official | 205:c41fc65bcfb4 | 273 | available in reference manual). |
mbed_official | 205:c41fc65bcfb4 | 274 | |
mbed_official | 205:c41fc65bcfb4 | 275 | @endverbatim |
mbed_official | 205:c41fc65bcfb4 | 276 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 277 | */ |
mbed_official | 205:c41fc65bcfb4 | 278 | |
mbed_official | 205:c41fc65bcfb4 | 279 | |
mbed_official | 205:c41fc65bcfb4 | 280 | /** |
mbed_official | 205:c41fc65bcfb4 | 281 | * @brief Initializes the RS485 Driver enable feature according to the specified |
mbed_official | 205:c41fc65bcfb4 | 282 | * parameters in the UART_InitTypeDef and creates the associated handle . |
mbed_official | 205:c41fc65bcfb4 | 283 | * @param huart: uart handle |
mbed_official | 205:c41fc65bcfb4 | 284 | * @param UART_DEPolarity: select the driver enable polarity |
mbed_official | 205:c41fc65bcfb4 | 285 | * This parameter can be one of the following values: |
mbed_official | 205:c41fc65bcfb4 | 286 | * @arg UART_DE_POLARITY_HIGH: DE signal is active high |
mbed_official | 205:c41fc65bcfb4 | 287 | * @arg UART_DE_POLARITY_LOW: DE signal is active low |
mbed_official | 205:c41fc65bcfb4 | 288 | * @param UART_DEAssertionTime: Driver Enable assertion time |
mbed_official | 205:c41fc65bcfb4 | 289 | * 5-bit value defining the time between the activation of the DE (Driver Enable) |
mbed_official | 205:c41fc65bcfb4 | 290 | * signal and the beginning of the start bit. It is expressed in sample time |
mbed_official | 205:c41fc65bcfb4 | 291 | * units (1/8 or 1/16 bit time, depending on the oversampling rate) |
mbed_official | 205:c41fc65bcfb4 | 292 | * @param UART_DEDeassertionTime: Driver Enable deassertion time |
mbed_official | 205:c41fc65bcfb4 | 293 | * 5-bit value defining the time between the end of the last stop bit, in a |
mbed_official | 205:c41fc65bcfb4 | 294 | * transmitted message, and the de-activation of the DE (Driver Enable) signal. |
mbed_official | 205:c41fc65bcfb4 | 295 | * It is expressed in sample time units (1/8 or 1/16 bit time, depending on the |
mbed_official | 205:c41fc65bcfb4 | 296 | * oversampling rate). |
mbed_official | 205:c41fc65bcfb4 | 297 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 298 | */ |
mbed_official | 205:c41fc65bcfb4 | 299 | HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t UART_DEPolarity, uint32_t UART_DEAssertionTime, uint32_t UART_DEDeassertionTime) |
mbed_official | 205:c41fc65bcfb4 | 300 | { |
mbed_official | 205:c41fc65bcfb4 | 301 | uint32_t temp = 0x0; |
mbed_official | 205:c41fc65bcfb4 | 302 | |
mbed_official | 205:c41fc65bcfb4 | 303 | /* Check the UART handle allocation */ |
mbed_official | 205:c41fc65bcfb4 | 304 | if(huart == NULL) |
mbed_official | 205:c41fc65bcfb4 | 305 | { |
mbed_official | 205:c41fc65bcfb4 | 306 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 307 | } |
mbed_official | 205:c41fc65bcfb4 | 308 | /* Check the Driver Enable UART instance */ |
mbed_official | 205:c41fc65bcfb4 | 309 | assert_param(IS_UART_DRIVER_ENABLE_INSTANCE(huart->Instance)); |
mbed_official | 205:c41fc65bcfb4 | 310 | |
mbed_official | 205:c41fc65bcfb4 | 311 | /* Check the Driver Enable polarity */ |
mbed_official | 205:c41fc65bcfb4 | 312 | assert_param(IS_UART_DE_POLARITY(UART_DEPolarity)); |
mbed_official | 205:c41fc65bcfb4 | 313 | |
mbed_official | 205:c41fc65bcfb4 | 314 | /* Check the Driver Enable assertion time */ |
mbed_official | 205:c41fc65bcfb4 | 315 | assert_param(IS_UART_ASSERTIONTIME(UART_DEAssertionTime)); |
mbed_official | 205:c41fc65bcfb4 | 316 | |
mbed_official | 205:c41fc65bcfb4 | 317 | /* Check the Driver Enable deassertion time */ |
mbed_official | 205:c41fc65bcfb4 | 318 | assert_param(IS_UART_DEASSERTIONTIME(UART_DEDeassertionTime)); |
mbed_official | 205:c41fc65bcfb4 | 319 | |
mbed_official | 205:c41fc65bcfb4 | 320 | if(huart->State == HAL_UART_STATE_RESET) |
mbed_official | 205:c41fc65bcfb4 | 321 | { |
mbed_official | 205:c41fc65bcfb4 | 322 | /* Init the low level hardware : GPIO, CLOCK */ |
mbed_official | 205:c41fc65bcfb4 | 323 | HAL_UART_MspInit(huart); |
mbed_official | 205:c41fc65bcfb4 | 324 | } |
mbed_official | 205:c41fc65bcfb4 | 325 | |
mbed_official | 205:c41fc65bcfb4 | 326 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 327 | |
mbed_official | 205:c41fc65bcfb4 | 328 | /* Disable the Peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 329 | __HAL_UART_DISABLE(huart); |
mbed_official | 205:c41fc65bcfb4 | 330 | |
mbed_official | 205:c41fc65bcfb4 | 331 | /* Set the UART Communication parameters */ |
mbed_official | 205:c41fc65bcfb4 | 332 | if (UART_SetConfig(huart) == HAL_ERROR) |
mbed_official | 205:c41fc65bcfb4 | 333 | { |
mbed_official | 205:c41fc65bcfb4 | 334 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 335 | } |
mbed_official | 205:c41fc65bcfb4 | 336 | |
mbed_official | 205:c41fc65bcfb4 | 337 | if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT) |
mbed_official | 205:c41fc65bcfb4 | 338 | { |
mbed_official | 205:c41fc65bcfb4 | 339 | UART_AdvFeatureConfig(huart); |
mbed_official | 205:c41fc65bcfb4 | 340 | } |
mbed_official | 205:c41fc65bcfb4 | 341 | |
mbed_official | 205:c41fc65bcfb4 | 342 | /* Enable the Driver Enable mode by setting the DEM bit in the CR3 register */ |
mbed_official | 205:c41fc65bcfb4 | 343 | huart->Instance->CR3 |= USART_CR3_DEM; |
mbed_official | 205:c41fc65bcfb4 | 344 | |
mbed_official | 205:c41fc65bcfb4 | 345 | /* Set the Driver Enable polarity */ |
mbed_official | 205:c41fc65bcfb4 | 346 | MODIFY_REG(huart->Instance->CR3, USART_CR3_DEP, UART_DEPolarity); |
mbed_official | 205:c41fc65bcfb4 | 347 | |
mbed_official | 205:c41fc65bcfb4 | 348 | /* Set the Driver Enable assertion and deassertion times */ |
mbed_official | 205:c41fc65bcfb4 | 349 | temp = (UART_DEAssertionTime << UART_CR1_DEAT_ADDRESS_LSB_POS); |
mbed_official | 205:c41fc65bcfb4 | 350 | temp |= (UART_DEDeassertionTime << UART_CR1_DEDT_ADDRESS_LSB_POS); |
mbed_official | 205:c41fc65bcfb4 | 351 | MODIFY_REG(huart->Instance->CR1, (USART_CR1_DEDT|USART_CR1_DEAT), temp); |
mbed_official | 205:c41fc65bcfb4 | 352 | |
mbed_official | 205:c41fc65bcfb4 | 353 | /* Enable the Peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 354 | __HAL_UART_ENABLE(huart); |
mbed_official | 205:c41fc65bcfb4 | 355 | |
mbed_official | 205:c41fc65bcfb4 | 356 | /* TEACK and/or REACK to check before moving huart->State to Ready */ |
mbed_official | 205:c41fc65bcfb4 | 357 | return (UART_CheckIdleState(huart)); |
mbed_official | 205:c41fc65bcfb4 | 358 | } |
mbed_official | 205:c41fc65bcfb4 | 359 | |
mbed_official | 205:c41fc65bcfb4 | 360 | |
mbed_official | 205:c41fc65bcfb4 | 361 | #if !defined(STM32F030x6) && !defined(STM32F030x8) |
mbed_official | 205:c41fc65bcfb4 | 362 | /** |
mbed_official | 205:c41fc65bcfb4 | 363 | * @brief Initializes the LIN mode according to the specified |
mbed_official | 205:c41fc65bcfb4 | 364 | * parameters in the UART_InitTypeDef and creates the associated handle . |
mbed_official | 205:c41fc65bcfb4 | 365 | * @param huart: uart handle |
mbed_official | 205:c41fc65bcfb4 | 366 | * @param BreakDetectLength: specifies the LIN break detection length. |
mbed_official | 205:c41fc65bcfb4 | 367 | * This parameter can be one of the following values: |
mbed_official | 205:c41fc65bcfb4 | 368 | * @arg UART_LINBREAKDETECTLENGTH_10B: 10-bit break detection |
mbed_official | 205:c41fc65bcfb4 | 369 | * @arg UART_LINBREAKDETECTLENGTH_11B: 11-bit break detection |
mbed_official | 205:c41fc65bcfb4 | 370 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 371 | */ |
mbed_official | 205:c41fc65bcfb4 | 372 | HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint16_t BreakDetectLength) |
mbed_official | 205:c41fc65bcfb4 | 373 | { |
mbed_official | 205:c41fc65bcfb4 | 374 | /* Check the UART handle allocation */ |
mbed_official | 205:c41fc65bcfb4 | 375 | if(huart == NULL) |
mbed_official | 205:c41fc65bcfb4 | 376 | { |
mbed_official | 205:c41fc65bcfb4 | 377 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 378 | } |
mbed_official | 205:c41fc65bcfb4 | 379 | /* Check the Break detection length parameter */ |
mbed_official | 205:c41fc65bcfb4 | 380 | assert_param(IS_UART_LIN_BREAK_DETECT_LENGTH(BreakDetectLength)); |
mbed_official | 205:c41fc65bcfb4 | 381 | |
mbed_official | 205:c41fc65bcfb4 | 382 | /* LIN mode limited to 16-bit oversampling only */ |
mbed_official | 205:c41fc65bcfb4 | 383 | if(huart->Init.OverSampling == UART_OVERSAMPLING_8) |
mbed_official | 205:c41fc65bcfb4 | 384 | { |
mbed_official | 205:c41fc65bcfb4 | 385 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 386 | } |
mbed_official | 205:c41fc65bcfb4 | 387 | |
mbed_official | 205:c41fc65bcfb4 | 388 | /* Init the low level hardware : GPIO, CLOCK, CORTEX */ |
mbed_official | 205:c41fc65bcfb4 | 389 | HAL_UART_MspInit(huart); |
mbed_official | 205:c41fc65bcfb4 | 390 | |
mbed_official | 205:c41fc65bcfb4 | 391 | /* Disable the Peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 392 | __HAL_UART_DISABLE(huart); |
mbed_official | 205:c41fc65bcfb4 | 393 | |
mbed_official | 205:c41fc65bcfb4 | 394 | /* Set the UART Communication parameters */ |
mbed_official | 205:c41fc65bcfb4 | 395 | if (UART_SetConfig(huart) == HAL_ERROR) |
mbed_official | 205:c41fc65bcfb4 | 396 | { |
mbed_official | 205:c41fc65bcfb4 | 397 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 398 | } |
mbed_official | 205:c41fc65bcfb4 | 399 | |
mbed_official | 205:c41fc65bcfb4 | 400 | if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT) |
mbed_official | 205:c41fc65bcfb4 | 401 | { |
mbed_official | 205:c41fc65bcfb4 | 402 | UART_AdvFeatureConfig(huart); |
mbed_official | 205:c41fc65bcfb4 | 403 | } |
mbed_official | 205:c41fc65bcfb4 | 404 | |
mbed_official | 205:c41fc65bcfb4 | 405 | /* In LIN mode, the following bits must be kept cleared: |
mbed_official | 205:c41fc65bcfb4 | 406 | - LINEN and CLKEN bits in the USART_CR2 register, |
mbed_official | 205:c41fc65bcfb4 | 407 | - SCEN and IREN bits in the USART_CR3 register.*/ |
mbed_official | 205:c41fc65bcfb4 | 408 | huart->Instance->CR2 &= ~(USART_CR2_CLKEN); |
mbed_official | 205:c41fc65bcfb4 | 409 | huart->Instance->CR3 &= ~(USART_CR3_HDSEL | USART_CR3_IREN | USART_CR3_SCEN); |
mbed_official | 205:c41fc65bcfb4 | 410 | |
mbed_official | 205:c41fc65bcfb4 | 411 | /* Enable the LIN mode by setting the LINEN bit in the CR2 register */ |
mbed_official | 205:c41fc65bcfb4 | 412 | huart->Instance->CR2 |= USART_CR2_LINEN; |
mbed_official | 205:c41fc65bcfb4 | 413 | |
mbed_official | 205:c41fc65bcfb4 | 414 | /* Set the USART LIN Break detection length. */ |
mbed_official | 205:c41fc65bcfb4 | 415 | MODIFY_REG(huart->Instance->CR2, USART_CR2_LBDL, BreakDetectLength); |
mbed_official | 205:c41fc65bcfb4 | 416 | |
mbed_official | 205:c41fc65bcfb4 | 417 | /* Enable the Peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 418 | __HAL_UART_ENABLE(huart); |
mbed_official | 205:c41fc65bcfb4 | 419 | |
mbed_official | 205:c41fc65bcfb4 | 420 | /* TEACK and/or REACK to check before moving huart->State to Ready */ |
mbed_official | 205:c41fc65bcfb4 | 421 | return (UART_CheckIdleState(huart)); |
mbed_official | 205:c41fc65bcfb4 | 422 | } |
mbed_official | 205:c41fc65bcfb4 | 423 | #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) */ |
mbed_official | 205:c41fc65bcfb4 | 424 | /** |
mbed_official | 205:c41fc65bcfb4 | 425 | * @} |
mbed_official | 205:c41fc65bcfb4 | 426 | */ |
mbed_official | 205:c41fc65bcfb4 | 427 | |
mbed_official | 205:c41fc65bcfb4 | 428 | /** @defgroup UARTEx_Group3 Extended Peripheral Control functions |
mbed_official | 205:c41fc65bcfb4 | 429 | * @brief Extended Peripheral Control functions |
mbed_official | 205:c41fc65bcfb4 | 430 | * |
mbed_official | 205:c41fc65bcfb4 | 431 | @verbatim |
mbed_official | 205:c41fc65bcfb4 | 432 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 433 | ##### Peripheral Control function ##### |
mbed_official | 205:c41fc65bcfb4 | 434 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 435 | [..] |
mbed_official | 205:c41fc65bcfb4 | 436 | This subsection provides extended functions allowing to control the UART. |
mbed_official | 205:c41fc65bcfb4 | 437 | (+) HAL_MultiProcessorEx_AddressLength_Set() API optionally sets the UART node address |
mbed_official | 205:c41fc65bcfb4 | 438 | detection length to more than 4 bits for multiprocessor address mark wake up. |
mbed_official | 205:c41fc65bcfb4 | 439 | (+) HAL_UART_EnableStopMode() API allows the UART to wake up the MCU from Stop mode as |
mbed_official | 205:c41fc65bcfb4 | 440 | long as UART clock is HSI or LSE |
mbed_official | 205:c41fc65bcfb4 | 441 | (+) HAL_UART_DisableStopMode() API disables the above feature |
mbed_official | 205:c41fc65bcfb4 | 442 | (+) HAL_MultiProcessorEx_AddressLength_Set() API configures the address length when the |
mbed_official | 205:c41fc65bcfb4 | 443 | wake-up event is the address match feature |
mbed_official | 205:c41fc65bcfb4 | 444 | (+) UART_Wakeup_AddressConfig() API sets the reference address used when address |
mbed_official | 205:c41fc65bcfb4 | 445 | match feature is carried out |
mbed_official | 205:c41fc65bcfb4 | 446 | |
mbed_official | 205:c41fc65bcfb4 | 447 | @endverbatim |
mbed_official | 205:c41fc65bcfb4 | 448 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 449 | */ |
mbed_official | 205:c41fc65bcfb4 | 450 | |
mbed_official | 205:c41fc65bcfb4 | 451 | |
mbed_official | 205:c41fc65bcfb4 | 452 | |
mbed_official | 205:c41fc65bcfb4 | 453 | |
mbed_official | 205:c41fc65bcfb4 | 454 | #if !defined(STM32F030x6) && !defined(STM32F030x8) |
mbed_official | 205:c41fc65bcfb4 | 455 | /** |
mbed_official | 205:c41fc65bcfb4 | 456 | * @brief Set Wakeup from Stop mode interrupt flag selection |
mbed_official | 205:c41fc65bcfb4 | 457 | * @param huart: uart handle, |
mbed_official | 205:c41fc65bcfb4 | 458 | * @param WakeUpSelection: address match, Start Bit detection or RXNE bit status. |
mbed_official | 205:c41fc65bcfb4 | 459 | * This parameter can be one of the following values: |
mbed_official | 205:c41fc65bcfb4 | 460 | * @arg UART_WAKEUP_ON_ADDRESS |
mbed_official | 205:c41fc65bcfb4 | 461 | * @arg UART_WAKEUP_ON_STARTBIT |
mbed_official | 205:c41fc65bcfb4 | 462 | * @arg UART_WAKEUP_ON_READDATA_NONEMPTY |
mbed_official | 205:c41fc65bcfb4 | 463 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 464 | */ |
mbed_official | 205:c41fc65bcfb4 | 465 | HAL_StatusTypeDef HAL_UARTEx_StopModeWakeUpSourceConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection) |
mbed_official | 205:c41fc65bcfb4 | 466 | { |
mbed_official | 205:c41fc65bcfb4 | 467 | /* Check the wake-up selection parameter */ |
mbed_official | 205:c41fc65bcfb4 | 468 | assert_param(IS_UART_WAKEUP_SELECTION(WakeUpSelection.WakeUpEvent)); |
mbed_official | 205:c41fc65bcfb4 | 469 | |
mbed_official | 205:c41fc65bcfb4 | 470 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 471 | __HAL_LOCK(huart); |
mbed_official | 205:c41fc65bcfb4 | 472 | |
mbed_official | 205:c41fc65bcfb4 | 473 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 474 | |
mbed_official | 205:c41fc65bcfb4 | 475 | /* Disable the Peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 476 | __HAL_UART_DISABLE(huart); |
mbed_official | 205:c41fc65bcfb4 | 477 | |
mbed_official | 205:c41fc65bcfb4 | 478 | /* Set the wake-up selection scheme */ |
mbed_official | 205:c41fc65bcfb4 | 479 | MODIFY_REG(huart->Instance->CR3, USART_CR3_WUS, WakeUpSelection.WakeUpEvent); |
mbed_official | 205:c41fc65bcfb4 | 480 | |
mbed_official | 205:c41fc65bcfb4 | 481 | if (WakeUpSelection.WakeUpEvent == UART_WAKEUP_ON_ADDRESS) |
mbed_official | 205:c41fc65bcfb4 | 482 | { |
mbed_official | 205:c41fc65bcfb4 | 483 | UART_Wakeup_AddressConfig(huart, WakeUpSelection); |
mbed_official | 205:c41fc65bcfb4 | 484 | } |
mbed_official | 205:c41fc65bcfb4 | 485 | |
mbed_official | 205:c41fc65bcfb4 | 486 | /* Enable the Peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 487 | __HAL_UART_ENABLE(huart); |
mbed_official | 205:c41fc65bcfb4 | 488 | |
mbed_official | 205:c41fc65bcfb4 | 489 | /* Wait until REACK flag is set */ |
mbed_official | 205:c41fc65bcfb4 | 490 | if(UART_WaitOnFlagUntilTimeout(huart, USART_ISR_REACK, RESET, HAL_UART_TIMEOUT_VALUE) != HAL_OK) |
mbed_official | 205:c41fc65bcfb4 | 491 | { |
mbed_official | 205:c41fc65bcfb4 | 492 | return HAL_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 493 | } |
mbed_official | 205:c41fc65bcfb4 | 494 | else |
mbed_official | 205:c41fc65bcfb4 | 495 | { |
mbed_official | 205:c41fc65bcfb4 | 496 | /* Initialize the UART State */ |
mbed_official | 205:c41fc65bcfb4 | 497 | huart->State= HAL_UART_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 498 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 499 | __HAL_UNLOCK(huart); |
mbed_official | 205:c41fc65bcfb4 | 500 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 501 | } |
mbed_official | 205:c41fc65bcfb4 | 502 | } |
mbed_official | 205:c41fc65bcfb4 | 503 | |
mbed_official | 205:c41fc65bcfb4 | 504 | |
mbed_official | 205:c41fc65bcfb4 | 505 | /** |
mbed_official | 205:c41fc65bcfb4 | 506 | * @brief Enable UART Stop Mode |
mbed_official | 205:c41fc65bcfb4 | 507 | * The UART is able to wake up the MCU from Stop mode as long as UART clock is HSI or LSE |
mbed_official | 205:c41fc65bcfb4 | 508 | * @param huart: uart handle |
mbed_official | 205:c41fc65bcfb4 | 509 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 510 | */ |
mbed_official | 205:c41fc65bcfb4 | 511 | HAL_StatusTypeDef HAL_UARTEx_EnableStopMode(UART_HandleTypeDef *huart) |
mbed_official | 205:c41fc65bcfb4 | 512 | { |
mbed_official | 205:c41fc65bcfb4 | 513 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 514 | __HAL_LOCK(huart); |
mbed_official | 205:c41fc65bcfb4 | 515 | |
mbed_official | 205:c41fc65bcfb4 | 516 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 517 | |
mbed_official | 205:c41fc65bcfb4 | 518 | /* Set the USART UESM bit */ |
mbed_official | 205:c41fc65bcfb4 | 519 | huart->Instance->CR1 |= USART_CR1_UESM; |
mbed_official | 205:c41fc65bcfb4 | 520 | |
mbed_official | 205:c41fc65bcfb4 | 521 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 522 | |
mbed_official | 205:c41fc65bcfb4 | 523 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 524 | __HAL_UNLOCK(huart); |
mbed_official | 205:c41fc65bcfb4 | 525 | |
mbed_official | 205:c41fc65bcfb4 | 526 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 527 | } |
mbed_official | 205:c41fc65bcfb4 | 528 | |
mbed_official | 205:c41fc65bcfb4 | 529 | /** |
mbed_official | 205:c41fc65bcfb4 | 530 | * @brief Disable UART Stop Mode |
mbed_official | 205:c41fc65bcfb4 | 531 | * @param huart: uart handle |
mbed_official | 205:c41fc65bcfb4 | 532 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 533 | */ |
mbed_official | 205:c41fc65bcfb4 | 534 | HAL_StatusTypeDef HAL_UARTEx_DisableStopMode(UART_HandleTypeDef *huart) |
mbed_official | 205:c41fc65bcfb4 | 535 | { |
mbed_official | 205:c41fc65bcfb4 | 536 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 537 | __HAL_LOCK(huart); |
mbed_official | 205:c41fc65bcfb4 | 538 | |
mbed_official | 205:c41fc65bcfb4 | 539 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 540 | |
mbed_official | 205:c41fc65bcfb4 | 541 | /* Clear USART UESM bit */ |
mbed_official | 205:c41fc65bcfb4 | 542 | huart->Instance->CR1 &= ~(USART_CR1_UESM); |
mbed_official | 205:c41fc65bcfb4 | 543 | |
mbed_official | 205:c41fc65bcfb4 | 544 | huart->State = HAL_UART_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 545 | |
mbed_official | 205:c41fc65bcfb4 | 546 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 547 | __HAL_UNLOCK(huart); |
mbed_official | 205:c41fc65bcfb4 | 548 | |
mbed_official | 205:c41fc65bcfb4 | 549 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 550 | } |
mbed_official | 205:c41fc65bcfb4 | 551 | |
mbed_official | 205:c41fc65bcfb4 | 552 | #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) */ |
mbed_official | 205:c41fc65bcfb4 | 553 | |
mbed_official | 205:c41fc65bcfb4 | 554 | |
mbed_official | 205:c41fc65bcfb4 | 555 | |
mbed_official | 205:c41fc65bcfb4 | 556 | /** |
mbed_official | 205:c41fc65bcfb4 | 557 | * @brief By default in multiprocessor mode, when the wake up method is set |
mbed_official | 205:c41fc65bcfb4 | 558 | * to address mark, the UART handles only 4-bit long addresses detection. |
mbed_official | 205:c41fc65bcfb4 | 559 | * This API allows to enable longer addresses detection (6-, 7- or 8-bit |
mbed_official | 205:c41fc65bcfb4 | 560 | * long): |
mbed_official | 205:c41fc65bcfb4 | 561 | * - 6-bit address detection in 7-bit data mode |
mbed_official | 205:c41fc65bcfb4 | 562 | * - 7-bit address detection in 8-bit data mode |
mbed_official | 205:c41fc65bcfb4 | 563 | * - 8-bit address detection in 9-bit data mode |
mbed_official | 205:c41fc65bcfb4 | 564 | * @param huart: UART handle |
mbed_official | 205:c41fc65bcfb4 | 565 | * @param AddressLength: this parameter can be one of the following values: |
mbed_official | 205:c41fc65bcfb4 | 566 | * @arg UART_ADDRESS_DETECT_4B: 4-bit long address |
mbed_official | 205:c41fc65bcfb4 | 567 | * @arg UART_ADDRESS_DETECT_7B: 6-, 7- or 8-bit long address |
mbed_official | 205:c41fc65bcfb4 | 568 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 569 | */ |
mbed_official | 205:c41fc65bcfb4 | 570 | HAL_StatusTypeDef HAL_MultiProcessorEx_AddressLength_Set(UART_HandleTypeDef *huart, uint32_t AddressLength) |
mbed_official | 205:c41fc65bcfb4 | 571 | { |
mbed_official | 205:c41fc65bcfb4 | 572 | /* Check the UART handle allocation */ |
mbed_official | 205:c41fc65bcfb4 | 573 | if(huart == NULL) |
mbed_official | 205:c41fc65bcfb4 | 574 | { |
mbed_official | 205:c41fc65bcfb4 | 575 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 576 | } |
mbed_official | 205:c41fc65bcfb4 | 577 | |
mbed_official | 205:c41fc65bcfb4 | 578 | /* Check the address length parameter */ |
mbed_official | 205:c41fc65bcfb4 | 579 | assert_param(IS_UART_ADDRESSLENGTH_DETECT(AddressLength)); |
mbed_official | 205:c41fc65bcfb4 | 580 | |
mbed_official | 205:c41fc65bcfb4 | 581 | huart->State = HAL_UART_STATE_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 582 | |
mbed_official | 205:c41fc65bcfb4 | 583 | /* Disable the Peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 584 | __HAL_UART_DISABLE(huart); |
mbed_official | 205:c41fc65bcfb4 | 585 | |
mbed_official | 205:c41fc65bcfb4 | 586 | /* Set the address length */ |
mbed_official | 205:c41fc65bcfb4 | 587 | MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, AddressLength); |
mbed_official | 205:c41fc65bcfb4 | 588 | |
mbed_official | 205:c41fc65bcfb4 | 589 | /* Enable the Peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 590 | __HAL_UART_ENABLE(huart); |
mbed_official | 205:c41fc65bcfb4 | 591 | |
mbed_official | 205:c41fc65bcfb4 | 592 | /* TEACK and/or REACK to check before moving huart->State to Ready */ |
mbed_official | 205:c41fc65bcfb4 | 593 | return (UART_CheckIdleState(huart)); |
mbed_official | 205:c41fc65bcfb4 | 594 | } |
mbed_official | 205:c41fc65bcfb4 | 595 | |
mbed_official | 205:c41fc65bcfb4 | 596 | |
mbed_official | 205:c41fc65bcfb4 | 597 | #if !defined(STM32F030x6) && !defined(STM32F030x8) |
mbed_official | 205:c41fc65bcfb4 | 598 | /** |
mbed_official | 205:c41fc65bcfb4 | 599 | * @brief Initializes the UART wake-up from stop mode parameters when triggered by address detection. |
mbed_official | 205:c41fc65bcfb4 | 600 | * @param huart: uart handle |
mbed_official | 205:c41fc65bcfb4 | 601 | * @param WakeUpSelection: UART wake up from stop mode parameters |
mbed_official | 205:c41fc65bcfb4 | 602 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 603 | */ |
mbed_official | 205:c41fc65bcfb4 | 604 | static void UART_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection) |
mbed_official | 205:c41fc65bcfb4 | 605 | { |
mbed_official | 205:c41fc65bcfb4 | 606 | assert_param(IS_UART_ADDRESSLENGTH_DETECT(WakeUpSelection.AddressLength)); |
mbed_official | 205:c41fc65bcfb4 | 607 | |
mbed_official | 205:c41fc65bcfb4 | 608 | /* Set the USART address length */ |
mbed_official | 205:c41fc65bcfb4 | 609 | MODIFY_REG(huart->Instance->CR2, USART_CR2_ADDM7, WakeUpSelection.AddressLength); |
mbed_official | 205:c41fc65bcfb4 | 610 | |
mbed_official | 205:c41fc65bcfb4 | 611 | /* Set the USART address node */ |
mbed_official | 205:c41fc65bcfb4 | 612 | MODIFY_REG(huart->Instance->CR2, USART_CR2_ADD, ((uint32_t)WakeUpSelection.Address << UART_CR2_ADDRESS_LSB_POS)); |
mbed_official | 205:c41fc65bcfb4 | 613 | } |
mbed_official | 205:c41fc65bcfb4 | 614 | #endif /* !defined(STM32F030x6) && !defined(STM32F030x8) */ |
mbed_official | 205:c41fc65bcfb4 | 615 | |
mbed_official | 205:c41fc65bcfb4 | 616 | /** |
mbed_official | 205:c41fc65bcfb4 | 617 | * @} |
mbed_official | 205:c41fc65bcfb4 | 618 | */ |
mbed_official | 205:c41fc65bcfb4 | 619 | |
mbed_official | 205:c41fc65bcfb4 | 620 | /** |
mbed_official | 205:c41fc65bcfb4 | 621 | * @} |
mbed_official | 205:c41fc65bcfb4 | 622 | */ |
mbed_official | 205:c41fc65bcfb4 | 623 | |
mbed_official | 205:c41fc65bcfb4 | 624 | #endif /* HAL_UART_MODULE_ENABLED */ |
mbed_official | 205:c41fc65bcfb4 | 625 | |
mbed_official | 205:c41fc65bcfb4 | 626 | /** |
mbed_official | 205:c41fc65bcfb4 | 627 | * @} |
mbed_official | 205:c41fc65bcfb4 | 628 | */ |
mbed_official | 205:c41fc65bcfb4 | 629 | |
mbed_official | 205:c41fc65bcfb4 | 630 | /** |
mbed_official | 205:c41fc65bcfb4 | 631 | * @} |
mbed_official | 205:c41fc65bcfb4 | 632 | */ |
mbed_official | 205:c41fc65bcfb4 | 633 | |
mbed_official | 205:c41fc65bcfb4 | 634 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |