nrf9160 GPTIOTE and DPPI pub/sub won't fire

I'm looking to test the DPPI peripheral on the dev-kit, and to that end I though a good example would be to setup the DPPI peripheral to trigger an event when a button is pushed, and toggle the output to one of the LEDs. 

I'm having trouble getting my example to do anything though, and I can't find anymore settings in the datasheet or the nrfx drivers to show what configuration I am missing.

My attempt at this is below:

#include <zephyr.h>
#include <hal/nrf_gpiote.h>
#include <hal/nrf_dppi.h>

#define PUBLISH_EVENT_INDEX  (0)
#define SUBSCRIBE_TASK_INDEX (1)
#define DPPI_CHANNEL         (0)

/** @brief Set bit at given position. */
#define DPPI_BIT_SET(pos) (1uL << (pos))


void main(void) {
	printk("The sample has started\n");

	/* Configure GPIOTE Index 0 to be an Event */
    nrf_gpiote_event_configure(PUBLISH_EVENT_INDEX,SW0_GPIO_PIN,NRF_GPIOTE_POLARITY_HITOLO);

    /* Configure GPIOTE Index 1 to be a Task*/
    nrf_gpiote_task_configure(SUBSCRIBE_TASK_INDEX,LED3_GPIO_PIN,NRF_GPIOTE_POLARITY_TOGGLE,NRF_GPIOTE_INITIAL_VALUE_LOW);

    /* Index 0 will Publish on DPPI Channel 0 */
    nrf_gpiote_publish_set(NRF_GPIOTE_EVENTS_IN_0,DPPI_CHANNEL);

    /* Index 1 will Subscribe on DPPI Channel 0 */
    nrf_gpiote_subscribe_set(NRF_GPIOTE_TASKS_OUT_1,DPPI_CHANNEL);

    /* Enable Publish and Subscribe */
    nrf_gpiote_event_enable(PUBLISH_EVENT_INDEX);
    nrf_gpiote_task_enable(SUBSCRIBE_TASK_INDEX);

    /* Enable DPPI Channel */
    nrf_dppi_channels_enable(NRF_DPPIC, DPPI_BIT_SET(DPPI_CHANNEL));

    /* Validate things did get enabled */
    printk("[0] is %d\n",nrf_gpiote_te_is_enabled(PUBLISH_EVENT_INDEX));
    printk("[1] is %d\n",nrf_gpiote_te_is_enabled(SUBSCRIBE_TASK_INDEX));
    printk("[2] is %d\n",nrf_dppi_channel_check(NRF_DPPIC,DPPI_CHANNEL));

}

I also modified the Secure Bootloader to set the DPPI peripheral to Unsecure, and to also unlock all of the DPPI channels by adding this line to the spm.c file:

	    NRF_SPU->DPPI[0].PERM = 0; // unsecures all

Before I did that the "nrf_dppi_channel_check" would return false (which is what it is supposed to do).

A full example run (showing the bootloader as well) looks like this:

***** Booting Zephyr OS v1.13.99-ncs1-5781-g1937b41459ca *****
Flash region		Domain		Permissions
00 0x00000 0x02000 	Secure		rwxl
01 0x02000 0x04000 	Secure		rwxl
02 0x04000 0x06000 	Secure		rwxl
03 0x06000 0x08000 	Secure		rwxl
04 0x08000 0x0a000 	Secure		rwxl
05 0x0a000 0x0c000 	Secure		rwxl
06 0x0c000 0x0e000 	Secure		rwxl
07 0x0e000 0x10000 	Secure		rwxl
08 0x10000 0x12000 	Non-Secure	rwxl
09 0x12000 0x14000 	Non-Secure	rwxl
10 0x14000 0x16000 	Non-Secure	rwxl
11 0x16000 0x18000 	Non-Secure	rwxl
12 0x18000 0x1a000 	Non-Secure	rwxl
13 0x1a000 0x1c000 	Non-Secure	rwxl
14 0x1c000 0x1e000 	Non-Secure	rwxl
15 0x1e000 0x20000 	Non-Secure	rwxl
16 0x20000 0x22000 	Non-Secure	rwxl
17 0x22000 0x24000 	Non-Secure	rwxl
18 0x24000 0x26000 	Non-Secure	rwxl
19 0x26000 0x28000 	Non-Secure	rwxl
20 0x28000 0x2a000 	Non-Secure	rwxl
21 0x2a000 0x2c000 	Non-Secure	rwxl
22 0x2c000 0x2e000 	Non-Secure	rwxl
23 0x2e000 0x30000 	Non-Secure	rwxl
24 0x30000 0x32000 	Non-Secure	rwxl
25 0x32000 0x34000 	Non-Secure	rwxl
26 0x34000 0x36000 	Non-Secure	rwxl
27 0x36000 0x38000 	Non-Secure	rwxl
28 0x38000 0x3a000 	Non-Secure	rwxl
29 0x3a000 0x3c000 	Non-Secure	rwxl
30 0x3c000 0x3e000 	Non-Secure	rwxl
31 0x3e000 0x40000 	Non-Secure	rwxl

SRAM region		Domain		Permissions
00 0x00000 0x01000	Secure		rwxl
01 0x01000 0x02000	Secure		rwxl
02 0x02000 0x03000	Secure		rwxl
03 0x03000 0x04000	Secure		rwxl
04 0x04000 0x05000	Secure		rwxl
05 0x05000 0x06000	Secure		rwxl
06 0x06000 0x07000	Secure		rwxl
07 0x07000 0x08000	Secure		rwxl
08 0x08000 0x09000	Non-Secure	rwxl
09 0x09000 0x0a000	Non-Secure	rwxl
10 0x0a000 0x0b000	Non-Secure	rwxl
11 0x0b000 0x0c000	Non-Secure	rwxl
12 0x0c000 0x0d000	Non-Secure	rwxl
13 0x0d000 0x0e000	Non-Secure	rwxl
14 0x0e000 0x0f000	Non-Secure	rwxl
15 0x0f000 0x10000	Non-Secure	rwxl
16 0x10000 0x11000	Non-Secure	rwxl
17 0x11000 0x12000	Non-Secure	rwxl
18 0x12000 0x13000	Non-Secure	rwxl
19 0x13000 0x14000	Non-Secure	rwxl
20 0x14000 0x15000	Non-Secure	rwxl
21 0x15000 0x16000	Non-Secure	rwxl
22 0x16000 0x17000	Non-Secure	rwxl
23 0x17000 0x18000	Non-Secure	rwxl
24 0x18000 0x19000	Non-Secure	rwxl
25 0x19000 0x1a000	Non-Secure	rwxl
26 0x1a000 0x1b000	Non-Secure	rwxl
27 0x1b000 0x1c000	Non-Secure	rwxl
28 0x1c000 0x1d000	Non-Secure	rwxl
29 0x1d000 0x1e000	Non-Secure	rwxl
30 0x1e000 0x1f000	Non-Secure	rwxl
31 0x1f000 0x20000	Non-Secure	rwxl


DPPI NONSECURE
Peripheral		Domain		Status
00 NRF_P0		Non-Secure	OK
01 NRF_CLOCK		Non-Secure	OK
02 NRF_RTC1		Non-Secure	OK
03 NRF_NVMC		Non-Secure	OK
04 NRF_UARTE1		Non-Secure	OK
05 NRF_UARTE2		Secure		SKIP
06 NRF_IPC		Non-Secure	OK
07 NRF_VMC		Non-Secure	OK
08 NRF_FPU		Non-Secure	ERROR
09 NRF_EGU1		Non-Secure	OK
10 NRF_EGU2		Non-Secure	OK
11 NRF_TWIM2		Non-Secure	OK
12 NRF_SPIM3		Non-Secure	OK
13 NRF_TIMER0		Non-Secure	OK
14 NRF_TIMER1		Non-Secure	OK
15 NRF_TIMER2		Non-Secure	OK
16 NRF_SAADC		Non-Secure	OK
17 NRF_DPPI		Non-Secure	OK
18 NRF_GPIOTE1		Non-Secure	OK

SPM: MSP_NS 20021570
SPM: prepare to jump to Non-Secure image
***** Booting Zephyr OS v1.13.99-ncs1-5781-g1937b41459ca *****
The sample has started
[0] is 1
[1] is 1
[2] is 1

Any thoughts on what I am missing?

Thank you so much!

  • I did figure this out.  The GPIO input pin still needs to be configured like this:

    nrf_gpio_cfg_input(SW0_GPIO_PIN,NRF_GPIO_PIN_PULLUP);

    That wasn't super clear to me from the datasheet where it is describing what the GPIOTE block does when it configures a pin to be an event source.