PWM not working

Which Khadas SBC do you use?

VIM3L

Which system do you use? Android, Ubuntu, OOWOW or others?

Ubuntu

Which version of system do you use? Khadas official images, self built images, or others?

Khadas Ubuntu Server 20.04
Linux Khadas 4.9.241

Please describe your issue below:

Hi,

I can’t get pwm to work. I have followed the instructions from the docs here VIM3/3L PWM [Khadas Docs].
When I try the command echo 1 | sudo tee /sys/class/pwm/pwmchip4/export I get tee: /sys/class/pwm/pwmchip4/export: Device or resource busy and when I try enable I get tee: /sys/class/pwm/pwmchip4/enable: Permission denied.
How can I fix this and get PWM to work?

@CaptainWhale

Good day!

Does it not work without reinstalling the complete OS? I have a lot of stuff on my current OS installation and reinstalling it would be really annoying. Why do I have to use another os just to use pwm?

@CaptainWhale

  • Everything is fine on my end.
khadas@Khadas:/$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/export
1
khadas@Khadas:/$ echo 1000000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/period
1000000
khadas@Khadas:/$ echo 500000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/duty_cycle
500000
khadas@Khadas:/$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
1
  • Here’s what happened on my end
overlays=uart3 pwm_f i2c3 i2s os08a10 watchdog
khadas@Khadas:/$ ls /sys/class/pwm/pwmchip4/
device  export  npwm  power  subsystem  uevent  unexport

And I get:

khadas@Khadas:~$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/export
1
tee: /sys/class/pwm/pwmchip4/export: Device or resource busy
khadas@Khadas:~$ echo 1000000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/period
tee: /sys/class/pwm/pwmchip4/pwm1/period: No such file or directory
1000000
khadas@Khadas:~$ echo 500000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/duty_cycle
tee: /sys/class/pwm/pwmchip4/pwm1/duty_cycle: No such file or directory
500000
khadas@Khadas:~$ echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable
tee: /sys/class/pwm/pwmchip4/pwm1/enable: No such file or directory
1

Overlays:

overlays=uart3 pwm_f i2c3 watchdog
khadas@Khadas:~$ ls /sys/class/pwm/pwmchip4/
device  export  npwm  power  subsystem  uevent  unexport

Why is it not working for me?

@CaptainWhale
It looks like the GPIO is occupied. Have you made any changes about the GPIO?

Hi, I am having the exact same issue on a VIM3 Pro. I have also enabled UART for Pins 15 and 16, and I have the proper overlays for enabling PWM_F, what else should I try? I am trying to drive a servo motor. @ivan.li

@cscrosati98 @CaptainWhale
It exists, and I plan to talk about it next week.

Okay, so in the mean time software pwm is the only option? My team and I are working on a project and need a pwm pin of any sort as soon as possible. I’ve tried using the wiringPi distro with python and I am having issues with exporting pins/configuring for soft pwm.

Which image you used? If you used the latest 4.9 kernel image, the PWM should work.

1 Like

My kernel is listed as
4.9.241
@numbqq

Hello @cscrosati98

Please provide the clear image you used. The images below which one you used?

https://dl.khadas.com/products/vim3/firmware/ubuntu/emmc/vim3-ubuntu-20.04-gnome-linux-4.9-fenix-1.4-221229-emmc.img.xz
https://dl.khadas.com/products/vim3/firmware/ubuntu/emmc/vim3-ubuntu-20.04-server-linux-4.9-fenix-1.4-221229-emmc.img.xz

Gnome linux, but I believe the original flash is from the 1.3 image. @numbqq

Have you upgrade the system to latest version?

Could you provide the information to us?

cat /etc/fenix-release

@numbqq

Hello @cscrosati98

@ivan.li will check and update here.

@cscrosati98
For VIM3pro, PWM works properly. What are the differences between us?

# Device Tree Overlays
#   uart3           -- Enable UART3 (uart_C, GPIO Header PIN15 & PIN16)
#   pwm_f           -- Enable PWM_F (GPIO Header PIN35)
#   i2c3            -- Enable i2c3 (GPIO Header PIN22 & PIN23)
#   spi1            -- Enable SPI1 (GPIO Header PIN15 & PIN16 & PIN35 & PIN37),  
pwm_f need to be removed
#   i2s             -- Enable I2S (GPIO Header PIN29 & PIN30 & PIN31 & PIN32 & PP
IN33)
#   os08a10         -- Enable OS08A10 Camera
#   onewire         -- Enable onewire bus (GPIO Header PIN15)
#   disable-ts050   -- Disable TS050 LCD
#   m2x-eth         -- Enable M2X 100M ethernet. Note: 1G ethernet will be disabb
led.
#   otg-device      -- Enable USB OTG Device
#   watchdog        -- Enable watchdog
#   can             -- Enable mcp2515 (GPIO Header PIN15 && PIN16 && PIN22 && PII
N35 && PIN37), pwm_f/i2c3/uart3 need to be removed
#   mpu6050-i2c     -- Enable mpu6050 (GPIO Header PIN22 & PIN23 & PIN37), pwm_ff
 need to be removed
#   ext_board       -- Enable for Khadas EXT Board
#   spdifin         -- Enable SPDIFIN (GPIO Header PIN35), pwm_f need to be remoo
ved
overlays=uart3 pwm_f i2c3 i2s os08a10 watchdog
khadas@Khadas:~$ cat /etc/fenix-release 
# PLEASE DO NOT EDIT THIS FILE
BOARD=VIM3
VENDOR=Amlogic
VERSION=1.4
ARCH=arm64
INITRD_ARCH=arm64
INSTALL_TYPE=EMMC
IMAGE_VERSION=1.4-221229
################ GIT VERSION ################
UBOOT_GIT_VERSION=khadas-vims-u-boot-v2015.01-v1.4-release
LINUX_GIT_VERSION=khadas-vims-linux-4.9-v1.4-release
FENIX_GIT_VERSION=v1.4
#############################################
khadas@Khadas:~$ 

Can you provide me with the result of executing the following command?

echo 1 | sudo tee /sys/class/pwm/pwmchip4/export
echo 1000000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/period
echo 500000 | sudo tee /sys/class/pwm/pwmchip4/pwm1/duty_cycle
echo 1 | sudo tee /sys/class/pwm/pwmchip4/pwm1/enable

Hi~ @cscrosati98
Execute the following command and paste the resulting dts file here .(I want to see if there are any differences)

khadas@Khadas:~$ sudo dtc -I dtb /sys/firmware/fdt -O dts -o kvim3.dts
khadas@Khadas:~$ ls
kvim3.dts

Hi~ @CaptainWhale
Thank you for your feedback. To use PWM on VIM3L, please execute the following command.

$ echo 1 | sudo tee /sys/class/pwm/pwmchip0/export
$ echo 1000000 | sudo tee /sys/class/pwm/pwmchip0/pwm1/period
$ echo 500000 | sudo tee /sys/class/pwm/pwmchip0/pwm1/duty_cycle
$ echo 1 | sudo tee /sys/class/pwm/pwmchip0/pwm1/enable
1 Like