2022-12-21 01:02 AM
Hi all ~
I'm trying to control GPIO input in own application.
and I refered to below wiki.
https://wiki.st.com/stm32mpu/wiki/How_to_control_a_GPIO_in_userspace
this is my code.
gint gpiochip_fd, ret;
gchar gpiochip_path[20];
struct gpioevent_request in_req;
struct gpiohandle_request out_req;
// IN1 PB12 gpiochip1
// IN2 PB5 gpiochip1
// IN3 PH6 gpiochip7
// IN4 PD15 gpiochip3
// IN5 PD14 gpiochip3
// IN6 PD11 gpiochip3
// IN7 PE7 gpiochip4
// IN8 PE9 gpiochip4
// IN9 PE8 gpiochip4
// IN10 PG9 gpiochip6
// IN11 PE10 gpiochip4
// IN12 PD12 gpiochip3
gint idx;
gint in_gpio_chipno[NO_INPUT] = {1, 1, 7, 3, 3, 3, 4, 4, 4, 6, 4, 3};
gint in_gpio_lineoffset[NO_INPUT] = {12, 5, 6, 15, 14, 11, 7, 9, 8, 9, 10, 12};
for (idx=0; idx<NO_INPUT; idx++) {
g_sprintf(gpiochip_path, "/dev/gpiochip%d", in_gpio_chipno[idx]);
gpiochip_fd = open (gpiochip_path, O_RDWR);
if (gpiochip_fd == -1)
fprintf(stderr, "Failed to open %s\n", gpiochip_path);
else {
in_req.lineoffset = in_gpio_lineoffset[idx];
in_req.eventflags = GPIOEVENT_REQUEST_BOTH_EDGES;
in_req.handleflags = GPIOHANDLE_REQUEST_INPUT;
ret = ioctl(gpiochip_fd, GPIO_GET_LINEEVENT_IOCTL, &in_req);
if (ret == -1) {
in_fd[idx] = -1;
fprintf(stderr, "Failed to issue GPIO_GET_LINEEVENT_IOCTL (%d)\n", -errno);
} else {
in_fd[idx] = in_req.fd;
in_gio[idx] = g_io_channel_unix_new (in_req.fd);
in_gsrc[idx] = g_io_create_watch (in_gio[idx], G_IO_IN);
g_source_set_callback (in_gsrc[idx], (GSourceFunc)gpio_event_cb, GINT_TO_POINTER(idx), NULL);
g_source_attach (in_gsrc[idx], g_main_loop_get_context (Threads_GetMainLoop(MLID_Gpio)));
g_source_unref (in_gsrc[idx]);
}
if (close(gpiochip_fd) == -1)
perror("Failed to close GPIO character device file");
}
}
When I run application, 3 input pins (PE9, PG9, PD12) return error like below.
Failed to issue GPIO_GET_LINEEVENT_IOCTL (-19)
And the kernel log printed as below.
[ 5366.798479] stm32mp157-pinctrl soc:pinctrl@50002000: irq line 9 already requested.
[ 5366.812031] stm32mp157-pinctrl soc:pinctrl@50002000: irq line 9 already requested.
[ 5366.825262] stm32mp157-pinctrl soc:pinctrl@50002000: irq line 12 already requested.
below is my gpio info of these pins.
line 9: "PE9" unused input active-high
line 9: "PG9" unused input active-high
line 12: "PD12" unused input active-high
Where should I check to solve this problem?
Thanks in advanced.
Solved! Go to Solution.
2022-12-21 01:59 AM
Hi,
Please note that there is a inherent HW limitation in EXTI (common to most STM32 products) that there is only 16 GPIO interrupts and only one interrupt EXTIx could be set for all port with same index Py[x].See also https://wiki.st.com/stm32mpu/wiki/EXTI_internal_peripheral
You should align your overall GPIO EXTI interrupt choices to this HW constraint.
Regards,
Patrick
2022-12-21 01:39 AM
Hello @hochul yoo ,
It is highly possible that the 3 gpios that you are asking for are already reserved for other IPs. For example, if you take a look at the device tree stm32mp15xx-dkx.dtsi file, you can see that gpio PG9 is used by cs42l51 node.
In this case, you have 2 choices. Use another GPIO or disable the node if you do not use the specific feature.
Kind regards,
Erwan.
2022-12-21 01:59 AM
Hi,
Please note that there is a inherent HW limitation in EXTI (common to most STM32 products) that there is only 16 GPIO interrupts and only one interrupt EXTIx could be set for all port with same index Py[x].See also https://wiki.st.com/stm32mpu/wiki/EXTI_internal_peripheral
You should align your overall GPIO EXTI interrupt choices to this HW constraint.
Regards,
Patrick