User | Revision | Line number | New contents of line |
Sergunb |
0:8f0d870509fe
|
1
|
/**
|
Sergunb |
0:8f0d870509fe
|
2
|
******************************************************************************
|
Sergunb |
0:8f0d870509fe
|
3
|
* @file stm32f10x_usart.c
|
Sergunb |
0:8f0d870509fe
|
4
|
* @author MCD Application Team
|
Sergunb |
0:8f0d870509fe
|
5
|
* @version V3.5.0
|
Sergunb |
0:8f0d870509fe
|
6
|
* @date 11-March-2011
|
Sergunb |
0:8f0d870509fe
|
7
|
* @brief This file provides all the USART firmware functions.
|
Sergunb |
0:8f0d870509fe
|
8
|
******************************************************************************
|
Sergunb |
0:8f0d870509fe
|
9
|
* @attention
|
Sergunb |
0:8f0d870509fe
|
10
|
*
|
Sergunb |
0:8f0d870509fe
|
11
|
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
Sergunb |
0:8f0d870509fe
|
12
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
Sergunb |
0:8f0d870509fe
|
13
|
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
Sergunb |
0:8f0d870509fe
|
14
|
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
Sergunb |
0:8f0d870509fe
|
15
|
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
Sergunb |
0:8f0d870509fe
|
16
|
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
Sergunb |
0:8f0d870509fe
|
17
|
*
|
Sergunb |
0:8f0d870509fe
|
18
|
* <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
|
Sergunb |
0:8f0d870509fe
|
19
|
******************************************************************************
|
Sergunb |
0:8f0d870509fe
|
20
|
*/
|
Sergunb |
0:8f0d870509fe
|
21
|
|
Sergunb |
0:8f0d870509fe
|
22
|
/* Includes ------------------------------------------------------------------*/
|
Sergunb |
0:8f0d870509fe
|
23
|
#include "stm32f10x_usart.h"
|
Sergunb |
0:8f0d870509fe
|
24
|
#include "stm32f10x_rcc.h"
|
Sergunb |
0:8f0d870509fe
|
25
|
|
Sergunb |
0:8f0d870509fe
|
26
|
/** @addtogroup STM32F10x_StdPeriph_Driver
|
Sergunb |
0:8f0d870509fe
|
27
|
* @{
|
Sergunb |
0:8f0d870509fe
|
28
|
*/
|
Sergunb |
0:8f0d870509fe
|
29
|
|
Sergunb |
0:8f0d870509fe
|
30
|
/** @defgroup USART
|
Sergunb |
0:8f0d870509fe
|
31
|
* @brief USART driver modules
|
Sergunb |
0:8f0d870509fe
|
32
|
* @{
|
Sergunb |
0:8f0d870509fe
|
33
|
*/
|
Sergunb |
0:8f0d870509fe
|
34
|
|
Sergunb |
0:8f0d870509fe
|
35
|
/** @defgroup USART_Private_TypesDefinitions
|
Sergunb |
0:8f0d870509fe
|
36
|
* @{
|
Sergunb |
0:8f0d870509fe
|
37
|
*/
|
Sergunb |
0:8f0d870509fe
|
38
|
|
Sergunb |
0:8f0d870509fe
|
39
|
/**
|
Sergunb |
0:8f0d870509fe
|
40
|
* @}
|
Sergunb |
0:8f0d870509fe
|
41
|
*/
|
Sergunb |
0:8f0d870509fe
|
42
|
|
Sergunb |
0:8f0d870509fe
|
43
|
/** @defgroup USART_Private_Defines
|
Sergunb |
0:8f0d870509fe
|
44
|
* @{
|
Sergunb |
0:8f0d870509fe
|
45
|
*/
|
Sergunb |
0:8f0d870509fe
|
46
|
|
Sergunb |
0:8f0d870509fe
|
47
|
#define CR1_UE_Set ((uint16_t)0x2000) /*!< USART Enable Mask */
|
Sergunb |
0:8f0d870509fe
|
48
|
#define CR1_UE_Reset ((uint16_t)0xDFFF) /*!< USART Disable Mask */
|
Sergunb |
0:8f0d870509fe
|
49
|
|
Sergunb |
0:8f0d870509fe
|
50
|
#define CR1_WAKE_Mask ((uint16_t)0xF7FF) /*!< USART WakeUp Method Mask */
|
Sergunb |
0:8f0d870509fe
|
51
|
|
Sergunb |
0:8f0d870509fe
|
52
|
#define CR1_RWU_Set ((uint16_t)0x0002) /*!< USART mute mode Enable Mask */
|
Sergunb |
0:8f0d870509fe
|
53
|
#define CR1_RWU_Reset ((uint16_t)0xFFFD) /*!< USART mute mode Enable Mask */
|
Sergunb |
0:8f0d870509fe
|
54
|
#define CR1_SBK_Set ((uint16_t)0x0001) /*!< USART Break Character send Mask */
|
Sergunb |
0:8f0d870509fe
|
55
|
#define CR1_CLEAR_Mask ((uint16_t)0xE9F3) /*!< USART CR1 Mask */
|
Sergunb |
0:8f0d870509fe
|
56
|
#define CR2_Address_Mask ((uint16_t)0xFFF0) /*!< USART address Mask */
|
Sergunb |
0:8f0d870509fe
|
57
|
|
Sergunb |
0:8f0d870509fe
|
58
|
#define CR2_LINEN_Set ((uint16_t)0x4000) /*!< USART LIN Enable Mask */
|
Sergunb |
0:8f0d870509fe
|
59
|
#define CR2_LINEN_Reset ((uint16_t)0xBFFF) /*!< USART LIN Disable Mask */
|
Sergunb |
0:8f0d870509fe
|
60
|
|
Sergunb |
0:8f0d870509fe
|
61
|
#define CR2_LBDL_Mask ((uint16_t)0xFFDF) /*!< USART LIN Break detection Mask */
|
Sergunb |
0:8f0d870509fe
|
62
|
#define CR2_STOP_CLEAR_Mask ((uint16_t)0xCFFF) /*!< USART CR2 STOP Bits Mask */
|
Sergunb |
0:8f0d870509fe
|
63
|
#define CR2_CLOCK_CLEAR_Mask ((uint16_t)0xF0FF) /*!< USART CR2 Clock Mask */
|
Sergunb |
0:8f0d870509fe
|
64
|
|
Sergunb |
0:8f0d870509fe
|
65
|
#define CR3_SCEN_Set ((uint16_t)0x0020) /*!< USART SC Enable Mask */
|
Sergunb |
0:8f0d870509fe
|
66
|
#define CR3_SCEN_Reset ((uint16_t)0xFFDF) /*!< USART SC Disable Mask */
|
Sergunb |
0:8f0d870509fe
|
67
|
|
Sergunb |
0:8f0d870509fe
|
68
|
#define CR3_NACK_Set ((uint16_t)0x0010) /*!< USART SC NACK Enable Mask */
|
Sergunb |
0:8f0d870509fe
|
69
|
#define CR3_NACK_Reset ((uint16_t)0xFFEF) /*!< USART SC NACK Disable Mask */
|
Sergunb |
0:8f0d870509fe
|
70
|
|
Sergunb |
0:8f0d870509fe
|
71
|
#define CR3_HDSEL_Set ((uint16_t)0x0008) /*!< USART Half-Duplex Enable Mask */
|
Sergunb |
0:8f0d870509fe
|
72
|
#define CR3_HDSEL_Reset ((uint16_t)0xFFF7) /*!< USART Half-Duplex Disable Mask */
|
Sergunb |
0:8f0d870509fe
|
73
|
|
Sergunb |
0:8f0d870509fe
|
74
|
#define CR3_IRLP_Mask ((uint16_t)0xFFFB) /*!< USART IrDA LowPower mode Mask */
|
Sergunb |
0:8f0d870509fe
|
75
|
#define CR3_CLEAR_Mask ((uint16_t)0xFCFF) /*!< USART CR3 Mask */
|
Sergunb |
0:8f0d870509fe
|
76
|
|
Sergunb |
0:8f0d870509fe
|
77
|
#define CR3_IREN_Set ((uint16_t)0x0002) /*!< USART IrDA Enable Mask */
|
Sergunb |
0:8f0d870509fe
|
78
|
#define CR3_IREN_Reset ((uint16_t)0xFFFD) /*!< USART IrDA Disable Mask */
|
Sergunb |
0:8f0d870509fe
|
79
|
#define GTPR_LSB_Mask ((uint16_t)0x00FF) /*!< Guard Time Register LSB Mask */
|
Sergunb |
0:8f0d870509fe
|
80
|
#define GTPR_MSB_Mask ((uint16_t)0xFF00) /*!< Guard Time Register MSB Mask */
|
Sergunb |
0:8f0d870509fe
|
81
|
#define IT_Mask ((uint16_t)0x001F) /*!< USART Interrupt Mask */
|
Sergunb |
0:8f0d870509fe
|
82
|
|
Sergunb |
0:8f0d870509fe
|
83
|
/* USART OverSampling-8 Mask */
|
Sergunb |
0:8f0d870509fe
|
84
|
#define CR1_OVER8_Set ((u16)0x8000) /* USART OVER8 mode Enable Mask */
|
Sergunb |
0:8f0d870509fe
|
85
|
#define CR1_OVER8_Reset ((u16)0x7FFF) /* USART OVER8 mode Disable Mask */
|
Sergunb |
0:8f0d870509fe
|
86
|
|
Sergunb |
0:8f0d870509fe
|
87
|
/* USART One Bit Sampling Mask */
|
Sergunb |
0:8f0d870509fe
|
88
|
#define CR3_ONEBITE_Set ((u16)0x0800) /* USART ONEBITE mode Enable Mask */
|
Sergunb |
0:8f0d870509fe
|
89
|
#define CR3_ONEBITE_Reset ((u16)0xF7FF) /* USART ONEBITE mode Disable Mask */
|
Sergunb |
0:8f0d870509fe
|
90
|
|
Sergunb |
0:8f0d870509fe
|
91
|
/**
|
Sergunb |
0:8f0d870509fe
|
92
|
* @}
|
Sergunb |
0:8f0d870509fe
|
93
|
*/
|
Sergunb |
0:8f0d870509fe
|
94
|
|
Sergunb |
0:8f0d870509fe
|
95
|
/** @defgroup USART_Private_Macros
|
Sergunb |
0:8f0d870509fe
|
96
|
* @{
|
Sergunb |
0:8f0d870509fe
|
97
|
*/
|
Sergunb |
0:8f0d870509fe
|
98
|
|
Sergunb |
0:8f0d870509fe
|
99
|
/**
|
Sergunb |
0:8f0d870509fe
|
100
|
* @}
|
Sergunb |
0:8f0d870509fe
|
101
|
*/
|
Sergunb |
0:8f0d870509fe
|
102
|
|
Sergunb |
0:8f0d870509fe
|
103
|
/** @defgroup USART_Private_Variables
|
Sergunb |
0:8f0d870509fe
|
104
|
* @{
|
Sergunb |
0:8f0d870509fe
|
105
|
*/
|
Sergunb |
0:8f0d870509fe
|
106
|
|
Sergunb |
0:8f0d870509fe
|
107
|
/**
|
Sergunb |
0:8f0d870509fe
|
108
|
* @}
|
Sergunb |
0:8f0d870509fe
|
109
|
*/
|
Sergunb |
0:8f0d870509fe
|
110
|
|
Sergunb |
0:8f0d870509fe
|
111
|
/** @defgroup USART_Private_FunctionPrototypes
|
Sergunb |
0:8f0d870509fe
|
112
|
* @{
|
Sergunb |
0:8f0d870509fe
|
113
|
*/
|
Sergunb |
0:8f0d870509fe
|
114
|
|
Sergunb |
0:8f0d870509fe
|
115
|
/**
|
Sergunb |
0:8f0d870509fe
|
116
|
* @}
|
Sergunb |
0:8f0d870509fe
|
117
|
*/
|
Sergunb |
0:8f0d870509fe
|
118
|
|
Sergunb |
0:8f0d870509fe
|
119
|
/** @defgroup USART_Private_Functions
|
Sergunb |
0:8f0d870509fe
|
120
|
* @{
|
Sergunb |
0:8f0d870509fe
|
121
|
*/
|
Sergunb |
0:8f0d870509fe
|
122
|
|
Sergunb |
0:8f0d870509fe
|
123
|
/**
|
Sergunb |
0:8f0d870509fe
|
124
|
* @brief Deinitializes the USARTx peripheral registers to their default reset values.
|
Sergunb |
0:8f0d870509fe
|
125
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
126
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
127
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
128
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
129
|
*/
|
Sergunb |
0:8f0d870509fe
|
130
|
void USART_DeInit(USART_TypeDef* USARTx)
|
Sergunb |
0:8f0d870509fe
|
131
|
{
|
Sergunb |
0:8f0d870509fe
|
132
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
133
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
134
|
|
Sergunb |
0:8f0d870509fe
|
135
|
if (USARTx == USART1)
|
Sergunb |
0:8f0d870509fe
|
136
|
{
|
Sergunb |
0:8f0d870509fe
|
137
|
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
|
Sergunb |
0:8f0d870509fe
|
138
|
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
|
Sergunb |
0:8f0d870509fe
|
139
|
}
|
Sergunb |
0:8f0d870509fe
|
140
|
else if (USARTx == USART2)
|
Sergunb |
0:8f0d870509fe
|
141
|
{
|
Sergunb |
0:8f0d870509fe
|
142
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
|
Sergunb |
0:8f0d870509fe
|
143
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
|
Sergunb |
0:8f0d870509fe
|
144
|
}
|
Sergunb |
0:8f0d870509fe
|
145
|
else if (USARTx == USART3)
|
Sergunb |
0:8f0d870509fe
|
146
|
{
|
Sergunb |
0:8f0d870509fe
|
147
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
|
Sergunb |
0:8f0d870509fe
|
148
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
|
Sergunb |
0:8f0d870509fe
|
149
|
}
|
Sergunb |
0:8f0d870509fe
|
150
|
else if (USARTx == UART4)
|
Sergunb |
0:8f0d870509fe
|
151
|
{
|
Sergunb |
0:8f0d870509fe
|
152
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
|
Sergunb |
0:8f0d870509fe
|
153
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
|
Sergunb |
0:8f0d870509fe
|
154
|
}
|
Sergunb |
0:8f0d870509fe
|
155
|
else
|
Sergunb |
0:8f0d870509fe
|
156
|
{
|
Sergunb |
0:8f0d870509fe
|
157
|
if (USARTx == UART5)
|
Sergunb |
0:8f0d870509fe
|
158
|
{
|
Sergunb |
0:8f0d870509fe
|
159
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
|
Sergunb |
0:8f0d870509fe
|
160
|
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
|
Sergunb |
0:8f0d870509fe
|
161
|
}
|
Sergunb |
0:8f0d870509fe
|
162
|
}
|
Sergunb |
0:8f0d870509fe
|
163
|
}
|
Sergunb |
0:8f0d870509fe
|
164
|
|
Sergunb |
0:8f0d870509fe
|
165
|
/**
|
Sergunb |
0:8f0d870509fe
|
166
|
* @brief Initializes the USARTx peripheral according to the specified
|
Sergunb |
0:8f0d870509fe
|
167
|
* parameters in the USART_InitStruct .
|
Sergunb |
0:8f0d870509fe
|
168
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
169
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
170
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
171
|
* @param USART_InitStruct: pointer to a USART_InitTypeDef structure
|
Sergunb |
0:8f0d870509fe
|
172
|
* that contains the configuration information for the specified USART
|
Sergunb |
0:8f0d870509fe
|
173
|
* peripheral.
|
Sergunb |
0:8f0d870509fe
|
174
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
175
|
*/
|
Sergunb |
0:8f0d870509fe
|
176
|
void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct)
|
Sergunb |
0:8f0d870509fe
|
177
|
{
|
Sergunb |
0:8f0d870509fe
|
178
|
uint32_t tmpreg = 0x00, apbclock = 0x00;
|
Sergunb |
0:8f0d870509fe
|
179
|
uint32_t integerdivider = 0x00;
|
Sergunb |
0:8f0d870509fe
|
180
|
uint32_t fractionaldivider = 0x00;
|
Sergunb |
0:8f0d870509fe
|
181
|
uint32_t usartxbase = 0;
|
Sergunb |
0:8f0d870509fe
|
182
|
RCC_ClocksTypeDef RCC_ClocksStatus;
|
Sergunb |
0:8f0d870509fe
|
183
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
184
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
185
|
assert_param(IS_USART_BAUDRATE(USART_InitStruct->USART_BaudRate));
|
Sergunb |
0:8f0d870509fe
|
186
|
assert_param(IS_USART_WORD_LENGTH(USART_InitStruct->USART_WordLength));
|
Sergunb |
0:8f0d870509fe
|
187
|
assert_param(IS_USART_STOPBITS(USART_InitStruct->USART_StopBits));
|
Sergunb |
0:8f0d870509fe
|
188
|
assert_param(IS_USART_PARITY(USART_InitStruct->USART_Parity));
|
Sergunb |
0:8f0d870509fe
|
189
|
assert_param(IS_USART_MODE(USART_InitStruct->USART_Mode));
|
Sergunb |
0:8f0d870509fe
|
190
|
assert_param(IS_USART_HARDWARE_FLOW_CONTROL(USART_InitStruct->USART_HardwareFlowControl));
|
Sergunb |
0:8f0d870509fe
|
191
|
/* The hardware flow control is available only for USART1, USART2 and USART3 */
|
Sergunb |
0:8f0d870509fe
|
192
|
if (USART_InitStruct->USART_HardwareFlowControl != USART_HardwareFlowControl_None)
|
Sergunb |
0:8f0d870509fe
|
193
|
{
|
Sergunb |
0:8f0d870509fe
|
194
|
assert_param(IS_USART_123_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
195
|
}
|
Sergunb |
0:8f0d870509fe
|
196
|
|
Sergunb |
0:8f0d870509fe
|
197
|
usartxbase = (uint32_t)USARTx;
|
Sergunb |
0:8f0d870509fe
|
198
|
|
Sergunb |
0:8f0d870509fe
|
199
|
/*---------------------------- USART CR2 Configuration -----------------------*/
|
Sergunb |
0:8f0d870509fe
|
200
|
tmpreg = USARTx->CR2;
|
Sergunb |
0:8f0d870509fe
|
201
|
/* Clear STOP[13:12] bits */
|
Sergunb |
0:8f0d870509fe
|
202
|
tmpreg &= CR2_STOP_CLEAR_Mask;
|
Sergunb |
0:8f0d870509fe
|
203
|
/* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit ------------*/
|
Sergunb |
0:8f0d870509fe
|
204
|
/* Set STOP[13:12] bits according to USART_StopBits value */
|
Sergunb |
0:8f0d870509fe
|
205
|
tmpreg |= (uint32_t)USART_InitStruct->USART_StopBits;
|
Sergunb |
0:8f0d870509fe
|
206
|
|
Sergunb |
0:8f0d870509fe
|
207
|
/* Write to USART CR2 */
|
Sergunb |
0:8f0d870509fe
|
208
|
USARTx->CR2 = (uint16_t)tmpreg;
|
Sergunb |
0:8f0d870509fe
|
209
|
|
Sergunb |
0:8f0d870509fe
|
210
|
/*---------------------------- USART CR1 Configuration -----------------------*/
|
Sergunb |
0:8f0d870509fe
|
211
|
tmpreg = USARTx->CR1;
|
Sergunb |
0:8f0d870509fe
|
212
|
/* Clear M, PCE, PS, TE and RE bits */
|
Sergunb |
0:8f0d870509fe
|
213
|
tmpreg &= CR1_CLEAR_Mask;
|
Sergunb |
0:8f0d870509fe
|
214
|
/* Configure the USART Word Length, Parity and mode ----------------------- */
|
Sergunb |
0:8f0d870509fe
|
215
|
/* Set the M bits according to USART_WordLength value */
|
Sergunb |
0:8f0d870509fe
|
216
|
/* Set PCE and PS bits according to USART_Parity value */
|
Sergunb |
0:8f0d870509fe
|
217
|
/* Set TE and RE bits according to USART_Mode value */
|
Sergunb |
0:8f0d870509fe
|
218
|
tmpreg |= (uint32_t)USART_InitStruct->USART_WordLength | USART_InitStruct->USART_Parity |
|
Sergunb |
0:8f0d870509fe
|
219
|
USART_InitStruct->USART_Mode;
|
Sergunb |
0:8f0d870509fe
|
220
|
/* Write to USART CR1 */
|
Sergunb |
0:8f0d870509fe
|
221
|
USARTx->CR1 = (uint16_t)tmpreg;
|
Sergunb |
0:8f0d870509fe
|
222
|
|
Sergunb |
0:8f0d870509fe
|
223
|
/*---------------------------- USART CR3 Configuration -----------------------*/
|
Sergunb |
0:8f0d870509fe
|
224
|
tmpreg = USARTx->CR3;
|
Sergunb |
0:8f0d870509fe
|
225
|
/* Clear CTSE and RTSE bits */
|
Sergunb |
0:8f0d870509fe
|
226
|
tmpreg &= CR3_CLEAR_Mask;
|
Sergunb |
0:8f0d870509fe
|
227
|
/* Configure the USART HFC -------------------------------------------------*/
|
Sergunb |
0:8f0d870509fe
|
228
|
/* Set CTSE and RTSE bits according to USART_HardwareFlowControl value */
|
Sergunb |
0:8f0d870509fe
|
229
|
tmpreg |= USART_InitStruct->USART_HardwareFlowControl;
|
Sergunb |
0:8f0d870509fe
|
230
|
/* Write to USART CR3 */
|
Sergunb |
0:8f0d870509fe
|
231
|
USARTx->CR3 = (uint16_t)tmpreg;
|
Sergunb |
0:8f0d870509fe
|
232
|
|
Sergunb |
0:8f0d870509fe
|
233
|
/*---------------------------- USART BRR Configuration -----------------------*/
|
Sergunb |
0:8f0d870509fe
|
234
|
/* Configure the USART Baud Rate -------------------------------------------*/
|
Sergunb |
0:8f0d870509fe
|
235
|
RCC_GetClocksFreq(&RCC_ClocksStatus);
|
Sergunb |
0:8f0d870509fe
|
236
|
if (usartxbase == USART1_BASE)
|
Sergunb |
0:8f0d870509fe
|
237
|
{
|
Sergunb |
0:8f0d870509fe
|
238
|
apbclock = RCC_ClocksStatus.PCLK2_Frequency;
|
Sergunb |
0:8f0d870509fe
|
239
|
}
|
Sergunb |
0:8f0d870509fe
|
240
|
else
|
Sergunb |
0:8f0d870509fe
|
241
|
{
|
Sergunb |
0:8f0d870509fe
|
242
|
apbclock = RCC_ClocksStatus.PCLK1_Frequency;
|
Sergunb |
0:8f0d870509fe
|
243
|
}
|
Sergunb |
0:8f0d870509fe
|
244
|
|
Sergunb |
0:8f0d870509fe
|
245
|
/* Determine the integer part */
|
Sergunb |
0:8f0d870509fe
|
246
|
if ((USARTx->CR1 & CR1_OVER8_Set) != 0)
|
Sergunb |
0:8f0d870509fe
|
247
|
{
|
Sergunb |
0:8f0d870509fe
|
248
|
/* Integer part computing in case Oversampling mode is 8 Samples */
|
Sergunb |
0:8f0d870509fe
|
249
|
integerdivider = ((25 * apbclock) / (2 * (USART_InitStruct->USART_BaudRate)));
|
Sergunb |
0:8f0d870509fe
|
250
|
}
|
Sergunb |
0:8f0d870509fe
|
251
|
else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
|
Sergunb |
0:8f0d870509fe
|
252
|
{
|
Sergunb |
0:8f0d870509fe
|
253
|
/* Integer part computing in case Oversampling mode is 16 Samples */
|
Sergunb |
0:8f0d870509fe
|
254
|
integerdivider = ((25 * apbclock) / (4 * (USART_InitStruct->USART_BaudRate)));
|
Sergunb |
0:8f0d870509fe
|
255
|
}
|
Sergunb |
0:8f0d870509fe
|
256
|
tmpreg = (integerdivider / 100) << 4;
|
Sergunb |
0:8f0d870509fe
|
257
|
|
Sergunb |
0:8f0d870509fe
|
258
|
/* Determine the fractional part */
|
Sergunb |
0:8f0d870509fe
|
259
|
fractionaldivider = integerdivider - (100 * (tmpreg >> 4));
|
Sergunb |
0:8f0d870509fe
|
260
|
|
Sergunb |
0:8f0d870509fe
|
261
|
/* Implement the fractional part in the register */
|
Sergunb |
0:8f0d870509fe
|
262
|
if ((USARTx->CR1 & CR1_OVER8_Set) != 0)
|
Sergunb |
0:8f0d870509fe
|
263
|
{
|
Sergunb |
0:8f0d870509fe
|
264
|
tmpreg |= ((((fractionaldivider * 8) + 50) / 100)) & ((uint8_t)0x07);
|
Sergunb |
0:8f0d870509fe
|
265
|
}
|
Sergunb |
0:8f0d870509fe
|
266
|
else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
|
Sergunb |
0:8f0d870509fe
|
267
|
{
|
Sergunb |
0:8f0d870509fe
|
268
|
tmpreg |= ((((fractionaldivider * 16) + 50) / 100)) & ((uint8_t)0x0F);
|
Sergunb |
0:8f0d870509fe
|
269
|
}
|
Sergunb |
0:8f0d870509fe
|
270
|
|
Sergunb |
0:8f0d870509fe
|
271
|
/* Write to USART BRR */
|
Sergunb |
0:8f0d870509fe
|
272
|
USARTx->BRR = (uint16_t)tmpreg;
|
Sergunb |
0:8f0d870509fe
|
273
|
}
|
Sergunb |
0:8f0d870509fe
|
274
|
|
Sergunb |
0:8f0d870509fe
|
275
|
/**
|
Sergunb |
0:8f0d870509fe
|
276
|
* @brief Fills each USART_InitStruct member with its default value.
|
Sergunb |
0:8f0d870509fe
|
277
|
* @param USART_InitStruct: pointer to a USART_InitTypeDef structure
|
Sergunb |
0:8f0d870509fe
|
278
|
* which will be initialized.
|
Sergunb |
0:8f0d870509fe
|
279
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
280
|
*/
|
Sergunb |
0:8f0d870509fe
|
281
|
void USART_StructInit(USART_InitTypeDef* USART_InitStruct)
|
Sergunb |
0:8f0d870509fe
|
282
|
{
|
Sergunb |
0:8f0d870509fe
|
283
|
/* USART_InitStruct members default value */
|
Sergunb |
0:8f0d870509fe
|
284
|
USART_InitStruct->USART_BaudRate = 9600;
|
Sergunb |
0:8f0d870509fe
|
285
|
USART_InitStruct->USART_WordLength = USART_WordLength_8b;
|
Sergunb |
0:8f0d870509fe
|
286
|
USART_InitStruct->USART_StopBits = USART_StopBits_1;
|
Sergunb |
0:8f0d870509fe
|
287
|
USART_InitStruct->USART_Parity = USART_Parity_No ;
|
Sergunb |
0:8f0d870509fe
|
288
|
USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
Sergunb |
0:8f0d870509fe
|
289
|
USART_InitStruct->USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
Sergunb |
0:8f0d870509fe
|
290
|
}
|
Sergunb |
0:8f0d870509fe
|
291
|
|
Sergunb |
0:8f0d870509fe
|
292
|
/**
|
Sergunb |
0:8f0d870509fe
|
293
|
* @brief Initializes the USARTx peripheral Clock according to the
|
Sergunb |
0:8f0d870509fe
|
294
|
* specified parameters in the USART_ClockInitStruct .
|
Sergunb |
0:8f0d870509fe
|
295
|
* @param USARTx: where x can be 1, 2, 3 to select the USART peripheral.
|
Sergunb |
0:8f0d870509fe
|
296
|
* @param USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
|
Sergunb |
0:8f0d870509fe
|
297
|
* structure that contains the configuration information for the specified
|
Sergunb |
0:8f0d870509fe
|
298
|
* USART peripheral.
|
Sergunb |
0:8f0d870509fe
|
299
|
* @note The Smart Card and Synchronous modes are not available for UART4 and UART5.
|
Sergunb |
0:8f0d870509fe
|
300
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
301
|
*/
|
Sergunb |
0:8f0d870509fe
|
302
|
void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct)
|
Sergunb |
0:8f0d870509fe
|
303
|
{
|
Sergunb |
0:8f0d870509fe
|
304
|
uint32_t tmpreg = 0x00;
|
Sergunb |
0:8f0d870509fe
|
305
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
306
|
assert_param(IS_USART_123_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
307
|
assert_param(IS_USART_CLOCK(USART_ClockInitStruct->USART_Clock));
|
Sergunb |
0:8f0d870509fe
|
308
|
assert_param(IS_USART_CPOL(USART_ClockInitStruct->USART_CPOL));
|
Sergunb |
0:8f0d870509fe
|
309
|
assert_param(IS_USART_CPHA(USART_ClockInitStruct->USART_CPHA));
|
Sergunb |
0:8f0d870509fe
|
310
|
assert_param(IS_USART_LASTBIT(USART_ClockInitStruct->USART_LastBit));
|
Sergunb |
0:8f0d870509fe
|
311
|
|
Sergunb |
0:8f0d870509fe
|
312
|
/*---------------------------- USART CR2 Configuration -----------------------*/
|
Sergunb |
0:8f0d870509fe
|
313
|
tmpreg = USARTx->CR2;
|
Sergunb |
0:8f0d870509fe
|
314
|
/* Clear CLKEN, CPOL, CPHA and LBCL bits */
|
Sergunb |
0:8f0d870509fe
|
315
|
tmpreg &= CR2_CLOCK_CLEAR_Mask;
|
Sergunb |
0:8f0d870509fe
|
316
|
/* Configure the USART Clock, CPOL, CPHA and LastBit ------------*/
|
Sergunb |
0:8f0d870509fe
|
317
|
/* Set CLKEN bit according to USART_Clock value */
|
Sergunb |
0:8f0d870509fe
|
318
|
/* Set CPOL bit according to USART_CPOL value */
|
Sergunb |
0:8f0d870509fe
|
319
|
/* Set CPHA bit according to USART_CPHA value */
|
Sergunb |
0:8f0d870509fe
|
320
|
/* Set LBCL bit according to USART_LastBit value */
|
Sergunb |
0:8f0d870509fe
|
321
|
tmpreg |= (uint32_t)USART_ClockInitStruct->USART_Clock | USART_ClockInitStruct->USART_CPOL |
|
Sergunb |
0:8f0d870509fe
|
322
|
USART_ClockInitStruct->USART_CPHA | USART_ClockInitStruct->USART_LastBit;
|
Sergunb |
0:8f0d870509fe
|
323
|
/* Write to USART CR2 */
|
Sergunb |
0:8f0d870509fe
|
324
|
USARTx->CR2 = (uint16_t)tmpreg;
|
Sergunb |
0:8f0d870509fe
|
325
|
}
|
Sergunb |
0:8f0d870509fe
|
326
|
|
Sergunb |
0:8f0d870509fe
|
327
|
/**
|
Sergunb |
0:8f0d870509fe
|
328
|
* @brief Fills each USART_ClockInitStruct member with its default value.
|
Sergunb |
0:8f0d870509fe
|
329
|
* @param USART_ClockInitStruct: pointer to a USART_ClockInitTypeDef
|
Sergunb |
0:8f0d870509fe
|
330
|
* structure which will be initialized.
|
Sergunb |
0:8f0d870509fe
|
331
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
332
|
*/
|
Sergunb |
0:8f0d870509fe
|
333
|
void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct)
|
Sergunb |
0:8f0d870509fe
|
334
|
{
|
Sergunb |
0:8f0d870509fe
|
335
|
/* USART_ClockInitStruct members default value */
|
Sergunb |
0:8f0d870509fe
|
336
|
USART_ClockInitStruct->USART_Clock = USART_Clock_Disable;
|
Sergunb |
0:8f0d870509fe
|
337
|
USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
|
Sergunb |
0:8f0d870509fe
|
338
|
USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
|
Sergunb |
0:8f0d870509fe
|
339
|
USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
|
Sergunb |
0:8f0d870509fe
|
340
|
}
|
Sergunb |
0:8f0d870509fe
|
341
|
|
Sergunb |
0:8f0d870509fe
|
342
|
/**
|
Sergunb |
0:8f0d870509fe
|
343
|
* @brief Enables or disables the specified USART peripheral.
|
Sergunb |
0:8f0d870509fe
|
344
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
345
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
346
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
347
|
* @param NewState: new state of the USARTx peripheral.
|
Sergunb |
0:8f0d870509fe
|
348
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
349
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
350
|
*/
|
Sergunb |
0:8f0d870509fe
|
351
|
void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
352
|
{
|
Sergunb |
0:8f0d870509fe
|
353
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
354
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
355
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
356
|
|
Sergunb |
0:8f0d870509fe
|
357
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
358
|
{
|
Sergunb |
0:8f0d870509fe
|
359
|
/* Enable the selected USART by setting the UE bit in the CR1 register */
|
Sergunb |
0:8f0d870509fe
|
360
|
USARTx->CR1 |= CR1_UE_Set;
|
Sergunb |
0:8f0d870509fe
|
361
|
}
|
Sergunb |
0:8f0d870509fe
|
362
|
else
|
Sergunb |
0:8f0d870509fe
|
363
|
{
|
Sergunb |
0:8f0d870509fe
|
364
|
/* Disable the selected USART by clearing the UE bit in the CR1 register */
|
Sergunb |
0:8f0d870509fe
|
365
|
USARTx->CR1 &= CR1_UE_Reset;
|
Sergunb |
0:8f0d870509fe
|
366
|
}
|
Sergunb |
0:8f0d870509fe
|
367
|
}
|
Sergunb |
0:8f0d870509fe
|
368
|
|
Sergunb |
0:8f0d870509fe
|
369
|
/**
|
Sergunb |
0:8f0d870509fe
|
370
|
* @brief Enables or disables the specified USART interrupts.
|
Sergunb |
0:8f0d870509fe
|
371
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
372
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
373
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
374
|
* @param USART_IT: specifies the USART interrupt sources to be enabled or disabled.
|
Sergunb |
0:8f0d870509fe
|
375
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
376
|
* @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
|
Sergunb |
0:8f0d870509fe
|
377
|
* @arg USART_IT_LBD: LIN Break detection interrupt
|
Sergunb |
0:8f0d870509fe
|
378
|
* @arg USART_IT_TXE: Transmit Data Register empty interrupt
|
Sergunb |
0:8f0d870509fe
|
379
|
* @arg USART_IT_TC: Transmission complete interrupt
|
Sergunb |
0:8f0d870509fe
|
380
|
* @arg USART_IT_RXNE: Receive Data register not empty interrupt
|
Sergunb |
0:8f0d870509fe
|
381
|
* @arg USART_IT_IDLE: Idle line detection interrupt
|
Sergunb |
0:8f0d870509fe
|
382
|
* @arg USART_IT_PE: Parity Error interrupt
|
Sergunb |
0:8f0d870509fe
|
383
|
* @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
|
Sergunb |
0:8f0d870509fe
|
384
|
* @param NewState: new state of the specified USARTx interrupts.
|
Sergunb |
0:8f0d870509fe
|
385
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
386
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
387
|
*/
|
Sergunb |
0:8f0d870509fe
|
388
|
void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
389
|
{
|
Sergunb |
0:8f0d870509fe
|
390
|
uint32_t usartreg = 0x00, itpos = 0x00, itmask = 0x00;
|
Sergunb |
0:8f0d870509fe
|
391
|
uint32_t usartxbase = 0x00;
|
Sergunb |
0:8f0d870509fe
|
392
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
393
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
394
|
assert_param(IS_USART_CONFIG_IT(USART_IT));
|
Sergunb |
0:8f0d870509fe
|
395
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
396
|
/* The CTS interrupt is not available for UART4 and UART5 */
|
Sergunb |
0:8f0d870509fe
|
397
|
if (USART_IT == USART_IT_CTS)
|
Sergunb |
0:8f0d870509fe
|
398
|
{
|
Sergunb |
0:8f0d870509fe
|
399
|
assert_param(IS_USART_123_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
400
|
}
|
Sergunb |
0:8f0d870509fe
|
401
|
|
Sergunb |
0:8f0d870509fe
|
402
|
usartxbase = (uint32_t)USARTx;
|
Sergunb |
0:8f0d870509fe
|
403
|
|
Sergunb |
0:8f0d870509fe
|
404
|
/* Get the USART register index */
|
Sergunb |
0:8f0d870509fe
|
405
|
usartreg = (((uint8_t)USART_IT) >> 0x05);
|
Sergunb |
0:8f0d870509fe
|
406
|
|
Sergunb |
0:8f0d870509fe
|
407
|
/* Get the interrupt position */
|
Sergunb |
0:8f0d870509fe
|
408
|
itpos = USART_IT & IT_Mask;
|
Sergunb |
0:8f0d870509fe
|
409
|
itmask = (((uint32_t)0x01) << itpos);
|
Sergunb |
0:8f0d870509fe
|
410
|
|
Sergunb |
0:8f0d870509fe
|
411
|
if (usartreg == 0x01) /* The IT is in CR1 register */
|
Sergunb |
0:8f0d870509fe
|
412
|
{
|
Sergunb |
0:8f0d870509fe
|
413
|
usartxbase += 0x0C;
|
Sergunb |
0:8f0d870509fe
|
414
|
}
|
Sergunb |
0:8f0d870509fe
|
415
|
else if (usartreg == 0x02) /* The IT is in CR2 register */
|
Sergunb |
0:8f0d870509fe
|
416
|
{
|
Sergunb |
0:8f0d870509fe
|
417
|
usartxbase += 0x10;
|
Sergunb |
0:8f0d870509fe
|
418
|
}
|
Sergunb |
0:8f0d870509fe
|
419
|
else /* The IT is in CR3 register */
|
Sergunb |
0:8f0d870509fe
|
420
|
{
|
Sergunb |
0:8f0d870509fe
|
421
|
usartxbase += 0x14;
|
Sergunb |
0:8f0d870509fe
|
422
|
}
|
Sergunb |
0:8f0d870509fe
|
423
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
424
|
{
|
Sergunb |
0:8f0d870509fe
|
425
|
*(__IO uint32_t*)usartxbase |= itmask;
|
Sergunb |
0:8f0d870509fe
|
426
|
}
|
Sergunb |
0:8f0d870509fe
|
427
|
else
|
Sergunb |
0:8f0d870509fe
|
428
|
{
|
Sergunb |
0:8f0d870509fe
|
429
|
*(__IO uint32_t*)usartxbase &= ~itmask;
|
Sergunb |
0:8f0d870509fe
|
430
|
}
|
Sergunb |
0:8f0d870509fe
|
431
|
}
|
Sergunb |
0:8f0d870509fe
|
432
|
|
Sergunb |
0:8f0d870509fe
|
433
|
/**
|
Sergunb |
0:8f0d870509fe
|
434
|
* @brief Enables or disables the USARTs DMA interface.
|
Sergunb |
0:8f0d870509fe
|
435
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
436
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
437
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
438
|
* @param USART_DMAReq: specifies the DMA request.
|
Sergunb |
0:8f0d870509fe
|
439
|
* This parameter can be any combination of the following values:
|
Sergunb |
0:8f0d870509fe
|
440
|
* @arg USART_DMAReq_Tx: USART DMA transmit request
|
Sergunb |
0:8f0d870509fe
|
441
|
* @arg USART_DMAReq_Rx: USART DMA receive request
|
Sergunb |
0:8f0d870509fe
|
442
|
* @param NewState: new state of the DMA Request sources.
|
Sergunb |
0:8f0d870509fe
|
443
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
444
|
* @note The DMA mode is not available for UART5 except in the STM32
|
Sergunb |
0:8f0d870509fe
|
445
|
* High density value line devices(STM32F10X_HD_VL).
|
Sergunb |
0:8f0d870509fe
|
446
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
447
|
*/
|
Sergunb |
0:8f0d870509fe
|
448
|
void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
449
|
{
|
Sergunb |
0:8f0d870509fe
|
450
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
451
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
452
|
assert_param(IS_USART_DMAREQ(USART_DMAReq));
|
Sergunb |
0:8f0d870509fe
|
453
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
454
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
455
|
{
|
Sergunb |
0:8f0d870509fe
|
456
|
/* Enable the DMA transfer for selected requests by setting the DMAT and/or
|
Sergunb |
0:8f0d870509fe
|
457
|
DMAR bits in the USART CR3 register */
|
Sergunb |
0:8f0d870509fe
|
458
|
USARTx->CR3 |= USART_DMAReq;
|
Sergunb |
0:8f0d870509fe
|
459
|
}
|
Sergunb |
0:8f0d870509fe
|
460
|
else
|
Sergunb |
0:8f0d870509fe
|
461
|
{
|
Sergunb |
0:8f0d870509fe
|
462
|
/* Disable the DMA transfer for selected requests by clearing the DMAT and/or
|
Sergunb |
0:8f0d870509fe
|
463
|
DMAR bits in the USART CR3 register */
|
Sergunb |
0:8f0d870509fe
|
464
|
USARTx->CR3 &= (uint16_t)~USART_DMAReq;
|
Sergunb |
0:8f0d870509fe
|
465
|
}
|
Sergunb |
0:8f0d870509fe
|
466
|
}
|
Sergunb |
0:8f0d870509fe
|
467
|
|
Sergunb |
0:8f0d870509fe
|
468
|
/**
|
Sergunb |
0:8f0d870509fe
|
469
|
* @brief Sets the address of the USART node.
|
Sergunb |
0:8f0d870509fe
|
470
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
471
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
472
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
473
|
* @param USART_Address: Indicates the address of the USART node.
|
Sergunb |
0:8f0d870509fe
|
474
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
475
|
*/
|
Sergunb |
0:8f0d870509fe
|
476
|
void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address)
|
Sergunb |
0:8f0d870509fe
|
477
|
{
|
Sergunb |
0:8f0d870509fe
|
478
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
479
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
480
|
assert_param(IS_USART_ADDRESS(USART_Address));
|
Sergunb |
0:8f0d870509fe
|
481
|
|
Sergunb |
0:8f0d870509fe
|
482
|
/* Clear the USART address */
|
Sergunb |
0:8f0d870509fe
|
483
|
USARTx->CR2 &= CR2_Address_Mask;
|
Sergunb |
0:8f0d870509fe
|
484
|
/* Set the USART address node */
|
Sergunb |
0:8f0d870509fe
|
485
|
USARTx->CR2 |= USART_Address;
|
Sergunb |
0:8f0d870509fe
|
486
|
}
|
Sergunb |
0:8f0d870509fe
|
487
|
|
Sergunb |
0:8f0d870509fe
|
488
|
/**
|
Sergunb |
0:8f0d870509fe
|
489
|
* @brief Selects the USART WakeUp method.
|
Sergunb |
0:8f0d870509fe
|
490
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
491
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
492
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
493
|
* @param USART_WakeUp: specifies the USART wakeup method.
|
Sergunb |
0:8f0d870509fe
|
494
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
495
|
* @arg USART_WakeUp_IdleLine: WakeUp by an idle line detection
|
Sergunb |
0:8f0d870509fe
|
496
|
* @arg USART_WakeUp_AddressMark: WakeUp by an address mark
|
Sergunb |
0:8f0d870509fe
|
497
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
498
|
*/
|
Sergunb |
0:8f0d870509fe
|
499
|
void USART_WakeUpConfig(USART_TypeDef* USARTx, uint16_t USART_WakeUp)
|
Sergunb |
0:8f0d870509fe
|
500
|
{
|
Sergunb |
0:8f0d870509fe
|
501
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
502
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
503
|
assert_param(IS_USART_WAKEUP(USART_WakeUp));
|
Sergunb |
0:8f0d870509fe
|
504
|
|
Sergunb |
0:8f0d870509fe
|
505
|
USARTx->CR1 &= CR1_WAKE_Mask;
|
Sergunb |
0:8f0d870509fe
|
506
|
USARTx->CR1 |= USART_WakeUp;
|
Sergunb |
0:8f0d870509fe
|
507
|
}
|
Sergunb |
0:8f0d870509fe
|
508
|
|
Sergunb |
0:8f0d870509fe
|
509
|
/**
|
Sergunb |
0:8f0d870509fe
|
510
|
* @brief Determines if the USART is in mute mode or not.
|
Sergunb |
0:8f0d870509fe
|
511
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
512
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
513
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
514
|
* @param NewState: new state of the USART mute mode.
|
Sergunb |
0:8f0d870509fe
|
515
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
516
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
517
|
*/
|
Sergunb |
0:8f0d870509fe
|
518
|
void USART_ReceiverWakeUpCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
519
|
{
|
Sergunb |
0:8f0d870509fe
|
520
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
521
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
522
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
523
|
|
Sergunb |
0:8f0d870509fe
|
524
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
525
|
{
|
Sergunb |
0:8f0d870509fe
|
526
|
/* Enable the USART mute mode by setting the RWU bit in the CR1 register */
|
Sergunb |
0:8f0d870509fe
|
527
|
USARTx->CR1 |= CR1_RWU_Set;
|
Sergunb |
0:8f0d870509fe
|
528
|
}
|
Sergunb |
0:8f0d870509fe
|
529
|
else
|
Sergunb |
0:8f0d870509fe
|
530
|
{
|
Sergunb |
0:8f0d870509fe
|
531
|
/* Disable the USART mute mode by clearing the RWU bit in the CR1 register */
|
Sergunb |
0:8f0d870509fe
|
532
|
USARTx->CR1 &= CR1_RWU_Reset;
|
Sergunb |
0:8f0d870509fe
|
533
|
}
|
Sergunb |
0:8f0d870509fe
|
534
|
}
|
Sergunb |
0:8f0d870509fe
|
535
|
|
Sergunb |
0:8f0d870509fe
|
536
|
/**
|
Sergunb |
0:8f0d870509fe
|
537
|
* @brief Sets the USART LIN Break detection length.
|
Sergunb |
0:8f0d870509fe
|
538
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
539
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
540
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
541
|
* @param USART_LINBreakDetectLength: specifies the LIN break detection length.
|
Sergunb |
0:8f0d870509fe
|
542
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
543
|
* @arg USART_LINBreakDetectLength_10b: 10-bit break detection
|
Sergunb |
0:8f0d870509fe
|
544
|
* @arg USART_LINBreakDetectLength_11b: 11-bit break detection
|
Sergunb |
0:8f0d870509fe
|
545
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
546
|
*/
|
Sergunb |
0:8f0d870509fe
|
547
|
void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint16_t USART_LINBreakDetectLength)
|
Sergunb |
0:8f0d870509fe
|
548
|
{
|
Sergunb |
0:8f0d870509fe
|
549
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
550
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
551
|
assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
|
Sergunb |
0:8f0d870509fe
|
552
|
|
Sergunb |
0:8f0d870509fe
|
553
|
USARTx->CR2 &= CR2_LBDL_Mask;
|
Sergunb |
0:8f0d870509fe
|
554
|
USARTx->CR2 |= USART_LINBreakDetectLength;
|
Sergunb |
0:8f0d870509fe
|
555
|
}
|
Sergunb |
0:8f0d870509fe
|
556
|
|
Sergunb |
0:8f0d870509fe
|
557
|
/**
|
Sergunb |
0:8f0d870509fe
|
558
|
* @brief Enables or disables the USARTs LIN mode.
|
Sergunb |
0:8f0d870509fe
|
559
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
560
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
561
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
562
|
* @param NewState: new state of the USART LIN mode.
|
Sergunb |
0:8f0d870509fe
|
563
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
564
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
565
|
*/
|
Sergunb |
0:8f0d870509fe
|
566
|
void USART_LINCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
567
|
{
|
Sergunb |
0:8f0d870509fe
|
568
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
569
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
570
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
571
|
|
Sergunb |
0:8f0d870509fe
|
572
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
573
|
{
|
Sergunb |
0:8f0d870509fe
|
574
|
/* Enable the LIN mode by setting the LINEN bit in the CR2 register */
|
Sergunb |
0:8f0d870509fe
|
575
|
USARTx->CR2 |= CR2_LINEN_Set;
|
Sergunb |
0:8f0d870509fe
|
576
|
}
|
Sergunb |
0:8f0d870509fe
|
577
|
else
|
Sergunb |
0:8f0d870509fe
|
578
|
{
|
Sergunb |
0:8f0d870509fe
|
579
|
/* Disable the LIN mode by clearing the LINEN bit in the CR2 register */
|
Sergunb |
0:8f0d870509fe
|
580
|
USARTx->CR2 &= CR2_LINEN_Reset;
|
Sergunb |
0:8f0d870509fe
|
581
|
}
|
Sergunb |
0:8f0d870509fe
|
582
|
}
|
Sergunb |
0:8f0d870509fe
|
583
|
|
Sergunb |
0:8f0d870509fe
|
584
|
/**
|
Sergunb |
0:8f0d870509fe
|
585
|
* @brief Transmits single data through the USARTx peripheral.
|
Sergunb |
0:8f0d870509fe
|
586
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
587
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
588
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
589
|
* @param Data: the data to transmit.
|
Sergunb |
0:8f0d870509fe
|
590
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
591
|
*/
|
Sergunb |
0:8f0d870509fe
|
592
|
void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
|
Sergunb |
0:8f0d870509fe
|
593
|
{
|
Sergunb |
0:8f0d870509fe
|
594
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
595
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
596
|
assert_param(IS_USART_DATA(Data));
|
Sergunb |
0:8f0d870509fe
|
597
|
|
Sergunb |
0:8f0d870509fe
|
598
|
/* Transmit Data */
|
Sergunb |
0:8f0d870509fe
|
599
|
USARTx->DR = (Data & (uint16_t)0x01FF);
|
Sergunb |
0:8f0d870509fe
|
600
|
}
|
Sergunb |
0:8f0d870509fe
|
601
|
|
Sergunb |
0:8f0d870509fe
|
602
|
/**
|
Sergunb |
0:8f0d870509fe
|
603
|
* @brief Returns the most recent received data by the USARTx peripheral.
|
Sergunb |
0:8f0d870509fe
|
604
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
605
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
606
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
607
|
* @retval The received data.
|
Sergunb |
0:8f0d870509fe
|
608
|
*/
|
Sergunb |
0:8f0d870509fe
|
609
|
uint16_t USART_ReceiveData(USART_TypeDef* USARTx)
|
Sergunb |
0:8f0d870509fe
|
610
|
{
|
Sergunb |
0:8f0d870509fe
|
611
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
612
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
613
|
|
Sergunb |
0:8f0d870509fe
|
614
|
/* Receive Data */
|
Sergunb |
0:8f0d870509fe
|
615
|
return (uint16_t)(USARTx->DR & (uint16_t)0x01FF);
|
Sergunb |
0:8f0d870509fe
|
616
|
}
|
Sergunb |
0:8f0d870509fe
|
617
|
|
Sergunb |
0:8f0d870509fe
|
618
|
/**
|
Sergunb |
0:8f0d870509fe
|
619
|
* @brief Transmits break characters.
|
Sergunb |
0:8f0d870509fe
|
620
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
621
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
622
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
623
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
624
|
*/
|
Sergunb |
0:8f0d870509fe
|
625
|
void USART_SendBreak(USART_TypeDef* USARTx)
|
Sergunb |
0:8f0d870509fe
|
626
|
{
|
Sergunb |
0:8f0d870509fe
|
627
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
628
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
629
|
|
Sergunb |
0:8f0d870509fe
|
630
|
/* Send break characters */
|
Sergunb |
0:8f0d870509fe
|
631
|
USARTx->CR1 |= CR1_SBK_Set;
|
Sergunb |
0:8f0d870509fe
|
632
|
}
|
Sergunb |
0:8f0d870509fe
|
633
|
|
Sergunb |
0:8f0d870509fe
|
634
|
/**
|
Sergunb |
0:8f0d870509fe
|
635
|
* @brief Sets the specified USART guard time.
|
Sergunb |
0:8f0d870509fe
|
636
|
* @param USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
|
Sergunb |
0:8f0d870509fe
|
637
|
* @param USART_GuardTime: specifies the guard time.
|
Sergunb |
0:8f0d870509fe
|
638
|
* @note The guard time bits are not available for UART4 and UART5.
|
Sergunb |
0:8f0d870509fe
|
639
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
640
|
*/
|
Sergunb |
0:8f0d870509fe
|
641
|
void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime)
|
Sergunb |
0:8f0d870509fe
|
642
|
{
|
Sergunb |
0:8f0d870509fe
|
643
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
644
|
assert_param(IS_USART_123_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
645
|
|
Sergunb |
0:8f0d870509fe
|
646
|
/* Clear the USART Guard time */
|
Sergunb |
0:8f0d870509fe
|
647
|
USARTx->GTPR &= GTPR_LSB_Mask;
|
Sergunb |
0:8f0d870509fe
|
648
|
/* Set the USART guard time */
|
Sergunb |
0:8f0d870509fe
|
649
|
USARTx->GTPR |= (uint16_t)((uint16_t)USART_GuardTime << 0x08);
|
Sergunb |
0:8f0d870509fe
|
650
|
}
|
Sergunb |
0:8f0d870509fe
|
651
|
|
Sergunb |
0:8f0d870509fe
|
652
|
/**
|
Sergunb |
0:8f0d870509fe
|
653
|
* @brief Sets the system clock prescaler.
|
Sergunb |
0:8f0d870509fe
|
654
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
655
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
656
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
657
|
* @param USART_Prescaler: specifies the prescaler clock.
|
Sergunb |
0:8f0d870509fe
|
658
|
* @note The function is used for IrDA mode with UART4 and UART5.
|
Sergunb |
0:8f0d870509fe
|
659
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
660
|
*/
|
Sergunb |
0:8f0d870509fe
|
661
|
void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler)
|
Sergunb |
0:8f0d870509fe
|
662
|
{
|
Sergunb |
0:8f0d870509fe
|
663
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
664
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
665
|
|
Sergunb |
0:8f0d870509fe
|
666
|
/* Clear the USART prescaler */
|
Sergunb |
0:8f0d870509fe
|
667
|
USARTx->GTPR &= GTPR_MSB_Mask;
|
Sergunb |
0:8f0d870509fe
|
668
|
/* Set the USART prescaler */
|
Sergunb |
0:8f0d870509fe
|
669
|
USARTx->GTPR |= USART_Prescaler;
|
Sergunb |
0:8f0d870509fe
|
670
|
}
|
Sergunb |
0:8f0d870509fe
|
671
|
|
Sergunb |
0:8f0d870509fe
|
672
|
/**
|
Sergunb |
0:8f0d870509fe
|
673
|
* @brief Enables or disables the USARTs Smart Card mode.
|
Sergunb |
0:8f0d870509fe
|
674
|
* @param USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
|
Sergunb |
0:8f0d870509fe
|
675
|
* @param NewState: new state of the Smart Card mode.
|
Sergunb |
0:8f0d870509fe
|
676
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
677
|
* @note The Smart Card mode is not available for UART4 and UART5.
|
Sergunb |
0:8f0d870509fe
|
678
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
679
|
*/
|
Sergunb |
0:8f0d870509fe
|
680
|
void USART_SmartCardCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
681
|
{
|
Sergunb |
0:8f0d870509fe
|
682
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
683
|
assert_param(IS_USART_123_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
684
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
685
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
686
|
{
|
Sergunb |
0:8f0d870509fe
|
687
|
/* Enable the SC mode by setting the SCEN bit in the CR3 register */
|
Sergunb |
0:8f0d870509fe
|
688
|
USARTx->CR3 |= CR3_SCEN_Set;
|
Sergunb |
0:8f0d870509fe
|
689
|
}
|
Sergunb |
0:8f0d870509fe
|
690
|
else
|
Sergunb |
0:8f0d870509fe
|
691
|
{
|
Sergunb |
0:8f0d870509fe
|
692
|
/* Disable the SC mode by clearing the SCEN bit in the CR3 register */
|
Sergunb |
0:8f0d870509fe
|
693
|
USARTx->CR3 &= CR3_SCEN_Reset;
|
Sergunb |
0:8f0d870509fe
|
694
|
}
|
Sergunb |
0:8f0d870509fe
|
695
|
}
|
Sergunb |
0:8f0d870509fe
|
696
|
|
Sergunb |
0:8f0d870509fe
|
697
|
/**
|
Sergunb |
0:8f0d870509fe
|
698
|
* @brief Enables or disables NACK transmission.
|
Sergunb |
0:8f0d870509fe
|
699
|
* @param USARTx: where x can be 1, 2 or 3 to select the USART peripheral.
|
Sergunb |
0:8f0d870509fe
|
700
|
* @param NewState: new state of the NACK transmission.
|
Sergunb |
0:8f0d870509fe
|
701
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
702
|
* @note The Smart Card mode is not available for UART4 and UART5.
|
Sergunb |
0:8f0d870509fe
|
703
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
704
|
*/
|
Sergunb |
0:8f0d870509fe
|
705
|
void USART_SmartCardNACKCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
706
|
{
|
Sergunb |
0:8f0d870509fe
|
707
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
708
|
assert_param(IS_USART_123_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
709
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
710
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
711
|
{
|
Sergunb |
0:8f0d870509fe
|
712
|
/* Enable the NACK transmission by setting the NACK bit in the CR3 register */
|
Sergunb |
0:8f0d870509fe
|
713
|
USARTx->CR3 |= CR3_NACK_Set;
|
Sergunb |
0:8f0d870509fe
|
714
|
}
|
Sergunb |
0:8f0d870509fe
|
715
|
else
|
Sergunb |
0:8f0d870509fe
|
716
|
{
|
Sergunb |
0:8f0d870509fe
|
717
|
/* Disable the NACK transmission by clearing the NACK bit in the CR3 register */
|
Sergunb |
0:8f0d870509fe
|
718
|
USARTx->CR3 &= CR3_NACK_Reset;
|
Sergunb |
0:8f0d870509fe
|
719
|
}
|
Sergunb |
0:8f0d870509fe
|
720
|
}
|
Sergunb |
0:8f0d870509fe
|
721
|
|
Sergunb |
0:8f0d870509fe
|
722
|
/**
|
Sergunb |
0:8f0d870509fe
|
723
|
* @brief Enables or disables the USARTs Half Duplex communication.
|
Sergunb |
0:8f0d870509fe
|
724
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
725
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
726
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
727
|
* @param NewState: new state of the USART Communication.
|
Sergunb |
0:8f0d870509fe
|
728
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
729
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
730
|
*/
|
Sergunb |
0:8f0d870509fe
|
731
|
void USART_HalfDuplexCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
732
|
{
|
Sergunb |
0:8f0d870509fe
|
733
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
734
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
735
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
736
|
|
Sergunb |
0:8f0d870509fe
|
737
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
738
|
{
|
Sergunb |
0:8f0d870509fe
|
739
|
/* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
|
Sergunb |
0:8f0d870509fe
|
740
|
USARTx->CR3 |= CR3_HDSEL_Set;
|
Sergunb |
0:8f0d870509fe
|
741
|
}
|
Sergunb |
0:8f0d870509fe
|
742
|
else
|
Sergunb |
0:8f0d870509fe
|
743
|
{
|
Sergunb |
0:8f0d870509fe
|
744
|
/* Disable the Half-Duplex mode by clearing the HDSEL bit in the CR3 register */
|
Sergunb |
0:8f0d870509fe
|
745
|
USARTx->CR3 &= CR3_HDSEL_Reset;
|
Sergunb |
0:8f0d870509fe
|
746
|
}
|
Sergunb |
0:8f0d870509fe
|
747
|
}
|
Sergunb |
0:8f0d870509fe
|
748
|
|
Sergunb |
0:8f0d870509fe
|
749
|
|
Sergunb |
0:8f0d870509fe
|
750
|
/**
|
Sergunb |
0:8f0d870509fe
|
751
|
* @brief Enables or disables the USART's 8x oversampling mode.
|
Sergunb |
0:8f0d870509fe
|
752
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
753
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
754
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
755
|
* @param NewState: new state of the USART one bit sampling method.
|
Sergunb |
0:8f0d870509fe
|
756
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
757
|
* @note
|
Sergunb |
0:8f0d870509fe
|
758
|
* This function has to be called before calling USART_Init()
|
Sergunb |
0:8f0d870509fe
|
759
|
* function in order to have correct baudrate Divider value.
|
Sergunb |
0:8f0d870509fe
|
760
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
761
|
*/
|
Sergunb |
0:8f0d870509fe
|
762
|
void USART_OverSampling8Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
763
|
{
|
Sergunb |
0:8f0d870509fe
|
764
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
765
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
766
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
767
|
|
Sergunb |
0:8f0d870509fe
|
768
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
769
|
{
|
Sergunb |
0:8f0d870509fe
|
770
|
/* Enable the 8x Oversampling mode by setting the OVER8 bit in the CR1 register */
|
Sergunb |
0:8f0d870509fe
|
771
|
USARTx->CR1 |= CR1_OVER8_Set;
|
Sergunb |
0:8f0d870509fe
|
772
|
}
|
Sergunb |
0:8f0d870509fe
|
773
|
else
|
Sergunb |
0:8f0d870509fe
|
774
|
{
|
Sergunb |
0:8f0d870509fe
|
775
|
/* Disable the 8x Oversampling mode by clearing the OVER8 bit in the CR1 register */
|
Sergunb |
0:8f0d870509fe
|
776
|
USARTx->CR1 &= CR1_OVER8_Reset;
|
Sergunb |
0:8f0d870509fe
|
777
|
}
|
Sergunb |
0:8f0d870509fe
|
778
|
}
|
Sergunb |
0:8f0d870509fe
|
779
|
|
Sergunb |
0:8f0d870509fe
|
780
|
/**
|
Sergunb |
0:8f0d870509fe
|
781
|
* @brief Enables or disables the USART's one bit sampling method.
|
Sergunb |
0:8f0d870509fe
|
782
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
783
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
784
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
785
|
* @param NewState: new state of the USART one bit sampling method.
|
Sergunb |
0:8f0d870509fe
|
786
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
787
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
788
|
*/
|
Sergunb |
0:8f0d870509fe
|
789
|
void USART_OneBitMethodCmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
790
|
{
|
Sergunb |
0:8f0d870509fe
|
791
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
792
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
793
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
794
|
|
Sergunb |
0:8f0d870509fe
|
795
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
796
|
{
|
Sergunb |
0:8f0d870509fe
|
797
|
/* Enable the one bit method by setting the ONEBITE bit in the CR3 register */
|
Sergunb |
0:8f0d870509fe
|
798
|
USARTx->CR3 |= CR3_ONEBITE_Set;
|
Sergunb |
0:8f0d870509fe
|
799
|
}
|
Sergunb |
0:8f0d870509fe
|
800
|
else
|
Sergunb |
0:8f0d870509fe
|
801
|
{
|
Sergunb |
0:8f0d870509fe
|
802
|
/* Disable tthe one bit method by clearing the ONEBITE bit in the CR3 register */
|
Sergunb |
0:8f0d870509fe
|
803
|
USARTx->CR3 &= CR3_ONEBITE_Reset;
|
Sergunb |
0:8f0d870509fe
|
804
|
}
|
Sergunb |
0:8f0d870509fe
|
805
|
}
|
Sergunb |
0:8f0d870509fe
|
806
|
|
Sergunb |
0:8f0d870509fe
|
807
|
/**
|
Sergunb |
0:8f0d870509fe
|
808
|
* @brief Configures the USART's IrDA interface.
|
Sergunb |
0:8f0d870509fe
|
809
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
810
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
811
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
812
|
* @param USART_IrDAMode: specifies the IrDA mode.
|
Sergunb |
0:8f0d870509fe
|
813
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
814
|
* @arg USART_IrDAMode_LowPower
|
Sergunb |
0:8f0d870509fe
|
815
|
* @arg USART_IrDAMode_Normal
|
Sergunb |
0:8f0d870509fe
|
816
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
817
|
*/
|
Sergunb |
0:8f0d870509fe
|
818
|
void USART_IrDAConfig(USART_TypeDef* USARTx, uint16_t USART_IrDAMode)
|
Sergunb |
0:8f0d870509fe
|
819
|
{
|
Sergunb |
0:8f0d870509fe
|
820
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
821
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
822
|
assert_param(IS_USART_IRDA_MODE(USART_IrDAMode));
|
Sergunb |
0:8f0d870509fe
|
823
|
|
Sergunb |
0:8f0d870509fe
|
824
|
USARTx->CR3 &= CR3_IRLP_Mask;
|
Sergunb |
0:8f0d870509fe
|
825
|
USARTx->CR3 |= USART_IrDAMode;
|
Sergunb |
0:8f0d870509fe
|
826
|
}
|
Sergunb |
0:8f0d870509fe
|
827
|
|
Sergunb |
0:8f0d870509fe
|
828
|
/**
|
Sergunb |
0:8f0d870509fe
|
829
|
* @brief Enables or disables the USART's IrDA interface.
|
Sergunb |
0:8f0d870509fe
|
830
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
831
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
832
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
833
|
* @param NewState: new state of the IrDA mode.
|
Sergunb |
0:8f0d870509fe
|
834
|
* This parameter can be: ENABLE or DISABLE.
|
Sergunb |
0:8f0d870509fe
|
835
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
836
|
*/
|
Sergunb |
0:8f0d870509fe
|
837
|
void USART_IrDACmd(USART_TypeDef* USARTx, FunctionalState NewState)
|
Sergunb |
0:8f0d870509fe
|
838
|
{
|
Sergunb |
0:8f0d870509fe
|
839
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
840
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
841
|
assert_param(IS_FUNCTIONAL_STATE(NewState));
|
Sergunb |
0:8f0d870509fe
|
842
|
|
Sergunb |
0:8f0d870509fe
|
843
|
if (NewState != DISABLE)
|
Sergunb |
0:8f0d870509fe
|
844
|
{
|
Sergunb |
0:8f0d870509fe
|
845
|
/* Enable the IrDA mode by setting the IREN bit in the CR3 register */
|
Sergunb |
0:8f0d870509fe
|
846
|
USARTx->CR3 |= CR3_IREN_Set;
|
Sergunb |
0:8f0d870509fe
|
847
|
}
|
Sergunb |
0:8f0d870509fe
|
848
|
else
|
Sergunb |
0:8f0d870509fe
|
849
|
{
|
Sergunb |
0:8f0d870509fe
|
850
|
/* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
|
Sergunb |
0:8f0d870509fe
|
851
|
USARTx->CR3 &= CR3_IREN_Reset;
|
Sergunb |
0:8f0d870509fe
|
852
|
}
|
Sergunb |
0:8f0d870509fe
|
853
|
}
|
Sergunb |
0:8f0d870509fe
|
854
|
|
Sergunb |
0:8f0d870509fe
|
855
|
/**
|
Sergunb |
0:8f0d870509fe
|
856
|
* @brief Checks whether the specified USART flag is set or not.
|
Sergunb |
0:8f0d870509fe
|
857
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
858
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
859
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
860
|
* @param USART_FLAG: specifies the flag to check.
|
Sergunb |
0:8f0d870509fe
|
861
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
862
|
* @arg USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
|
Sergunb |
0:8f0d870509fe
|
863
|
* @arg USART_FLAG_LBD: LIN Break detection flag
|
Sergunb |
0:8f0d870509fe
|
864
|
* @arg USART_FLAG_TXE: Transmit data register empty flag
|
Sergunb |
0:8f0d870509fe
|
865
|
* @arg USART_FLAG_TC: Transmission Complete flag
|
Sergunb |
0:8f0d870509fe
|
866
|
* @arg USART_FLAG_RXNE: Receive data register not empty flag
|
Sergunb |
0:8f0d870509fe
|
867
|
* @arg USART_FLAG_IDLE: Idle Line detection flag
|
Sergunb |
0:8f0d870509fe
|
868
|
* @arg USART_FLAG_ORE: OverRun Error flag
|
Sergunb |
0:8f0d870509fe
|
869
|
* @arg USART_FLAG_NE: Noise Error flag
|
Sergunb |
0:8f0d870509fe
|
870
|
* @arg USART_FLAG_FE: Framing Error flag
|
Sergunb |
0:8f0d870509fe
|
871
|
* @arg USART_FLAG_PE: Parity Error flag
|
Sergunb |
0:8f0d870509fe
|
872
|
* @retval The new state of USART_FLAG (SET or RESET).
|
Sergunb |
0:8f0d870509fe
|
873
|
*/
|
Sergunb |
0:8f0d870509fe
|
874
|
FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG)
|
Sergunb |
0:8f0d870509fe
|
875
|
{
|
Sergunb |
0:8f0d870509fe
|
876
|
FlagStatus bitstatus = RESET;
|
Sergunb |
0:8f0d870509fe
|
877
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
878
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
879
|
assert_param(IS_USART_FLAG(USART_FLAG));
|
Sergunb |
0:8f0d870509fe
|
880
|
/* The CTS flag is not available for UART4 and UART5 */
|
Sergunb |
0:8f0d870509fe
|
881
|
if (USART_FLAG == USART_FLAG_CTS)
|
Sergunb |
0:8f0d870509fe
|
882
|
{
|
Sergunb |
0:8f0d870509fe
|
883
|
assert_param(IS_USART_123_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
884
|
}
|
Sergunb |
0:8f0d870509fe
|
885
|
|
Sergunb |
0:8f0d870509fe
|
886
|
if ((USARTx->SR & USART_FLAG) != (uint16_t)RESET)
|
Sergunb |
0:8f0d870509fe
|
887
|
{
|
Sergunb |
0:8f0d870509fe
|
888
|
bitstatus = SET;
|
Sergunb |
0:8f0d870509fe
|
889
|
}
|
Sergunb |
0:8f0d870509fe
|
890
|
else
|
Sergunb |
0:8f0d870509fe
|
891
|
{
|
Sergunb |
0:8f0d870509fe
|
892
|
bitstatus = RESET;
|
Sergunb |
0:8f0d870509fe
|
893
|
}
|
Sergunb |
0:8f0d870509fe
|
894
|
return bitstatus;
|
Sergunb |
0:8f0d870509fe
|
895
|
}
|
Sergunb |
0:8f0d870509fe
|
896
|
|
Sergunb |
0:8f0d870509fe
|
897
|
/**
|
Sergunb |
0:8f0d870509fe
|
898
|
* @brief Clears the USARTx's pending flags.
|
Sergunb |
0:8f0d870509fe
|
899
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
900
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
901
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
902
|
* @param USART_FLAG: specifies the flag to clear.
|
Sergunb |
0:8f0d870509fe
|
903
|
* This parameter can be any combination of the following values:
|
Sergunb |
0:8f0d870509fe
|
904
|
* @arg USART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5).
|
Sergunb |
0:8f0d870509fe
|
905
|
* @arg USART_FLAG_LBD: LIN Break detection flag.
|
Sergunb |
0:8f0d870509fe
|
906
|
* @arg USART_FLAG_TC: Transmission Complete flag.
|
Sergunb |
0:8f0d870509fe
|
907
|
* @arg USART_FLAG_RXNE: Receive data register not empty flag.
|
Sergunb |
0:8f0d870509fe
|
908
|
*
|
Sergunb |
0:8f0d870509fe
|
909
|
* @note
|
Sergunb |
0:8f0d870509fe
|
910
|
* - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
|
Sergunb |
0:8f0d870509fe
|
911
|
* error) and IDLE (Idle line detected) flags are cleared by software
|
Sergunb |
0:8f0d870509fe
|
912
|
* sequence: a read operation to USART_SR register (USART_GetFlagStatus())
|
Sergunb |
0:8f0d870509fe
|
913
|
* followed by a read operation to USART_DR register (USART_ReceiveData()).
|
Sergunb |
0:8f0d870509fe
|
914
|
* - RXNE flag can be also cleared by a read to the USART_DR register
|
Sergunb |
0:8f0d870509fe
|
915
|
* (USART_ReceiveData()).
|
Sergunb |
0:8f0d870509fe
|
916
|
* - TC flag can be also cleared by software sequence: a read operation to
|
Sergunb |
0:8f0d870509fe
|
917
|
* USART_SR register (USART_GetFlagStatus()) followed by a write operation
|
Sergunb |
0:8f0d870509fe
|
918
|
* to USART_DR register (USART_SendData()).
|
Sergunb |
0:8f0d870509fe
|
919
|
* - TXE flag is cleared only by a write to the USART_DR register
|
Sergunb |
0:8f0d870509fe
|
920
|
* (USART_SendData()).
|
Sergunb |
0:8f0d870509fe
|
921
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
922
|
*/
|
Sergunb |
0:8f0d870509fe
|
923
|
void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG)
|
Sergunb |
0:8f0d870509fe
|
924
|
{
|
Sergunb |
0:8f0d870509fe
|
925
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
926
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
927
|
assert_param(IS_USART_CLEAR_FLAG(USART_FLAG));
|
Sergunb |
0:8f0d870509fe
|
928
|
/* The CTS flag is not available for UART4 and UART5 */
|
Sergunb |
0:8f0d870509fe
|
929
|
if ((USART_FLAG & USART_FLAG_CTS) == USART_FLAG_CTS)
|
Sergunb |
0:8f0d870509fe
|
930
|
{
|
Sergunb |
0:8f0d870509fe
|
931
|
assert_param(IS_USART_123_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
932
|
}
|
Sergunb |
0:8f0d870509fe
|
933
|
|
Sergunb |
0:8f0d870509fe
|
934
|
USARTx->SR = (uint16_t)~USART_FLAG;
|
Sergunb |
0:8f0d870509fe
|
935
|
}
|
Sergunb |
0:8f0d870509fe
|
936
|
|
Sergunb |
0:8f0d870509fe
|
937
|
/**
|
Sergunb |
0:8f0d870509fe
|
938
|
* @brief Checks whether the specified USART interrupt has occurred or not.
|
Sergunb |
0:8f0d870509fe
|
939
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
940
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
941
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
942
|
* @param USART_IT: specifies the USART interrupt source to check.
|
Sergunb |
0:8f0d870509fe
|
943
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
944
|
* @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
|
Sergunb |
0:8f0d870509fe
|
945
|
* @arg USART_IT_LBD: LIN Break detection interrupt
|
Sergunb |
0:8f0d870509fe
|
946
|
* @arg USART_IT_TXE: Tansmit Data Register empty interrupt
|
Sergunb |
0:8f0d870509fe
|
947
|
* @arg USART_IT_TC: Transmission complete interrupt
|
Sergunb |
0:8f0d870509fe
|
948
|
* @arg USART_IT_RXNE: Receive Data register not empty interrupt
|
Sergunb |
0:8f0d870509fe
|
949
|
* @arg USART_IT_IDLE: Idle line detection interrupt
|
Sergunb |
0:8f0d870509fe
|
950
|
* @arg USART_IT_ORE: OverRun Error interrupt
|
Sergunb |
0:8f0d870509fe
|
951
|
* @arg USART_IT_NE: Noise Error interrupt
|
Sergunb |
0:8f0d870509fe
|
952
|
* @arg USART_IT_FE: Framing Error interrupt
|
Sergunb |
0:8f0d870509fe
|
953
|
* @arg USART_IT_PE: Parity Error interrupt
|
Sergunb |
0:8f0d870509fe
|
954
|
* @retval The new state of USART_IT (SET or RESET).
|
Sergunb |
0:8f0d870509fe
|
955
|
*/
|
Sergunb |
0:8f0d870509fe
|
956
|
ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint16_t USART_IT)
|
Sergunb |
0:8f0d870509fe
|
957
|
{
|
Sergunb |
0:8f0d870509fe
|
958
|
uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
|
Sergunb |
0:8f0d870509fe
|
959
|
ITStatus bitstatus = RESET;
|
Sergunb |
0:8f0d870509fe
|
960
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
961
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
962
|
assert_param(IS_USART_GET_IT(USART_IT));
|
Sergunb |
0:8f0d870509fe
|
963
|
/* The CTS interrupt is not available for UART4 and UART5 */
|
Sergunb |
0:8f0d870509fe
|
964
|
if (USART_IT == USART_IT_CTS)
|
Sergunb |
0:8f0d870509fe
|
965
|
{
|
Sergunb |
0:8f0d870509fe
|
966
|
assert_param(IS_USART_123_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
967
|
}
|
Sergunb |
0:8f0d870509fe
|
968
|
|
Sergunb |
0:8f0d870509fe
|
969
|
/* Get the USART register index */
|
Sergunb |
0:8f0d870509fe
|
970
|
usartreg = (((uint8_t)USART_IT) >> 0x05);
|
Sergunb |
0:8f0d870509fe
|
971
|
/* Get the interrupt position */
|
Sergunb |
0:8f0d870509fe
|
972
|
itmask = USART_IT & IT_Mask;
|
Sergunb |
0:8f0d870509fe
|
973
|
itmask = (uint32_t)0x01 << itmask;
|
Sergunb |
0:8f0d870509fe
|
974
|
|
Sergunb |
0:8f0d870509fe
|
975
|
if (usartreg == 0x01) /* The IT is in CR1 register */
|
Sergunb |
0:8f0d870509fe
|
976
|
{
|
Sergunb |
0:8f0d870509fe
|
977
|
itmask &= USARTx->CR1;
|
Sergunb |
0:8f0d870509fe
|
978
|
}
|
Sergunb |
0:8f0d870509fe
|
979
|
else if (usartreg == 0x02) /* The IT is in CR2 register */
|
Sergunb |
0:8f0d870509fe
|
980
|
{
|
Sergunb |
0:8f0d870509fe
|
981
|
itmask &= USARTx->CR2;
|
Sergunb |
0:8f0d870509fe
|
982
|
}
|
Sergunb |
0:8f0d870509fe
|
983
|
else /* The IT is in CR3 register */
|
Sergunb |
0:8f0d870509fe
|
984
|
{
|
Sergunb |
0:8f0d870509fe
|
985
|
itmask &= USARTx->CR3;
|
Sergunb |
0:8f0d870509fe
|
986
|
}
|
Sergunb |
0:8f0d870509fe
|
987
|
|
Sergunb |
0:8f0d870509fe
|
988
|
bitpos = USART_IT >> 0x08;
|
Sergunb |
0:8f0d870509fe
|
989
|
bitpos = (uint32_t)0x01 << bitpos;
|
Sergunb |
0:8f0d870509fe
|
990
|
bitpos &= USARTx->SR;
|
Sergunb |
0:8f0d870509fe
|
991
|
if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
|
Sergunb |
0:8f0d870509fe
|
992
|
{
|
Sergunb |
0:8f0d870509fe
|
993
|
bitstatus = SET;
|
Sergunb |
0:8f0d870509fe
|
994
|
}
|
Sergunb |
0:8f0d870509fe
|
995
|
else
|
Sergunb |
0:8f0d870509fe
|
996
|
{
|
Sergunb |
0:8f0d870509fe
|
997
|
bitstatus = RESET;
|
Sergunb |
0:8f0d870509fe
|
998
|
}
|
Sergunb |
0:8f0d870509fe
|
999
|
|
Sergunb |
0:8f0d870509fe
|
1000
|
return bitstatus;
|
Sergunb |
0:8f0d870509fe
|
1001
|
}
|
Sergunb |
0:8f0d870509fe
|
1002
|
|
Sergunb |
0:8f0d870509fe
|
1003
|
/**
|
Sergunb |
0:8f0d870509fe
|
1004
|
* @brief Clears the USARTx's interrupt pending bits.
|
Sergunb |
0:8f0d870509fe
|
1005
|
* @param USARTx: Select the USART or the UART peripheral.
|
Sergunb |
0:8f0d870509fe
|
1006
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
1007
|
* USART1, USART2, USART3, UART4 or UART5.
|
Sergunb |
0:8f0d870509fe
|
1008
|
* @param USART_IT: specifies the interrupt pending bit to clear.
|
Sergunb |
0:8f0d870509fe
|
1009
|
* This parameter can be one of the following values:
|
Sergunb |
0:8f0d870509fe
|
1010
|
* @arg USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
|
Sergunb |
0:8f0d870509fe
|
1011
|
* @arg USART_IT_LBD: LIN Break detection interrupt
|
Sergunb |
0:8f0d870509fe
|
1012
|
* @arg USART_IT_TC: Transmission complete interrupt.
|
Sergunb |
0:8f0d870509fe
|
1013
|
* @arg USART_IT_RXNE: Receive Data register not empty interrupt.
|
Sergunb |
0:8f0d870509fe
|
1014
|
*
|
Sergunb |
0:8f0d870509fe
|
1015
|
* @note
|
Sergunb |
0:8f0d870509fe
|
1016
|
* - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
|
Sergunb |
0:8f0d870509fe
|
1017
|
* error) and IDLE (Idle line detected) pending bits are cleared by
|
Sergunb |
0:8f0d870509fe
|
1018
|
* software sequence: a read operation to USART_SR register
|
Sergunb |
0:8f0d870509fe
|
1019
|
* (USART_GetITStatus()) followed by a read operation to USART_DR register
|
Sergunb |
0:8f0d870509fe
|
1020
|
* (USART_ReceiveData()).
|
Sergunb |
0:8f0d870509fe
|
1021
|
* - RXNE pending bit can be also cleared by a read to the USART_DR register
|
Sergunb |
0:8f0d870509fe
|
1022
|
* (USART_ReceiveData()).
|
Sergunb |
0:8f0d870509fe
|
1023
|
* - TC pending bit can be also cleared by software sequence: a read
|
Sergunb |
0:8f0d870509fe
|
1024
|
* operation to USART_SR register (USART_GetITStatus()) followed by a write
|
Sergunb |
0:8f0d870509fe
|
1025
|
* operation to USART_DR register (USART_SendData()).
|
Sergunb |
0:8f0d870509fe
|
1026
|
* - TXE pending bit is cleared only by a write to the USART_DR register
|
Sergunb |
0:8f0d870509fe
|
1027
|
* (USART_SendData()).
|
Sergunb |
0:8f0d870509fe
|
1028
|
* @retval None
|
Sergunb |
0:8f0d870509fe
|
1029
|
*/
|
Sergunb |
0:8f0d870509fe
|
1030
|
void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT)
|
Sergunb |
0:8f0d870509fe
|
1031
|
{
|
Sergunb |
0:8f0d870509fe
|
1032
|
uint16_t bitpos = 0x00, itmask = 0x00;
|
Sergunb |
0:8f0d870509fe
|
1033
|
/* Check the parameters */
|
Sergunb |
0:8f0d870509fe
|
1034
|
assert_param(IS_USART_ALL_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
1035
|
assert_param(IS_USART_CLEAR_IT(USART_IT));
|
Sergunb |
0:8f0d870509fe
|
1036
|
/* The CTS interrupt is not available for UART4 and UART5 */
|
Sergunb |
0:8f0d870509fe
|
1037
|
if (USART_IT == USART_IT_CTS)
|
Sergunb |
0:8f0d870509fe
|
1038
|
{
|
Sergunb |
0:8f0d870509fe
|
1039
|
assert_param(IS_USART_123_PERIPH(USARTx));
|
Sergunb |
0:8f0d870509fe
|
1040
|
}
|
Sergunb |
0:8f0d870509fe
|
1041
|
|
Sergunb |
0:8f0d870509fe
|
1042
|
bitpos = USART_IT >> 0x08;
|
Sergunb |
0:8f0d870509fe
|
1043
|
itmask = ((uint16_t)0x01 << (uint16_t)bitpos);
|
Sergunb |
0:8f0d870509fe
|
1044
|
USARTx->SR = (uint16_t)~itmask;
|
Sergunb |
0:8f0d870509fe
|
1045
|
}
|
Sergunb |
0:8f0d870509fe
|
1046
|
/**
|
Sergunb |
0:8f0d870509fe
|
1047
|
* @}
|
Sergunb |
0:8f0d870509fe
|
1048
|
*/
|
Sergunb |
0:8f0d870509fe
|
1049
|
|
Sergunb |
0:8f0d870509fe
|
1050
|
/**
|
Sergunb |
0:8f0d870509fe
|
1051
|
* @}
|
Sergunb |
0:8f0d870509fe
|
1052
|
*/
|
Sergunb |
0:8f0d870509fe
|
1053
|
|
Sergunb |
0:8f0d870509fe
|
1054
|
/**
|
Sergunb |
0:8f0d870509fe
|
1055
|
* @}
|
Sergunb |
0:8f0d870509fe
|
1056
|
*/
|
Sergunb |
0:8f0d870509fe
|
1057
|
|
Sergunb |
0:8f0d870509fe
|
1058
|
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
|