What is Android Things Raspberry Pi GPIO max frequ

2019-01-20 05:06发布

问题:

Where can be found the characteristics of the switching speed of GPIO port for the Raspberry Pi 3 under Android Things like that?

回答1:

In DP2 there is two ways to control GPIO:

1) with SDK using java (analyzed by Harry Fairhead here);

2) with NDK using C/C++ (analyzed by Harry Fairhead here).

With SDK using java the fastest pulses seen are around 0.23ms and there are lots of large (up to 8ms) interruptions (!!!) in the pulse train. And with NDK using C/C++ the pulse width is reduced from 0.23ms to just around 0.15ms.

Conclusion: Android Things DP2 Raspberry Pi GPIO max frequency is about 3 kHz, that is not fast enough to write drivers that interface to most not supported "from the box" protocols.



回答2:

I got this java code to run in 0.633 seconds, equivalent to roughly 1500 Hz.

for (int i = 0 ; i < 1000 ; i++) {
     buzzer.setValue(true);
     buzzer.setValue(false);
}

There seems to be some optimization though because if you run it multiple times it occasionally goes faster.

I'm very curious to see the results using C/C++ though.



回答3:

Here goes the results with C: it's near 100kHz.

Since I don't have a scope or proper equipment for these measures, here's what I did:

A java method that measures time, and invokes a C method that is efficient for a big number of cycles. This was for simplicity only, and I believe it's enough to show that for high number of cycles the speed asymptotically reaches almost 100kHz:

1 Iterations done in 501.38547 ms = 0.0019944734 kHz
10000 Iterations done in 599.4385 ms = 16.68228 kHz
100000 Iterations done in 1496.2832 ms = 66.83227 kHz
1000000 Iterations done in 10275.258 ms = 97.32116 kHz
2000000 Iterations done in 20104.879 ms = 99.47834 kHz

Among other things that the C code must do is sit waiting for 500ms until the pin is configured properly.

All code used for this measurement is available at https://github.com/fmatosqg/androidthings_ndk/tree/SO_speed_measurement, and I believe there still may be room for speed improvement. Though it uses a hack to write from C code, instructions available in the README.md.