Pinctrl and PWM

Does anyone have an example of using pinctrl and pwm on a Nordic device using Zephyr for a motor driver or something like that?

All the examples appear to NOT use the pinctrl, even though there are messages all over that not using pinctrl is deprecated. Also, they all seem to use pwm-leds, which appears to duplicate the pinctrl information and make pinctrl basically worthless. 

In particular, if I set things up like this:

&pinctrl {
/* boost pwm drive pin */
boost_pwm_default: boost_pwm_default {
group1 {
// Put boost drive output onto LED1 for now
psels = <NRF_PSEL(PWM_OUT0, 0, 14)>;
};
};
/* make sure sleeping does not alter pinout */
boost_pwm_sleep: boost_pwm_sleep {
group1 {
// Put boost drive output onto LED1 for now
psels = <NRF_PSEL(PWM_OUT0, 0, 14)>;
};
};

};

// Get this using a dt label of boostpwm
boostpwm: &pwm0 {
status = "okay";
pinctrl-0 = <&boost_pwm_default>;
pinctrl-1 = <&boost_pwm_sleep>; // make sure sleeping does not change pinout
};

How do I call pwm_pin_set_cycles()? I need to provide it a device controller, a pin, and flags. All the examples use macros that
go through pwm-leds, like DT_PWMS_CTLR, DT_PWMS_CHANNEL and DT_PWMS_FLAGS. But these macros don't appear to work without pwm-leds.
Are there equivalent macros using pinctrl?

Or should I be using a different API?


  • Hi there,

    Where is it stated that not using pinctrl is deprecated? Maybe you could try to use DEVICE_DT_GET(PWM_DEV_NODE) as in this example?

    regards

    Jared 

  • In zephyr/dts/bindings/pwm/nordic,nrf-pwm.yaml:

    ch0-pin:
    type: int
    required: false
    description: |
    IMPORTANT: This option will only be used if the new pin control driver
    is not enabled. It will be deprecated in the future.

    Note that this phrase:

    IMPORTANT: This option will only be used if the new pin control driver
    is not enabled. It will be deprecated in the future.

    Is in lots of other nordic yaml files. I assume the word IMPORTANT means its important NOW. 

    Also, when I try to define things without pinctrl, I get a warning that pinctrl is on so I MUST use it. I did not turn pinctrl on in my config file. It appears that the file nrf52840dk_nrf52840_defconfig has CONFIG_PINCTRL=y. So Nordic is essentially forcing us to use pinctrl at this point.

  • Oh, and looking at that example you mentioned, which is actually just a pwm test, I see this comment:

    /* Default port should be adapted per board to fit the channel
     * associated to the PWM pin. For intsance, for following device,
     *      pwm1: pwm {
     *              status = "okay";
     *              pinctrl-0 = <&tim1_ch3_pe13>;
     *      };
     * the following should be used:
     * #define DEFAULT_PWM_PORT 3
     */

    There are a ton of ifdefs here too. In other words, even the test file is not using pinctrl to define the pwm pin, but rather testing for a specific #define and then manually setting the pin.

    Again I ask, what is the point of pinctrl if you have to redefine the exact same pin elsewhere. It actually makes things worse because now you MUST define the same pin in two different places and keep them synchronized if something changes.

     

Related