Identify GPIO pins on output header ( howto )

Post Reply
mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

Update: This is the mapping table for both the X and X2 expansion header
Note: only GPIO pins can use the sysfs echo value, such as the ones with the description: LCD
For the others use a kernel module such as the SPI one or I2C

50-pin header map

Code: Select all

Pin     GP_Name         GPIOCHIP                Description             sysfs_echo_value
1       GPX3.3          gpiochip217 + 3         WAKEUP_INT3[3]_KP               220
2       GPA1.3          gpiochip9 + 3           UART_2_RTSn_I2C_3_SCL           12
3       GPD1.2          gpiochip42 + 2          I2C_1_SDA               44
4       GPX2.1          gpiochip208 + 1         WAKEUP_INT2[1]_KP               209
5       GPD1.3          gpiochip42 + 3          I2C_1_SCL               45
6       GPB.4           gpiochip16 + 4          SPI_1_CLK_IEM_SCLK              20
7       GPB.3           gpiochip16 + 3          SPI_0_MOSI_I2C_5_SCL            19
8       GPB.2           gpiochip16 + 2          SPI_0_MISO_I2C_5_SDA            18
9       GPX1.4          gpiochip199 + 4         WAKEUP_INT1[4]_KP               203
10      GPB.5           gpiochip16 + 5          SPI_1_nSS_IEM_SPWI              21
11      GPB.7           gpiochip16 + 7          SPI_1_MOSI              23
12      VDDQ_LCD
13      GPD0.1          gpiochip37 + 1          TOUT_1_LCD_PWM          38
14      GPA1.4          gpiochip9 + 4           UART_3_RXD_UART_AUDIO           13
15      GPB.6           gpiochip16 + 6          SPI_1_MISO              22
16      GPA1.1          gpiochip9 + 1           UART_3_TXD_UART_AUDIO           10
17      GPF2.7          gpiochip105 + 7         LCD_VD19                112
18      GPF3.1          gpiochip114 + 1         LCD_VD21                115
19      GPF0.6          gpiochip87 + 6          LCD_VD[2]               93
20      GPF1.4          gpiochip96 + 4          LCD_VD[8]               100
21      GPF2.3          gpiochip105 + 3         LCD_VD15                108
22      GPF0.4          gpiochip87 + 4          LCD_VD[0]               91
23      GPF0.3          gpiochip87 + 3          LCD_VCLK                90
24      GPF1.3          gpiochip96 + 3          LCD_VD[7]               99
25      GPF2.6          gpiochip105 + 6         LCD_VD18                111
26      GPF1.7          gpiochip96 + 7          LCD_VD11                103
27      GPF0.1          gpiochip87 + 1          LCD_VSYNC               88
28      GPF1.2          gpiochip96 + 2          LCD_VD[6]               98
29      GPF0.2          gpiochip87 + 2          LCD_VDEN                89
30      GPF3.0          gpiochip114 + 0         LCD_VD20                114
31      GPF0.0          gpiochip87 + 0          LCD_HSYNC               87
32      GND
33      GPF0.7          gpiochip87 + 7          LCD_VD[3]               94
34      GPF2.0          gpiochip105 + 0         LCD_VD12                105
35      GPF1.1          gpiochip96 + 1          LCD_VD[5]               97
36      GPF1.6          gpiochip96 + 6          LCD_VD10                102
37      GPF2.2          gpiochip105 + 2         LCD_VD14                107
38      GPF2.5          gpiochip105 + 5         LCD_VD17                110
39      GPF1.5          gpiochip96 + 5          LCD_VD[9]               101
40      GPF3.3          gpiochip114 + 3         LCD_VD23                117
41      GPF0.5          gpiochip87 + 5          LCD_VD[1]               92
42      GPF1.0          gpiochip96 + 0          LCD_VD[4]               96
43      GPF3.2          gpiochip114 + 2         LCD_VD22                116
44      GPF2.1          gpiochip105 + 1         LCD_VD13                106
45      GPF2.4          gpiochip105 + 4         LCD_VD16                109
46      SYS5v
47      XadcAIN
48      VDD_IO
49      XadcAIN
50      GND
Note: file attachment is a diagram showing the 50-pin header with SYSFS GPIO names

Update #2
I have created a C library for python that allows you to control the Odroid-x/2 GPIO pins without have GPIO SYSFS enabled in your kernel. It directly
modifies the GPIO registers in memory. You can download the library with python examples from this post:
http://forum.odroid.com/viewtopic.php?f ... t=20#p5726

============================================ previous material ===============
I rescued this from cache
I have built a custom kernel using the latest odroidx-next branch and enabled spi-bitbang, GPIO options and 1-wire modules, I also disabled the LCD configuration as I am going to use its GPIO pins.

CONFIG_I2C_GPIO=m
CONFIG_SPI_GPIO=m
CONFIG_SPI_BITBANG=m
CONFIG_SPI_GPIO=m
CONFIG_SPI_S3C64XX=m (after fixing the required CONFIG_USE_OF that was missing)

----- Now to the fun stuff, I've booted my new kernel
# uname -a
Linux linaro-ubuntu-desktop 3.6.1 #2 SMP PREEMPT Sun Oct 7 18:13:11 CDT 2012 armv7l armv7l armv7l GNU/Linux

# cd /sys/class/gpio/
# ls
export gpiochip130 gpiochip177 gpiochip233 gpiochip281 gpiochip69
gpio87 gpiochip136 gpiochip181 gpiochip238 gpiochip31 gpiochip78
gpio88 gpiochip144 gpiochip190 gpiochip245 gpiochip37 gpiochip87
gpiochip0 gpiochip152 gpiochip199 gpiochip25 gpiochip42 gpiochip9
gpiochip105 gpiochip16 gpiochip208 gpiochip254 gpiochip47 gpiochip96
gpiochip114 gpiochip160 gpiochip217 gpiochip263 gpiochip53 unexport
gpiochip121 gpiochip168 gpiochip226 gpiochip272 gpiochip62

How does this map to the Odroid-x 50-pin header?
/sys/class/gpio# for file in gpio*; do echo -n "$file - ";cat $file/label; done
gpiochip0 - GPA0
gpiochip105 - GPF2
gpiochip114 - GPF3
gpiochip121 - GPJ0
gpiochip130 - GPJ1
gpiochip136 - GPK0
gpiochip144 - GPK1
gpiochip152 - GPK2
gpiochip16 - GPB
gpiochip160 - GPK3
gpiochip168 - GPL0
gpiochip177 - GPL1
gpiochip181 - GPL2
gpiochip190 - GPX0
gpiochip199 - GPX1
gpiochip208 - GPX2
gpiochip217 - GPX3
gpiochip226 - GPY0
gpiochip233 - GPY1
gpiochip238 - GPY2
gpiochip245 - GPY3
gpiochip25 - GPC0
gpiochip254 - GPY4
gpiochip263 - GPY5
gpiochip272 - GPY6
gpiochip281 - GPZ
gpiochip31 - GPC1
gpiochip37 - GPD0
gpiochip42 - GPD1
gpiochip47 - GPE0
gpiochip53 - GPE1
gpiochip62 - GPE2
gpiochip69 - GPE3
gpiochip78 - GPE4
gpiochip87 - GPF0 <----- here is our target GPIO chip
gpiochip9 - GPA1
gpiochip96 - GPF1

Mapping the GPF0 to the odroid-x 50-pin header gives us:
31 HSYNC XvHSYNC GPF0[0]/LCD_HSYNC
27 VSYNC XvVSYNC GPF0[1]/LCD_VSYNC
29 VDEN XvVDEN GPF0[2]/LCD_VDEN
23 VCLK XvVCLK GPF0[3]/LCD_VCLK

Where GPF0 is: gpiochip87 - GPF0

# echo 87 > /sys/class/gpio/export
# cd gpio87
# echo "out" > /sys/class/gpio/gpio87/direction
# echo "1" > /sys/class/gpio/gpio87/value
^^^ measured 1.8v on pin 31
# echo "0" > /sys/class/gpio/gpio87/value
^^^ measured 0v on pin 31

What about gpio 1 on gpiochip87 - GPF0 (vsync pin 27)
# cat gpiochip87/base
87
So to get gpio 1 also enabled its: 87 + 1 (the gpio number on the chip) = 88
# echo 88 > /sys/class/gpio/export
# cd gpio88
# echo "out" > /sys/class/gpio/gpio88/direction
echo "1" > /sys/class/gpio/gpio88/value
^^^ measured 1.8v on pin 27
# echo "0" > /sys/class/gpio/gpio88/value
^^^ and now measure 0v on pin 27

------ Here is the python code to toggle our GPIO chip 87 pin 31, 10 seconds on and off so you can measure the voltage

Code: Select all

#!/usr/bin/python
import time
# use gpiochip87 gpio 0
# this will turn on pin 31 for 10 seconds then off for 10 seconds
# you should have time to measure the voltage varying from 1.8v to 0v
# every 10 seconds
try:
  # check to see if the pin is already exported
  open('/sys/class/gpio/gpio87/direction').read()
except:
  # it isn't, so export it
  print("exporting GPIO 87, gpiochip87 - GPF0 which is pin 31 on odroid-x header")
  open('/sys/class/gpio/export', 'w').write('87')

# set gpiochip87 ID=0  on header pin 31 to output
open('/sys/class/gpio/gpio87/direction', 'w').write('out')

for i in range(10):
  open('/sys/class/gpio/gpio87/value', 'w').write("1")
  time.sleep(10)
  open('/sys/class/gpio/gpio87/value', 'w').write("0")
  time.sleep(10)

# remove GPIO87 folder from file system
open('/sys/class/gpio/unexport', 'w').write('87')
Attachments
odroid_header.pdf
PDF diagram of the 50-pin header
(26.21 KiB) Downloaded 799 times
Last edited by mlinuxguy on Fri Apr 12, 2013 3:10 pm, edited 11 times in total.

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

daaaaaaaammmnn aweseome i was told "nothing cached" last time i searched .. thanks again man ... unfortunatly i am not at work where my O-X is, tomorrow will be a great day :)

User avatar
sert00
Posts: 745
Joined: Sun Feb 24, 2013 12:26 am
languages_spoken: english,italian
ODROIDs: ODROID-U2*2__ODROID-U3__ODROID-XU-E__ODROID-XU-Ebeta__ODROID-C1__ODROID-XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by sert00 »

possible to have it enable on u2 kernel also?it would be great..
2x Odroid-U2
2x Odroid-XU-E
Odroid-U3
Odroid-C1+
Odroid-XU4
Lcd touch panel 10.1"
....and many of the goodies available....

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

i know i asked it before, i followed the "how to to rebuild the ubuntu kernel", i started "make xconfig" and there was some truck that run over me but i forgot to write down his license plate when the window opened XD

so where do i have to insert your code or how to manage to add this to get SPI working ? or will this be a step AFTER rebuilding the kernel ?

EDIT: i think i found what you have done there and now ever so slowly begin to understand! xconfig is awesome but lacks of good documentation at most options!
so i already burdened mdrjr with that question as i was confused with alle that options and now my new challenge is to understand:

how to map those GPIO SPI bitbanging driver to the pins i want!

and after that i may be able to layback through the driver source how to control the GPIOs in a direct way and may try to write my own driver

EDIT 2nd: now i think i am getting it, not exactly what you are doing there XD the xconfig and mdrjr gave me some inspiration

BUT new question just for my understanding, if i am going to write an simple application (in c not python unless i do not know about python syntax at all .. shame on me) lets say a blinking LED like you did!

all i would have to do is including the arch/arm/mach-Exynos/include/GPIOxxxx.h (and dependands) and then i should be able to control them !?! i don't know if i am totally wrong or this is so simple as it looks like to me ?

Just for you to understand, i worked with PIC32 and it looks like the same structure but i may can misunderstand it totally, it looks so freaking familliar!

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

The key is this sequence here:
# echo 88 > /sys/class/gpio/export
# cd gpio88
# echo "out" > /sys/class/gpio/gpio88/direction
echo "1" > /sys/class/gpio/gpio88/value
^^^ measured 1.8v on pin 27
# echo "0" > /sys/class/gpio/gpio88/value
^^^ and now measure 0v on pin 27

If you built your kernel with GPIO support
You will see those directories. Its as simple as echoing a "1" or "0" to the appropriate /subdir/file
No need for a "C" program, just setup the export for the correct GPIO that you have mapped and then do your echo.
Please keep in mind this is only 1.8v pins on the Odroid's... if you have a LED with a large voltage drop across them it may not light up.

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

but i'd like to have it the C way ;) well this is enough for first testing and further understanding!
i already have a PCB planned for a voltage adjustable optocoupling testboard

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

okay, where do i find the pin mapping now? 88 is not listed in my gpio folder and strangly looks like not related with gpf[0] at all ... did i miss something?

and how do i control/access the SPI GPIO bitbang-driver ? the spi_master folder is emppty for me

ahhh okay i am just plain stupid ^^ i had overseen how to readout the labels ... sorry

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

okay, i have made myself a small tool using java to get access to those GPIO "filehandles"

pretty nice but slow as hell ....

is there ANYBODY who tried to access the pins over the source directly?

well if not, is there ANYBODY willing to help me with getting into driver/module programming? maybe a simple example to get into what basic things i need ?! and more important how to patch into my kernel :)

i were thinking about a simple file handle that is displaying random messages whenever i open it!

when i use google i get everything but nothing usefull

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

is there ANYBODY who tried to access the pins over the source directly?
What do you mean by this statement? You can directly access the pins via shell commands as previously shown. If you wish to do it from 'C' code you just open those 'directories + gpio file names' and read/write to them.

Perhaps from your earlier post you want to bit-bang a specific GPIO port? In which case you google 'SPI bitbang c program' (or some such) and the pin you will use in such a 'C' program will be whichever one you earlier mapped as output.

No need for a kernel module as that could all be done with user-land code.

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

i tested the performance and the fastest i can get from the interface is a 5kHz clock, tis is way behind what i had in my mind

i've read this interface is capable to 96Mhz, i don't want to go that high but i want a way more basic access to the pins than this unreliable timed GPIOs

really it's nice to have them but no use for me with this performance :)

i never want to offend somebody, if my post sounds like this i am really sorry that was not my intention

PS: it's always good to have deeper knowledge even if it's just an example or proof of concept how it works, but the internet is nor very helpfull if you get down on linux ... mostly i only find examples that assume an already expert level in kowledge about kernel stuff and don't explain anything straight waving big circles and pointing out uninteresting details without getting to a point :(

the new "how to"s and the people in this forum have taught me more over linux than i have learned during study ... and there was a whole lecture about unix systems (i know unix != linux) XD but there was nothing like kernelstuff or anything like that usefull

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

I will have to look back at my testing but with the odroid-x2 + USB IO board I could get around a 11 msec square wave pulse when just toggling a GPIO pin. Probably it was the overhead of the USB transaction limiting me there. Anyway that provides a baseline where toggling it directly (not over USB to the IO board) should result in faster than the 11msec pulse I was getting.

The problem you face is the very first sleep that you do (even a nanosleep) will take you off the run queue (let alone when your timeslice ends). For this you need a RT OS to sit tightly around your bit-bang routine. That's why hardware assisted PWM/SPI/I2C is used to offload the OS and achieve higher frequencies.

A test to see what your max throughput would be is to write 'C' code to toggle a GPIO pin as fast as possible and monitor it with a logic analyzer to see the frequency. Then add a nanosleep in to control your frequency and see how that effects the waveform. This would set your min and max pulse frequency under the Linux OS.

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

the timing is highly unstable due to priority in threading
i want to get access to the low level controls of the I2C and the SPI, as the SPI driver from the kernel seems to be not working for me and what i've read it's limited to 1MHz and that is around 10 times below what i am looking for

and the moment mdrjr has time to check out how to get rid of the framebuffer without killing the HDMI i want to have a look into the framebuffer-controller :D ... hopefully i have collected enough knowledge to get access to it !

this could turn out to be an very usefull and powerfull interface!

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

I've written a little TestTool to check the Performance and control the GPIOs on my Odroid-X via GPIO Driver File Handles
screenshot
screenshot
Unbenannt.png (54.26 KiB) Viewed 30460 times
GPIOTest.zip
Unzip to get the JAR and run it with "sudo java -jar"
(18.33 KiB) Downloaded 485 times
When you rebuild the Kernel as mlinuxguy told with the GPIO Flaggs enabled you just have to run this jar via
sudo java -jar GPIOTest.zip (sudo because of the root access to the "sys/class/gpio")
click the "Read GPIO" Button to get a Listing of all GPIO

Disclaimer:
BE WARNED! THIS LIST CONTAINS EVERY GPIO OF THE EXYNOS EVEN THOSE THAT ARE CONNECTED TO BOARDHARDWARE! ONLY USE THE GPIOS OF THE DISPLAYPORT OR YOU MAY DAMAGE YOUR BOARD!
you have been warned, use at own risk

then you can select a pin from the drop down and enable it (exports the pin and disables it normal behaviour) toggle it to high and low or let it autotoggle with max possible frequency (consumes a lot of CPU) or read the input!

I'll make source available if wanted, but its nothing special, just wrapped a small GUI around the Filehandles used to interface the GPIO

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

okay, nailed it! well .. partially
instead of going the hard way understanding how to get my own code into the kernel, understanding on how to get access to the pin descriptors and what has to be checked before accessing them

i just cheated! i modified the gpiolib.c and made on value_store an addition that every pin toggles twice before going into target state ... a little bit dangerous but now i have my information that i were looking for!
TEK0000.JPG
TEK0000.JPG (108.85 KiB) Viewed 30374 times

User avatar
odroid
Site Admin
Posts: 42312
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 3651 times
Been thanked: 2028 times
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by odroid »

Thank you for the capture..
It seems to be possible to make about 1~2Mhz toggling clock in user land driver or application.

Can you show me the modified gpiolib.c to find a way to generate more faster clock.
Or un-roll-loop option or other compiler optimization option will be helpful.

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

Code: Select all

static ssize_t gpio_value_store(struct device *dev,
322                 struct device_attribute *attr, const char *buf, size_t size)
323 {
324         const struct gpio_desc  *desc = dev_get_drvdata(dev);
325         unsigned                gpio = desc - gpio_desc;
326         ssize_t                 status;
327 
328         mutex_lock(&sysfs_lock);
329 
330         if (!test_bit(FLAG_EXPORT, &desc->flags))
331                 status = -EIO;
332         else if (!test_bit(FLAG_IS_OUT, &desc->flags))
333                 status = -EPERM;
334         else {
335                 long            value;
336 
337                 status = strict_strtol(buf, 0, &value);
338                 if (status == 0) {
339                         if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
340                                 value = !value;
                        gpio_set_value_cansleep(gpio, 1);
                        gpio_set_value_cansleep(gpio, 0);
                        gpio_set_value_cansleep(gpio, 1);
                        gpio_set_value_cansleep(gpio, 0);
341                         gpio_set_value_cansleep(gpio, value != 0);
342                         status = size;
343                 }
344         }
just as simple as it is! But there seems to be a lot more possible!
at the end of the day i had spoken with a workmate and he gave me the final hint how to insert my own files into the toolchain (editing the makefile and adding a flag)... it's a shame ... i am used to develop a lot software but i never dealt with toolchains manually XD ... i am spoiled kid, playing around with toys :) and odroid is my favorite

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

i just found the config flags for the RCU Subsystem
most of them sound like they were responsible for the OS behaviour?
can i set the linux to realtime mode with this to get predictable timing?
there are also the different kinds of shedulers in the config that may have an huge influence of the timing behaviour! But i do not understand them yet :)

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

Nice work!
The RT kernel patches might help you here, however I have not even tried the new 3.8 kernel from mdrjr yet. That would be the kernel to apply the RT patches to if you go that route.

Adjusting the linux schedulers might help some as would changing the nice levels of your process.

After playing with the USB IO board and building my own version of it, I have come to appreciate what hardware assist via PWM or SPI hardware can provide. I integrated one of these chips in my last PIC18F4550 board: TLC 5940 (16-PWM channels). Since I have somewhat mastered Eagle PCB design I think my next project will be a cape for the Odroid-X2 that implements level conversion and PWM based on a chip like this. Perhaps toss in a GPIO expander chip also....

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

well as far as i have digged into the config you can expand the userland GPIO controls for a predefined count of Pins and add directly the drivers for supported I2C Port expanders, so you should be able to almost automatically add your port expander to your sys/class/gpio

and as i heared from a workmade since 3.0 thr RT Patches hould be inside the kernel by default, configurable via the compilerswitches, but i did not found out which switches are responsible therfore

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

Not all of the RT patches are in mainline as yet
You need to install this patch: https://www.kernel.org/pub/linux/kernel ... ts/rt/3.8/

Their HOWTO wiki is here: https://rt.wiki.kernel.org/index.php/RT_PREEMPT_HOWTO

I have not played with mdrjr's 3.8 kernel as yet thinking it was still in early stages...

Is it ready enough for me to apply the RT patches and play with RT?

mdrjr
Site Admin
Posts: 12103
Joined: Fri Feb 22, 2013 11:34 pm
languages_spoken: english, portuguese
ODROIDs: -
Location: Brazil
Has thanked: 8 times
Been thanked: 154 times
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mdrjr »

mlinuxguy wrote:Not all of the RT patches are in mainline as yet
You need to install this patch: https://www.kernel.org/pub/linux/kernel ... ts/rt/3.8/

Their HOWTO wiki is here: https://rt.wiki.kernel.org/index.php/RT_PREEMPT_HOWTO

I have not played with mdrjr's 3.8 kernel as yet thinking it was still in early stages...

Is it ready enough for me to apply the RT patches and play with RT?
IF you don't want to relay on Sound.. Its fine.

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

RT patches applied to 3.8.4
I had to power cycle it as a mere reboot command failed to bring it up, so I'm not sure how stable it is as yet.
If its still up in the morning I'll run some latency tests.
I'm not sure my logic analyzer will sync to 1.8v so I may not be able to get any bit-bang timings

# uname -a
Linux linaro-ubuntu-desktop 3.8.4-rt2 #2 SMP PREEMPT RT Wed Mar 27 07:09:36 UTC 2013 armv7l armv7l armv7l GNU/Linux

As expected the IRQ handlers are in kernel thread context

Code: Select all

  501 ?        S      0:00 [irq/249-s3c_fb]
  505 ?        S      0:00 [irq/67-dma-pl33]
  538 ?        S      0:00 [irq/68-dma-pl33]
  569 ?        S      0:00 [irq/66-dma-pl33]
 1154 ?        S      0:00 [irq/102-ehci_hc]
 1158 ?        S      0:00 [irq/102-ohci_hc]
 1164 ?        S      0:00 [irq/76-s3c2410-]
 1165 ?        S      0:00 [irq/77-s3c2410-]
 1168 ?        S      0:00 [irq/124-hdmi]
 1177 ?        S      0:00 [irq/123-s5p-mix]
 1185 ?        S      0:00 [irq/180-exynos-]
 1191 ?        S      0:01 [irq/107-mmc0]
 1197 ?        S      0:00 [irq/109-dw-mci]
Cyclictest run with default power save options

Code: Select all

# cyclictest -p 80 -t5 -n
# /dev/cpu_dma_latency set to 0us
policy: fifo: loadavg: 0.55 0.83 0.69 1/212 8848

T: 0 ( 8844) P:80 I:1000 C:  10249 Min:     47 Act:   54 Avg:   54 Max:     112
T: 1 ( 8845) P:80 I:1500 C:   6833 Min:     46 Act:   67 Avg:   56 Max:     132
T: 2 ( 8846) P:80 I:2000 C:   5124 Min:     45 Act:   51 Avg:   53 Max:      91
T: 3 ( 8847) P:80 I:2500 C:   4099 Min:     48 Act:   54 Avg:   54 Max:      98
T: 4 ( 8848) P:80 I:3000 C:   3416 Min:     48 Act:   52 Avg:   53 Max:      88
And the same test run in performance mode

Code: Select all

# cyclictest -p 80 -t5 -n
# /dev/cpu_dma_latency set to 0us
policy: fifo: loadavg: 0.04 0.45 0.57 1/218 8990

T: 0 ( 8986) P:80 I:1000 C:   3542 Min:     10 Act:   11 Avg:   11 Max:      18
T: 1 ( 8987) P:80 I:1500 C:   2361 Min:     11 Act:   11 Avg:   11 Max:      20
T: 2 ( 8988) P:80 I:2000 C:   1771 Min:     11 Act:   11 Avg:   11 Max:      14
T: 3 ( 8989) P:80 I:2500 C:   1417 Min:     11 Act:   11 Avg:   11 Max:      16
T: 4 ( 8990) P:80 I:3000 C:   1180 Min:     11 Act:   12 Avg:   11 Max:      16

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

damn awesome ... i wish i could test it by myself but i am visiting my parents ... no equipment here Q_Q

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

Testing various GPIO output programs under the RT (real-time) kernel
ref: http://codeandlife.com/2012/07/03/bench ... pio-speed/

Simple bash script

Code: Select all

#!/bin/bash
# pin 31 GPIO
# pin 50 gnd
# pin 27 (vsync) used as +1.8v

# setup pin 31 for GPIO
#echo "87" > /sys/class/gpio/export
#echo "88" > /sys/class/gpio/export
# direction is output
echo "out" > /sys/class/gpio/gpio87/direction
echo "out" > /sys/class/gpio/gpio88/direction

echo 1 > /sys/class/gpio/gpio88/value
while true
do
        echo 1 > /sys/class/gpio/gpio87/value
        echo 0 > /sys/class/gpio/gpio87/value
done
Results
Default powersave options: 4.275Khz (RPI achives 3.4Khz)
Performance mode: 4.275Khz

Note: later on I will code up a RT aware C program

Python program

Code: Select all

#!/usr/bin/python
import time
# use gpiochip87 gpio 0         (toggle)
# use gpiochip88 gpio 1         (1.8v power)

try:
  # check to see if the pin is already exported
  open('/sys/class/gpio/gpio87/direction').read()
except:
  # it isn't, so export it
  print("exporting GPIO 87, gpiochip87 - GPF0 which is pin 31 on odroid-x header")
  open('/sys/class/gpio/export', 'w').write('87')

try:
  # check to see if the pin is already exported
  open('/sys/class/gpio/gpio88/direction').read()
except:
  # it isn't, so export it
  print("exporting GPIO 88, gpiochip88 - GPF0 which is pin 27 on odroid-x header")
  open('/sys/class/gpio/export', 'w').write('88')

# set gpiochip87 ID=0  on header pin 31 to output
open('/sys/class/gpio/gpio87/direction', 'w').write('out')
# set gpiochip88 ID=1  on header pin 27 to output
open('/sys/class/gpio/gpio88/direction', 'w').write('out')

# power on to logic convertor
open('/sys/class/gpio/gpio88/value', 'w').write("1")

for i in range(1000):
  open('/sys/class/gpio/gpio87/value', 'w').write("1")
  open('/sys/class/gpio/gpio87/value', 'w').write("0")

# remove GPIO87 and GPIO88 folder from file system
open('/sys/class/gpio/unexport', 'w').write('87')
open('/sys/class/gpio/unexport', 'w').write('88')
python results
performance mode: 4.6Khz (RPI results with special GPIO library 44khz)
Note: I will need to either make a C GPIO library to call from python or hunt up one I can modify for the Odroid-x

C program to toggle GPIO pin
modified from several examples found on the web

Code: Select all

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define SYSFSGPIO "/sys/class/gpio"

FILE *fp;

int main(int argc, char** argv)
{
        int toggle = 0;
        char value[6];

        if ((fp = fopen(SYSFSGPIO "/export", "ab")) == NULL)
        {
                        printf("Cannot open export file.\n");
                        exit(1);
        }
        //Set pointer to begining of the file
        rewind(fp);
        //Write value of "87" to the file
        strcpy(value,"87");
        fwrite(&value, sizeof(char), 2, fp);
        fclose(fp);

        if ((fp = fopen(SYSFSGPIO "/gpio87/direction", "rb+")) == NULL)
        {
                printf("Cannot open direction file.\n");
                exit(1);
        }
        //Set pointer to begining of the file
        rewind(fp);
        //Write our value of "out" to the file
        strcpy(value,"out");
        fwrite(&value, sizeof(char), 3, fp);
        fclose(fp);

        if ((fp = fopen(SYSFSGPIO "/gpio87/value", "rb+")) == NULL)
        {
                printf("Cannot open value file.\n");
                exit(1);
        }
        //Run an infinite loop - will require Ctrl-C to exit this program
        while(1)
        {
                toggle = !toggle;
                if(toggle)
                {
                        //Set pointer to begining of the file
                        rewind(fp);
                        //Write our value of "1" to the file
                        strcpy(value,"1");
                        fwrite(&value, sizeof(char), 1, fp);
                        fflush(fp);
                }
                else
                {
                        //Set pointer to begining of the file
                        rewind(fp);
                        //Write our value of "0" to the file
                        strcpy(value,"0");
                        fwrite(&value, sizeof(char), 1, fp);
                        fflush(fp);
                }
        }
        fclose(fp);
        return 0;
}
C program results: 142.9Khz
slightly modified C program results: 166.7Khz
changed fwrite to fputs result: 200Khz
Notes: For maximum performance, this would need to be redone to avoid the sysfs interface and follow what HK does in the linux kernel drivers to setup GPIO

Update:
It appears that I will have to do some more research and spend time developing a GPIO C library to provide fast access to GPIO. The sysfs interface has too much overhead and if I could reduce it to something like this:

Code: Select all

        gpio_request(EXYNOS4_GPA1(3), "bl_enable");
        gpio_direction_output(EXYNOS4_GPA1(3), power);
        gpio_free(EXYNOS4_GPA1(3));
I could get the speed up much faster. I found many RPI libraries where this has been done, and someone has even ported the Wiring library to the RPI.
This would make an excellent Odroid project if someone wanted to tackle porting Wiring to the odroid

Notes: I used the adafruit level converter found here: http://www.adafruit.com/products/395

mindforger
Posts: 242
Joined: Mon Feb 25, 2013 8:54 pm
languages_spoken: english, german
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mindforger »

the following post has been misplaced by myself into the wrong topic,
but for levelchangers i found some nice parts from farnell

soldering skills required

http://www.farnell.com/datasheets/1648269.pdf I2C 3.3V
http://www.farnell.com/datasheets/1633997.pdf I2C 5.0V

http://www.ti.com/lit/ds/symlink/sn74lvc2t45.pdf 2bit 5V
http://www.ti.com/lit/ds/symlink/sn74avc4t245.pdf 4bit 5V
http://www.ti.com/lit/ds/symlink/sn74avc8t245.pdf 8bit but only 3.6V

all of them are cheaper than a dollar and MAYBE available as DIP ... unfortunatly farnell storage is not well equipped in germany, there are lot more!!!!

i'll try having a look into your stuff when i can find any time, easter holiday with family is sucking away my free time :D

when i bought the O-X i hoped i could use it at work for quick prototyping via the GPIO (i am using some AVR32 at the moment but there is no user interface, i always used a self made socketlib and a wiznet LAN module to connect to the computer as interface) and some fun for home-entertainment .... now that i have worked deep into the GPIO Drivers and your research i may be able to get it working. My biggest problem on the whole thing was the understanding of linux ... commands, recompiling, filehandlers, mounting, drivers etc. it's hard for a windows spoiled linux noob to get into it

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

Please check the first post in this thread for an update
I now show the full mapping table for the 50-pin expansion header, use that for mapping the GPIO you want to the correct SYSFS export
http://forum.odroid.com/viewtopic.php?f=52&t=202#p950

DroidyDave
Posts: 15
Joined: Tue Apr 09, 2013 4:14 am
languages_spoken: english
ODROIDs: ODROID-X2
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by DroidyDave »

Hi All,

Thank you all for your input on this thread. I am new to kernel compiling and never would have figured this out. I am having some issues though, I am using this kernel:

https://www.kernel.org/pub/linux/kernel ... 8.4.tar.xz

and this patch:

https://www.kernel.org/pub/linux/kernel ... ts/rt/3.8/

The patch installs fine so I move on to the kernel install and follow these instructions (because the digitalhermit site in the HOWTO wiki is down):

http://www.howopensource.com/2011/08/ho ... and-10-04/

When I compile I am getting errors, started with the OHCI usb, fixed that and now there are other errors:

LD init/built-in.o
ld: no machine record defined
make: *** [vmlinux] Error 1

Anyway, since all the X2 boards are the same I was wondering if someone could post their .config file for 3.8.4 or whatever working kernel you have with GPIO pins enabled.

Thanks in advance.

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

From my post on zram and kernel 3.8.4
ref: http://forum.odroid.com/viewtopic.php?f=15&t=1051#p6051
topic: 3.8.4 RT on github
You can pull my working RT config from github: https://github.com/hardkernel/linux/blo ... oidx2_gpio

DroidyDave
Posts: 15
Joined: Tue Apr 09, 2013 4:14 am
languages_spoken: english
ODROIDs: ODROID-X2
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by DroidyDave »

Thanks mlinuxguy, I won't be able to try it until Monday but I will let you know if it worked.

DroidyDave
Posts: 15
Joined: Tue Apr 09, 2013 4:14 am
languages_spoken: english
ODROIDs: ODROID-X2
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by DroidyDave »

Well I got a lot farther. I can install the kernel and following the directions here:
http://forum.odroid.com/viewtopic.php?f=52&t=81

I can sync and reboot but the boot fails. I get D5 and D6 lights to come on, but then D5 goes off and D6 blinks. The Monitor does not get a signal so I don’t know what is going on. Three notes; I didn’t see a linux defconfig in the arch/arm/configs so I skipped that step. I tried cloning the git for 3.8.y-rt, but I got errors on the make, so I downloaded the zip, unzipped it, did the menuconfig then copied your .config over it and continued with the directions. Also I was reading in this post:
http://forum.odroid.com/viewtopic.php?f=15&t=1051#p6051
that you may need to update uboot for kernel 3.8.4, is that correct? Any other advice is greatly appreciated, I am very new to this.

Thanks,
DD

mdrjr
Site Admin
Posts: 12103
Joined: Fri Feb 22, 2013 11:34 pm
languages_spoken: english, portuguese
ODROIDs: -
Location: Brazil
Has thanked: 8 times
Been thanked: 154 times
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mdrjr »

If you are on a later image you should, also this statement only applies to eMMC.

DroidyDave
Posts: 15
Joined: Tue Apr 09, 2013 4:14 am
languages_spoken: english
ODROIDs: ODROID-X2
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by DroidyDave »

I wasn’t able to get it working, but I found Ubuntu_20130404_customized_X2-HDMI.img.tar.gz on this site:

http://odroid.mirrors.ofthe.us/Ubuntu/

That had the GPIO configured for sysfs and I was able to light up my LED board. I want to say thank you mlinuxguy for putting this guide together. I am switching from sysfs to memory map GPIO in this forum:

http://forum.odroid.com/viewtopic.php?f ... t=20#p5726

I am having issues so far but at least I know the GPIO works.

Thanks,
DD

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

Are you having issues with the mmap GPIO library? That should work regardless of if you have SYSFS GPIO enabled or not (as long as you stick with the c_mmap_example code)

Someone was having issues on ARCH linux with the GPIO matching my SYSFS mapping instructions but even that would go away by using my C mmap GPIO library since it directly modifies the GPIO registers.

Gisela0110
Posts: 14
Joined: Fri May 03, 2013 10:49 am
languages_spoken: english
ODROIDs: ODROID-X
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by Gisela0110 »

Hi I'm really new to linux . currently I'm trying to interface the i2c pins SDA/SCL .I'm unsure of this instruction - ( /sys/class/gpio# for file in gpio*; do echo -n "$file - ";cat $file/label; done ). how to I get to /sys/class/gpio/export . Thanks :D

mlinuxguy
Posts: 842
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Has thanked: 0
Been thanked: 0
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by mlinuxguy »

I2c is different than GPIO pins. For I2c you will need to use the samsung I2c driver, which works or does not variously under the different kernels (I have not kept track of which work, last I knew 3.8.4 i2c driver did not).

User avatar
memeka
Posts: 4420
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART
Has thanked: 2 times
Been thanked: 61 times
Contact:

Re: Identify GPIO pins on output header ( howto )

Post by memeka »

FYI,

this is a patch to enable 1-wire protocol on PIN 17 (GPX1.6), if the Dallas 1-wire protocol is selected in the kernel configuration (DEVICE DRIVERS -> DALLAS 1-wire support -> 1-wire Bus Masters -> GPIO 1-wire busmaster):

http://forum.odroid.com/viewtopic.php?f ... 180#p28180

Post Reply

Return to “Ubuntu (All Linux'es)”

Who is online

Users browsing this forum: No registered users and 1 guest