[SOLVED] GPIO performance drop

Post Reply
leoanicio
Posts: 5
Joined: Mon May 07, 2018 10:03 am
languages_spoken: english, portuguese (BR)
ODROIDs: C2
Contact:

[SOLVED] GPIO performance drop

Unread post by leoanicio » Sat Sep 01, 2018 5:58 am

So, i've recently noticed a huge performance drop on my gpio speed. As others topics mention, the max toggle speed should be about 2~3MHz, but I'm currently stuck in ~11Khz...

Here's the code I'm using to test:

Code: Select all

int main(int argc, char **argv)
{
	wiringPiSetup();
	pinMode(1, OUTPUT);
	
	int y = atoi(argv[1]);
	
	int x =0;
	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
	while(x < y)
	{
		digitalWrite(1, 0);
		digitalWrite(1, 1);
		x++;
	}
	clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &stop);
	printf("%.9f\n",  (stop.tv_sec - start.tv_sec) + (stop.tv_nsec - start.tv_nsec) / 1e9);
}
At y=11000 I get 1.03 seconds.

User avatar
odroid
Site Admin
Posts: 29700
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: GPIO performance drop

Unread post by odroid » Mon Sep 03, 2018 8:21 am

Which Kernel version do you use?
Did you get this Wiringpi library?
https://wiki.odroid.com/odroid-xu4/appl ... o/wiringpi

leoanicio
Posts: 5
Joined: Mon May 07, 2018 10:03 am
languages_spoken: english, portuguese (BR)
ODROIDs: C2
Contact:

Re: GPIO performance drop

Unread post by leoanicio » Tue Sep 04, 2018 1:47 am

I've got the wiringPi form here:
https://wiki.odroid.com/odroid-c2/appli ... o/wiringpi

The kernel version is:
3.14.79-116

Also, I've found that if I don't include wiringPi.h and just copy/paste the basic gpio configuration from the lib to another header file, it goes back to the normal frequency.

User avatar
odroid
Site Admin
Posts: 29700
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: GPIO performance drop

Unread post by odroid » Tue Sep 04, 2018 9:06 am

I think the default wiringpi library build option was not configured well.
We will try to find where is a bottleneck.

joshua.yang
Posts: 117
Joined: Fri Sep 22, 2017 5:54 pm
languages_spoken: English
ODROIDs: XU4, XU4Q + Cloudshell2
Contact:

Re: GPIO performance drop

Unread post by joshua.yang » Tue Sep 04, 2018 12:14 pm

Hi @leoanicio,

I had made a mistake that when I patched about I2C pins, I inserted code checks whether I2C module loaded or not and the used pin is for I2C.
https://github.com/hardkernel/wiringPi/ ... dc2.c#L304

Code: Select all

	if (moduleLoaded(AML_MODULE_I2C) && (retPin == 205 || retPin == 206))
		return -1;
	else
		return retPin;
This code made the GPIO speed slower. I should do checking the module after checking the pin. :o

Maybe compiler optimization might correct this issue but I edited the code and made that explicitly.
The corrected code below.

Code: Select all

	if (retPin == 205 || retPin == 206) {
		if (moduleLoaded(AML_MODULE_I2C))
			return -1;
	}

	return retPin;
And the speed comparison.

Code: Select all

### Before ###
root@odroid:~# ./gpio_toggling_speed 11000
0.973827000
root@odroid:~# ./gpio_toggling_speed 11000
0.973115000
root@odroid:~# ./gpio_toggling_speed 11000
0.970517000

### After ###
root@odroid:~# ./gpio_toggling_speed 11000
0.005915000
root@odroid:~# ./gpio_toggling_speed 11000
0.005770000
root@odroid:~# ./gpio_toggling_speed 11000
0.006007000
I just have updated our Github repository: https://github.com/hardkernel/wiringPi/ ... d9caa4c6cb
Could you please test the latest WiringPi?

I apologize for your inconvenience.

leoanicio
Posts: 5
Joined: Mon May 07, 2018 10:03 am
languages_spoken: english, portuguese (BR)
ODROIDs: C2
Contact:

Re: GPIO performance drop

Unread post by leoanicio » Wed Sep 05, 2018 1:16 am

Thank you Joshua, it works flawlessly now!

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 3 guests