1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
28
33
38
43
48
53
54
55
56
57
58
59
60
61
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
86
87
88
89
90
91
92
93
94
95
96
97
98
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
125
126
127
128
129
130
131
132
133
134
135
136
137
138
144
145
146
147
148
149
150
151
152
153
154
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
178
179
180
181
182
183
184
185
186
187
188
190
191
192
193
194
198
199
200
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
229
230
231
232
233
234
235
236
237
238
239
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/* ... */
#include "main.h"
extern DMA_HandleTypeDef hdma_usart3_tx;
Includes
Private typedef
Private define
Private macro
Private variables
Private function prototypes
/* ... */
void HAL_MspInit(void)
{
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
}{ ... }
/* ... */
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(huart->Instance==USART3)
{
__HAL_RCC_USART3_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/* ... */
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
hdma_usart3_tx.Instance = DMA1_Stream3;
hdma_usart3_tx.Init.Channel = DMA_CHANNEL_4;
hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart3_tx.Init.Mode = DMA_NORMAL;
hdma_usart3_tx.Init.Priority = DMA_PRIORITY_LOW;
hdma_usart3_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
if (HAL_DMA_Init(&hdma_usart3_tx) != HAL_OK)
{
Error_Handler();
}if (HAL_DMA_Init(&hdma_usart3_tx) != HAL_OK) { ... }
__HAL_LINKDMA(huart,hdmatx,hdma_usart3_tx);
HAL_NVIC_SetPriority(USART3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(USART3_IRQn);
}if (huart->Instance==USART3) { ... }
}{ ... }
/* ... */
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
{
if(huart->Instance==USART3)
{
__HAL_RCC_USART3_CLK_DISABLE();
/* ... */
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11);
HAL_DMA_DeInit(huart->hdmatx);
HAL_NVIC_DisableIRQ(USART3_IRQn);
}if (huart->Instance==USART3) { ... }
}{ ... }
/* ... */
void HAL_PCD_MspInit(PCD_HandleTypeDef* hpcd)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if(hpcd->Instance==USB_OTG_FS)
{
/* ... */
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_CLK48;
PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV8;
PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLSAIP;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { ... }
__HAL_RCC_GPIOA_CLK_ENABLE();
/* ... */
GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_11;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
HAL_NVIC_SetPriority(OTG_FS_IRQn, 6, 0);
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
}if (hpcd->Instance==USB_OTG_FS) { ... }
}{ ... }
/* ... */
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* hpcd)
{
if(hpcd->Instance==USB_OTG_FS)
{
__HAL_RCC_USB_OTG_FS_CLK_DISABLE();
/* ... */
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12|GPIO_PIN_11);
HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
}if (hpcd->Instance==USB_OTG_FS) { ... }
}{ ... }
External functions