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