一、原本的提示如下
/** if you want to use pwm you can use the following instructions.
*
/
需要把void HAL_TIM_Base_MspInit(TIM_HandleTypeDef htim_base);
改成void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle);
并且要打开通道的宏#define BSP_USING_PWM3_CH1
board.c
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle)
{
if (tim_pwmHandle->Instance == TIM3)
{
/* USER CODE BEGIN TIM3_MspInit 0 /
/ USER CODE END TIM3_MspInit 0 /
/ TIM3 clock enable /
__HAL_RCC_TIM3_CLK_ENABLE()
;
/ USER CODE BEGIN TIM3_MspInit 1 /
/ USER CODE END TIM3_MspInit 1 /
}
}
void HAL_TIM_MspPostInit(TIM_HandleTypeDef timHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(timHandle->Instance==TIM3)
{
/* USER CODE BEGIN TIM3_MspPostInit 0 /
/ USER CODE END TIM3_MspPostInit 0 */
__HAL_RCC_GPIOB_CLK_ENABLE();
/**TIM3 GPIO Configuration
PB4 ------> TIM3_CH1
/
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/ USER CODE BEGIN TIM3_MspPostInit 1 /
/ USER CODE END TIM3_MspPostInit 1 */
}
}
原作者:用RTT跑流水灯
更多回帖