annotate l476rg/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c @ 0:32a3b1785697

a rough draft of Hardware Abstraction Layer for C++ STM32L476RG drivers
author cin
date Thu, 12 Jan 2017 02:45:43 +0300
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2 ******************************************************************************
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
3 * @file stm32l4xx_hal_uart.c
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
4 * @author MCD Application Team
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
5 * @version V1.6.0
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
6 * @date 28-October-2016
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
7 * @brief UART HAL module driver.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
8 * This file provides firmware functions to manage the following
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
9 * functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
10 * + Initialization and de-initialization functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
11 * + IO operation functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
12 * + Peripheral Control functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
13 *
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
14 *
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
15 @verbatim
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
16 ===============================================================================
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
17 ##### How to use this driver #####
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
18 ===============================================================================
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
19 [..]
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
20 The UART HAL driver can be used as follows:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
21
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
22 (#) Declare a UART_HandleTypeDef handle structure (eg. UART_HandleTypeDef huart).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
23 (#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
24 (++) Enable the USARTx interface clock.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
25 (++) UART pins configuration:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
26 (+++) Enable the clock for the UART GPIOs.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
27 (+++) Configure these UART pins as alternate function pull-up.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
28 (++) NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
29 and HAL_UART_Receive_IT() APIs):
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
30 (+++) Configure the USARTx interrupt priority.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
31 (+++) Enable the NVIC USART IRQ handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
32 (++) UART interrupts handling:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
33 -@@- The specific UART interrupts (Transmission complete interrupt,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
34 RXNE interrupt and Error Interrupts) are managed using the macros
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
35 __HAL_UART_ENABLE_IT() and __HAL_UART_DISABLE_IT() inside the transmit and receive processes.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
36 (++) DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
37 and HAL_UART_Receive_DMA() APIs):
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
38 (+++) Declare a DMA handle structure for the Tx/Rx channel.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
39 (+++) Enable the DMAx interface clock.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
40 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
41 (+++) Configure the DMA Tx/Rx channel.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
42 (+++) Associate the initialized DMA handle to the UART DMA Tx/Rx handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
43 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
44
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
45 (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
46 flow control and Mode (Receiver/Transmitter) in the huart handle Init structure.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
47
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
48 (#) If required, program UART advanced features (TX/RX pins swap, auto Baud rate detection,...)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
49 in the huart handle AdvancedInit structure.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
50
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
51 (#) For the UART asynchronous mode, initialize the UART registers by calling
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
52 the HAL_UART_Init() API.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
53
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
54 (#) For the UART Half duplex mode, initialize the UART registers by calling
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
55 the HAL_HalfDuplex_Init() API.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
56
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
57 (#) For the UART LIN (Local Interconnection Network) mode, initialize the UART registers
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
58 by calling the HAL_LIN_Init() API.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
59
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
60 (#) For the UART Multiprocessor mode, initialize the UART registers
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
61 by calling the HAL_MultiProcessor_Init() API.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
62
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
63 (#) For the UART RS485 Driver Enabled mode, initialize the UART registers
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
64 by calling the HAL_RS485Ex_Init() API.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
65
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
66 [..]
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
67 (@) These API's (HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init(), HAL_MultiProcessor_Init(),
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
68 also configure the low level Hardware GPIO, CLOCK, CORTEX...etc) by
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
69 calling the customized HAL_UART_MspInit() API.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
70
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
71 @endverbatim
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
72 ******************************************************************************
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
73 * @attention
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
74 *
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
75 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
76 *
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
77 * Redistribution and use in source and binary forms, with or without modification,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
78 * are permitted provided that the following conditions are met:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
79 * 1. Redistributions of source code must retain the above copyright notice,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
80 * this list of conditions and the following disclaimer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
81 * 2. Redistributions in binary form must reproduce the above copyright notice,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
82 * this list of conditions and the following disclaimer in the documentation
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
83 * and/or other materials provided with the distribution.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
84 * 3. Neither the name of STMicroelectronics nor the names of its contributors
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
85 * may be used to endorse or promote products derived from this software
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
86 * without specific prior written permission.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
87 *
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
88 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
89 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
90 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
91 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
92 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
93 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
94 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
95 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
96 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
97 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
98 *
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
99 ******************************************************************************
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
100 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
101
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
102 /* Includes ------------------------------------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
103 #include "stm32l4xx_hal.h"
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
104
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
105 /** @addtogroup STM32L4xx_HAL_Driver
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
106 * @{
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
107 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
108
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
109 /** @defgroup UART UART
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
110 * @brief HAL UART module driver
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
111 * @{
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
112 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
113
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
114 #ifdef HAL_UART_MODULE_ENABLED
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
115
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
116 /* Private typedef -----------------------------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
117 /* Private define ------------------------------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
118 /** @defgroup UART_Private_Constants UART Private Constants
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
119 * @{
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
120 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
121 #define UART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | \
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
122 USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8)) /*!< UART or USART CR1 fields of parameters set by UART_SetConfig API */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
123
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
124 #define UART_LPUART_BRR_MIN ((uint32_t)0x00000300) /* LPUART BRR minimum authorized value */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
125 #define UART_LPUART_BRR_MAX ((uint32_t)0x000FFFFF) /* LPUART BRR maximum authorized value */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
126 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
127 * @}
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
128 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
129
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
130 /* Private macros ------------------------------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
131 /* Private variables ---------------------------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
132 /* Private function prototypes -----------------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
133 /** @addtogroup UART_Private_Functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
134 * @{
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
135 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
136 static void UART_EndTxTransfer(UART_HandleTypeDef *huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
137 static void UART_EndRxTransfer(UART_HandleTypeDef *huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
138 static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
139 static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
140 static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
141 static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
142 static void UART_DMAError(DMA_HandleTypeDef *hdma);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
143 static void UART_DMAAbortOnError(DMA_HandleTypeDef *hdma);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
144 static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
145 static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
146 static void UART_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
147 static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
148 static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
149 static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
150 static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
151 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
152 * @}
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
153 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
154
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
155 /* Exported functions --------------------------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
156
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
157 /** @defgroup UART_Exported_Functions UART Exported Functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
158 * @{
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
159 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
160
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
161 /** @defgroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
162 * @brief Initialization and Configuration functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
163 *
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
164 @verbatim
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
165 ===============================================================================
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
166 ##### Initialization and Configuration functions #####
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
167 ===============================================================================
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
168 [..]
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
169 This subsection provides a set of functions allowing to initialize the USARTx or the UARTy
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
170 in asynchronous mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
171 (+) For the asynchronous mode the parameters below can be configured:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
172 (++) Baud Rate
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
173 (++) Word Length
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
174 (++) Stop Bit
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
175 (++) Parity: If the parity is enabled, then the MSB bit of the data written
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
176 in the data register is transmitted but is changed by the parity bit.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
177 (++) Hardware flow control
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
178 (++) Receiver/transmitter modes
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
179 (++) Over Sampling Method
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
180 (++) One-Bit Sampling Method
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
181 (+) For the asynchronous mode, the following advanced features can be configured as well:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
182 (++) TX and/or RX pin level inversion
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
183 (++) data logical level inversion
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
184 (++) RX and TX pins swap
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
185 (++) RX overrun detection disabling
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
186 (++) DMA disabling on RX error
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
187 (++) MSB first on communication line
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
188 (++) auto Baud rate detection
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
189 [..]
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
190 The HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_Init()and HAL_MultiProcessor_Init()API
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
191 follow respectively the UART asynchronous, UART Half duplex, UART LIN mode
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
192 and UART multiprocessor mode configuration procedures (details for the procedures
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
193 are available in reference manual).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
194
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
195 @endverbatim
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
196
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
197 Depending on the frame length defined by the M1 and M0 bits (7-bit,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
198 8-bit or 9-bit), the possible UART formats are listed in the
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
199 following table.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
200
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
201 Table 1. UART frame format.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
202 +-----------------------------------------------------------------------+
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
203 | M1 bit | M0 bit | PCE bit | UART frame |
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
204 |---------|---------|-----------|---------------------------------------|
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
205 | 0 | 0 | 0 | | SB | 8 bit data | STB | |
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
206 |---------|---------|-----------|---------------------------------------|
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
207 | 0 | 0 | 1 | | SB | 7 bit data | PB | STB | |
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
208 |---------|---------|-----------|---------------------------------------|
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
209 | 0 | 1 | 0 | | SB | 9 bit data | STB | |
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
210 |---------|---------|-----------|---------------------------------------|
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
211 | 0 | 1 | 1 | | SB | 8 bit data | PB | STB | |
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
212 |---------|---------|-----------|---------------------------------------|
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
213 | 1 | 0 | 0 | | SB | 7 bit data | STB | |
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
214 |---------|---------|-----------|---------------------------------------|
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
215 | 1 | 0 | 1 | | SB | 6 bit data | PB | STB | |
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
216 +-----------------------------------------------------------------------+
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
217
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
218 * @{
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
219 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
220
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
221 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
222 * @brief Initialize the UART mode according to the specified
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
223 * parameters in the UART_InitTypeDef and initialize the associated handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
224 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
225 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
226 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
227 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
228 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
229 /* Check the UART handle allocation */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
230 if(huart == NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
231 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
232 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
233 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
234
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
235 if(huart->Init.HwFlowCtl != UART_HWCONTROL_NONE)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
236 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
237 /* Check the parameters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
238 assert_param(IS_UART_HWFLOW_INSTANCE(huart->Instance));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
239 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
240 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
241 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
242 /* Check the parameters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
243 assert_param((IS_UART_INSTANCE(huart->Instance)) || (IS_LPUART_INSTANCE(huart->Instance)));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
244 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
245
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
246 if(huart->gState == HAL_UART_STATE_RESET)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
247 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
248 /* Allocate lock resource and initialize it */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
249 huart->Lock = HAL_UNLOCKED;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
250
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
251 /* Init the low level hardware : GPIO, CLOCK */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
252 HAL_UART_MspInit(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
253 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
254
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
255 huart->gState = HAL_UART_STATE_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
256
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
257 /* Disable the Peripheral */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
258 __HAL_UART_DISABLE(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
259
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
260 /* Set the UART Communication parameters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
261 if (UART_SetConfig(huart) == HAL_ERROR)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
262 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
263 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
264 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
265
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
266 if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
267 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
268 UART_AdvFeatureConfig(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
269 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
270
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
271 /* In asynchronous mode, the following bits must be kept cleared:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
272 - LINEN and CLKEN bits in the USART_CR2 register,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
273 - SCEN, HDSEL and IREN bits in the USART_CR3 register.*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
274 CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
275 CLEAR_BIT(huart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
276
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
277 /* Enable the Peripheral */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
278 __HAL_UART_ENABLE(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
279
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
280 /* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
281 return (UART_CheckIdleState(huart));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
282 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
283
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
284 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
285 * @brief Initialize the half-duplex mode according to the specified
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
286 * parameters in the UART_InitTypeDef and creates the associated handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
287 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
288 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
289 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
290 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
291 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
292 /* Check the UART handle allocation */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
293 if(huart == NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
294 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
295 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
296 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
297
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
298 /* Check UART instance */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
299 assert_param(IS_UART_HALFDUPLEX_INSTANCE(huart->Instance));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
300
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
301 if(huart->gState == HAL_UART_STATE_RESET)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
302 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
303 /* Allocate lock resource and initialize it */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
304 huart->Lock = HAL_UNLOCKED;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
305
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
306 /* Init the low level hardware : GPIO, CLOCK */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
307 HAL_UART_MspInit(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
308 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
309
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
310 huart->gState = HAL_UART_STATE_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
311
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
312 /* Disable the Peripheral */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
313 __HAL_UART_DISABLE(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
314
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
315 /* Set the UART Communication parameters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
316 if (UART_SetConfig(huart) == HAL_ERROR)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
317 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
318 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
319 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
320
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
321 if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
322 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
323 UART_AdvFeatureConfig(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
324 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
325
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
326 /* In half-duplex mode, the following bits must be kept cleared:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
327 - LINEN and CLKEN bits in the USART_CR2 register,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
328 - SCEN and IREN bits in the USART_CR3 register.*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
329 CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
330 CLEAR_BIT(huart->Instance->CR3, (USART_CR3_IREN | USART_CR3_SCEN));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
331
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
332 /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
333 SET_BIT(huart->Instance->CR3, USART_CR3_HDSEL);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
334
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
335 /* Enable the Peripheral */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
336 __HAL_UART_ENABLE(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
337
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
338 /* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
339 return (UART_CheckIdleState(huart));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
340 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
341
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
342
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
343 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
344 * @brief Initialize the LIN mode according to the specified
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
345 * parameters in the UART_InitTypeDef and creates the associated handle .
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
346 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
347 * @param BreakDetectLength: specifies the LIN break detection length.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
348 * This parameter can be one of the following values:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
349 * @arg @ref UART_LINBREAKDETECTLENGTH_10B 10-bit break detection
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
350 * @arg @ref UART_LINBREAKDETECTLENGTH_11B 11-bit break detection
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
351 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
352 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
353 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
354 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
355 /* Check the UART handle allocation */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
356 if(huart == NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
357 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
358 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
359 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
360
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
361 /* Check the LIN UART instance */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
362 assert_param(IS_UART_LIN_INSTANCE(huart->Instance));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
363 /* Check the Break detection length parameter */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
364 assert_param(IS_UART_LIN_BREAK_DETECT_LENGTH(BreakDetectLength));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
365
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
366 /* LIN mode limited to 16-bit oversampling only */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
367 if(huart->Init.OverSampling == UART_OVERSAMPLING_8)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
368 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
369 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
370 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
371 /* LIN mode limited to 8-bit data length */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
372 if(huart->Init.WordLength != UART_WORDLENGTH_8B)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
373 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
374 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
375 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
376
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
377 if(huart->gState == HAL_UART_STATE_RESET)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
378 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
379 /* Allocate lock resource and initialize it */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
380 huart->Lock = HAL_UNLOCKED;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
381
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
382 /* Init the low level hardware : GPIO, CLOCK */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
383 HAL_UART_MspInit(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
384 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
385
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
386 huart->gState = HAL_UART_STATE_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
387
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
388 /* Disable the Peripheral */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
389 __HAL_UART_DISABLE(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
390
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
391 /* Set the UART Communication parameters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
392 if (UART_SetConfig(huart) == HAL_ERROR)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
393 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
394 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
395 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
396
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
397 if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
398 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
399 UART_AdvFeatureConfig(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
400 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
401
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
402 /* In LIN mode, the following bits must be kept cleared:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
403 - LINEN and CLKEN bits in the USART_CR2 register,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
404 - SCEN and IREN bits in the USART_CR3 register.*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
405 CLEAR_BIT(huart->Instance->CR2, USART_CR2_CLKEN);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
406 CLEAR_BIT(huart->Instance->CR3, (USART_CR3_HDSEL | USART_CR3_IREN | USART_CR3_SCEN));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
407
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
408 /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
409 SET_BIT(huart->Instance->CR2, USART_CR2_LINEN);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
410
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
411 /* Set the USART LIN Break detection length. */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
412 MODIFY_REG(huart->Instance->CR2, USART_CR2_LBDL, BreakDetectLength);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
413
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
414 /* Enable the Peripheral */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
415 __HAL_UART_ENABLE(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
416
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
417 /* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
418 return (UART_CheckIdleState(huart));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
419 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
420
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
421
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
422 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
423 * @brief Initialize the multiprocessor mode according to the specified
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
424 * parameters in the UART_InitTypeDef and initialize the associated handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
425 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
426 * @param Address: UART node address (4-, 6-, 7- or 8-bit long).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
427 * @param WakeUpMethod: specifies the UART wakeup method.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
428 * This parameter can be one of the following values:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
429 * @arg @ref UART_WAKEUPMETHOD_IDLELINE WakeUp by an idle line detection
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
430 * @arg @ref UART_WAKEUPMETHOD_ADDRESSMARK WakeUp by an address mark
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
431 * @note If the user resorts to idle line detection wake up, the Address parameter
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
432 * is useless and ignored by the initialization function.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
433 * @note If the user resorts to address mark wake up, the address length detection
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
434 * is configured by default to 4 bits only. For the UART to be able to
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
435 * manage 6-, 7- or 8-bit long addresses detection, the API
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
436 * HAL_MultiProcessorEx_AddressLength_Set() must be called after
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
437 * HAL_MultiProcessor_Init().
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
438 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
439 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
440 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
441 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
442 /* Check the UART handle allocation */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
443 if(huart == NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
444 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
445 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
446 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
447
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
448 /* Check the wake up method parameter */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
449 assert_param(IS_UART_WAKEUPMETHOD(WakeUpMethod));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
450
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
451 if(huart->gState == HAL_UART_STATE_RESET)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
452 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
453 /* Allocate lock resource and initialize it */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
454 huart->Lock = HAL_UNLOCKED;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
455
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
456 /* Init the low level hardware : GPIO, CLOCK */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
457 HAL_UART_MspInit(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
458 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
459
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
460 huart->gState = HAL_UART_STATE_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
461
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
462 /* Disable the Peripheral */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
463 __HAL_UART_DISABLE(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
464
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
465 /* Set the UART Communication parameters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
466 if (UART_SetConfig(huart) == HAL_ERROR)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
467 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
468 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
469 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
470
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
471 if (huart->AdvancedInit.AdvFeatureInit != UART_ADVFEATURE_NO_INIT)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
472 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
473 UART_AdvFeatureConfig(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
474 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
475
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
476 /* In multiprocessor mode, the following bits must be kept cleared:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
477 - LINEN and CLKEN bits in the USART_CR2 register,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
478 - SCEN, HDSEL and IREN bits in the USART_CR3 register. */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
479 CLEAR_BIT(huart->Instance->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
480 CLEAR_BIT(huart->Instance->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
481
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
482 if (WakeUpMethod == UART_WAKEUPMETHOD_ADDRESSMARK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
483 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
484 /* If address mark wake up method is chosen, set the USART address node */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
485 MODIFY_REG(huart->Instance->CR2, USART_CR2_ADD, ((uint32_t)Address << UART_CR2_ADDRESS_LSB_POS));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
486 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
487
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
488 /* Set the wake up method by setting the WAKE bit in the CR1 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
489 MODIFY_REG(huart->Instance->CR1, USART_CR1_WAKE, WakeUpMethod);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
490
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
491 /* Enable the Peripheral */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
492 __HAL_UART_ENABLE(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
493
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
494 /* TEACK and/or REACK to check before moving huart->gState and huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
495 return (UART_CheckIdleState(huart));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
496 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
497
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
498
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
499 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
500 * @brief DeInitialize the UART peripheral.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
501 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
502 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
503 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
504 HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
505 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
506 /* Check the UART handle allocation */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
507 if(huart == NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
508 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
509 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
510 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
511
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
512 /* Check the parameters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
513 assert_param((IS_UART_INSTANCE(huart->Instance)) || (IS_LPUART_INSTANCE(huart->Instance)));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
514
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
515 huart->gState = HAL_UART_STATE_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
516
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
517 /* Disable the Peripheral */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
518 __HAL_UART_DISABLE(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
519
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
520 huart->Instance->CR1 = 0x0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
521 huart->Instance->CR2 = 0x0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
522 huart->Instance->CR3 = 0x0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
523
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
524 /* DeInit the low level hardware */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
525 HAL_UART_MspDeInit(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
526
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
527 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
528 huart->gState = HAL_UART_STATE_RESET;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
529 huart->RxState = HAL_UART_STATE_RESET;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
530
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
531 /* Process Unlock */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
532 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
533
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
534 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
535 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
536
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
537 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
538 * @brief Initialize the UART MSP.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
539 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
540 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
541 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
542 __weak void HAL_UART_MspInit(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
543 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
544 /* Prevent unused argument(s) compilation warning */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
545 UNUSED(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
546
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
547 /* NOTE : This function should not be modified, when the callback is needed,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
548 the HAL_UART_MspInit can be implemented in the user file
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
549 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
550 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
551
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
552 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
553 * @brief DeInitialize the UART MSP.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
554 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
555 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
556 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
557 __weak void HAL_UART_MspDeInit(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
558 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
559 /* Prevent unused argument(s) compilation warning */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
560 UNUSED(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
561
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
562 /* NOTE : This function should not be modified, when the callback is needed,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
563 the HAL_UART_MspDeInit can be implemented in the user file
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
564 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
565 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
566
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
567 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
568 * @}
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
569 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
570
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
571 /** @defgroup UART_Exported_Functions_Group2 IO operation functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
572 * @brief UART Transmit/Receive functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
573 *
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
574 @verbatim
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
575 ===============================================================================
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
576 ##### IO operation functions #####
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
577 ===============================================================================
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
578 This subsection provides a set of functions allowing to manage the UART asynchronous
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
579 and Half duplex data transfers.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
580
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
581 (#) There are two mode of transfer:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
582 (+) Blocking mode: The communication is performed in polling mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
583 The HAL status of all data processing is returned by the same function
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
584 after finishing transfer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
585 (+) Non-Blocking mode: The communication is performed using Interrupts
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
586 or DMA, These API's return the HAL status.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
587 The end of the data processing will be indicated through the
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
588 dedicated UART IRQ when using Interrupt mode or the DMA IRQ when
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
589 using DMA mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
590 The HAL_UART_TxCpltCallback(), HAL_UART_RxCpltCallback() user callbacks
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
591 will be executed respectively at the end of the transmit or Receive process
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
592 The HAL_UART_ErrorCallback()user callback will be executed when a communication error is detected
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
593
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
594 (#) Blocking mode API's are :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
595 (+) HAL_UART_Transmit()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
596 (+) HAL_UART_Receive()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
597
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
598 (#) Non-Blocking mode API's with Interrupt are :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
599 (+) HAL_UART_Transmit_IT()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
600 (+) HAL_UART_Receive_IT()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
601 (+) HAL_UART_IRQHandler()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
602
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
603 (#) Non-Blocking mode API's with DMA are :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
604 (+) HAL_UART_Transmit_DMA()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
605 (+) HAL_UART_Receive_DMA()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
606 (+) HAL_UART_DMAPause()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
607 (+) HAL_UART_DMAResume()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
608 (+) HAL_UART_DMAStop()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
609
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
610 (#) A set of Transfer Complete Callbacks are provided in Non_Blocking mode:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
611 (+) HAL_UART_TxHalfCpltCallback()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
612 (+) HAL_UART_TxCpltCallback()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
613 (+) HAL_UART_RxHalfCpltCallback()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
614 (+) HAL_UART_RxCpltCallback()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
615 (+) HAL_UART_ErrorCallback()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
616
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
617 (#) Non-Blocking mode transfers could be aborted using Abort API's :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
618 (+) HAL_UART_Abort()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
619 (+) HAL_UART_AbortTransmit()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
620 (+) HAL_UART_AbortReceive()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
621 (+) HAL_UART_Abort_IT()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
622 (+) HAL_UART_AbortTransmit_IT()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
623 (+) HAL_UART_AbortReceive_IT()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
624
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
625 (#) For Abort services based on interrupts (HAL_UART_Abortxxx_IT), a set of Abort Complete Callbacks are provided:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
626 (+) HAL_UART_AbortCpltCallback()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
627 (+) HAL_UART_AbortTransmitCpltCallback()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
628 (+) HAL_UART_AbortReceiveCpltCallback()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
629
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
630 (#) In Non-Blocking mode transfers, possible errors are split into 2 categories.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
631 Errors are handled as follows :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
632 (+) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
633 to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception .
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
634 Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
635 and HAL_UART_ErrorCallback() user callback is executed. Transfer is kept ongoing on UART side.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
636 If user wants to abort it, Abort services should be called by user.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
637 (+) Error is considered as Blocking : Transfer could not be completed properly and is aborted.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
638 This concerns Overrun Error In Interrupt mode reception and all errors in DMA mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
639 Error code is set to allow user to identify error type, and HAL_UART_ErrorCallback() user callback is executed.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
640
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
641 -@- In the Half duplex communication, it is forbidden to run the transmit
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
642 and receive process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX can't be useful.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
643
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
644 @endverbatim
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
645 * @{
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
646 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
647
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
648 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
649 * @brief Send an amount of data in blocking mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
650 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
651 * @param pData: Pointer to data buffer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
652 * @param Size: Amount of data to be sent.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
653 * @param Timeout: Timeout duration.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
654 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
655 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
656 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
657 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
658 uint16_t* tmp;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
659 uint32_t tickstart = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
660
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
661 /* Check that a Tx process is not already ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
662 if(huart->gState == HAL_UART_STATE_READY)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
663 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
664 if((pData == NULL ) || (Size == 0))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
665 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
666 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
667 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
668
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
669 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
670 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
671
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
672 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
673 huart->gState = HAL_UART_STATE_BUSY_TX;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
674
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
675 /* Init tickstart for timeout managment*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
676 tickstart = HAL_GetTick();
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
677
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
678 huart->TxXferSize = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
679 huart->TxXferCount = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
680 while(huart->TxXferCount > 0)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
681 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
682 huart->TxXferCount--;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
683 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
684 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
685 return HAL_TIMEOUT;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
686 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
687 if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
688 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
689 tmp = (uint16_t*) pData;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
690 huart->Instance->TDR = (*tmp & (uint16_t)0x01FF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
691 pData += 2;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
692 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
693 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
694 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
695 huart->Instance->TDR = (*pData++ & (uint8_t)0xFF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
696 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
697 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
698 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
699 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
700 return HAL_TIMEOUT;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
701 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
702
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
703 /* At end of Tx process, restore huart->gState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
704 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
705
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
706 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
707 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
708
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
709 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
710 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
711 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
712 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
713 return HAL_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
714 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
715 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
716
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
717 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
718 * @brief Receive an amount of data in blocking mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
719 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
720 * @param pData: pointer to data buffer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
721 * @param Size: amount of data to be received.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
722 * @param Timeout: Timeout duration.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
723 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
724 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
725 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
726 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
727 uint16_t* tmp;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
728 uint16_t uhMask;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
729 uint32_t tickstart = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
730
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
731 /* Check that a Rx process is not already ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
732 if(huart->RxState == HAL_UART_STATE_READY)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
733 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
734 if((pData == NULL ) || (Size == 0))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
735 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
736 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
737 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
738
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
739 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
740 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
741
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
742 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
743 huart->RxState = HAL_UART_STATE_BUSY_RX;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
744
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
745 /* Init tickstart for timeout managment*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
746 tickstart = HAL_GetTick();
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
747
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
748 huart->RxXferSize = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
749 huart->RxXferCount = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
750
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
751 /* Computation of UART mask to apply to RDR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
752 UART_MASK_COMPUTATION(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
753 uhMask = huart->Mask;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
754
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
755 /* as long as data have to be received */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
756 while(huart->RxXferCount > 0)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
757 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
758 huart->RxXferCount--;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
759 if(UART_WaitOnFlagUntilTimeout(huart, UART_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
760 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
761 return HAL_TIMEOUT;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
762 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
763 if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
764 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
765 tmp = (uint16_t*) pData ;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
766 *tmp = (uint16_t)(huart->Instance->RDR & uhMask);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
767 pData +=2;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
768 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
769 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
770 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
771 *pData++ = (uint8_t)(huart->Instance->RDR & (uint8_t)uhMask);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
772 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
773 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
774
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
775 /* At end of Rx process, restore huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
776 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
777
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
778 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
779 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
780
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
781 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
782 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
783 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
784 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
785 return HAL_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
786 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
787 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
788
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
789 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
790 * @brief Send an amount of data in interrupt mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
791 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
792 * @param pData: pointer to data buffer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
793 * @param Size: amount of data to be sent.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
794 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
795 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
796 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
797 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
798 /* Check that a Tx process is not already ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
799 if(huart->gState == HAL_UART_STATE_READY)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
800 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
801 if((pData == NULL ) || (Size == 0))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
802 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
803 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
804 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
805
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
806 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
807 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
808
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
809 huart->pTxBuffPtr = pData;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
810 huart->TxXferSize = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
811 huart->TxXferCount = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
812
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
813 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
814 huart->gState = HAL_UART_STATE_BUSY_TX;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
815
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
816 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
817 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
818
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
819 /* Enable the UART Transmit Data Register Empty Interrupt */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
820 SET_BIT(huart->Instance->CR1, USART_CR1_TXEIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
821
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
822 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
823 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
824 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
825 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
826 return HAL_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
827 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
828 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
829
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
830 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
831 * @brief Receive an amount of data in interrupt mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
832 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
833 * @param pData: pointer to data buffer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
834 * @param Size: amount of data to be received.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
835 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
836 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
837 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
838 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
839 /* Check that a Rx process is not already ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
840 if(huart->RxState == HAL_UART_STATE_READY)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
841 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
842 if((pData == NULL ) || (Size == 0))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
843 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
844 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
845 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
846
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
847 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
848 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
849
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
850 huart->pRxBuffPtr = pData;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
851 huart->RxXferSize = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
852 huart->RxXferCount = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
853
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
854 /* Computation of UART mask to apply to RDR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
855 UART_MASK_COMPUTATION(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
856
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
857 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
858 huart->RxState = HAL_UART_STATE_BUSY_RX;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
859
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
860 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
861 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
862
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
863 /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
864 SET_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
865
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
866 /* Enable the UART Parity Error and Data Register not empty Interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
867 SET_BIT(huart->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
868
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
869 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
870 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
871 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
872 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
873 return HAL_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
874 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
875 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
876
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
877 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
878 * @brief Send an amount of data in DMA mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
879 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
880 * @param pData: pointer to data buffer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
881 * @param Size: amount of data to be sent.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
882 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
883 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
884 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
885 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
886 /* Check that a Tx process is not already ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
887 if(huart->gState == HAL_UART_STATE_READY)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
888 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
889 if((pData == NULL ) || (Size == 0))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
890 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
891 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
892 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
893
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
894 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
895 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
896
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
897 huart->pTxBuffPtr = pData;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
898 huart->TxXferSize = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
899 huart->TxXferCount = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
900
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
901 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
902 huart->gState = HAL_UART_STATE_BUSY_TX;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
903
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
904 /* Set the UART DMA transfer complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
905 huart->hdmatx->XferCpltCallback = UART_DMATransmitCplt;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
906
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
907 /* Set the UART DMA Half transfer complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
908 huart->hdmatx->XferHalfCpltCallback = UART_DMATxHalfCplt;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
909
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
910 /* Set the DMA error callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
911 huart->hdmatx->XferErrorCallback = UART_DMAError;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
912
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
913 /* Set the DMA abort callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
914 huart->hdmatx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
915
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
916 /* Enable the UART transmit DMA channel */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
917 HAL_DMA_Start_IT(huart->hdmatx, (uint32_t)huart->pTxBuffPtr, (uint32_t)&huart->Instance->TDR, Size);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
918
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
919 /* Clear the TC flag in the ICR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
920 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_TCF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
921
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
922 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
923 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
924
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
925 /* Enable the DMA transfer for transmit request by setting the DMAT bit
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
926 in the UART CR3 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
927 SET_BIT(huart->Instance->CR3, USART_CR3_DMAT);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
928
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
929 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
930 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
931 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
932 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
933 return HAL_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
934 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
935 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
936
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
937 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
938 * @brief Receive an amount of data in DMA mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
939 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
940 * @param pData: pointer to data buffer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
941 * @param Size: amount of data to be received.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
942 * @note When the UART parity is enabled (PCE = 1), the received data contain
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
943 * the parity bit (MSB position).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
944 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
945 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
946 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
947 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
948 /* Check that a Rx process is not already ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
949 if(huart->RxState == HAL_UART_STATE_READY)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
950 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
951 if((pData == NULL ) || (Size == 0))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
952 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
953 return HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
954 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
955
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
956 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
957 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
958
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
959 huart->pRxBuffPtr = pData;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
960 huart->RxXferSize = Size;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
961
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
962 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
963 huart->RxState = HAL_UART_STATE_BUSY_RX;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
964
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
965 /* Set the UART DMA transfer complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
966 huart->hdmarx->XferCpltCallback = UART_DMAReceiveCplt;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
967
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
968 /* Set the UART DMA Half transfer complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
969 huart->hdmarx->XferHalfCpltCallback = UART_DMARxHalfCplt;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
970
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
971 /* Set the DMA error callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
972 huart->hdmarx->XferErrorCallback = UART_DMAError;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
973
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
974 /* Set the DMA abort callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
975 huart->hdmarx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
976
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
977 /* Enable the DMA channel */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
978 HAL_DMA_Start_IT(huart->hdmarx, (uint32_t)&huart->Instance->RDR, (uint32_t)huart->pRxBuffPtr, Size);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
979
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
980 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
981 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
982
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
983 /* Enable the UART Parity Error Interrupt */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
984 SET_BIT(huart->Instance->CR1, USART_CR1_PEIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
985
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
986 /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
987 SET_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
988
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
989 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
990 in the UART CR3 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
991 SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
992
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
993 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
994 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
995 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
996 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
997 return HAL_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
998 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
999 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1000
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1001 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1002 * @brief Pause the DMA Transfer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1003 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1004 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1005 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1006 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1007 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1008 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1009 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1010
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1011 if ((huart->gState == HAL_UART_STATE_BUSY_TX) &&
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1012 (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1013 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1014 /* Disable the UART DMA Tx request */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1015 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1016 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1017 if ((huart->RxState == HAL_UART_STATE_BUSY_RX) &&
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1018 (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1019 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1020 /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1021 CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1022 CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1023
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1024 /* Disable the UART DMA Rx request */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1025 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1026 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1027
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1028 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1029 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1030
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1031 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1032 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1033
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1034 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1035 * @brief Resume the DMA Transfer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1036 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1037 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1038 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1039 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1040 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1041 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1042 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1043
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1044 if(huart->gState == HAL_UART_STATE_BUSY_TX)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1045 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1046 /* Enable the UART DMA Tx request */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1047 SET_BIT(huart->Instance->CR3, USART_CR3_DMAT);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1048 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1049 if(huart->RxState == HAL_UART_STATE_BUSY_RX)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1050 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1051 /* Clear the Overrun flag before resuming the Rx transfer */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1052 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1053
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1054 /* Reenable PE and ERR (Frame error, noise error, overrun error) interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1055 SET_BIT(huart->Instance->CR1, USART_CR1_PEIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1056 SET_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1057
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1058 /* Enable the UART DMA Rx request */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1059 SET_BIT(huart->Instance->CR3, USART_CR3_DMAR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1060 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1061
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1062 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1063 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1064
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1065 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1066 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1067
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1068 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1069 * @brief Stop the DMA Transfer.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1070 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1071 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1072 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1073 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1074 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1075 /* The Lock is not implemented on this API to allow the user application
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1076 to call the HAL UART API under callbacks HAL_UART_TxCpltCallback() / HAL_UART_RxCpltCallback() /
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1077 HAL_UART_TxHalfCpltCallback / HAL_UART_RxHalfCpltCallback:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1078 indeed, when HAL_DMA_Abort() API is called, the DMA TX/RX Transfer or Half Transfer complete
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1079 interrupt is generated if the DMA transfer interruption occurs at the middle or at the end of
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1080 the stream and the corresponding call back is executed. */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1081
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1082 /* Stop UART DMA Tx request if ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1083 if ((huart->gState == HAL_UART_STATE_BUSY_TX) &&
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1084 (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1085 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1086 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1087
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1088 /* Abort the UART DMA Tx channel */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1089 if(huart->hdmatx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1090 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1091 HAL_DMA_Abort(huart->hdmatx);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1092 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1093
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1094 UART_EndTxTransfer(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1095 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1096
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1097 /* Stop UART DMA Rx request if ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1098 if ((huart->RxState == HAL_UART_STATE_BUSY_RX) &&
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1099 (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1100 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1101 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1102
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1103 /* Abort the UART DMA Rx channel */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1104 if(huart->hdmarx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1105 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1106 HAL_DMA_Abort(huart->hdmarx);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1107 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1108
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1109 UART_EndRxTransfer(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1110 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1111
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1112 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1113 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1114
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1115 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1116 * @brief Abort ongoing transfers (blocking mode).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1117 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1118 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1119 * This procedure performs following operations :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1120 * - Disable UART Interrupts (Tx and Rx)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1121 * - Disable the DMA transfer in the peripheral register (if enabled)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1122 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1123 * - Set handle State to READY
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1124 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1125 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1126 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1127 HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1128 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1129 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1130 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1131 CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1132
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1133 /* Disable the UART DMA Tx request if enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1134 if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1135 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1136 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1137
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1138 /* Abort the UART DMA Tx channel : use blocking DMA Abort API (no callback) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1139 if(huart->hdmatx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1140 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1141 /* Set the UART DMA Abort callback to Null.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1142 No call back execution at end of DMA abort procedure */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1143 huart->hdmatx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1144
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1145 HAL_DMA_Abort(huart->hdmatx);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1146 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1147 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1148
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1149 /* Disable the UART DMA Rx request if enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1150 if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1151 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1152 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1153
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1154 /* Abort the UART DMA Rx channel : use blocking DMA Abort API (no callback) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1155 if(huart->hdmarx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1156 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1157 /* Set the UART DMA Abort callback to Null.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1158 No call back execution at end of DMA abort procedure */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1159 huart->hdmarx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1160
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1161 HAL_DMA_Abort(huart->hdmarx);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1162 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1163 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1164
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1165 /* Reset Tx and Rx transfer counters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1166 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1167 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1168
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1169 /* Clear the Error flags in the ICR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1170 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF | UART_CLEAR_NEF | UART_CLEAR_PEF | UART_CLEAR_FEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1171
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1172 /* Restore huart->gState and huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1173 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1174 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1175
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1176 /* Reset Handle ErrorCode to No Error */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1177 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1178
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1179 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1180 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1181
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1182 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1183 * @brief Abort ongoing Transmit transfer (blocking mode).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1184 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1185 * @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1186 * This procedure performs following operations :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1187 * - Disable UART Interrupts (Tx)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1188 * - Disable the DMA transfer in the peripheral register (if enabled)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1189 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1190 * - Set handle State to READY
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1191 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1192 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1193 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1194 HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1195 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1196 /* Disable TXEIE and TCIE interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1197 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1198
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1199 /* Disable the UART DMA Tx request if enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1200 if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1201 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1202 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1203
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1204 /* Abort the UART DMA Tx channel : use blocking DMA Abort API (no callback) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1205 if(huart->hdmatx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1206 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1207 /* Set the UART DMA Abort callback to Null.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1208 No call back execution at end of DMA abort procedure */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1209 huart->hdmatx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1210
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1211 HAL_DMA_Abort(huart->hdmatx);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1212 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1213 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1214
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1215 /* Reset Tx transfer counter */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1216 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1217
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1218 /* Restore huart->gState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1219 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1220
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1221 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1222 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1223
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1224 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1225 * @brief Abort ongoing Receive transfer (blocking mode).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1226 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1227 * @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1228 * This procedure performs following operations :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1229 * - Disable UART Interrupts (Rx)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1230 * - Disable the DMA transfer in the peripheral register (if enabled)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1231 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1232 * - Set handle State to READY
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1233 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1234 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1235 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1236 HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1237 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1238 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1239 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1240 CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1241
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1242 /* Disable the UART DMA Rx request if enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1243 if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1244 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1245 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1246
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1247 /* Abort the UART DMA Rx channel : use blocking DMA Abort API (no callback) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1248 if(huart->hdmarx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1249 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1250 /* Set the UART DMA Abort callback to Null.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1251 No call back execution at end of DMA abort procedure */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1252 huart->hdmarx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1253
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1254 HAL_DMA_Abort(huart->hdmarx);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1255 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1256 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1257
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1258 /* Reset Rx transfer counter */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1259 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1260
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1261 /* Clear the Error flags in the ICR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1262 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF | UART_CLEAR_NEF | UART_CLEAR_PEF | UART_CLEAR_FEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1263
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1264 /* Restore huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1265 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1266
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1267 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1268 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1269
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1270 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1271 * @brief Abort ongoing transfers (Interrupt mode).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1272 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1273 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1274 * This procedure performs following operations :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1275 * - Disable UART Interrupts (Tx and Rx)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1276 * - Disable the DMA transfer in the peripheral register (if enabled)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1277 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1278 * - Set handle State to READY
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1279 * - At abort completion, call user abort complete callback
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1280 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1281 * considered as completed only when user abort complete callback is executed (not when exiting function).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1282 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1283 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1284 HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1285 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1286 uint32_t abortcplt = 1;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1287
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1288 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1289 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1290 CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1291
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1292 /* If DMA Tx and/or DMA Rx Handles are associated to UART Handle, DMA Abort complete callbacks should be initialised
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1293 before any call to DMA Abort functions */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1294 /* DMA Tx Handle is valid */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1295 if(huart->hdmatx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1296 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1297 /* Set DMA Abort Complete callback if UART DMA Tx request if enabled.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1298 Otherwise, set it to NULL */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1299 if(HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1300 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1301 huart->hdmatx->XferAbortCallback = UART_DMATxAbortCallback;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1302 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1303 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1304 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1305 huart->hdmatx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1306 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1307 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1308 /* DMA Rx Handle is valid */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1309 if(huart->hdmarx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1310 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1311 /* Set DMA Abort Complete callback if UART DMA Rx request if enabled.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1312 Otherwise, set it to NULL */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1313 if(HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1314 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1315 huart->hdmarx->XferAbortCallback = UART_DMARxAbortCallback;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1316 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1317 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1318 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1319 huart->hdmarx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1320 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1321 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1322
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1323 /* Disable the UART DMA Tx request if enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1324 if(HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1325 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1326 /* Disable DMA Tx at UART level */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1327 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1328
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1329 /* Abort the UART DMA Tx channel : use non blocking DMA Abort API (callback) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1330 if(huart->hdmatx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1331 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1332 /* UART Tx DMA Abort callback has already been initialised :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1333 will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1334
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1335 /* Abort DMA TX */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1336 if(HAL_DMA_Abort_IT(huart->hdmatx) != HAL_OK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1337 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1338 huart->hdmatx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1339 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1340 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1341 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1342 abortcplt = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1343 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1344 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1345 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1346
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1347 /* Disable the UART DMA Rx request if enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1348 if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1349 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1350 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1351
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1352 /* Abort the UART DMA Rx channel : use non blocking DMA Abort API (callback) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1353 if(huart->hdmarx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1354 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1355 /* UART Rx DMA Abort callback has already been initialised :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1356 will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1357
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1358 /* Abort DMA RX */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1359 if(HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1360 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1361 huart->hdmarx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1362 abortcplt = 1;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1363 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1364 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1365 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1366 abortcplt = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1367 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1368 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1369 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1370
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1371 /* if no DMA abort complete callback execution is required => call user Abort Complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1372 if (abortcplt == 1)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1373 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1374 /* Reset Tx and Rx transfer counters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1375 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1376 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1377
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1378 /* Reset errorCode */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1379 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1380
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1381 /* Clear the Error flags in the ICR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1382 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF | UART_CLEAR_NEF | UART_CLEAR_PEF | UART_CLEAR_FEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1383
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1384 /* Restore huart->gState and huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1385 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1386 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1387
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1388 /* As no DMA to be aborted, call directly user Abort complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1389 HAL_UART_AbortCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1390 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1391
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1392 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1393 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1394
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1395 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1396 * @brief Abort ongoing Transmit transfer (Interrupt mode).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1397 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1398 * @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1399 * This procedure performs following operations :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1400 * - Disable UART Interrupts (Tx)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1401 * - Disable the DMA transfer in the peripheral register (if enabled)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1402 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1403 * - Set handle State to READY
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1404 * - At abort completion, call user abort complete callback
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1405 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1406 * considered as completed only when user abort complete callback is executed (not when exiting function).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1407 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1408 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1409 HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1410 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1411 /* Disable TXEIE and TCIE interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1412 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1413
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1414 /* Disable the UART DMA Tx request if enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1415 if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1416 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1417 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1418
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1419 /* Abort the UART DMA Tx channel : use non blocking DMA Abort API (callback) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1420 if(huart->hdmatx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1421 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1422 /* Set the UART DMA Abort callback :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1423 will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1424 huart->hdmatx->XferAbortCallback = UART_DMATxOnlyAbortCallback;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1425
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1426 /* Abort DMA TX */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1427 if(HAL_DMA_Abort_IT(huart->hdmatx) != HAL_OK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1428 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1429 /* Call Directly huart->hdmatx->XferAbortCallback function in case of error */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1430 huart->hdmatx->XferAbortCallback(huart->hdmatx);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1431 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1432 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1433 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1434 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1435 /* Reset Tx transfer counter */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1436 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1437
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1438 /* Restore huart->gState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1439 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1440
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1441 /* As no DMA to be aborted, call directly user Abort complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1442 HAL_UART_AbortTransmitCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1443 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1444 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1445 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1446 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1447 /* Reset Tx transfer counter */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1448 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1449
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1450 /* Restore huart->gState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1451 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1452
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1453 /* As no DMA to be aborted, call directly user Abort complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1454 HAL_UART_AbortTransmitCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1455 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1456
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1457 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1458 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1459
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1460 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1461 * @brief Abort ongoing Receive transfer (Interrupt mode).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1462 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1463 * @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1464 * This procedure performs following operations :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1465 * - Disable UART Interrupts (Rx)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1466 * - Disable the DMA transfer in the peripheral register (if enabled)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1467 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1468 * - Set handle State to READY
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1469 * - At abort completion, call user abort complete callback
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1470 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1471 * considered as completed only when user abort complete callback is executed (not when exiting function).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1472 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1473 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1474 HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1475 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1476 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1477 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1478 CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1479
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1480 /* Disable the UART DMA Rx request if enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1481 if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1482 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1483 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1484
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1485 /* Abort the UART DMA Rx channel : use non blocking DMA Abort API (callback) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1486 if(huart->hdmarx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1487 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1488 /* Set the UART DMA Abort callback :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1489 will lead to call HAL_UART_AbortCpltCallback() at end of DMA abort procedure */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1490 huart->hdmarx->XferAbortCallback = UART_DMARxOnlyAbortCallback;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1491
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1492 /* Abort DMA RX */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1493 if(HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1494 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1495 /* Call Directly huart->hdmarx->XferAbortCallback function in case of error */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1496 huart->hdmarx->XferAbortCallback(huart->hdmarx);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1497 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1498 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1499 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1500 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1501 /* Reset Rx transfer counter */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1502 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1503
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1504 /* Clear the Error flags in the ICR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1505 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF | UART_CLEAR_NEF | UART_CLEAR_PEF | UART_CLEAR_FEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1506
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1507 /* Restore huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1508 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1509
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1510 /* As no DMA to be aborted, call directly user Abort complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1511 HAL_UART_AbortReceiveCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1512 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1513 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1514 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1515 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1516 /* Reset Rx transfer counter */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1517 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1518
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1519 /* Clear the Error flags in the ICR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1520 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF | UART_CLEAR_NEF | UART_CLEAR_PEF | UART_CLEAR_FEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1521
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1522 /* Restore huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1523 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1524
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1525 /* As no DMA to be aborted, call directly user Abort complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1526 HAL_UART_AbortReceiveCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1527 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1528
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1529 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1530 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1531
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1532 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1533 * @brief Handle UART interrupt request.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1534 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1535 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1536 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1537 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1538 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1539 uint32_t isrflags = READ_REG(huart->Instance->ISR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1540 uint32_t cr1its = READ_REG(huart->Instance->CR1);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1541 uint32_t cr3its;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1542 uint32_t errorflags;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1543
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1544 /* If no error occurs */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1545 errorflags = (isrflags & (uint32_t)(USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1546 if (errorflags == RESET)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1547 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1548 /* UART in mode Receiver ---------------------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1549 if(((isrflags & USART_ISR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1550 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1551 UART_Receive_IT(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1552 return;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1553 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1554 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1555
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1556 /* If some errors occur */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1557 cr3its = READ_REG(huart->Instance->CR3);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1558 if( (errorflags != RESET)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1559 && ( ((cr3its & USART_CR3_EIE) != RESET)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1560 || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)) )
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1561 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1562 /* UART parity error interrupt occurred -------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1563 if(((isrflags & USART_ISR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1564 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1565 __HAL_UART_CLEAR_IT(huart, UART_CLEAR_PEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1566
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1567 huart->ErrorCode |= HAL_UART_ERROR_PE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1568 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1569
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1570 /* UART frame error interrupt occurred --------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1571 if(((isrflags & USART_ISR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1572 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1573 __HAL_UART_CLEAR_IT(huart, UART_CLEAR_FEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1574
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1575 huart->ErrorCode |= HAL_UART_ERROR_FE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1576 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1577
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1578 /* UART noise error interrupt occurred --------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1579 if(((isrflags & USART_ISR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1580 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1581 __HAL_UART_CLEAR_IT(huart, UART_CLEAR_NEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1582
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1583 huart->ErrorCode |= HAL_UART_ERROR_NE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1584 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1585
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1586 /* UART Over-Run interrupt occurred -----------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1587 if(((isrflags & USART_ISR_ORE) != RESET) &&
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1588 (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET)))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1589 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1590 __HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1591
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1592 huart->ErrorCode |= HAL_UART_ERROR_ORE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1593 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1594
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1595 /* Call UART Error Call back function if need be --------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1596 if(huart->ErrorCode != HAL_UART_ERROR_NONE)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1597 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1598 /* UART in mode Receiver ---------------------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1599 if(((isrflags & USART_ISR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1600 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1601 UART_Receive_IT(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1602 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1603
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1604 /* If Overrun error occurs, or if any error occurs in DMA mode reception,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1605 consider error as blocking */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1606 if (((huart->ErrorCode & HAL_UART_ERROR_ORE) != RESET) ||
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1607 (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1608 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1609 /* Blocking error : transfer is aborted
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1610 Set the UART state ready to be able to start again the process,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1611 Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1612 UART_EndRxTransfer(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1613
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1614 /* Disable the UART DMA Rx request if enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1615 if (HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1616 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1617 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1618
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1619 /* Abort the UART DMA Rx channel */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1620 if(huart->hdmarx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1621 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1622 /* Set the UART DMA Abort callback :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1623 will lead to call HAL_UART_ErrorCallback() at end of DMA abort procedure */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1624 huart->hdmarx->XferAbortCallback = UART_DMAAbortOnError;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1625
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1626 /* Abort DMA RX */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1627 if(HAL_DMA_Abort_IT(huart->hdmarx) != HAL_OK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1628 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1629 /* Call Directly huart->hdmarx->XferAbortCallback function in case of error */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1630 huart->hdmarx->XferAbortCallback(huart->hdmarx);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1631 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1632 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1633 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1634 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1635 /* Call user error callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1636 HAL_UART_ErrorCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1637 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1638 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1639 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1640 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1641 /* Call user error callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1642 HAL_UART_ErrorCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1643 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1644 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1645 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1646 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1647 /* Non Blocking error : transfer could go on.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1648 Error is notified to user through user error callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1649 HAL_UART_ErrorCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1650 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1651 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1652 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1653 return;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1654
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1655 } /* End if some error occurs */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1656
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1657 /* UART wakeup from Stop mode interrupt occurred ---------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1658 cr3its = READ_REG(huart->Instance->CR3);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1659 if(((isrflags & USART_ISR_WUF) != RESET) && ((cr3its & USART_CR3_WUFIE) != RESET))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1660 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1661 __HAL_UART_CLEAR_IT(huart, UART_CLEAR_WUF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1662 /* Set the UART state ready to be able to start again the process */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1663 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1664 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1665 HAL_UARTEx_WakeupCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1666 return;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1667 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1668
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1669 /* UART in mode Transmitter ------------------------------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1670 if(((isrflags & USART_ISR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1671 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1672 UART_Transmit_IT(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1673 return;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1674 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1675
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1676 /* UART in mode Transmitter (transmission end) -----------------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1677 if(((isrflags & USART_ISR_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1678 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1679 UART_EndTransmit_IT(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1680 return;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1681 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1682
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1683 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1684
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1685 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1686 * @brief Tx Transfer completed callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1687 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1688 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1689 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1690 __weak void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1691 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1692 /* Prevent unused argument(s) compilation warning */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1693 UNUSED(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1694
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1695 /* NOTE : This function should not be modified, when the callback is needed,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1696 the HAL_UART_TxCpltCallback can be implemented in the user file.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1697 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1698 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1699
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1700 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1701 * @brief Tx Half Transfer completed callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1702 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1703 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1704 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1705 __weak void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1706 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1707 /* Prevent unused argument(s) compilation warning */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1708 UNUSED(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1709
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1710 /* NOTE: This function should not be modified, when the callback is needed,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1711 the HAL_UART_TxHalfCpltCallback can be implemented in the user file.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1712 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1713 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1714
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1715 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1716 * @brief Rx Transfer completed callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1717 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1718 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1719 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1720 __weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1721 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1722 /* Prevent unused argument(s) compilation warning */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1723 UNUSED(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1724
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1725 /* NOTE : This function should not be modified, when the callback is needed,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1726 the HAL_UART_RxCpltCallback can be implemented in the user file.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1727 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1728 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1729
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1730 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1731 * @brief Rx Half Transfer completed callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1732 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1733 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1734 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1735 __weak void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1736 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1737 /* Prevent unused argument(s) compilation warning */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1738 UNUSED(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1739
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1740 /* NOTE: This function should not be modified, when the callback is needed,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1741 the HAL_UART_RxHalfCpltCallback can be implemented in the user file.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1742 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1743 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1744
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1745 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1746 * @brief UART error callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1747 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1748 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1749 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1750 __weak void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1751 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1752 /* Prevent unused argument(s) compilation warning */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1753 UNUSED(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1754
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1755 /* NOTE : This function should not be modified, when the callback is needed,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1756 the HAL_UART_ErrorCallback can be implemented in the user file.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1757 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1758 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1759
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1760 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1761 * @brief UART Abort Complete callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1762 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1763 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1764 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1765 __weak void HAL_UART_AbortCpltCallback (UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1766 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1767 /* Prevent unused argument(s) compilation warning */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1768 UNUSED(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1769
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1770 /* NOTE : This function should not be modified, when the callback is needed,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1771 the HAL_UART_AbortCpltCallback can be implemented in the user file.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1772 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1773 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1774
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1775 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1776 * @brief UART Abort Complete callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1777 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1778 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1779 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1780 __weak void HAL_UART_AbortTransmitCpltCallback (UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1781 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1782 /* Prevent unused argument(s) compilation warning */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1783 UNUSED(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1784
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1785 /* NOTE : This function should not be modified, when the callback is needed,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1786 the HAL_UART_AbortTransmitCpltCallback can be implemented in the user file.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1787 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1788 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1789
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1790 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1791 * @brief UART Abort Receive Complete callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1792 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1793 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1794 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1795 __weak void HAL_UART_AbortReceiveCpltCallback (UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1796 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1797 /* Prevent unused argument(s) compilation warning */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1798 UNUSED(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1799
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1800 /* NOTE : This function should not be modified, when the callback is needed,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1801 the HAL_UART_AbortReceiveCpltCallback can be implemented in the user file.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1802 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1803 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1804
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1805 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1806 * @}
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1807 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1808
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1809 /** @defgroup UART_Exported_Functions_Group3 Peripheral Control functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1810 * @brief UART control functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1811 *
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1812 @verbatim
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1813 ===============================================================================
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1814 ##### Peripheral Control functions #####
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1815 ===============================================================================
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1816 [..]
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1817 This subsection provides a set of functions allowing to control the UART.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1818 (+) HAL_MultiProcessor_EnableMuteMode() API enables mute mode
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1819 (+) HAL_MultiProcessor_DisableMuteMode() API disables mute mode
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1820 (+) HAL_MultiProcessor_EnterMuteMode() API enters mute mode
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1821 (+) UART_SetConfig() API configures the UART peripheral
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1822 (+) UART_AdvFeatureConfig() API optionally configures the UART advanced features
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1823 (+) UART_CheckIdleState() API ensures that TEACK and/or REACK are set after initialization
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1824 (+) HAL_HalfDuplex_EnableTransmitter() API disables receiver and enables transmitter
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1825 (+) HAL_HalfDuplex_EnableReceiver() API disables transmitter and enables receiver
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1826 (+) HAL_LIN_SendBreak() API transmits the break characters
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1827 @endverbatim
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1828 * @{
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1829 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1830
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1831 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1832 * @brief Enable UART in mute mode (does not mean UART enters mute mode;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1833 * to enter mute mode, HAL_MultiProcessor_EnterMuteMode() API must be called).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1834 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1835 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1836 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1837 HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1838 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1839 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1840 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1841
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1842 huart->gState = HAL_UART_STATE_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1843
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1844 /* Enable USART mute mode by setting the MME bit in the CR1 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1845 SET_BIT(huart->Instance->CR1, USART_CR1_MME);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1846
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1847 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1848
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1849 return (UART_CheckIdleState(huart));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1850 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1851
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1852 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1853 * @brief Disable UART mute mode (does not mean the UART actually exits mute mode
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1854 * as it may not have been in mute mode at this very moment).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1855 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1856 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1857 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1858 HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1859 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1860 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1861 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1862
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1863 huart->gState = HAL_UART_STATE_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1864
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1865 /* Disable USART mute mode by clearing the MME bit in the CR1 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1866 CLEAR_BIT(huart->Instance->CR1, USART_CR1_MME);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1867
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1868 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1869
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1870 return (UART_CheckIdleState(huart));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1871 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1872
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1873 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1874 * @brief Enter UART mute mode (means UART actually enters mute mode).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1875 * @note To exit from mute mode, HAL_MultiProcessor_DisableMuteMode() API must be called.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1876 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1877 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1878 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1879 void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1880 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1881 __HAL_UART_SEND_REQ(huart, UART_MUTE_MODE_REQUEST);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1882 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1883
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1884 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1885 * @brief Enable the UART transmitter and disable the UART receiver.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1886 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1887 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1888 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1889 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1890 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1891 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1892 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1893 huart->gState = HAL_UART_STATE_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1894
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1895 /* Clear TE and RE bits */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1896 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TE | USART_CR1_RE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1897 /* Enable the USART's transmit interface by setting the TE bit in the USART CR1 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1898 SET_BIT(huart->Instance->CR1, USART_CR1_TE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1899
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1900 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1901
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1902 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1903 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1904
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1905 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1906 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1907
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1908 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1909 * @brief Enable the UART receiver and disable the UART transmitter.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1910 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1911 * @retval HAL status.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1912 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1913 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1914 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1915 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1916 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1917 huart->gState = HAL_UART_STATE_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1918
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1919 /* Clear TE and RE bits */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1920 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TE | USART_CR1_RE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1921 /* Enable the USART's receive interface by setting the RE bit in the USART CR1 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1922 SET_BIT(huart->Instance->CR1, USART_CR1_RE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1923
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1924 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1925 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1926 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1927
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1928 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1929 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1930
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1931
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1932 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1933 * @brief Transmit break characters.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1934 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1935 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1936 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1937 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1938 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1939 /* Check the parameters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1940 assert_param(IS_UART_LIN_INSTANCE(huart->Instance));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1941
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1942 /* Process Locked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1943 __HAL_LOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1944
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1945 huart->gState = HAL_UART_STATE_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1946
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1947 /* Send break characters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1948 huart->Instance->RQR |= UART_SENDBREAK_REQUEST;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1949
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1950 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1951
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1952 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1953 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1954
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1955 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1956 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1957
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1958
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1959 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1960 * @}
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1961 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1962
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1963 /** @defgroup UART_Exported_Functions_Group4 Peripheral State and Error functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1964 * @brief UART Peripheral State functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1965 *
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1966 @verbatim
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1967 ==============================================================================
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1968 ##### Peripheral State and Error functions #####
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1969 ==============================================================================
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1970 [..]
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1971 This subsection provides functions allowing to :
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1972 (+) Return the UART handle state.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1973 (+) Return the UART handle error code
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1974
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1975 @endverbatim
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1976 * @{
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1977 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1978
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1979 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1980 * @brief Return the UART handle state.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1981 * @param huart Pointer to a UART_HandleTypeDef structure that contains
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1982 * the configuration information for the specified UART.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1983 * @retval HAL state
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1984 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1985 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1986 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1987 uint32_t temp1= 0x00, temp2 = 0x00;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1988 temp1 = huart->gState;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1989 temp2 = huart->RxState;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1990
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1991 return (HAL_UART_StateTypeDef)(temp1 | temp2);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1992 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1993
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1994 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1995 * @brief Return the UART handle error code.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1996 * @param huart Pointer to a UART_HandleTypeDef structure that contains
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1997 * the configuration information for the specified UART.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1998 * @retval UART Error Code
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
1999 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2000 uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2001 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2002 return huart->ErrorCode;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2003 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2004 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2005 * @}
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2006 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2007
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2008 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2009 * @}
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2010 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2011
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2012 /** @defgroup UART_Private_Functions UART Private Functions
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2013 * @{
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2014 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2015
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2016 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2017 * @brief Configure the UART peripheral.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2018 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2019 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2020 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2021 HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2022 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2023 uint32_t tmpreg = 0x00000000;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2024 UART_ClockSourceTypeDef clocksource = UART_CLOCKSOURCE_UNDEFINED;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2025 uint16_t brrtemp = 0x0000;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2026 uint16_t usartdiv = 0x0000;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2027 HAL_StatusTypeDef ret = HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2028
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2029 /* Check the parameters */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2030 assert_param(IS_UART_BAUDRATE(huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2031 assert_param(IS_UART_WORD_LENGTH(huart->Init.WordLength));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2032 if(UART_INSTANCE_LOWPOWER(huart))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2033 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2034 assert_param(IS_LPUART_STOPBITS(huart->Init.StopBits));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2035 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2036 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2037 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2038 assert_param(IS_UART_STOPBITS(huart->Init.StopBits));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2039 assert_param(IS_UART_ONE_BIT_SAMPLE(huart->Init.OneBitSampling));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2040 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2041
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2042 assert_param(IS_UART_PARITY(huart->Init.Parity));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2043 assert_param(IS_UART_MODE(huart->Init.Mode));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2044 assert_param(IS_UART_HARDWARE_FLOW_CONTROL(huart->Init.HwFlowCtl));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2045 assert_param(IS_UART_OVERSAMPLING(huart->Init.OverSampling));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2046
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2047
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2048 /*-------------------------- USART CR1 Configuration -----------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2049 /* Clear M, PCE, PS, TE, RE and OVER8 bits and configure
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2050 * the UART Word Length, Parity, Mode and oversampling:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2051 * set the M bits according to huart->Init.WordLength value
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2052 * set PCE and PS bits according to huart->Init.Parity value
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2053 * set TE and RE bits according to huart->Init.Mode value
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2054 * set OVER8 bit according to huart->Init.OverSampling value */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2055 tmpreg = (uint32_t)huart->Init.WordLength | huart->Init.Parity | huart->Init.Mode | huart->Init.OverSampling ;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2056 MODIFY_REG(huart->Instance->CR1, UART_CR1_FIELDS, tmpreg);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2057
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2058 /*-------------------------- USART CR2 Configuration -----------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2059 /* Configure the UART Stop Bits: Set STOP[13:12] bits according
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2060 * to huart->Init.StopBits value */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2061 MODIFY_REG(huart->Instance->CR2, USART_CR2_STOP, huart->Init.StopBits);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2062
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2063 /*-------------------------- USART CR3 Configuration -----------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2064 /* Configure
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2065 * - UART HardWare Flow Control: set CTSE and RTSE bits according
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2066 * to huart->Init.HwFlowCtl value
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2067 * - one-bit sampling method versus three samples' majority rule according
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2068 * to huart->Init.OneBitSampling (not applicable to LPUART) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2069 tmpreg = (uint32_t)huart->Init.HwFlowCtl;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2070 if (!(UART_INSTANCE_LOWPOWER(huart)))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2071 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2072 tmpreg |= huart->Init.OneBitSampling;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2073 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2074 MODIFY_REG(huart->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE | USART_CR3_ONEBIT), tmpreg);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2075
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2076 /*-------------------------- USART BRR Configuration -----------------------*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2077 UART_GETCLOCKSOURCE(huart, clocksource);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2078
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2079 /* Check LPUART instance */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2080 if(UART_INSTANCE_LOWPOWER(huart))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2081 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2082 /* Retrieve frequency clock */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2083 tmpreg = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2084
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2085 switch (clocksource)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2086 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2087 case UART_CLOCKSOURCE_PCLK1:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2088 tmpreg = HAL_RCC_GetPCLK1Freq();
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2089 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2090 case UART_CLOCKSOURCE_HSI:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2091 tmpreg = (uint32_t) HSI_VALUE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2092 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2093 case UART_CLOCKSOURCE_SYSCLK:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2094 tmpreg = HAL_RCC_GetSysClockFreq();
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2095 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2096 case UART_CLOCKSOURCE_LSE:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2097 tmpreg = (uint32_t) LSE_VALUE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2098 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2099 case UART_CLOCKSOURCE_UNDEFINED:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2100 default:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2101 ret = HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2102 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2103 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2104
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2105 /* if proper clock source reported */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2106 if (tmpreg != 0)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2107 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2108 /* ensure that Frequency clock is in the range [3 * baudrate, 4096 * baudrate] */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2109 if ( (tmpreg < (3 * huart->Init.BaudRate) ) ||
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2110 (tmpreg > (4096 * huart->Init.BaudRate) ))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2111 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2112 ret = HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2113 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2114 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2115 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2116 switch (clocksource)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2117 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2118 case UART_CLOCKSOURCE_PCLK1:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2119 tmpreg = (uint32_t)(UART_DIV_LPUART(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2120 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2121 case UART_CLOCKSOURCE_HSI:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2122 tmpreg = (uint32_t)(UART_DIV_LPUART(HSI_VALUE, huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2123 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2124 case UART_CLOCKSOURCE_SYSCLK:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2125 tmpreg = (uint32_t)(UART_DIV_LPUART(HAL_RCC_GetSysClockFreq(), huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2126 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2127 case UART_CLOCKSOURCE_LSE:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2128 tmpreg = (uint32_t)(UART_DIV_LPUART(LSE_VALUE, huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2129 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2130 case UART_CLOCKSOURCE_UNDEFINED:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2131 default:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2132 ret = HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2133 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2134 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2135
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2136 if ((tmpreg >= UART_LPUART_BRR_MIN) && (tmpreg <= UART_LPUART_BRR_MAX))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2137 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2138 huart->Instance->BRR = tmpreg;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2139 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2140 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2141 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2142 ret = HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2143 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2144 } /* if ( (tmpreg < (3 * huart->Init.BaudRate) ) || (tmpreg > (4096 * huart->Init.BaudRate) )) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2145 } /* if (tmpreg != 0) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2146 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2147 /* Check UART Over Sampling to set Baud Rate Register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2148 else if (huart->Init.OverSampling == UART_OVERSAMPLING_8)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2149 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2150 switch (clocksource)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2151 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2152 case UART_CLOCKSOURCE_PCLK1:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2153 usartdiv = (uint16_t)(UART_DIV_SAMPLING8(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2154 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2155 case UART_CLOCKSOURCE_PCLK2:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2156 usartdiv = (uint16_t)(UART_DIV_SAMPLING8(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2157 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2158 case UART_CLOCKSOURCE_HSI:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2159 usartdiv = (uint16_t)(UART_DIV_SAMPLING8(HSI_VALUE, huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2160 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2161 case UART_CLOCKSOURCE_SYSCLK:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2162 usartdiv = (uint16_t)(UART_DIV_SAMPLING8(HAL_RCC_GetSysClockFreq(), huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2163 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2164 case UART_CLOCKSOURCE_LSE:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2165 usartdiv = (uint16_t)(UART_DIV_SAMPLING8(LSE_VALUE, huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2166 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2167 case UART_CLOCKSOURCE_UNDEFINED:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2168 default:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2169 ret = HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2170 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2171 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2172
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2173 brrtemp = usartdiv & 0xFFF0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2174 brrtemp |= (uint16_t)((usartdiv & (uint16_t)0x000F) >> 1U);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2175 huart->Instance->BRR = brrtemp;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2176 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2177 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2178 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2179 switch (clocksource)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2180 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2181 case UART_CLOCKSOURCE_PCLK1:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2182 huart->Instance->BRR = (uint16_t)(UART_DIV_SAMPLING16(HAL_RCC_GetPCLK1Freq(), huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2183 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2184 case UART_CLOCKSOURCE_PCLK2:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2185 huart->Instance->BRR = (uint16_t)(UART_DIV_SAMPLING16(HAL_RCC_GetPCLK2Freq(), huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2186 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2187 case UART_CLOCKSOURCE_HSI:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2188 huart->Instance->BRR = (uint16_t)(UART_DIV_SAMPLING16(HSI_VALUE, huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2189 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2190 case UART_CLOCKSOURCE_SYSCLK:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2191 huart->Instance->BRR = (uint16_t)(UART_DIV_SAMPLING16(HAL_RCC_GetSysClockFreq(), huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2192 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2193 case UART_CLOCKSOURCE_LSE:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2194 huart->Instance->BRR = (uint16_t)(UART_DIV_SAMPLING16(LSE_VALUE, huart->Init.BaudRate));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2195 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2196 case UART_CLOCKSOURCE_UNDEFINED:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2197 default:
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2198 ret = HAL_ERROR;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2199 break;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2200 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2201 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2202
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2203 return ret;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2204
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2205 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2206
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2207 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2208 * @brief Configure the UART peripheral advanced features.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2209 * @param huart: UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2210 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2211 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2212 void UART_AdvFeatureConfig(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2213 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2214 /* Check whether the set of advanced features to configure is properly set */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2215 assert_param(IS_UART_ADVFEATURE_INIT(huart->AdvancedInit.AdvFeatureInit));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2216
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2217 /* if required, configure TX pin active level inversion */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2218 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_TXINVERT_INIT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2219 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2220 assert_param(IS_UART_ADVFEATURE_TXINV(huart->AdvancedInit.TxPinLevelInvert));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2221 MODIFY_REG(huart->Instance->CR2, USART_CR2_TXINV, huart->AdvancedInit.TxPinLevelInvert);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2222 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2223
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2224 /* if required, configure RX pin active level inversion */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2225 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_RXINVERT_INIT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2226 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2227 assert_param(IS_UART_ADVFEATURE_RXINV(huart->AdvancedInit.RxPinLevelInvert));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2228 MODIFY_REG(huart->Instance->CR2, USART_CR2_RXINV, huart->AdvancedInit.RxPinLevelInvert);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2229 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2230
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2231 /* if required, configure data inversion */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2232 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_DATAINVERT_INIT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2233 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2234 assert_param(IS_UART_ADVFEATURE_DATAINV(huart->AdvancedInit.DataInvert));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2235 MODIFY_REG(huart->Instance->CR2, USART_CR2_DATAINV, huart->AdvancedInit.DataInvert);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2236 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2237
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2238 /* if required, configure RX/TX pins swap */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2239 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_SWAP_INIT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2240 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2241 assert_param(IS_UART_ADVFEATURE_SWAP(huart->AdvancedInit.Swap));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2242 MODIFY_REG(huart->Instance->CR2, USART_CR2_SWAP, huart->AdvancedInit.Swap);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2243 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2244
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2245 /* if required, configure RX overrun detection disabling */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2246 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_RXOVERRUNDISABLE_INIT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2247 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2248 assert_param(IS_UART_OVERRUN(huart->AdvancedInit.OverrunDisable));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2249 MODIFY_REG(huart->Instance->CR3, USART_CR3_OVRDIS, huart->AdvancedInit.OverrunDisable);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2250 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2251
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2252 /* if required, configure DMA disabling on reception error */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2253 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_DMADISABLEONERROR_INIT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2254 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2255 assert_param(IS_UART_ADVFEATURE_DMAONRXERROR(huart->AdvancedInit.DMADisableonRxError));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2256 MODIFY_REG(huart->Instance->CR3, USART_CR3_DDRE, huart->AdvancedInit.DMADisableonRxError);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2257 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2258
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2259 /* if required, configure auto Baud rate detection scheme */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2260 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_AUTOBAUDRATE_INIT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2261 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2262 assert_param(IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(huart->Instance));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2263 assert_param(IS_UART_ADVFEATURE_AUTOBAUDRATE(huart->AdvancedInit.AutoBaudRateEnable));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2264 MODIFY_REG(huart->Instance->CR2, USART_CR2_ABREN, huart->AdvancedInit.AutoBaudRateEnable);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2265 /* set auto Baudrate detection parameters if detection is enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2266 if(huart->AdvancedInit.AutoBaudRateEnable == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2267 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2268 assert_param(IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(huart->AdvancedInit.AutoBaudRateMode));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2269 MODIFY_REG(huart->Instance->CR2, USART_CR2_ABRMODE, huart->AdvancedInit.AutoBaudRateMode);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2270 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2271 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2272
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2273 /* if required, configure MSB first on communication line */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2274 if(HAL_IS_BIT_SET(huart->AdvancedInit.AdvFeatureInit, UART_ADVFEATURE_MSBFIRST_INIT))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2275 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2276 assert_param(IS_UART_ADVFEATURE_MSBFIRST(huart->AdvancedInit.MSBFirst));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2277 MODIFY_REG(huart->Instance->CR2, USART_CR2_MSBFIRST, huart->AdvancedInit.MSBFirst);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2278 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2279 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2280
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2281 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2282 * @brief Check the UART Idle State.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2283 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2284 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2285 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2286 HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2287 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2288 uint32_t tickstart = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2289
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2290 /* Initialize the UART ErrorCode */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2291 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2292
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2293 /* Init tickstart for timeout managment*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2294 tickstart = HAL_GetTick();
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2295
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2296 /* Check if the Transmitter is enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2297 if((huart->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2298 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2299 /* Wait until TEACK flag is set */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2300 if(UART_WaitOnFlagUntilTimeout(huart, USART_ISR_TEACK, RESET, tickstart, HAL_UART_TIMEOUT_VALUE) != HAL_OK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2301 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2302 /* Timeout occurred */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2303 return HAL_TIMEOUT;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2304 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2305 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2306 /* Check if the Receiver is enabled */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2307 if((huart->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2308 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2309 /* Wait until REACK flag is set */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2310 if(UART_WaitOnFlagUntilTimeout(huart, USART_ISR_REACK, RESET, tickstart, HAL_UART_TIMEOUT_VALUE) != HAL_OK)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2311 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2312 /* Timeout occurred */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2313 return HAL_TIMEOUT;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2314 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2315 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2316
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2317 /* Initialize the UART State */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2318 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2319 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2320
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2321 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2322 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2323
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2324 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2325 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2326
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2327 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2328 * @brief Handle UART Communication Timeout.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2329 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2330 * @param Flag Specifies the UART flag to check
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2331 * @param Status Flag status (SET or RESET)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2332 * @param Tickstart Tick start value
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2333 * @param Timeout Timeout duration
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2334 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2335 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2336 HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2337 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2338 /* Wait until flag is set */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2339 while((__HAL_UART_GET_FLAG(huart, Flag) ? SET : RESET) == Status)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2340 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2341 /* Check for the Timeout */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2342 if(Timeout != HAL_MAX_DELAY)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2343 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2344 if((Timeout == 0) || ((HAL_GetTick()-Tickstart) > Timeout))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2345 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2346 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2347 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2348 CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2349
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2350 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2351 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2352
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2353 /* Process Unlocked */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2354 __HAL_UNLOCK(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2355 return HAL_TIMEOUT;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2356 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2357 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2358 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2359 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2360 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2361
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2362
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2363 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2364 * @brief End ongoing Tx transfer on UART peripheral (following error detection or Transmit completion).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2365 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2366 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2367 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2368 static void UART_EndTxTransfer(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2369 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2370 /* Disable TXEIE and TCIE interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2371 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2372
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2373 /* At end of Tx process, restore huart->gState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2374 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2375 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2376
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2377
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2378 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2379 * @brief End ongoing Rx transfer on UART peripheral (following error detection or Reception completion).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2380 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2381 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2382 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2383 static void UART_EndRxTransfer(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2384 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2385 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2386 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2387 CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2388
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2389 /* At end of Rx process, restore huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2390 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2391 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2392
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2393
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2394 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2395 * @brief DMA UART transmit process complete callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2396 * @param hdma DMA handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2397 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2398 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2399 static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2400 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2401 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)(hdma->Parent);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2402
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2403 /* DMA Normal mode */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2404 if ( HAL_IS_BIT_CLR(hdma->Instance->CCR, DMA_CCR_CIRC) )
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2405 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2406 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2407
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2408 /* Disable the DMA transfer for transmit request by resetting the DMAT bit
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2409 in the UART CR3 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2410 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAT);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2411
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2412 /* Enable the UART Transmit Complete Interrupt */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2413 SET_BIT(huart->Instance->CR1, USART_CR1_TCIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2414 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2415 /* DMA Circular mode */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2416 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2417 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2418 HAL_UART_TxCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2419 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2420
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2421 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2422
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2423 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2424 * @brief DMA UART transmit process half complete callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2425 * @param hdma DMA handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2426 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2427 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2428 static void UART_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2429 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2430 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)(hdma->Parent);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2431
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2432 HAL_UART_TxHalfCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2433 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2434
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2435 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2436 * @brief DMA UART receive process complete callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2437 * @param hdma DMA handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2438 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2439 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2440 static void UART_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2441 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2442 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)(hdma->Parent);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2443
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2444 /* DMA Normal mode */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2445 if ( HAL_IS_BIT_CLR(hdma->Instance->CCR, DMA_CCR_CIRC) )
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2446 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2447 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2448
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2449 /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2450 CLEAR_BIT(huart->Instance->CR1, USART_CR1_PEIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2451 CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2452
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2453 /* Disable the DMA transfer for the receiver request by resetting the DMAR bit
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2454 in the UART CR3 register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2455 CLEAR_BIT(huart->Instance->CR3, USART_CR3_DMAR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2456
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2457 /* At end of Rx process, restore huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2458 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2459 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2460
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2461 HAL_UART_RxCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2462 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2463
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2464 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2465 * @brief DMA UART receive process half complete callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2466 * @param hdma DMA handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2467 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2468 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2469 static void UART_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2470 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2471 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)(hdma->Parent);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2472
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2473 HAL_UART_RxHalfCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2474 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2475
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2476 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2477 * @brief DMA UART communication error callback.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2478 * @param hdma DMA handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2479 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2480 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2481 static void UART_DMAError(DMA_HandleTypeDef *hdma)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2482 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2483 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)(hdma->Parent);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2484
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2485 /* Stop UART DMA Tx request if ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2486 if ( (huart->gState == HAL_UART_STATE_BUSY_TX)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2487 &&(HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAT)) )
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2488 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2489 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2490 UART_EndTxTransfer(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2491 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2492
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2493 /* Stop UART DMA Rx request if ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2494 if ( (huart->RxState == HAL_UART_STATE_BUSY_RX)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2495 &&(HAL_IS_BIT_SET(huart->Instance->CR3, USART_CR3_DMAR)) )
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2496 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2497 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2498 UART_EndRxTransfer(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2499 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2500
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2501 huart->ErrorCode |= HAL_UART_ERROR_DMA;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2502 HAL_UART_ErrorCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2503 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2504
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2505 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2506 * @brief DMA UART communication abort callback, when initiated by HAL services on Error
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2507 * (To be called at end of DMA Abort procedure following error occurrence).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2508 * @param hdma DMA handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2509 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2510 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2511 static void UART_DMAAbortOnError(DMA_HandleTypeDef *hdma)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2512 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2513 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)(hdma->Parent);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2514 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2515 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2516
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2517 HAL_UART_ErrorCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2518 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2519
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2520 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2521 * @brief DMA UART Tx communication abort callback, when initiated by user
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2522 * (To be called at end of DMA Tx Abort procedure following user abort request).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2523 * @note When this callback is executed, User Abort complete call back is called only if no
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2524 * Abort still ongoing for Rx DMA Handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2525 * @param hdma DMA handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2526 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2527 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2528 static void UART_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2529 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2530 UART_HandleTypeDef* huart = (UART_HandleTypeDef* )(hdma->Parent);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2531
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2532 huart->hdmatx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2533
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2534 /* Check if an Abort process is still ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2535 if(huart->hdmarx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2536 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2537 if(huart->hdmarx->XferAbortCallback != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2538 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2539 return;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2540 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2541 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2542
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2543 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2544 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2545 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2546
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2547 /* Reset errorCode */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2548 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2549
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2550 /* Clear the Error flags in the ICR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2551 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF | UART_CLEAR_NEF | UART_CLEAR_PEF | UART_CLEAR_FEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2552
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2553 /* Restore huart->gState and huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2554 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2555 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2556
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2557 /* Call user Abort complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2558 HAL_UART_AbortCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2559 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2560
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2561
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2562 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2563 * @brief DMA UART Rx communication abort callback, when initiated by user
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2564 * (To be called at end of DMA Rx Abort procedure following user abort request).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2565 * @note When this callback is executed, User Abort complete call back is called only if no
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2566 * Abort still ongoing for Tx DMA Handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2567 * @param hdma DMA handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2568 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2569 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2570 static void UART_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2571 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2572 UART_HandleTypeDef* huart = (UART_HandleTypeDef* )(hdma->Parent);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2573
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2574 huart->hdmarx->XferAbortCallback = NULL;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2575
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2576 /* Check if an Abort process is still ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2577 if(huart->hdmatx != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2578 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2579 if(huart->hdmatx->XferAbortCallback != NULL)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2580 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2581 return;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2582 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2583 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2584
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2585 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2586 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2587 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2588
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2589 /* Reset errorCode */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2590 huart->ErrorCode = HAL_UART_ERROR_NONE;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2591
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2592 /* Clear the Error flags in the ICR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2593 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF | UART_CLEAR_NEF | UART_CLEAR_PEF | UART_CLEAR_FEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2594
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2595 /* Restore huart->gState and huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2596 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2597 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2598
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2599 /* Call user Abort complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2600 HAL_UART_AbortCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2601 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2602
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2603
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2604 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2605 * @brief DMA UART Tx communication abort callback, when initiated by user by a call to
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2606 * HAL_UART_AbortTransmit_IT API (Abort only Tx transfer)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2607 * (This callback is executed at end of DMA Tx Abort procedure following user abort request,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2608 * and leads to user Tx Abort Complete callback execution).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2609 * @param hdma DMA handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2610 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2611 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2612 static void UART_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2613 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2614 UART_HandleTypeDef* huart = (UART_HandleTypeDef*)(hdma->Parent);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2615
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2616 huart->TxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2617
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2618 /* Restore huart->gState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2619 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2620
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2621 /* Call user Abort complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2622 HAL_UART_AbortTransmitCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2623 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2624
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2625 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2626 * @brief DMA UART Rx communication abort callback, when initiated by user by a call to
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2627 * HAL_UART_AbortReceive_IT API (Abort only Rx transfer)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2628 * (This callback is executed at end of DMA Rx Abort procedure following user abort request,
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2629 * and leads to user Rx Abort Complete callback execution).
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2630 * @param hdma DMA handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2631 * @retval None
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2632 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2633 static void UART_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2634 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2635 UART_HandleTypeDef* huart = ( UART_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2636
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2637 huart->RxXferCount = 0;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2638
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2639 /* Clear the Error flags in the ICR register */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2640 __HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_OREF | UART_CLEAR_NEF | UART_CLEAR_PEF | UART_CLEAR_FEF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2641
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2642 /* Restore huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2643 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2644
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2645 /* Call user Abort complete callback */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2646 HAL_UART_AbortReceiveCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2647 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2648
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2649 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2650 * @brief Send an amount of data in interrupt mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2651 * @note Function is called under interruption only, once
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2652 * interruptions have been enabled by HAL_UART_Transmit_IT().
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2653 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2654 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2655 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2656 static HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2657 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2658 uint16_t* tmp;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2659
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2660 /* Check that a Tx process is ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2661 if (huart->gState == HAL_UART_STATE_BUSY_TX)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2662 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2663 if(huart->TxXferCount == 0)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2664 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2665 /* Disable the UART Transmit Data Register Empty Interrupt */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2666 CLEAR_BIT(huart->Instance->CR1, USART_CR1_TXEIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2667
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2668 /* Enable the UART Transmit Complete Interrupt */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2669 SET_BIT(huart->Instance->CR1, USART_CR1_TCIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2670
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2671 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2672 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2673 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2674 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2675 if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2676 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2677 tmp = (uint16_t*) huart->pTxBuffPtr;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2678 huart->Instance->TDR = (*tmp & (uint16_t)0x01FF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2679 huart->pTxBuffPtr += 2;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2680 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2681 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2682 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2683 huart->Instance->TDR = (uint8_t)(*huart->pTxBuffPtr++ & (uint8_t)0xFF);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2684 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2685 huart->TxXferCount--;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2686
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2687 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2688 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2689 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2690 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2691 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2692 return HAL_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2693 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2694 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2695
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2696 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2697 * @brief Wrap up transmission in non-blocking mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2698 * @param huart pointer to a UART_HandleTypeDef structure that contains
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2699 * the configuration information for the specified UART module.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2700 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2701 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2702 static HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2703 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2704 /* Disable the UART Transmit Complete Interrupt */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2705 CLEAR_BIT(huart->Instance->CR1, USART_CR1_TCIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2706
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2707 /* Tx process is ended, restore huart->gState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2708 huart->gState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2709
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2710 HAL_UART_TxCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2711
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2712 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2713 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2714
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2715 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2716 * @brief Receive an amount of data in interrupt mode.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2717 * @note Function is called under interruption only, once
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2718 * interruptions have been enabled by HAL_UART_Receive_IT()
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2719 * @param huart UART handle.
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2720 * @retval HAL status
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2721 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2722 static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2723 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2724 uint16_t* tmp;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2725 uint16_t uhMask = huart->Mask;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2726 uint16_t uhdata;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2727
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2728 /* Check that a Rx process is ongoing */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2729 if(huart->RxState == HAL_UART_STATE_BUSY_RX)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2730 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2731 uhdata = (uint16_t) READ_REG(huart->Instance->RDR);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2732 if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2733 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2734 tmp = (uint16_t*) huart->pRxBuffPtr ;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2735 *tmp = (uint16_t)(uhdata & uhMask);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2736 huart->pRxBuffPtr +=2;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2737 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2738 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2739 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2740 *huart->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)uhMask);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2741 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2742
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2743 if(--huart->RxXferCount == 0)
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2744 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2745 /* Disable the UART Parity Error Interrupt and RXNE interrupt*/
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2746 CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2747
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2748 /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2749 CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2750
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2751 /* Rx process is completed, restore huart->RxState to Ready */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2752 huart->RxState = HAL_UART_STATE_READY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2753
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2754 HAL_UART_RxCpltCallback(huart);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2755
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2756 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2757 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2758
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2759 return HAL_OK;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2760 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2761 else
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2762 {
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2763 /* Clear RXNE interrupt flag */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2764 __HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST);
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2765
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2766 return HAL_BUSY;
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2767 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2768 }
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2769
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2770 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2771 * @}
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2772 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2773
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2774 #endif /* HAL_UART_MODULE_ENABLED */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2775 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2776 * @}
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2777 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2778
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2779 /**
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2780 * @}
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2781 */
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2782
32a3b1785697 a rough draft of Hardware Abstraction Layer for C++
cin
parents:
diff changeset
2783 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/