annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_usart.c @ 60:96026ba1834f

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