提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file : BSP.c |
|
4 |
* @brief : Board Speciafic program |
|
5 |
****************************************************************************** |
|
6 |
* |
|
7 |
****************************************************************************** |
|
8 |
*/ |
|
9 |
/* Includes ------------------------------------------------------------------*/ |
|
10 |
|
|
11 |
#include "BSP.h" |
|
12 |
|
|
13 |
#include "Globaldef.h" |
|
14 |
#include "Functions.h" |
|
15 |
#if (BOARD_TYPE == 14) |
5dd1b7
|
16 |
#include "fpx.h" |
483170
|
17 |
#endif |
Q |
18 |
|
|
19 |
/** |
|
20 |
* @brief System Clock Configuration |
|
21 |
* @retval None |
|
22 |
*/ |
|
23 |
|
842bb6
|
24 |
void SystemClock_Config_New(void) |
483170
|
25 |
{ |
842bb6
|
26 |
LL_FLASH_SetLatency(LL_FLASH_LATENCY_1); |
Q |
27 |
|
|
28 |
if(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_1) |
|
29 |
{ |
|
30 |
Error_Handler(); |
|
31 |
} |
|
32 |
LL_RCC_HSE_Enable(); |
|
33 |
|
|
34 |
/* Wait till HSE is ready */ |
|
35 |
while(LL_RCC_HSE_IsReady() != 1) |
|
36 |
{ |
|
37 |
|
|
38 |
} |
|
39 |
LL_RCC_LSI_Enable(); |
|
40 |
|
|
41 |
/* Wait till LSI is ready */ |
|
42 |
while(LL_RCC_LSI_IsReady() != 1) |
|
43 |
{ |
|
44 |
|
|
45 |
} |
|
46 |
#if (XLAT_FREQ == 12) |
|
47 |
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_3, LL_RCC_PLL_MUL_12); |
|
48 |
#else |
|
49 |
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE_DIV_2, LL_RCC_PLL_MUL_12); |
|
50 |
#endif |
|
51 |
LL_RCC_PLL_Enable(); |
|
52 |
|
|
53 |
/* Wait till PLL is ready */ |
|
54 |
while(LL_RCC_PLL_IsReady() != 1) |
|
55 |
{ |
|
56 |
|
|
57 |
} |
|
58 |
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1); |
|
59 |
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1); |
|
60 |
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL); |
|
61 |
|
|
62 |
/* Wait till System clock is ready */ |
|
63 |
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) |
|
64 |
{ |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
LL_InitTick(48000000,10000); |
|
69 |
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
|
70 |
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
|
71 |
|
|
72 |
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk |
|
73 |
| SysTick_CTRL_TICKINT_Msk; |
|
74 |
|
|
75 |
LL_SetSystemCoreClock(48000000); |
|
76 |
LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK1); |
|
77 |
|
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
void SystemClock_Config(void) |
|
82 |
{ |
483170
|
83 |
RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
Q |
84 |
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
|
85 |
|
|
86 |
/** Initializes the CPU, AHB and APB busses clocks |
|
87 |
*/ |
|
88 |
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
|
89 |
RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
|
90 |
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
|
91 |
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
|
92 |
// RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
|
93 |
|
|
94 |
#if (XLAT_FREQ == 12) |
|
95 |
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV3; |
|
96 |
#else |
|
97 |
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2; |
|
98 |
#endif |
|
99 |
|
|
100 |
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; |
|
101 |
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
|
102 |
{ |
|
103 |
Error_Handler(); |
|
104 |
} |
|
105 |
/** Initializes the CPU, AHB and APB busses clocks |
|
106 |
*/ |
|
107 |
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
|
108 |
|RCC_CLOCKTYPE_PCLK1; |
|
109 |
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
|
110 |
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
|
111 |
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
|
112 |
|
|
113 |
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
|
114 |
{ |
|
115 |
Error_Handler(); |
|
116 |
} |
|
117 |
|
|
118 |
//RCC_OscInitTypeDef RCC_OscInitStruct; |
|
119 |
//RCC_ClkInitTypeDef RCC_ClkInitStruct; |
|
120 |
RCC_PeriphCLKInitTypeDef PeriphClkInit; |
|
121 |
|
|
122 |
/**Initializes the CPU, AHB and APB busses clocks |
|
123 |
*/ |
|
124 |
|
|
125 |
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; |
|
126 |
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK; |
|
127 |
|
|
128 |
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) |
|
129 |
{ |
|
130 |
_Error_Handler(__FILE__, __LINE__); |
|
131 |
} |
|
132 |
|
|
133 |
/**Configure the Systick interrupt time |
|
134 |
*/ |
|
135 |
// HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/10000); |
|
136 |
HAL_SYSTICK_Config(48000000/10000); |
|
137 |
|
|
138 |
/**Configure the Systick |
|
139 |
*/ |
|
140 |
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
|
141 |
|
|
142 |
/* SysTick_IRQn interrupt configuration */ |
|
143 |
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
|
144 |
} |
|
145 |
|
|
146 |
void MX_IWDG_Init(void) |
|
147 |
{ |
|
148 |
|
|
149 |
/* USER CODE BEGIN IWDG_Init 0 */ |
|
150 |
|
|
151 |
/* USER CODE END IWDG_Init 0 */ |
|
152 |
|
|
153 |
/* USER CODE BEGIN IWDG_Init 1 */ |
|
154 |
|
|
155 |
/* USER CODE END IWDG_Init 1 */ |
|
156 |
LL_IWDG_Enable(IWDG); |
|
157 |
LL_IWDG_EnableWriteAccess(IWDG); |
|
158 |
LL_IWDG_SetPrescaler(IWDG, LL_IWDG_PRESCALER_64); |
|
159 |
LL_IWDG_SetReloadCounter(IWDG, 4095); |
|
160 |
while (LL_IWDG_IsReady(IWDG) != 1) |
|
161 |
{ |
|
162 |
} |
|
163 |
|
|
164 |
LL_IWDG_SetWindow(IWDG, 4095); |
|
165 |
LL_IWDG_ReloadCounter(IWDG); |
|
166 |
/* USER CODE BEGIN IWDG_Init 2 */ |
|
167 |
|
|
168 |
/* USER CODE END IWDG_Init 2 */ |
|
169 |
|
|
170 |
} |
|
171 |
/** |
9aed5d
|
172 |
* @brief TIM1 Initialization Function |
Q |
173 |
* @param None |
|
174 |
* @retval None |
|
175 |
*/ |
|
176 |
void MX_TIM1_Init(void) |
|
177 |
{ |
|
178 |
|
|
179 |
/* USER CODE BEGIN TIM1_Init 0 */ |
|
180 |
|
|
181 |
/* USER CODE END TIM1_Init 0 */ |
|
182 |
|
|
183 |
LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
|
184 |
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; |
|
185 |
LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0}; |
|
186 |
|
|
187 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
188 |
|
|
189 |
/* Peripheral clock enable */ |
|
190 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM1); |
|
191 |
|
|
192 |
|
|
193 |
/* USER CODE BEGIN TIM1_Init 1 */ |
|
194 |
|
|
195 |
/* USER CODE END TIM1_Init 1 */ |
|
196 |
TIM_InitStruct.Prescaler = 0; |
|
197 |
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
|
198 |
TIM_InitStruct.Autoreload = 1713; |
|
199 |
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
|
200 |
TIM_InitStruct.RepetitionCounter = 0; |
|
201 |
LL_TIM_Init(TIM1, &TIM_InitStruct); |
|
202 |
LL_TIM_EnableARRPreload(TIM1); |
|
203 |
LL_TIM_SetClockSource(TIM1, LL_TIM_CLOCKSOURCE_INTERNAL); |
|
204 |
LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH1); |
|
205 |
|
|
206 |
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1; |
|
207 |
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
|
208 |
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
|
209 |
TIM_OC_InitStruct.CompareValue = 857; |
|
210 |
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
|
211 |
TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH; |
|
212 |
TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW; |
|
213 |
TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW; |
|
214 |
LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); |
|
215 |
LL_TIM_OC_DisableFast(TIM1, LL_TIM_CHANNEL_CH1); |
|
216 |
|
|
217 |
|
|
218 |
LL_TIM_OC_EnablePreload(TIM1, LL_TIM_CHANNEL_CH4); |
|
219 |
|
|
220 |
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1; |
|
221 |
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
|
222 |
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
|
223 |
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
|
224 |
TIM_OC_InitStruct.CompareValue = 856; |
|
225 |
LL_TIM_OC_Init(TIM1, LL_TIM_CHANNEL_CH4, &TIM_OC_InitStruct); |
|
226 |
|
|
227 |
|
|
228 |
LL_TIM_OC_DisableFast(TIM1, LL_TIM_CHANNEL_CH4); |
|
229 |
LL_TIM_SetTriggerInput(TIM1, LL_TIM_TS_ITR0); |
|
230 |
LL_TIM_SetSlaveMode(TIM1, LL_TIM_SLAVEMODE_RESET); |
|
231 |
LL_TIM_DisableIT_TRIG(TIM1); |
|
232 |
LL_TIM_DisableDMAReq_TRIG(TIM1); |
|
233 |
LL_TIM_SetTriggerOutput(TIM1, LL_TIM_TRGO_RESET); |
|
234 |
LL_TIM_DisableMasterSlaveMode(TIM1); |
|
235 |
|
|
236 |
TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE; |
|
237 |
TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE; |
|
238 |
TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF; |
|
239 |
TIM_BDTRInitStruct.DeadTime = 20; |
|
240 |
TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE; |
|
241 |
TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH; |
|
242 |
TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE; |
|
243 |
LL_TIM_BDTR_Init(TIM1, &TIM_BDTRInitStruct); |
|
244 |
|
|
245 |
|
|
246 |
/* USER CODE BEGIN TIM1_Init 2 */ |
|
247 |
|
|
248 |
/* USER CODE END TIM1_Init 2 */ |
|
249 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
250 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
|
251 |
/**TIM1 GPIO Configuration |
|
252 |
PB13 ------> TIM1_CH1N |
|
253 |
PA8 ------> TIM1_CH1 |
|
254 |
PA11 ------> TIM1_CH4 |
|
255 |
*/ |
|
256 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_13; |
|
257 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
258 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; |
|
259 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
260 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
261 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_2; |
|
262 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
263 |
|
|
264 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_8; |
|
265 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
266 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; |
|
267 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
268 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
269 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_2; |
|
270 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
271 |
|
|
272 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_11; |
|
273 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
274 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; |
|
275 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
276 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
277 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_2; |
|
278 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
279 |
|
|
280 |
|
|
281 |
} |
|
282 |
/** |
483170
|
283 |
* @brief TIM6 Initialization Function |
Q |
284 |
* @param None |
|
285 |
* @retval None |
|
286 |
*/ |
|
287 |
void MX_TIM6_Init(void) |
|
288 |
{ |
|
289 |
|
|
290 |
/* USER CODE BEGIN TIM6_Init 0 */ |
|
291 |
|
|
292 |
/* USER CODE END TIM6_Init 0 */ |
|
293 |
|
|
294 |
LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
|
295 |
|
|
296 |
/* Peripheral clock enable */ |
|
297 |
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6); |
|
298 |
|
|
299 |
/* TIM6 interrupt Init */ |
|
300 |
NVIC_SetPriority(TIM6_IRQn, 0); |
|
301 |
NVIC_EnableIRQ(TIM6_IRQn); |
|
302 |
|
|
303 |
/* USER CODE BEGIN TIM6_Init 1 */ |
|
304 |
|
|
305 |
/* USER CODE END TIM6_Init 1 */ |
|
306 |
TIM_InitStruct.Prescaler = 47; |
|
307 |
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
|
308 |
TIM_InitStruct.Autoreload = 999; |
|
309 |
LL_TIM_Init(TIM6, &TIM_InitStruct); |
|
310 |
LL_TIM_DisableARRPreload(TIM6); |
|
311 |
/* USER CODE BEGIN TIM6_Init 2 */ |
|
312 |
LL_TIM_EnableIT_UPDATE(TIM6); |
|
313 |
/* USER CODE END TIM6_Init 2 */ |
|
314 |
|
|
315 |
} |
9aed5d
|
316 |
|
Q |
317 |
/** |
|
318 |
* @brief TIM14 Initialization Function |
|
319 |
* @param None |
|
320 |
* @retval None |
|
321 |
*/ |
|
322 |
void MX_TIM14_Init(void) |
|
323 |
{ |
|
324 |
|
|
325 |
/* USER CODE BEGIN TIM14_Init 0 */ |
|
326 |
|
|
327 |
/* USER CODE END TIM14_Init 0 */ |
|
328 |
|
|
329 |
LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
|
330 |
|
|
331 |
/* Peripheral clock enable */ |
|
332 |
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM14); |
|
333 |
|
|
334 |
/* USER CODE BEGIN TIM14_Init 1 */ |
|
335 |
|
|
336 |
/* USER CODE END TIM14_Init 1 */ |
|
337 |
TIM_InitStruct.Prescaler = 2; |
|
338 |
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
|
339 |
TIM_InitStruct.Autoreload = 2400; |
|
340 |
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
|
341 |
LL_TIM_Init(TIM14, &TIM_InitStruct); |
|
342 |
LL_TIM_EnableARRPreload(TIM14); |
|
343 |
/* USER CODE BEGIN TIM14_Init 2 */ |
|
344 |
|
|
345 |
/* USER CODE END TIM14_Init 2 */ |
|
346 |
|
|
347 |
} |
|
348 |
|
|
349 |
/** |
|
350 |
* @brief TIM15 Initialization Function |
|
351 |
* @param None |
|
352 |
* @retval None |
|
353 |
*/ |
|
354 |
void MX_TIM15_Init(void) |
|
355 |
{ |
|
356 |
|
|
357 |
/* USER CODE BEGIN TIM15_Init 0 */ |
|
358 |
|
|
359 |
/* USER CODE END TIM15_Init 0 */ |
|
360 |
|
|
361 |
LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
|
362 |
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; |
|
363 |
LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0}; |
|
364 |
|
|
365 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
366 |
|
|
367 |
/* Peripheral clock enable */ |
|
368 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM15); |
|
369 |
|
|
370 |
/* USER CODE BEGIN TIM15_Init 1 */ |
|
371 |
|
|
372 |
/* USER CODE END TIM15_Init 1 */ |
|
373 |
TIM_InitStruct.Prescaler = 0; |
|
374 |
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
|
375 |
TIM_InitStruct.Autoreload = 1713; |
|
376 |
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
|
377 |
TIM_InitStruct.RepetitionCounter = 0; |
|
378 |
LL_TIM_Init(TIM15, &TIM_InitStruct); |
|
379 |
LL_TIM_EnableARRPreload(TIM15); |
|
380 |
LL_TIM_SetClockSource(TIM15, LL_TIM_CLOCKSOURCE_INTERNAL); |
|
381 |
|
|
382 |
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1; |
|
383 |
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
|
384 |
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
|
385 |
TIM_OC_InitStruct.CompareValue = 856; |
|
386 |
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
|
387 |
TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH; |
|
388 |
TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW; |
|
389 |
TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW; |
|
390 |
LL_TIM_OC_Init(TIM15, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); |
|
391 |
LL_TIM_OC_DisableFast(TIM15, LL_TIM_CHANNEL_CH1); |
|
392 |
|
|
393 |
LL_TIM_OC_EnablePreload(TIM15, LL_TIM_CHANNEL_CH2); |
|
394 |
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM2; |
|
395 |
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
|
396 |
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
|
397 |
TIM_OC_InitStruct.CompareValue = 100; |
|
398 |
LL_TIM_OC_Init(TIM15, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct); |
|
399 |
LL_TIM_OC_DisableFast(TIM15, LL_TIM_CHANNEL_CH2); |
|
400 |
LL_TIM_SetTriggerOutput(TIM15, LL_TIM_TRGO_OC2REF); |
|
401 |
LL_TIM_DisableMasterSlaveMode(TIM15); |
|
402 |
|
|
403 |
|
|
404 |
TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE; |
|
405 |
TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE; |
|
406 |
TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF; |
|
407 |
TIM_BDTRInitStruct.DeadTime = 5; |
|
408 |
TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE; |
|
409 |
TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH; |
|
410 |
TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE; |
|
411 |
LL_TIM_BDTR_Init(TIM15, &TIM_BDTRInitStruct); |
|
412 |
/* USER CODE BEGIN TIM15_Init 2 */ |
|
413 |
|
|
414 |
/* USER CODE END TIM15_Init 2 */ |
|
415 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
416 |
/**TIM15 GPIO Configuration |
|
417 |
PB14 ------> TIM15_CH1 |
|
418 |
PB15 ------> TIM15_CH1N |
|
419 |
*/ |
|
420 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_14; |
|
421 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
422 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; |
|
423 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
424 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
425 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
|
426 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
427 |
|
|
428 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_15; |
|
429 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
430 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW; |
|
431 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
432 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
433 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_3; |
|
434 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
435 |
|
|
436 |
} |
|
437 |
|
|
438 |
/** |
|
439 |
* @brief TIM16 Initialization Function |
|
440 |
* @param None |
|
441 |
* @retval None |
|
442 |
*/ |
|
443 |
void MX_TIM16_Init(void) |
|
444 |
{ |
|
445 |
|
|
446 |
/* USER CODE BEGIN TIM16_Init 0 */ |
|
447 |
|
|
448 |
/* USER CODE END TIM16_Init 0 */ |
|
449 |
|
|
450 |
LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
|
451 |
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0}; |
|
452 |
LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0}; |
|
453 |
|
|
454 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
455 |
|
|
456 |
/* Peripheral clock enable */ |
|
457 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_TIM16); |
|
458 |
/* TIM6 interrupt Init */ |
|
459 |
NVIC_SetPriority(TIM16_IRQn, 0); |
|
460 |
NVIC_EnableIRQ(TIM16_IRQn); |
|
461 |
|
|
462 |
/* USER CODE BEGIN TIM16_Init 1 */ |
|
463 |
|
|
464 |
/* USER CODE END TIM16_Init 1 */ |
|
465 |
TIM_InitStruct.Prescaler = 100; |
|
466 |
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
|
467 |
TIM_InitStruct.Autoreload = 1417; |
|
468 |
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; |
|
469 |
TIM_InitStruct.RepetitionCounter = 0; |
|
470 |
LL_TIM_Init(TIM16, &TIM_InitStruct); |
|
471 |
LL_TIM_DisableARRPreload(TIM16); |
|
472 |
|
|
473 |
LL_TIM_OC_EnablePreload(TIM16, LL_TIM_CHANNEL_CH1); |
|
474 |
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_TOGGLE; |
|
475 |
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE; |
|
476 |
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE; |
|
477 |
TIM_OC_InitStruct.CompareValue = 500; |
|
478 |
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH; |
|
479 |
TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH; |
|
480 |
TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW; |
|
481 |
TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW; |
|
482 |
LL_TIM_OC_Init(TIM16, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct); |
|
483 |
LL_TIM_OC_DisableFast(TIM16, LL_TIM_CHANNEL_CH1); |
|
484 |
TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE; |
|
485 |
TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE; |
|
486 |
TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF; |
|
487 |
TIM_BDTRInitStruct.DeadTime = 6; |
|
488 |
TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE; |
|
489 |
TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH; |
|
490 |
TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE; |
|
491 |
LL_TIM_BDTR_Init(TIM16, &TIM_BDTRInitStruct); |
|
492 |
|
|
493 |
/* USER CODE BEGIN TIM16_Init 2 */ |
|
494 |
|
|
495 |
/* USER CODE END TIM16_Init 2 */ |
|
496 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
|
497 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
498 |
/**TIM16 GPIO Configuration |
|
499 |
PA6 ------> TIM16_CH1 |
|
500 |
PB6 ------> TIM16_CH1N |
|
501 |
*/ |
|
502 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_6; |
|
503 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
504 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
505 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
506 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
507 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_5; |
|
508 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
509 |
|
|
510 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_6; |
|
511 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
512 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
513 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
514 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
515 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_2; |
|
516 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
517 |
|
|
518 |
LL_TIM_EnableIT_UPDATE(TIM16); |
|
519 |
} |
|
520 |
|
|
521 |
|
483170
|
522 |
/* ADC init function */ |
Q |
523 |
void MX_ADC_Init(void) |
|
524 |
{ |
|
525 |
|
|
526 |
LL_ADC_InitTypeDef ADC_InitStruct; |
|
527 |
LL_ADC_REG_InitTypeDef ADC_REG_InitStruct; |
|
528 |
|
|
529 |
/* Peripheral clock enable */ |
|
530 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_ADC1); |
|
531 |
|
|
532 |
/**Configure Regular Channel |
|
533 |
*/ |
|
534 |
LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_0|LL_ADC_CHANNEL_1); |
|
535 |
|
|
536 |
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR|LL_ADC_PATH_INTERNAL_VREFINT); |
|
537 |
|
|
538 |
/**Configure Regular Channel |
|
539 |
*/ |
|
540 |
LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_TEMPSENSOR|LL_ADC_CHANNEL_VREFINT); |
|
541 |
|
|
542 |
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR|LL_ADC_PATH_INTERNAL_VREFINT); |
|
543 |
|
|
544 |
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) |
|
545 |
*/ |
|
546 |
ADC_InitStruct.Clock = LL_ADC_CLOCK_ASYNC; |
|
547 |
ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B; |
|
548 |
ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; |
|
549 |
ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE; |
|
550 |
LL_ADC_Init(ADC1, &ADC_InitStruct); |
|
551 |
|
|
552 |
ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE; |
|
553 |
ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; |
|
554 |
ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_SINGLE; |
|
555 |
ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_LIMITED; |
|
556 |
ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED; |
|
557 |
LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct); |
|
558 |
|
|
559 |
LL_ADC_REG_SetSequencerScanDirection(ADC1, LL_ADC_REG_SEQ_SCAN_DIR_FORWARD); |
|
560 |
|
|
561 |
LL_ADC_SetSamplingTimeCommonChannels(ADC1, LL_ADC_SAMPLINGTIME_28CYCLES_5); |
|
562 |
|
|
563 |
LL_ADC_EnableIT_EOC(ADC1); |
|
564 |
|
|
565 |
LL_ADC_DisableIT_EOS(ADC1); |
|
566 |
|
|
567 |
LL_ADC_StartCalibration(ADC1); |
|
568 |
|
|
569 |
// LL_ADC_EnableInternalRegulator(ADC1); |
|
570 |
|
|
571 |
// ADC_TempSensorCmd(ENABLE);//????????? |
|
572 |
// ADC_VrefintCmd(ENABLE); //???????? |
|
573 |
|
|
574 |
|
|
575 |
//ADC_TempSensorCmd(ENABLE);// |
|
576 |
//ADC_ChannelConfig(); |
|
577 |
//ADC_VrefintCmd(ENABLE); // |
|
578 |
|
|
579 |
while( LL_ADC_IsCalibrationOnGoing(ADC1)); |
|
580 |
LL_ADC_Enable(ADC1); |
|
581 |
/* |
|
582 |
LL_ADC_REG_SetDMATransfer(ADC1,LL_ADC_REG_DMA_TRANSFER_UNLIMITED); |
|
583 |
LL_ADC_REG_StartConversion(ADC1); |
|
584 |
*/ |
|
585 |
} |
|
586 |
|
|
587 |
/* SPI1 init function */ |
|
588 |
void MX_SPI1_Init(void) |
|
589 |
{ |
|
590 |
|
|
591 |
LL_SPI_InitTypeDef SPI_InitStruct = {0}; |
|
592 |
|
|
593 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
594 |
|
|
595 |
/* Peripheral clock enable */ |
|
596 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SPI1); |
|
597 |
|
|
598 |
/**SPI1 GPIO Configuration |
|
599 |
PA5 ------> SPI1_SCK |
|
600 |
PA6 ------> SPI1_MISO |
|
601 |
PA7 ------> SPI1_MOSI |
|
602 |
*/ |
|
603 |
// GPIO_InitStruct.Pin = LL_GPIO_PIN_5; |
|
604 |
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
605 |
// GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
606 |
// GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
607 |
// GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
608 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
609 |
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
610 |
|
|
611 |
// GPIO_InitStruct.Pin = LL_GPIO_PIN_6; |
|
612 |
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
613 |
// GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
614 |
// GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
615 |
// GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
616 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
617 |
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
618 |
|
|
619 |
// GPIO_InitStruct.Pin = LL_GPIO_PIN_7; |
|
620 |
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
621 |
// GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
622 |
// GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
623 |
// GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
624 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
625 |
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
626 |
|
005755
|
627 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_15; |
Q |
628 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
629 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
630 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
631 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
9aed5d
|
632 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
005755
|
633 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
9aed5d
|
634 |
LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_15); |
Q |
635 |
|
483170
|
636 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
Q |
637 |
/**SPI1 GPIO Configuration |
|
638 |
PB3 ------> SPI1_SCK |
|
639 |
PB4 ------> SPI1_MISO |
|
640 |
PB5 ------> SPI1_MOSI |
|
641 |
*/ |
005755
|
642 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5; |
483170
|
643 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
Q |
644 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
645 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
005755
|
646 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
483170
|
647 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
Q |
648 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
9aed5d
|
649 |
|
Q |
650 |
/* |
|
651 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_5; |
|
652 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
653 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
654 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
655 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
656 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
657 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
658 |
|
|
659 |
LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_5); |
|
660 |
*/ |
|
661 |
|
005755
|
662 |
/* |
483170
|
663 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_4; |
Q |
664 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
665 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
666 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
667 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
668 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
669 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
670 |
|
|
671 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_5; |
|
672 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
673 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
674 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
675 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
676 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
677 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
005755
|
678 |
*/ |
483170
|
679 |
/* SPI1 interrupt Init */ |
Q |
680 |
NVIC_SetPriority(SPI1_IRQn, 0); |
|
681 |
// NVIC_EnableIRQ(SPI1_IRQn); |
|
682 |
/* USER CODE BEGIN SPI1_Init 1 */ |
|
683 |
|
9aed5d
|
684 |
#if (BOARD_TYPE == 13 || BOARD_TYPE == 9) |
483170
|
685 |
|
Q |
686 |
NVIC_EnableIRQ(SPI1_IRQn); |
|
687 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
|
688 |
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; |
|
689 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; |
|
690 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_HIGH; //LL_SPI_POLARITY_LOW; |
|
691 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE ; //LL_SPI_PHASE_1EDGE; |
|
692 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
|
693 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2; |
|
694 |
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; |
|
695 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
|
696 |
SPI_InitStruct.CRCPoly = 7; |
|
697 |
LL_SPI_Init(SPI1, &SPI_InitStruct); |
|
698 |
|
|
699 |
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); |
|
700 |
|
|
701 |
LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); |
|
702 |
// LL_SPI_EnableNSSPulseMgt(SPI1); |
|
703 |
|
|
704 |
#elif (BOARD_TYPE == 14) |
|
705 |
|
|
706 |
NVIC_EnableIRQ(SPI1_IRQn); |
|
707 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
|
708 |
SPI_InitStruct.Mode = LL_SPI_MODE_SLAVE; |
|
709 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; |
|
710 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; //LL_SPI_POLARITY_LOW; |
|
711 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE ; //LL_SPI_PHASE_1EDGE; |
|
712 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
|
713 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; |
|
714 |
SPI_InitStruct.BitOrder = LL_SPI_LSB_FIRST; |
|
715 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
|
716 |
SPI_InitStruct.CRCPoly = 7; |
|
717 |
LL_SPI_Init(SPI1, &SPI_InitStruct); |
|
718 |
|
|
719 |
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); |
|
720 |
LL_SPI_DisableNSSPulseMgt(SPI1); |
|
721 |
LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); |
|
722 |
// LL_SPI_EnableNSSPulseMgt(SPI1); |
9aed5d
|
723 |
LL_SPI_EnableIT_RXNE(SPI1); |
Q |
724 |
|
eaf5d5
|
725 |
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
Q |
726 |
|
|
727 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
|
728 |
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; |
|
729 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; |
|
730 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; |
|
731 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; |
|
732 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
1fb934
|
733 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; |
eaf5d5
|
734 |
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; |
Q |
735 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
|
736 |
SPI_InitStruct.CRCPoly = 7; |
|
737 |
LL_SPI_Init(SPI1, &SPI_InitStruct); |
|
738 |
|
|
739 |
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); |
|
740 |
|
|
741 |
LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); |
|
742 |
// LL_SPI_EnableNSSPulseMgt(SPI1); |
|
743 |
|
483170
|
744 |
#else |
Q |
745 |
|
|
746 |
/* USER CODE END SPI1_Init 1 */ |
|
747 |
|
|
748 |
/* SPI1 parameter configuration*/ |
|
749 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
|
750 |
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; |
|
751 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; |
|
752 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; |
|
753 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; |
|
754 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
|
755 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; |
|
756 |
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; |
|
757 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
|
758 |
SPI_InitStruct.CRCPoly = 7; |
|
759 |
LL_SPI_Init(SPI1, &SPI_InitStruct); |
|
760 |
|
|
761 |
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); |
|
762 |
|
|
763 |
LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); |
|
764 |
// LL_SPI_EnableNSSPulseMgt(SPI1); |
|
765 |
|
|
766 |
/* USER CODE BEGIN SPI1_Init 2 */ |
|
767 |
|
|
768 |
#endif |
|
769 |
|
|
770 |
LL_SPI_Enable(SPI1); |
|
771 |
/* USER CODE END SPI1_Init 2 */ |
|
772 |
} |
|
773 |
|
|
774 |
/* SPI2 init function */ |
|
775 |
void MX_SPI2_Init(void) |
|
776 |
{ |
|
777 |
|
|
778 |
LL_SPI_InitTypeDef SPI_InitStruct = {0}; |
|
779 |
|
|
780 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
781 |
|
|
782 |
/* Peripheral clock enable */ |
|
783 |
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); |
|
784 |
|
|
785 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
786 |
/**SPI2 GPIO Configuration |
|
787 |
PB13 ------> SPI2_SCK |
|
788 |
PB14 ------> SPI2_MISO |
|
789 |
PB15 ------> SPI2_MOSI |
|
790 |
*/ |
|
791 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_13; |
|
792 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
793 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
794 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
795 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
796 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
797 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
798 |
|
|
799 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_14; |
|
800 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
801 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
802 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
803 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
804 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
805 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
806 |
|
|
807 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_15; |
|
808 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
809 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
810 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
811 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
812 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
813 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
814 |
|
|
815 |
/* SPI2 interrupt Init */ |
|
816 |
//NVIC_SetPriority(SPI2_IRQn, 0); |
|
817 |
//NVIC_EnableIRQ(SPI2_IRQn); |
|
818 |
/* USER CODE BEGIN SPI2_Init 1 */ |
|
819 |
|
|
820 |
/* USER CODE END SPI2_Init 1 */ |
|
821 |
|
|
822 |
/* SPI2 parameter configuration*/ |
|
823 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
|
824 |
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; |
|
825 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; |
|
826 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; //LL_SPI_POLARITY_HIGH;//LL_SPI_POLARITY_LOW; |
|
827 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; //LL_SPI_PHASE_1EDGE; |
|
828 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
9aed5d
|
829 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; |
483170
|
830 |
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; |
Q |
831 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
|
832 |
SPI_InitStruct.CRCPoly = 7; |
|
833 |
LL_SPI_Init(SPI2, &SPI_InitStruct); |
|
834 |
LL_SPI_SetStandard(SPI2, LL_SPI_PROTOCOL_MOTOROLA); |
|
835 |
LL_SPI_EnableNSSPulseMgt(SPI2); |
|
836 |
/* USER CODE BEGIN SP21_Init 2 */ |
|
837 |
LL_SPI_Enable(SPI2); |
|
838 |
/* USER CODE END SPI2_Init 2 */ |
|
839 |
} |
|
840 |
|
005755
|
841 |
void Soft_I2C1_Init(void) |
Q |
842 |
{ |
|
843 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
844 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
845 |
/**I2C1 GPIO Configuration |
|
846 |
PB6 ------> I2C1_SCL |
|
847 |
PB7 ------> I2C1_SDA |
|
848 |
*/ |
|
849 |
LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_6|LL_GPIO_PIN_7); |
|
850 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_6 | LL_GPIO_PIN_7; |
|
851 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
852 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
853 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
|
854 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
855 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
856 |
LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_6 | LL_GPIO_PIN_7); |
|
857 |
|
|
858 |
} |
483170
|
859 |
|
Q |
860 |
/* USART1 init function */ |
|
861 |
void MX_USART1_UART_Init(void) |
|
862 |
{ |
|
863 |
|
|
864 |
LL_USART_InitTypeDef USART_InitStruct; |
|
865 |
|
|
866 |
LL_GPIO_InitTypeDef GPIO_InitStruct; |
|
867 |
|
|
868 |
/* Peripheral clock enable */ |
|
869 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_USART1); |
|
870 |
|
|
871 |
/**USART1 GPIO Configuration |
|
872 |
// PA1 ------> USART1_DE |
|
873 |
PA9 ------> USART1_TX |
|
874 |
PA10 ------> USART1_RX |
|
875 |
*/ |
|
876 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_10; |
|
877 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
878 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
879 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
880 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
881 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
|
882 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
883 |
|
|
884 |
/* USART1 DMA Init */ |
|
885 |
|
|
886 |
/* USART1_TX Init */ |
|
887 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_2, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); |
|
888 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PRIORITY_LOW); |
|
889 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MODE_NORMAL); |
|
890 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PERIPH_NOINCREMENT); |
|
891 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MEMORY_INCREMENT); |
|
892 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PDATAALIGN_BYTE); |
|
893 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MDATAALIGN_BYTE); |
|
894 |
|
|
895 |
/* USART1_RX Init */ |
|
896 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_3, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); |
|
897 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PRIORITY_LOW); |
|
898 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MODE_NORMAL); |
|
899 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PERIPH_NOINCREMENT); |
|
900 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MEMORY_INCREMENT); |
|
901 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PDATAALIGN_BYTE); |
|
902 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MDATAALIGN_BYTE); |
|
903 |
|
|
904 |
/* USART1 interrupt Init */ |
|
905 |
NVIC_SetPriority(USART1_IRQn, 0); |
|
906 |
NVIC_EnableIRQ(USART1_IRQn); |
|
907 |
|
|
908 |
USART_InitStruct.BaudRate = Uart1Baud; |
|
909 |
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; |
|
910 |
USART_InitStruct.StopBits = LL_USART_STOPBITS_1; |
|
911 |
USART_InitStruct.Parity = LL_USART_PARITY_NONE; |
|
912 |
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; |
|
913 |
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; |
|
914 |
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; |
|
915 |
LL_USART_Init(USART1, &USART_InitStruct); |
|
916 |
// LL_USART_EnableDEMode(USART1); |
|
917 |
// LL_USART_SetDESignalPolarity(USART1, LL_USART_DE_POLARITY_LOW); |
|
918 |
// LL_USART_SetDEAssertionTime(USART1, 1); |
|
919 |
// LL_USART_SetDEDeassertionTime(USART1, 1); |
|
920 |
// LL_USART_EnableOneBitSamp(USART1); |
7d8ba5
|
921 |
|
Q |
922 |
#if (USART1_AUTO_BAUDRATE == 1) |
483170
|
923 |
LL_USART_EnableAutoBaudRate(USART1); |
Q |
924 |
LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
7d8ba5
|
925 |
#endif |
Q |
926 |
|
|
927 |
LL_USART_DisableOverrunDetect(USART1); |
483170
|
928 |
LL_USART_ConfigAsyncMode(USART1); |
Q |
929 |
LL_USART_Enable(USART1); |
|
930 |
} |
|
931 |
|
|
932 |
|
|
933 |
/* USART2 init function */ |
|
934 |
void MX_USART2_UART_Init(void) |
|
935 |
{ |
|
936 |
|
|
937 |
LL_USART_InitTypeDef USART_InitStruct = {0}; |
|
938 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
939 |
|
|
940 |
/* Peripheral clock enable */ |
|
941 |
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2); |
|
942 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
|
943 |
|
|
944 |
/**USART2 GPIO Configuration |
|
945 |
PA1 ------> USART2_DE |
|
946 |
PA2 ------> USART2_TX |
|
947 |
PA3 ------> USART2_RX |
|
948 |
*/ |
|
949 |
|
|
950 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_3; |
|
951 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
952 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
953 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
|
954 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
955 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
|
956 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
957 |
|
|
958 |
#if (USART2_USE_HARDWARE_DE == 1) |
|
959 |
|
|
960 |
#else |
|
961 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_1; |
|
962 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
963 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
964 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
|
965 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
966 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
967 |
|
|
968 |
#endif |
|
969 |
|
|
970 |
/* USART2 DMA Init */ |
|
971 |
|
|
972 |
/* USART2_TX Init */ |
|
973 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_4, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); |
|
974 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PRIORITY_LOW); |
|
975 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MODE_NORMAL); |
|
976 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PERIPH_NOINCREMENT); |
|
977 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MEMORY_INCREMENT); |
|
978 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PDATAALIGN_BYTE); |
|
979 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MDATAALIGN_BYTE); |
|
980 |
|
|
981 |
/* USART2_RX Init */ |
|
982 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_5, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); |
|
983 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PRIORITY_LOW); |
|
984 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MODE_NORMAL); |
|
985 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PERIPH_NOINCREMENT); |
|
986 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MEMORY_INCREMENT); |
|
987 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PDATAALIGN_BYTE); |
|
988 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MDATAALIGN_BYTE); |
|
989 |
|
|
990 |
/* USART2 interrupt Init */ |
|
991 |
NVIC_SetPriority(USART2_IRQn, 0); |
|
992 |
NVIC_EnableIRQ(USART2_IRQn); |
|
993 |
|
|
994 |
NVIC_SetPriority(PendSV_IRQn, 255); |
|
995 |
NVIC_EnableIRQ(PendSV_IRQn); |
|
996 |
// NVIC_SetPendingIRQ(PendSV_IRQn); |
|
997 |
|
|
998 |
USART_InitStruct.BaudRate = Uart2Baud; |
|
999 |
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; |
|
1000 |
USART_InitStruct.StopBits = LL_USART_STOPBITS_1; |
|
1001 |
USART_InitStruct.Parity = LL_USART_PARITY_NONE; |
|
1002 |
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; |
|
1003 |
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; |
|
1004 |
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_8; |
|
1005 |
LL_USART_Init(USART2, &USART_InitStruct); |
|
1006 |
|
|
1007 |
#if (USART2_USE_HARDWARE_DE == 1) |
|
1008 |
|
|
1009 |
LL_USART_EnableDEMode(USART2); |
|
1010 |
LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_LOW); |
|
1011 |
// LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_HIGH); |
842bb6
|
1012 |
LL_USART_SetDEAssertionTime(USART2, 15); |
Q |
1013 |
LL_USART_SetDEDeassertionTime(USART2, 15); |
483170
|
1014 |
#else |
Q |
1015 |
|
|
1016 |
#endif |
|
1017 |
|
|
1018 |
// LL_USART_EnableOneBitSamp(USART2); |
|
1019 |
// LL_USART_EnableAutoBaudRate(USART2); |
|
1020 |
// LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
1021 |
LL_USART_DisableOverrunDetect(USART2); |
|
1022 |
LL_USART_ConfigAsyncMode(USART2); |
|
1023 |
LL_USART_Enable(USART2); |
|
1024 |
} |
|
1025 |
|
|
1026 |
/** |
|
1027 |
* Enable DMA controller clock |
|
1028 |
*/ |
|
1029 |
void MX_DMA_Init(void) |
|
1030 |
{ |
|
1031 |
/* Init with LL driver */ |
|
1032 |
/* DMA controller clock enable */ |
|
1033 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); |
|
1034 |
|
|
1035 |
/* DMA interrupt init */ |
|
1036 |
/* DMA1_Channel2_3_IRQn interrupt configuration */ |
|
1037 |
NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0); |
|
1038 |
NVIC_EnableIRQ(DMA1_Channel2_3_IRQn); |
|
1039 |
NVIC_SetPriority(DMA1_Channel4_5_IRQn, 0); |
|
1040 |
NVIC_EnableIRQ(DMA1_Channel4_5_IRQn); |
|
1041 |
} |
|
1042 |
|
|
1043 |
/** Configure pins as |
|
1044 |
* Analog |
|
1045 |
* Input |
|
1046 |
* Output |
|
1047 |
* EVENT_OUT |
|
1048 |
* EXTI |
|
1049 |
*/ |
|
1050 |
void MX_GPIO_Init(void) |
|
1051 |
{ |
|
1052 |
|
|
1053 |
LL_GPIO_InitTypeDef GPIO_InitStruct; |
|
1054 |
|
|
1055 |
/* GPIO Ports Clock Enable */ |
|
1056 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
|
1057 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
1058 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOC); |
|
1059 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOF); |
|
1060 |
/**/ |
|
1061 |
|
|
1062 |
|
|
1063 |
/**/ |
|
1064 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_6 |LL_GPIO_PIN_7; |
|
1065 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
1066 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1067 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
1068 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
1069 |
|
|
1070 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_7 ; |
|
1071 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
1072 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1073 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
1074 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
1075 |
|
|
1076 |
|
9aed5d
|
1077 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_8; //|LL_GPIO_PIN_11; |
483170
|
1078 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
Q |
1079 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1080 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
1081 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
1082 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
1083 |
LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_8); |
|
1084 |
|
|
1085 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_10; |
|
1086 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
1087 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1088 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
1089 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
1090 |
|
|
1091 |
|
|
1092 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10; |
|
1093 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
1094 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1095 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
1096 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
1097 |
|
1fb934
|
1098 |
#if (BOARD_TYPE==2) |
Q |
1099 |
|
483170
|
1100 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
Q |
1101 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
|
1102 |
|
1fb934
|
1103 |
|
005755
|
1104 |
#elif (BOARD_TYPE==9 || BOARD_TYPE==10) |
Q |
1105 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| |
|
1106 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
|
1107 |
|
|
1108 |
#elif (BOARD_TYPE==15 || BOARD_TYPE == 16 ) |
1fb934
|
1109 |
|
483170
|
1110 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
Q |
1111 |
LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| |
|
1112 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
1fb934
|
1113 |
#elif ( BOARD_TYPE == 11 ) |
Q |
1114 |
|
483170
|
1115 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
Q |
1116 |
LL_GPIO_PIN_2|LL_GPIO_PIN_10|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
1fb934
|
1117 |
#elif (BOARD_TYPE == 14) |
Q |
1118 |
|
483170
|
1119 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
Q |
1120 |
LL_GPIO_PIN_10|LL_GPIO_PIN_11|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_14|LL_GPIO_PIN_15; |
1fb934
|
1121 |
#else |
Q |
1122 |
|
483170
|
1123 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
Q |
1124 |
LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| |
|
1125 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
1fb934
|
1126 |
|
Q |
1127 |
#endif |
|
1128 |
|
|
1129 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
483170
|
1130 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
Q |
1131 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
1132 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
1133 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
1134 |
|
|
1135 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_13|LL_GPIO_PIN_14|LL_GPIO_PIN_15; |
|
1136 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
1137 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_LOW; |
|
1138 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
1139 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
1140 |
LL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
|
1141 |
|
|
1142 |
// RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO,ENABLE ); |
|
1143 |
// PWR_BackupAccessCmd( ENABLE );/* ????RTC??????*/ |
|
1144 |
// RCC_LSEConfig( RCC_LSE_OFF ); /* ????????,PC14+PC15??????IO*/ |
|
1145 |
// BKP_TamperPinCmd(DISABLE); /* ????????,PC13??????IO*/ |
|
1146 |
|
|
1147 |
#if (BORAD_TYPE == 13) |
|
1148 |
|
|
1149 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_15 ; |
|
1150 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
1151 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1152 |
GPIO_InitStruct.Pull = LL_GPIO_OUTPUT_PUSHPULL; |
|
1153 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
1154 |
|
|
1155 |
#elif (BOARD_TYPE == 14) |
|
1156 |
|
|
1157 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7; |
|
1158 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
1159 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1160 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
1161 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
1162 |
LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_8); |
|
1163 |
|
|
1164 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_9 ; //RST_PIN in |
|
1165 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
1166 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1167 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
1168 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
1169 |
|
|
1170 |
GPIO_InitStruct.Pin = SYN_PIN ; //SYN_PIN Pin in |
|
1171 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
1172 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1173 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
1174 |
LL_GPIO_Init(SYN_PORT, &GPIO_InitStruct); |
|
1175 |
|
|
1176 |
GPIO_InitStruct.Pin = ACK_PIN ; //ACK_PIN Pin out |
|
1177 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
1178 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1179 |
GPIO_InitStruct.Pull = LL_GPIO_OUTPUT_PUSHPULL; |
|
1180 |
LL_GPIO_Init(ACK_PORT, &GPIO_InitStruct); |
|
1181 |
|
|
1182 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_7 ; //485DE Pin out |
|
1183 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
1184 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1185 |
GPIO_InitStruct.Pull = LL_GPIO_OUTPUT_PUSHPULL; |
|
1186 |
LL_GPIO_Init(GPIOF, &GPIO_InitStruct); |
|
1187 |
|
|
1188 |
GPIO_InitStruct.Pin = OE_PIN ; // OE Pin in |
|
1189 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
1190 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1191 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
1192 |
LL_GPIO_Init(OE_PORT, &GPIO_InitStruct); |
|
1193 |
|
|
1194 |
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
1195 |
|
|
1196 |
// Radio Pins |
|
1197 |
// busy pin |
|
1198 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_7; |
|
1199 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
1200 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1201 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
1202 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
1203 |
|
|
1204 |
// Dio 1 pin |
|
1205 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_12; |
|
1206 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
1207 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1208 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
1209 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
1210 |
|
|
1211 |
|
|
1212 |
//Sel pin |
|
1213 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_15; |
|
1214 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
1215 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1216 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
1217 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
1218 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
1219 |
|
|
1220 |
|
|
1221 |
//RST pin |
|
1222 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_6; |
|
1223 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
1224 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
1225 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
1226 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
1227 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
1228 |
|
|
1229 |
#endif |
|
1230 |
|
|
1231 |
} |
9aed5d
|
1232 |
|
Q |
1233 |
|
|
1234 |
/* |
|
1235 |
if ((nCurTick &0xff) ==0) |
|
1236 |
{ |
|
1237 |
if (freqdir) { freq+=1+freq/10;if (freq>=1500) {freq=1500;freqdir=0;}} |
|
1238 |
else {freq-=1+freq/10;if (freq<=10) {freq=10;freqdir=1;} } |
|
1239 |
} |
|
1240 |
*/ |
|
1241 |
|
|
1242 |
/* |
|
1243 |
static int outputsum=0; |
|
1244 |
static int freq=10; |
|
1245 |
static int freqdir=1; |
|
1246 |
static int phase=0; |
|
1247 |
static int somb=0; |
|
1248 |
static int len=0; |
|
1249 |
static int curbb=0; |
|
1250 |
|
|
1251 |
if ((nCurTick &0x3ff) ==1) |
|
1252 |
{ |
|
1253 |
curbb++; |
|
1254 |
if (curbb+1==len) |
|
1255 |
{ |
|
1256 |
// freq=0; |
|
1257 |
}else if (curbb>=len) |
|
1258 |
{ |
|
1259 |
somb=musictab1[cur_musicpos*2]; |
|
1260 |
len=musictab1[cur_musicpos*2+1]; |
|
1261 |
freq=freqtab[somb]; |
|
1262 |
curbb=0;cur_musicpos++; if (cur_musicpos >= Totalmusiccount) {cur_musicpos=0;} |
|
1263 |
} |
|
1264 |
} |
|
1265 |
if ((nCurTick &0x3ff) ==0x1ff) |
|
1266 |
{ |
|
1267 |
if (curbb+1==len) |
|
1268 |
{ |
|
1269 |
freq=0; |
|
1270 |
} |
|
1271 |
} |
|
1272 |
phase+=freq; |
|
1273 |
if (phase>=5000) {phase-=5000;} |
|
1274 |
|
|
1275 |
|
|
1276 |
if (outtype==1) |
|
1277 |
{ |
|
1278 |
outputsum+=freq; |
|
1279 |
if (outputsum>=5000) |
|
1280 |
{ |
|
1281 |
//LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
|
1282 |
LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
|
1283 |
outputsum-=5000; |
|
1284 |
} |
|
1285 |
else |
|
1286 |
{ |
|
1287 |
//LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
|
1288 |
} |
|
1289 |
}else if (outtype==2) |
|
1290 |
{ |
|
1291 |
const int volume = 2500; |
|
1292 |
int amp; |
|
1293 |
if (phase<1250) |
|
1294 |
{ |
|
1295 |
amp=2500+sintab[(phase -0)*256/1250]*volume/256; |
|
1296 |
|
|
1297 |
}else if (phase <2500) |
|
1298 |
{ |
|
1299 |
amp=2500+sintab[(2500-1-phase)*256/1250]*volume/256; |
|
1300 |
}else if (phase <3750) |
|
1301 |
{ |
|
1302 |
amp=2500-sintab[(phase-2500)*256/1250]*volume/256; |
|
1303 |
}else |
|
1304 |
{ |
|
1305 |
amp=2500-sintab[(5000-1-phase)*256/1250]*volume/256; |
|
1306 |
} |
|
1307 |
outputsum+=amp; |
|
1308 |
if (outputsum>=5000) |
|
1309 |
{ |
|
1310 |
LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
|
1311 |
//LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
|
1312 |
outputsum-=5000; |
|
1313 |
} |
|
1314 |
else |
|
1315 |
{ |
|
1316 |
LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
|
1317 |
} |
|
1318 |
} |
|
1319 |
*/ |