PWM With Rust

Using Bash and /sys

P8.13 -> /sys/class/pwm/pwmchip6/pwm1

How is this determined?

# Enable pwm driver
echo am33xx_pwm > /sys/devices/platform/bone_capemgr/slots
echo cape-universal > /sys/devices/platform/bone_capemgr/slots

# Export chip
echo 1 > /sys/class/pwm/pwmchip6/export

# Setup PWM
echo 20000 > /sys/class/pwm/pwmchip6/pwm1/period
echo 10000 > /sys/class/pwm/pwmchip6/pwm1/duty_cycle
echo 1 > /sys/class/pwm/pwmchip6/pwm1/enable

PWM With SysFS Library

Found a pwm library from posborne which works with sysfs:

Add the following to Cargo.toml

# or latest version
sysfs-pwm = "^0.1.0"

Package does not seem to be found since it is not in carg

sysfs-pwm = {git="", branch="master"}

The following script works using sysfs-pwm

extern crate sysfs_pwm;
use sysfs_pwm::{Pwm, Result};

// PIN: EHRPWM2B (P8_13)
const BB_PWM_CHIP: u32 = 6;
const BB_PWM_NUMBER: u32 = 1;

/// Make an LED "breathe" by increasing and
/// decreasing the brightness
fn main() {
    let pwm = Pwm::new(BB_PWM_CHIP, BB_PWM_NUMBER).unwrap(); // number depends on chip, etc.
    pwm.with_exported(|| {

Note I think using this requires the pwm to be enabled using the capemanager and the pinmux to be set ahead of time.