提交 | 用户 | age
|
bfc108
|
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 |
|
|
16 |
/*
|
|
17 |
if ((nCurTick &0xff) ==0)
|
|
18 |
{
|
|
19 |
if (freqdir) { freq+=1+freq/10;if (freq>=1500) {freq=1500;freqdir=0;}}
|
|
20 |
else {freq-=1+freq/10;if (freq<=10) {freq=10;freqdir=1;} }
|
|
21 |
}
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
static int outputsum=0;
|
|
26 |
static int freq=10;
|
|
27 |
static int freqdir=1;
|
|
28 |
static int phase=0;
|
|
29 |
static int somb=0;
|
|
30 |
static int len=0;
|
|
31 |
static int curbb=0;
|
|
32 |
|
|
33 |
if ((nCurTick &0x3ff) ==1)
|
|
34 |
{
|
|
35 |
curbb++;
|
|
36 |
if (curbb+1==len)
|
|
37 |
{
|
|
38 |
// freq=0;
|
|
39 |
}else if (curbb>=len)
|
|
40 |
{
|
|
41 |
somb=musictab1[cur_musicpos*2];
|
|
42 |
len=musictab1[cur_musicpos*2+1];
|
|
43 |
freq=freqtab[somb];
|
|
44 |
curbb=0;cur_musicpos++; if (cur_musicpos >= Totalmusiccount) {cur_musicpos=0;}
|
|
45 |
}
|
|
46 |
}
|
|
47 |
if ((nCurTick &0x3ff) ==0x1ff)
|
|
48 |
{
|
|
49 |
if (curbb+1==len)
|
|
50 |
{
|
|
51 |
freq=0;
|
|
52 |
}
|
|
53 |
}
|
|
54 |
phase+=freq;
|
|
55 |
if (phase>=5000) {phase-=5000;}
|
|
56 |
|
|
57 |
|
|
58 |
if (outtype==1)
|
|
59 |
{
|
|
60 |
outputsum+=freq;
|
|
61 |
if (outputsum>=5000)
|
|
62 |
{
|
|
63 |
//LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3);
|
|
64 |
LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3);
|
|
65 |
outputsum-=5000;
|
|
66 |
}
|
|
67 |
else
|
|
68 |
{
|
|
69 |
//LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3);
|
|
70 |
}
|
|
71 |
}else if (outtype==2)
|
|
72 |
{
|
|
73 |
const int volume = 2500;
|
|
74 |
int amp;
|
|
75 |
if (phase<1250)
|
|
76 |
{
|
|
77 |
amp=2500+sintab[(phase -0)*256/1250]*volume/256;
|
|
78 |
|
|
79 |
}else if (phase <2500)
|
|
80 |
{
|
|
81 |
amp=2500+sintab[(2500-1-phase)*256/1250]*volume/256;
|
|
82 |
}else if (phase <3750)
|
|
83 |
{
|
|
84 |
amp=2500-sintab[(phase-2500)*256/1250]*volume/256;
|
|
85 |
}else
|
|
86 |
{
|
|
87 |
amp=2500-sintab[(5000-1-phase)*256/1250]*volume/256;
|
|
88 |
}
|
|
89 |
outputsum+=amp;
|
|
90 |
if (outputsum>=5000)
|
|
91 |
{
|
|
92 |
LL_GPIO_SetOutputPin(GPIOB,LL_GPIO_PIN_3);
|
|
93 |
//LL_GPIO_TogglePin(GPIOB,LL_GPIO_PIN_3);
|
|
94 |
outputsum-=5000;
|
|
95 |
}
|
|
96 |
else
|
|
97 |
{
|
|
98 |
LL_GPIO_ResetOutputPin(GPIOB,LL_GPIO_PIN_3);
|
|
99 |
}
|
|
100 |
}
|
|
101 |
*/
|
|
102 |
|
|
103 |
|
|
104 |
/**
|
|
105 |
* @brief System Clock Configuration
|
|
106 |
* @retval None
|
|
107 |
*/
|
|
108 |
void SystemClock_Config(void)
|
|
109 |
{
|
|
110 |
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
111 |
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
112 |
|
|
113 |
/** Initializes the CPU, AHB and APB busses clocks
|
|
114 |
*/
|
|
115 |
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
116 |
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
117 |
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
118 |
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
0aeaad
|
119 |
|
Q |
120 |
#if (XLAT_FREQ == 12)
|
|
121 |
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4;
|
|
122 |
#else
|
bfc108
|
123 |
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
|
0aeaad
|
124 |
#endif
|
Q |
125 |
|
bfc108
|
126 |
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
|
Q |
127 |
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
128 |
{
|
|
129 |
Error_Handler();
|
|
130 |
}
|
|
131 |
/** Initializes the CPU, AHB and APB busses clocks
|
|
132 |
*/
|
|
133 |
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
134 |
|RCC_CLOCKTYPE_PCLK1;
|
|
135 |
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
136 |
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
137 |
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
|
138 |
|
|
139 |
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
|
|
140 |
{
|
|
141 |
Error_Handler();
|
|
142 |
}
|
|
143 |
|
|
144 |
//RCC_OscInitTypeDef RCC_OscInitStruct;
|
|
145 |
//RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
|
146 |
RCC_PeriphCLKInitTypeDef PeriphClkInit;
|
|
147 |
|
|
148 |
/**Initializes the CPU, AHB and APB busses clocks
|
|
149 |
*/
|
|
150 |
|
|
151 |
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1;
|
|
152 |
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK;
|
|
153 |
|
|
154 |
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
155 |
{
|
|
156 |
_Error_Handler(__FILE__, __LINE__);
|
|
157 |
}
|
|
158 |
|
|
159 |
/**Configure the Systick interrupt time
|
|
160 |
*/
|
|
161 |
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/10000);
|
|
162 |
|
|
163 |
/**Configure the Systick
|
|
164 |
*/
|
|
165 |
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
|
166 |
|
|
167 |
/* SysTick_IRQn interrupt configuration */
|
|
168 |
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
|
169 |
}
|
|
170 |
|
|
171 |
void MX_IWDG_Init(void)
|
|
172 |
{
|
|
173 |
|
|
174 |
/* USER CODE BEGIN IWDG_Init 0 */
|
|
175 |
|
|
176 |
/* USER CODE END IWDG_Init 0 */
|
|
177 |
|
|
178 |
/* USER CODE BEGIN IWDG_Init 1 */
|
|
179 |
|
|
180 |
/* USER CODE END IWDG_Init 1 */
|
|
181 |
LL_IWDG_Enable(IWDG);
|
|
182 |
LL_IWDG_EnableWriteAccess(IWDG);
|
|
183 |
LL_IWDG_SetPrescaler(IWDG, LL_IWDG_PRESCALER_64);
|
|
184 |
LL_IWDG_SetReloadCounter(IWDG, 4095);
|
|
185 |
while (LL_IWDG_IsReady(IWDG) != 1)
|
|
186 |
{
|
|
187 |
}
|
|
188 |
|
|
189 |
LL_IWDG_SetWindow(IWDG, 4095);
|
|
190 |
LL_IWDG_ReloadCounter(IWDG);
|
|
191 |
/* USER CODE BEGIN IWDG_Init 2 */
|
|
192 |
|
|
193 |
/* USER CODE END IWDG_Init 2 */
|
|
194 |
|
|
195 |
}
|
|
196 |
|
|
197 |
/* ADC init function */
|
|
198 |
void MX_ADC_Init(void)
|
|
199 |
{
|
|
200 |
|
|
201 |
LL_ADC_InitTypeDef ADC_InitStruct;
|
|
202 |
LL_ADC_REG_InitTypeDef ADC_REG_InitStruct;
|
|
203 |
|
|
204 |
/* Peripheral clock enable */
|
|
205 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_ADC1);
|
|
206 |
|
|
207 |
/**Configure Regular Channel
|
|
208 |
*/
|
0aeaad
|
209 |
LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_0|LL_ADC_CHANNEL_1);
|
bfc108
|
210 |
|
Q |
211 |
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR|LL_ADC_PATH_INTERNAL_VREFINT);
|
|
212 |
|
|
213 |
/**Configure Regular Channel
|
|
214 |
*/
|
|
215 |
LL_ADC_REG_SetSequencerChAdd(ADC1, LL_ADC_CHANNEL_TEMPSENSOR|LL_ADC_CHANNEL_VREFINT);
|
|
216 |
|
|
217 |
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_TEMPSENSOR|LL_ADC_PATH_INTERNAL_VREFINT);
|
|
218 |
|
|
219 |
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
|
|
220 |
*/
|
|
221 |
ADC_InitStruct.Clock = LL_ADC_CLOCK_ASYNC;
|
|
222 |
ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B;
|
|
223 |
ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
|
|
224 |
ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE;
|
|
225 |
LL_ADC_Init(ADC1, &ADC_InitStruct);
|
|
226 |
|
|
227 |
ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
|
|
228 |
ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
|
|
229 |
ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_SINGLE;
|
|
230 |
ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_LIMITED;
|
|
231 |
ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED;
|
|
232 |
LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct);
|
|
233 |
|
|
234 |
LL_ADC_REG_SetSequencerScanDirection(ADC1, LL_ADC_REG_SEQ_SCAN_DIR_FORWARD);
|
|
235 |
|
0aeaad
|
236 |
LL_ADC_SetSamplingTimeCommonChannels(ADC1, LL_ADC_SAMPLINGTIME_28CYCLES_5);
|
bfc108
|
237 |
|
Q |
238 |
LL_ADC_EnableIT_EOC(ADC1);
|
|
239 |
|
|
240 |
LL_ADC_DisableIT_EOS(ADC1);
|
|
241 |
|
|
242 |
LL_ADC_StartCalibration(ADC1);
|
|
243 |
|
|
244 |
// LL_ADC_EnableInternalRegulator(ADC1);
|
|
245 |
|
|
246 |
// ADC_TempSensorCmd(ENABLE);//?????????
|
|
247 |
// ADC_VrefintCmd(ENABLE); //????????
|
|
248 |
|
|
249 |
|
|
250 |
//ADC_TempSensorCmd(ENABLE);//
|
|
251 |
//ADC_ChannelConfig();
|
|
252 |
//ADC_VrefintCmd(ENABLE); //
|
|
253 |
|
|
254 |
while( LL_ADC_IsCalibrationOnGoing(ADC1));
|
|
255 |
LL_ADC_Enable(ADC1);
|
|
256 |
/*
|
|
257 |
LL_ADC_REG_SetDMATransfer(ADC1,LL_ADC_REG_DMA_TRANSFER_UNLIMITED);
|
|
258 |
LL_ADC_REG_StartConversion(ADC1);
|
|
259 |
*/
|
|
260 |
}
|
|
261 |
|
|
262 |
/* SPI1 init function */
|
|
263 |
void MX_SPI1_Init(void)
|
|
264 |
{
|
|
265 |
|
|
266 |
LL_SPI_InitTypeDef SPI_InitStruct;
|
|
267 |
|
|
268 |
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
|
269 |
|
|
270 |
/* Peripheral clock enable */
|
|
271 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SPI1);
|
|
272 |
|
|
273 |
/**SPI1 GPIO Configuration
|
|
274 |
PA5 ------> SPI1_SCK
|
|
275 |
PA6 ------> SPI1_MISO
|
|
276 |
PA7 ------> SPI1_MOSI
|
|
277 |
*/
|
|
278 |
// GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
|
|
279 |
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
280 |
// GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
281 |
// GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
282 |
// GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
283 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
|
|
284 |
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
285 |
|
|
286 |
// GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
|
|
287 |
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
288 |
// GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
289 |
// GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
290 |
// GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
291 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
|
|
292 |
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
293 |
|
|
294 |
// GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
|
|
295 |
// GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
296 |
// GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
297 |
// GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
298 |
// GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
299 |
// GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
|
|
300 |
// LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
301 |
|
|
302 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
|
|
303 |
/**SPI1 GPIO Configuration
|
|
304 |
PB3 ------> SPI1_SCK
|
|
305 |
PB4 ------> SPI1_MISO
|
|
306 |
PB5 ------> SPI1_MOSI
|
|
307 |
*/
|
|
308 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
|
|
309 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
310 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
311 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
312 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
313 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
|
|
314 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
315 |
|
|
316 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_4;
|
|
317 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
318 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
319 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
320 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
321 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
|
|
322 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
323 |
|
|
324 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
|
|
325 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
326 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
327 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
328 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
329 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
|
|
330 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
331 |
|
|
332 |
/* SPI1 interrupt Init */
|
|
333 |
NVIC_SetPriority(SPI1_IRQn, 0);
|
|
334 |
NVIC_EnableIRQ(SPI1_IRQn);
|
|
335 |
/* USER CODE BEGIN SPI1_Init 1 */
|
|
336 |
|
|
337 |
/* USER CODE END SPI1_Init 1 */
|
|
338 |
|
|
339 |
/* SPI1 parameter configuration*/
|
|
340 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
|
|
341 |
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
|
|
342 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
|
|
343 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
|
|
344 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
|
|
345 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
|
|
346 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4;
|
|
347 |
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
|
|
348 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
|
|
349 |
SPI_InitStruct.CRCPoly = 7;
|
|
350 |
LL_SPI_Init(SPI1, &SPI_InitStruct);
|
|
351 |
|
|
352 |
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
|
|
353 |
|
|
354 |
LL_SPI_EnableNSSPulseMgt(SPI1);
|
|
355 |
/* USER CODE BEGIN SPI1_Init 2 */
|
0aeaad
|
356 |
LL_SPI_Enable(SPI1);
|
bfc108
|
357 |
/* USER CODE END SPI1_Init 2 */
|
Q |
358 |
}
|
0aeaad
|
359 |
|
Q |
360 |
/* SPI2 init function */
|
|
361 |
void MX_SPI2_Init(void)
|
|
362 |
{
|
|
363 |
|
|
364 |
LL_SPI_InitTypeDef SPI_InitStruct = {0};
|
|
365 |
|
|
366 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
367 |
|
|
368 |
/* Peripheral clock enable */
|
|
369 |
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2);
|
|
370 |
|
|
371 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
|
|
372 |
/**SPI2 GPIO Configuration
|
|
373 |
PB13 ------> SPI2_SCK
|
|
374 |
PB14 ------> SPI2_MISO
|
|
375 |
PB15 ------> SPI2_MOSI
|
|
376 |
*/
|
|
377 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_13;
|
|
378 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
379 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
380 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
381 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
382 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
|
|
383 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
384 |
|
|
385 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_14;
|
|
386 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
387 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
388 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
389 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
390 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
|
|
391 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
392 |
|
|
393 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
|
|
394 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
395 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
396 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
397 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
398 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
|
|
399 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
400 |
|
|
401 |
/* SPI2 interrupt Init */
|
|
402 |
//NVIC_SetPriority(SPI2_IRQn, 0);
|
|
403 |
//NVIC_EnableIRQ(SPI2_IRQn);
|
|
404 |
/* USER CODE BEGIN SPI2_Init 1 */
|
|
405 |
|
|
406 |
/* USER CODE END SPI2_Init 1 */
|
|
407 |
|
|
408 |
/* SPI2 parameter configuration*/
|
|
409 |
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
|
|
410 |
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
|
|
411 |
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
|
|
412 |
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW; //LL_SPI_POLARITY_HIGH;//LL_SPI_POLARITY_LOW;
|
|
413 |
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE; //LL_SPI_PHASE_1EDGE;
|
|
414 |
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
|
|
415 |
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
|
|
416 |
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
|
|
417 |
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
|
|
418 |
SPI_InitStruct.CRCPoly = 7;
|
|
419 |
LL_SPI_Init(SPI2, &SPI_InitStruct);
|
|
420 |
LL_SPI_SetStandard(SPI2, LL_SPI_PROTOCOL_MOTOROLA);
|
|
421 |
LL_SPI_EnableNSSPulseMgt(SPI2);
|
|
422 |
/* USER CODE BEGIN SP21_Init 2 */
|
|
423 |
LL_SPI_Enable(SPI2);
|
|
424 |
/* USER CODE END SPI2_Init 2 */
|
|
425 |
}
|
|
426 |
|
bfc108
|
427 |
|
Q |
428 |
/* USART1 init function */
|
|
429 |
void MX_USART1_UART_Init(void)
|
|
430 |
{
|
|
431 |
|
|
432 |
LL_USART_InitTypeDef USART_InitStruct;
|
|
433 |
|
|
434 |
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
|
435 |
|
|
436 |
/* Peripheral clock enable */
|
|
437 |
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_USART1);
|
|
438 |
|
|
439 |
/**USART1 GPIO Configuration
|
|
440 |
// PA1 ------> USART1_DE
|
|
441 |
PA9 ------> USART1_TX
|
|
442 |
PA10 ------> USART1_RX
|
|
443 |
*/
|
|
444 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_10;
|
|
445 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
446 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
447 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
448 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
449 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
|
|
450 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
451 |
|
|
452 |
/* USART1 DMA Init */
|
|
453 |
|
|
454 |
/* USART1_TX Init */
|
|
455 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_2, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
|
|
456 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PRIORITY_LOW);
|
|
457 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MODE_NORMAL);
|
|
458 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PERIPH_NOINCREMENT);
|
|
459 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MEMORY_INCREMENT);
|
|
460 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PDATAALIGN_BYTE);
|
|
461 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MDATAALIGN_BYTE);
|
|
462 |
|
|
463 |
/* USART1_RX Init */
|
|
464 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_3, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
|
|
465 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PRIORITY_LOW);
|
|
466 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MODE_NORMAL);
|
|
467 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PERIPH_NOINCREMENT);
|
|
468 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MEMORY_INCREMENT);
|
|
469 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PDATAALIGN_BYTE);
|
|
470 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MDATAALIGN_BYTE);
|
|
471 |
|
|
472 |
/* USART1 interrupt Init */
|
|
473 |
NVIC_SetPriority(USART1_IRQn, 0);
|
|
474 |
NVIC_EnableIRQ(USART1_IRQn);
|
|
475 |
|
|
476 |
USART_InitStruct.BaudRate = Uart1Baud;
|
|
477 |
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
|
|
478 |
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
|
|
479 |
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
|
|
480 |
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
|
|
481 |
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
|
|
482 |
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
|
|
483 |
LL_USART_Init(USART1, &USART_InitStruct);
|
|
484 |
// LL_USART_EnableDEMode(USART1);
|
|
485 |
// LL_USART_SetDESignalPolarity(USART1, LL_USART_DE_POLARITY_LOW);
|
|
486 |
// LL_USART_SetDEAssertionTime(USART1, 1);
|
|
487 |
// LL_USART_SetDEDeassertionTime(USART1, 1);
|
|
488 |
// LL_USART_EnableOneBitSamp(USART1);
|
|
489 |
LL_USART_EnableAutoBaudRate(USART1);
|
|
490 |
LL_USART_SetAutoBaudRateMode(USART1, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE);
|
|
491 |
LL_USART_DisableOverrunDetect(USART1);
|
|
492 |
LL_USART_ConfigAsyncMode(USART1);
|
|
493 |
LL_USART_Enable(USART1);
|
|
494 |
}
|
|
495 |
|
|
496 |
|
|
497 |
/* USART2 init function */
|
|
498 |
void MX_USART2_UART_Init(void)
|
|
499 |
{
|
|
500 |
|
|
501 |
LL_USART_InitTypeDef USART_InitStruct = {0};
|
|
502 |
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
503 |
|
|
504 |
/* Peripheral clock enable */
|
|
505 |
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2);
|
|
506 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
|
|
507 |
|
|
508 |
/**USART2 GPIO Configuration
|
|
509 |
PA1 ------> USART2_DE
|
|
510 |
PA2 ------> USART2_TX
|
|
511 |
PA3 ------> USART2_RX
|
|
512 |
*/
|
|
513 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_3;
|
|
514 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
|
515 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
516 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
517 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
518 |
GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
|
|
519 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
520 |
|
|
521 |
/* USART2 DMA Init */
|
|
522 |
|
|
523 |
/* USART2_TX Init */
|
|
524 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_4, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
|
|
525 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PRIORITY_LOW);
|
|
526 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MODE_NORMAL);
|
|
527 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PERIPH_NOINCREMENT);
|
|
528 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MEMORY_INCREMENT);
|
|
529 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PDATAALIGN_BYTE);
|
|
530 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MDATAALIGN_BYTE);
|
|
531 |
|
|
532 |
/* USART2_RX Init */
|
|
533 |
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_5, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
|
|
534 |
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PRIORITY_LOW);
|
|
535 |
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MODE_NORMAL);
|
|
536 |
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PERIPH_NOINCREMENT);
|
|
537 |
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MEMORY_INCREMENT);
|
|
538 |
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PDATAALIGN_BYTE);
|
|
539 |
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MDATAALIGN_BYTE);
|
|
540 |
|
|
541 |
/* USART2 interrupt Init */
|
|
542 |
NVIC_SetPriority(USART2_IRQn, 0);
|
|
543 |
NVIC_EnableIRQ(USART2_IRQn);
|
|
544 |
|
|
545 |
NVIC_SetPriority(PendSV_IRQn, 255);
|
|
546 |
NVIC_EnableIRQ(PendSV_IRQn);
|
|
547 |
// NVIC_SetPendingIRQ(PendSV_IRQn);
|
|
548 |
|
|
549 |
USART_InitStruct.BaudRate = Uart2Baud;
|
|
550 |
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
|
|
551 |
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
|
|
552 |
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
|
|
553 |
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
|
|
554 |
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
|
|
555 |
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_8;
|
|
556 |
LL_USART_Init(USART2, &USART_InitStruct);
|
|
557 |
|
|
558 |
LL_USART_EnableDEMode(USART2);
|
|
559 |
LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_LOW);
|
|
560 |
// LL_USART_SetDESignalPolarity(USART2, LL_USART_DE_POLARITY_HIGH);
|
|
561 |
LL_USART_SetDEAssertionTime(USART2, 3);
|
|
562 |
LL_USART_SetDEDeassertionTime(USART2, 3);
|
|
563 |
LL_USART_EnableOneBitSamp(USART2);
|
|
564 |
// LL_USART_EnableAutoBaudRate(USART2);
|
|
565 |
// LL_USART_SetAutoBaudRateMode(USART2, LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE);
|
|
566 |
LL_USART_DisableOverrunDetect(USART2);
|
|
567 |
LL_USART_ConfigAsyncMode(USART2);
|
|
568 |
LL_USART_Enable(USART2);
|
|
569 |
}
|
|
570 |
|
|
571 |
/**
|
|
572 |
* Enable DMA controller clock
|
|
573 |
*/
|
|
574 |
void MX_DMA_Init(void)
|
|
575 |
{
|
|
576 |
/* Init with LL driver */
|
|
577 |
/* DMA controller clock enable */
|
|
578 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
|
|
579 |
|
|
580 |
/* DMA interrupt init */
|
|
581 |
/* DMA1_Channel2_3_IRQn interrupt configuration */
|
|
582 |
NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0);
|
|
583 |
NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
|
|
584 |
NVIC_SetPriority(DMA1_Channel4_5_IRQn, 0);
|
|
585 |
NVIC_EnableIRQ(DMA1_Channel4_5_IRQn);
|
|
586 |
}
|
|
587 |
|
|
588 |
/** Configure pins as
|
|
589 |
* Analog
|
|
590 |
* Input
|
|
591 |
* Output
|
|
592 |
* EVENT_OUT
|
|
593 |
* EXTI
|
|
594 |
*/
|
|
595 |
void MX_GPIO_Init(void)
|
|
596 |
{
|
|
597 |
|
|
598 |
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
|
599 |
|
|
600 |
/* GPIO Ports Clock Enable */
|
|
601 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
|
|
602 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
|
|
603 |
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOC);
|
|
604 |
/**/
|
|
605 |
|
|
606 |
|
|
607 |
/**/
|
|
608 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_6 ; //|LL_GPIO_PIN_7;
|
|
609 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
|
610 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
611 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
|
612 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
613 |
|
|
614 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_7 ;
|
|
615 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
|
616 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
617 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
618 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
619 |
|
|
620 |
|
|
621 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_8|LL_GPIO_PIN_11;
|
|
622 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
|
623 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
624 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
625 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
626 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
627 |
LL_GPIO_SetOutputPin(GPIOA, LL_GPIO_PIN_8);
|
|
628 |
|
|
629 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_9|LL_GPIO_PIN_10;
|
|
630 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
|
631 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
632 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
|
633 |
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
634 |
|
|
635 |
|
|
636 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10;
|
|
637 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
|
638 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
639 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
|
|
640 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
641 |
|
|
642 |
if (GetBoardType()==2)
|
|
643 |
{
|
|
644 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|
|
|
645 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
|
646 |
|
|
647 |
}
|
|
648 |
else if (GetBoardType()==9 || GetBoardType()==10 )
|
|
649 |
{
|
|
650 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|
|
|
651 |
LL_GPIO_PIN_11|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10|
|
|
652 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
|
653 |
}
|
0aeaad
|
654 |
else if ( GetBoardType() == 11 )
|
Q |
655 |
{
|
|
656 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|
|
|
657 |
LL_GPIO_PIN_2|LL_GPIO_PIN_10|
|
|
658 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
|
659 |
} else
|
bfc108
|
660 |
{
|
Q |
661 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_3|LL_GPIO_PIN_4|LL_GPIO_PIN_5|LL_GPIO_PIN_6|LL_GPIO_PIN_7|
|
|
662 |
LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2|LL_GPIO_PIN_10|
|
|
663 |
LL_GPIO_PIN_12|LL_GPIO_PIN_13|LL_GPIO_PIN_15;
|
|
664 |
}
|
|
665 |
|
|
666 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
|
667 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
|
|
668 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
669 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
670 |
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
671 |
|
|
672 |
LL_GPIO_SetOutputPin(GPIOB, LL_GPIO_PIN_3);
|
|
673 |
|
|
674 |
GPIO_InitStruct.Pin = LL_GPIO_PIN_13|LL_GPIO_PIN_14;
|
|
675 |
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
|
|
676 |
GPIO_InitStruct.Speed = LL_GPIO_SPEED_LOW;
|
|
677 |
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
|
678 |
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
|
679 |
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
680 |
|
|
681 |
// RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO,ENABLE );
|
|
682 |
// PWR_BackupAccessCmd( ENABLE );/* ????RTC??????*/
|
|
683 |
// RCC_LSEConfig( RCC_LSE_OFF ); /* ????????,PC14+PC15??????IO*/
|
|
684 |
// BKP_TamperPinCmd(DISABLE); /* ????????,PC13??????IO*/
|
|
685 |
|
|
686 |
}
|