annotate l476rg/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart_ex.c @ 2:0c59e7a7782a

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