IMX8 how to improve GPIO access speed

I use GPIOLIB to toggle a gpio pin (GPIO0 bit9), but the speed is only about 400kbps.

So I have to use mmap function to directly access gpio’s registers, then toggle speed can be up to 6.67MHz.

But I found read speed is still very slow. it will take about 500ns to read a gpio pin, but writing only takes 75ns.

there is no other task to run in linux system. I do not know why so slowly to read a pin.

How can I improve gpio access speed?

  t = gpio.ReadDR(0);           //   read gpio0 DR register
  while (1) {
      gpio.Get(JTAG_TDO);       //   read gpio0 PAD register bit8, it will take 500ns
      t ^= 1 << 9;              //   toggle gpio0 bit9
      gpio.WriteDR(0, t);       //   write gpio0 DR register
    }

the upper code can implement 1MHz on gpio0 pin9, but if I remove ‘gpio.Get(JTAG_TDO)’, it can be up to 6.7MHz

Hi @wen_jian_1973

Thanks for writing to the Toradex Support.

Could you provide the version of the Software of your module?
Regarding your question, what is your application?

For toggling an output PIN very fast, you could also use a PWM output.

But I found read speed is still very slow. it will take about 500ns

What speed did you want to achieve?

How can I improve gpio access speed?

You could write a kernel driver or write the code for M4 core of iMXQM.

Best regards,
Jaski