TChapman500
Posts: 3
Joined: Wed Dec 19, 2018 7:05 pm
Contact: Website YouTube

Faster GPIO Access than mmap

Wed Dec 19, 2018 7:24 pm

Hello, I'm new here, but not so new to the Pi.

I'm trying to find a faster way to switch the GPIO pins on and off than what mmap can provide. For something that's supposed to give me direct control over the registers that set the GPIO values, it seems rather slow. 22-25 MHz vs the 1.0 GHz processor clock. That is 40-46 clock cycles where the GPIO pins are not being changed at all. I'm hoping to be able to get than down to 1 or 2 clock cycles, but when I try to create a pointer directly to the correct registers, I get a segmentation fault. Is there any way to achieve what I'm trying to achieve? mmap() just hides the fact that there are files being written to and I believe that's the reason the GPIO pins are so slow.

User avatar
joan
Posts: 14175
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Faster GPIO Access than mmap

Wed Dec 19, 2018 7:41 pm

No.

The bottleneck is probably because the peripherals (of which the GPIO are one) are on the other side of the AXI bus.

mmap has nothing to do with files. It configures the MMU to give you access to a memory area.

Perhaps see http://abyz.me.uk/rpi/pigpio/examples.h ... _tiny_gpio

TChapman500
Posts: 3
Joined: Wed Dec 19, 2018 7:05 pm
Contact: Website YouTube

Re: Faster GPIO Access than mmap

Wed Dec 19, 2018 8:36 pm

Oh. I thought they were embedded into the processor itself. That explains a few things. Though I'm confused about how the /dev/*mem files work if they're not actual files.

If I understand this correctly, there's a chip that is connected to the CPU via the data and address lines used by RAM which controls the peripherals and has its own AXI bus through which it controls said peripherals.

Thanks for the link.

rhubarbdog
Posts: 64
Joined: Mon Dec 11, 2017 9:58 pm

Re: Faster GPIO Access than mmap

Thu Dec 20, 2018 4:26 am

You need to consider assembly routines.
Read the bare metal forum.
Learn a bit of raspberry pi assembly
Then post your question there

User avatar
rpdom
Posts: 14979
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Faster GPIO Access than mmap

Thu Dec 20, 2018 7:14 am

Even in direct ARM code, the GPIOs can only respond so fast. You won't be able to get anywhere near updating them at CPU clock speed.
TChapman500 wrote:
Wed Dec 19, 2018 8:36 pm
If I understand this correctly, there's a chip that is connected to the CPU via the data and address lines used by RAM which controls the peripherals and has its own AXI bus through which it controls said peripherals.
Something like that, although the "GPIO chip" is part of the same silicon as the CPUs and GPU (it is actually part of the GPU).

Files in /dev (also /proc, /sys and some others) are not actual files. They are a way of interfacing with either the hardware or with internal Linux kernel values.

TChapman500
Posts: 3
Joined: Wed Dec 19, 2018 7:05 pm
Contact: Website YouTube

Re: Faster GPIO Access than mmap

Thu Dec 20, 2018 10:20 pm

rpdom wrote: Even in direct ARM code, the GPIOs can only respond so fast. You won't be able to get anywhere near updating them at CPU clock speed.
Looks like it's time for a few experiments then.
rpdom wrote: Files in /dev (also /proc, /sys and some others) are not actual files. They are a way of interfacing with either the hardware or with internal Linux kernel values.
That explains a few things.

Return to “Advanced users”