提交 | 用户 | age
|
8b51c7
|
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) |
|
16 |
#include "fp0.h" |
|
17 |
#endif |
|
18 |
|
|
19 |
/* |
|
20 |
if ((nCurTick &0xff) ==0) |
|
21 |
{ |
|
22 |
if (freqdir) { freq+=1+freq/10;if (freq>=1500) {freq=1500;freqdir=0;}} |
|
23 |
else {freq-=1+freq/10;if (freq<=10) {freq=10;freqdir=1;} } |
|
24 |
} |
|
25 |
*/ |
|
26 |
|
|
27 |
/* |
|
28 |
static int outputsum=0; |
|
29 |
static int freq=10; |
|
30 |
static int freqdir=1; |
|
31 |
static int phase=0; |
|
32 |
static int somb=0; |
|
33 |
static int len=0; |
|
34 |
static int curbb=0; |
|
35 |
|
|
36 |
if ((nCurTick &0x3ff) ==1) |
|
37 |
{ |
|
38 |
curbb++; |
|
39 |
if (curbb+1==len) |
|
40 |
{ |
|
41 |
// freq=0; |
|
42 |
}else if (curbb>=len) |
|
43 |
{ |
|
44 |
somb=musictab1[cur_musicpos*2]; |
|
45 |
len=musictab1[cur_musicpos*2+1]; |
|
46 |
freq=freqtab[somb]; |
|
47 |
curbb=0;cur_musicpos++; if (cur_musicpos >= Totalmusiccount) {cur_musicpos=0;} |
|
48 |
} |
|
49 |
} |
|
50 |
if ((nCurTick &0x3ff) ==0x1ff) |
|
51 |
{ |
|
52 |
if (curbb+1==len) |
|
53 |
{ |
|
54 |
freq=0; |
|
55 |
} |
|
56 |
} |
|
57 |
phase+=freq; |
|
58 |
if (phase>=5000) {phase-=5000;} |
|
59 |
|
|
60 |
|
|
61 |
if (outtype==1) |
|
62 |
{ |
|
63 |
outputsum+=freq; |
|
64 |
if (outputsum>=5000) |
|
65 |
{ |
|
66 |
//LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
|
67 |
LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
|
68 |
outputsum-=5000; |
|
69 |
} |
|
70 |
else |
|
71 |
{ |
|
72 |
//LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
|
73 |
} |
|
74 |
}else if (outtype==2) |
|
75 |
{ |
|
76 |
const int volume = 2500; |
|
77 |
int amp; |
|
78 |
if (phase<1250) |
|
79 |
{ |
|
80 |
amp=2500+sintab[(phase -0)*256/1250]*volume/256; |
|
81 |
|
|
82 |
}else if (phase <2500) |
|
83 |
{ |
|
84 |
amp=2500+sintab[(2500-1-phase)*256/1250]*volume/256; |
|
85 |
}else if (phase <3750) |
|
86 |
{ |
|
87 |
amp=2500-sintab[(phase-2500)*256/1250]*volume/256; |
|
88 |
}else |
|
89 |
{ |
|
90 |
amp=2500-sintab[(5000-1-phase)*256/1250]*volume/256; |
|
91 |
} |
|
92 |
outputsum+=amp; |
|
93 |
if (outputsum>=5000) |
|
94 |
{ |
|
95 |
LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3); |
|
96 |
//LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3); |
|
97 |
outputsum-=5000; |
|
98 |
} |
|
99 |
else |
|
100 |
{ |
|
101 |
LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3); |
|
102 |
} |
|
103 |
} |
|
104 |
*/ |
|
105 |
|
|
106 |
|
|
107 |
/** |
|
108 |
* @brief System Clock Configuration |
|
109 |
* @retval None |
|
110 |
*/ |
|
111 |
|
|
112 |
void SystemClock_Config(void) |
|
113 |
{ |
|
114 |
RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
|
115 |
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
|
116 |
|
|
117 |
/** Initializes the CPU, AHB and APB busses clocks |
|
118 |
*/ |
|
119 |
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
|
120 |
RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
|
121 |
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
|
122 |
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
|
123 |
// RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
|
124 |
|
|
125 |
#if (XLAT_FREQ == 12) |
|
126 |
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV3; |
|
127 |
#else |
|
128 |
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2; |
|
129 |
#endif |
|
130 |
|
|
131 |
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; |
|
132 |
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
|
133 |
{ |
|
134 |
Error_Handler(); |
|
135 |
} |
|
136 |
/** Initializes the CPU, AHB and APB busses clocks |
|
137 |
*/ |
|
138 |
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
|
139 |
|RCC_CLOCKTYPE_PCLK1; |
|
140 |
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
|
141 |
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
|
142 |
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
|
143 |
|
|
144 |
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
|
145 |
{ |
|
146 |
Error_Handler(); |
|
147 |
} |
|
148 |
|
|
149 |
//RCC_OscInitTypeDef RCC_OscInitStruct; |
|
150 |
//RCC_ClkInitTypeDef RCC_ClkInitStruct; |
|
151 |
RCC_PeriphCLKInitTypeDef PeriphClkInit; |
|
152 |
|
|
153 |
/**Initializes the CPU, AHB and APB busses clocks |
|
154 |
*/ |
|
155 |
|
|
156 |
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; |
|
157 |
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK; |
|
158 |
|
|
159 |
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) |
|
160 |
{ |
|
161 |
_Error_Handler(__FILE__, __LINE__); |
|
162 |
} |
|
163 |
|
|
164 |
/**Configure the Systick interrupt time |
|
165 |
*/ |
|
166 |
// HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/10000); |
|
167 |
HAL_SYSTICK_Config(48000000/10000); |
|
168 |
|
|
169 |
/**Configure the Systick |
|
170 |
*/ |
|
171 |
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
|
172 |
|
|
173 |
/* SysTick_IRQn interrupt configuration */ |
|
174 |
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
|
175 |
} |
|
176 |
|
|
177 |
void MX_IWDG_Init(void) |
|
178 |
{ |
|
179 |
|
|
180 |
/* USER CODE BEGIN IWDG_Init 0 */ |
|
181 |
|
|
182 |
/* USER CODE END IWDG_Init 0 */ |
|
183 |
|
|
184 |
/* USER CODE BEGIN IWDG_Init 1 */ |
|
185 |
|
|
186 |
/* USER CODE END IWDG_Init 1 */ |
|
187 |
LL_IWDG_Enable(IWDG); |
|
188 |
LL_IWDG_EnableWriteAccess(IWDG); |
|
189 |
LL_IWDG_SetPrescaler(IWDG, LL_IWDG_PRESCALER_64); |
|
190 |
LL_IWDG_SetReloadCounter(IWDG, 4095); |
|
191 |
while (LL_IWDG_IsReady(IWDG) != 1) |
|
192 |
{ |
|
193 |
} |
|
194 |
|
|
195 |
LL_IWDG_SetWindow(IWDG, 4095); |
|
196 |
LL_IWDG_ReloadCounter(IWDG); |
|
197 |
/* USER CODE BEGIN IWDG_Init 2 */ |
|
198 |
|
|
199 |
/* USER CODE END IWDG_Init 2 */ |
|
200 |
|
|
201 |
} |
|
202 |
/** |
|
203 |
* @brief TIM6 Initialization Function |
|
204 |
* @param None |
|
205 |
* @retval None |
|
206 |
*/ |
|
207 |
void MX_TIM6_Init(void) |
|
208 |
{ |
|
209 |
|
|
210 |
/* USER CODE BEGIN TIM6_Init 0 */ |
|
211 |
|
|
212 |
/* USER CODE END TIM6_Init 0 */ |
|
213 |
|
|
214 |
LL_TIM_InitTypeDef TIM_InitStruct = {0}; |
|
215 |
|
|
216 |
/* Peripheral clock enable */ |
|
217 |
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6); |
|
218 |
|
|
219 |
/* TIM6 interrupt Init */ |
|
220 |
NVIC_SetPriority(TIM6_IRQn, 0); |
|
221 |
NVIC_EnableIRQ(TIM6_IRQn); |
|
222 |
|
|
223 |
/* USER CODE BEGIN TIM6_Init 1 */ |
|
224 |
|
|
225 |
/* USER CODE END TIM6_Init 1 */ |
|
226 |
TIM_InitStruct.Prescaler = 47; |
|
227 |
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP; |
|
228 |
TIM_InitStruct.Autoreload = 999; |
|
229 |
LL_TIM_Init(TIM6, &TIM_InitStruct); |
|
230 |
LL_TIM_DisableARRPreload(TIM6); |
|
231 |
/* USER CODE BEGIN TIM6_Init 2 */ |
|
232 |
LL_TIM_EnableIT_UPDATE(TIM6); |
|
233 |
/* USER CODE END TIM6_Init 2 */ |
|
234 |
|
|
235 |
} |
|
236 |
/* ADC init function */ |
|
237 |
void MX_ADC_Init(void) |
|
238 |
{ |
|
239 |
|
|
240 |
LL_ADC_InitTypeDef ADC_InitStruct; |
|
241 |
LL_ADC_REG_InitTypeDef ADC_REG_InitStruct; |
|
242 |
|
|
243 |
/* Peripheral clock enable */ |
|
244 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_ADC1); |
|
245 |
|
|
246 |
/**Configure Regular Channel |
|
247 |
*/ |
|
248 |
LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_0|LL_ADC_CHANNEL_1); |
|
249 |
|
|
250 |
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR|LL_ADC_PATH_INTERNAL_VREFINT); |
|
251 |
|
|
252 |
/**Configure Regular Channel |
|
253 |
*/ |
|
254 |
LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_TEMPSENSOR|LL_ADC_CHANNEL_VREFINT); |
|
255 |
|
|
256 |
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR|LL_ADC_PATH_INTERNAL_VREFINT); |
|
257 |
|
|
258 |
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) |
|
259 |
*/ |
|
260 |
ADC_InitStruct.Clock = LL_ADC_CLOCK_ASYNC; |
|
261 |
ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B; |
|
262 |
ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT; |
|
263 |
ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE; |
|
264 |
LL_ADC_Init(ADC1, &ADC_InitStruct); |
|
265 |
|
|
266 |
ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE; |
|
267 |
ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; |
|
268 |
ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_SINGLE; |
|
269 |
ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_LIMITED; |
|
270 |
ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED; |
|
271 |
LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct); |
|
272 |
|
|
273 |
LL_ADC_REG_SetSequencerScanDirection(ADC1, LL_ADC_REG_SEQ_SCAN_DIR_FORWARD); |
|
274 |
|
|
275 |
LL_ADC_SetSamplingTimeCommonChannels(ADC1, LL_ADC_SAMPLINGTIME_28CYCLES_5); |
|
276 |
|
|
277 |
LL_ADC_EnableIT_EOC(ADC1); |
|
278 |
|
|
279 |
LL_ADC_DisableIT_EOS(ADC1); |
|
280 |
|
|
281 |
LL_ADC_StartCalibration(ADC1); |
|
282 |
|
|
283 |
// LL_ADC_EnableInternalRegulator(ADC1); |
|
284 |
|
|
285 |
// ADC_TempSensorCmd(ENABLE);//????????? |
|
286 |
// ADC_VrefintCmd(ENABLE); //???????? |
|
287 |
|
|
288 |
|
|
289 |
//ADC_TempSensorCmd(ENABLE);// |
|
290 |
//ADC_ChannelConfig(); |
|
291 |
//ADC_VrefintCmd(ENABLE); // |
|
292 |
|
|
293 |
while( LL_ADC_IsCalibrationOnGoing(ADC1)); |
|
294 |
LL_ADC_Enable(ADC1); |
|
295 |
/* |
|
296 |
LL_ADC_REG_SetDMATransfer(ADC1,LL_ADC_REG_DMA_TRANSFER_UNLIMITED); |
|
297 |
LL_ADC_REG_StartConversion(ADC1); |
|
298 |
*/ |
|
299 |
} |
|
300 |
|
|
301 |
/* SPI1 init function */ |
|
302 |
void MX_SPI1_Init(void) |
|
303 |
{ |
|
304 |
|
|
305 |
LL_SPI_InitTypeDef SPI_InitStruct = {0}; |
|
306 |
|
|
307 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
308 |
|
|
309 |
/* Peripheral clock enable */ |
|
310 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SPI1); |
|
311 |
|
|
312 |
/**SPI1 GPIO Configuration |
|
313 |
PA5 ------> SPI1_SCK |
|
314 |
PA6 ------> SPI1_MISO |
|
315 |
PA7 ------> SPI1_MOSI |
|
316 |
*/ |
|
317 |
// GPIO_InitStruct.Pin = LL_GPIO_PIN_5; |
|
318 |
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
319 |
// GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
320 |
// GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
321 |
// GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
322 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
323 |
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
324 |
|
|
325 |
// GPIO_InitStruct.Pin = LL_GPIO_PIN_6; |
|
326 |
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
327 |
// GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
328 |
// GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
329 |
// GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
330 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
331 |
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
332 |
|
|
333 |
// GPIO_InitStruct.Pin = LL_GPIO_PIN_7; |
|
334 |
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
335 |
// GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
336 |
// GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
337 |
// GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
338 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
339 |
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
340 |
|
|
341 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
342 |
/**SPI1 GPIO Configuration |
|
343 |
PB3 ------> SPI1_SCK |
|
344 |
PB4 ------> SPI1_MISO |
|
345 |
PB5 ------> SPI1_MOSI |
|
346 |
*/ |
|
347 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3; |
|
348 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
349 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
350 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
351 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
352 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
353 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
354 |
|
|
355 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_4; |
|
356 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
357 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
358 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
359 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
360 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
361 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
362 |
|
|
363 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_5; |
|
364 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
365 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
366 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
367 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
368 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
369 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
370 |
|
|
371 |
/* SPI1 interrupt Init */ |
|
372 |
NVIC_SetPriority(SPI1_IRQn, 0); |
|
373 |
// NVIC_EnableIRQ(SPI1_IRQn); |
|
374 |
/* USER CODE BEGIN SPI1_Init 1 */ |
|
375 |
|
|
376 |
#if (BOARD_TYPE == 13) |
|
377 |
|
|
378 |
NVIC_EnableIRQ(SPI1_IRQn); |
|
379 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
|
380 |
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; |
|
381 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; |
|
382 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_HIGH; //LL_SPI_POLARITY_LOW; |
|
383 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE ; //LL_SPI_PHASE_1EDGE; |
|
384 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
|
385 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2; |
|
386 |
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; |
|
387 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
|
388 |
SPI_InitStruct.CRCPoly = 7; |
|
389 |
LL_SPI_Init(SPI1, &SPI_InitStruct); |
|
390 |
|
|
391 |
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); |
|
392 |
|
|
393 |
LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); |
|
394 |
// LL_SPI_EnableNSSPulseMgt(SPI1); |
|
395 |
|
|
396 |
#elif (BOARD_TYPE == 14) |
|
397 |
|
|
398 |
NVIC_EnableIRQ(SPI1_IRQn); |
|
399 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
|
400 |
SPI_InitStruct.Mode = LL_SPI_MODE_SLAVE; |
|
401 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; |
|
402 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; //LL_SPI_POLARITY_LOW; |
|
403 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE ; //LL_SPI_PHASE_1EDGE; |
|
404 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
|
405 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; |
|
406 |
SPI_InitStruct.BitOrder = LL_SPI_LSB_FIRST; |
|
407 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
|
408 |
SPI_InitStruct.CRCPoly = 7; |
|
409 |
LL_SPI_Init(SPI1, &SPI_InitStruct); |
|
410 |
|
|
411 |
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); |
|
412 |
LL_SPI_DisableNSSPulseMgt(SPI1); |
|
413 |
LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); |
|
414 |
// LL_SPI_EnableNSSPulseMgt(SPI1); |
|
415 |
|
|
416 |
#elif (BOARD_TYPE == 15 || BOARD_TYPE == 16) |
|
417 |
|
|
418 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
|
419 |
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; |
|
420 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; |
|
421 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; |
|
422 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; |
|
423 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
|
424 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; |
|
425 |
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; |
|
426 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
|
427 |
SPI_InitStruct.CRCPoly = 7; |
|
428 |
LL_SPI_Init(SPI1, &SPI_InitStruct); |
|
429 |
|
|
430 |
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); |
|
431 |
|
|
432 |
LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); |
|
433 |
// LL_SPI_EnableNSSPulseMgt(SPI1); |
|
434 |
|
|
435 |
#else |
|
436 |
|
|
437 |
/* USER CODE END SPI1_Init 1 */ |
|
438 |
|
|
439 |
/* SPI1 parameter configuration*/ |
|
440 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
|
441 |
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; |
|
442 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; |
|
443 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; |
|
444 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; |
|
445 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
|
446 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; |
|
447 |
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; |
|
448 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
|
449 |
SPI_InitStruct.CRCPoly = 7; |
|
450 |
LL_SPI_Init(SPI1, &SPI_InitStruct); |
|
451 |
|
|
452 |
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA); |
|
453 |
|
|
454 |
LL_SPI_SetRxFIFOThreshold(SPI1,LL_SPI_RX_FIFO_TH_QUARTER); |
|
455 |
// LL_SPI_EnableNSSPulseMgt(SPI1); |
|
456 |
|
|
457 |
/* USER CODE BEGIN SPI1_Init 2 */ |
|
458 |
|
|
459 |
#endif |
|
460 |
|
|
461 |
LL_SPI_Enable(SPI1); |
|
462 |
/* USER CODE END SPI1_Init 2 */ |
|
463 |
} |
|
464 |
|
|
465 |
/* SPI2 init function */ |
|
466 |
void MX_SPI2_Init(void) |
|
467 |
{ |
|
468 |
|
|
469 |
LL_SPI_InitTypeDef SPI_InitStruct = {0}; |
|
470 |
|
|
471 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
472 |
|
|
473 |
/* Peripheral clock enable */ |
|
474 |
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); |
|
475 |
|
|
476 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
477 |
/**SPI2 GPIO Configuration |
|
478 |
PB13 ------> SPI2_SCK |
|
479 |
PB14 ------> SPI2_MISO |
|
480 |
PB15 ------> SPI2_MOSI |
|
481 |
*/ |
|
482 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_13; |
|
483 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
484 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
485 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
486 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
487 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
488 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
489 |
|
|
490 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_14; |
|
491 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
492 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
493 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
494 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
495 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
496 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
497 |
|
|
498 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_15; |
|
499 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
500 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
501 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
502 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
503 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0; |
|
504 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
505 |
|
|
506 |
/* SPI2 interrupt Init */ |
|
507 |
//NVIC_SetPriority(SPI2_IRQn, 0); |
|
508 |
//NVIC_EnableIRQ(SPI2_IRQn); |
|
509 |
/* USER CODE BEGIN SPI2_Init 1 */ |
|
510 |
|
|
511 |
/* USER CODE END SPI2_Init 1 */ |
|
512 |
|
|
513 |
/* SPI2 parameter configuration*/ |
|
514 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX; |
|
515 |
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER; |
|
516 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT; |
|
517 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; //LL_SPI_POLARITY_HIGH;//LL_SPI_POLARITY_LOW; |
|
518 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; //LL_SPI_PHASE_1EDGE; |
|
519 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT; |
|
520 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8; |
|
521 |
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST; |
|
522 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; |
|
523 |
SPI_InitStruct.CRCPoly = 7; |
|
524 |
LL_SPI_Init(SPI2, &SPI_InitStruct); |
|
525 |
LL_SPI_SetStandard(SPI2, LL_SPI_PROTOCOL_MOTOROLA); |
|
526 |
LL_SPI_EnableNSSPulseMgt(SPI2); |
|
527 |
/* USER CODE BEGIN SP21_Init 2 */ |
|
528 |
LL_SPI_Enable(SPI2); |
|
529 |
/* USER CODE END SPI2_Init 2 */ |
|
530 |
} |
|
531 |
|
|
532 |
|
|
533 |
/* USART1 init function */ |
|
534 |
void MX_USART1_UART_Init(void) |
|
535 |
{ |
|
536 |
|
|
537 |
LL_USART_InitTypeDef USART_InitStruct; |
|
538 |
|
|
539 |
LL_GPIO_InitTypeDef GPIO_InitStruct; |
|
540 |
|
|
541 |
/* Peripheral clock enable */ |
|
542 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_USART1); |
|
543 |
|
|
544 |
/**USART1 GPIO Configuration |
|
545 |
// PA1 ------> USART1_DE |
|
546 |
PA9 ------> USART1_TX |
|
547 |
PA10 ------> USART1_RX |
|
548 |
*/ |
|
549 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_10; |
|
550 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
551 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
552 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
553 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
554 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
|
555 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
556 |
|
|
557 |
/* USART1 DMA Init */ |
|
558 |
|
|
559 |
/* USART1_TX Init */ |
|
560 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_2, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); |
|
561 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PRIORITY_LOW); |
|
562 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MODE_NORMAL); |
|
563 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PERIPH_NOINCREMENT); |
|
564 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MEMORY_INCREMENT); |
|
565 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PDATAALIGN_BYTE); |
|
566 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MDATAALIGN_BYTE); |
|
567 |
|
|
568 |
/* USART1_RX Init */ |
|
569 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_3, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); |
|
570 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PRIORITY_LOW); |
|
571 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MODE_NORMAL); |
|
572 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PERIPH_NOINCREMENT); |
|
573 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MEMORY_INCREMENT); |
|
574 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PDATAALIGN_BYTE); |
|
575 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MDATAALIGN_BYTE); |
|
576 |
|
|
577 |
/* USART1 interrupt Init */ |
|
578 |
NVIC_SetPriority(USART1_IRQn, 0); |
|
579 |
NVIC_EnableIRQ(USART1_IRQn); |
|
580 |
|
|
581 |
USART_InitStruct.BaudRate = Uart1Baud; |
|
582 |
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; |
|
583 |
USART_InitStruct.StopBits = LL_USART_STOPBITS_1; |
|
584 |
USART_InitStruct.Parity = LL_USART_PARITY_NONE; |
|
585 |
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; |
|
586 |
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; |
|
587 |
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16; |
|
588 |
LL_USART_Init(USART1, &USART_InitStruct); |
|
589 |
// LL_USART_EnableDEMode(USART1); |
|
590 |
// LL_USART_SetDESignalPolarity(USART1, LL_USART_DE_POLARITY_LOW); |
|
591 |
// LL_USART_SetDEAssertionTime(USART1, 1); |
|
592 |
// LL_USART_SetDEDeassertionTime(USART1, 1); |
|
593 |
// LL_USART_EnableOneBitSamp(USART1); |
|
594 |
LL_USART_EnableAutoBaudRate(USART1); |
|
595 |
LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
596 |
LL_USART_DisableOverrunDetect(USART1); |
|
597 |
LL_USART_ConfigAsyncMode(USART1); |
|
598 |
LL_USART_Enable(USART1); |
|
599 |
} |
|
600 |
|
|
601 |
|
|
602 |
/* USART2 init function */ |
|
603 |
void MX_USART2_UART_Init(void) |
|
604 |
{ |
|
605 |
|
|
606 |
LL_USART_InitTypeDef USART_InitStruct = {0}; |
|
607 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
608 |
|
|
609 |
/* Peripheral clock enable */ |
|
610 |
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2); |
|
611 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
|
612 |
|
|
613 |
/**USART2 GPIO Configuration |
|
614 |
PA1 ------> USART2_DE |
|
615 |
PA2 ------> USART2_TX |
|
616 |
PA3 ------> USART2_RX |
|
617 |
*/ |
|
618 |
|
|
619 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_3; |
|
620 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
621 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
622 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
|
623 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
624 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
|
625 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
626 |
|
|
627 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_1; |
|
628 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
629 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
630 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
|
631 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
632 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_1; |
|
633 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
634 |
|
|
635 |
#if (USART2_USE_HARDWARE_DE == 1) |
|
636 |
|
|
637 |
#else |
|
638 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_1; |
|
639 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
640 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
641 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN; |
|
642 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
643 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
644 |
|
|
645 |
#endif |
|
646 |
|
|
647 |
/* USART2 DMA Init */ |
|
648 |
|
|
649 |
/* USART2_TX Init */ |
|
650 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_4, LL_DMA_DIRECTION_MEMORY_TO_PERIPH); |
|
651 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PRIORITY_LOW); |
|
652 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MODE_NORMAL); |
|
653 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PERIPH_NOINCREMENT); |
|
654 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MEMORY_INCREMENT); |
|
655 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PDATAALIGN_BYTE); |
|
656 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MDATAALIGN_BYTE); |
|
657 |
|
|
658 |
/* USART2_RX Init */ |
|
659 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_5, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); |
|
660 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PRIORITY_LOW); |
|
661 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MODE_NORMAL); |
|
662 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PERIPH_NOINCREMENT); |
|
663 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MEMORY_INCREMENT); |
|
664 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PDATAALIGN_BYTE); |
|
665 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MDATAALIGN_BYTE); |
|
666 |
|
|
667 |
/* USART2 interrupt Init */ |
|
668 |
NVIC_SetPriority(USART2_IRQn, 0); |
|
669 |
NVIC_EnableIRQ(USART2_IRQn); |
|
670 |
|
|
671 |
NVIC_SetPriority(PendSV_IRQn, 255); |
|
672 |
NVIC_EnableIRQ(PendSV_IRQn); |
|
673 |
// NVIC_SetPendingIRQ(PendSV_IRQn); |
|
674 |
|
|
675 |
USART_InitStruct.BaudRate = Uart2Baud; |
|
676 |
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; |
|
677 |
USART_InitStruct.StopBits = LL_USART_STOPBITS_1; |
|
678 |
USART_InitStruct.Parity = LL_USART_PARITY_NONE; |
|
679 |
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; |
|
680 |
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; |
|
681 |
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_8; |
|
682 |
LL_USART_Init(USART2, &USART_InitStruct); |
|
683 |
|
|
684 |
#if (USART2_USE_HARDWARE_DE == 1) |
|
685 |
|
|
686 |
LL_USART_EnableDEMode(USART2); |
|
687 |
LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_LOW); |
|
688 |
|
|
689 |
// LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_HIGH); |
|
690 |
LL_USART_SetDEAssertionTime(USART2, 31); |
|
691 |
LL_USART_SetDEDeassertionTime(USART2, 31); |
|
692 |
#else |
|
693 |
|
|
694 |
#endif |
|
695 |
|
|
696 |
// LL_USART_EnableOneBitSamp(USART2); |
|
697 |
LL_USART_EnableAutoBaudRate(USART2); |
|
698 |
LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
699 |
LL_USART_DisableOverrunDetect(USART2); |
|
700 |
LL_USART_ConfigAsyncMode(USART2); |
|
701 |
LL_USART_Enable(USART2); |
|
702 |
} |
|
703 |
|
|
704 |
|
|
705 |
/* USART5 init function */ |
|
706 |
void MX_USART5_UART_Init(void) |
|
707 |
{ |
|
708 |
|
|
709 |
|
|
710 |
LL_USART_InitTypeDef USART_InitStruct = {0}; |
|
711 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
712 |
|
|
713 |
/* Peripheral clock enable */ |
|
714 |
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART5); |
|
715 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
716 |
|
|
717 |
/**USART5 GPIO Configuration |
|
718 |
PB5 ------> USART5_DE |
|
719 |
PB3 ------> USART5_TX |
|
720 |
PB4 ------> USART5_RX |
|
721 |
*/ |
|
722 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4; |
|
723 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
724 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
725 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
726 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
727 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_4; |
|
728 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
729 |
|
|
730 |
|
|
731 |
/* USART5 interrupt Init */ |
|
732 |
NVIC_SetPriority(USART3_6_IRQn, 0); |
|
733 |
NVIC_EnableIRQ(USART3_6_IRQn); |
|
734 |
|
|
735 |
USART_InitStruct.BaudRate = 57600; |
|
736 |
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; |
|
737 |
USART_InitStruct.StopBits = LL_USART_STOPBITS_1; |
|
738 |
USART_InitStruct.Parity = LL_USART_PARITY_NONE; |
|
739 |
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; |
|
740 |
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; |
|
741 |
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_8; |
|
742 |
LL_USART_Init(USART5, &USART_InitStruct); |
|
743 |
|
|
744 |
/* |
|
745 |
LL_USART_EnableDEMode(USART5); |
|
746 |
LL_USART_SetDESignalPolarity(USART5, LL_USART_DE_POLARITY_LOW); |
|
747 |
// LL_USART_SetDESignalPolarity(USART5, LL_USART_DE_POLARITY_HIGH); |
|
748 |
LL_USART_SetDEAssertionTime(USART5, 3); |
|
749 |
LL_USART_SetDEDeassertionTime(USART5, 3); |
|
750 |
LL_USART_EnableOneBitSamp(USART5); |
|
751 |
// LL_USART_EnableAutoBaudRate(USART5); |
|
752 |
// LL_USART_SetAutoBaudRateMode(USART5, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
753 |
*/ |
|
754 |
LL_USART_DisableOverrunDetect(USART5); |
|
755 |
LL_USART_ConfigAsyncMode(USART5); |
|
756 |
LL_USART_Enable(USART5); |
|
757 |
} |
|
758 |
|
|
759 |
/* USART6 init function */ |
|
760 |
void MX_USART6_UART_Init(void) |
|
761 |
{ |
|
762 |
|
|
763 |
LL_USART_InitTypeDef USART_InitStruct = {0}; |
|
764 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0}; |
|
765 |
|
|
766 |
/* Peripheral clock enable */ |
|
767 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_USART6); |
|
768 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
|
769 |
|
|
770 |
/**USART5 GPIO Configuration |
|
771 |
PA4 ------> USART6_TX // Swap |
|
772 |
PA5 ------> USART6_RX |
|
773 |
*/ |
|
774 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_5; |
|
775 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE; |
|
776 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
777 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
778 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
779 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_5; |
|
780 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
781 |
|
|
782 |
|
|
783 |
/* USART5 interrupt Init */ |
|
784 |
NVIC_SetPriority(USART3_6_IRQn, 0); |
|
785 |
NVIC_EnableIRQ(USART3_6_IRQn); |
|
786 |
|
|
787 |
USART_InitStruct.BaudRate = 57600; |
|
788 |
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; |
|
789 |
USART_InitStruct.StopBits = LL_USART_STOPBITS_1; |
|
790 |
USART_InitStruct.Parity = LL_USART_PARITY_NONE; |
|
791 |
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX; |
|
792 |
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE; |
|
793 |
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_8; |
|
794 |
LL_USART_Init(USART6, &USART_InitStruct); |
|
795 |
|
|
796 |
/* |
|
797 |
LL_USART_EnableDEMode(USART6) |
|
798 |
LL_USART_SetDESignalPolarity(USART6, LL_USART_DE_POLARITY_LOW); |
|
799 |
// LL_USART_SetDESignalPolarity(USART6, LL_USART_DE_POLARITY_HIGH); |
|
800 |
LL_USART_SetDEAssertionTime(USART6, 3); |
|
801 |
LL_USART_SetDEDeassertionTime(USART6, 3); |
|
802 |
LL_USART_EnableOneBitSamp(USART6); |
|
803 |
// LL_USART_EnableAutoBaudRate(USART6); |
|
804 |
// LL_USART_SetAutoBaudRateMode(USART6, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE); |
|
805 |
*/ |
|
806 |
|
|
807 |
LL_USART_SetTXRXSwap(USART6,LL_USART_TXRX_SWAPPED); |
|
808 |
LL_USART_DisableOverrunDetect(USART6); |
|
809 |
LL_USART_ConfigAsyncMode(USART6); |
|
810 |
LL_USART_Enable(USART6); |
|
811 |
} |
|
812 |
|
|
813 |
/** |
|
814 |
* Enable DMA controller clock |
|
815 |
*/ |
|
816 |
void MX_DMA_Init(void) |
|
817 |
{ |
|
818 |
/* Init with LL driver */ |
|
819 |
/* DMA controller clock enable */ |
|
820 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1); |
|
821 |
|
|
822 |
/* DMA interrupt init */ |
|
823 |
/* DMA1_Channel2_3_IRQn interrupt configuration */ |
|
824 |
NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0); |
|
825 |
NVIC_EnableIRQ(DMA1_Channel2_3_IRQn); |
|
826 |
NVIC_SetPriority(DMA1_Channel4_5_IRQn, 0); |
|
827 |
NVIC_EnableIRQ(DMA1_Channel4_5_IRQn); |
|
828 |
} |
|
829 |
|
|
830 |
/** Configure pins as |
|
831 |
* Analog |
|
832 |
* Input |
|
833 |
* Output |
|
834 |
* EVENT_OUT |
|
835 |
* EXTI |
|
836 |
*/ |
|
837 |
void MX_GPIO_Init(void) |
|
838 |
{ |
|
839 |
|
|
840 |
LL_GPIO_InitTypeDef GPIO_InitStruct; |
|
841 |
|
|
842 |
/* GPIO Ports Clock Enable */ |
|
843 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA); |
|
844 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
845 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOC); |
|
846 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOF); |
|
847 |
/**/ |
|
848 |
|
|
849 |
|
|
850 |
/**/ |
|
851 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_6 |LL_GPIO_PIN_7|LL_GPIO_PIN_15; |
|
852 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
853 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
854 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
855 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
856 |
|
|
857 |
|
|
858 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_8|LL_GPIO_PIN_11|LL_GPIO_PIN_12; |
|
859 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
860 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
861 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
862 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
863 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
|
864 |
LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_8); |
|
865 |
|
|
866 |
|
|
867 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
|
868 |
LL_GPIO_PIN_8|LL_GPIO_PIN_9|LL_GPIO_PIN_14; |
|
869 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT; |
|
870 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
871 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP; |
|
872 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
873 |
|
|
874 |
if (GetBoardType()==2) |
|
875 |
{ |
|
876 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
|
877 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
|
878 |
|
|
879 |
} |
|
880 |
else if (GetBoardType()==9 || GetBoardType()==10 || GetBoardType()==15 || BOARD_TYPE == 16 ) |
|
881 |
{ |
|
882 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
|
883 |
LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| |
|
884 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
|
885 |
} |
|
886 |
else if ( GetBoardType() == 11 ) |
|
887 |
{ |
|
888 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
|
889 |
LL_GPIO_PIN_2|LL_GPIO_PIN_10|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
|
890 |
} else if (BOARD_TYPE == 14) |
|
891 |
{ |
|
892 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
|
893 |
LL_GPIO_PIN_10|LL_GPIO_PIN_11|LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_14|LL_GPIO_PIN_15; |
|
894 |
} else if (BOARD_TYPE == 17) |
|
895 |
{ |
|
896 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
|
897 |
} else |
|
898 |
{ |
|
899 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7| |
|
900 |
LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10| |
|
901 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15; |
|
902 |
} |
|
903 |
|
|
904 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
905 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH; |
|
906 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
907 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
908 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
|
909 |
|
|
910 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_13|LL_GPIO_PIN_14|LL_GPIO_PIN_15; |
|
911 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT; |
|
912 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_LOW; |
|
913 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
914 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO; |
|
915 |
LL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
|
916 |
|
|
917 |
} |