define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)

Im trying to use lvgl with ST7789v display and nRF52832, in nRF Connect.

My .overlay:

#include <zephyr/dt-bindings/display/panel.h>

/ {
    chosen {
        zephyr,display = &st7789v;
    };
 };
 
 &pinctrl {
    spi0_default: spi0_default {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 27)>,
            <NRF_PSEL(SPIM_MOSI, 0, 26)>,
            <NRF_PSEL(SPIM_MISO, 0, 29)>;
        };
    };
    
    spi0_sleep: spi0_sleep {
        group1 {
            psels = <NRF_PSEL(SPIM_SCK, 0, 27)>,
            <NRF_PSEL(SPIM_MOSI, 0, 26)>,
            <NRF_PSEL(SPIM_MISO, 0, 29)>;
            low-power-enable;
        };
    };
    
    &spi0 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = <&spi0_default>;
        pinctrl-1 = <&spi0_sleep>;
        cs-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
        pinctrl-names = "default", "sleep";
        
        st7789v: st7789v@0 {
            compatible = "sitronix,st7789v";
            label = "ST7789V";
            spi-max-frequency = <20000000>;
            reg = <0>;
            cmd-data-gpios = <&gpio0 31 GPIO_ACTIVE_LOW>;
            reset-gpios = <&gpio0 30 GPIO_ACTIVE_LOW>;
            width = <240>;
            height = <240>;
            x-offset = <0>;
            y-offset = <0>;
            vcom = <0x19>;
            gctrl = <0x35>;
            vrhs = <0x12>;
            vdvs = <0x20>;
            mdac = <0x00>;
            lcm = <0x2c>;
            colmod = <0x05>;
            gamma = <0x01>;
            porch-param = [0c 0c 00 33 33];
            cmd2en-param = [5a 69 02 01];
            pwctrl1-param = [a4 a1];
            pvgam-param = [D0 04 0D 11 13 2B 3F 54 4C 18 0D 0B 1F 23];
            nvgam-param = [D0 04 0C 11 13 2C 3F 44 51 2F 1F 1F 20 23];
            ram-param = [00 F0];
            rgb-param = [CD 08 14];
        };
    };
};

My prj.conf:

# Enable logging and RTT DEBUG output
CONFIG_LOG=y
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=1
CONFIG_LOG_PRINTK=y
CONFIG_LOG_MODE_DEFERRED=n

# LVGL
CONFIG_LV_Z_MEM_POOL_SIZE=16384
CONFIG_LV_Z_SHELL=y
CONFIG_MAIN_STACK_SIZE=2048

CONFIG_DISPLAY=y
CONFIG_DISPLAY_LOG_LEVEL_ERR=y

CONFIG_SHELL=y

CONFIG_LVGL=y
CONFIG_LV_MEM_CUSTOM=y
CONFIG_LV_USE_LOG=y
CONFIG_LV_USE_LABEL=y
CONFIG_LV_USE_BTN=y
CONFIG_LV_USE_ARC=y
CONFIG_LV_USE_IMG=y
CONFIG_LV_USE_MONKEY=y
CONFIG_LV_FONT_MONTSERRAT_14=y

When I enable LVGL and build, i got the error:

In file included from /home/santos/ncs/v2.9.0/zephyr/include/zephyr/arch/arm/arch.h:20,
                 from /home/santos/ncs/v2.9.0/zephyr/include/zephyr/arch/cpu.h:19,
                 from /home/santos/ncs/v2.9.0/zephyr/include/zephyr/kernel_includes.h:36,
                 from /home/santos/ncs/v2.9.0/zephyr/include/zephyr/kernel.h:17,
                 from /home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:8:
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/devicetree.h:2729:32: error: 'DT_CHOSEN_zephyr_display_P_width' undeclared here (not in a function); did you mean 'DT_CHOSEN_zephyr_sram_EXISTS'?
 2729 | #define DT_CHOSEN(prop) DT_CAT(DT_CHOSEN_, prop)
      |                                ^~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/devicetree.h:4879:29: note: in definition of macro 'DT_CAT3'
 4879 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
      |                             ^~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:35:24: note: in expansion of macro 'DT_PROP'
   35 | #define DISPLAY_WIDTH  DT_PROP(DISPLAY_NODE, width)
      |                        ^~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/devicetree.h:2729:25: note: in expansion of macro 'DT_CAT'
 2729 | #define DT_CHOSEN(prop) DT_CAT(DT_CHOSEN_, prop)
      |                         ^~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:29:22: note: in expansion of macro 'DT_CHOSEN'
   29 | #define DISPLAY_NODE DT_CHOSEN(zephyr_display)
      |                      ^~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:35:32: note: in expansion of macro 'DISPLAY_NODE'
   35 | #define DISPLAY_WIDTH  DT_PROP(DISPLAY_NODE, width)
      |                                ^~~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:40:35: note: in expansion of macro 'DISPLAY_WIDTH'
   40 |          ((CONFIG_LV_Z_VDB_SIZE * DISPLAY_WIDTH * DISPLAY_HEIGHT) / 100) / 8)
      |                                   ^~~~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:48:21: note: in expansion of macro 'BUFFER_SIZE'
   48 | static uint8_t buf0[BUFFER_SIZE]
      |                     ^~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/devicetree.h:2729:32: error: 'DT_CHOSEN_zephyr_display_P_height' undeclared here (not in a function)
 2729 | #define DT_CHOSEN(prop) DT_CAT(DT_CHOSEN_, prop)
      |                                ^~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/devicetree.h:4879:29: note: in definition of macro 'DT_CAT3'
 4879 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
      |                             ^~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:36:24: note: in expansion of macro 'DT_PROP'
   36 | #define DISPLAY_HEIGHT DT_PROP(DISPLAY_NODE, height)
      |                        ^~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/devicetree.h:2729:25: note: in expansion of macro 'DT_CAT'
 2729 | #define DT_CHOSEN(prop) DT_CAT(DT_CHOSEN_, prop)
      |                         ^~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:29:22: note: in expansion of macro 'DT_CHOSEN'
   29 | #define DISPLAY_NODE DT_CHOSEN(zephyr_display)
      |                      ^~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:36:32: note: in expansion of macro 'DISPLAY_NODE'
   36 | #define DISPLAY_HEIGHT DT_PROP(DISPLAY_NODE, height)
      |                                ^~~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:40:51: note: in expansion of macro 'DISPLAY_HEIGHT'
   40 |          ((CONFIG_LV_Z_VDB_SIZE * DISPLAY_WIDTH * DISPLAY_HEIGHT) / 100) / 8)
      |                                                   ^~~~~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:48:21: note: in expansion of macro 'BUFFER_SIZE'
   48 | static uint8_t buf0[BUFFER_SIZE]
      |                     ^~~~~~~~~~~
In file included from /home/santos/ncs/v2.9.0/zephyr/include/zephyr/toolchain/gcc.h:98,
                 from /home/santos/ncs/v2.9.0/zephyr/include/zephyr/toolchain.h:50,
                 from /home/santos/ncs/v2.9.0/zephyr/include/zephyr/sys/util.h:18,
                 from /home/santos/ncs/v2.9.0/zephyr/include/zephyr/init.h:13,
                 from /home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:7:
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c: In function 'lvgl_init':
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/device.h:92:41: error: '__device_dts_ord_DT_CHOSEN_zephyr_display_ORD' undeclared (first use in this function)
   92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                         ^~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
  137 | #define _DO_CONCAT(x, y) x ## y
      |                          ^
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/device.h:92:33: note: in expansion of macro '_CONCAT'
   92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                 ^~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/device.h:229:37: note: in expansion of macro 'DEVICE_NAME_GET'
  229 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
      |                                     ^~~~~~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/device.h:246:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
  246 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
      |                                  ^~~~~~~~~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:200:44: note: in expansion of macro 'DEVICE_DT_GET'
  200 |         const struct device *display_dev = DEVICE_DT_GET(DISPLAY_NODE);
      |                                            ^~~~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/device.h:92:41: note: each undeclared identifier is reported only once for each function it appears in
   92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                         ^~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
  137 | #define _DO_CONCAT(x, y) x ## y
      |                          ^
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/device.h:92:33: note: in expansion of macro '_CONCAT'
   92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                 ^~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/device.h:229:37: note: in expansion of macro 'DEVICE_NAME_GET'
  229 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
      |                                     ^~~~~~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/include/zephyr/device.h:246:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
  246 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
      |                                  ^~~~~~~~~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:200:44: note: in expansion of macro 'DEVICE_DT_GET'
  200 |         const struct device *display_dev = DEVICE_DT_GET(DISPLAY_NODE);
      |                                            ^~~~~~~~~~~~~
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c: At top level:
/home/santos/ncs/v2.9.0/zephyr/modules/lvgl/lvgl.c:48:16: warning: 'buf0' defined but not used [-Wunused-variable]
   48 | static uint8_t buf0[BUFFER_SIZE]
      |                ^~~~
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /home/santos/ncs/toolchains/b77d8c1312/usr/local/bin/cmake --build /home/santos/Documents/auraZephyr/aura/build/aura

Could you please help me resolve this issue?

Parents
  • Hi,

     

    Your declaration of spi0 seems to be within the scope of &pinctrl {..}.

    Can you try moving it outside of that scope and see if it works better then?

     

    Kind regards,

    Håkon

  • Thanks for your reply, Hakon.

    Like this?

    / {
        chosen {
            zephyr,display = &st7789v;
        };
    };
    
    &pinctrl {
        spi0_default: spi0_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 27)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 26)>,
                        <NRF_PSEL(SPIM_MISO, 0, 29)>;
            };
        };
        
        spi0_sleep: spi0_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 27)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 26)>,
                        <NRF_PSEL(SPIM_MISO, 0, 29)>;
                low-power-enable;
            };
        };
    };
    
    &spi0 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = <&spi0_default>;
        pinctrl-1 = <&spi0_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
    
        st7789v: st7789v@0 {
            compatible = "sitronix,st7789v";
            label = "ST7789V";
            spi-max-frequency = <20000000>;
            reg = <0>;
            cmd-data-gpios = <&gpio0 31 GPIO_ACTIVE_LOW>;
            reset-gpios = <&gpio0 30 GPIO_ACTIVE_LOW>;
            width = <240>;
            height = <240>;
            x-offset = <0>;
            y-offset = <0>;
            vcom = <0x19>;
            gctrl = <0x35>;
            vrhs = <0x12>;
            vdvs = <0x20>;
            mdac = <0x00>;
            lcm = <0x2c>;
            colmod = <0x05>;
            gamma = <0x01>;
            porch-param = [0c 0c 00 33 33];
            cmd2en-param = [5a 69 02 01];
            pwctrl1-param = [a4 a1];
            pvgam-param = [D0 04 0D 11 13 2B 3F 54 4C 18 0D 0B 1F 23];
            nvgam-param = [D0 04 0C 11 13 2C 3F 44 51 2F 1F 1F 20 23];
            ram-param = [00 F0];
            rgb-param = [CD 08 14];
        };
    };


    The error persists. 

Reply
  • Thanks for your reply, Hakon.

    Like this?

    / {
        chosen {
            zephyr,display = &st7789v;
        };
    };
    
    &pinctrl {
        spi0_default: spi0_default {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 27)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 26)>,
                        <NRF_PSEL(SPIM_MISO, 0, 29)>;
            };
        };
        
        spi0_sleep: spi0_sleep {
            group1 {
                psels = <NRF_PSEL(SPIM_SCK, 0, 27)>,
                        <NRF_PSEL(SPIM_MOSI, 0, 26)>,
                        <NRF_PSEL(SPIM_MISO, 0, 29)>;
                low-power-enable;
            };
        };
    };
    
    &spi0 {
        compatible = "nordic,nrf-spim";
        status = "okay";
        pinctrl-0 = <&spi0_default>;
        pinctrl-1 = <&spi0_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
    
        st7789v: st7789v@0 {
            compatible = "sitronix,st7789v";
            label = "ST7789V";
            spi-max-frequency = <20000000>;
            reg = <0>;
            cmd-data-gpios = <&gpio0 31 GPIO_ACTIVE_LOW>;
            reset-gpios = <&gpio0 30 GPIO_ACTIVE_LOW>;
            width = <240>;
            height = <240>;
            x-offset = <0>;
            y-offset = <0>;
            vcom = <0x19>;
            gctrl = <0x35>;
            vrhs = <0x12>;
            vdvs = <0x20>;
            mdac = <0x00>;
            lcm = <0x2c>;
            colmod = <0x05>;
            gamma = <0x01>;
            porch-param = [0c 0c 00 33 33];
            cmd2en-param = [5a 69 02 01];
            pwctrl1-param = [a4 a1];
            pvgam-param = [D0 04 0D 11 13 2B 3F 54 4C 18 0D 0B 1F 23];
            nvgam-param = [D0 04 0C 11 13 2C 3F 44 51 2F 1F 1F 20 23];
            ram-param = [00 F0];
            rgb-param = [CD 08 14];
        };
    };


    The error persists. 

Children
  • Hi,

     

    Sorry for not noticing this before, but this has a breaking change with zephyr 3.7, as the MIPI DBI driver was added:

    https://docs.zephyrproject.org/latest/releases/migration-guide-3.7.html#display

     

    Kind regards,

    Håkon

  • Thank you very much for your reply!

    I managed to get the display working by setting the shield board to st7789v_waveshare_240x240.overlay.

    The solution I found for using this shield with the nRF Connect build interface was to configure CMake with the following line:

    set(SHIELD st7789v_waveshare_240x240)

    I'm not entirely sure why, but the mipi_dbi_st7789v_waveshare_240x240 overlay must be applied outside of the .dts board file that I create. When I try to overlay this node on my .dts file—even after a clean build—the display stops working.

    With these changes, my display now functions perfectly.

    This code print a "Hello World" on display.


    #include <stdio.h>
    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/devicetree.h>
    #include <zephyr/drivers/display.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/drivers/pwm.h>
    #include <lvgl.h>
    #include "lvgl_sample.h"
    
    #define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
    #include <zephyr/logging/log.h>
    LOG_MODULE_REGISTER(app);
    
    #define SLEEP_TIME_MS   10
    
    static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
    static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(DT_ALIAS(led1), gpios);
    
    int main(void) {
    	int ret;
    	uint32_t cont = 0;
    	int blink = 0;
    
    	if (!gpio_is_ready_dt(&led0)) {
    		return 0;
    	}
    	
    	if (!gpio_is_ready_dt(&led1)) {
    		return 0;
    	}
    	
    	ret = gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE);
    	if (ret < 0) {
    		return 0;
    	}
    	gpio_pin_set_dt(&led0, 1);
    	
    	ret = gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE);
    	if (ret < 0) {
    		return 0;
    	}
    	
    	const struct device *display_dev;
    	display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
    	if (!device_is_ready(display_dev)) {
    		LOG_ERR("Device not ready, aborting test");
    		return 0;
    	}
    	
    	lv_obj_t *hello_world_label = lv_label_create(lv_scr_act());
        lv_label_set_text(hello_world_label, "Hello world!");
        lv_obj_align(hello_world_label, LV_ALIGN_CENTER, 0, 0);
    	
    	lv_task_handler();
    	display_blanking_off(display_dev);
    	
    	while (1) {
    		cont++;
    		if(cont > 100){
    			gpio_pin_set_dt(&led1, blink);
    			blink = ~blink;
    			cont = 0;
    		}
    		lv_timer_handler();
    		k_msleep(SLEEP_TIME_MS);
    	}
    	return 0;
    }
Related