Using ws2812 with nrf52840

I am trying to control ws2812 LED (1 LED) with NRF52840 using nrf connect SDK, I was able to control it with no problem when I set building optimization to debug optimization, but when I set optimization to size or speed optimization I get a hard fault message when function 

led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS); is called
[00:00:04.002,014] <err> os: ***** USAGE FAULT *****
[00:00:04.002,349] <err> os:   Attempt to execute undefined instruction
[00:00:04.002,777] <err> os: r0/a1:  0x01000002  r1/a2:  0x00000000  r2/a3:  0x0000001f
[00:00:04.003,295] <err> os: r3/a4:  0x07ffffff r12/ip:  0x00000100 r14/lr:  0x003d0900
[00:00:04.003,814] <err> os:  xpsr:  0x21000000
[00:00:04.004,*** Booting My Application v3.5.0-c1ab2163a399 ***
*** Using nRF Connect SDK v2.8.0-a2386bfc8401 ***
*** Using Zephyr OS v3.7.99-0bc3393fb112 ***
I am using nrf connect sdk 2.8.0
BR
M.ElSabagh
  • Here is how my overlay looks like 

    &spi3 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	pinctrl-0 = <&spi3_default_alt>;
    	pinctrl-1 = <&spi3_sleep_alt>;
    	// cs-gpios = <&gpio1 8 GPIO_ACTIVE_LOW>; /* D4 */ 
        pinctrl-names = "default", "sleep";
    
    	led_strip: ws2812@0 {
    		compatible = "worldsemi,ws2812-spi";
    
    		/* 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>;
    	};
    };
    
    
    
    spi3_default_alt: spi3_default_alt {
    		group1 {
    			psels = <NRF_PSEL(SPIM_MOSI, 0, 9)>;
    			low-power-enable;
    		};
    	};
    
    	spi3_sleep_alt: spi3_sleep_alt {
    		group1 {
    			psels = <NRF_PSEL(SPIM_MOSI, 0, 9)>;
    			low-power-enable;
    		};
    	};

  • Hello,

    I have checked your overlay file. It is missing include header file. 

    spi3_default_alt and spi3_sleep_alt should be inside pinctrl node.

    Can you try this following overlay instead?

    #include <zephyr/dt-bindings/led/led.h>
    #include "../nrf52-bindings.h"
    
    &pinctrl {
        spi3_default_alt: spi3_default_alt {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 10)>,
                       <NRF_PSEL(SPIM_MOSI, 0, 9)>;
            };
        };
    
        spi3_sleep_alt: spi3_sleep_alt {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 10)>,
                       <NRF_PSEL(SPIM_MOSI, 0, 9)>;
                low-power-enable;
            };
        };
    };
    
    &spi3 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = <&spi3_default_alt>;
        pinctrl-1 = <&spi3_sleep_alt>;
        pinctrl-names = "default", "sleep";
    
        led_strip: ws2812@0 {
            compatible = "worldsemi,ws2812-spi";
    
            /* 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;
        };
    };

  • I actually have those on top of my file 

    #include <nordic/nrf52840_qiaa.dtsi>
    #include <zephyr/dt-bindings/led/led.h>
    
    #include "../../../nrf52-bindings.h"
     also as I mentioned everything is working fine when the build is set to debug optimization but I get those errors only with size or speed optimization build

Related