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

  • I've now found that this will not coexist with other SPI devices.

    If I declare the other two spi pins it does not work, presumably because SPI driver is not expecting a 1-wire device.

    With just mosi-pin declared it works it there are no other SPIs in the configuration.

    If there are other devices the build process complains that sck-pin and miso-pin are undefined and the process does not complete.

    It seems odd to me that it builds at all without all 3 pins defined.

    Is there anything I can do about this? Alternatively, is there a proper driver for 1-wire devices?

  • 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.

Reply
  • 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.

Children
No Data
Related