GPIO Interrupt Configuration for Pressure and Gyro Sensors on nRF54L15 (SDK 3.0.2)

I am using the nRF54L15 and NCS SDK v3.0.2 in my project. I need to wake up the board via interrupts from a pressure sensor and a gyro sensor.

The GPIO requirements are as follows:

  • Pressure sensor interrupt: P0.02

  • Gyro sensor interrupts: P0.00 and P0.01

To configure the pressure sensor interrupt, I added the following to my .overlay file:

/ {
press_int: press_int {
gpios = <&gpio0 2 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "PRESS_INT";
};

aliases {
press-int = &press_int;
};
};

In main.c, I used

#define PRESS_NODE DT_ALIAS(press_int)
static const struct gpio_dt_spec press = GPIO_DT_SPEC_GET(PRESS_NODE, gpios);

However, during compilation, I get the following error:

identifier "__device_dts_ord_DT_N_S_press_0_P_gpios_IDX_0_PH_ORD" is undefined

Could you please advise if I need to configure this GPIO differently, or if there's something missing in my device tree or code setup?

Best regards,
Hashir

Parents
  • Hello,

    I suspect that you are trying to use the pins already being used by the UART by default. If you look at the back of your DK, you can see the default uses for the pins. However, it is possible to disable the UART, or move it to use other pins.

    Without seeing your application it is difficult to say exactly why it fails. Is it possible to upload the application, so that I can try to build it myself?

    Best regards,

    Edvin

Reply
  • Hello,

    I suspect that you are trying to use the pins already being used by the UART by default. If you look at the back of your DK, you can see the default uses for the pins. However, it is possible to disable the UART, or move it to use other pins.

    Without seeing your application it is difficult to say exactly why it fails. Is it possible to upload the application, so that I can try to build it myself?

    Best regards,

    Edvin

Children
  • Hi,
    /cfs-file/__key/communityserver-discussions-components-files/4/Sample_5F00_Project.zip

    This is the zip file.

    I am trying to enable the following GPIO-based interrupts:

    • Pressure sensor interrupt on P0.02

    • Gyro sensor interrupts on P0.00 and P0.01

    The GPIO-based wakeup works correctly on P0.02, but wakeup does not occur on P0.00 and P0.01.

    Are P0.00 and P0.01 reserved for other functions, or do they require any additional configuration to enable wakeup functionality?

    main.c

    #include <zephyr/kernel.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/sys/printk.h>
    #include <zephyr/drivers/uart.h>
    #include <zephyr/drivers/timer/nrf_grtc_timer.h>
    #include <zephyr/drivers/hwinfo.h>
    
    #define PRESS_NODE DT_ALIAS(press_int)
    #define MEMS_INT1_NODE DT_ALIAS(mems_int1)
    #define MEMS_INT2_NODE DT_ALIAS(mems_int2)
    #define ACTIVE_TIMEOUT_MS 15000  // 20 seconds before auto-sleep
    #define GRTC_WAKEUP_S     12      // GRTC wakeup after 5s in sleep
    
    const struct gpio_dt_spec press = GPIO_DT_SPEC_GET(PRESS_NODE, gpios);
    const struct gpio_dt_spec mems_int1 = GPIO_DT_SPEC_GET(MEMS_INT1_NODE, gpios);
    const struct gpio_dt_spec mems_int2 = GPIO_DT_SPEC_GET(MEMS_INT2_NODE, gpios);
    
    void enter_system_off(void)
    {
    
        hwinfo_clear_reset_cause();
    	int err = z_nrf_grtc_wakeup_prepare(GRTC_WAKEUP_S * USEC_PER_SEC);
        if (err < 0) {
            printf("GRTC wakeup prepare failed: %d\n", err);
        } else {
            printf("Will also wake from GRTC in %d sec\n", GRTC_WAKEUP_S);
        }
        sys_poweroff();
    }
    
    void schedule_sleep_work(struct k_work *work)
    {
        printf("Sleep timeout reached, going to system off\n");
        enter_system_off();
    }
    
    K_WORK_DELAYABLE_DEFINE(ble_sleep_work, schedule_sleep_work);
    void rtc_wakeup_schedule(void){
    	// k_work_schedule(&adv_on_work, K_NO_WAIT);
        // Schedule system-off after ACTIVE_TIMEOUT_MS
        k_work_schedule(&ble_sleep_work, K_MSEC(ACTIVE_TIMEOUT_MS));
    }
    
    int setup_press_int_wakeup(){
    	int rc;
    	if (!device_is_ready(press.port)) {
    	printf("Pressure INT GPIO device not ready");
    	return 0;
        }
    	rc = gpio_pin_configure_dt(&press, GPIO_INPUT);
        if (rc < 0) {
            printf("GPIO config failed (%d)\n", rc);
            return 0;
        }
    
        rc = gpio_pin_interrupt_configure_dt(&press, GPIO_INT_LEVEL_ACTIVE);
        if (rc < 0) {
            printf("GPIO interrupt config failed (%d)\n", rc);
            return 0;
        }
    	return rc;
    }
    
    int setup_memsint1_wakeup(void) {
        int rc=1;
    
        if (!device_is_ready(mems_int1.port)) {
            printf("MEMS INT1 GPIO device not ready\n");
            return 0;
        }
    printf("Device ready. Configuring pin...\n");
        rc = gpio_pin_configure_dt(&mems_int1, GPIO_INPUT);
        if (rc < 0) {
            printf("MEMS INT1 GPIO config failed \n");
            return 0;
        }
    printf("Pin config result: %d\n", rc);
        rc = gpio_pin_interrupt_configure_dt(&mems_int1, GPIO_INT_LEVEL_ACTIVE);
    
        if (rc < 0) {
            printf("MEMS INT1 interrupt config failed \n");
            return 0;
        }
    printf("Interrupt config result: %d\n", rc);
        return rc;
    }
    
    int setup_memsint2_wakeup(void) {
        int rc;
    
        if (!device_is_ready(mems_int2.port)) {
            printf("MEMS INT2 GPIO device not ready\n");
            return -ENODEV;
        }
    
        rc = gpio_pin_configure_dt(&mems_int2, GPIO_INPUT);
        if (rc < 0) {
            printf("MEMS INT2 GPIO config failed (%d)\n", rc);
            return rc;
        }
    
        rc = gpio_pin_interrupt_configure_dt(&mems_int2, GPIO_INT_LEVEL_ACTIVE);
        if (rc < 0) {
            printf("MEMS INT2 interrupt config failed (%d)\n", rc);
            return rc;
        }
        return 0;
    }
    
    void print_reset_cause(void)
    {
        uint32_t cause;
        hwinfo_get_reset_cause(&cause);
    
        if (cause & RESET_PIN) {
            // printf("Reset by pin\n");
    		printf("Start\n");
        } else if (cause & RESET_SOFTWARE) {
            printf("Reset by software\n");
        } else if (cause & RESET_POR) {
            printf("Power-on reset\n");
        } else if (cause & RESET_LOW_POWER_WAKE) {
            // printf("Wake from low power state\n");
    		printf("GPIO wakeup\n");
        } else {
            // printf("Reset cause unknown: 0x%08X\n", cause);
    		printf("RTC wakeup\n");
        }
    }
    int main(void)
    {
            print_reset_cause();
            setup_press_int_wakeup();
    	setup_memsint1_wakeup();
            
    	rtc_wakeup_schedule();
            return 0;
            while(1){
                 k_msleep(1000);   
            }
    }
    

    .overlay

    / {
        nfc_pins: nfc-pins {
            status = "disabled";
        };
    };
    
    / {
        gpio_keys: gpio_keys {
            compatible = "gpio-keys";
    
            mems_int1: mems_int1_0 {
                gpios = <&gpio0 0 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; // P0.00
                label = "MEMS INT1";
            };
    
            mems_int2: mems_int2_0 {
                gpios = <&gpio0 1 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; // P0.01
                label = "MEMS INT2";
            };
        };
    
        aliases {
            mems-int1 = &mems_int1;
            mems-int2 = &mems_int2;
        };
    };
    
    
    / {
        press_int: press_int {
            compatible = "gpio-keys";
    
            press: press_0 {
                gpios = <&gpio0 2 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
                label = "PRESS_INT";
                
            };
        };
    
        aliases {
            press-int = &press;
        };
    };
    
    
    /delete-node/ &{/pin-controller/pwm20_default/group1/};
    /delete-node/ &{/pin-controller/pwm20_sleep/group1/};
    /delete-node/ &led1;
    /delete-node/ &led2;
    /delete-node/ &led3;
    /delete-node/ &button2;
    /delete-node/ &button3;
    /delete-node/ &button0;

    .conf

    CONFIG_UART_CONSOLE=y
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_ASYNC_API=n
    CONFIG_PM_DEVICE=y
    CONFIG_GPIO=y
    CONFIG_CRC=y
    CONFIG_POWEROFF=y
    CONFIG_HWINFO=y
    CONFIG_DK_LIBRARY=y
    CONFIG_NRFX_GRTC=y
    CONFIG_COUNTER=y
    
    CONFIG_NFCT_PINS_AS_GPIOS=y
    

  • What I can see in my build log is not the same as you saw:

    C:\nordic\SDKs\ncs\my_projects\3.0.2\cust\Sample_Project>west build -b nrf54l15dk/nrf54l15/cpuapp -d _build
    -- west build: generating a build system
    Loading Zephyr module(s) (Zephyr base): sysbuild_default
    -- Found Python3: C:/ncs/toolchains/0b393f9e1b/opt/bin/python.exe (found suitable version "3.12.4", minimum required is "3.10") found components: Interpreter
    -- Cache files will be written to: C:/nordic/SDKs/ncs/v3.0.2/zephyr/.cache
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf54l15dk, qualifiers: nrf54l15/cpuapp
    Parsing C:/nordic/SDKs/ncs/v3.0.2/zephyr/share/sysbuild/Kconfig
    Loaded configuration 'C:/nordic/SDKs/ncs/my_projects/3.0.2/cust/Sample_Project/_build/_sysbuild/empty.conf'
    Merged configuration 'C:/nordic/SDKs/ncs/my_projects/3.0.2/cust/Sample_Project/_build/_sysbuild/empty.conf'
    Configuration saved to 'C:/nordic/SDKs/ncs/my_projects/3.0.2/cust/Sample_Project/_build/zephyr/.config'
    Kconfig header saved to 'C:/nordic/SDKs/ncs/my_projects/3.0.2/cust/Sample_Project/_build/_sysbuild/autoconf.h'
    --
       ************************************
       * Running CMake for Sample_Project *
       ************************************
    
    Loading Zephyr default modules (Zephyr base).
    -- Application: C:/nordic/SDKs/ncs/my_projects/3.0.2/cust/Sample_Project
    -- CMake version: 3.21.0
    -- Found Python3: C:/ncs/toolchains/0b393f9e1b/opt/bin/python.exe (found suitable version "3.12.4", minimum required is "3.10") found components: Interpreter
    -- Cache files will be written to: C:/nordic/SDKs/ncs/v3.0.2/zephyr/.cache
    -- Zephyr version: 4.0.99 (C:/nordic/SDKs/ncs/v3.0.2/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf54l15dk, qualifiers: nrf54l15/cpuapp
    -- Found host-tools: zephyr 0.17.0 (C:/ncs/toolchains/0b393f9e1b/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.17.0 (C:/ncs/toolchains/0b393f9e1b/opt/zephyr-sdk)
    -- Found Dtc: C:/ncs/toolchains/0b393f9e1b/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found BOARD.dts: C:/nordic/SDKs/ncs/v3.0.2/zephyr/boards/nordic/nrf54l15dk/nrf54l15dk_nrf54l15_cpuapp.dts
    -- Found devicetree overlay: C:/nordic/SDKs/ncs/my_projects/3.0.2/cust/Sample_Project/nrf54l15dk_nrf54l15_cpuapp.overlay
    devicetree error: /aliases: undefined node label 'led1'
    CMake Error at C:/nordic/SDKs/ncs/v3.0.2/zephyr/cmake/modules/dts.cmake:305 (execute_process):
      execute_process failed command indexes:
    
        1: "Child return code: 1"
    
    Call Stack (most recent call first):
      C:/nordic/SDKs/ncs/v3.0.2/zephyr/cmake/modules/zephyr_default.c-- Configuring incomplete, errors occurred!
    make:133 (include)
      C:/nordic/SDKs/ncs/v3.0.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      C:/nordic/SDKs/ncs/v3.0.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      CMakeLists.txt:2 (find_package)
    
    
    CMake Error at cmake/modules/sysbuild_extensions.cmake:514 (message):
      CMake configure failed for Zephyr project: Sample_Project
    
      Location: C:/nordic/SDKs/ncs/my_projects/3.0.2/cust/Sample_Project
    Call Stack (most recent call first):
      cmake/modules/sysbuild_images.cmake:43 (ExternalZephyrProject_Cmake)
      cmake/modules/sysbuild_default.cmake:21 (include)
      C:/nordic/SDKs/ncs/v3.0.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:75 (include)
      C:/nordic/SDKs/ncs/v3.0.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
      C:/nordic/SDKs/ncs/v3.0.2/zephyr/share/sysbuild-package/cmake/SysbuildConfig.cmake:8 (include)
      template/CMakeLists.txt:10 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    See also "C:/nordic/SDKs/ncs/my_projects/3.0.2/cust/Sample_Project/_build/CMakeFiles/CMakeOutput.log".
    ←[91mFATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\0b393f9e1b\opt\bin\cmake.EXE' -DWEST_PYTHON=C:/ncs/toolchains/0b393f9e1b/opt/bin/python.exe '-BC:\nordic\SDKs\ncs\my_projects\3.0.2\cust\Sample_Project\_build' -GNinja -DBOARD=nrf54l15dk/nrf54l15/cpuapp '-SC:\nordic\SDKs\ncs\v3.0.2\zephyr\share\sysbuild' '-DAPP_DIR:PATH=C:\nordic\SDKs\ncs\my_projects\3.0.2\cust\Sample_Project'
    ←[0m

    I can work this out, but if I don't see the same as you, then perhaps we are not looking at the same project. If I don't see the same output, what is the difference between the application that I am working on and the application that you have?

    I see that you deleted a bunch of nodes at the bottom of your .overlay. Does the build log not mention a lacking LED1? If so, did you modify any of the drivers in the SDK?

    Best regards,

    Edvin

Related