Application Faults Upon Adding GPIO Change Event Handler

Hi everyone,

I am having an issue with my Legato application. When I attempt to add a GPIO change event handler, the program suddenly faults.

What Im doing:
I’m attempting to add a change event handler to GPIO Pin 35 via AddChangeEventHandler. An abbreviated version of my code is below:

static le_gpioPin35_ChangeEventHandlerRef_t gpio35Ref;
int PIN_35 = 35;
static void onStateChangeGpio35 (bool state, void *ctx) { ... }

gpio35Ref = le_gpioPin35_AddChangeEventHandler(LE_GPIOPIN35_EDGE_BOTH, onStateChangeGpio35, &PIN_35, 0);

I’ve bound 35 in my .adef file via:
myApp.mainComponent.le_gpioPin35 -> gpioExpanderServiceRed.le_gpioPin35

…and required the API in my .cdef file via:
le_gpioPin35 = le_gpio.api

What I’m experiencing:
Everything compiles and runs fine, until it gets to the line where the change event handler is added. When I call that function, the application faults, displaying the following in the log:
*EMR* | myApp@0[4701]/framework T=main | le_gpioPin35_client.c SessionCloseHandler() 424 | Component for le_gpioPin35 disconnected
INFO | supervisor[460]/supervisor T=main | proc.c proc_SigChildHandler() 1986 | Process 'myApp@0' (PID: 4701) has exited with exit code 1.
-WRN- | supervisor[460]/supervisor T=main | app.c app_SigChildHandler() 3355 | Process 'myApp@0' in app 'myApp' faulted: Ignored.
INFO | supervisor[460]/supervisor T=main | apps.c DeactivateAppContainer() 348 | Application 'myApp' has stopped.

It seems as though the application loses connection to the GPIO server, or something of the sort. Interestingly enough, I tried this same setup with Pin 22, and everything worked without any issue. Furthermore, I’ve tried polling Pin 35 with le_gpioPin35_Read() and it detects state changes without issue; this only happens when I try to add the change event handler.

Is there perhaps something different about Pin 35, and something I need to do differently to handle it?

Thank you much in advance for any assistance.

Additional Information:
Board: MangOH Red
Device: WP8548
Device Firmware: SWI9X15Y_07.12.09.00
Legato Version: 16.10.3

HI @coffeebean

GPIO35 seems to be inaccessible via the Legato API.

Here’s a link to the product technical specification:

See Table 10-1 on page 121.
According to the PTS: GPIO35 is accessible via sysfs/Legato only (denoted by 'h')

In order to use this pin, you’ll need to first reconfigure it via an AT command (see below), export it, and use /sys/class/gpio/ to access the GPIO from Linux user space.

AT command document:

Try running the command AT+WIOCGF? and it should give a response like this:

 +WIOCFG: 2,16,0,0,1,0,0
 +WIOCFG: 6,16,0,0,1,0,0
 +WIOCFG: 7,16,0,0,1,0,0
 +WIOCFG: 8,16,0,0,1,0,0
 +WIOCFG: 13,16,0,0,1,0,0
 +WIOCFG: 21,16,0,0,1,0,0
 +WIOCFG: 22,16,0,0,1,0,0
 +WIOCFG: 23,16,0,0,1,0,0
 +WIOCFG: 24,16,0,0,1,0,0
 +WIOCFG: 25,16,0,0,1,0,0
 +WIOCFG: 28,0,0,0,1,0,0
 +WIOCFG: 29,0,0,0,1,0,0
 +WIOCFG: 30,0,0,0,1,0,0
 +WIOCFG: 31,0,0,0,1,0,0
 +WIOCFG: 32,16,0,0,1,0,0
 +WIOCFG: 33,16,0,0,1,0,0
 +WIOCFG: 34,0,0,0,1,0,0
+WIOCFG: 35,0,0,0,1,0,0
 +WIOCFG: 36,0,0,0,1,0,0
 +WIOCFG: 37,0,0,0,1,0,0
 +WIOCFG: 42,16,0,0,1,0,0

You can then use this command to configure GPIO35 for usage by the embedded Linux host:

To my knowledge, if you’re set on using the Legato API then unfortunately you’ll need to select another capable pin.

Hope this helps.

Hi @raf

Thank you very much for your quick reply. For clarification, are the instructions you listed for general Linux implementations? As it is, I am indeed locked into the Legato API. Just in case, I tried the following:

First I set the GPIO to firmware in microcom via AT+WIOCFG=35,16 as per your instruction. Upon querying the command, it returns +WIOCFG: 35,16,0,0,1,0,0. Then, I SSH’d into the device and entered: echo 35 > /sys/class/gpio/export. I also tried setting sandboxed: false in my .adef file. These did not yield any changes, of course. Is that because of how Legato is set up?

An interesting observation I noted is, while I don’t have anything connected to it at the moment, GPIO36 does not cause a fault upon attaching a change event handler to it. If I cannot find any other solution, I will try re-soldering to that pin and seeing if there is any change. It would be interesting if it worked, though, as it’s marked with an 'h' like GPIO35 in the manual.