1 | /**
|
2 |
|
3 | *
|
4 | ******************************************************************************
|
5 | */
|
6 | /* Includes ------------------------------------------------------------------*/
|
7 | #include "main.h"
|
8 | #include "stm32l4xx_hal.h"
|
9 |
|
10 | /* USER CODE BEGIN Includes */
|
11 |
|
12 | #define TIM_OCMODE_PWM2_CH1 TIM_OCMODE_PWM2
|
13 | #define TIM_OCMODE_PWM2_CH2 ((uint32_t)TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_0)
|
14 | #define TIM_OCMODE_PWM2_CH3 ((uint32_t)TIM_CCMR2_OC3M_2 | TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_0)
|
15 | #define TIM_OCMODE_PWM2_CH4 ((uint32_t)TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_0)
|
16 | #define TIM_OCMODE_PWM1_CH5 ((uint32_t)TIM_CCMR2_OC4M_2 | TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_0)
|
17 | #define CH17_SEL 23
|
18 | #define ADC_Channel_Pos 6
|
19 | /* USER CODE END Includes */
|
20 |
|
21 | /* Private variables ---------------------------------------------------------*/
|
22 | ADC_HandleTypeDef hadc1;
|
23 | DMA_HandleTypeDef hdma_adc1;
|
24 |
|
25 | TIM_HandleTypeDef htim1;
|
26 | TIM_HandleTypeDef htim2;
|
27 |
|
28 | /* USER CODE BEGIN PV */
|
29 | /* Private variables ---------------------------------------------------------*/
|
30 |
|
31 | /* USER CODE END PV */
|
32 |
|
33 | /* Private function prototypes -----------------------------------------------*/
|
34 | void SystemClock_Config(void);
|
35 | void Error_Handler(void);
|
36 | static void MX_GPIO_Init(void);
|
37 | static void MX_DMA_Init(void);
|
38 | static void MX_TIM1_Init(void);
|
39 | static void MX_ADC1_Init(void);
|
40 | static void MX_TIM2_Init(void);
|
41 |
|
42 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
43 |
|
44 |
|
45 |
|
46 | /* USER CODE BEGIN PFP */
|
47 | /* Private function prototypes -----------------------------------------------*/
|
48 |
|
49 | void Enable_Timerx_Counter(uint8_t Timer_x);
|
50 | void Init_Timer2(uint8_t Presc, uint8_t period);
|
51 | void Enable_LED_x(uint8_t led_x, uint16_t duty_Cycle_value);
|
52 |
|
53 |
|
54 | /* USER CODE END PFP */
|
55 |
|
56 | /* USER CODE BEGIN 0 */
|
57 |
|
58 |
|
59 |
|
60 | void Enable_Timerx_Counter(uint8_t Timer_x)
|
61 | {
|
62 | /* Enable_Timerx_Counter(uint8_t Timer_x) where Timer_x is 1, 2, 15, 16 */
|
63 |
|
64 | if (Timer_x == 1)
|
65 | {
|
66 | TIM1->CR1 |= TIM_CR1_CEN;
|
67 | }
|
68 |
|
69 | if (Timer_x == 2)
|
70 | {
|
71 | TIM2->CR1 |= TIM_CR1_CEN;
|
72 | }
|
73 |
|
74 | if (Timer_x == 15)
|
75 | {
|
76 | TIM15->CR1 |= TIM_CR1_CEN;
|
77 | }
|
78 |
|
79 | if (Timer_x == 16)
|
80 | {
|
81 | TIM16->CR1 |= TIM_CR1_CEN;
|
82 | }
|
83 |
|
84 | }
|
85 |
|
86 |
|
87 |
|
88 | void Init_Timer2(uint8_t Presc, uint8_t period)
|
89 | {
|
90 | /* General configuration for all Timer 1 Channels 1-4*/
|
91 | RCC->APB1ENR1 |= RCC_APB1ENR1_TIM2EN; /* Peripheral clock enable */
|
92 | TIM2->CR1 |= TIM_CR1_CMS_0; /* Select the Counter Centeraligned Mode 1 */
|
93 | TIM2->CR1 &= ~TIM_CR1_CKD; /* Erase bits of CKD */
|
94 | TIM2->PSC = Presc; /* Set the Prescaler value */
|
95 | TIM2->ARR = period - 1; /* Set the Auto-reload value - top value counter*/
|
96 |
|
97 | /* Configure register bits for Channel 1*/
|
98 | TIM2->CCMR1 |=(uint16_t)TIM_CCMR1_OC1M; /* OC1 is low until CCR1, with PWM mode 2 the polarity is set */
|
99 | TIM2->CCMR1 &= (uint16_t)~TIM_CCMR1_CC1S; /* Set CC1 as output */
|
100 | TIM2->CCER &= ~TIM_CCER_CC1P; /* CC1P for OC1 active high */
|
101 |
|
102 |
|
103 | /* Configure register bits for Channel 1*/
|
104 | TIM2->CCMR1 |=(uint16_t)TIM_CCMR1_OC1M; /* OC1 is low until CCR1, with PWM mode 2 the polarity is set */
|
105 | TIM2->CCMR1 &= (uint16_t)~TIM_CCMR1_CC1S; /* Set CC1 as output */
|
106 | TIM2->CCER &= ~TIM_CCER_CC1P; /* CC1P for OC1 active high */
|
107 |
|
108 | /* Configure register bits for Channel 1*/
|
109 | TIM2->CCMR2 |=(uint16_t)TIM_CCMR2_OC3M; /* OC1 is low until CCR1, with PWM mode 2 the polarity is set */
|
110 | TIM2->CCMR2 &= (uint16_t)~TIM_CCMR2_CC3S; /* Set CC2 as output */
|
111 | TIM2->CCER &= ~TIM_CCER_CC2P; /* CC2P for OC1 active high */
|
112 |
|
113 | /* Configure register bits for Channel 1*/
|
114 | TIM2->CCMR2 |=(uint16_t)TIM_CCMR2_OC4M; /* OC1 is low until CCR1, with PWM mode 2 the polarity is set */
|
115 | TIM2->CCMR2 &= (uint16_t)~TIM_CCMR2_CC4S; /* Set CC1 as output */
|
116 | TIM2->CCER &= ~TIM_CCER_CC4P; /* CC1P for OC1 active high */
|
117 |
|
118 |
|
119 | /* General configuration of GPIO for Timer2 PWM Generation*/
|
120 | GPIO_InitTypeDef gpio;
|
121 |
|
122 | /* GPIO Ports Clock Enable */
|
123 | __HAL_RCC_GPIOA_CLK_ENABLE();
|
124 | __HAL_RCC_GPIOB_CLK_ENABLE();
|
125 |
|
126 | /**TIM2 GPIO Configuration
|
127 | PB3 ------> TIM2_CH2
|
128 | PB10 ------> TIM2_CH3
|
129 | PB11 ------> TIM2_CH4
|
130 | PA15 ------> TIM2_CH1
|
131 | */
|
132 | gpio.Pin = GPIO_PIN_15;
|
133 | gpio.Mode = GPIO_MODE_AF_PP;
|
134 | gpio.Pull = GPIO_NOPULL;
|
135 | gpio.Speed = GPIO_SPEED_FREQ_LOW;
|
136 | gpio.Alternate = GPIO_AF1_TIM2;
|
137 | HAL_GPIO_Init(GPIOA, &gpio);
|
138 |
|
139 | gpio.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_3;
|
140 | gpio.Mode = GPIO_MODE_AF_PP;
|
141 | gpio.Pull = GPIO_NOPULL;
|
142 | gpio.Speed = GPIO_SPEED_FREQ_LOW;
|
143 | gpio.Alternate = GPIO_AF1_TIM2;
|
144 | HAL_GPIO_Init(GPIOB, &gpio);
|
145 |
|
146 | }
|
147 |
|
148 | void Enable_Timer2_Counter()
|
149 | {
|
150 | TIM2->CR1 |= TIM_CR1_CEN;
|
151 | }
|
152 |
|
153 | void Enable_LED_x(uint8_t led_x, uint16_t duty_Cycle_value)
|
154 | {
|
155 |
|
156 | if (led_x == 1)
|
157 | {
|
158 | TIM2->CCR1 = duty_Cycle_value; /* Set the compare value channel 1*/
|
159 | TIM2->CCER |= TIM_CCER_CC1E; /* Enable the Compare output channel 1 */
|
160 | }
|
161 |
|
162 | if (led_x == 2)
|
163 | {
|
164 | TIM2->CCR2 = duty_Cycle_value; /* Set the compare value channel 2*/
|
165 | TIM2->CCER |= TIM_CCER_CC2E; /* Enable the Compare output channel 2 */
|
166 | }
|
167 |
|
168 | if (led_x == 3)
|
169 | {
|
170 | TIM2->CCR3 = duty_Cycle_value; /* Set the compare value channel 3*/
|
171 | TIM2->CCER |= TIM_CCER_CC3E; /* Enable the Compare output channel 3 */
|
172 | }
|
173 |
|
174 | if (led_x == 4)
|
175 | {
|
176 | TIM2->CCR4 = duty_Cycle_value; /* Set the compare value channel 4*/
|
177 | TIM2->CCER |= TIM_CCER_CC4E; /* Enable the Compare output channel 4 */
|
178 | }
|
179 | }
|
180 |
|
181 | /* USER CODE END 0 */
|
182 |
|
183 | int main(void)
|
184 | {
|
185 |
|
186 | /* USER CODE BEGIN 1 */
|
187 |
|
188 | /* USER CODE END 1 */
|
189 |
|
190 | /* MCU Configuration----------------------------------------------------------*/
|
191 |
|
192 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
193 | HAL_Init();
|
194 |
|
195 | /* Configure the system clock */
|
196 | SystemClock_Config();
|
197 |
|
198 | /* Initialize all configured peripherals */
|
199 | MX_GPIO_Init();
|
200 | MX_DMA_Init();
|
201 | MX_TIM1_Init();
|
202 | MX_ADC1_Init();
|
203 | MX_TIM2_Init();
|
204 |
|
205 | /* USER CODE BEGIN 2 */
|
206 |
|
207 | /* USER Inits*/
|
208 |
|
209 | Init_Timer2(0, 255);
|
210 |
|
211 |
|
212 | Enable_Timerx_Counter(2);
|
213 | Enable_LED_x(1, 50);
|
214 | Enable_LED_x(2, 65);
|
215 | Enable_LED_x(3, 80);
|
216 | Enable_LED_x(4, 100);
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 | /* USER CODE END 2 */
|
223 |
|
224 | /* Infinite loop */
|
225 | /* USER CODE BEGIN WHILE */
|
226 | while (1)
|
227 | {
|
228 |
|
229 | /* USER CODE END WHILE */
|
230 |
|
231 | /* USER CODE BEGIN 3 */
|
232 |
|
233 | }
|
234 | /* USER CODE END 3 */
|
235 |
|
236 | }
|
237 |
|
238 | /** System Clock Configuration
|
239 | */
|
240 | void SystemClock_Config(void)
|
241 | {
|
242 |
|
243 | RCC_OscInitTypeDef RCC_OscInitStruct;
|
244 | RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
245 | RCC_PeriphCLKInitTypeDef PeriphClkInit;
|
246 |
|
247 | /**Initializes the CPU, AHB and APB busses clocks
|
248 | */
|
249 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
250 | RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
251 | RCC_OscInitStruct.HSICalibrationValue = 16;
|
252 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
253 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
254 | RCC_OscInitStruct.PLL.PLLM = 1;
|
255 | RCC_OscInitStruct.PLL.PLLN = 10;
|
256 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
|
257 | RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
|
258 | RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
259 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
260 | {
|
261 | Error_Handler();
|
262 | }
|
263 |
|
264 | /**Initializes the CPU, AHB and APB busses clocks
|
265 | */
|
266 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
267 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
268 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
269 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
270 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
271 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
272 |
|
273 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
274 | {
|
275 | Error_Handler();
|
276 | }
|
277 |
|
278 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
279 | PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK;
|
280 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
281 | {
|
282 | Error_Handler();
|
283 | }
|
284 |
|
285 | /**Configure the main internal regulator output voltage
|
286 | */
|
287 | if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
|
288 | {
|
289 | Error_Handler();
|
290 | }
|
291 |
|
292 | /**Configure the Systick interrupt time
|
293 | */
|
294 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
|
295 |
|
296 | /**Configure the Systick
|
297 | */
|
298 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
299 |
|
300 | /* SysTick_IRQn interrupt configuration */
|
301 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
302 | }
|
303 |
|
304 | /* ADC1 init function */
|
305 | static void MX_ADC1_Init(void)
|
306 | {
|
307 |
|
308 | ADC_MultiModeTypeDef multimode;
|
309 | ADC_ChannelConfTypeDef sConfig;
|
310 |
|
311 | /**Common config
|
312 | */
|
313 | hadc1.Instance = ADC1;
|
314 | hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
|
315 | hadc1.Init.Resolution = ADC_RESOLUTION_12B;
|
316 | hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
317 | hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
318 | hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
|
319 | hadc1.Init.LowPowerAutoWait = DISABLE;
|
320 | hadc1.Init.ContinuousConvMode = DISABLE;
|
321 | hadc1.Init.NbrOfConversion = 1;
|
322 | hadc1.Init.DiscontinuousConvMode = DISABLE;
|
323 | hadc1.Init.NbrOfDiscConversion = 1;
|
324 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
325 | hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
326 | hadc1.Init.DMAContinuousRequests = ENABLE;
|
327 | hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
328 | hadc1.Init.OversamplingMode = DISABLE;
|
329 | if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
330 | {
|
331 | Error_Handler();
|
332 | }
|
333 |
|
334 | /**Configure the ADC multi-mode
|
335 | */
|
336 | multimode.Mode = ADC_MODE_INDEPENDENT;
|
337 | if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
|
338 | {
|
339 | Error_Handler();
|
340 | }
|
341 |
|
342 | /**Configure Regular Channel
|
343 | */
|
344 | sConfig.Channel = ADC_CHANNEL_1;
|
345 | sConfig.Rank = 1;
|
346 | sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
347 | sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
348 | sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
349 | sConfig.Offset = 0;
|
350 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
351 | {
|
352 | Error_Handler();
|
353 | }
|
354 |
|
355 | }
|
356 |
|
357 | /* TIM1 init function */
|
358 | static void MX_TIM1_Init(void)
|
359 | {
|
360 |
|
361 | TIM_MasterConfigTypeDef sMasterConfig;
|
362 | TIM_OC_InitTypeDef sConfigOC;
|
363 | TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
|
364 |
|
365 | htim1.Instance = TIM1;
|
366 | htim1.Init.Prescaler = 1;
|
367 | htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
368 | htim1.Init.Period = 8;
|
369 | htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
370 | htim1.Init.RepetitionCounter = 255;
|
371 | if (HAL_TIM_OC_Init(&htim1) != HAL_OK)
|
372 | {
|
373 | Error_Handler();
|
374 | }
|
375 |
|
376 | if (HAL_TIM_OnePulse_Init(&htim1, TIM_OPMODE_SINGLE) != HAL_OK)
|
377 | {
|
378 | Error_Handler();
|
379 | }
|
380 |
|
381 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
382 | sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
|
383 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
384 | if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
385 | {
|
386 | Error_Handler();
|
387 | }
|
388 |
|
389 | sConfigOC.OCMode = TIM_OCMODE_TIMING;
|
390 | sConfigOC.Pulse = 0;
|
391 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
392 | sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
393 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
394 | sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
395 | sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
396 | if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
397 | {
|
398 | Error_Handler();
|
399 | }
|
400 |
|
401 | if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
402 | {
|
403 | Error_Handler();
|
404 | }
|
405 |
|
406 | if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
|
407 | {
|
408 | Error_Handler();
|
409 | }
|
410 |
|
411 | if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
412 | {
|
413 | Error_Handler();
|
414 | }
|
415 |
|
416 | sConfigOC.Pulse = 8;
|
417 | if (HAL_TIM_OC_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_5) != HAL_OK)
|
418 | {
|
419 | Error_Handler();
|
420 | }
|
421 |
|
422 | sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
423 | sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
424 | sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
425 | sBreakDeadTimeConfig.DeadTime = 0;
|
426 | sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
427 | sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
428 | sBreakDeadTimeConfig.BreakFilter = 0;
|
429 | sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
|
430 | sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
|
431 | sBreakDeadTimeConfig.Break2Filter = 0;
|
432 | sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
433 | if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
|
434 | {
|
435 | Error_Handler();
|
436 | }
|
437 |
|
438 | HAL_TIM_MspPostInit(&htim1);
|
439 |
|
440 | }
|
441 |
|
442 | /* TIM2 init function */
|
443 | static void MX_TIM2_Init(void)
|
444 | {
|
445 |
|
446 | TIM_MasterConfigTypeDef sMasterConfig;
|
447 | TIM_OC_InitTypeDef sConfigOC;
|
448 |
|
449 | htim2.Instance = TIM2;
|
450 | htim2.Init.Prescaler = 0;
|
451 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
452 | htim2.Init.Period = 0;
|
453 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
454 | if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
|
455 | {
|
456 | Error_Handler();
|
457 | }
|
458 |
|
459 | if (HAL_TIM_OnePulse_Init(&htim2, TIM_OPMODE_SINGLE) != HAL_OK)
|
460 | {
|
461 | Error_Handler();
|
462 | }
|
463 |
|
464 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
465 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
466 | if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
|
467 | {
|
468 | Error_Handler();
|
469 | }
|
470 |
|
471 | sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
472 | sConfigOC.Pulse = 0;
|
473 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
474 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
475 | if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
476 | {
|
477 | Error_Handler();
|
478 | }
|
479 |
|
480 | if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
481 | {
|
482 | Error_Handler();
|
483 | }
|
484 |
|
485 | if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
|
486 | {
|
487 | Error_Handler();
|
488 | }
|
489 |
|
490 | if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
491 | {
|
492 | Error_Handler();
|
493 | }
|
494 |
|
495 | HAL_TIM_MspPostInit(&htim2);
|
496 |
|
497 | }
|
498 |
|
499 | /**
|
500 | * Enable DMA controller clock
|
501 | */
|
502 | static void MX_DMA_Init(void)
|
503 | {
|
504 | /* DMA controller clock enable */
|
505 | __HAL_RCC_DMA1_CLK_ENABLE();
|
506 |
|
507 | /* DMA interrupt init */
|
508 | /* DMA1_Channel1_IRQn interrupt configuration */
|
509 | HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0);
|
510 | HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
|
511 |
|
512 | }
|
513 |
|
514 | /** Configure pins as
|
515 | * Analog
|
516 | * Input
|
517 | * Output
|
518 | * EVENT_OUT
|
519 | * EXTI
|
520 | */
|
521 | static void MX_GPIO_Init(void)
|
522 | {
|
523 |
|
524 | GPIO_InitTypeDef GPIO_InitStruct;
|
525 |
|
526 | /* GPIO Ports Clock Enable */
|
527 | __HAL_RCC_GPIOC_CLK_ENABLE();
|
528 | __HAL_RCC_GPIOA_CLK_ENABLE();
|
529 | __HAL_RCC_GPIOB_CLK_ENABLE();
|
530 |
|
531 | /*Configure GPIO pin Output Level */
|
532 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|GPIO_PIN_5, GPIO_PIN_RESET);
|
533 |
|
534 | /*Configure GPIO pin : PC13 */
|
535 | GPIO_InitStruct.Pin = GPIO_PIN_13;
|
536 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
537 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
538 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
539 |
|
540 | /*Configure GPIO pins : PA0 PA5 */
|
541 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_5;
|
542 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
543 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
544 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
545 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
546 |
|
547 | /*Configure GPIO pin : PC12 */
|
548 | GPIO_InitStruct.Pin = GPIO_PIN_12;
|
549 | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
550 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
551 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
552 |
|
553 | }
|
554 |
|
555 | /* USER CODE BEGIN 4 */
|
556 |
|
557 | /* USER CODE END 4 */
|
558 |
|
559 | /**
|
560 | * @brief This function is executed in case of error occurrence.
|
561 | * @param None
|
562 | * @retval None
|
563 | */
|
564 | void Error_Handler(void)
|
565 | {
|
566 | /* USER CODE BEGIN Error_Handler */
|
567 | /* User can add his own implementation to report the HAL error return state */
|
568 | while(1)
|
569 | {
|
570 | }
|
571 | /* USER CODE END Error_Handler */
|
572 | }
|
573 |
|
574 | #ifdef USE_FULL_ASSERT
|
575 |
|
576 | /**
|
577 | * @brief Reports the name of the source file and the source line number
|
578 | * where the assert_param error has occurred.
|
579 | * @param file: pointer to the source file name
|
580 | * @param line: assert_param error line source number
|
581 | * @retval None
|
582 | */
|
583 | void assert_failed(uint8_t* file, uint32_t line)
|
584 | {
|
585 | /* USER CODE BEGIN 6 */
|
586 | /* User can add his own implementation to report the file name and line number,
|
587 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
588 | /* USER CODE END 6 */
|
589 |
|
590 | }
|
591 |
|
592 | #endif
|
593 |
|
594 | /**
|
595 | * @}
|
596 | */
|
597 |
|
598 | /**
|
599 | * @}
|
600 | */
|
601 |
|
602 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|