mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Nov 07 08:15:08 2014 +0000
Revision:
392:2b59412bb664
Parent:
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F091RC/stm32f0xx_hal_uart_ex.c@340:28d1f895c6fe
Child:
441:d2c15dda23c1
Synchronized with git revision eec0be05cd92349bee83c65f9e1302b25b5badf4

Full URL: https://github.com/mbedmicro/mbed/commit/eec0be05cd92349bee83c65f9e1302b25b5badf4/

Targets: STM32F0 - Factorisation of NUCLEO_F030R8/F072RB/F091RC cmsis folders

Who changed what in which revision?

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