nRF52832 with SK6812 LEDs

Hello,

I tried to run the example code for the ws2812 (which can be found at C:\ncs\v2.4.1\v2.4.1\zephyr\samples\drivers\led_ws2812) for the nRF52832 using nRF Connect SDK (v2.4.1).

Looking at the nrf52dk_nrf52832.overlay, it looks like MOSI would be used on P0.23.

&arduino_spi { /* MOSI on D11 / P0.23 */

I am trying to experiment using the nRF52 DK board. 
I have a known working LED ring which lights up from another board.

The code builds fine but when I run it, I see the following in the terminal.

Using a Saleae Logic analyzer, I don't see anything on P0.23. 

I tried adding the following from nrf52dk_nrf52832.dts but I ended up with the same message in the terminal and didn't see anything on the logic analyzer.

I tried multiple pins and couldn't see any changes on the IO lines that looked like the required signal for the WS2812 LEDs.

&spi2_default {
    group1 {
        psels = <NRF_PSEL(SPIM_SCK, 0, 25)>, <NRF_PSEL(SPIM_MISO, 0, 24)>,
        <NRF_PSEL(SPIM_MOSI, 0, 12)>;
    };
};

/*
 * Copyright (c) 2017 Linaro Limited
 * Copyright (c) 2018 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <errno.h>
#include <string.h>

#define LOG_LEVEL 4
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main);

#include <zephyr/kernel.h>
#include <zephyr/drivers/led_strip.h>
#include <zephyr/device.h>
#include <zephyr/drivers/spi.h>
#include <zephyr/sys/util.h>

#define STRIP_NODE		DT_ALIAS(led_strip)
#define STRIP_NUM_PIXELS	DT_PROP(DT_ALIAS(led_strip), chain_length)

#define DELAY_TIME K_MSEC(50)

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

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

struct led_rgb pixels[STRIP_NUM_PIXELS];

static const struct device *const strip = DEVICE_DT_GET(STRIP_NODE);

int main(void)
{
	size_t cursor = 0, color = 0;
	int rc;

	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 0;
	}

	LOG_INF("Displaying pattern on strip");
	while (1) {
		memset(&pixels, 0x00, sizeof(pixels));
		memcpy(&pixels[cursor], &colors[color], sizeof(struct led_rgb));
		rc = led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS);

		if (rc) {
			LOG_ERR("couldn't update strip: %d", rc);
		}

		cursor++;
		if (cursor >= STRIP_NUM_PIXELS) {
			cursor = 0;
			color++;
			if (color == ARRAY_SIZE(colors)) {
				color = 0;
			}
		}

		k_sleep(DELAY_TIME);
	}
	return 0;
}

0334.prj.conf

nrf52dk_nrf52832.dts

Has anyone had success with the WS2812 or SK6812 with the nRF52832 and nRF Connect SDK?

Thanks.

Parents
  • I don't have a WS2812 LED ring currently, will ask in office if anyone has one, But you might also want to check out older post here on the forum on the led example: https://devzone.nordicsemi.com/search?q=led_ws2812 

    You can also reach out in the Zephyr community https://zephyrproject.org/community/ .

    Can you also share the datasheet for the LED ring that you are using? 


    Regards,
    Jonathan

  • I see now that I am using NCS v 2.4.2. 

    Here are the files:
    3568.led_ws2812.zip


    Here is just the hex file:1513.zephyr.hex

    No major changes only made sure to include the conf and overlay files



    Regards,
    Jonathan


  • Hello Jonathan,

    I am not what exactly I did but trying changing the prj.conf in the project I had resulted in the code no longer compiling.  It is unclear to what I did because when I perform a beyond Compare of the files, I don't see differences. 

    Here is what is in the output form the Terminal in visual studio code.  (I am was using NCS 2.4.1)

    [168/178] Linking C executable zephyr\zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map
    cmd.exe /C "cd . && C:\ncs\toolchains\c57af46cb7\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe  -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr\zephyr_pre0.elf  -fuse-ld=bfd  -T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=C:/ncs/v2.4.1/v2.4.1/zephyr/samples/drivers/led_ws2812/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a  zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a  zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a  zephyr/lib/libc/minimal/liblib__libc__minimal.a  zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a  zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/led_strip/libdrivers__led_strip.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/spi/libdrivers__spi.a  zephyr/drivers/timer/libdrivers__timer.a  modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -L"c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v7e-m/nofp"  -LC:/ncs/v2.4.1/v2.4.1/zephyr/samples/drivers/led_ws2812/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -mcpu=cortex-m4  -mthumb  -mabi=aapcs  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie && cmd.exe /C "cd /D C:\ncs\v2.4.1\v2.4.1\zephyr\samples\drivers\led_ws2812\build\zephyr && C:\ncs\toolchains\c57af46cb7\opt\bin\cmake.exe -E echo ""
    c:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: zephyr/drivers/led_strip/libdrivers__led_strip.a(ws2812_spi.c.obj):(.rodata.ws2812_spi_0_cfg+0x0): undefined reference to `__device_dts_ord_107'
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\c57af46cb7\opt\bin\cmake.EXE' --build 'c:\ncs\v2.4.1\v2.4.1\zephyr\samples\drivers\led_ws2812\build'

    I downloaded NCS V2.5.0-rc2.

    I found the WS2812 example, was able to compile it using the Build Configuration based on the screenshot you shared. 

    The example just worked.  I am thankful it worked but I am struggling to understand how to modify things in NCS/zephyr.  When something breaks, I am having issues figuring what is wrong.  If there is other zephyr training that you can recommend, I would love to get some.

    Thanks for your assistance.

  • jablackann said:
    I found the WS2812 example, was able to compile it using the Build Configuration based on the screenshot you shared. 

    Good to hear that you got it working.

    jablackann said:
    If there is other zephyr training that you can recommend, I would love to get some.

    We do have the DevAcadamy, but that might not be exactly what you are looking for:https://academy.nordicsemi.com 

    There is also our webinars that can be foundhere: https://webinars.nordicsemi.com/videos , contain different types of showcases and introductions. 

    Then you also have the Zephyr YouTube channel, it does contains some very informative videos, https://www.youtube.com/@ZephyrProject/videos 



    As for continue debugging issues, its nice if you create new tickets for new topics here on DevZone, keeps it easier to find the correct topics when searching. 
    Happy to help!

    Regards,
    Jonathan

  • I tried to see if I could move the MOSI from P0.23 to a P0.08 and it seems to have broken something.

    I tried the following to change the pin and it didn't seem to work.

    &spi2_default {
        group1 {
            psels = <NRF_PSEL(SPIM_MOSI, 0, 8)>;

        };
    };

    &spi2_sleep {
        group1 {
            psels = <NRF_PSEL(SPIM_MOSI, 0, 8)>;

        };
    };

    I tried to remove this code and now I can't get the LED ring to work at all using P0.23.

    I hooked up the UART and it is spitting out the following message.

    As far as I can tell the code is back to the original of what I started with.  I am using NCS 2.5.0-rc2

    I do see the following before the code builds.

    ")
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    CMake Warning at ../../../soc/arm/nordic_nrf/nrf52/CMakeLists.txt:15 (message):
      Both SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 and an NRF SPIM driver are
      enabled, therefore PAN 58 will apply if RXD.MAXCNT == 1 and TXD.MAXCNT <= 1

    I am not sure how to get the code to work properly again unless I get rid of NCS and try again.

Reply
  • I tried to see if I could move the MOSI from P0.23 to a P0.08 and it seems to have broken something.

    I tried the following to change the pin and it didn't seem to work.

    &spi2_default {
        group1 {
            psels = <NRF_PSEL(SPIM_MOSI, 0, 8)>;

        };
    };

    &spi2_sleep {
        group1 {
            psels = <NRF_PSEL(SPIM_MOSI, 0, 8)>;

        };
    };

    I tried to remove this code and now I can't get the LED ring to work at all using P0.23.

    I hooked up the UART and it is spitting out the following message.

    As far as I can tell the code is back to the original of what I started with.  I am using NCS 2.5.0-rc2

    I do see the following before the code builds.

    ")
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/ncs/toolchains/c57af46cb7/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    CMake Warning at ../../../soc/arm/nordic_nrf/nrf52/CMakeLists.txt:15 (message):
      Both SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 and an NRF SPIM driver are
      enabled, therefore PAN 58 will apply if RXD.MAXCNT == 1 and TXD.MAXCNT <= 1

    I am not sure how to get the code to work properly again unless I get rid of NCS and try again.

Children
  • Can you create a new project and copy the /led_ws2812 sample?  should not need to re-install NCS every time. 


    	spi2_default: spi2_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 25)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 23)>,
    				<NRF_PSEL(SPIM_MISO, 0, 24)>;
    		};
    	};
    
    	spi2_sleep: spi2_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 25)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 23)>,
    				<NRF_PSEL(SPIM_MISO, 0, 24)>;
    			low-power-enable;
    		};
    	};


    This should be what it originally was, does it not work when you revert to using the setup ? 




    jablackann said:
    I do see the following before the code builds.

    The PAN error warning should be fine in this case as I believe that it will not cause an issue for this use case. 

    Regards,
    Jonathan

Related