I’m using libgpiod v1.6.x on the Beagleboard Black (Debian Bullseye IoT Image 2023-09-02, 5.10.168-ti-r71) to poll gpio lines for edge events from some peripherals (ICM20948 and SX1276). However, it seems that some GPIO pins cannot be used and make the board crash. I am currently using:
P9.12 for ICM20948 and P8.41 through P8.46 for SX1276. Pin P9.12 always works, but the pins on P8 cause crashes sometimes. In particular, pins P8.41 and P8.42 can cause the crash. Previously I tried this setup but using pins P8.11,12,14,15,16,17 with the same result: often pins P8.15 and 16 would cause a crash.
In /boot/uEnv.txt I have disabled video, audio, wireless and adc.
The code I use is:
static int open_chips_and_lines(struct gpiod_chip** chips, struct gpiod_line** lines){
int num_chips = 0;
int ret = 0;
uint8_t chip_opened_bits = 0;
uint32_t line_count[GPIO_CHIPS] = {0};
for(int i = 0; i < TOTAL_INTERRUPT_LINES; i++){
uint32_t pin = INTC_PINS[i];
uint32_t chip = GET_GPIO_CHIP(pin);
uint32_t line = GET_GPIO_LINE(pin);
uint32_t edge = INTC_EDGES[i];
BBBLOG(debug, 1, NULL, "Opening Chip%u/Line%u:\n", chip, line);
if(!((chip_opened_bits & (1 << chip)) >> chip)){
chips[chip] = gpiod_chip_open_by_number(chip);
BBBLOG(error, !chips[chip], return -1, "Open Chip %u failed\n", chip);
num_chips++;
}
BBBLOG(debug, 1, NULL, "Requesting Line\n");
lines[i] = gpiod_chip_get_line(chips[chip], line);
BBBLOG(error, !lines[i], return -1, "Open Line Chip%u/Line%u failed\n", chip, line);
BBBLOG(debug, 1, NULL, "Requesting edge events\n");
if(edge == GPIOD_LINE_EVENT_RISING_EDGE){
ret = gpiod_line_request_rising_edge_events(lines[i], CONSUMER);
} else {
ret = gpiod_line_request_falling_edge_events(lines[i], CONSUMER);
}
BBBLOG(error, ret < 0, return -1, "Requesting line events for Chip%u/Line%u failed\n", chip, line);
line_count[chip]++;
usleep(1000000);
}
return num_chips;
}
where INTC_PINS and INTC_EDGES are arrays given at compile-time containing the pins and edge types to monitor. The board freezes when requesting edge events (gpiod_line_request_rising_edge_events) and needs to be reset using the reset button.
Am I simply using libgpiod wrong, or are there hardware limitations I am not aware of?
Edit: a simple working example is found below in this comment of mine.