Using pwm-gpio-custom to control servo

445 views
Skip to first unread message

Rob Jackson

unread,
Aug 15, 2011, 9:02:00 PM8/15/11
to Bifferboard
Hi. I'm running 8MB Bifferboard and I'm having some difficulty using
pwm-gpio-custom.


root@OpenWrt:/lib/modules/2.6.32.33# insmod pwm-gpio-custom bus0=0,16
root@OpenWrt:/lib/modules/2.6.32.33# lsmod | grep pwm
pwm_gpio_custom 1036 0
root@OpenWrt:/lib/modules/2.6.32.33#

I can verify that the resource (pin 16, red LED) is busy because I
can't change gpio16/value.

Where in the filesystem (if at all) are the bus/PWM objects mounted
and how to manipulate them?


Andrew Scheller

unread,
Aug 17, 2011, 2:46:36 PM8/17/11
to biffe...@googlegroups.com
Dunno if it helps, but did you already have a look at this? (found
near the top of the google search results)
http://groups.google.com/group/bifferboard/browse_thread/thread/abe46bfec6f64909

Lurch

> --
> To unsubscribe send email to bifferboard...@googlegroups.com
>

nicolas le falher

unread,
Aug 18, 2011, 4:33:47 AM8/18/11
to biffe...@googlegroups.com
Hi,

Don't know why, but a character device (gpio_pwm) is not created in
/dev (tested on 2.6.32.33 and 2.6.38.8).
The package i2c-gpio-custom use nearly the same init code, and it works.
If I got time, I going tested this on an other platform.

Regards.

Ps : If I load pwm-gpio-custom on gpio 16, I can manage led without
problem, it's not locked.
--

Nicolas Le Falher.

nicolas le falher

unread,
Aug 18, 2011, 3:30:29 PM8/18/11
to biffe...@googlegroups.com
Ok, pwm drivers is not linked to the kernel.
It seem run on 2.6.38.8, let me make patch, and I'll send another mail with.

root@OpenWrt:/# insmod pwm-gpio-custom bus0=0,16
Custom GPIO-based pwm driver version 0.1.0
gpio_pwm gpio_pwm.0: 1 channel
root@OpenWrt:/# ls /sys/class/
bdi          i2c-dev      mem          pci_bus      scsi_disk
block        input        misc         ppp          scsi_host
firmware     leds         mtd          pwm          tty
gpio         mdio_bus     net          scsi_device
root@OpenWrt:/# ls /sys/class/pwm/
gpio_pwm.0:0
root@OpenWrt:/# ls /sys/class/pwm/gpio_pwm.0\:0/
device     period_ns  request    subsystem
duty_ns    polarity   run        uevent

--

Nicolas Le Falher.

nicolas le falher

unread,
Aug 18, 2011, 6:24:12 PM8/18/11
to biffe...@googlegroups.com
So, with kernel 2.6.32, I don't have sysfs support for pwm.
You need to upgrade to 2.6.38.8.

How to proceed :

- Download a fresh trunk : svn co svn://svn.openwrt.org/openwrt/trunk
- Extract patch from archive in attachment (overwrite patch when is needed).
- Edit file target/linux/rdc/Makefile and replace "LINUX_VERSION:=2.6.32.33" by "LINUX_VERSION:=2.6.38.8".
- Prepare kernel : make prepare
- Edit kernel and select pwm driver : make kernel_menuconfig
   Device Drivers  --->
   <*> PWM Support  --->
   <*>   PWM emulation using GPIO
- Select Bifferboard platform and package kmod-pwm-gpio-custom : make menuconfig
- Make your jffs2 image : make
- flash your board.

After loading module, you should have an entry in /sys/class/pwm.
I don't know how manage that, if you are able to found, share here.

Ps : If someone know how select a kernel symbol by a package, I'm interested.

--

Nicolas Le Falher.
target.tar.gz

nicolas le falher

unread,
Aug 20, 2011, 5:42:19 AM8/20/11
to biffe...@googlegroups.com
Hi,

Here is the method to produce a 100hz signal, with 50% of output :

Load module on gpio 12.
# insmod pwm-gpio-custom bus0=0,12

Important ! Init @tick_hz at 1000000000UL (hardcoded in openwrt version, not on git).
Without that, period_ns and duty_ns always goes to 0, because tick_hz = 0.
# cat /sys/class/pwm/gpio_pwm.0\:0/request

Define 100hz period.
# echo 10000000 > /sys/class/pwm/gpio_pwm.0\:0/period_ns

Define percent when gpio goes polarity for one tick.
Base polarity is 0, so here 10% of tick is 0v, 90% is +3.3v.
If you set polarity to 1, gpio goes 10% to 3.3v, and 90% to 0v.
# echo 1000000 > /sys/class/pwm/gpio_pwm.0\:0/duty_ns

Running pwm.
# echo 1 > /sys/class/pwm/gpio_pwm.0\:0/run

Analyzer, polarity set to 0 : http://www.imagup.com/data/1128498509.html
Analyzer, polarity set to 1 : http://www.imagup.com/data/1128498569.html

ref lkml : https://lkml.org/lkml/2011/4/6/17810000000
ref git for variable : http://git.billgatliff.com/pwm.git/?p=pwm.git;a=blob;f=include/linux/pwm/pwm.h

Regards.

--

Nicolas Le Falher.

Andrew Scheller

unread,
Aug 20, 2011, 6:34:05 AM8/20/11
to biffe...@googlegroups.com
> Here is the method to produce a 100hz signal, with 50% of output :

That's great work Nicolas!
Would you be willing to type this all up on the wiki? :)

Lurch

nicolas le falher

unread,
Aug 20, 2011, 6:42:19 AM8/20/11
to biffe...@googlegroups.com
That's great work Nicolas!
Would you be willing to type this all up on the wiki? :)

Sure, give me an access to the wiki and I add this.
But, maybe Biff must add patchs to git before no ? Or validate all works on 2.6.38.8 before ?

--

Nicolas Le Falher.

biff...@yahoo.co.uk

unread,
Aug 20, 2011, 4:00:41 PM8/20/11
to Bifferboard
About the wiki, you have to send me the google account you want to use
to access the site, then I can send an invitation.

If git switches to 2.6.38.8, then first rtai hal patches must be
applied to that and all other patches rebased for this kernel
version. I depends on what you think will be easiest.

cheers,
Biff.

nicolas le falher

unread,
Aug 20, 2011, 8:27:26 PM8/20/11
to biffe...@googlegroups.com
Hi Biff,

About the wiki, you have to send me the google account you want to use
to access the site, then I can send an invitation.

You can take this mail : n.lef...@gmail.com
 
If git switches to 2.6.38.8, then first rtai hal patches must be
applied to that and all other patches rebased for this kernel
version.  I depends on what you think will be easiest.

Can you list all patches that you changed from Openwrt ?

biff...@yahoo.co.uk

unread,
Aug 20, 2011, 9:02:39 PM8/20/11
to Bifferboard, nicolas le falher
On Aug 21, 1:27 am, nicolas le falher <n.lef...@gmail.com> wrote:
> You can take this mail : n.lef...@gmail.com

Invitation has been sent.

> > If git switches to 2.6.38.8, then first rtai hal patches must be
> > applied to that and all other patches rebased for this kernel
> > version.  I depends on what you think will be easiest.
>
> Can you list all patches that you changed from Openwrt ?

You can see that from doing a diff between this:
https://github.com/bifferos/openwrt/tree/master/target/linux/rdc/patches-2.6.32
and this:
https://dev.openwrt.org/browser/trunk/target/linux/rdc/patches-2.6.32

(no generic patches have been changed).

However, be aware I changed r6040.c driver to be a file to avoid
having several patches in git. I think it's simpler like that.


For support of 2.6.38 it's necessary to copy this to git:
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-2.6.38
and this:
https://dev.openwrt.org/browser/trunk/target/linux/generic/config-2.6.38

That is not so hard, it just needs testing.

but then you need these:
https://github.com/bifferos/openwrt/tree/master/target/linux/rdc/files-2.6.38
https://github.com/bifferos/openwrt/tree/master/target/linux/rdc/patches-2.6.38
https://github.com/bifferos/openwrt/blob/master/target/linux/rdc/config-2.6.38

Which don't exist at all in OpenWrt, see:
https://dev.openwrt.org/browser/trunk/target/linux/rdc

As you can see there is nothing after 2.6.32 in terms of RDC-specific
patches, so the old ones have to be re-based to 2.6.38.

regards,
Biff.


Rob Jackson

unread,
Aug 21, 2011, 3:05:54 PM8/21/11
to Bifferboard
When I do that, I get a kernel panic.

All bugs added by David S. Miller <da...@redhat.com>
VFS: Cannot open root device "(null)" or unknown-block(0,0)
Please append a correct "root=" boot option; here are the available
partitions:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-
block(0,0)
Pid: 1, comm: swapper Not tainted 2.6.38.8 #1
Call Trace:
[<c02458f6>] ? 0xc02458f6
[<c029e8fa>] ? 0xc029e8fa
[<c029ea0d>] ? 0xc029ea0d
[<c029e59b>] ? 0xc029e59b
[<c029eb51>] ? 0xc029eb51
[<c029e689>] ? 0xc029e689
[<c01029f6>] ? 0xc01029f6
>  target.tar.gz
> 30KViewDownload

nicolas le falher

unread,
Aug 21, 2011, 3:36:39 PM8/21/11
to biffe...@googlegroups.com

Can you set cmndline in Bifboot to blank, and retry ?

nicolas le falher

unread,
Aug 25, 2011, 12:34:55 PM8/25/11
to biffe...@googlegroups.com
> If git switches to 2.6.38.8, then first rtai hal patches must be
> applied to that and all other patches rebased for this kernel
> version.  I depends on what you think will be easiest.

Hi biff,

I switched to the 2.6.37.6 kernel has support because of the rtai
patches (pwm works with this version).
I see that you download from the cvs gna.org a copy of rtai
(stable_cvs_20110206.tar.bz2).
I also try, but the anonymous access fails, it seems that the cvs
server does not accept it.

How did you download ? Do you have a tip?

--

Nicolas Le Falher.

nicolas le falher

unread,
Aug 27, 2011, 9:37:08 AM8/27/11
to biffe...@googlegroups.com
Hi,

So, i finally got a workable copy for RTAI and it's ported on kernel 2.6.37.6.
But the binary "rtai-led-demo" never light the LED error on blink, and
got one tick on pulsate mode (with git version too).

Someone can test for confirm ?

Markos Vakondios

unread,
Aug 27, 2011, 10:25:58 AM8/27/11
to biffe...@googlegroups.com
Sure, can you tell me what to get from git?





Nicolas Le Falher.

nicolas le falher

unread,
Aug 27, 2011, 10:33:57 AM8/27/11
to biffe...@googlegroups.com
> Sure, can you tell me what to get from git?

You need to compile your own image from git for test because RTAI is
not included in factory firmware.
http://sites.google.com/site/bifferboard/Home/openwrt-git

In make menuconfig, add this :
Base system --->
<*> rtai-led-demo

After get flashed your Bifferboard, launch "rtai-led-demo blink" or
"rtai-led-demo pulsate" and watch the error led.

--

Nicolas Le Falher.

Markos Vakondios

unread,
Aug 29, 2011, 9:17:24 AM8/29/11
to biffe...@googlegroups.com
It works for me.
Here is the output after compiling the latest git branch:

root@OpenWrt:/# killall watchdog; rmmod rdc321x_wdt
root@OpenWrt:/# insmod rtai_hal
I-pipe: Domain RTAI registered.
RTAI[hal]: <3.8.1> mounted over IPIPE-NOTHREADS 2.7-03.
RTAI[hal]: compiled with gcc version 4.1.2.
RTAI[hal]: mounted (IPIPE-NOTHREADS, IMMEDIATE (INTERNAL IRQs DISPATCHED), ISOL_CPUS_MASK: 0).
PIPELINE layers:
c38fd380 9ac15d93 RTAI 200
c02c51e0 0 Linux 100
root@OpenWrt:/# insmod rtai_lxrt
RTAI[malloc]: global heap size = 2097152 bytes, <BSD>.
RTAI[sched]: loaded (IMMEDIATE, UP, USER/KERNEL SPACE: <without RTAI OWN KTASKs>, kstacks pool size = 524288 bytes.
RTAI[sched]: hard timer type/freq = 8254-PIT/1193180(Hz); default timing: periodic; linear timed lists.
RTAI[sched]: Linux timer freq = 250 (Hz), TimeBase freq = 1193180 hz.
RTAI[sched]: timer setup = 1676 ns, resched latency = 2514 ns.
RTAI[usi]: enabled.
root@OpenWrt:/# insmod rtai_fifos
root@OpenWrt:/# rtai-led-demo pulsate
Task is now realtime!
root@OpenWrt:/# rtai-led-demo blink
Task is now realtime!

Both demos work as expected.

Nicolas: I was expecting kernel 2.6.37.6. on this git branch based on your previous msg:
"...So, i finally got a workable copy for RTAI and it's ported on kernel 2.6.37.6..."

But on:
uname -a
Linux OpenWrt 2.6.32.20 #5 Mon Aug 29 15:45:18 EEST 2011 i486 GNU/Linux

Am I missing something?






Nicolas Le Falher.

nicolas le falher

unread,
Aug 29, 2011, 9:41:03 AM8/29/11
to biffe...@googlegroups.com

You missing nothing.
I make my test on 2.6.37.6 and 2.6.32.20 (git version).

Modules loaded without error but led never light as expected.
I'm going to retry today, maybe I make a error.

Thanks for reply.

Markos Vakondios

unread,
Aug 29, 2011, 9:54:26 AM8/29/11
to biffe...@googlegroups.com
Is there a 2.6.37.6 git branch for bb?

nicolas le falher

unread,
Aug 29, 2011, 10:05:18 AM8/29/11
to biffe...@googlegroups.com

If I got RTAI working on, maybe (because 2.6.37 support pwm class).

nicolas le falher

unread,
Aug 29, 2011, 12:27:54 PM8/29/11
to biffe...@googlegroups.com
I make a mistake, I don't killed watchog before my test ...
RTAI works on 2.6.37.6 too.

@Biff : Do you want other tests ?

--

Nicolas Le Falher.

biff...@yahoo.co.uk

unread,
Aug 29, 2011, 3:06:24 PM8/29/11
to Bifferboard

On Aug 29, 5:27 pm, nicolas le falher <n.lefal...@gmail.com> wrote:
> I make a mistake, I don't killed watchog before my test ...

Ahh, a common mistake!

> RTAI works on 2.6.37.6 too.
>
> @Biff : Do you want other tests ?

If the demo program works fine for blink and pulsate, then I think
it's working :). Let me know where I can pick up the patches from and
I'll add them to git.

cheers,
Biff.
Reply all
Reply to author
Forward
0 new messages