Why a GPIO pin cannot detect both rising and falling events in Linux?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why a GPIO pin cannot detect both rising and falling events in Linux?

473 Views
ddbug
Contributor II

I have the following code to monitor GPIO pulses on i.MX8, using GPIO v2 ioctls of kernel 6.x:

(partially borrowed from [linux tree]/tools/gpio/gpio-utils)

 

 

 

 

#define PULSE_PIN 1
struct gpio_v2_line_config config;
memset(&config, 0, sizeof(config));

unsigned pins[]={PULSE_PIN};
config.flags |= GPIO_V2_LINE_FLAG_INPUT;
config.flags |= GPIO_V2_LINE_FLAG_EDGE_RISING;
//config.flags |= GPIO_V2_LINE_FLAG_EDGE_FALLING;
config.flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME;
ret = gpiotools_request_line("gpiochip0", pins, 1, &config, "IN_PULSE");

for (;;) 
{
		int rc;
		uint64_t ts;
		rc = gpiotools_read_line_event(fd, (void*)&ts);
		if (rc > 0) {
			printf(" %d\n", rc);
		}
}

 

 

 

 

 

When I use only GPIO_V2_LINE_FLAG_EDGE_RISING or GPIO_V2_LINE_FLAG_EDGE_FALLING, these events are properly detected. But if I use both, only falling is detected. Why? The i.MX8 itself can be configured to interrupt on both edges.

Same behavior using gpiomon -r -f .

 

Tags (2)
0 Kudos
3 Replies

369 Views
JorgeCas
NXP TechSupport
NXP TechSupport

Hello,

I just wanted to verify if that behavior could be caused by the logic operation since there is a definition for both rising and falling events.

Jorge7u7_0-1699977446330.png

Best regards

0 Kudos

387 Views
ddbug
Contributor II

@JorgeCas Thank you for your response - but I did what you advise, only in slightly different way.

 

0 Kudos

411 Views
JorgeCas
NXP TechSupport
NXP TechSupport

Hello, I hope you are doing well.

Could you please try with:

config.flags |= (GPIO_V2_LINE_FLAG_EDGE_RISING | (GPIO_V2_LINE_FLAG_EDGE_FALLING);

Best regards.

0 Kudos