STM32L151 stm32cubemx ETR
配置如图:
实际生成代码:
/
tiM2 init function /void MX_TIM2_Init(void){
/ USER CODE BEGIN TIM2_Init 0 /
/ USER CODE END TIM2_Init 0 /
TIM_ClockConfigTypeDef sClockSourceConfig = {0};TIM_MasterConfigTypeDef sMasterConfig = {0};
/ USER CODE BEGIN TIM2_Init 1 /
/ USER CODE END TIM2_Init 1 /htim2.Instance = TIM2;htim2.Init.Prescaler = 0;htim2.Init.CounterMode = TIM_COUNTERMODE_UP;htim2.Init.Period = 79;htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4;htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;if (HAL_TIM_Base_Init( htim2) != HAL_OK){Error_Handler();}sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_ETRMODE2;sClockSourceConfig.ClockPolarity = TIM_CLOCKPOLARITY_INVERTED;sClockSourceConfig.ClockPrescaler = TIM_CLOCKPRESCALER_DIV1;sClockSourceConfig.ClockFilter = 0;if (HAL_TIM_ConfigClockSource( htim2, sClockSourceConfig) != HAL_OK){Error_Handler();}sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;if (HAL_TIMEx_MasterConfigSynchronization( htim2, sMasterConfig) != HAL_OK){Error_Handler();}/ USER CODE BEGIN TIM2_Init 2 /
/ USER CODE END TIM2_Init 2 /
}
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle){
GPIO_InitTypeDef GPIO_InitStruct = {0};if(tim_baseHandle->Instance==TIM2){/ USER CODE BEGIN TIM2_MspInit 0 /
/ USER CODE END TIM2_MspInit 0 // TIM2 clock enable /__HAL_RCC_TIM2_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();/*TIM2 GPIO ConfigurationPA0-WKUP1 ------> TIM2_ETR/GPIO_InitStruct.Pin = GPIO_PIN_0;GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;GPIO_InitStruct.Pull = GPIO_PULLUP;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOA, GPIO_InitStruct);
/ TIM2 interrupt Init /HAL_NVIC_SetPriority(TIM2_IRQn, 1, 0);HAL_NVIC_EnableIRQ(TIM2_IRQn);/ USER CODE BEGIN TIM2_MspInit 1 /GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;HAL_GPIO_Init(GPIOA, GPIO_InitStruct);/ USER CODE END TIM2_MspInit 1 /}}
回帖(1)
2024-3-8 10:45:25
是使用STM32CubeMX复用功能没有打开
是使用STM32CubeMX复用功能没有打开
举报
更多回帖