Issues with custom board files & simple peripherals.

I'm bringing up a custom board, working through the peripherals one at a time. Unfortunately, I haven't gotten very far before things started misbehaving. One part of the design will be an RGB status LED, with PWM for colour & intensity. Here's a snippet which should work as far as I can see. I'm able to drive the individual LEDs fine, but the PWM will not work at all. Note - LEDs are active low, if relevant.

Source Code
------------------
#if PWM_TEST == 1
        #define PWM_PERIOD_NS   20000000
        #define PWM_PULSE_NS    10000000
        #define PWM_GREEN       DT_ALIAS(pwmgreen)
        static const struct pwm_dt_spec pwm_green = PWM_DT_SPEC_GET(PWM_GREEN);
#endif

int main() {
#if PWM_TEST == 1
  if (!pwm_is_ready_dt(&pwm_green)) {
                LOG_ERR("Error: PWM device %s is not ready\n", pwm_green.dev->name);
                return 0;
        }

        int err = pwm_set_dt(&pwm_green, PWM_PERIOD_NS, PWM_PULSE_NS);
        if (err) {
                LOG_ERR("Error in pwm_set_dt(), err: %d", err);
                return 0;
        }
#endif
}
DTS
-------
leds {
        compatible = "gpio-leds"; // generic compatible

        ledred: led_red {
            gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;
            label = "Red LED";
        };

        ledgreen: led_green {
            gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
            label = "Green LED";
        };

        ledblue: led_blue {
            gpios = <&gpio0 1 GPIO_ACTIVE_LOW>;
            label = "Blue LED";
        };

        vccswen: vcc_sw_en {
            gpios = <&gpio0 31 GPIO_ACTIVE_LOW>;
            label = "VCC Switch Enable";
        };
    };

    pwmleds {
        compatible = "pwm-leds";

        pwm_led0: pwm_led_0 {
            pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
        };

        pwm_led1: pwm_led_1 {
            pwms = <&pwm0 1 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
        };

        pwm_led2: pwm_led_2 {
            pwms = <&pwm0 2 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
        };
    };

aliases {

        ledred = &ledred;
        ledgreen = &ledgreen;
        ledblue = &ledblue;
        vccswen = &vccswen;
        pwmled0 = &pwm_led0;
        pwmred = &pwm_led0;
        pwmgreen = &pwm_led2;
        pwmblue = &pwm_led1;
        mode = &button_mode;

        watchdog0 = &wdt0;
    };
 
proj.conf
------------
...
CONFIG_PWM=y
CONFIG_PWM_LOG_LEVEL_DBG=y

CONFIG_LED=y
CONFIG_LED_PWM=y
Parents Reply
  • The dev academy course is great. But it only has a single PWM channel in the example - so didn't address the aspect that was confusing me (I appreciate that it's on me to learn how device tree works though). Is dev academy the only nrf connect specific resource for developers, or would you recommend other resources? It's all a bit new, but I'm keen to read around as much as possible. 

Children
No Data
Related