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