[SOLVED] Zero 3E PWM GPIO under Kernel 6.1 Ubuntu

My Host

OS: Armbian (24.8.4) aarch64 
Host: Radxa ZERO 3 
Kernel: 6.1.75-vendor-rk35xx 
Uptime: 1 hour, 27 mins 
Packages: 1011 (dpkg) 
Shell: bash 5.2.21 
Terminal: /dev/pts/1 
CPU: (4) @ 2.000GHz 
Memory: 1313MiB / 3732MiB

Overlays I have activated (as per github & .dts contents these are for Zero 3)

overlays=npu-enable pwm12-m1 pwm13-m1 pwm14-m0 pwm14-m1 pwm15-m1 pwm8-m0 pwm9-m0

After this I can find

ls /sys/class/pwm/
pwmchip0  pwmchip1  pwmchip2  pwmchip3  pwmchip4  pwmchip5
cat /sys/class/pwm/pwmchip{0,1,2,3,4,5}/device/modalias 
of:NpwmT(null)Crockchip,rk3568-pwmCrockchip,rk3328-pwm
of:NpwmT(null)Crockchip,rk3568-pwmCrockchip,rk3328-pwm
of:NpwmT(null)Crockchip,rk3568-pwmCrockchip,rk3328-pwm
of:NpwmT(null)Crockchip,rk3568-pwmCrockchip,rk3328-pwm
of:NpwmT(null)Crockchip,rk3568-pwmCrockchip,rk3328-pwm
of:NpwmT(null)Crockchip,rk3568-pwmCrockchip,rk3328-pwm

However, there is something wrong

cat /sys/kernel/debug/pwm
platform/fe700030.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/fe700020.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/fe700010.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/fe700000.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/fe6f0010.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/fe6f0000.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

The output should be something like How to use any PWM on Radxa Zero (sysfs)

I have also compiled mraa However per official documentation it will not work under kernel 6.1 https://docs.radxa.com/en/zero/zero3/app-development/mraa#pwm

I can run CLI commands properly though

mraa-gpio list
01         3V3: 
02          5V: 
03    GPIO0_D1: I2C  UART 
04          5V: 
05    GPIO0_D0: I2C  UART 
06         GND: 
07    GPIO3_C4: GPIO PWM  
08    GPIO0_D1: UART 
09         GND: 
10    GPIO0_D0: UART 
11    GPIO3_A1: GPIO 
12    GPIO3_A3: GPIO 
13    GPIO3_A2: GPIO 
14         GND: 
15   GPIO03_B0: GPIO 
16   GPIO03_B1: GPIO PWM  UART 
17         3V3: 
18    GPIO3_B2: GPIO PWM  UART 
19    GPIO4_C3: GPIO SPI  
20         GND: 
21    GPIO4_C5: GPIO SPI  PWM  UART 
22    GPIO3_C1: GPIO 
23    GPIO4_C2: GPIO SPI  PWM  
24    GPIO4_C6: GPIO SPI  PWM  UART 
25         GND: 
26    GPIO4_D1: GPIO 
27    GPIO4_B2: GPIO I2C  
28    GPIO4_B3: GPIO I2C  
29    GPIO3_B3: GPIO 
30         GND: 
31    GPIO3_B4: GPIO 
32    GPIO3_C2: GPIO UART 
33    GPIO3_C3: GPIO UART 
34         GND: 
35    GPIO3_A4: GPIO 
36    GPIO3_A7: GPIO 
37    GPIO1_A4: 
38    GPIO3_A6: GPIO 
39         GND: 
40    GPIO3_A5: GPIO 

mraa-gpio version
Version v2.2.0 on Radxa ZERO 3

Any help will be highly welcomed

In examples folder of mraa I tried both pwm.c & pwm.py both gave this error

Error initialising PWM on pin

I did change PIN# for instance in python code

import mraa
import time

# initialise PWM
x = mraa.Pwm(23) #in my case it will be 7,23,24...

# set PWM period
x.period_us(700)

# enable PWM
x.enable(True)

value= 0.0

while True:
    # write PWM value
    x.write(value)

    time.sleep(0.05)

    value = value + 0.01
    if value >= 1:
        value = 0.0

Nothing wrong with your output, you need to export it and set the values.
I’m not running kernel 6.1.x on my 3W, but I’m running 6.1.x in Rock5-lite, where you can use the PWM pins the same way. Take this as an example:

root@rock5c-lite:/home/rock# cat /sys/class/pwm/pwmchip{0,1,2,3,4}/device/modalias
of:NpwmT(null)Crockchip,rk3588-pwmCrockchip,rk3328-pwm
of:NpwmT(null)Crockchip,rk3588-pwmCrockchip,rk3328-pwm
of:NpwmT(null)Crockchip,rk3588-pwmCrockchip,rk3328-pwm
of:NpwmT(null)Crockchip,rk3588-pwmCrockchip,rk3328-pwm
of:NpwmT(null)Crockchip,rk3588-pwmCrockchip,rk3328-pwm
root@rock5c-lite:/home/rock# cat /sys/kernel/debug/pwm
platform/febd0030.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/febd0020.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/fd8b0030.pwm, 1 PWM device
 pwm-0   (pwm-fan             ): requested enabled period: 60000 ns duty: 59999 ns polarity: normal

platform/fd8b0010.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/fd8b0000.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
root@rock5c-lite:/home/rock# echo 0 > /sys/class/pwm/pwmchip1/export
root@rock5c-lite:/home/rock# cat /sys/kernel/debug/pwm
platform/febd0030.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/febd0020.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal

platform/fd8b0030.pwm, 1 PWM device
 pwm-0   (pwm-fan             ): requested enabled period: 60000 ns duty: 59999 ns polarity: normal

platform/fd8b0010.pwm, 1 PWM device
 pwm-0   (sysfs               ): requested period: 0 ns duty: 0 ns polarity: inverse

platform/fd8b0000.pwm, 1 PWM device
 pwm-0   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
root@rock5c-lite:/home/rock# 

T

Due to changes in the pwmchip driver, the PWM function of the MRAA does not work properly on the 6.1 kernel.

The current pwm driver assigns the pwm chip id dynamically, rather than statically as in the past.

Hey @ioncube I know it’s not related to your question, but how are you running your board at 2.0Ghz under Armbian?

@avaf @Nasca

python-periphery works instead of mraa

Thanks for your input. I have been successful in running PWM under Kernel 6.1
Instructions are here:

https://www.reddit.com/r/OrangePI/comments/1jl963x/success_activating_using_pwm_on_opi_3b_radxa_3e/

My github account which had a wealth of knowledge is being suspended temporarily. I am resolving it at the moment. You can overclock both CPU & GPU

I am attaching overclock .dtb & .dts In my configuration only CPU is overclocked

rk3566-radxa-zero3.zip (62.4 KB)

Thank you for sharing.