嵌入式技术论坛
直播中

chumowei

8年用户 703经验值
擅长:电源/新能源
私信 关注
[经验]

如何解决RT-Thread studio里面的PWM驱动提示有误的问题

一、原本的提示如下

/** if you want to use pwm you can use the following instructions.
*

  • STEP 1, open pwm driver framework support in the RT-Thread Settings file
  • STEP 2, define macro related to the pwm
  • such as #define BSP_USING_PWM1
  • STEP 3, copy your pwm timer init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end if board.c file
  • such as void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) and
  • void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
  • STEP 4, modify your stm32xxxx_hal_config.h file to support pwm peripherals. define macro related to the peripherals
  • such as #define HAL_TIM_MODULE_ENABLED

/
需要把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跑流水灯

更多回帖

发帖
×
20
完善资料,
赚取积分