39 #include "stm32f4xx_hal.h" 152 RCC_OscInitTypeDef RCC_OscInitStruct;
153 RCC_ClkInitTypeDef RCC_ClkInitStruct;
157 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
159 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
160 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
161 RCC_OscInitStruct.HSICalibrationValue = 6;
162 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
163 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
164 RCC_OscInitStruct.PLL.PLLM = 16;
165 RCC_OscInitStruct.PLL.PLLN = 336;
166 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
167 RCC_OscInitStruct.PLL.PLLQ = 7;
168 HAL_RCC_OscConfig(&RCC_OscInitStruct);
170 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
171 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
172 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
173 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
174 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
175 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
183 ADC_ChannelConfTypeDef sConfig;
187 hadc1.Instance = ADC1;
188 hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
189 hadc1.Init.Resolution = ADC_RESOLUTION12b;
190 hadc1.Init.ScanConvMode = DISABLE;
191 hadc1.Init.ContinuousConvMode = DISABLE;
192 hadc1.Init.DiscontinuousConvMode = DISABLE;
193 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
194 hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO;
195 hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
196 hadc1.Init.NbrOfConversion = 1;
197 hadc1.Init.DMAContinuousRequests = DISABLE;
198 hadc1.Init.EOCSelection = EOC_SINGLE_CONV;
199 HAL_ADC_Init(&
hadc1);
203 sConfig.Channel = ADC_CHANNEL_2;
205 sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
206 HAL_ADC_ConfigChannel(&
hadc1, &sConfig);
215 TIM_OC_InitTypeDef sConfig;
216 TIM_SlaveConfigTypeDef sSlaveConfig;
217 TIM_MasterConfigTypeDef sMasterConfig;
226 htim1.Instance = TIM1;
228 htim1.Init.Period = 839;
229 htim1.Init.Prescaler = 0;
230 htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
231 htim1.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED1;
232 htim1.Init.RepetitionCounter = 0;
234 HAL_TIM_PWM_Init(&
htim1) ;
237 sSlaveConfig.SlaveMode = TIM_SLAVEMODE_TRIGGER;
238 sSlaveConfig.InputTrigger = TIM_TS_ITR3;
239 HAL_TIM_SlaveConfigSynchronization(&
htim1, &sSlaveConfig);
241 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
242 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
243 HAL_TIMEx_MasterConfigSynchronization(&
htim1, &sMasterConfig);
247 sConfig.OCMode = TIM_OCMODE_PWM2;
248 sConfig.OCFastMode = TIM_OCFAST_DISABLE;
249 sConfig.OCPolarity = TIM_OCPOLARITY_LOW;
250 sConfig.OCNPolarity = TIM_OCNPOLARITY_LOW;
251 sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
252 sConfig.OCNIdleState= TIM_OCNIDLESTATE_RESET;
256 HAL_TIM_PWM_ConfigChannel(&
htim1, &sConfig, TIM_CHANNEL_1) ;
259 HAL_TIM_PWM_ConfigChannel(&
htim1, &sConfig, TIM_CHANNEL_2) ;
262 HAL_TIM_PWM_ConfigChannel(&
htim1, &sConfig, TIM_CHANNEL_3) ;
274 TIM_SlaveConfigTypeDef sSlaveConfig;
275 TIM_MasterConfigTypeDef sMasterConfig;
276 TIM_OC_InitTypeDef sConfigOC;
278 htim3.Instance = TIM3;
279 htim3.Init.Prescaler = 0;
280 htim3.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED1;
281 htim3.Init.Period = 839;
282 htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
283 HAL_TIM_Base_Init(&
htim3);
285 HAL_TIM_PWM_Init(&
htim3);
287 sSlaveConfig.SlaveMode = TIM_SLAVEMODE_TRIGGER;
288 sSlaveConfig.InputTrigger = TIM_TS_ITR3;
289 HAL_TIM_SlaveConfigSynchronization(&
htim3, &sSlaveConfig);
291 sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
292 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;
293 HAL_TIMEx_MasterConfigSynchronization(&
htim3, &sMasterConfig);
295 sConfigOC.OCMode = TIM_OCMODE_PWM1;
296 sConfigOC.Pulse = 671;
297 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
298 sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
299 HAL_TIM_PWM_ConfigChannel(&
htim3, &sConfigOC, TIM_CHANNEL_1);
307 TIM_ClockConfigTypeDef sClockSourceConfig;
308 TIM_MasterConfigTypeDef sMasterConfig;
310 htim4.Instance = TIM4;
311 htim4.Init.Prescaler = 0;
312 htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
313 htim4.Init.Period = 24000;
314 htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
315 HAL_TIM_Base_Init(&
htim4);
317 sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
318 HAL_TIM_ConfigClockSource(&
htim4, &sClockSourceConfig);
320 sMasterConfig.MasterOutputTrigger = TIM_TRGO_ENABLE;
321 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;
322 HAL_TIMEx_MasterConfigSynchronization(&
htim4, &sMasterConfig);
331 huart2.Init.BaudRate = 19200;
332 huart2.Init.WordLength = UART_WORDLENGTH_9B;
333 huart2.Init.StopBits = UART_STOPBITS_1;
334 huart2.Init.Parity = UART_PARITY_ODD;
335 huart2.Init.Mode = UART_MODE_TX_RX;
336 huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
337 huart2.Init.OverSampling = UART_OVERSAMPLING_16;
348 #ifdef USE_FULL_ASSERT 357 void assert_failed(uint8_t* file, uint32_t line)
static void MX_TIM4_Init(void)
static void MX_ADC1_Init(void)
UART_HandleTypeDef huart2
void SystemClock_Config(void)
System Clock Configuration.
static void MX_TIM1_Init(void)
static void MX_TIM3_Init(void)
This header file provides the set of functions for Motor Control library.
void MC_SixStep_INIT(void)
static void MX_USART2_UART_Init(void)