error: 'DT_N_S_pwmleds_S_pwm_led_0_P_gpios_IDX_0_PH_P_label' undeclared

Hello,

I am trying to use PWM to control two LEDS, one red and one green (referred to as blueled in the code) to produce different colours. I have had a look at the example _fade-led-sample provided by Nordic and based my changes on this. However, I am seeing some errors when I try to build my project in Segger Embedded Studio. 

9> zephyr/include/generated/devicetree_unfixed.h:1949:33: error: 'DT_N_S_pwmleds_S_pwm_led_0_P_gpios_IDX_0_PH_P_label' undeclared (first use in this function); did you mean 'DT_N_S_pwmleds_S_pwm_led_0_P_pwms_IDX_0_VAL_channel'?
9> zephyr/include/generated/devicetree_unfixed.h:1949:33: error: 'DT_N_S_pwmleds_S_pwm_led_0_P_gpios_IDX_0_VAL_pin' undeclared (first use in this function); did you mean 'DT_N_S_leds_S_led_0_P_gpios_IDX_0_VAL_pin'?
9> zephyr/include/generated/devicetree_unfixed.h:2002:33: error: 'DT_N_S_pwmleds_S_pwm_led_1_P_gpios_IDX_0_PH_P_label' undeclared (first use in this function); did you mean 'DT_N_S_pwmleds_S_pwm_led_1_P_pwms_IDX_0_PH'?
9> zephyr/include/generated/devicetree_unfixed.h:2002:33: error: 'DT_N_S_pwmleds_S_pwm_led_1_P_gpios_IDX_0_VAL_pin' undeclared (first use in this function); did you mean 'DT_N_S_leds_S_led_1_P_gpios_IDX_0_VAL_pin'?

Note, I am using the following development environment.

- Zephyr OS build v2.6.99-ncs1

- SEGGER Embedded Studio for ARM
  Release 5.60  Build 2021081102.47262
  Nordic Edition
  Windows x64

I am attaching the build error logs, my overlay file and snippets of my C code. The file prj.conf contains the line CONFIG_PWM=y.

Thank you for your help.

0676.nrf52833dk_nrf52833.overlay

#include <stdio.h>
#include <zephyr.h>
#include <arch/cpu.h>
#include <sys/printk.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>
#include <drivers/pwm.h>
#include <drivers/i2c.h>
#include <drivers/spi.h>
#include <drivers/adc.h>
#include <logging/log.h>
#include <logging/log_ctrl.h>
[snip]
...

#define PWM_OFF                                     (0U)
#define PWM_PERCENTAGE_ORANGE                       (23U)

#define LED_TEST                                    0
#define FADING_TEST                                 1

static result_t io_PWM_initialise (uint8_t percentage);
static void pwm_stop(void);
//static void registers_read(void);
//static void LED_test(void);
static void fading_test(void);

/*
    -----------------------------------------------------------------------------------------------------
    !GLOBAL VARIABLES
    -----------------------------------------------------------------------------------------------------
*/
//Leds
const struct device *io_redled_dev;
const struct device *io_blueled_dev;
const struct device *pwm_dev;

[snip]
...

///////////////////////////////////////////////////////////////////////////////
void io_led_initialise(void)
{
    uint8_t ret;

    /* Initialise IO ports attached to the LEDs */
    io_redled_dev = device_get_binding( DT_GPIO_LABEL(DT_ALIAS( redled ), gpios ) );
    if ( io_redled_dev )
    {
        ret = gpio_pin_configure( io_redled_dev,
                                  DT_GPIO_PIN( DT_ALIAS( redled ), gpios ),
                                  GPIO_OUTPUT_INACTIVE | DT_GPIO_FLAGS( DT_ALIAS(redled ), gpios ) );
        if ( ret )
        {
            LOG_ERR( "RedLed not configured" );
        }
    }
    else
    {
        LOG_ERR( "RedLed not bound" );
    }

    io_blueled_dev = device_get_binding( DT_GPIO_LABEL( DT_ALIAS( blueled ), gpios ) );
    if ( io_blueled_dev )
    {
        ret = gpio_pin_configure( io_blueled_dev,
                                  DT_GPIO_PIN(DT_ALIAS(blueled), gpios),
                                  GPIO_OUTPUT_INACTIVE | DT_GPIO_FLAGS( DT_ALIAS( blueled ), gpios ) );
        if ( ret )
        {
            LOG_ERR( "Green not configured" );
        }
    }
    else
    {
        LOG_ERR( "GreenLed not bound" );
    }

    #ifdef SALEAE

    io_buzzerP_dev = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(buz_p), gpios));
    if ( io_buzzerP_dev == NULL )
    {
        LOG_ERR( "BuzzerP not bound" );
    }

    gpio_pin_configure(io_buzzerP_dev, DT_GPIO_PIN(DT_ALIAS(buz_p), gpios), GPIO_OUTPUT_INACTIVE | DT_GPIO_FLAGS(DT_ALIAS(buz_p), gpios));
    if ( ret )
    {
        LOG_ERR( "BuzzerP not configured" );
    }

    io_buzzerN_dev = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(buz_n), gpios));
    if ( io_buzzerN_dev == NULL )
    {
        LOG_ERR( "BuzzerN not bound" );
    }

    gpio_pin_configure(io_buzzerN_dev, DT_GPIO_PIN(DT_ALIAS(buz_n), gpios), GPIO_OUTPUT_INACTIVE | DT_GPIO_FLAGS(DT_ALIAS(buz_n), gpios));
    if ( ret )
    {
        LOG_ERR( "BuzzerN not configured" );
    }

    #endif
}


///////////////////////////////////////////////////////////////////////////////
void io_led_on(uint8_t colour)
{
    if ( colour & GREEN_LED )
    {
        io.led.state |= GREEN_LED;
        gpio_pin_set( io_blueled_dev, DT_GPIO_PIN(DT_ALIAS(blueled),gpios), 1 );
    }
    if ( colour & RED_LED )
    {
        io.led.state |= RED_LED;
        gpio_pin_set( io_redled_dev, DT_GPIO_PIN(DT_ALIAS(redled),gpios), 1 );
    }
}

void io_led_off(uint8_t colour)
{
    if ( colour & GREEN_LED )
    {
        io.led.state &= ~GREEN_LED;
        gpio_pin_set( io_blueled_dev, DT_GPIO_PIN(DT_ALIAS(blueled),gpios), 0 );
    }
    if ( colour & RED_LED )
    {
        io.led.state &= ~RED_LED;
        gpio_pin_set( io_redled_dev, DT_GPIO_PIN(DT_ALIAS(redled),gpios), 0 );
    }
}


// New PWM code

#define PWM_LED0_NODE   DT_ALIAS(pwm_led0) 

#if DT_NODE_HAS_STATUS(PWM_LED0_NODE, okay)
#define PWM_CTLR    DT_PWMS_CTLR(PWM_LED0_NODE)
#define PWM_CHANNEL DT_PWMS_CHANNEL(PWM_LED0_NODE)
#define PWM_FLAGS   DT_PWMS_FLAGS(PWM_LED0_NODE)
#else
#error "Unsupported board: pwm-led0 devicetree alias is not defined"
#define PWM_CTLR    DT_INVALID_NODE
#define PWM_CHANNEL 0
#define PWM_FLAGS   0
#endif


result_t io_PWM_initialise (uint8_t percentage)
{
    uint32_t period = 1000;   /* 1000us = 1 ms 1000 Hz */
    uint32_t pwm_percentage ;
    int ret;
    result_t result = RESULT_ERROR;
    static boolean_t initialised = FALSE;

    pwm_dev = DEVICE_DT_GET(PWM_CTLR);

    if (device_is_ready(pwm_dev)) /* Check that the structure in ROM containing settings exists */
    {
        if ( percentage > 100)
        {
            percentage = 100; /* Limit maximum value to 100% */
        }

        pwm_percentage = ( (uint32_t) percentage * period) / 100; /* Scale percentage to 0 to 1000 */

        /* The function pwm_pin_set_usec() is used to setup the PWM and takes 4 arguments:
         * pwm_dev = pointer to structure in ROM containing settings for PWM0 to PWM3
         * PWM_CHANNEL = 0 for PWM0.
         * period = 1000us = 1ms.
         * pwm_percentage = % of time PWM is active, 0 = 0% off 100 = 100% full on.
         * PWM_FLAGS = 0. Not used.
        */

        ret = pwm_pin_set_usec(pwm_dev, PWM_CHANNEL, period, pwm_percentage, PWM_FLAGS);

        if ( ret == 0)
        {
            result = RESULT_OK;
            if ( percentage > 0 )
            {
              initialised = TRUE; /* Running some value of PWM rather than being off */
            }
        }

        if ( percentage == 0 && initialised == TRUE )
        {
            /* Do this after the green LED has been set to 0% and was previously running PWM */

            pwm_stop();  /* Only expecuted if PWM percentage was previously 1% or greater */
            initialised = FALSE;
        }
    }
    else
    {
        LOG_ERR( "PWM Device not bound" );
    }

    return (result);
}


///////////////////////////////////////////////////////////////////////////////
void io_led_on( uint8_t colour, uint32_t pulse_width )
{
    if ( ( pwm_dev == NULL ) || ( pwm_dev == NULL ) )
    {
        return;
    }

    if ( colour & GREEN_LED )
    {
        io.led.state |= GREEN_LED;
        pwm_pin_set_usec( pwm_dev,                              /* Pointer to the Green LED dev struct */
                          DT_PWMS_CHANNEL(DT_ALIAS(blueled)),   /* PWM pin/channel */
                          PERIOD_USEC,                          /* PWM period in USEC */
                          pulse_width,                          /* PWM pulse width in USEC */
                          DT_PWMS_FLAGS(DT_ALIAS(blueled))  );  /* PWM Flags for pin config (polarity)*/
    }
    if ( colour & RED_LED )
    {
        io.led.state |= RED_LED;
        pwm_pin_set_usec( pwm_dev,                              /* Pointer to the Red LED dev struct */
                          DT_PWMS_CHANNEL(DT_ALIAS(redled)),    /* PWM pin/channel */
                          PERIOD_USEC,                          /* PWM period in USEC */
                          pulse_width,                          /* PWM pulse width in USEC */
                          DT_PWMS_FLAGS(DT_ALIAS(redled))   );  /* PWM Flags for pin config (polarity)*/
    }
}


///////////////////////////////////////////////////////////////////////////////
void io_led_off( uint8_t colour )
{
    if ( ( pwm_dev == NULL ) || ( pwm_dev == NULL ) )
    {
        return;
    }

    if ( colour & GREEN_LED )
    {
        io.led.state &= ~GREEN_LED;
        pwm_pin_set_usec(pwm_dev, DT_PWMS_CHANNEL(DT_ALIAS(blueled)), PERIOD_USEC,0,0);
    }
    if ( colour & RED_LED )
    {
        io.led.state &= ~RED_LED;
        pwm_pin_set_usec(pwm_dev, DT_PWMS_CHANNEL(DT_ALIAS(redled)), PERIOD_USEC,0,0);
    }
}


/**
*******************************************************************************
*      Fading test. Cycles through all the PWM values from 0% to 100%
*******************************************************************************
**/

/* Used to determine which PWM percentage gives the best orange */

#ifdef FADING_TEST

static void fading_test(void)
{
    static uint8_t counter = 0;

    io_PWM_initialise(counter);

    if ( counter >= 100)
    {
        counter = 0;
    }
    else
    {
        counter++;
    }
}

#endif


/**
*******************************************************************************
*                  New Function to turn off PWM. PTC 82496 
*******************************************************************************
 * The original blinky_pwm code did not provide a global function to turn off
 * the PWM. Use low level code to directly write to the PWM_TASKS_STOP register
 * at address 0x4001C004. 
 * There is also the PWM0_ENABLE register, but this is best not used as it does
 * not re-enable the next time used. 
*******************************************************************************
**/

static void pwm_stop(void)
{
    registers_read();   /* Check status of PWM registers while running */ 

    PWM0_TASKS_STOP = TRIGGER_TASK;

    /*  PWM0_ENABLE = DISABLE; Do not use this. Does not re-enable the next time through */ 
   
    registers_read();  /* Check status of PWM registers when stopped */
}


///////////////////////////////////////////////////////////////////////////////
/*
 *  This function needs to be called every 250 ms as was the case in the
 *  Homestation firmware.
 *
 */
///////////////////////////////////////////////////////////////////////////////
void io_update(void)
{
    ...
    [snip]
    
#if ( LED_TEST )
    LED_test(); /* Test for contention between GPIO and PWM driving LEDS */
#endif

#if ( FADING_TEST )
    fading_test();  /* Cycles through PWM percentage between 0% and 100% */
#endif
}    

void main( void )
{
    ...
    [snip]
    
    io_update();
}

Build_error-1.txt

Kind regards

Mohamed

Parents
  • Hi, 

    NCS v1.7.0 is quite an old version. Please try the latest version v2.7.0 and take a look at this course: Troubleshooting the devicetree

    Regards,
    Amanda H.

  • Thank you Amanda.

    Unfortunately I do not want to update to a more recent version at this stage. I would rather get it to work with v1.7.0.

    Kind regards

    Mohamed

  • Thank you Amanda.

    The line in question can be found at line 142 in the C code I share with you.

    I managed to get the code to build without errors since my last post. But I still have other problems.

    I will share with you the new C code snippets shortly. The overlay file has not changed since yesterday.

    #include <stdio.h>
    #include <zephyr.h>
    #include <arch/cpu.h>
    #include <sys/printk.h>
    #include <device.h>
    #include <devicetree.h>
    #include <drivers/gpio.h>
    #include <drivers/pwm.h>
    #include <drivers/i2c.h>
    #include <drivers/spi.h>
    #include <drivers/adc.h>
    #include <logging/log.h>
    #include <logging/log_ctrl.h>
    [snip]
    ...
    
    #define PWM_OFF                                     (0U)
    #define PWM_PERCENTAGE_ORANGE                       (23U)
    
    #define LED_TEST                                    0
    #define FADING_TEST                                 1
    
    static result_t io_PWM_initialise (uint8_t percentage);
    static void pwm_stop(void);
    //static void registers_read(void);
    //static void LED_test(void);
    static void fading_test(void);
    
    /*
        -----------------------------------------------------------------------------------------------------
        !GLOBAL VARIABLES
        -----------------------------------------------------------------------------------------------------
    */
    //Leds
    const struct device *io_redled_dev;
    const struct device *io_blueled_dev;
    const struct device *pwm_dev;
    
    [snip]
    ...
    
    // New PWM code
    
    #define PWM_LED0_NODE   DT_ALIAS(pwm_led0) 
    #define PWM_LED1_NODE   DT_ALIAS(pwm_led1)
    
    #if DT_NODE_HAS_STATUS(PWM_LED0_NODE, okay)
    #define PWM_CTLR    DT_PWMS_CTLR(PWM_LED0_NODE)
    #define PWM_CHANNEL DT_PWMS_CHANNEL(PWM_LED0_NODE)
    #define PWM_FLAGS   DT_PWMS_FLAGS(PWM_LED0_NODE)
    #else
    #error "Unsupported board: pwm-led0 devicetree alias is not defined"
    #define PWM_CTLR    DT_INVALID_NODE
    #define PWM_CHANNEL 0
    #define PWM_FLAGS   0
    #endif
    
    #if DT_NODE_HAS_STATUS(PWM_LED1_NODE, okay)
    #define PWM_CTLR1    DT_PWMS_CTLR(PWM_LED1_NODE)
    #define PWM_CHANNEL1 DT_PWMS_CHANNEL(PWM_LED1_NODE)
    #define PWM_FLAGS1   DT_PWMS_FLAGS(PWM_LED1_NODE)
    #else
    #error "Unsupported board: pwm-led1 devicetree alias is not defined"
    #define PWM_CTLR1    DT_INVALID_NODE
    #define PWM_CHANNEL1 0
    #define PWM_FLAGS1   0
    #endif
    
    
    ///////////////////////////////////////////////////////////////////////////////
    void io_led_initialise( void )
    {
        /* Initialise PWM ports attached to the LEDs */
    //  io_blueled_dev = device_get_binding( DT_PWMS_CTLR(PWM_LED0_NODE) );
        io_blueled_dev = DEVICE_DT_GET( DT_PWMS_CTLR(PWM_LED0_NODE) );
        if ( io_blueled_dev == NULL )
        {
            LOG_ERR( "Green not bound" );
        }
    
    //  io_redled_dev = device_get_binding( DT_PWMS_CTLR(PWM_LED1_NODE) );
        io_redled_dev = DEVICE_DT_GET( PWM_CTLR1 );
        if ( io_redled_dev == NULL )
        {
            LOG_ERR( "Red not bound" );
        }
    }
    
    
    result_t io_PWM_initialise (uint8_t percentage)
    {
        uint32_t period = 1000;   /* 1000us = 1 ms 1000 Hz */
        uint32_t pwm_percentage ;
        int ret;
        result_t result = RESULT_ERROR;
        static boolean_t initialised = FALSE;
    
        pwm_dev = DEVICE_DT_GET(PWM_CTLR);
    
        if (device_is_ready(pwm_dev)) /* Check that the structure in ROM containing settings exists */
        {
            if ( percentage > 100)
            {
                percentage = 100; /* Limit maximum value to 100% */
            }
    
            pwm_percentage = ( (uint32_t) percentage * period) / 100; /* Scale percentage to 0 to 1000 */
    
            /* The function pwm_pin_set_usec() is used to setup the PWM and takes 4 arguments:
             * pwm_dev = pointer to structure in ROM containing settings for PWM0 to PWM3
             * PWM_CHANNEL = 0 for PWM0.
             * period = 1000us = 1ms.
             * pwm_percentage = % of time PWM is active, 0 = 0% off 100 = 100% full on.
             * PWM_FLAGS = 0. Not used.
            */
    
            ret = pwm_pin_set_usec(pwm_dev, PWM_CHANNEL, period, pwm_percentage, PWM_FLAGS);
    
            if ( ret == 0)
            {
                result = RESULT_OK;
                if ( percentage > 0 )
                {
                  initialised = TRUE; /* Running some value of PWM rather than being off */
                }
            }
    
            if ( percentage == 0 && initialised == TRUE )
            {
                /* Do this after the green LED has been set to 0% and was previously running PWM */
    
                pwm_stop();  /* Only expecuted if PWM percentage was previously 1% or greater */
                initialised = FALSE;
            }
        }
        else
        {
            LOG_ERR( "PWM Device not bound" );
        }
    
        return (result);
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////
    void io_led_on( uint8_t colour, uint32_t pulse_width )
    {
        if ( ( pwm_dev == NULL ) || ( pwm_dev == NULL ) )
        {
            return;
        }
    
        if ( colour & GREEN_LED )
        {
            io.led.state |= GREEN_LED;
            pwm_pin_set_usec( io_blueled_dev,                       /* Pointer to the Green LED dev struct */
    //                        DT_PWMS_CHANNEL(DT_ALIAS(blueled)),   /* PWM pin/channel */
                              PWM_CHANNEL,                          /* PWM pin/channel */
                              PERIOD_USEC,                          /* PWM period in USEC */
                              pulse_width,                          /* PWM pulse width in USEC */
    //                        DT_PWMS_FLAGS(DT_ALIAS(blueled))  );  /* PWM Flags for pin config (polarity)*/
                              PWM_FLAGS  );                         /* PWM Flags for pin config (polarity)*/
        }
        if ( colour & RED_LED )
        {
            io.led.state |= RED_LED;
            pwm_pin_set_usec( io_redled_dev,                        /* Pointer to the Red LED dev struct */
    //                        DT_PWMS_CHANNEL(DT_ALIAS(redled)),    /* PWM pin/channel */
                              PWM_CHANNEL1,                         /* PWM pin/channel */
                              PERIOD_USEC,                          /* PWM period in USEC */
                              pulse_width,                          /* PWM pulse width in USEC */
    //                        DT_PWMS_FLAGS(DT_ALIAS(redled))   );  /* PWM Flags for pin config (polarity)*/
                              PWM_FLAGS1  );                        /* PWM Flags for pin config (polarity)*/
        }
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////
    void io_led_off( uint8_t colour )
    {
        if ( ( pwm_dev == NULL ) || ( pwm_dev == NULL ) )
        {
            return;
        }
    
        if ( colour & GREEN_LED )
        {
            io.led.state &= ~GREEN_LED;
    //      pwm_pin_set_usec(pwm_dev, DT_PWMS_CHANNEL(DT_ALIAS(blueled)), PERIOD_USEC,0,0);
            pwm_pin_set_usec(io_blueled_dev, PWM_CHANNEL, PERIOD_USEC,0,0);
        }
        if ( colour & RED_LED )
        {
            io.led.state &= ~RED_LED;
    //      pwm_pin_set_usec(pwm_dev, DT_PWMS_CHANNEL(DT_ALIAS(redled)), PERIOD_USEC,0,0);
            pwm_pin_set_usec(io_redled_dev, PWM_CHANNEL1, PERIOD_USEC,0,0);
        }
    }
    
    
    /**
    *******************************************************************************
    *      Fading test. Cycles through all the PWM values from 0% to 100%
    *******************************************************************************
    **/
    
    /* Used to determine which PWM percentage gives the best orange */
    
    #ifdef FADING_TEST
    
    static void fading_test(void)
    {
        static uint8_t counter = 0;
    
        io_PWM_initialise(counter);
    
        if ( counter >= 100)
        {
            counter = 0;
        }
        else
        {
            counter++;
        }
    }
    
    #endif
    
    
    /**
    *******************************************************************************
    *                  New Function to turn off PWM. PTC 82496 
    *******************************************************************************
     * The original blinky_pwm code did not provide a global function to turn off
     * the PWM. Use low level code to directly write to the PWM_TASKS_STOP register
     * at address 0x4001C004. 
     * There is also the PWM0_ENABLE register, but this is best not used as it does
     * not re-enable the next time used. 
    *******************************************************************************
    **/
    
    static void pwm_stop(void)
    {
        registers_read();   /* Check status of PWM registers while running */ 
    
        PWM0_TASKS_STOP = TRIGGER_TASK;
    
        /*  PWM0_ENABLE = DISABLE; Do not use this. Does not re-enable the next time through */ 
       
        registers_read();  /* Check status of PWM registers when stopped */
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////
    /*
     *  This function needs to be called every 250 ms as was the case in the
     *  Homestation firmware.
     *
     */
    ///////////////////////////////////////////////////////////////////////////////
    void io_update(void)
    {
        ...
        [snip]
        
    #if ( LED_TEST )
        LED_test(); /* Test for contention between GPIO and PWM driving LEDS */
    #endif
    
    #if ( FADING_TEST )
        fading_test();  /* Cycles through PWM percentage between 0% and 100% */
    #endif
    }    
    
    void main( void )
    {
        ...
        [snip]
        
        io_update();
    }

    The build logs showing errors are below.

    Building ‘C:/Zypher/v1.7.0/zephyr/include/dt-bindings/gpio/gpio.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘C:/Zypher/v1.7.0/zephyr/include/dt-bindings/i2c/i2c.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/misc/generated/syscalls.json’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/misc/generated/struct_tags.json’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/parse_syscalls_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/parse_syscalls_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/driver-validation.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/driver_validation_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/driver_validation_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/kobj-types-enum.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/otype-to-str.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/kobj_types_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/otype-to-size.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/kobj_types_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/syscall_list.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/syscall_list_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/syscall_dispatch.c’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/syscall_list_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘cmake_object_order_depends_target_offsets’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/offsets.dir/arch/arm/core/offsets/offsets.c.obj’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/offsets’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/offsets.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/offsets_h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/offsets_h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/zephyr_generated_headers’ from solution ‘build’ in configuration ‘Common’
    Building ‘cmake_object_order_depends_target_app’ from solution ‘build’ in configuration ‘Common’
    Building ‘app/libapp.a’ from solution ‘build’ in configuration ‘Common’
    8> Compiling ‘io.c’
    8> C:\Zypher\v1.7.0\toolchain\opt/bin/arm-none-eabi-gcc -DBUILD_VERSION=v2.6.99-ncs1 -DKERNEL -DNRF52833_XXAA -DNRF52_SERIES -DUSE_PARTITION_MANAGER=1 -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/Zypher/v1.7.0/zephyr/include -Izephyr/include/generated -IC:/Zypher/v1.7.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/Zypher/v1.7.0/zephyr/subsys/bluetooth -IC:/Zypher/v1.7.0/zephyr/subsys/bluetooth/controller/ll_sw/nordic -IC:/Zypher/v1.7.0/nrf/include -IC:/Zypher/v1.7.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/Zypher/v1.7.0/modules/hal/nordic/nrfx -IC:/Zypher/v1.7.0/modules/hal/nordic/nrfx/drivers/include -IC:/Zypher/v1.7.0/modules/hal/nordic/nrfx/mdk -IC:/Zypher/v1.7.0/zephyr/modules/hal_nordic/nrfx/. -IC:/Zypher/v1.7.0/modules/debug/segger/SEGGER -IC:/Zypher/v1.7.0/modules/debug/segger/Config -IC:/Zypher/v1.7.0/zephyr/modules/segger/. -isystem C:/Zypher/v1.7.0/zephyr/lib/libc/minimal/include -isystem c:/zypher/v1.7.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/include -isystem c:/zypher/v1.7.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/include-fixed -g -Og -imacros C:/Sandbox/HomeBeacon_dev_sb/build_nrf52833dk_nrf52833_console_v157_dbg/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -imacros C:/Zypher/v1.7.0/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-address-of-packed-member -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=C:/Sandbox/HomeBeacon_dev_sb=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/Zypher/v1.7.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/Zypher/v1.7.0=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MF C:/Sandbox/HomeBeacon_dev_sb/build_nrf52833dk_nrf52833_console_v157_dbg/CMakeFiles\app.dir\src\io.c.obj.d -fno-diagnostics-show-caret -o CMakeFiles/app.dir/src/io.c.obj -c ../src/io.c
    8> ../src/io.c:344:2: error: #error "Unsupported board: pwm-led1 devicetree alias is not defined"
    8> In file included from C:/Zypher/v1.7.0/zephyr/include/toolchain/gcc.h:66,
    8>                  from C:/Zypher/v1.7.0/zephyr/include/toolchain.h:43,
    8>                  from C:/Zypher/v1.7.0/zephyr/lib/libc/minimal/include/stdio.h:12,
    8>                  from ../src/io.c:30:
    8> ../src/io.c: In function 'io_led_initialise':
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:80:39: error: '__device_dts_ord___ORD' undeclared (first use in this function); did you mean '__device_dts_ord_69'?
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:232:37: note: in expansion of macro 'DEVICE_NAME_GET'
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:246:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
    8> ../src/io.c:362:21: note: in expansion of macro 'DEVICE_DT_GET'
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:80:39: note: each undeclared identifier is reported only once for each function it appears in
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:232:37: note: in expansion of macro 'DEVICE_NAME_GET'
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:246:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
    8> ../src/io.c:362:21: note: in expansion of macro 'DEVICE_DT_GET'
    Build failed
    

    Kind regards

    Mohamed

Reply
  • Thank you Amanda.

    The line in question can be found at line 142 in the C code I share with you.

    I managed to get the code to build without errors since my last post. But I still have other problems.

    I will share with you the new C code snippets shortly. The overlay file has not changed since yesterday.

    #include <stdio.h>
    #include <zephyr.h>
    #include <arch/cpu.h>
    #include <sys/printk.h>
    #include <device.h>
    #include <devicetree.h>
    #include <drivers/gpio.h>
    #include <drivers/pwm.h>
    #include <drivers/i2c.h>
    #include <drivers/spi.h>
    #include <drivers/adc.h>
    #include <logging/log.h>
    #include <logging/log_ctrl.h>
    [snip]
    ...
    
    #define PWM_OFF                                     (0U)
    #define PWM_PERCENTAGE_ORANGE                       (23U)
    
    #define LED_TEST                                    0
    #define FADING_TEST                                 1
    
    static result_t io_PWM_initialise (uint8_t percentage);
    static void pwm_stop(void);
    //static void registers_read(void);
    //static void LED_test(void);
    static void fading_test(void);
    
    /*
        -----------------------------------------------------------------------------------------------------
        !GLOBAL VARIABLES
        -----------------------------------------------------------------------------------------------------
    */
    //Leds
    const struct device *io_redled_dev;
    const struct device *io_blueled_dev;
    const struct device *pwm_dev;
    
    [snip]
    ...
    
    // New PWM code
    
    #define PWM_LED0_NODE   DT_ALIAS(pwm_led0) 
    #define PWM_LED1_NODE   DT_ALIAS(pwm_led1)
    
    #if DT_NODE_HAS_STATUS(PWM_LED0_NODE, okay)
    #define PWM_CTLR    DT_PWMS_CTLR(PWM_LED0_NODE)
    #define PWM_CHANNEL DT_PWMS_CHANNEL(PWM_LED0_NODE)
    #define PWM_FLAGS   DT_PWMS_FLAGS(PWM_LED0_NODE)
    #else
    #error "Unsupported board: pwm-led0 devicetree alias is not defined"
    #define PWM_CTLR    DT_INVALID_NODE
    #define PWM_CHANNEL 0
    #define PWM_FLAGS   0
    #endif
    
    #if DT_NODE_HAS_STATUS(PWM_LED1_NODE, okay)
    #define PWM_CTLR1    DT_PWMS_CTLR(PWM_LED1_NODE)
    #define PWM_CHANNEL1 DT_PWMS_CHANNEL(PWM_LED1_NODE)
    #define PWM_FLAGS1   DT_PWMS_FLAGS(PWM_LED1_NODE)
    #else
    #error "Unsupported board: pwm-led1 devicetree alias is not defined"
    #define PWM_CTLR1    DT_INVALID_NODE
    #define PWM_CHANNEL1 0
    #define PWM_FLAGS1   0
    #endif
    
    
    ///////////////////////////////////////////////////////////////////////////////
    void io_led_initialise( void )
    {
        /* Initialise PWM ports attached to the LEDs */
    //  io_blueled_dev = device_get_binding( DT_PWMS_CTLR(PWM_LED0_NODE) );
        io_blueled_dev = DEVICE_DT_GET( DT_PWMS_CTLR(PWM_LED0_NODE) );
        if ( io_blueled_dev == NULL )
        {
            LOG_ERR( "Green not bound" );
        }
    
    //  io_redled_dev = device_get_binding( DT_PWMS_CTLR(PWM_LED1_NODE) );
        io_redled_dev = DEVICE_DT_GET( PWM_CTLR1 );
        if ( io_redled_dev == NULL )
        {
            LOG_ERR( "Red not bound" );
        }
    }
    
    
    result_t io_PWM_initialise (uint8_t percentage)
    {
        uint32_t period = 1000;   /* 1000us = 1 ms 1000 Hz */
        uint32_t pwm_percentage ;
        int ret;
        result_t result = RESULT_ERROR;
        static boolean_t initialised = FALSE;
    
        pwm_dev = DEVICE_DT_GET(PWM_CTLR);
    
        if (device_is_ready(pwm_dev)) /* Check that the structure in ROM containing settings exists */
        {
            if ( percentage > 100)
            {
                percentage = 100; /* Limit maximum value to 100% */
            }
    
            pwm_percentage = ( (uint32_t) percentage * period) / 100; /* Scale percentage to 0 to 1000 */
    
            /* The function pwm_pin_set_usec() is used to setup the PWM and takes 4 arguments:
             * pwm_dev = pointer to structure in ROM containing settings for PWM0 to PWM3
             * PWM_CHANNEL = 0 for PWM0.
             * period = 1000us = 1ms.
             * pwm_percentage = % of time PWM is active, 0 = 0% off 100 = 100% full on.
             * PWM_FLAGS = 0. Not used.
            */
    
            ret = pwm_pin_set_usec(pwm_dev, PWM_CHANNEL, period, pwm_percentage, PWM_FLAGS);
    
            if ( ret == 0)
            {
                result = RESULT_OK;
                if ( percentage > 0 )
                {
                  initialised = TRUE; /* Running some value of PWM rather than being off */
                }
            }
    
            if ( percentage == 0 && initialised == TRUE )
            {
                /* Do this after the green LED has been set to 0% and was previously running PWM */
    
                pwm_stop();  /* Only expecuted if PWM percentage was previously 1% or greater */
                initialised = FALSE;
            }
        }
        else
        {
            LOG_ERR( "PWM Device not bound" );
        }
    
        return (result);
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////
    void io_led_on( uint8_t colour, uint32_t pulse_width )
    {
        if ( ( pwm_dev == NULL ) || ( pwm_dev == NULL ) )
        {
            return;
        }
    
        if ( colour & GREEN_LED )
        {
            io.led.state |= GREEN_LED;
            pwm_pin_set_usec( io_blueled_dev,                       /* Pointer to the Green LED dev struct */
    //                        DT_PWMS_CHANNEL(DT_ALIAS(blueled)),   /* PWM pin/channel */
                              PWM_CHANNEL,                          /* PWM pin/channel */
                              PERIOD_USEC,                          /* PWM period in USEC */
                              pulse_width,                          /* PWM pulse width in USEC */
    //                        DT_PWMS_FLAGS(DT_ALIAS(blueled))  );  /* PWM Flags for pin config (polarity)*/
                              PWM_FLAGS  );                         /* PWM Flags for pin config (polarity)*/
        }
        if ( colour & RED_LED )
        {
            io.led.state |= RED_LED;
            pwm_pin_set_usec( io_redled_dev,                        /* Pointer to the Red LED dev struct */
    //                        DT_PWMS_CHANNEL(DT_ALIAS(redled)),    /* PWM pin/channel */
                              PWM_CHANNEL1,                         /* PWM pin/channel */
                              PERIOD_USEC,                          /* PWM period in USEC */
                              pulse_width,                          /* PWM pulse width in USEC */
    //                        DT_PWMS_FLAGS(DT_ALIAS(redled))   );  /* PWM Flags for pin config (polarity)*/
                              PWM_FLAGS1  );                        /* PWM Flags for pin config (polarity)*/
        }
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////
    void io_led_off( uint8_t colour )
    {
        if ( ( pwm_dev == NULL ) || ( pwm_dev == NULL ) )
        {
            return;
        }
    
        if ( colour & GREEN_LED )
        {
            io.led.state &= ~GREEN_LED;
    //      pwm_pin_set_usec(pwm_dev, DT_PWMS_CHANNEL(DT_ALIAS(blueled)), PERIOD_USEC,0,0);
            pwm_pin_set_usec(io_blueled_dev, PWM_CHANNEL, PERIOD_USEC,0,0);
        }
        if ( colour & RED_LED )
        {
            io.led.state &= ~RED_LED;
    //      pwm_pin_set_usec(pwm_dev, DT_PWMS_CHANNEL(DT_ALIAS(redled)), PERIOD_USEC,0,0);
            pwm_pin_set_usec(io_redled_dev, PWM_CHANNEL1, PERIOD_USEC,0,0);
        }
    }
    
    
    /**
    *******************************************************************************
    *      Fading test. Cycles through all the PWM values from 0% to 100%
    *******************************************************************************
    **/
    
    /* Used to determine which PWM percentage gives the best orange */
    
    #ifdef FADING_TEST
    
    static void fading_test(void)
    {
        static uint8_t counter = 0;
    
        io_PWM_initialise(counter);
    
        if ( counter >= 100)
        {
            counter = 0;
        }
        else
        {
            counter++;
        }
    }
    
    #endif
    
    
    /**
    *******************************************************************************
    *                  New Function to turn off PWM. PTC 82496 
    *******************************************************************************
     * The original blinky_pwm code did not provide a global function to turn off
     * the PWM. Use low level code to directly write to the PWM_TASKS_STOP register
     * at address 0x4001C004. 
     * There is also the PWM0_ENABLE register, but this is best not used as it does
     * not re-enable the next time used. 
    *******************************************************************************
    **/
    
    static void pwm_stop(void)
    {
        registers_read();   /* Check status of PWM registers while running */ 
    
        PWM0_TASKS_STOP = TRIGGER_TASK;
    
        /*  PWM0_ENABLE = DISABLE; Do not use this. Does not re-enable the next time through */ 
       
        registers_read();  /* Check status of PWM registers when stopped */
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////
    /*
     *  This function needs to be called every 250 ms as was the case in the
     *  Homestation firmware.
     *
     */
    ///////////////////////////////////////////////////////////////////////////////
    void io_update(void)
    {
        ...
        [snip]
        
    #if ( LED_TEST )
        LED_test(); /* Test for contention between GPIO and PWM driving LEDS */
    #endif
    
    #if ( FADING_TEST )
        fading_test();  /* Cycles through PWM percentage between 0% and 100% */
    #endif
    }    
    
    void main( void )
    {
        ...
        [snip]
        
        io_update();
    }

    The build logs showing errors are below.

    Building ‘C:/Zypher/v1.7.0/zephyr/include/dt-bindings/gpio/gpio.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘C:/Zypher/v1.7.0/zephyr/include/dt-bindings/i2c/i2c.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/misc/generated/syscalls.json’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/misc/generated/struct_tags.json’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/parse_syscalls_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/parse_syscalls_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/driver-validation.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/driver_validation_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/driver_validation_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/kobj-types-enum.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/otype-to-str.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/kobj_types_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/otype-to-size.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/kobj_types_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/syscall_list.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/syscall_list_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/syscall_dispatch.c’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/syscall_list_h_target’ from solution ‘build’ in configuration ‘Common’
    Building ‘cmake_object_order_depends_target_offsets’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/offsets.dir/arch/arm/core/offsets/offsets.c.obj’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/offsets’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/include/generated/offsets.h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/CMakeFiles/offsets_h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/offsets_h’ from solution ‘build’ in configuration ‘Common’
    Building ‘zephyr/zephyr_generated_headers’ from solution ‘build’ in configuration ‘Common’
    Building ‘cmake_object_order_depends_target_app’ from solution ‘build’ in configuration ‘Common’
    Building ‘app/libapp.a’ from solution ‘build’ in configuration ‘Common’
    8> Compiling ‘io.c’
    8> C:\Zypher\v1.7.0\toolchain\opt/bin/arm-none-eabi-gcc -DBUILD_VERSION=v2.6.99-ncs1 -DKERNEL -DNRF52833_XXAA -DNRF52_SERIES -DUSE_PARTITION_MANAGER=1 -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/Zypher/v1.7.0/zephyr/include -Izephyr/include/generated -IC:/Zypher/v1.7.0/zephyr/soc/arm/nordic_nrf/nrf52 -IC:/Zypher/v1.7.0/zephyr/subsys/bluetooth -IC:/Zypher/v1.7.0/zephyr/subsys/bluetooth/controller/ll_sw/nordic -IC:/Zypher/v1.7.0/nrf/include -IC:/Zypher/v1.7.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/Zypher/v1.7.0/modules/hal/nordic/nrfx -IC:/Zypher/v1.7.0/modules/hal/nordic/nrfx/drivers/include -IC:/Zypher/v1.7.0/modules/hal/nordic/nrfx/mdk -IC:/Zypher/v1.7.0/zephyr/modules/hal_nordic/nrfx/. -IC:/Zypher/v1.7.0/modules/debug/segger/SEGGER -IC:/Zypher/v1.7.0/modules/debug/segger/Config -IC:/Zypher/v1.7.0/zephyr/modules/segger/. -isystem C:/Zypher/v1.7.0/zephyr/lib/libc/minimal/include -isystem c:/zypher/v1.7.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/include -isystem c:/zypher/v1.7.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/include-fixed -g -Og -imacros C:/Sandbox/HomeBeacon_dev_sb/build_nrf52833dk_nrf52833_console_v157_dbg/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -imacros C:/Zypher/v1.7.0/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-address-of-packed-member -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=C:/Sandbox/HomeBeacon_dev_sb=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/Zypher/v1.7.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/Zypher/v1.7.0=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -MD -MF C:/Sandbox/HomeBeacon_dev_sb/build_nrf52833dk_nrf52833_console_v157_dbg/CMakeFiles\app.dir\src\io.c.obj.d -fno-diagnostics-show-caret -o CMakeFiles/app.dir/src/io.c.obj -c ../src/io.c
    8> ../src/io.c:344:2: error: #error "Unsupported board: pwm-led1 devicetree alias is not defined"
    8> In file included from C:/Zypher/v1.7.0/zephyr/include/toolchain/gcc.h:66,
    8>                  from C:/Zypher/v1.7.0/zephyr/include/toolchain.h:43,
    8>                  from C:/Zypher/v1.7.0/zephyr/lib/libc/minimal/include/stdio.h:12,
    8>                  from ../src/io.c:30:
    8> ../src/io.c: In function 'io_led_initialise':
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:80:39: error: '__device_dts_ord___ORD' undeclared (first use in this function); did you mean '__device_dts_ord_69'?
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:232:37: note: in expansion of macro 'DEVICE_NAME_GET'
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:246:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
    8> ../src/io.c:362:21: note: in expansion of macro 'DEVICE_DT_GET'
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:80:39: note: each undeclared identifier is reported only once for each function it appears in
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:232:37: note: in expansion of macro 'DEVICE_NAME_GET'
    8> C:/Zypher/v1.7.0/zephyr/include/device.h:246:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
    8> ../src/io.c:362:21: note: in expansion of macro 'DEVICE_DT_GET'
    Build failed
    

    Kind regards

    Mohamed

Children
No Data
Related