Rock Pi4 pwm control - no overlay?


PetrozPL
 Share

3 3

Recommended Posts

Armbianmonitor:

Hi, 

 

I'm new to armbian and I've started with RockPi4b board. I would like to add fan control with PWM, but adding pwm (or pwm0) overlay doesn't work. I can't also find the overlay for it at /boot/dtb-5.8.6-rockchip64/rockchip/overlay/. Is it supported? I've checked and the /sys/class/pwm/pwmchip0 is present, but accessing export, as described here : 

 

 

doesn't work and /sys/class/pwm/pwmchip0/pwm0 is not present.

 

I've tried to find pwm access examples for this board, but none of it works on armbian (all are vendor builds specific). Can anybody point me in the right direction or give any hint how to enable pwm?

 


EDIT I've managed to enable/dosable PWM pin with 

 

sudo mraa-gpio set 11 1

 

Although, its GPIO, rather PWM access so I can't control the FAN speed and only power on/off the fan. 

Edited by PetrozPL
update regarding power on/off fan
Link to post
Share on other sites

Armbian is a community driven open source project. Do you like to contribute your code?

ok, I've managed to sort this out on my own. I've decompiled the rockchip-rockpi4.dtb and find out that pwm is disabled by default. So I've wrote new overlay for pwm, just to enable it

 

/dts-v1/;

/ {
        compatible = "rockchip,rk3399";
		
        fragment@0 {
                target-path = "/aliases";
                __overlay__ {
                        pwm0 = "/pwm@ff420000";
                        pwm1 = "/pwm@ff420010";
                };
        };

        fragment@1 {
                target-path = "/pwm@ff420000";
                __overlay__ {
                        status = "okay";
                };
        };

        fragment@2 {
                target-path = "/pwm@ff420010";
                __overlay__ {
                        status = "okay";
                };
        };
		
};

next, compiled it with dtc

dtc -O dtb -o rockchip-pwm-gpio.dtbo -b 0 -@ rockchip-pwm-gpio.dts

and moved dtbo to /boot/dtc/rockchip/overlays, and activated it in overlays in /boot/armbianEnv.txt.

 

Now PWM works like a charm. I'm just leaving this thread and my resolution as reference, for anyone with the same problem.

 

Edited by PetrozPL
typo fixed
Link to post
Share on other sites

Hi, no I haven't. The previous configuration is still working, so no need to update to new images. The overlay should be compiled via dtc to file rockchip-pwm-gpio.dtbo, and put in location : /boot/dtb/rockchip/overlay/

 

The activation in /boot/armbianEnv.txt should be via overlays variable : 

overlay_prefix=rockchip
overlays=pwm-gpio

Hope this helps. 

 

Best regards

Link to post
Share on other sites

Hi,

 

I know, this thread is pretty old. Hope its okay to post here anyway.

 

I have a rockpi 4A with penta-sata-hat, armbian-buster (21.02.3) desktop with current kernel and following the instructions from this thread turns the fan on.

Although I'm happy with the turning fan, its too loud and I'd like to be able to vary fanspeed.

 

Following advices from other threads like writing values to .../duty_cycle and .../period does not work. I don't have such files. Pwm related tree from sysfs looks like this:

 

find /sys/class/pwm/pwmchip0/
/sys/class/pwm/pwmchip0/
/sys/class/pwm/pwmchip0/uevent
/sys/class/pwm/pwmchip0/power
/sys/class/pwm/pwmchip0/power/runtime_active_time
/sys/class/pwm/pwmchip0/power/runtime_status
/sys/class/pwm/pwmchip0/power/autosuspend_delay_ms
/sys/class/pwm/pwmchip0/power/runtime_suspended_time
/sys/class/pwm/pwmchip0/power/control
/sys/class/pwm/pwmchip0/unexport
/sys/class/pwm/pwmchip0/device
/sys/class/pwm/pwmchip0/export
/sys/class/pwm/pwmchip0/subsystem
/sys/class/pwm/pwmchip0/npwm

 

Any hints on how I could modify fan speed (based on temperature values)?

 

I also tried the script from nanopi m4 thread - but that script simply turns the fan off. No matter what cpu temperature might be. I have to reboot to get the fan spinning again.

Link to post
Share on other sites

1 hour ago, tony013 said:

Hi,

 

I know, this thread is pretty old. Hope its okay to post here anyway.

 

I have a rockpi 4A with penta-sata-hat, armbian-buster (21.02.3) desktop with current kernel and following the instructions from this thread turns the fan on.

Although I'm happy with the turning fan, its too loud and I'd like to be able to vary fanspeed.

 

Following advices from other threads like writing values to .../duty_cycle and .../period does not work. I don't have such files. Pwm related tree from sysfs looks like this:

 


find /sys/class/pwm/pwmchip0/
/sys/class/pwm/pwmchip0/
/sys/class/pwm/pwmchip0/uevent
/sys/class/pwm/pwmchip0/power
/sys/class/pwm/pwmchip0/power/runtime_active_time
/sys/class/pwm/pwmchip0/power/runtime_status
/sys/class/pwm/pwmchip0/power/autosuspend_delay_ms
/sys/class/pwm/pwmchip0/power/runtime_suspended_time
/sys/class/pwm/pwmchip0/power/control
/sys/class/pwm/pwmchip0/unexport
/sys/class/pwm/pwmchip0/device
/sys/class/pwm/pwmchip0/export
/sys/class/pwm/pwmchip0/subsystem
/sys/class/pwm/pwmchip0/npwm

 

Any hints on how I could modify fan speed (based on temperature values)?

 

I also tried the script from nanopi m4 thread - but that script simply turns the fan off. No matter what cpu temperature might be. I have to reboot to get the fan spinning again.

 

I've created the repository on github with all required files, including 2 scripts I'm using to control and query PWM FAN speed.

 

https://github.com/PetrozPL/rockpi4_pwm_overlay

 

Hope You'll find it usefull.

 

EDIT : Also, to control fan speed based on HDD temperature you can use smartctl tool to read HDD temperature from SMART. Example output for my NVMe : 

sudo smartctl -a /dev/nvme0 | grep Temperature
Temperature:                        76 Celsius
Warning  Comp. Temperature Time:    0
Critical Comp. Temperature Time:    0
Temperature Sensor 2:               83 Celsius

 

If you would like to get system temperature instead hdd You can use another script to check thermal_zone0 temperature: 

#!/bin/bash

_temp=`cat /sys/class/thermal/thermal_zone0/temp`
_temp1=${_temp::-3}
_temp2=${_temp::(-3)}
echo ${_temp::-3}.${_temp:(-3)} C

 

Best regards,
PetrozPL 

 

Link to post
Share on other sites

Thank you @PetrozPL

 

... but your script does the same as other scripts: write values to duty_cycle and period.

As I already wrote, that does not work on my system.

Your script returns (as expected) -1

... and manually writing value to duty_cycle or period results in "no such file or directory".

 

So may be, its related to the different kernel version, other dtb, whatever.

I don't know, where to search for support/solution.

Could you please check your dts file, whether it contains "duty_cycle" and "period"?

If you post the surrounding paragraph, I could give it a try.

 

When I use raspian and install the original driver from radxa, fanspeed is related to cputemperature.

With armbian there's no way to change fanspeed.

Well - original driver from radxa uses pigpio and python. I tried to port pigpio to rockpi, but I wasn't successful.

 

I don't care about language - anything that works would be ok for me.

The point is, I don't know nothing about lowlevel programming of pi/rockpi, but if you gimme a hand, I'll try to solve it.

 

Link to post
Share on other sites

3 hours ago, tony013 said:

Thank you @PetrozPL

 

... but your script does the same as other scripts: write values to duty_cycle and period.

As I already wrote, that does not work on my system.

Your script returns (as expected) -1

... and manually writing value to duty_cycle or period results in "no such file or directory".

 

So may be, its related to the different kernel version, other dtb, whatever.

I don't know, where to search for support/solution.

Could you please check your dts file, whether it contains "duty_cycle" and "period"?

If you post the surrounding paragraph, I could give it a try.

 

When I use raspian and install the original driver from radxa, fanspeed is related to cputemperature.

With armbian there's no way to change fanspeed.

Well - original driver from radxa uses pigpio and python. I tried to port pigpio to rockpi, but I wasn't successful.

 

I don't care about language - anything that works would be ok for me.

The point is, I don't know nothing about lowlevel programming of pi/rockpi, but if you gimme a hand, I'll try to solve it.

 

Did you tried to call

 

sudo echo 0 > /sys/class/pwm/pwmchip1/export

 

Before calling pwmset / pwmsts?

 

EDIT : Ok, I've forgotten about permissions and initialization - on my system it's called once after power up, so there's no need for it on pwmset/pwmsts

 

I've added to repo new file : udev-pwm-permissions.sh. call it with root priviliges or add it to execution on startup.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

3 3