Jump to content
macemoneta

Fedora 23 on pcduino3 nano lite GPIO issue

Recommended Posts

Fedora 23 boots and runs fine, but I'm having a problem with GPIOs.

 

From the command line, I can export a GPIO:

echo 2 >/sys/class/gpio/export

But if I try to set it to output:

echo out > /sys/class/gpio/gpio2/direction

the pcduino immediately hard locks requiring a reset. I've tried this with the 4.3.3 kernel and the 4.4.0 kernel. Nothing is actually connected to the GPIO or other pins on the pcduino.

 

 

Share this post


Link to post
Share on other sites

OK, I found the info. The mainline kernel which is used by Fedora doesn't use the pin mapping, so you have to calculate the sysfs GPIO from the port number, using the formula:

(position of letter in alphabet - 1) * 32 + pin number

If the port is Pxnn, you take the position of the letter 'x' in the alphabet, and 'nn' is the pin number. So gpio pin 2 is port PH07, which has x=H (the 8th letter of the alphabet) and nn=7. Plugging that in, you get:

(8-1)*32+7=231

So to use gpio pin 2:

echo 231 >/sys/class/gpio/export
echo out > /sys/class/gpio/gpio231/direction

I made a quick reference for the pcduino3 nano lite:

gpio_pin_0 = port:PI19 = sysfs:275
gpio_pin_1 = port:PI18 = sysfs:274
gpio_pin_2 = port:PH07 = sysfs:231
gpio_pin_3 = port:PH06 = sysfs:230
gpio_pin_4 = port:PH08 = sysfs:232
gpio_pin_5 = port:PB02 = sysfs:34
gpio_pin_6 = port:PI03 = sysfs:265
gpio_pin_7 = port:PH09 = sysfs:233
gpio_pin_8 = port:PH10 = sysfs:234
gpio_pin_9 = port:PH05 = sysfs:229
gpio_pin_10 = port:PI10 = sysfs:266
gpio_pin_11 = port:PI12 = sysfs:268
gpio_pin_12 = port:PI13 = sysfs:269
gpio_pin_13 = port:PI11 = sysfs:267

I hope that saves someone else the time hunting this down.

Share this post


Link to post
Share on other sites

Wow, it is great!

 

Yes, mainline 4.4 kernel, latest Fedora software, what's not to like?   :)

 

Also, the onboard LEDs USR1 and USR2 (marked LED3 and LED4 on the board) can be controlled by:

# Remove from system control
modprobe -r leds-gpio

# Export the USR1 and USR2 LEDs
echo 239 > /sys/class/gpio/export
echo 240 > /sys/class/gpio/export

# Turn them on
echo 0 > /sys/class/gpio/gpio239/value
echo 0 > /sys/class/gpio/gpio240/value

# Turn them off
echo 255 > /sys/class/gpio/gpio239/value
echo 255 > /sys/class/gpio/gpio240/value

Very handy while testing.

Share this post


Link to post
Share on other sites

Yes, mainline 4.4 kernel, latest Fedora software, what's not to like?   :)

 

Also, the onboard LEDs USR1 and USR2 (marked LED3 and LED4 on the board) can be controlled by:

# Remove from system control
modprobe -r leds-gpio

# Export the USR1 and USR2 LEDs
echo 239 > /sys/class/gpio/export
echo 240 > /sys/class/gpio/export

# Turn them on
echo 0 > /sys/class/gpio/gpio239/value
echo 0 > /sys/class/gpio/gpio240/value

# Turn them off
echo 255 > /sys/class/gpio/gpio239/value
echo 255 > /sys/class/gpio/gpio240/value

Very handy while testing.

 

 

Brilliant! I've also verified it on Lubuntu 14.04.

 

But the LED pins may have some problems on reusing. Got an error when removing the led module:

linaro@Nano:~$ sudo modprobe -r leds-gpio
modprobe: ERROR: ../libkmod/libkmod-module.c:769 kmod_module_remove_module() could not remove 'leds_gpio': Function not implemented
 
My kernel version is also 4.4.0:
root@Nano:/home/linaro# uname -a
Linux Nano 4.4.0-rc1 #7 SMP Mon Jan 25 10:25:26 CET 2016 armv7l armv7l armv7l GNU/Linux

 

Can you share your kernel configurations? Or Any suggestions on the error?

 

Thanks.

BR//Xiaohai

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×