bask185 wrote: ↑
Tue Jul 31, 2018 8:21 am
I want to write a C program to controll the I/O. Than compile it to a binary and run that binary on a raspberry 3B+ with raspbian or raspian lite
The maximum frequency you could toggle a GPIO pin at would seem to be about 22MHz according to the link jahboater posted -
http://codeandlife.com/2012/07/03/bench ... gpio-speed
I would expect roughly the same for a Pi 3B+ as for the earlier Pi because I believe the I/O hardware and the connecting bus is the same, only the ARM cores are faster.
The slower examples should get faster because there is more overhead to them which will execute faster on more modern Pi. For native C the bottleneck would be the bus to the GPIO pins, not CPU execution speed, so I would not expect to see much improvement if any.
My guess is that 25MHz might be achievable with assembly language and optimal coding.
The problem is that running code on a Pi with an OS isn't like running code on a micro which doesn't have an OS.
On the Pi things can happen at any time and take control away from you code. It would be like having interrupts handled by you microcontroller code; those interrupts would affect the maximum GPIO pin toggle frequency, extend the high and/or low periods.
There is a maximum theoretical toggling rate but no guarantee that you will achieve that continually.
You could run the Pi without an OS, could even run your code in the GPU rather than on an ARM core, or maybe even put your pin toggling code on a separate core, but once you have anything other than just your code running you will see some drop from maximum frequency.
It seems the bus to GPIO is faster on the later Pi's -
Shows the (non-DMA) maximum bit-banged pin toggling rate as 22.7MHz for Pi original, 41.7MHz for a Pi 2 and 65.8MHz for a Pi 3.
Also - https://periph.io/news/2017/gpio_perf
- shows 82.6MHz on a Pi 3, and 29.3MHz on a Pi Zero W, so I guess it really does come down to how optimal the executable code is.