如何在设备树覆盖中设置 PWM 周期

How can I set the PWM period in a device tree overlay

我知道 PWM1A 和 PWM1B 必须具有相同的周期,但使用默认覆盖阻止我在加载后更改周期。我认为在一个叠加层中同时加载两个引脚可能会解决这个问题,让我可以在它们混合时为它们设置周期。我正在尝试将伺服连接到 P9_16 和 P9_14(EHRPWM1A 和 EHRPWM1B),因此它们都需要相同的周期,但在默认覆盖层中不是 5000us。

这是我目前的覆盖图:

/dts-v1/;
/plugin/;

/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black";

    /* identification */
    part-number = "car_pwm_controls";
    version = "00A0";

    /* state the resources this cape uses */
    exclusive-use =
      /* the pin header uses */
      "P9.14",    /* pwm: ehrpwm1A - STEERING */
      "P9.16",                /* pwm: ehrpwm1B - MOTOR */
      /* the hardware IP uses */
      "ehrpwm1A",
      "ehrpwm1B";

  fragment@0 {
    target = <&am33xx_pinmux>;
    __overlay__ {
      car_pwm_controls_pins: pinmux_pwm_controls_pins {
        pinctrl-single,pins = <
            0x048  0x6 /* P9_14 (ZCZ ball U14) | MODE 6 */
            0x04c  0x6 /* P9_16 (ZCZ ball T14) | MODE 6 */
        >;
      };
    };
  };

    fragment@1 {
        target = <&ocp>;
        __overlay__ {
            car_pwm_helper {
                 compatible  = "pwm_test";
                 pinctrl-names = "default";
                 pinctrl-0 = <&car_pwm_controls_pins>;

                 car_motor {
                   pwms    = <&ehrpwm1 0 20000000 1>;
                   pwm-names   = "PWM_P9_14";
                   enabled   = <1>;
                   duty    = <0>;
                   status    = "okay";
                 };

                 car_steering {
                   pwms    = <&ehrpwm1 1 20000000 1>;
                   pwm-names   = "PWM_P9_16";
                   enabled   = <1>;
                   duty    = <0>;
                   status    = "okay";
                 };
             };
        };
  };

};

我真的不确定第二部分(fragment1),这是我第一次写一个不仅仅是一个引脚或简单 gpio 的非平凡覆盖。

我已经看到了两个答案 here and 但我很好奇如何使用叠加层来完成这项工作,这是否是更好的解决方案?主要问题是虽然这个覆盖编译它不会加载并且不会设置 PWM 引脚。

我检查了 overlay used for the 3D printer cape 并做了一些修改。新的叠加层有效,甚至可以使用自定义名称创建 pwm 文件夹,而不仅仅是 P9_16_PWM 默认值。

/dts-v1/;
/plugin/;

/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black";

    /* identification */
    part-number = "CAR_CONTROLS";
    version = "00A0";

    /* state the resources this cape uses */
    exclusive-use =
        /* the pin header uses */
        "P9.14",        /* pwm: ehrpwm1A - STEERING */
                "P9.16",                /* pwm: ehrpwm1B - MOTOR */
        /* the hardware IP uses */
        "ehrpwm1A",
                "ehrpwm1B";

    // Each PWM pin is it's own node, even though they are on the same module
    fragment@0 {
        target = <&am33xx_pinmux>;
        __overlay__ {
            car_steering_pins: pinmux_car_steering_pins {  // STEERING PIN
                pinctrl-single,pins = <0x048  0x6>;    /* P9_14 (ZCZ ball U14) | MODE 6 */
            };
                        car_motor_pins: pinmux_car_motor_pins {      // MOTOR CONTROL PIN
                                pinctrl-single,pins = <0x04c  0x6>;  /* P9_16 (ZCZ ball T14) | MODE 6 */
            };
        };
    };

    fragment@1 {
        target = <&ocp>;
        __overlay__ {
            car_pwm_helper {
                car_steering {      // Directory Will Be Called this
                    compatible  = "pwm_test";   // unknown ???
                    pinctrl-names   = "default";    // unknown ???
                    pinctrl-0   = <&car_steering_pins>;
                    pwms        = <&ehrpwm1 0 20000000 1>;  // Module 0 at 20MHz ... unsure what last 1 is?
                    pwm-names   = "STEER_P9_14";
                    enabled     = <1>;      // enable plz
                    polarity        = <0>;      // 0=normal, 1=inverse
                    duty        = <0>;      // initial duty
                    status      = "okay";   // be ok plz?
                };
                car_motor {     // Directory will be called this
                    compatible  = "pwm_test";
                    pinctrl-names   = "default";
                    pinctrl-0   = <&car_motor_pins>;
                    pwms        = <&ehrpwm1 1 20000000 1>;  // Module 1 at 20MHz ... unsure what last 1 is?
                    pwm-names   = "MOTOR_P9_16";
                    enabled     = <1>;      // enable plz
                    polarity        = <0>;      // 0=normal, 1=inverse
                    duty        = <0>;      // initial duty
                    status      = "okay";   // be ok plz?
                };
            };
        };
    };
};

仍然不确定几行的作用,但它起作用了,所以我们的项目可以向前推进。回答我自己的问题,这样也许这会对那里的其他人有所帮助。