How to Enable and Control PWM on AML-S905X-CC

Chip is pwmchip0 and channel is pwm0 so 0,0.

Either I am dumb or something is wrong. Here is code that I used and nothing happens… Code runes no errors but nothing mover or motor even detects PWM signal. Checked with Arduino, and all works with first try. I also tried running default code for periphery and did not work too. I enabled pwm on pin 32 and tried other pins. I also checked if pwmchip is mapping and it is. And I do not have an oscilloscope to check if anything comes out. I did not move jumper, do I need to? What am I doing wrong?

from periphery import PWM
import time

# Open PWM chip 0, channel 0
pwm = PWM(0, 0)

# Set frequency to 15 kHz
pwm.frequency = 15e3

# Enable PWM output
pwm.enable()

# Set duty cycle to 20%
pwm.duty_cycle = 0.20

# Wait for 10 seconds
time.sleep(10)

# Disable PWM output
pwm.disable()

# Close PWM
pwm.close()

I even tried rung by command line and here is what I got:

yasushiko@raspberrypi:~ $ sudo ldto enable pwm-e
ls -al /sys/class/pwm
echo 0 | sudo tee /sys/class/pwm/pwmchip0/export
echo 15000000 | sudo tee /sys/class/pwm/pwmchip0/pwm0/period
echo 7500000 | sudo tee /sys/class/pwm/pwmchip0/pwm0/duty_cycle
echo 1 | sudo tee /sys/class/pwm/pwmchip0/pwm0/enable
Overlay pwm-e: applied
total 0
drwxr-xr-x  2 root root 0 Dec 31  1969 .
drwxr-xr-x 87 root root 0 Dec 31  1969 ..
lrwxrwxrwx  1 root root 0 Apr 12 21:22 pwmchip0 -> ../../devices/platform/soc/c1100000.bus/c11086c0.pwm/pwm/pwmchip0
0
15000000
7500000
1

But nothing happened. Controller continued blinking like I didn’t receive anything.

I’m seeing the same behavior on my Le Potato - did something change recently?

I’m running this system image: 2022-09-22-raspbian-bullseye-arm64-lite+aml-s905x-cc.img

…and this kernel: Linux potato 6.1.22-04692-gac1e6970fbc0 #1 SMP PREEMPT_DYNAMIC Mon Apr 3 22:49:07 UTC 2023 aarch64 GNU/Linux

For this initial test, what I want to do is get a 1KHz signal at 50% duty cycle on pin 11. This is how I am enabling it.

john@potato:~ $ sudo ldto enable pwm-ao-a
Overlay pwm-ao-a: applied

john@potato:~ $ echo 0 | sudo tee /sys/class/pwm/pwmchip0/export
0

john@potato:~ $ echo 1000000 | sudo tee /sys/class/pwm/pwmchip0/pwm0/period
1000000

john@potato:~ $ echo 500000 | sudo tee /sys/class/pwm/pwmchip0/pwm0/duty_cycle
500000

john@potato:~ $ echo 1 | sudo tee /sys/class/pwm/pwmchip0/pwm0/enable
1

I’m monitoring the pin with an oscilloscope and I’m not getting any output at all. I have tried a few different PWM pins and I’m getting the same experience across the board.

EDIT: I went through an tested every single pin and combination. pwm-a / pwm0 /pin33 seems to be working correctly. No others are.

1 Like

Did you reset the overlays, reboot, and then merge again?

1 Like

So I’m trying to control a pwm fan on CoreELEC for AML-S905X-CC. The Wiring Tool explicitly states it is not supported on CoreELEC. The usual commands for libgpiod do not seem to be available. Only c11086c0.pwm seems to be listed in sysfs. The npwm for this chip indicates there are 4 pwm’s available on this chip. When exporting, pwm0 and 2 are busy, but 1 and 3 are available to be exported.

If I understand correctly, pwm1 on this chip should correspond to pin 35. I’ve read that 25khz is appropriate, so I’ve set the period to 40000, the duty_cycle to 20000 and enable to 1. Nothing seems to change.

Could someone point me in the right direction?

You have to look at the code for CoreELEC. It’s based on the Amlogic kernel rather than upstream.

This is the upstream device tree: https://boot.libre.computer/ci/aml-s905x-cc.dts

pwm_ef = "/soc/bus@c1100000/pwm@86c0";

The header maps are here: GPIO Pin Header Maps and Wiring Tool for Libre Computer Boards

E and F are on pin 32 and 35 respectively.

Even after setting the PWM to the right frequency, you need to toggle the GPIO pinmux register to the PWM function from the GPIO function. Not sure how that is done in the Amlogic kernel. This should be setting 1 bit in memory based on the datasheet: https://dl.khadas.com/products/vim1/datasheet/s905x_datasheet_v0.3-20170314_public_version-wesion.pdf

For example exposing PWM_E on GPIOX_16 is controlled by REG5 (PERIPHS_PIN_MUX_5 0xc88344c4) bit 15.