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

时间:2016-04-02 20:32:36

标签: embedded-linux beagleboneblack device-tree pwm

我知道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的非平凡覆盖。

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

1 个答案:

答案 0 :(得分:0)

I inspected the overlay used for the 3D printer cape and made some changes. The new overlay works, and even creates the pwm folders with custom names instead of just P9_16_PWM lie the default.

/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?
                };
            };
        };
    };
};

Still unsure about what a few lines do but it works so our project can move forward. Answering my own question so that maybe this will help someone else out there.