annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_uart.c @ 103:f5d2f02dc73f kittz

Generalize TEXT of pressure unit
author Dmitry Romanov <kitt@bk.ru>
date Wed, 28 Nov 2018 09:36:33 +0300
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_uart.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief UART HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * functionalities of the Universal Asynchronous Receiver Transmitter (UART) peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * + Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * + Peripheral State and Errors functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 The UART HAL driver can be used as follows:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 (#) Declare a UART_HandleTypeDef handle structure.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 (##) Enable the USARTx interface clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 (##) UART pins configuration:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 (+++) Enable the clock for the UART GPIOs.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 (+++) Configure these UART pins as alternate function pull-up.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 (##) NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 and HAL_UART_Receive_IT() APIs):
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 (+++) Configure the USARTx interrupt priority.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 (+++) Enable the NVIC USART IRQ handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 (##) DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 and HAL_UART_Receive_DMA() APIs):
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 (+++) Declare a DMA handle structure for the Tx/Rx stream.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 (+++) Enable the DMAx interface clock.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 (+++) Configure the declared DMA handle structure with the required
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 Tx/Rx parameters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 (+++) Configure the DMA Tx/Rx Stream.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 (+++) Associate the initialized DMA handle to the UART DMA Tx/Rx handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 (+++) Configure the priority and enable the NVIC for the transfer complete
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 interrupt on the DMA Tx/Rx Stream.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 flow control and Mode(Receiver/Transmitter) in the Init structure.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 (#) For the UART asynchronous mode, initialize the UART registers by calling
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 the HAL_UART_Init() API.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 (#) For the UART Half duplex mode, initialize the UART registers by calling
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 the HAL_HalfDuplex_Init() API.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 (#) For the LIN mode, initialize the UART registers by calling the HAL_LIN_Init() API.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 (#) For the Multi-Processor mode, initialize the UART registers by calling
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 the HAL_MultiProcessor_Init() API.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 (@) The specific UART interrupts (Transmission complete interrupt,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 RXNE interrupt and Error Interrupts) will be managed using the macros
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 __HAL_UART_ENABLE_IT() and __HAL_UART_DISABLE_IT() inside the transmit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 and receive process.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 (@) These APIs (HAL_UART_Init() and HAL_HalfDuplex_Init()) configure also the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 HAL_UART_MspInit() API.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 Three operation modes are available within this driver :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 *** Polling mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 =================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 (+) Send an amount of data in blocking mode using HAL_UART_Transmit()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 (+) Receive an amount of data in blocking mode using HAL_UART_Receive()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 *** Interrupt mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 ===================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 (+) Send an amount of data in non blocking mode using HAL_UART_Transmit_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 (+) At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 add his own code by customization of function pointer HAL_UART_TxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 (+) Receive an amount of data in non blocking mode using HAL_UART_Receive_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 (+) At reception end of transfer HAL_UART_RxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 add his own code by customization of function pointer HAL_UART_RxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 (+) In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 add his own code by customization of function pointer HAL_UART_ErrorCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 *** DMA mode IO operation ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 ==============================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 (+) Send an amount of data in non blocking mode (DMA) using HAL_UART_Transmit_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 (+) At transmission end of half transfer HAL_UART_TxHalfCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 add his own code by customization of function pointer HAL_UART_TxHalfCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 (+) At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 add his own code by customization of function pointer HAL_UART_TxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 (+) Receive an amount of data in non blocking mode (DMA) using HAL_UART_Receive_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 (+) At reception end of half transfer HAL_UART_RxHalfCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 add his own code by customization of function pointer HAL_UART_RxHalfCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 (+) At reception end of transfer HAL_UART_RxCpltCallback is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 add his own code by customization of function pointer HAL_UART_RxCpltCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 (+) In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 add his own code by customization of function pointer HAL_UART_ErrorCallback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 (+) Pause the DMA Transfer using HAL_UART_DMAPause()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 (+) Resume the DMA Transfer using HAL_UART_DMAResume()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 (+) Stop the DMA Transfer using HAL_UART_DMAStop()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 *** UART HAL driver macros list ***
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 =============================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 Below the list of most used macros in UART HAL driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 (+) __HAL_UART_ENABLE: Enable the UART peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 (+) __HAL_UART_DISABLE: Disable the UART peripheral
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 (+) __HAL_UART_GET_FLAG : Check whether the specified UART flag is set or not
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 (+) __HAL_UART_CLEAR_FLAG : Clear the specified UART pending flag
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 (+) __HAL_UART_ENABLE_IT: Enable the specified UART interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 (+) __HAL_UART_DISABLE_IT: Disable the specified UART interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 (+) __HAL_UART_GET_IT_SOURCE: Check whether the specified UART interrupt has occurred or not
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 (@) You can refer to the UART HAL driver header file for more useful macros
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 /** @defgroup UART UART
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 * @brief HAL UART module driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 #ifdef HAL_UART_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 /** @addtogroup UART_Private_Constants
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 #define UART_TIMEOUT_VALUE 22000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 /** @addtogroup UART_Private_Functions UART Private Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 static void UART_SetConfig (UART_HandleTypeDef *huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 static void UART_DMAError(DMA_HandleTypeDef *hdma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 /* Exported functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 /** @defgroup UART_Exported_Functions UART Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 /** @defgroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 * @brief Initialization and Configuration functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 ##### Initialization and Configuration functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 in asynchronous mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 (+) For the asynchronous mode only these parameters can be configured:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 (++) Baud Rate
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 (++) Word Length
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 (++) Stop Bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 (++) Parity: If the parity is enabled, then the MSB bit of the data written
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 in the data register is transmitted but is changed by the parity bit.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 Depending on the frame length defined by the M bit (8-bits or 9-bits),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 please refer to Reference manual for possible UART frame formats.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 (++) Hardware flow control
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 (++) Receiver/transmitter modes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 (++) Over Sampling Method
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 The HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init() and HAL_MultiProcessor_Init() APIs
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 follow respectively the UART asynchronous, UART Half duplex, LIN and Multi-Processor
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 configuration procedures (details for the procedures are available in reference manual (RM0329)).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 * @brief Initializes the UART mode according to the specified parameters in
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 * the UART_InitTypeDef and create the associated handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 /* Check the UART handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 if(huart == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 if(huart->Init.HwFlowCtl != UART_HWCONTROL_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 /* The hardware flow control is available only for USART1, USART2, USART3 and USART6 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 assert_param(IS_UART_HWFLOW_INSTANCE(huart->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 assert_param(IS_UART_HARDWARE_FLOW_CONTROL(huart->Init.HwFlowCtl));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 assert_param(IS_UART_INSTANCE(huart->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 if(huart->State == HAL_UART_STATE_RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 /* Init the low level hardware */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 HAL_UART_MspInit(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 huart->State = HAL_UART_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 /* Disable the peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 __HAL_UART_DISABLE(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 /* Set the UART Communication parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 UART_SetConfig(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 /* In asynchronous mode, the following bits must be kept cleared:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 - LINEN and CLKEN bits in the USART_CR2 register,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 - SCEN, HDSEL and IREN bits in the USART_CR3 register.*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 huart->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 huart->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 /* Enable the peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 __HAL_UART_ENABLE(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 /* Initialize the UART state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 huart->State= HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 * @brief Initializes the half-duplex mode according to the specified
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 * parameters in the UART_InitTypeDef and create the associated handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 /* Check the UART handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 if(huart == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 assert_param(IS_UART_INSTANCE(huart->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 if(huart->State == HAL_UART_STATE_RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 /* Init the low level hardware */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 HAL_UART_MspInit(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 huart->State = HAL_UART_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 /* Disable the peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 __HAL_UART_DISABLE(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 /* Set the UART Communication parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 UART_SetConfig(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 /* In half-duplex mode, the following bits must be kept cleared:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 - LINEN and CLKEN bits in the USART_CR2 register,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 - SCEN and IREN bits in the USART_CR3 register.*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 huart->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 huart->Instance->CR3 &= ~(USART_CR3_IREN | USART_CR3_SCEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 huart->Instance->CR3 |= USART_CR3_HDSEL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 /* Enable the peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 __HAL_UART_ENABLE(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 /* Initialize the UART state*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 huart->State= HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 * @brief Initializes the LIN mode according to the specified
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 * parameters in the UART_InitTypeDef and create the associated handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 * @param BreakDetectLength: Specifies the LIN break detection length.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 * @arg UART_LINBREAKDETECTLENGTH_10B: 10-bit break detection
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 * @arg UART_LINBREAKDETECTLENGTH_11B: 11-bit break detection
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 /* Check the UART handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 if(huart == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 assert_param(IS_UART_INSTANCE(huart->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 assert_param(IS_UART_LIN_BREAK_DETECT_LENGTH(BreakDetectLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 assert_param(IS_UART_LIN_WORD_LENGTH(huart->Init.WordLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 assert_param(IS_UART_LIN_OVERSAMPLING(huart->Init.OverSampling));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 if(huart->State == HAL_UART_STATE_RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 /* Init the low level hardware */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 HAL_UART_MspInit(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 huart->State = HAL_UART_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 /* Disable the peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 __HAL_UART_DISABLE(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 /* Set the UART Communication parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 UART_SetConfig(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 /* In LIN mode, the following bits must be kept cleared:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 - LINEN and CLKEN bits in the USART_CR2 register,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 - SCEN and IREN bits in the USART_CR3 register.*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 huart->Instance->CR2 &= ~(USART_CR2_CLKEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 huart->Instance->CR3 &= ~(USART_CR3_HDSEL | USART_CR3_IREN | USART_CR3_SCEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 huart->Instance->CR2 |= USART_CR2_LINEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 /* Set the USART LIN Break detection length. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 huart->Instance->CR2 &= ~(USART_CR2_LBDL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 huart->Instance->CR2 |= BreakDetectLength;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 /* Enable the peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 __HAL_UART_ENABLE(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 /* Initialize the UART state*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 huart->State= HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 * @brief Initializes the Multi-Processor mode according to the specified
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 * parameters in the UART_InitTypeDef and create the associated handle.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 * @param Address: USART address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 * @param WakeUpMethod: specifies the USART wake-up method.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 * @arg UART_WAKEUPMETHOD_IDLELINE: Wake-up by an idle line detection
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 * @arg UART_WAKEUPMETHOD_ADDRESSMARK: Wake-up by an address mark
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 /* Check the UART handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 if(huart == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 assert_param(IS_UART_INSTANCE(huart->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 assert_param(IS_UART_WAKEUPMETHOD(WakeUpMethod));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 assert_param(IS_UART_ADDRESS(Address));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 if(huart->State == HAL_UART_STATE_RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 /* Init the low level hardware */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 HAL_UART_MspInit(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 huart->State = HAL_UART_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 /* Disable the peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 __HAL_UART_DISABLE(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 /* Set the UART Communication parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 UART_SetConfig(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 /* In Multi-Processor mode, the following bits must be kept cleared:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 - LINEN and CLKEN bits in the USART_CR2 register,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 - SCEN, HDSEL and IREN bits in the USART_CR3 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 huart->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 huart->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 /* Clear the USART address */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 huart->Instance->CR2 &= ~(USART_CR2_ADD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 /* Set the USART address node */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 huart->Instance->CR2 |= Address;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 /* Set the wake up method by setting the WAKE bit in the CR1 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 huart->Instance->CR1 &= ~(USART_CR1_WAKE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 huart->Instance->CR1 |= WakeUpMethod;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 /* Enable the peripheral */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 __HAL_UART_ENABLE(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 /* Initialize the UART state */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 huart->State= HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 * @brief DeInitializes the UART peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 /* Check the UART handle allocation */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 if(huart == NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 assert_param(IS_UART_INSTANCE(huart->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 huart->State = HAL_UART_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 /* DeInit the low level hardware */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 HAL_UART_MspDeInit(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 huart->State = HAL_UART_STATE_RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 /* Process Lock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 * @brief UART MSP Init.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 __weak void HAL_UART_MspInit(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 /* NOTE: This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 the HAL_UART_MspInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 * @brief UART MSP DeInit.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 __weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 /* NOTE: This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 the HAL_UART_MspDeInit could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 /** @defgroup UART_Exported_Functions_Group2 IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 * @brief UART Transmit and Receive functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 ##### IO operation functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 This subsection provides a set of functions allowing to manage the UART asynchronous
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 and Half duplex data transfers.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 (#) There are two modes of transfer:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 (++) Blocking mode: The communication is performed in polling mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 The HAL status of all data processing is returned by the same function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 after finishing transfer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 (++) Non blocking mode: The communication is performed using Interrupts
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 or DMA, these APIs return the HAL status.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 The end of the data processing will be indicated through the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 dedicated UART IRQ when using Interrupt mode or the DMA IRQ when
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 using DMA mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 The HAL_UART_TxCpltCallback(), HAL_UART_RxCpltCallback() user callbacks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 will be executed respectively at the end of the transmit or receive process.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 The HAL_UART_ErrorCallback() user callback will be executed when
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 a communication error is detected.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 (#) Blocking mode APIs are:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 (++) HAL_UART_Transmit()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 (++) HAL_UART_Receive()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 (#) Non Blocking mode APIs with Interrupt are:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 (++) HAL_UART_Transmit_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 (++) HAL_UART_Receive_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 (++) HAL_UART_IRQHandler()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 (#) Non Blocking mode functions with DMA are:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 (++) HAL_UART_Transmit_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 (++) HAL_UART_Receive_DMA()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 (#) A set of Transfer Complete Callbacks are provided in non blocking mode:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 (++) HAL_UART_TxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 (++) HAL_UART_RxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 (++) HAL_UART_ErrorCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 (@) In the Half duplex communication, it is forbidden to run the transmit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 and receive process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 can't be useful.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 * @brief Sends an amount of data in blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 uint16_t* tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 uint32_t tmp1 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 tmp1 = huart->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 if((tmp1 == HAL_UART_STATE_READY) || (tmp1 == HAL_UART_STATE_BUSY_RX))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 if((pData == NULL ) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 /* Check if a non-blocking receive process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 if(huart->State == HAL_UART_STATE_BUSY_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 huart->State = HAL_UART_STATE_BUSY_TX_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 huart->State = HAL_UART_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 huart->TxXferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 huart->TxXferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 while(huart->TxXferCount > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 huart->TxXferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 if(huart->Init.WordLength == UART_WORDLENGTH_9B)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 tmp = (uint16_t*) pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 huart->Instance->DR = (*tmp & (uint16_t)0x01FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 if(huart->Init.Parity == UART_PARITY_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 pData +=2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 pData +=1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 huart->Instance->DR = (*pData++ & (uint8_t)0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 /* Check if a non-blocking receive process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 huart->State = HAL_UART_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 * @brief Receives an amount of data in blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 * @param Size: Amount of data to be received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 uint16_t* tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 uint32_t tmp1 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 tmp1 = huart->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 if((tmp1 == HAL_UART_STATE_READY) || (tmp1 == HAL_UART_STATE_BUSY_TX))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 if((pData == NULL ) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 /* Check if a non-blocking transmit process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 if(huart->State == HAL_UART_STATE_BUSY_TX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 huart->State = HAL_UART_STATE_BUSY_TX_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 huart->State = HAL_UART_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 huart->RxXferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 huart->RxXferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 /* Check the remain data to be received */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 while(huart->RxXferCount > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 huart->RxXferCount--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 if(huart->Init.WordLength == UART_WORDLENGTH_9B)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 tmp = (uint16_t*) pData ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 if(huart->Init.Parity == UART_PARITY_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 pData +=2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x00FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 pData +=1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, Timeout) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 if(huart->Init.Parity == UART_PARITY_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 *pData++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 *pData++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 /* Check if a non-blocking transmit process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 huart->State = HAL_UART_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 * @brief Sends an amount of data in non blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 uint32_t tmp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 tmp = huart->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 if((tmp == HAL_UART_STATE_READY) || (tmp == HAL_UART_STATE_BUSY_RX))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 if((pData == NULL ) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 huart->pTxBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 huart->TxXferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 huart->TxXferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 /* Check if a receive process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 if(huart->State == HAL_UART_STATE_BUSY_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 huart->State = HAL_UART_STATE_BUSY_TX_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 huart->State = HAL_UART_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 /* Enable the UART Parity Error Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 __HAL_UART_ENABLE_IT(huart, UART_IT_PE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 __HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 /* Enable the UART Transmit data register empty Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 __HAL_UART_ENABLE_IT(huart, UART_IT_TXE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 * @brief Receives an amount of data in non blocking mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 * @param Size: Amount of data to be received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 uint32_t tmp = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 tmp = huart->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 if((tmp == HAL_UART_STATE_READY) || (tmp == HAL_UART_STATE_BUSY_TX))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 if((pData == NULL ) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 huart->pRxBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 huart->RxXferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 huart->RxXferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 /* Check if a transmit process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 if(huart->State == HAL_UART_STATE_BUSY_TX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 huart->State = HAL_UART_STATE_BUSY_TX_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 huart->State = HAL_UART_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 /* Enable the UART Parity Error Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 __HAL_UART_ENABLE_IT(huart, UART_IT_PE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 __HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 /* Enable the UART Data Register not empty Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 __HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 * @brief Sends an amount of data in non blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 * @param Size: Amount of data to be sent
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 uint32_t *tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 uint32_t tmp1 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 tmp1 = huart->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 if((tmp1 == HAL_UART_STATE_READY) || (tmp1 == HAL_UART_STATE_BUSY_RX))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 if((pData == NULL ) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 huart->pTxBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 huart->TxXferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 huart->TxXferCount = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 /* Check if a receive process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926 if(huart->State == HAL_UART_STATE_BUSY_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 huart->State = HAL_UART_STATE_BUSY_TX_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 huart->State = HAL_UART_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 /* Set the UART DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 huart->hdmatx->XferCpltCallback = UART_DMATransmitCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 /* Set the UART DMA Half transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 huart->hdmatx->XferHalfCpltCallback = UART_DMATxHalfCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 huart->hdmatx->XferErrorCallback = UART_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 /* Enable the UART transmit DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945 tmp = (uint32_t*)&pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 HAL_DMA_Start_IT(huart->hdmatx, *(uint32_t*)tmp, (uint32_t)&huart->Instance->DR, Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 /* Clear the TC flag in the SR register by writing 0 to it */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 __HAL_UART_CLEAR_FLAG(huart, UART_FLAG_TC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 /* Enable the DMA transfer for transmit request by setting the DMAT bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 in the UART CR3 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953 huart->Instance->CR3 |= USART_CR3_DMAT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 * @brief Receives an amount of data in non blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 * @param pData: Pointer to data buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 * @param Size: Amount of data to be received
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 * @note When the UART parity is enabled (PCE = 1) the data received contain the parity bit.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 uint32_t *tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 uint32_t tmp1 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 tmp1 = huart->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 if((tmp1 == HAL_UART_STATE_READY) || (tmp1 == HAL_UART_STATE_BUSY_TX))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 if((pData == NULL ) || (Size == 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 return HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 huart->pRxBuffPtr = pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 huart->RxXferSize = Size;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 huart->ErrorCode = HAL_UART_ERROR_NONE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 /* Check if a transmit process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 if(huart->State == HAL_UART_STATE_BUSY_TX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 huart->State = HAL_UART_STATE_BUSY_TX_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 huart->State = HAL_UART_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 /* Set the UART DMA transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 huart->hdmarx->XferCpltCallback = UART_DMAReceiveCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 /* Set the UART DMA Half transfer complete callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 huart->hdmarx->XferHalfCpltCallback = UART_DMARxHalfCplt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 /* Set the DMA error callback */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 huart->hdmarx->XferErrorCallback = UART_DMAError;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 /* Enable the DMA Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 tmp = (uint32_t*)&pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 HAL_DMA_Start_IT(huart->hdmarx, (uint32_t)&huart->Instance->DR, *(uint32_t*)tmp, Size);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 in the UART CR3 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 huart->Instance->CR3 |= USART_CR3_DMAR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 * @brief Pauses the DMA Transfer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 if(huart->State == HAL_UART_STATE_BUSY_TX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 /* Disable the UART DMA Tx request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 else if(huart->State == HAL_UART_STATE_BUSY_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 /* Disable the UART DMA Rx request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 else if (huart->State == HAL_UART_STATE_BUSY_TX_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 /* Disable the UART DMA Tx & Rx requests */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 * @brief Resumes the DMA Transfer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 if(huart->State == HAL_UART_STATE_BUSY_TX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 /* Enable the UART DMA Tx request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 huart->Instance->CR3 |= USART_CR3_DMAT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 else if(huart->State == HAL_UART_STATE_BUSY_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 /* Clear the Overrun flag before resuming the Rx transfer*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 __HAL_UART_CLEAR_OREFLAG(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 /* Enable the UART DMA Rx request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 huart->Instance->CR3 |= USART_CR3_DMAR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 else if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 /* Clear the Overrun flag before resuming the Rx transfer*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 __HAL_UART_CLEAR_OREFLAG(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 /* Enable the UART DMA Tx & Rx request */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 huart->Instance->CR3 |= USART_CR3_DMAT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 huart->Instance->CR3 |= USART_CR3_DMAR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 * @brief Stops the DMA Transfer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 /* The Lock is not implemented on this API to allow the user application
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 to call the HAL UART API under callbacks HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback():
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 and the correspond call back is executed HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 /* Disable the UART Tx/Rx DMA requests */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 huart->Instance->CR3 &= ~USART_CR3_DMAT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 huart->Instance->CR3 &= ~USART_CR3_DMAR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 /* Abort the UART DMA tx Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 if(huart->hdmatx != NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 HAL_DMA_Abort(huart->hdmatx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 /* Abort the UART DMA rx Stream */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 if(huart->hdmarx != NULL)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 HAL_DMA_Abort(huart->hdmarx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 * @brief This function handles UART interrupt request.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 uint32_t tmp1 = 0, tmp2 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_PE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_PE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 /* UART parity error interrupt occurred ------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 __HAL_UART_CLEAR_PEFLAG(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 huart->ErrorCode |= HAL_UART_ERROR_PE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_FE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 /* UART frame error interrupt occurred -------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 __HAL_UART_CLEAR_FEFLAG(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 huart->ErrorCode |= HAL_UART_ERROR_FE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_NE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 /* UART noise error interrupt occurred -------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 __HAL_UART_CLEAR_NEFLAG(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 huart->ErrorCode |= HAL_UART_ERROR_NE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_ORE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 /* UART Over-Run interrupt occurred ----------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 __HAL_UART_CLEAR_OREFLAG(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 huart->ErrorCode |= HAL_UART_ERROR_ORE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 /* UART in mode Receiver ---------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 UART_Receive_IT(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_TXE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 /* UART in mode Transmitter ------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 UART_Transmit_IT(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 tmp1 = __HAL_UART_GET_FLAG(huart, UART_FLAG_TC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_TC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 /* UART in mode Transmitter end --------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 if((tmp1 != RESET) && (tmp2 != RESET))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 UART_EndTransmit_IT(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213 if(huart->ErrorCode != HAL_UART_ERROR_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215 /* Set the UART state ready to be able to start again the process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 HAL_UART_ErrorCallback(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 * @brief Tx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 __weak void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 /* NOTE: This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 the HAL_UART_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 * @brief Tx Half Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 __weak void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 /* NOTE: This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 the HAL_UART_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 * @brief Rx Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 __weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 /* NOTE: This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 the HAL_UART_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 * @brief Rx Half Transfer completed callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 __weak void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 /* NOTE: This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 the HAL_UART_TxCpltCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 * @brief UART error callbacks.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 __weak void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282 /* NOTE: This function Should not be modified, when the callback is needed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 the HAL_UART_ErrorCallback could be implemented in the user file
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 /** @defgroup UART_Exported_Functions_Group3 Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 * @brief UART control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 ##### Peripheral Control functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 This subsection provides a set of functions allowing to control the UART:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 (+) HAL_LIN_SendBreak() API can be helpful to transmit the break character.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 (+) HAL_MultiProcessor_EnterMuteMode() API can be helpful to enter the UART in mute mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 (+) HAL_MultiProcessor_ExitMuteMode() API can be helpful to exit the UART mute mode by software.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 * @brief Transmits break characters.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317 assert_param(IS_UART_INSTANCE(huart->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322 huart->State = HAL_UART_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 /* Send break characters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 huart->Instance->CR1 |= USART_CR1_SBK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 * @brief Enters the UART in mute mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344 assert_param(IS_UART_INSTANCE(huart->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 huart->State = HAL_UART_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351 /* Enable the USART mute mode by setting the RWU bit in the CR1 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 huart->Instance->CR1 |= USART_CR1_RWU;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 * @brief Exits the UART mute mode: wake up software.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368 HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371 assert_param(IS_UART_INSTANCE(huart->Instance));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376 huart->State = HAL_UART_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378 /* Disable the USART mute mode by clearing the RWU bit in the CR1 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379 huart->Instance->CR1 &= (uint32_t)~((uint32_t)USART_CR1_RWU);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1390 * @brief Enables the UART transmitter and disables the UART receiver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1391 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1392 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1393 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1394 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1395 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1396 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1397 uint32_t tmpreg = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1398
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1399 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1400 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1401
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1402 huart->State = HAL_UART_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1403
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1404 /*-------------------------- USART CR1 Configuration -----------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1405 tmpreg = huart->Instance->CR1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1406
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1407 /* Clear TE and RE bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1408 tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1409
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1410 /* Enable the USART's transmit interface by setting the TE bit in the USART CR1 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1411 tmpreg |= (uint32_t)USART_CR1_TE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1413 /* Write to USART CR1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1414 huart->Instance->CR1 = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1415
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1416 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1417
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1418 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1419 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1420
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1421 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1422 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1423
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1424 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1425 * @brief Enables the UART receiver and disables the UART transmitter.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1426 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1427 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1428 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1429 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1430 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1431 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1432 uint32_t tmpreg = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1434 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1435 __HAL_LOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1436
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1437 huart->State = HAL_UART_STATE_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1438
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1439 /*-------------------------- USART CR1 Configuration -----------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1440 tmpreg = huart->Instance->CR1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1441
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1442 /* Clear TE and RE bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1443 tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1444
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1445 /* Enable the USART's receive interface by setting the RE bit in the USART CR1 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1446 tmpreg |= (uint32_t)USART_CR1_RE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1447
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1448 /* Write to USART CR1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1449 huart->Instance->CR1 = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1450
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1451 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1452
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1453 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1454 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1455
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1456 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1457 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1458
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1459 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1460 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1461 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1463 /** @defgroup UART_Exported_Functions_Group4 Peripheral State and Errors functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1464 * @brief UART State and Errors functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1465 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1466 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1467 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1468 ##### Peripheral State and Errors functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1469 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1470 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1471 This subsection provides a set of functions allowing to return the State of
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1472 UART communication process, return Peripheral Errors occurred during communication
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1473 process
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1474 (+) HAL_UART_GetState() API can be helpful to check in run-time the state of the UART peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1475 (+) HAL_UART_GetError() check in run-time errors that could be occurred during communication.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1476
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1477 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1478 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1479 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1480
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1481 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1482 * @brief Returns the UART state.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1483 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1484 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1485 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1486 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1487 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1488 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1489 return huart->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1490 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1491
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1492 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1493 * @brief Return the UART error code
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1494 * @param huart : pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1495 * the configuration information for the specified UART.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1496 * @retval UART Error Code
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1497 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1498 uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1499 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1500 return huart->ErrorCode;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1501 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1503 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1504 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1505 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1506
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1507 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1508 * @brief DMA UART transmit process complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1509 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1510 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1511 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1512 static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1513 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1514 UART_HandleTypeDef* huart = ( UART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1515 /* DMA Normal mode*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1516 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1517 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1518 huart->TxXferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1519
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1520 /* Disable the DMA transfer for transmit request by setting the DMAT bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1521 in the UART CR3 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1522 huart->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DMAT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1523
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1524 /* Enable the UART Transmit Complete Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1525 __HAL_UART_ENABLE_IT(huart, UART_IT_TC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1526 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1527 /* DMA Circular mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1528 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1529 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1530 HAL_UART_TxCpltCallback(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1531 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1532 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1533
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1534 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1535 * @brief DMA UART transmit process half complete callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1536 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1537 * the configuration information for the specified DMA module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1538 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1539 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1540 static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1541 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1542 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1543
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1544 HAL_UART_TxHalfCpltCallback(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1545 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1546
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1547 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1548 * @brief DMA UART receive process complete callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1549 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1550 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1551 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1552 static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1553 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1554 UART_HandleTypeDef* huart = ( UART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1555 /* DMA Normal mode*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1556 if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1557 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1558 huart->RxXferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1559
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1560 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1561 in the UART CR3 register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1562 huart->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DMAR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1563
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1564 /* Check if a transmit process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1565 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1566 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1567 huart->State = HAL_UART_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1568 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1569 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1570 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1571 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1572 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1573 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1574 HAL_UART_RxCpltCallback(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1575 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1576
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1577 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1578 * @brief DMA UART receive process half complete callback
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1579 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1580 * the configuration information for the specified DMA module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1581 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1582 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1583 static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1584 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1585 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1586
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1587 HAL_UART_RxHalfCpltCallback(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1588 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1589
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1590 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1591 * @brief DMA UART communication error callback.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1592 * @param hdma: DMA handle
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1593 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1594 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1595 static void UART_DMAError(DMA_HandleTypeDef *hdma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1596 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1597 UART_HandleTypeDef* huart = ( UART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1598 huart->RxXferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1599 huart->TxXferCount = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1600 huart->State= HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1601 huart->ErrorCode |= HAL_UART_ERROR_DMA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1602 HAL_UART_ErrorCallback(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1603 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1604
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1605 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1606 * @brief This function handles UART Communication Timeout.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1607 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1608 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1609 * @param Flag: specifies the UART flag to check.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1610 * @param Status: The new Flag status (SET or RESET).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1611 * @param Timeout: Timeout duration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1612 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1613 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1614 static HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1615 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1616 uint32_t tickstart = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1617
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1618 /* Get tick */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1619 tickstart = HAL_GetTick();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1620
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1621 /* Wait until flag is set */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1622 if(Status == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1623 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1624 while(__HAL_UART_GET_FLAG(huart, Flag) == RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1625 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1626 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1627 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1628 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1629 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1630 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1631 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1632 __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1633 __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1634 __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1635 __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1636
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1637 huart->State= HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1638
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1639 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1640 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1641
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1642 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1643 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1644 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1645 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1646 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1647 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1648 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1649 while(__HAL_UART_GET_FLAG(huart, Flag) != RESET)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1650 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1651 /* Check for the Timeout */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1652 if(Timeout != HAL_MAX_DELAY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1653 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1654 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1655 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1656 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1657 __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1658 __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1659 __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1660 __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1661
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1662 huart->State= HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1663
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1664 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1665 __HAL_UNLOCK(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1666
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1667 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1668 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1669 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1670 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1671 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1672 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1673 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1674
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1675 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1676 * @brief Sends an amount of data in non blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1677 * @param huart: Pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1678 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1679 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1680 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1681 static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1682 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1683 uint16_t* tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1684 uint32_t tmp1 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1685
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1686 tmp1 = huart->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1687 if((tmp1 == HAL_UART_STATE_BUSY_TX) || (tmp1 == HAL_UART_STATE_BUSY_TX_RX))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1688 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1689 if(huart->Init.WordLength == UART_WORDLENGTH_9B)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1690 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1691 tmp = (uint16_t*) huart->pTxBuffPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1692 huart->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1693 if(huart->Init.Parity == UART_PARITY_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1694 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1695 huart->pTxBuffPtr += 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1696 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1697 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1698 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1699 huart->pTxBuffPtr += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1700 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1701 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1702 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1703 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1704 huart->Instance->DR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0x00FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1705 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1706
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1707 if(--huart->TxXferCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1708 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1709 /* Disable the UART Transmit Complete Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1710 __HAL_UART_DISABLE_IT(huart, UART_IT_TXE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1711
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1712 /* Enable the UART Transmit Complete Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1713 __HAL_UART_ENABLE_IT(huart, UART_IT_TC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1714 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1715 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1716 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1717 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1718 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1719 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1720 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1721 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1722
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1723
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1724 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1725 * @brief Wraps up transmission in non blocking mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1726 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1727 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1728 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1729 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1730 static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1731 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1732 /* Disable the UART Transmit Complete Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1733 __HAL_UART_DISABLE_IT(huart, UART_IT_TC);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1734
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1735 /* Check if a receive process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1736 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1737 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1738 huart->State = HAL_UART_STATE_BUSY_RX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1739 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1740 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1741 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1742 /* Disable the UART Parity Error Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1743 __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1744
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1745 /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1746 __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1747
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1748 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1749 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1750
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1751 HAL_UART_TxCpltCallback(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1752
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1753 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1754 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1755
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1756 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1757 * @brief Receives an amount of data in non blocking mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1758 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1759 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1760 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1761 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1762 static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1763 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1764 uint16_t* tmp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1765 uint32_t tmp1 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1766
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1767 tmp1 = huart->State;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1768 if((tmp1 == HAL_UART_STATE_BUSY_RX) || (tmp1 == HAL_UART_STATE_BUSY_TX_RX))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1769 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1770 if(huart->Init.WordLength == UART_WORDLENGTH_9B)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1771 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1772 tmp = (uint16_t*) huart->pRxBuffPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1773 if(huart->Init.Parity == UART_PARITY_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1774 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1775 *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x01FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1776 huart->pRxBuffPtr += 2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1777 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1778 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1779 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1780 *tmp = (uint16_t)(huart->Instance->DR & (uint16_t)0x00FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1781 huart->pRxBuffPtr += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1782 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1783 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1784 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1785 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1786 if(huart->Init.Parity == UART_PARITY_NONE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1787 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1788 *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x00FF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1789 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1790 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1791 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1792 *huart->pRxBuffPtr++ = (uint8_t)(huart->Instance->DR & (uint8_t)0x007F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1793 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1794 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1795
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1796 if(--huart->RxXferCount == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1797 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1798 __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1799
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1800 /* Check if a transmit process is ongoing or not */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1801 if(huart->State == HAL_UART_STATE_BUSY_TX_RX)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1802 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1803 huart->State = HAL_UART_STATE_BUSY_TX;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1804 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1805 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1806 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1807 /* Disable the UART Parity Error Interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1808 __HAL_UART_DISABLE_IT(huart, UART_IT_PE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1809
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1810 /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1811 __HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1812
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1813 huart->State = HAL_UART_STATE_READY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1814 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1815 HAL_UART_RxCpltCallback(huart);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1816
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1817 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1818 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1819 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1820 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1821 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1822 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1823 return HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1824 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1825 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1826
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1827 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1828 * @brief Configures the UART peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1829 * @param huart: pointer to a UART_HandleTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1830 * the configuration information for the specified UART module.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1831 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1832 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1833 static void UART_SetConfig(UART_HandleTypeDef *huart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1834 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1835 uint32_t tmpreg = 0x00;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1836
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1837 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1838 assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1839 assert_param(IS_UART_STOPBITS(huart->Init.StopBits));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1840 assert_param(IS_UART_PARITY(huart->Init.Parity));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1841 assert_param(IS_UART_MODE(huart->Init.Mode));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1842
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1843 /*-------------------------- USART CR2 Configuration -----------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1844 tmpreg = huart->Instance->CR2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1845
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1846 /* Clear STOP[13:12] bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1847 tmpreg &= (uint32_t)~((uint32_t)USART_CR2_STOP);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1848
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1849 /* Configure the UART Stop Bits: Set STOP[13:12] bits according to huart->Init.StopBits value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1850 tmpreg |= (uint32_t)huart->Init.StopBits;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1851
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1852 /* Write to USART CR2 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1853 huart->Instance->CR2 = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1854
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1855 /*-------------------------- USART CR1 Configuration -----------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1856 tmpreg = huart->Instance->CR1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1857
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1858 /* Clear M, PCE, PS, TE and RE bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1859 tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | \
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1860 USART_CR1_RE | USART_CR1_OVER8));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1861
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1862 /* Configure the UART Word Length, Parity and mode:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1863 Set the M bits according to huart->Init.WordLength value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1864 Set PCE and PS bits according to huart->Init.Parity value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1865 Set TE and RE bits according to huart->Init.Mode value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1866 Set OVER8 bit according to huart->Init.OverSampling value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1867 tmpreg |= (uint32_t)huart->Init.WordLength | huart->Init.Parity | huart->Init.Mode | huart->Init.OverSampling;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1868
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1869 /* Write to USART CR1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1870 huart->Instance->CR1 = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1871
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1872 /*-------------------------- USART CR3 Configuration -----------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1873 tmpreg = huart->Instance->CR3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1874
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1875 /* Clear CTSE and RTSE bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1876 tmpreg &= (uint32_t)~((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1877
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1878 /* Configure the UART HFC: Set CTSE and RTSE bits according to huart->Init.HwFlowCtl value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1879 tmpreg |= huart->Init.HwFlowCtl;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1880
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1881 /* Write to USART CR3 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1882 huart->Instance->CR3 = (uint32_t)tmpreg;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1883
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1884 /* Check the Over Sampling */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1885 if(huart->Init.OverSampling == UART_OVERSAMPLING_8)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1886 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1887 /*-------------------------- USART BRR Configuration ---------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1888 if((huart->Instance == USART1) || (huart->Instance == USART6))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1889 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1890 huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1891 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1892 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1893 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1894 huart->Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1895 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1896 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1897 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1898 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1899 /*-------------------------- USART BRR Configuration ---------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1900 if((huart->Instance == USART1) || (huart->Instance == USART6))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1901 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1902 huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1903 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1904 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1905 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1906 huart->Instance->BRR = UART_BRR_SAMPLING16(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1907 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1908 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1909 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1910
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1911 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1912 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1913 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1914
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1915 #endif /* HAL_UART_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1916 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1917 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1918 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1919
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1920 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1921 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1922 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1923
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1924 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/