2008-08-24 21:38:50     gpio howto

Document created by Aaronwu Employee on Aug 7, 2013
Version 1Show Document
  • View in full screen mode

2008-08-24 21:38:50     gpio howto

John Doe (UNITED STATES)

Message: 60962   

 

I need to start writing drivers for applications my team and I are developing for our senior project. Apparently I have my work cut out for me being the software guy. I have only used an HC12 in class so I am somewhat familiar with very low level code. My teacher seems to think that one of my partners in this group including myself are the best coders in the school right now. I have plenty of experience with cpp and c as well. I am not sure where to start looking for the files that I need to include within a source file when I am writing these drivers. For now just to get me started, and I understand that there is a sample gpio program with the kernel that flashes the LEDs. Thats all fine and dandy but I need to learn how to turn those LEDs off and on through my own program. I have been able to get the gpios to show themselves within /dev but manipulating them from userspace is what I need to learn how to do. If someone could point me to a file that I could use for a reference or a good document that explains things in depth that would be awesome. Also, if someone wouldnt mind working closely with me until I feel comfortable with the 537 that would be ideal. Our completion date is the middle of february.

QuoteReplyEditDelete

 

 

2008-08-25 05:37:30     Re: gpio howto

Yi Li (CHINA)

Message: 61007   

 

please refer to: http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:simple-gpio

QuoteReplyEditDelete

 

 

2008-08-25 10:31:58     Re: gpio howto

John Doe (UNITED STATES)

Message: 61025   

 

I have looked over that how to and that is where i get confused. I need assistance on what calls that I need to use to request a gpio, and how to use them. If I could get a very simple example it would be greatly appreciated.

QuoteReplyEditDelete

 

 

2008-08-25 12:24:37     Re: gpio howto

Mike Frysinger (UNITED STATES)

Message: 61029   

 

that driver is as simple as it gets.  it shows you how to use the gpio framework which is documented here:

http://docs.blackfin.uclinux.org/doku.php?id=gpio

QuoteReplyEditDelete

 

 

2008-08-25 13:02:16     Re: gpio howto

John Doe (UNITED STATES)

Message: 61033   

 

Thank you so very much Mike, that is exactly what I was looking for. I guess that I was searching a little too weird or just missed that page all together.

QuoteReplyEditDelete

 

 

2008-08-26 15:26:34     Re: gpio howto

John Doe (UNITED STATES)

Message: 61122   

 

I guess that I am not understanding where I am going wrong so i am going to attach the file that I have written and hope someone can point me in a better direction. I know that the asm/gpio.h include is for kernel space, but how do I call and configure specific ports?

 

simple_gpio.c

QuoteReplyEditDelete

 

 

2008-08-26 15:55:25     Re: gpio howto

Mike Frysinger (UNITED STATES)

Message: 61127   

 

asm/gpio.h can only be used from kernel code.  it is not for userspace in any way.  so what exactly are you trying to do ?

QuoteReplyEditDelete

 

 

2008-08-26 16:02:25     Re: gpio howto

Ed Sutter (UNITED STATES)

Message: 61128   

 

Dustin,

 

If all you need to do is be able to play with GPIO pins from user space, then you probably can get by with the simple-gpio-test.  That gives you a real easy example of how to play with the gpio pins from a user program.

QuoteReplyEditDelete

 

 

2008-08-26 16:31:07     Re: gpio howto

John Doe (UNITED STATES)

Message: 61129   

 

So then the code that is on the simple gio page is similar to what my driver would look like? So, if that is the case with that page, do I replace the blatent keywords with specific pins that are in /dev?

QuoteReplyEditDelete

 

 

2008-08-26 16:41:51     Re: gpio howto

John Doe (UNITED STATES)

Message: 61130   

 

what I am really trying to do is make one of the LED's flash on the board, without using the program that is included with the kernel. So what I have read is this page: http://docs.blackfin.uclinux.org/doku.php?id=gpio

QuoteReplyEditDelete

 

 

2008-08-26 17:15:06     Re: gpio howto

Ed Sutter (UNITED STATES)

Message: 61132   

 

Either you're confused or I'm confused (probably the latter)... You have to use the code that is in the kernel; however, that doesn't mean you touch it.  You just interface to it by opening up the device (in user space) and accessing the driver.  In your earlier post you said:

 

... I need to learn how to turn those LEDs off and on through my own program. I have been able to get the gpios to show themselves within /dev but manipulating them from userspace is what I need to learn how to do....

 

I think you're getting confused between driver code (kernel) and application code (user).  If you just want to use the driver that is already in place to manipulate GPIO pins, then you should be able to refer to the code under user/blkfin-test/simple-gpio-test.  

QuoteReplyEditDelete

 

 

2008-08-26 17:16:10     Re: gpio howto

John Doe (UNITED STATES)

Message: 61133   

 

i feel really friggin stupid!! never did i once think to go a look at simple-gpio-test.c!! sorry for any frustration that I may have caused any one and thank you very much for your patience.

QuoteReplyEditDelete

 

 

2008-08-28 14:05:00     Re: gpio howto

John Doe (UNITED STATES)

Message: 61273   

 

I thought that I had this correct, can someone look at the code and let me know where i may be going wrong, i get a pretty mean dump from kernel. it compiles fine but doesnt run as expected.

 

simple_gpio.c

QuoteReplyEditDelete

 

 

2008-08-28 14:10:09     Re: gpio howto

Mike Frysinger (UNITED STATES)

Message: 61274   

 

post the actual output you're getting from the kernel.  often times, dump messages show you the source of your problem as we document in the wiki:

http://docs.blackfin.uclinux.org/doku.php?id=debuging_applications#analyzing_traces

QuoteReplyEditDelete

 

 

2008-08-28 16:15:54     Re: gpio howto

John Doe (UNITED STATES)

Message: 61277   

 

Thank you mike, ill read that page as soon as I get off of work.

 

kernelDump.txt

QuoteReplyEditDelete

 

 

2008-08-28 16:28:01     Re: gpio howto

Mike Frysinger (UNITED STATES)

Message: 61278   

 

yes, it would seem your code has a NULL pointer dereference ... that wiki page should assist you in finding out where it is (or you could try using gdb)

QuoteReplyEditDelete

 

 

2008-09-01 01:58:57     Re: gpio howto

John Doe (UNITED STATES)

Message: 61457   

 

good news, i've figured a lot out... but now i would like to try to make the attached file flash the leds faster. im not sure if it is the algorithm or the board itself. i have tried different combinations of time. any help is greatly appreciated.

 

take2.c

QuoteReplyEditDelete

 

 

2008-09-01 11:47:37     Re: gpio howto

Mike Frysinger (UNITED STATES)

Message: 61481   

 

"faster" is a relative term.  what speed exactly do you need ?

QuoteReplyEditDelete

 

 

2008-09-02 04:10:22     Re: gpio howto

John Doe (UNITED STATES)

Message: 61524   

 

i am not looking for a particular speed. my goal is to make the leds cycle from one side to the other as in leds all off initially, then led1 lights and as led1 is dimming i want led2 to light up and so forth. I dont think that I am using time() properly. in my file i have a varialbe of time_t <var>; when i read the man page it makes me think that type is in seconds and that I need to have a different type for smaller amounts of time. I just need to know if that is where my problem lies, and if not where else it might. Also, when using a pin from userspace, the leds for example, is it necessary to hold the pin low? or is there a better way to accomplish this?

QuoteReplyEditDelete

 

 

2008-09-02 09:32:17     Re: gpio howto

Mike Frysinger (UNITED STATES)

Message: 61541   

 

what are you expecting time() to do ?  as the man page says, it only gets the current time ... it does not delay/sleep in any way.

 

if you review the GPIO driver in the wiki, you'll see that writing values to the driver sets the GPIO state and it remains that way until your code tells the driver to change state again.

QuoteReplyEditDelete

 

 

2008-09-05 06:06:46     Re: gpio howto

John Doe (UNITED STATES)

Message: 61662   

 

This is the issue that I am having with time. I expect it to store a value in the variable that I send with it... and for some reason this isnt happening. I printed the value that was stored into the variable that I sent to time and received nothing but zero's. Is there a clock that I need to enable in my code ro in the kernel?

QuoteReplyEditDelete

 

 

2008-09-05 11:41:16     Re: gpio howto

Mike Frysinger (UNITED STATES)

Message: 61708   

 

there is nothing you need to enable other than the driver.  it simply uses the common GPIO api.  if a signal isnt going the way you expect, check your code.  the driver itself documents the simple API that it uses with userspace read/write commands.

QuoteReplyEditDelete

 

 

2008-09-07 21:29:12     Re: gpio howto

John Doe (UNITED STATES)

Message: 61763   

 

I have a new question involving  gptimers. how can i figure out which gpXX is a timer. I guess the better question is if there is a clock that I can use. I have looked at the hardware pdf and read the gptimers page and referenced the bf537 manual which says to reference the hardware for the port that the timers are usually on (port F). I cant find anything that shows or hints to what port or gpio it is in dev. i have enabled the timers in the kernel for it. I am trying to configure a timer that I can use  for timing when a pin should go high. I need to do it from user space, or if there is a way to read the core clock that would be even better.

QuoteReplyEditDelete

 

 

2008-09-07 22:36:33     Re: gpio howto

Mike Frysinger (UNITED STATES)

Message: 61767   

 

new questions get new threads

Attachments

Outcomes