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