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
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.
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.
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]
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?
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).
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)
(https://github.com/MarkAYoder/PRUCookbook)