This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

converting zephyr driver led_ws2812 to run on nrf9160

In the nrfConnect SDK 1.4 there is a sample for chainable RGB LEDs ../ncs/zephyr/samples/drivers/led_ws2812

I want to use this with nrf9160 so I created nrf9160dk_nrf9160ns.overlay by copying and editing the nrf52 one:

```

/*
* Copyright (c) 2019, Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "../nrf52-bindings.h"

&spi2 {
  led_strip: ws2812@0 {
    mosi-pin = <31>;
    compatible = "worldsemi,ws2812-spi";
    label = "WS2812";

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

    /* WS2812 */
    chain-length = <10>; /* arbitrary; change at will */
    spi-one-frame = <ONE_FRAME>;
    spi-zero-frame = <ZERO_FRAME>;
  };
};

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

```

When I try to build that west gives:

```

Error: nrf9160dk_nrf9160ns.dts.pre.tmp:587.25-26 syntax error

FATAL ERROR: Unable to parse input tree

CMake Error at /Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/cmake/dts.cmake:213 (message):

  command failed with return code: 1

Call Stack (most recent call first):

  /Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/cmake/app/boilerplate.cmake:590 (include)

  /Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)

  /Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)

  CMakeLists.txt:5 (find_package)

-- Configuring incomplete, errors occurred!

FATAL ERROR: command exited with status 1: /usr/local/bin/cmake -DWEST_PYTHON=/usr/local/opt/python/bin/python3.7 -B/Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/samples/drivers/led_ws2812/build -S/Users/paul_tanner/Nordic/nrfsrc/ncs/zephyr/samples/drivers/led_ws2812 -GNinja -DBOARD=nrf9160dk_nrf9160ns

```

Note: the file named nrf52-bindings.h does not look as though it needs to be changed so I did not rename i

Perhaps I need to do more to convert this for nrf9160?

There's a note in the README.rst: create a ``led-strip`` :ref:`devicetree alias <dt-alias-chosen>` ... I'm not sure what's needed.

Regards.

Parents
  • Hi,

    I don't have the hardware to test, but looks like this compiles. Pin31 was already assigned to i2c2, so had to disable it.

    Kenneth

    /*
     * Copyright (c) 2019, Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include "../nrf52-bindings.h"
    
    &i2c2 {
    	status = "disabled";
    };
    
    &spi2 { /* MOSI on D11 / P0.23 */
    	mosi-pin = <31>;
    	sck-pin = <30>;
    	miso-pin = <29>;
    	status = "okay";
    	compatible = "nordic,nrf-spim";	
    	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 */
    		spi-one-frame = <ONE_FRAME>;
    		spi-zero-frame = <ZERO_FRAME>;
    	};
    };
    
    / {
    	aliases {
    		led-strip = &led_strip;
    	};
    };

    Or this:

    /*
     * Copyright (c) 2019, Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include "../nrf52-bindings.h"
    
    &i2c2 {
    	status = "disabled";
    };
    
    &spi3 { /* MOSI on D11 / P0.23 */
    	mosi-pin = <31>;	
    	compatible = "nordic,nrf-spim";	
    	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 */
    		spi-one-frame = <ONE_FRAME>;
    		spi-zero-frame = <ZERO_FRAME>;
    	};
    };
    
    / {
    	aliases {
    		led-strip = &led_strip;
    	};
    };
    

  • I agree this compiles OK on 9160.  Also runs almost OK on 9160-DK.

    However, the colours were not in the right order so I made this change:

    ```

    #define GRB(_r, _g, _b) { .r = (_r), .g = (_g), .b = (_b) }

    static const struct led_rgb colors[] = {
    GRB(0x4f, 0x00, 0x00), /* green */
    GRB(0x00, 0x4f, 0x00), /* red */
    GRB(0x00, 0x00, 0x4f), /* blue */
    GRB(0x00, 0x00, 0x00), /* black */
    };

    ```

    The device I was testing with was this docs.rs-online.com/.../0900766b8139d70b.pdf

  • My impression is that the spi configuation (or any other peripheral driver) is static in zephyr  (set at compile time), so if you need to control two spi devices, you need two spi instances. So I don't have a fix for you no, other than possible use nrfx_spim directly for possible one of the spi instances, then you have the possibility to dynamically change settings run-time, however the api is not the same as the zephyr driver api, so you can't use the zephyr libraries that depend on the zephyr driver api then.

    Kenneth

  • Thx Kenneth,

    I *am* using 3 SPI devices, achieved by disabling i2c2 and uart1, and defining spi1 and spi2 in an overlay.

    Further testing revealed that setting the to "disabled" in an overlay may not be sufficient.  I have now got it working by editing the <board>_common.dts.  This is not a nice solution but I have a way forward for now.

    I would still be interested to know if anyone has written a 1-wire driver for zephyr.

  • Hi,

    I also have a problem with compiling code after adding nrf9160dk_nrf9160ns.overlay.
    Bulding output is next:

    Maybe, you can share your example with config?

    Thanks 

  • These are my config files

    ```

    CONFIG_SPI=y
    CONFIG_LOG=y
    CONFIG_LED_STRIP=y
    CONFIG_LED_STRIP_LOG_LEVEL_DBG=y
    CONFIG_WS2812_STRIP=y

    ```

    and overlay...

    ...

    &spi3 {
    status = "okay";
    compatible = "nordic,nrf-spim";
    mosi-pin = <31>;
    miso-pin = <29>;
    sck-pin = <28>;
    led_strip: ws2812@0 {
    compatible = "worldsemi,ws2812-spi";
    label = "WS2812";

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

    /* WS2812 */
    chain-length = <1>; /* arbitrary; change at will */
    spi-one-frame = <0x70>;
    spi-zero-frame = <0x40>;
    };
    };

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

    ```

    I am building with west

    Hope this helps.

    /P

  • Hi,

    The overlay filename is incorrect and should be nrf9160dk_nrf9160_ns.overlay.

    Afterwards, you'll likely encounter another compile error:

    -- Found devicetree overlay: /Users/lance/Developer/led_ws2812/boards/nrf9160dk_nrf9160_ns.overlay
    /Users/lance/Developer/led_ws2812/build/nrf9160dk_nrf9160_ns.dts.pre.tmp:367.32-371.5: Warning (simple_bus_reg): /soc/cryptocell-sw: missing or empty reg/ranges property
    devicetree error: 'color-mapping' is marked as required in 'properties:' in /Users/lance/ncs/zephyr/dts/bindings/led_strip/worldsemi,ws2812-spi.yaml, but does not appear in <Node /soc/peripheral@40000000/spi@b000/ws2812@0 in 'nrf9160dk_nrf9160_ns.dts.pre.tmp'>
    CMake Error at /Users/lance/ncs/zephyr/cmake/dts.cmake:251 (message):
    gen_defines.py failed with return code: 1
    Call Stack (most recent call first):
    /Users/lance/ncs/zephyr/cmake/app/boilerplate.cmake:545 (include)
    /Users/lance/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
    /Users/lance/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
    /Users/lance/Developer/led_ws2812/build/CMakeLists.txt:7 (find_package)


    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/v1.8.0/toolchain/bin/cmake -DWEST_PYTHON=/opt/nordic/ncs/v1.8.0/toolchain/opt/[email protected]/bin/python3.9 -B/Users/lance/Developer/led_ws2812/build -S/Users/lance/Developer/led_ws2812 -GNinja -DBOARD=nrf9160dk_nrf9160_ns -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=On -DNCS_TOOLCHAIN_VERSION:STRING=NONE '-DBOARD_ROOT:STRING=/Users/lance/Developer/renewables-evse-controller;/Users/lance/Developer/led_ws2812' -DCMAKE_BUILD_TYPE:STRING=Debug -DCONFIG_DEBUG_OPTIMIZATIONS:STRING=y -DCONFIG_DEBUG_THREAD_INFO:STRING=y -DCONF_FILE:STRING=/Users/lance/Developer/led_ws2812/prj.conf
    The terminal process terminated with exit code: 1.

    The fix as the error states is to add the color-mapping property:

    color-mapping = < LED_COLOR_ID_GREEN
    LED_COLOR_ID_RED
    LED_COLOR_ID_BLUE >;

Reply
  • Hi,

    The overlay filename is incorrect and should be nrf9160dk_nrf9160_ns.overlay.

    Afterwards, you'll likely encounter another compile error:

    -- Found devicetree overlay: /Users/lance/Developer/led_ws2812/boards/nrf9160dk_nrf9160_ns.overlay
    /Users/lance/Developer/led_ws2812/build/nrf9160dk_nrf9160_ns.dts.pre.tmp:367.32-371.5: Warning (simple_bus_reg): /soc/cryptocell-sw: missing or empty reg/ranges property
    devicetree error: 'color-mapping' is marked as required in 'properties:' in /Users/lance/ncs/zephyr/dts/bindings/led_strip/worldsemi,ws2812-spi.yaml, but does not appear in <Node /soc/peripheral@40000000/spi@b000/ws2812@0 in 'nrf9160dk_nrf9160_ns.dts.pre.tmp'>
    CMake Error at /Users/lance/ncs/zephyr/cmake/dts.cmake:251 (message):
    gen_defines.py failed with return code: 1
    Call Stack (most recent call first):
    /Users/lance/ncs/zephyr/cmake/app/boilerplate.cmake:545 (include)
    /Users/lance/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
    /Users/lance/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
    /Users/lance/Developer/led_ws2812/build/CMakeLists.txt:7 (find_package)


    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/v1.8.0/toolchain/bin/cmake -DWEST_PYTHON=/opt/nordic/ncs/v1.8.0/toolchain/opt/[email protected]/bin/python3.9 -B/Users/lance/Developer/led_ws2812/build -S/Users/lance/Developer/led_ws2812 -GNinja -DBOARD=nrf9160dk_nrf9160_ns -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=On -DNCS_TOOLCHAIN_VERSION:STRING=NONE '-DBOARD_ROOT:STRING=/Users/lance/Developer/renewables-evse-controller;/Users/lance/Developer/led_ws2812' -DCMAKE_BUILD_TYPE:STRING=Debug -DCONFIG_DEBUG_OPTIMIZATIONS:STRING=y -DCONFIG_DEBUG_THREAD_INFO:STRING=y -DCONF_FILE:STRING=/Users/lance/Developer/led_ws2812/prj.conf
    The terminal process terminated with exit code: 1.

    The fix as the error states is to add the color-mapping property:

    color-mapping = < LED_COLOR_ID_GREEN
    LED_COLOR_ID_RED
    LED_COLOR_ID_BLUE >;

Children
No Data
Related