Software pwm driver for am335x PRU
Shell C OpenEdge ABL
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
README add inversion, fix unload issue Apr 6, 2013



Code still in development, use at your own risk.

This repo contains BeagleBone Linux PWM driver for servo control source code. It is capable of controlling up to 32(and probably even 64 or more after minor code changes - however, there are not enough pins and imagine how much current would it require) servo motors. It generates 20ms long wave with 0.5 to 2.5ms(200 steps, 10us per step) active time.
The driver works on two cores:
- ARM - controls enable and disable pins, manages devices in /dev and processes data from the user, initializes pinmuxes etc.
- PRU 0 - responsible for pwm generation - runs in an infinite loop switching pin state. Uses ecap 0 for time base generation.

SoC subsystems required:
- ARM(running linux) - shared
- PRU 0 - exclusive
- ECAP 0 - exclusive
- GPIO banks 0-3 - banks shared, pins used for pwm exclusive

Work done:
- PRU software(complete): ecap config, interrupt config, pwm generation
- /dev pwm devices creation, read/write operation handling
- pinmux, gpio dir configuration (not tested, until I get my hands on a logic analizer:) )
- PRU initialization, software download
- arm->pru communication
- enable/disable /dev device

Work to do:
- GPIO Subsystem power and clock management (currently driver assumes that all gpios used are powered and clocked correctly)
- move BeagleBone's IP address and destination dir from Makefile to
- code cleanup:)
- code comments:)

- dynamic module reconfiguration (gpio switching, adding/removing pwm device without code recompilation)

1. After downloading the source copy or move the to the directory above the source code(ie. "cp ../").
2. Edit so that MY_COMPILER points to your ARM compiler(the same that was used to compile the kernel) and MY_SOURCE points to your kernel source.
3. Make sure that you have the pasm compiler directory in your PATH. (pasm can be downloaded from
4. Add or remove #define INVERTED_LOGIC in pru_pwm_sw.p if you are using inverted/normal logic for the gpio pins.
5. Type "make build" in the module source directory".
6(OPTIONAL). You can update Makefile with your bone IP address and destination dir, put ssh keys on the bone and type "make". The module will be compiled, uploaded to the bone and installed automatically.

1. If the optional step for the compilation was not performed, copy pwmd.ko to your BeagleBone memory card and type in the BeagleBone console "insmod path_to_module/pwmd.ko".
2. /dev/pwm_drv contains all the pwm devices.
3. Writing the value 50 - 250 to /dev/pwm_drv/pwmXXdev sets the PWM active time to 0.5ms - 2.5ms for servo XX.
4. Reading from /dev/pwm_drv/pwmXXdev returns the current active time for servo XX.
5. Enable/Disable - TODO