Is anyone working on a pwm driver for the 'bone?

3643 views
Skip to first unread message

Steve

unread,
Jan 28, 2012, 12:27:57 AM1/28/12
to Beagle Board
The PWM hardware available on the beaglebone seems significantly
different than what's available on the beagleboard. I'd very much like
to take advantage of the PWM modules, but I have not been able to find
evidence of any meaningful progress towards a working driver. So far
I've been able to make progress in other areas, figuring out how to
interface with the ADCs, working through the exercise of dealing with
GPIO both via the driver, and via /dev/mem, and have a few UARTs
running, but I'm going to have to tackle this soon. I have some
background directly programming AVRs, but I feel like embarking on the
mission to scratch build a driver for the ePWM is going to be quite a
tedious (but fun I'm sure) process for me; my first attempts at
tickling the hardware via /dev/mem have been very much less than
successful. If you're working on something similar, or have heard of
someone that is, I'd love to be in touch. In the mean time I'm going
to go back to the books to more thoroughly read (and re-read I'm sure)
the PWMSS segments of the 335x TRM. Next step I suppose will be to
start dissecting some existing driver code to learn something about
that side of things (if anyone has a favorite bit of clean driver code
to take as example I'd love to take a look), and then finally start
gluing it together.

Thanks for any leads!
Steve

Mark Renouf

unread,
Feb 4, 2012, 10:38:50 AM2/4/12
to beagl...@googlegroups.com
Hi Steve,

I'm very much in the same boat as you. I'm a software engineer and have
a solid understanding of low level register-level operations but very little
knowledge of kernel development. My main use case fore the BeagleBone
requires PWM and I see nothing concrete in any of the kernels supporting
them.

My idea was to implement the fairly simple API defined in <linux/pwm.h>

What are your thoughts? It wont support some of the advanced features 
of the PWMSS on the am335x (chopper, dead-band, etc)  but it will be 
simple to use and already exists in the kernel, which is nice. 

I'm still trying to understand the mechanics of implementing that API and
registering that with the system so a userspace app can make those calls
but I think I can hack something together from examples.

So far all I have though is #include definitions for all of the registers defined
in the technical docs for the pwm subsystem.

I just posted the skeleton here and I'll try to update as I make progress.

Koen Kooi

unread,
Feb 5, 2012, 3:35:26 AM2/5/12
to beagl...@googlegroups.com

The new angstrom 3.2 kernel for beaglebone has drivers for both the eCAP PWMs and EHR PWMs: https://github.com/koenkooi/linux/tree/beaglebone-3.2

I'm using it on the 7" LCD cape for backlight.

regards,

Koen

Charles G. Nutter

unread,
Feb 5, 2012, 12:23:32 PM2/5/12
to beagl...@googlegroups.com, Charles Oliver Nutter
We are working on the PWM. Apparently, one must code up a driver to work with Linux.  We should have the code ready next week and will release it to the forum.  So far all the features on our bone worked well so we are encouraged. I anyone finds the same problem with PWM let us know. 
  


--
To join: http://beagleboard.org/discuss
To unsubscribe from this group, send email to:
beagleboard...@googlegroups.com
Frequently asked questions: http://beagleboard.org/faq



--

**Disclaimer from Silacon Corporation **
Privileged/confidential information may be contained in this message. If you are not the addressee indicated in this message (or responsible for the delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply e-mail. Please advise immediately if you or your employer does not consent to Internet e-mail for messages of this kind. Opinions, conclusions and other information in this message that pertain to the sender's employer and its products and services represent the opinion of the sender and do not necessarily represent or reflect the views and opinions of the employer. 
** End of disclaimer **


Charles G. Nutter, CEO
Silacon Corporation Email Cha...@silacon.com, sil...@gmail.com
AIM user name: charlesgnutter
Site www.silacon.com
Phone 651-738-1965 cell 651-738-1965 Skype 612-524-0240 Skype name charles.g.nutter CEO Silacon Corporation


Eric Fort

unread,
Feb 5, 2012, 12:36:12 PM2/5/12
to beagl...@googlegroups.com
once pwm is in place what will it take to get the proper frame rate and duty cycle out of the bone for rc servo positioning? (1-2ms pulses in a 20ms frame).  How will one specify/set up the desired frame rate and pulse width?

Eric

Koen Kooi

unread,
Feb 5, 2012, 12:48:14 PM2/5/12
to beagl...@googlegroups.com, beagl...@googlegroups.com, Charles Oliver Nutter
As I said in my mail earlier today, the drivers are already written, working and publically available. No bonescript integration yet, though.

Eric Fort

unread,
Feb 5, 2012, 1:10:04 PM2/5/12
to beagl...@googlegroups.com
Just found the code for PWM.c.  Any examples available to use the module via sysfs? 

Eric

sak

unread,
Feb 10, 2012, 10:03:07 PM2/10/12
to Beagle Board
Koen - I see this branch (:https://github.com/koenkooi/linux/tree/
beaglebone-3.2) has PWM and SPI enabled. Can you give me a pointer on
how to pull this into my OpenEmbedded/bitbake tree? I have set up
(and built a kernel, uImage, etc), but more as a trained monkey
following the instructions! As such, I'm at a bit of a loss of how to
insert your branch of the kernel in...

Thanks for your help.
Cheers,
Sridhar

sak@ubuntu:~/bone/oe$ ls
bitbake.lock build conf oebb.sh pseudodone scripts sources

Eric Gero

unread,
Feb 10, 2012, 11:28:43 PM2/10/12
to Beagle Board
Where did you find the code for PWM.c? Can you share a link?

Thanks,
Eric

On Feb 5, 1:10 pm, Eric Fort <eric.f...@gmail.com> wrote:
> Just found the code for PWM.c.  Any examples available to use the module
> via sysfs?
>
> Eric
>
>
>
> On Sun, Feb 5, 2012 at 9:48 AM, Koen Kooi <k...@beagleboard.org> wrote:
> > As I said in my mail earlier today, the drivers are already written,
> > working and publically available. No bonescript integration yet, though.
>
> > Op 5 feb. 2012 om 18:23 heeft "Charles G. Nutter" <sila...@gmail.com> het
> > volgende geschreven:
>
> > We are working on the PWM. Apparently, one must code up a driver to work
> > with Linux.  We should have the code ready next week and will release it to
> > the forum.  So far all the features on our bone worked well so we are
> > encouraged. I anyone finds the same problem with PWM let us know.
>
> > Silacon Corporation Email Char...@silacon.com, sila...@gmail.com
> > AIM user name: charlesgnutter
> > Sitewww.silacon.com

Koen Kooi

unread,
Feb 11, 2012, 12:09:05 AM2/11/12
to beagl...@googlegroups.com

Op 11 feb. 2012, om 04:03 heeft sak het volgende geschreven:

> Koen - I see this branch (:https://github.com/koenkooi/linux/tree/
> beaglebone-3.2) has PWM and SPI enabled. Can you give me a pointer on
> how to pull this into my OpenEmbedded/bitbake tree?

does ./oebb.sh update and you'll get it. Denys pulled in the patches to update it to 3.2.0 last night.

regards,

Koen

Eric Fort

unread,
Feb 11, 2012, 12:16:51 AM2/11/12
to beagl...@googlegroups.com
As mentioned by Koen above in this thread, his branch of the kernel sources can be found at https://github.com/koenkooi/linux.  looking at the drivers directory I could have sworn I found the pwm subdirectoy containing the code for PWM.c.  that said it seems to have disappeared right before my eyes when I went to look again.  Koen, was your kernel tree recently updated, possibly leaving that out?

Eric

Koen Kooi

unread,
Feb 11, 2012, 1:50:20 AM2/11/12
to beagl...@googlegroups.com, beagl...@googlegroups.com
You need one of branches with '3.2' in the name

Steve Galle

unread,
Feb 11, 2012, 2:56:02 AM2/11/12
to beagl...@googlegroups.com
Koen, thanks for your effort and time. I just built and installed a 3.2 based Angstrom image. 

I almost certainly did this *wrong*, I'm still coming to terms with the whole openembedded setup. What I did seems to have worked though, so for those who are curious here's what I did.

Following directions under the getting started web page, I did: 
git clone git://git.angstrom-distribution.org/setup-scripts
cd setup-scripts
./oebb.sh config beaglebone
Next I edited ~/.oe/environment-oecore, and updated the DISTRO variable to "angstrom-2012.x"
After that, I did: 

. ~/.oe/environment-oecore
bitbake systemd-image

That built all of the files I needed to create a (seemingly) working installation. I copied the various bits and pieces onto a card, powered up.  The 'bone booted up just fine, and I was able to log in over ssh. I've begun installing the required packages to run my platform, but there's a bit of work to do. I have not yet attached the scope and actually tried the pwm, but poking around in /sys looks promising: 


root@minnow_beta:/sys/class# cd pwm
root@minnow_beta:/sys/class/pwm# ls
ecap.0      ecap.1      ehrpwm.0:0  ehrpwm.0:1  ehrpwm.1:0  ehrpwm.1:1

So having typed all that, like I say, I'm sure this wasn't probably the right way to go about this. If anyone can point me at a link or provide better direction I'll be sure to pass it along the next time I see the question come up. 


Thanks again Koen and the rest of the dev team. 
Steve

Eric Fort

unread,
Feb 11, 2012, 3:00:28 AM2/11/12
to beagl...@googlegroups.com
Steve,

When you do get it working, please post some userspace example code (hopefully in C or python)

Thanks,

Eric

Koen Kooi

unread,
Feb 11, 2012, 3:24:59 AM2/11/12
to beagl...@googlegroups.com, beagl...@googlegroups.com
I suspect pwm is enabled, but not pinmuxed. Gerald reported some other problems with it as well. I'll look into it during my flight to the ELC conference since I need to demo it there :)

Arthur Neves

unread,
Feb 11, 2012, 2:52:05 PM2/11/12
to Beagle Board
Question,

Do I have to build the kernel local? or can I use the latest one from
http://www.angstrom-distribution.org/demo/beaglebone/ ?



On Feb 11, 3:24 am, Koen Kooi <k...@beagleboard.org> wrote:
> I suspect pwm is enabled, but not pinmuxed. Gerald reported some other problems with it as well. I'll look into it during my flight to the ELC conference since I need to demo it there :)
>
> Op 11 feb. 2012 om 08:56 heeft Steve Galle <stevega...@gmail.com> het volgende geschreven:
>
>
>
>
>
>
>
> > Koen, thanks for your effort and time. I just built and installed a 3.2 based Angstrom image.
>
> > I almost certainly did this *wrong*, I'm still coming to terms with the whole openembedded setup. What I did seems to have worked though, so for those who are curious here's what I did.
>
> > Following directions under the getting started web page, I did:
> > git clone git://git.angstrom-distribution.org/setup-scripts
> > cd setup-scripts
> > ./oebb.sh config beaglebone
> > Next I edited ~/.oe/environment-oecore, and updated the DISTRO variable to "angstrom-2012.x"
> > After that, I did:
>
> > . ~/.oe/environment-oecore
> > bitbake systemd-image
>
> > That built all of the files I needed to create a (seemingly) working installation. I copied the various bits and pieces onto a card, powered up.  The 'bone booted up just fine, and I was able to log in over ssh. I've begun installing the required packages to run my platform, but there's a bit of work to do. I have not yet attached the scope and actually tried the pwm, but poking around in /sys looks promising:
>
> > root@minnow_beta:/sys/class# cd pwm
> > root@minnow_beta:/sys/class/pwm# ls
> > ecap.0      ecap.1      ehrpwm.0:0  ehrpwm.0:1  ehrpwm.1:0  ehrpwm.1:1
>
> > So having typed all that, like I say, I'm sure this wasn't probably the right way to go about this. If anyone can point me at a link or provide better direction I'll be sure to pass it along the next time I see the question come up.
>
> > Thanks again Koen and the rest of the dev team.
> > Steve
>
> > On Feb 10, 2012, at 10:50 PM, Koen Kooi wrote:
>
> >> You need one of branches with '3.2' in the name
>
> >> Op 11 feb. 2012 om 06:16 heeft Eric Fort <eric.f...@gmail.com> het volgende geschreven:
>
> >>> As mentioned by Koen above in this thread, his branch of the kernel sources can be found athttps://github.com/koenkooi/linux.  looking at the drivers directory I could have sworn I found the pwm subdirectoy containing the code for PWM.c.  that said it seems to have disappeared right before my eyes when I went to look again.  Koen, was your kernel tree recently updated, possibly leaving that out?
>
> >>> Eric

Koen Kooi

unread,
Feb 11, 2012, 5:31:36 PM2/11/12
to beagl...@googlegroups.com

Op 11 feb. 2012, om 20:52 heeft Arthur Neves het volgende geschreven:

> Question,
>
> Do I have to build the kernel local? or can I use the latest one from
> http://www.angstrom-distribution.org/demo/beaglebone/ ?

As long as it's a 3.2 based kernel it will have PWM. Pinmuxing can be done in userspace.

Steve Galle

unread,
Feb 11, 2012, 6:10:09 PM2/11/12
to beagl...@googlegroups.com
Koen, hi. I am clearly doing something wrong; by any chance have you seen stack traces that look like the following, and can you offer any direction? I seem to get something similar if I write a '1' to 'run', or try to set a 'period_freq'. Is there a timer I need to start someplace, or anything like that?

Thanks! 
Steve

[14334.313849] Unhandled fault: external abort on non-linefetch (0x1028) at 0xfa302200
[14334.321857] Internal error: : 1028 [#4]
[14334.325854] Modules linked in: ipv6
[14334.329503] CPU: 0    Tainted: G      D       (3.2.0+ #1)
[14334.335144] PC is at ehrpwm_pwm_config+0x1d2/0x25e
[14334.340149] LR is at pwm_config+0x4d/0x5a
[14334.344330] pc : [<c013cde8>]    lr : [<c013bc6f>]    psr: 40000033
[14334.344337] sp : cfbd7ed0  ip : 00000000  fp : 000d9328
[14334.356306] r10: cf9bf208  r9 : cfb53958  r8 : cfb53940
[14334.361752] r7 : 00000002  r6 : 00000000  r5 : cf9bf400  r4 : cf9bf400
[14334.368557] r3 : c28f5c29  r2 : fa302200  r1 : 00000000  r0 : cf9bf400
[14334.375366] Flags: nZcv  IRQs on  FIQs on  Mode SVC_32  ISA Thumb  Segment user
[14334.382989] Control: 50c5387d  Table: 8f998019  DAC: 00000015
[14334.388979] Process sh (pid: 407, stack limit = 0xcfbd62f0)
[14334.394789] Stack: (0xcfbd7ed0 to 0xcfbd8000)
[14334.399332] 7ec0:                                     cfbd7f00 cf9bf400 00000002 00000002
[14334.407866] 7ee0: cfb53940 cfb53958 cf9bf208 c013bc6f 00000008 cf9bf400 cf9bf400 c013bd7d
[14334.416404] 7f00: 00000008 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[14334.424946] 7f20: cfac5000 c013c0ad c013c091 cfbd7f80 c0168365 c016836f cf9c2130 c00ab5ab
[14334.433487] 7f40: 00000002 cfb7b940 000db408 c00ab509 cfbd7f80 00000000 00000000 c0077a0b
[14334.442029] 7f60: cfb7b940 000db408 cfb7b940 000db408 00000002 00000004 00000000 c0077c2b
[14334.450568] 7f80: 00000000 00000000 00000002 00000000 00000002 000db408 4024d5d0 c000c564
[14334.459111] 7fa0: cfbd6000 c000c3c1 00000002 000db408 00000001 000db408 00000002 00000000
[14334.467652] 7fc0: 00000002 000db408 4024d5d0 00000004 00000002 4006b7f0 000c2d74 000d9328
[14334.476193] 7fe0: 00000000 beb84a00 4018a38c 401dd14c 60000010 00000001 00000000 00000000
[14334.484748] [<c013cde8>] (ehrpwm_pwm_config+0x1d2/0x25e) from [<c013bc6f>] (pwm_config+0x4d/0x5a)
[14334.494011] [<c013bc6f>] (pwm_config+0x4d/0x5a) from [<c013bd7d>] (pwm_start+0x1d/0x20)
[14334.502369] [<c013bd7d>] (pwm_start+0x1d/0x20) from [<c013c0ad>] (pwm_run_store+0x1d/0x48)
[14334.511008] [<c013c0ad>] (pwm_run_store+0x1d/0x48) from [<c016836f>] (dev_attr_store+0xb/0x12)
[14334.520006] [<c016836f>] (dev_attr_store+0xb/0x12) from [<c00ab5ab>] (sysfs_write_file+0xa3/0xda)
[14334.529279] [<c00ab5ab>] (sysfs_write_file+0xa3/0xda) from [<c0077a0b>] (vfs_write+0x5f/0x10c)
[14334.538272] [<c0077a0b>] (vfs_write+0x5f/0x10c) from [<c0077c2b>] (sys_write+0x27/0x48)
[14334.546641] [<c0077c2b>] (sys_write+0x27/0x48) from [<c000c3c1>] (ret_fast_syscall+0x1/0x44)
[14334.555448] Code: 20ec 10b6 435e b2f1 (8813) f023 
[14334.560596] ---[ end trace e201b1a995654158 ]---

Arthur Neves

unread,
Feb 20, 2012, 8:36:58 PM2/20/12
to Beagle Board
Any progress in here! ?

i have built the edge version - ~/setup-scripts/build/tmp-
angstrom_2010_x-eglibc/deploy/images/beaglebone/Angstrom-systemd-image-
eglibc-ipk-v2012.02-core-beaglebone.rootfs.tar.bz2

But Have no idea if PWM is working in there? anything?
> > As mentioned by Koen above in this thread, his branch of the kernel sources can be found athttps://github.com/koenkooi/linux.  looking at the drivers directory I could have sworn I found the pwm subdirectoy containing the code for PWM.c.  that said it seems to have disappeared right before my eyes when I went to look again.  Koen, was your kernel tree recently updated, possibly leaving that out?
>
> > Eric

Michael Lewis

unread,
Feb 22, 2012, 4:49:41 PM2/22/12
to Beagle Board
Arthur - I can't comment on the others' progress, but this looks
promising:
https://github.com/tallakt/servodrive

I might look into modifying the muxing to work with BeagleBone if it's
not too difficult.
> > > > >> The new angstrom 3.2 kernel forbeaglebonehas drivers for both the eCAP

Steve Galle

unread,
Feb 22, 2012, 5:23:10 PM2/22/12
to beagl...@googlegroups.com
The pwm hardware on the bone is completely different than what's on the beagleboard, so this code is probably moot. I was able to build a kernel with the modules for the beaglebone hardware, but had to leave town for work before I was able to get it working on my board.

Steve

Michael Lewis

unread,
Feb 24, 2012, 3:11:02 PM2/24/12
to Beagle Board
So I understand if you build a new image with the 3.2 kernel, it will
have PWM. How do you access it in userspace? What files in the rfs do
I need to read/write to?

- Mike

On Feb 22, 2:23 pm, Steve Galle <stevega...@gmail.com> wrote:
> Thepwmhardware on the bone is completely different than what's on the beagleboard, so this code is probably moot. I was able to build a kernel with the modules for thebeaglebonehardware, but had to leave town for work before I was able to get it working on my board.
>
> Steve
>
> On Feb 22, 2012, at 4:49 PM, Michael Lewis wrote:
>
>
>
>
>
>
>
> > Arthur - I can't comment on the others' progress, but this looks
> > promising:
> >https://github.com/tallakt/servodrive
>
> > I might look into modifying the muxing to work withBeagleBoneif it's
> > not too difficult.
>
> > On Feb 20, 5:36 pm, Arthur Neves <arthu...@gmail.com> wrote:
> >> Any progress in here! ?
>
> >> i have built the edge version - ~/setup-scripts/build/tmp-
> >> angstrom_2010_x-eglibc/deploy/images/beaglebone/Angstrom-systemd-image-
> >> eglibc-ipk-v2012.02-core-beaglebone.rootfs.tar.bz2
>
> >> But Have no idea ifPWMis working in there? anything?
> >>>> As mentioned by Koen above in this thread, his branch of the kernel sources can be found athttps://github.com/koenkooi/linux.  looking at the drivers directory I could have sworn I found thepwmsubdirectoy containing the code forPWM.c.  that said it seems to have disappeared right before my eyes when I went to look again.  Koen, was your kernel tree recently updated, possibly leaving that out?
>
> >>>> Eric
>
> >>>> On Fri, Feb 10, 2012 at 8:28 PM, Eric Gero <gero.e...@gmail.com> wrote:
> >>>> Where did you find the code forPWM.c?  Can you share a link?
>
> >>>> Thanks,
> >>>> Eric
>
> >>>> On Feb 5, 1:10 pm, Eric Fort <eric.f...@gmail.com> wrote:
> >>>>> Just found the code forPWM.c.  Any examples available to use the module
> >>>>> via sysfs?
>
> >>>>> Eric
>
> >>>>> On Sun, Feb 5, 2012 at 9:48 AM, Koen Kooi <k...@beagleboard.org> wrote:
> >>>>>> As I said in my mail earlier today, the drivers are already written,
> >>>>>> working and publically available. No bonescript integration yet, though.
>
> >>>>>> Op 5 feb. 2012 om 18:23 heeft "Charles G. Nutter" <sila...@gmail.com> het
> >>>>>> volgende geschreven:
>
> >>>>>> We are working on thePWM. Apparently, one must code up a driver to work
> >>>>>> with Linux.  We should have the code ready next week and will release it to
> >>>>>> the forum.  So far all the features on our bone worked well so we are
> >>>>>> encouraged. I anyone finds the same problem withPWMlet us know.
>
> >>>>>> On Sun, Feb 5, 2012 at 2:35 AM, Koen Kooi <k...@beagleboard.org> wrote:
>
> >>>>>>> Op 4 feb. 2012, om 16:38 heeft Mark Renouf het volgende geschreven:
>
> >>>>>>>> Hi Steve,
>
> >>>>>>>> I'm very much in the same boat as you. I'm a software engineer and have
> >>>>>>>> a solid understanding of low level register-level operations but very
> >>>>>>> little
> >>>>>>>> knowledge of kernel development. My main use case fore theBeagleBone
> >>>>>>>> requiresPWMand I see nothing concrete in any of the kernels supporting

dmmi...@gmail.com

unread,
Feb 25, 2012, 6:23:30 PM2/25/12
to beagl...@googlegroups.com
Michael,

I was going to write a PWM driver for the kernel but in the process of setting up my development environment I discovered, to my pleasant surprise, that it has already been done.  I have done some quick hacking around and have gotten PWM output working on the beaglebone.  I am running short on time right now so I'll just give a quick and dirty description on what I did to get PWM output.  I'll post some more detailed information when I have some available time tonight or tomorrow.

First of all, the errors that previous users have reported when doing things like, "echo 1 > run" in one of the PWM sysfs folders is caused by the clocks not being turned on for the PWM module.  To turn on the system clocks I used the mmap /dev/mem trick.  Just open /dev/mem then mmap that file into your address space.  The register of interest for me was the CM_PER_EPWMSS1 register, for the PWM1 module.  It is located at offset 0x44e000cc in the address space of the beaglebone's processor.  See page 1017 of the AM335x ARM Cortex-A8 reference manual and look down for that register.  After writing 0x2 to this register the clock should be enabled for the PWM module allowing you to write to the files in sysfs.

The next thing I did was set up the pin mux to get the PWM outputs out to the pad.  I did this with:

echo 6 > /sys/kernel/debug/omap_mux/gpmc_a2

Then to control the PWM module I did:

cd /sys/class/pwm/ehrpwm.1\:0
echo 1 > run
echo 100 > period_freq
echo 10 > duty_percent

Then I was able to see a 1ms pulse with period of 10ms on my oscope coming out of the expected pin on the beaglebone.  Can anyone say servo control? ^_^

The step to enable the PWM clocks seems very hackish.  Does anyone know if there is a way to do this through the sysfs instead of writing to /dev/mem directly?

I hope this helps you, and anyone else, get going.  Again, since I'm running short on time I'll post the code I used to enable the PWM clocks when I get time.

Dustin
> >>>>>>> beagleboard+unsubscribe@googlegroups.com
> >>>>>>> Frequently asked questions:http://beagleboard.org/faq
>
> >>>>>> --
>
> >>>>>> **Disclaimer from Silacon Corporation **
> >>>>>> Privileged/confidential information may be contained in this message. If
> >>>>>> you are not the addressee indicated in this message (or responsible for the
> >>>>>> delivery of the message to such person), you may not copy or deliver this
> >>>>>> message to anyone. In such case, you should destroy this message and kindly
> >>>>>> notify the sender by reply e-mail. Please advise immediately if you or your
> >>>>>> employer does not consent to Internet e-mail for messages of this kind.
> >>>>>> Opinions, conclusions and other information in this message that pertain to
> >>>>>> the sender's employer and its products and services represent the opinion
> >>>>>> of the sender and do not necessarily represent or reflect the views and
> >>>>>> opinions of the employer.
> >>>>>> ** End of disclaimer **
>
> >>>>>> Charles G. Nutter, CEO
> >>>>>> Silacon Corporation Email Char...@silacon.com, sila...@gmail.com
> >>>>>> AIM user name: charlesgnutter
> >>>>>> Sitewww.silacon.com
> >>>>>> Phone 651-738-1965 cell 651-738-1965 Skype 612-524-0240 Skype name
> >>>>>> charles.g.nutter CEO Silacon Corporation
>
> >>>>>>  --
> >>>>>> To join:http://beagleboard.org/discuss
> >>>>>> To unsubscribe from this group, send email to:
> >>>>>> beagleboard+unsubscribe@googlegroups.com
> >>>>>> Frequently asked questions:http://beagleboard.org/faq
>
> >>>>>>  --
> >>>>>> To join:http://beagleboard.org/discuss
> >>>>>> To unsubscribe from this group, send email to:
> >>>>>> beagleboard+unsubscribe@googlegroups.com
> >>>>>> Frequently asked questions:http://beagleboard.org/faq
>
> >>>> --
> >>>> To join:http://beagleboard.org/discuss
> >>>> To unsubscribe from this group, send email to:
> >>>> beagleboard+unsubscribe@googlegroups.com
> >>>> Frequently asked questions:http://beagleboard.org/faq
>
> >>>> --
> >>>> To join:http://beagleboard.org/discuss
> >>>> To unsubscribe from this group, send email to:
> >>>> beagleboard+unsubscribe@googlegroups.com
> >>>> Frequently asked questions:http://beagleboard.org/faq
>
> > --
> > To join:http://beagleboard.org/discuss
> > To unsubscribe from this group, send email to:
> > beagleboard+unsubscribe@googlegroups.com

Steve Galle

unread,
Feb 25, 2012, 8:39:58 PM2/25/12
to beagl...@googlegroups.com
Dustin, I suspected this was what was going on, but am still traveling and haven't been able to confirm. Thanks for the post.

Steve

Dan

unread,
Feb 25, 2012, 11:13:32 PM2/25/12
to Beagle Board
Dustin,

Congrats on figuring this out, and thanks for sharing. I wasn't able
to figure out the mmap thing, so I look forward to seeing your
instructions on that.

I guess enabling the PWM timer will also enable the eCAP PWM? Based
on the SRM, I think ecap.0 is Port 9 Pin 42, Mode 0. No idea where
ecap.1 is, though.

For those looking for details on how to access the PWM settings
through the file system, I believe that the instructions on this page
are correct for the BeagleBone: http://processors.wiki.ti.com/index.php/AM335x_PWM_Driver's_Guide

For those looking to enable the 3.2 kernel, if you have a uImage-3.2.x
file in your /boot folder (updated via opkg, current latest version is
uImage-3.2.6+), then I believe Frank Meyer's instructions in this post
are correct
http://groups.google.com/group/beagleboard/browse_thread/thread/29006f9619c2cd79/9340f75616100f25?lnk=gst&q=uimage+beaglebone#9340f75616100f25

Dan.
> ...
>
> read more »

Steve Galle

unread,
Feb 25, 2012, 11:48:48 PM2/25/12
to beagl...@googlegroups.com
Dan, here's one way to set do the mmap bit in python (you only need the bold bits, but
leaving the rest there in case it's useful reference): 

from mmap import mmap
import struct

MMAP_OFFSET = 0x44c00000                # base address of registers
MMAP_SIZE   = 0x48ffffff-MMAP_OFFSET    # size of the register memory space

CM_PER_BASE = 0x44e00000 - MMAP_OFFSET
CM_PER_EPWMSS1_CLKCTRL = CM_PER_BASE + 0xcc
CM_PER_EPWMSS0_CLKCTRL = CM_PER_BASE + 0xd4
CM_PER_EPWMSS2_CLKCTRL = CM_PER_BASE + 0xd8

with open("/dev/mem", "r+b") as f:
    mem = mmap(f.fileno(), MMAP_SIZE, offset=MMAP_OFFSET)

def _andReg(address, mask):
    """ Sets 32-bit Register at address to its current value AND mask. """
    _setReg(address, _getReg(address)&mask)

def _orReg(address, mask):
    """ Sets 32-bit Register at address to its current value OR mask. """
    _setReg(address, _getReg(address)|mask)

def _xorReg(address, mask):
    """ Sets 32-bit Register at address to its current value XOR mask. """
    _setReg(address, _getReg(address)^mask)

def _getReg(address):
    """ Returns unpacked 32 bit register value starting from address. """
    return struct.unpack("<L", mem[address:address+4])[0]

def _setReg(address, new_value):
    """ Sets 32 bits at given address to given value. """
    mem[address:address+4] = struct.pack("<L", new_value)


_setReg(CM_PER_EPWMSS1_CLKCTRL, 0x2)


Steve
--
To join: http://beagleboard.org/discuss
To unsubscribe from this group, send email to:

dmmi...@gmail.com

unread,
Feb 26, 2012, 1:14:56 PM2/26/12
to beagl...@googlegroups.com
For those interested in a C solution for the mmap trick here is a program I wrote to enable/disable the PWM module clocks.  This mmap method that both Steve and I have demonstrated can be used to directly access any register on the processor.  Also, if anyone is wondering where Steve and I have gotten these magic offset values see the AM335x ARM Coretex-A8 Technical Reference Manual, page 207, which lists the memory map for all registers in the processor.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include <sys/mman.h>
#include <unistd.h>

#define CM_PER_REG_START 0x44e00000
#define CM_PER_REG_LENGTH 1024
#define CM_PER_EPWMSS0_CLKCTRL_OFFSET 0xd4
#define CM_PER_EPWMSS1_CLKCTRL_OFFSET 0xcc
#define CM_PER_EPWMSS2_CLKCTRL_OFFSET 0xd8

#define PWM_CLOCK_ENABLE 0x2
#define PWM_CLOCK_DISABLE 0x0

#define PWM_LIST_MAX 3

int PWM_OFFSETS[PWM_LIST_MAX] = {
  CM_PER_EPWMSS0_CLKCTRL_OFFSET / sizeof (uint32_t),
  CM_PER_EPWMSS1_CLKCTRL_OFFSET / sizeof (uint32_t),
  CM_PER_EPWMSS2_CLKCTRL_OFFSET / sizeof (uint32_t)
};

void print_usage (const char *message)
{
  if (message)
    printf ("%s\n", message);

  printf ("pwm_clock <-e | -d> <PWM [PWM]>\n\n");
}

int main (int argc, char **argv)
{
  int i;
  int *cur_list = NULL;
  int *cur_list_index = NULL;
  int enable_list[PWM_LIST_MAX];
  int enable_list_index = 0;
  int disable_list[PWM_LIST_MAX];
  int disable_list_index = 0;
  int dev_mem_fd;
  volatile uint32_t *cm_per_regs;

  for (i = 0; i < PWM_LIST_MAX; ++i) {
    enable_list[i] = -1;
    disable_list[i] = -1;
  }

  for (i = 1; i < argc; ++i) {
    if (strncmp (argv[i], "-e", 2) == 0) {
      cur_list = enable_list;
      cur_list_index = &enable_list_index;
    }
    else if (strncmp (argv[i], "-d", 2) == 0) {
      cur_list = disable_list;
      cur_list_index = &disable_list_index;
    }
    else {
      if (!cur_list) {
        print_usage (0);
        return 1;
      }

      if (*cur_list_index >= PWM_LIST_MAX) {
        print_usage ("Too many PWM's specified for an option");
        return 1;
      }

      cur_list[*cur_list_index] = atoi (argv[i]);
      ++*cur_list_index;
    }
  }

  dev_mem_fd = open ("/dev/mem", O_RDWR);
  if (dev_mem_fd == -1) {
    perror ("open failed");
    return 1;
  }

  cm_per_regs = (volatile uint32_t *)mmap (NULL, CM_PER_REG_LENGTH,
    PROT_READ | PROT_WRITE, MAP_SHARED, dev_mem_fd, CM_PER_REG_START);
        if (cm_per_regs == (volatile uint32_t *)MAP_FAILED) {
    perror ("mmap failed");
    close (dev_mem_fd);
    return 1;
  }

  for (i = 0; i < PWM_LIST_MAX && enable_list[i] != -1; ++i) {
    if (enable_list[i] < 0 || enable_list[i] >= PWM_LIST_MAX) {
      printf ("Invalid PWM specified, %d\n", enable_list[i]);
      goto out;
    }

    printf ("Enabling PWM %d\n", enable_list[i]);
    cm_per_regs[PWM_OFFSETS[enable_list[i]]] = PWM_CLOCK_ENABLE;
  }

  for (i = 0; i < PWM_LIST_MAX && disable_list[i] != -1; ++i) {
    if (disable_list[i] < 0 || disable_list[i] >= PWM_LIST_MAX) {
      printf ("Invalid PWM specified, %d\n", disable_list[i]);
      goto out;
    }

    printf ("Disabling PWM %d\n", disable_list[i]);
    cm_per_regs[PWM_OFFSETS[disable_list[i]]] = PWM_CLOCK_DISABLE;
  }

out:
  munmap ((void *)cm_per_regs, CM_PER_REG_LENGTH);
  close (dev_mem_fd);

  return 0;
}

Dustin

Crunchy

unread,
Feb 26, 2012, 5:16:40 PM2/26/12
to beagl...@googlegroups.com
Thanks so much you guys for all the work you've done. It would have taken me ages to figure this all out.

Steve, Python is complaining about there being no module named mmap. Did you use this with Python 2.7.2 on the BeagleBone?

- Mike

Steve Galle

unread,
Feb 26, 2012, 5:21:44 PM2/26/12
to beagl...@googlegroups.com
Not at the bone right now, but I think I did an opkg install python-mmap (or something quite similar)

Steve

Dan

unread,
Feb 26, 2012, 6:06:34 PM2/26/12
to Beagle Board
Dustin and Steve,

Thanks, guys!

For anyone who's having problems identifying the pins (hopefully I'm
not the only one), Port 9 Pin 14 is ehrpwm1:0 and Port 9 Pin 16 is
ehrpwm1:1. Both require mux setting to mode 6. Both output 3.3V, so
they work well with most LEDs too.

It looks like you can safely adjust the duty cycle on the fly by just
writing a new value to duty_percent. The value written to period_freq
is Hz.

Dan.

On Feb 26, 5:21 pm, Steve Galle <stevega...@gmail.com> wrote:
> Not at the bone right now, but I think I did an opkg install python-mmap (or something quite similar)
>
> Steve
>
> On Feb 26, 2012, at 5:16 PM, Crunchy wrote:
>
>
>
>
>
>
>
> > Thanks so much you guys for all the work you've done. It would have taken me ages to figure this all out.
>
> > Steve, Python is complaining about there being no module named mmap. Did you use this with Python 2.7.2 on the BeagleBone?
>
> > - Mike
>
> >>http://groups.google.com/group/beagleboard/browse_thread/thread/29006...
> ...
>
> read more »

Crunchy

unread,
Feb 26, 2012, 7:08:40 PM2/26/12
to beagl...@googlegroups.com
Thanks Steve, the python-mmap package worked for me.

I got a servo working! It's nano-sized, so it worked just fine off the 3.3V output (although my multimeter measured 3.8V).

# These settings were easier since the servo reference I was using described the pulse width control in terms of milliseconds
# This one in particular needed a period of 20ms and a pulse width of 1.5ms to achieve the center position.
# echo 2000000 > period_ns
# echo 1500000 > duty_ns
# echo 1 > run

- Mike

> ...
>
> read more »

Steve Galle

unread,
Feb 26, 2012, 7:19:27 PM2/26/12
to beagl...@googlegroups.com
Sweet, glad it's working! Can't wait to get home from this trip; I might have to take a quick break from my 'real' project for some r/c car shenanigans....

Steve

Arthur Neves

unread,
Feb 26, 2012, 11:02:16 PM2/26/12
to Beagle Board
hey guys,

i just got this Rover 5: http://www.sparkfun.com/datasheets/Robotics/Rover%205%20Introduction.pdf

and I am wondering what is the frequency that i have to use in PWM
output?

thanks!

On Feb 25, 11:13 pm, Dan <gigamegawa...@gmail.com> wrote:
> Dustin,
>
> Congrats on figuring this out, and thanks for sharing.  I wasn't able
> to figure out the mmap thing, so I look forward to seeing your
> instructions on that.
>
> I guess enabling the PWM timer will also enable the eCAP PWM?  Based
> on the SRM, I think ecap.0 is Port 9 Pin 42, Mode 0.  No idea where
> ecap.1 is, though.
>
> For those looking for details on how to access the PWM settings
> through the file system, I believe that the instructions on this page
> are correct for the BeagleBone:http://processors.wiki.ti.com/index.php/AM335x_PWM_Driver's_Guide
>
> For those looking to enable the 3.2 kernel, if you have a uImage-3.2.x
> file in your /boot folder (updated via opkg, current latest version is
> uImage-3.2.6+), then I believe Frank Meyer's instructions in this post
> are correcthttp://groups.google.com/group/beagleboard/browse_thread/thread/29006...
> > > > >>>>>> On Sun, Feb 5, 2012 at 2:35 AM, Koen Kooi <k...@beagleboard.org>...
>
> read more »

Eric Gero

unread,
Feb 29, 2012, 11:08:31 PM2/29/12
to beagl...@googlegroups.com
This doesn't compare to the awesome work Steve and Dustin posted, but it does make use of it.  It is a working example of controlling a servoe through PWM.  Perhaps some of the other rookies can make use of it and some of the more seasoned developers can help improve it.  To use it, run the Python code that was posted to perform the mapping.  Then run this.
 
import os
import time
# Enable clock for PWM module
# MMAP code borrowed from https://groups.google.com/forum/?fromgroups#!topic/beagleboard/alKf67dwMHI
# run the python version of mmap to enable the clock before running this
# Put Port 9 Pin 14 into mode 6
omap_mux = 'echo 6 > /sys/kernel/debug/omap_mux/gpmc_a2'
echo = 'echo '
path = ' > /sys/class/pwm/ehrpwm.1\:0/'
run = 'run'
period_freq = 'period_freq'
duty_percent = 'duty_percent'
# run = 'echo 1 > /sys/class/pwm/ehrpwm.1\:0/run'
# set_period_freq = 'echo 100 > /sys/class/pwm/ehrpwm.1\:0/period_freq'
# set_duty_percent = 'echo 10 > /sys/class/pwm/ehrpwm.1\:0/duty_percent'

count = 0;
os.system("%s%s%s%s" % (echo, str(1), path, run))
os.system("%s%s%s%s" % (echo, str(100), path, period_freq))
while (count < 50):
 os.system("%s%s%s%s" % (echo, str(6), path, duty_percent))
 time.sleep(2);
 os.system("%s%s%s%s" % (echo, str(22), path, duty_percent))
 time.sleep(2);
 os.system("%s%s%s%s" % (echo, str(15), path, duty_percent))
 time.sleep(2)
 count = count + 1
 
#servo (s3004) - echo 100 > period_freq
#echo 6 > duty_percent 0 degrees
#echo 15 > duty_percent center
#echo 22 > duty_percent 180 degrees
Reply all
Reply to author
Forward
0 new messages