1、修改stm32 pwm 驱动文件drv_pwm.c 的 drv_pwm_enable 函数:
static rt_err_t drv_pwm_enable(TIM_HandleTypeDef *htim, struct rt_pwm_configuration *configuration, rt_bool_t enable)
{
rt_uint32_t channel = 0x04 * (configuration->channel - 1);
if (!enable)
{
#ifdef BSP_USING_PWM1_CH1xN
HAL_TIMEx_PWMN_Stop(htim, channel);
#else
HAL_TIM_PWM_Stop(htim, channel);
#endif
}
else
{
#ifdef BSP_USING_PWM1_CH1xN
HAL_TIMEx_PWMN_Start(htim, channel);
#else
HAL_TIM_PWM_Start(htim, channel);
#endif
}
return RT_EOK;
}
2、修改Kconfig 文件,增加:
config BSP_USING_PWM1_CH1
bool "Enable pwm1 output"
default n
select RT_USING_PWM
select BSP_USING_PWM1
if BSP_USING_PWM1_CH1
config BSP_USING_PWM1_CH1xN
bool "Enable pwm CH1xN channel"
default n
endif
注意:
Kconfig文件修改时按照实际的通道做修改
记得在ST的CubeMx工具中做对应的引脚配置。
原作者:emlsyx
|