stm32f103标准库+RT-Thread操作系统实现PWM驱动---1

本文档详细介绍了如何使用STM32F103的标准库配合RT-Thread操作系统来实现PWM驱动,包括配置、驱动代码和错误检查。目前该驱动不支持TIM1和TIM8,但支持其他定时器通道的配置。通过示波器验证了驱动的正确性。
摘要由CSDN通过智能技术生成

 

 

转载请注明:https://mp.csdn.net/postedit/84571003

经过一天的实践,将基于标准库+RT-Thread的pwm驱动写完并通过示波器验证,此驱动目前不支持TIM1和TIM8,其他的定时器通道可以在rtconfig.h文件中配置,然后再在驱动文件中加上配置,此驱动目前只实现了TIM3的四个通道

 

typedef struct
{
  TIM_TypeDef                     *Instance;     /*!< Register base address             */
  TIM_TimeBaseInitTypeDef         Init;          /*!< TIM Time Base required parameters */
  uint16_t                       Channel;       /*!< Active channel                    */
}TIM_HandleTypeDef;


static rt_err_t drv_pwm_control(struct rt_device_pwm *device, int cmd, void *arg);
static struct rt_pwm_ops drv_ops =
{
    drv_pwm_control
};

static rt_err_t drv_pwm_enable(TIM_TypeDef *htim, struct rt_pwm_configuration *configuration, rt_bool_t enable)
{
    if((htim == TIM1) || (htim == TIM8))
    {
        rt_kprintf("The TIMX error\n");
        return RT_ERROR;
    }
    if((configuration->channel != TIM_Channel_1) && (configuration->channel != TIM_Channel_2) && 
        (configuration->channel != TIM_Channel_3) && (configuration->channel != TIM_Channel_4))
    {
        rt_kprintf("The TIMX Chx %d error\n",configuration->channel);
        return RT_ERROR;
    }
    if(enable)
    {
      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值