How to Toggle GPIO Faster

Hello everyone,

I’m having some trouble setting up a GPIO pulse with C code on linux.

Basically, what I’m doing is to set and reset the GPIO pin with SYSFS like this:

// ... Stuff Before This ...

FILE *fv;

fv = fopen("/sys/class/gpio/gpio1/value", "w");
fputs("1", fv);
fclose(fv);

fv = fopen("/sys/class/gpio/gpio1/value", "w");
fputs("0", fv);
fclose(fv);

However, this way is giving me two problems. First, the pulse happens around 0.5 ms after the end of my transmission and second, the pulse stays high for about 0.1 ms. At first, I though that I was supposed to setup the GPIO registers manually, but after some research (here) I figure out that this is not the right approach. I’m not very experienced with embedded Linux, so how can I make this whole process faster?

Hi @farina!

A good alternative would be to use libgpiod, the new GPIO subsystem in the Linux kernel.

As I saw your other question regarding libgpiod, let’s continue over there.