Zephyr WS2812 Driver undefined reference to `__device_dts_ord_68'

I am trying to implement the Ws2812 driver on the NRF5340 based on the driver example.  

The specific error I am getting is:

c:/sysgcc/arm-eabi/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: zephyr/drivers/spi/libdrivers__spi.a(spi_nrfx_spim.c.obj):(.rodata.__compound_literal.1+0x0): undefined reference to `__device_dts_ord_68'

This is similar to this post:

 Implementing WS2812 Driver NCS (undefined reference to `__device_dts_ord_61') 

 It seems like there is something missing in the configuration.  

prj.conf:

#	BT
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="QuantaFlo 2.0""
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_MAX_PAIRED=1
CONFIG_BT_DEBUG_LOG=y
CONFIG_BT_MAX_CONN=1
#CONFIG_BT_L2CAP_TX_BUF_COUNT=5


# This example requires more workqueue stack
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_HEAP_MEM_POOL_SIZE=2048

#	SPI
CONFIG_SPI=y
#CONFIG_NRFX_SPIM=y
#CONFIG_NRFX_SPIM4=y
CONFIG_GPIO=n

CONFIG_CPLUSPLUS=y
CONFIG_LIB_CPLUSPLUS=y
CONFIG_NEWLIB_LIBC=y


# CONFIG_CONSOLE is not set

CONFIG_GPIO_NRFX=n
#CONFIG_NRFX_GPIOTE=y

#	USB
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="SS QF2.0"
CONFIG_LOG=y
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y

CONFIG_USB_DEVICE_PID=0x0501
CONFIG_USB_DEVICE_VID=0x2047

#	Logging
CONFIG_USE_SEGGER_RTT=y
#CONFIG_LOG_BACKEND_RTT=y

#	Neopixels
CONFIG_LED_STRIP=y
CONFIG_WS2812_STRIP=y
CONFIG_LED_STRIP_LOG_LEVEL_DBG=y

The overlay file:

&spi4 {
	compatible="nordic,nrf-spim";
	status = "ok";
	sck-pin = <36>;
	mosi-pin = <41>;
	miso-pin = <25>;

}; 

&zephyr_udc0 {
	cdc_acm_uart0 {
		compatible = "zephyr,cdc-acm-uart";
		label = "CDC_ACM_0";
	};
};


#include <dt-bindings/led/led.h>



#define SPI_FREQ    4000000
#define ZERO_FRAME  0x40
#define ONE_FRAME   0x70

&spi2 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <0>;
	miso-pin = <0>;
	mosi-pin = <16>;

	led_strip: ws2812@0 {
		compatible = "worldsemi,ws2812-spi";
		label = "WS2812";

		/* SPI */
		reg = <0>; /* ignored, but necessary for SPI bindings */
		spi-max-frequency = <SPI_FREQ>;

		/* WS2812 */
		chain-length = <1>; /* arbitrary; change at will */
		color-mapping = <LED_COLOR_ID_GREEN
				 LED_COLOR_ID_RED
				 LED_COLOR_ID_BLUE>;
		spi-one-frame = <ONE_FRAME>;
		spi-zero-frame = <ZERO_FRAME>;
	};
};

/ {
	aliases {
		led-strip = &led_strip;
	};
};

Nothing in the other linked post seemed to help.

  • The code file:

    #include <zephyr.h>
    #include <device.h>
    #include <hal/nrf_gpio.h>
    #include "leds.h"
    #include "qf_settings.h"
    
    #include <logging/log.h>
    LOG_MODULE_REGISTER(Leds, LOG_LEVEL_DBG);
    
    #define RESET_BITS                      6                                                  /**< Reset bits. */
    #define I2S_BUFFER_SIZE                 ((3 * QfSettings::Leds::LED_COUNT) + RESET_BITS)   /**< i2s buffer size for driving the neopixel. */
    
    #define IRQ_PRI                         1
    
    Leds leds;
    
    
    #define STRIP_NODE		    DT_ALIAS(led_strip)
    #define STRIP_NUM_PIXELS	DT_PROP(DT_ALIAS(led_strip), chain_length)
    
    static const struct device *strip = DEVICE_DT_GET(STRIP_NODE);
    
    void Leds::init()
    {
    
        //	Configure 5V enable as output
    	nrf_gpio_pin_dir_set(QfSettings::Pins::Digital::LED_EN, NRF_GPIO_PIN_DIR_OUTPUT);
      enable_leds();
      
      
      if (device_is_ready(strip)) 
      {
        LOG_INF("Found LED strip device %s", strip->name);
      }
      else {
        LOG_ERR("LED strip device %s is not ready", strip->name);
        return;
      }
      
      
      while (1) k_sleep(K_MSEC(1000));
      
    }
    
    void Leds::enable_leds()
    {
      nrf_gpio_pin_set(QfSettings::Pins::Digital::LED_EN);
    }
    
    void Leds::disable_leds()
    {
      nrf_gpio_pin_clear(QfSettings::Pins::Digital::LED_EN);
    }

  • zephyr.dts

    spi2: spi@b000 {
    				compatible = "nordic,nrf-spim";
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0xb000 0x1000 >;
    				interrupts = < 0xb 0x1 >;
    				status = "okay";
    				label = "SPI_2";
    				sck-pin = < 0x0 >;
    				miso-pin = < 0x0 >;
    				mosi-pin = < 0x10 >;
    				led_strip: ws2812@0 {
    					compatible = "worldsemi,ws2812-spi";
    					label = "WS2812";
    					reg = < 0x0 >;
    					spi-max-frequency = < 0x3d0900 >;
    					chain-length = < 0x1 >;
    					color-mapping = < 0x2 0x1 0x3 >;
    					spi-one-frame = < 0x70 >;
    					spi-zero-frame = < 0x40 >;
    				};
    			};

  • Hi,

     

    Unused pins should be set to 0xFF (define NRFX_SPIM_PIN_NOT_USED). When you set them to 0, it implies P0.00.

     

    I tried the example in path/to/ncs/zephyr/samples/drivers/led_ws2812

    With the addition of these two files in the led_ws2812/boards/ catalog:

    nrf5340dk_nrf5340_cpuapp.conf:

    CONFIG_SPI=y

    nrf5340dk_nrf5340_cpuapp.overlay:

    /*
     * Copyright (c) 2019, Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <dt-bindings/led/led.h>
    
    #include "../nrf52-bindings.h"
    
    &spi2 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	/* Note that this pin is not routed to the gpio header on nRF5340-DK, it routed directly to the external flash */
    	mosi-pin = <16>;
    	led_strip: ws2812@0 {
    		compatible = "worldsemi,ws2812-spi";
    		label = "WS2812";
    
    		/* SPI */
    		reg = <0>; /* ignored, but necessary for SPI bindings */
    		spi-max-frequency = <SPI_FREQ>;
    
    		/* WS2812 */
    		chain-length = <16>; /* arbitrary; change at will */
    		color-mapping = <LED_COLOR_ID_GREEN
    				 LED_COLOR_ID_RED
    				 LED_COLOR_ID_BLUE>;
    		spi-one-frame = <ONE_FRAME>;
    		spi-zero-frame = <ZERO_FRAME>;
    	};
    };
    
    / {
    	aliases {
    		led-strip = &led_strip;
    	};
    };

     

    This compiled fine at my end, but please note that P0.16 is directly connected to the external flash on the nRF5340-DK!

    You should select another GPIO if using the DK.

     

    Kind regards,

    Håkon

  • Thank you for the tip regarding unused pin numbers.

    I am trying to integrate the WS2812 driver into an existing project on a custom board.

    After deleting the build directory, I noticed the following warning from CMAKE:

    CMake Warning at D:/nrf_connect/v1.9.1/zephyr/CMakeLists.txt:764 (message):
      No SOURCES given to Zephyr library: drivers__led_strip
    
      Excluding target from build.

    How do I resolve this?

  • Can you please share your full overlay file?

     

    Kind regards,

    Håkon

Related