DT_ALIAS issue

i have these aliases setup in the .dts file.

aliases {
        red_led         = &led0;
        grn_led         = &led1;
        blu_led         = &led2;
//      led3            = &led3;
//      watchdog0       = &wdt0;
//      mcuboot-led0    = &led0;
//      bootloader-led0 = &led0;
      sw0             = &button0;
//      sw1             = &button1;
//      sw2             = &button2;
//      sw3             = &button3;
//      mcuboot-button0 = &button0;
        red_pwm         = &pwm_led0;
        grn_pwm         = &pwm_led1;
        blu_pwm         = &pwm_led2;
    };
};
so why is this ok
#define SW0_BUTTON           DT_ALIAS(sw0)
#if !DT_NODE_HAS_STATUS(SW0_BUTTON, okay)
#error "Unsupported board: sw0 devicetree alias is not defined"
#endif
 
but this fails compilation with the error "Unsupported board: pwm_led devicetree alias is not defined" ?
#define PWM_RED_LED        DT_ALIAS(red_pwm)
#if !DT_NODE_HAS_STATUS(PWM_RED_LED, okay)
#error "Unsupported board: pwm_led devicetree alias is not defined"
#endif


Parents
  • Hi,

    Using underscore in devicetree aliases is not allowed. Instead, you should use a hyphen (-):

    aliases {
            red-led         = &led0;
            grn-led         = &led1;
            blu-led         = &led2;
            ...
            red-pwm         = &pwm_led0;
            grn-pwm         = &pwm_led1;
            blu-pwm         = &pwm_led2;
        };
    };

    In DT_ALIAS you should still use underscore:

    #define PWM_RED_LED  DT_ALIAS(red_pwm)

    Best regards,
    Marte

  • so change it to this

        aliases {
            red-led         = &led0;
            grn-led         = &led1;
            blu-led         = &led2;
            red-pwm         = &pwm_led0;
            grn-pwm         = &pwm_led1;
            blu-pwm         = &pwm_led2;
        };
    this check still fails at compile time
    #define PWM_RED_LED DT_ALIAS(red_pwm)
    #if !DT_NODE_HAS_STATUS(PWM_RED_LED, okay)
    #error "Unsupported board: pwm_led devicetree alias is not defined"
    #endif
    c:\Users\IMS_DEV\Documents\vscode\cdc_acm_composite\src\led.c:18:2: error: #error "Unsupported board: pwm_led devicetree alias is not defined"
    18 | #error "Unsupported board: pwm_led devicetree alias is not defined"
    | ^~~~~
Reply
  • so change it to this

        aliases {
            red-led         = &led0;
            grn-led         = &led1;
            blu-led         = &led2;
            red-pwm         = &pwm_led0;
            grn-pwm         = &pwm_led1;
            blu-pwm         = &pwm_led2;
        };
    this check still fails at compile time
    #define PWM_RED_LED DT_ALIAS(red_pwm)
    #if !DT_NODE_HAS_STATUS(PWM_RED_LED, okay)
    #error "Unsupported board: pwm_led devicetree alias is not defined"
    #endif
    c:\Users\IMS_DEV\Documents\vscode\cdc_acm_composite\src\led.c:18:2: error: #error "Unsupported board: pwm_led devicetree alias is not defined"
    18 | #error "Unsupported board: pwm_led devicetree alias is not defined"
    | ^~~~~
Children
Related