GPIO toggle Kernel Module for Beaglebone

3,701 views
Skip to first unread message

Wesley

unread,
Aug 30, 2012, 5:04:39 PM8/30/12
to beagl...@googlegroups.com
Hey,

So I tested to see how fast the GPIO toggle rate of the Beaglebone could get when using a kernel module. When using user space it was only about 4-5 MHz and once I did the kernel module it got up to 25 MHz. Since I had a difficult time getting the kernel source tree on the beaglebone and compiling everything here is some documentation and code for those who want to build kernel modules/device drivers on the beaglebone and also user program interaction with the kernel module.

gpio.c is the kernel code
gpio.h is the header file for both gpio.c and ioctl.c
ioctl.c is the user code

Here is my Makefile in case you want it also

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
obj-m := gpio.o

KERNELDIR := /usr/src/linux-3.2.23

default:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Also, the websites that I used that helped me get here were mainly these:
https://groups.google.com/forum/#!msg/beagleboard/BKnNkP3qzQs/PNloua3737MJ
http://www.cemetech.net/forum/viewtopic.php?t=7814
and the Linux Device Drivers book

~Wesley

gpio.c
gpio.h
ioctl.c
Kernel Module Documentation.txt

Jack Mitchell

unread,
Aug 31, 2012, 4:12:13 AM8/31/12
to beagl...@googlegroups.com
> <https://groups.google.com/forum/#%21msg/beagleboard/BKnNkP3qzQs/PNloua3737MJ>
> http://www.cemetech.net/forum/viewtopic.php?t=7814
> <http://www.cemetech.net/forum/viewtopic.php?t=7814>
> and the Linux Device Drivers book
>
> ~Wesley
>
> -- To join: http://beagleboard.org/discuss
> To unsubscribe from this group, send email to:
> beagleboard...@googlegroups.com
> Frequently asked questions: http://beagleboard.org/faq

Hi Wesley,

Seems like a good start, is there any reason you didn't use the GPIO
lib? Possibly for speed?It would be interesting to see if there was much
difference.

Well done for having a go and getting it working!

Regards,
Jack

--

Jack Mitchell (ja...@embed.me.uk)
Embedded Systems Engineer
http://www.embed.me.uk

--

Mark A. Yoder

unread,
Nov 12, 2012, 10:16:12 AM11/12/12
to beagl...@googlegroups.com
I've moved my class away from using bitbake for kernel work.  Here[1] are the instructions we use to prepare for kernel work.

--Mark

[1] http://elinux.org/EBC_Exercise_08_Installing_Development_Tools

On Monday, November 12, 2012 7:45:24 AM UTC-5, ksrenjith wrote:
Great guide,,Thank you so much,,

I followed your notes to start my play with beaglebone,,but when trying to bitbake,getting an error:ERROR:  OE-core's config sanity checker detected a potential misconfiguration.
    Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
    Following is the list of potential problems / advisories:

    Do not use Bitbake as root.
ERROR: Execution of event handler 'check_sanity_eventhandler' failed
 
in my ubuntu 12.04,,,I have tried it without sudo then again getting error like,,, OperationalError: attempt to write a readonly database

After so much googling I did this,as a starter in Linux I don't have much idea to solve this without proper direction.It looks like some of the files are owned by root,I do not have access to these files.Please help me to solve this.I am waiting to start my studies with beaglebone.Thanks in advance for your time and consideration.

Erik Dahlinghaus

unread,
Nov 12, 2012, 10:22:34 AM11/12/12
to beagl...@googlegroups.com
On the folder that you have setup-scripts downloaded, use chown to take ownership of the folder. Something like 'chown -r [username]:[username] setup-scripts' if you're above the folder. Replace [username] with your username.



On Monday, November 12, 2012 7:45:24 AM UTC-5, ksrenjith wrote:
Great guide,,Thank you so much,,

I followed your notes to start my play with beaglebone,,but when trying to bitbake,getting an error:ERROR:  OE-core's config sanity checker detected a potential misconfiguration.
    Either fix the cause of this error or at your own risk disable the checker (see sanity.conf).
    Following is the list of potential problems / advisories:

    Do not use Bitbake as root.
ERROR: Execution of event handler 'check_sanity_eventhandler' failed
 
in my ubuntu 12.04,,,I have tried it without sudo then again getting error like,,, OperationalError: attempt to write a readonly database

After so much googling I did this,as a starter in Linux I don't have much idea to solve this without proper direction.It looks like some of the files are owned by root,I do not have access to these files.Please help me to solve this.I am waiting to start my studies with beaglebone.Thanks in advance for your time and consideration.



On Friday, 31 August 2012 02:34:39 UTC+5:30, Wesley wrote:

Juanjo

unread,
Nov 12, 2012, 8:24:11 PM11/12/12
to beagl...@googlegroups.com
Nice ! I've been using the PRUSS on the BB. Each instruction which don't go out of local memory takes 5ns, so basically using one of the GPIO lines hooked to the PRUSS you could achieve more than 25[Mhz]

LOOP:
      SET r30.t15
      CLR r30.t15
      QBA LOOP

Should takes 15ns (33% duty cycle) that would be 66 [Mhz]

LOOP:
     SET r30.t15
     XOR r0, r0, 0
     CLR r30.t15
     QBA LOOP

Should take 20ns (%50 duty cycle) at 50 [Mhz]

PRUSS seems pretty useful for bit-banging, right now I'm trying to use it to make a "soft" i2s decoder to spare McASP0 for audio cape.

ksrenjith

unread,
Nov 19, 2012, 1:25:47 AM11/19/12
to beagl...@googlegroups.com
Thank you so much for your reply,,I could solve my problem,,

ksrenjith

unread,
Nov 19, 2012, 1:26:11 AM11/19/12
to beagl...@googlegroups.com
Thank you so much for your reply,,I could solve my problem,,

csu...@idapl.in

unread,
Sep 5, 2014, 4:38:48 AM9/5/14
to beagl...@googlegroups.com
does this kernel module will help me for my linux kernel 3.8.13-bone47 which is installed in my beagelbone black

thanking you

sumik chakka

Mihai Seba

unread,
Feb 7, 2016, 6:16:38 AM2/7/16
to BeagleBoard
Hi,

I took a look to your code and I have a question.

I don't understand these 3 instruction...
  gpioSetAddr = baseAddr + (0x4804c194 - MMAP_OFFSET);
  gpioClearAddr = baseAddr + (0x4804c190 - MMAP_OFFSET);
  directionAddr = baseAddr + (0x4804c134 - MMAP_OFFSET);

baseAddr I understood that is the address returned by ioremap and 0x4804c194,0x4804c190 and 0x4804c134 are the address of registers OE, SET_DATAOUT and CLEAR_DATAOUT took from datasheet. But why you subtracted MMAP_OFFSET from this addresses?

Best Regards,
Mihai Seba

rudydelo...@gmail.com

unread,
Oct 25, 2018, 8:41:29 PM10/25/18
to BeagleBoard
Hi Wesley,

I'm interested in checking this out!

The download links are broken, are you able to post new links?

Hope you're having a top day :D

-Rudy.

TJF

unread,
Oct 26, 2018, 11:23:01 PM10/26/18
to BeagleBoard
Hi Rudy!

Bitbanging from kernel module puts a lot of load on the ARM CPU and slows down the whole system.

Find an example on how to toggle a fast PRU GPIO at this link. It runs at user space, no reboot nor administrator privileges necessary. The code limits the toggling frequency down to 40 MHz in order to get good measurements by the eCAP feature. When you remove the NOOPs from the PRU ASM code you can get up to 200 MHz toggling frequency (=100 MHz pulse train @ 50 % duty cycle).

Regards

Bill Bitner

unread,
Oct 29, 2018, 10:12:24 AM10/29/18
to beagl...@googlegroups.com
Hi Rudy!   I'm not sure where the link was supposed to point to but I found the following an
excellent guide to experimenting the PRU's using the 4.14 series kernel. (you would have to
update for this to apply)


Bill Bitner

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/a282b742-f1db-4fc6-afa9-2c15599c5f59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rudy Misek

unread,
Oct 31, 2018, 9:54:58 AM10/31/18
to beagl...@googlegroups.com
Thank you guys!! Have a great rest of the week ✌

You received this message because you are subscribed to a topic in the Google Groups "BeagleBoard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/beagleboard/dyuax5415dc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/CAOYP4dhSp%3Dnbnq7BwYKb2vhpmKVCapfNyRPayC7q2nvDWvNN7A%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages