导航

    全志在线开发者论坛

    • 注册
    • 登录
    • 搜索
    • 版块
    • 话题
    • 在线文档
    • 社区主页

    T507 PWM互补输出

    T Series
    2
    2
    37
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • Y
      yozad LV 3 最后由 编辑

      需求:全志T507,把PI12、PI13复用为PWM2、PWM3,想要让PWM2、3互补输出。

      T507手册上支持pwm互补输出
      2125f226-ffb3-430f-89fb-ee35982f81a1-image.png

      看源码需要在设备树里面配置"bind_pwm"和"dead_time",获取死区时间和“互补输出绑定的pwm??”,这里的bind_pwm不是很理解。

      static int sunxi_pwm_get_config(struct platform_device *pdev, struct sunxi_pwm_config *config)
      {
      	struct device_node *np = pdev->dev.of_node;
      	int ret = 0;
      
      	/* read register config */
      	pr_info("sunxi_pwm_get_config %s\n", np->name);
      
      	ret = of_property_read_u32(np, "bind_pwm", &config->bind_pwm);
      	if (ret < 0) {
      		/*if there is no bind pwm,set 255, dual pwm invalid!*/
      		config->bind_pwm = 255;
      		ret = 0;
      	}
      
      	ret = of_property_read_u32(np, "dead_time", &config->dead_time);
      	if (ret < 0) {
      		/*if there is  bind pwm, but not set dead time,set bind pwm 255,dual pwm invalid!*/
      		config->bind_pwm = 255;
      		ret = 0;
      	}
      
      	pr_info("bind_pwm=%d,dead_time=%d\n", config->bind_pwm, config->dead_time);
      	ret = of_property_read_u32(np, "clk_bypass_output", &config->clk_bypass_output);
      	if (ret < 0) {
      		/*if use pwm as the internal clock source!*/
      		config->clk_bypass_output = 0;
      		ret = 0;
      	}
      
      	of_node_put(np);
      
      	return ret;
      }
      
      static int sunxi_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
      		int duty_ns, int period_ns)
      {
      	int bind_num;
      
      	struct sunxi_pwm_chip *pc = to_sunxi_pwm_chip(chip);
      
              //这里可以根据bind_num选择是否互补输出
      	bind_num = pc->config[pwm->pwm - chip->base].bind_pwm;
      	if (bind_num == 255)
      		sunxi_pwm_config_single(chip, pwm, duty_ns, period_ns);
      	else
      		sunxi_pwm_config_dual(chip, pwm, duty_ns, period_ns, bind_num);
      
      	return 0;
      }
      

      但是按照源码里面增加“bind_pwm”和“dead_time”

      		pwm2: pwm2@0300a000 {
      			pinctrl-names = "active", "sleep";
      			pinctrl-0 = <&pwm2_pin_a>;
      			pinctrl-1 = <&pwm2_pin_b>;
      			bind_pwm = 2;
      			dead_time = 1000;
      			status = "okay";
      		};
      

      编译报错

      Error: arch/arm64/boot/dts/sunxi/CII-Common.dtsi:543.15-16 syntax error
      FATAL ERROR: Unable to parse input tree
      make[2]: *** [scripts/Makefile.lib:313: arch/arm64/boot/dts/sunxi/board.dtb] Error 1
      make[1]: *** [scripts/Makefile.build:648: arch/arm64/boot/dts/sunxi] Error 2
      make: *** [arch/arm64/Makefile:153: dtbs] Error 2
      make: *** Waiting for unfinished jobs....
        CHK     kernel/config_data.h
      ERROR: build kernel Failed
      INFO: mkkernel failed
      

      请问怎么配置才能让pwm互补输出?

      J 1 条回复 最后回复 回复 引用 分享 0
      • J
        jasonzhang LV 5 @yozad 最后由 编辑

        @yozad d 设备树里面定义u32的数据格式时 key = <value>;
        按照要求应该是
        bind_pwm = <2>;
        dead_time = <1000>;
        你的写法不正确。

        1 条回复 最后回复 回复 引用 分享 0
        • 1 / 1
        • First post
          Last post

        Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

        行为准则 | 用户协议 | 隐私权政策