Dear NCS experts,
can you please lend a hand at configuring gpio input pins at nRF Connect SDK (1.7.1)? Here's a short code snippet that configures pin 3 as input:
static struct gpio_callback gpio_button_callback; #define BUTTON_PIN 3 static void button_callback(const struct device *gpiodev, struct gpio_callback *cb, uint32_t pin) { int isPinActive = gpio_pin_get(gpiodev, pin); printk("Pin: %d - isActive: %d\n", pin, isPinActive); } // This is how the gpio pins are configured. // Error handling has been removed to keep it short. gpio_pin_configure(dev_gpio, BUTTON_PIN, GPIO_INPUT | GPIO_INT_DEBOUNCE); gpio_init_callback(&gpio_button_callback, button_callback, 1 << BUTTON_PIN); gpio_add_callback(dev_gpio, &gpio_button_callback); gpio_pin_interrupt_configure(dev_gpio, BUTTON_PIN, GPIO_INT_EDGE_BOTH);
This is basically working. When pushing or releasing the button wired to pin 3 button_callback() is executed. Strange thing, however, is that gpio_pin_get() always returns 1, even if the button is released. In which case I'd expect the returned value to be zero. Do you have any ideas how to fix this?
And second:
Another thing that causes problems is setting BUTTON_PIN to 5 in the above example, which causes the call of gpio_pin_get(gpiodev, pin) at button_callback() to assert with:
ASSERTION FAIL [(cfg->port_pin_mask & (gpio_port_pins_t)(1UL << (pin))) != 0U] @ WEST_TOPDIR/zephyr/include/drivers/gpio.h:1107
Unsupported pin
[00:00:45.254,425] <err> os: r0/a1: 0x00000004 r1/a2: 0x00000453 r2/a3: 0x00000003
[00:00:45.254,425] <err> os: r3/a4: 0x200023c0 r12/ip: 0x00000000 r14/lr: 0x0001ae11
[00:00:45.254,425] <err> os: xpsr: 0x41000016
[00:00:45.254,455] <err> os: Faulting instruction address (r15/pc): 0x000424aa
[00:00:45.254,455] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
[00:00:45.254,455] <err> os: Fault during interrupt handling
[00:00:45.254,486] <err> os: Current thread: 0x20002f50 (idle 00)
[00:00:45.535,369] <err> fatal_error: Resetting system
Question here is, why is pin 5 unsupported? And how can it be made "supported"?
The hardware is based on a nRF52832 and is working well with a firmware application based on the Mesh SDK, so, obviously, I'm missing some important NCS details here.
Your help is very much appreciated,
Thank you,
Michael.