Jump to content

Recommended Posts

Posted (edited)
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
Posted (edited)

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
Posted

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

Posted
11 hours ago, Piscenois said:

Thank you PetrozPL !

I tried pwm, pwm0, pwm1 but no pwm-gpio...

 

Regards.

Yhea, that makes two of us :D It took me some time and digging before I figured out the correct naming convention :D

Posted

Your post is the only one accross the Internet to explain how to activate PWM with RockPi4 and it works ! It deserves to be pinned, tagged. Subliminal message for moderators :ph34r:

Posted

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.

Posted
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 

 

Posted

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.

 

Posted
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.

Posted
Am 6.5.2021 um 20:20 schrieb PetrozPL:

Did you tried to call

 



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

 

Thank you - that finally did the trick!

Posted (edited)

Please, post pictures with your FAN connection to the board.

 

EDIT : I've just checked and FAN in okdo is only 2-wire:

image.thumb.png.bc8c6390d4885b7ba37d6c9f48e06023.png

 

so to control it's speed via PWM you have to add additional circuit like on this page : 

 

https://forums.raspberrypi.com/viewtopic.php?t=194621&start=50

 

You need to connect GPIO wire to either PWM0 or PWM1 (one you would like to use to control FAN speed). Without this additional circuit you can't change the speed of 2-pin FAN. The other option is to buy the 3-pin FAN for 5V with additional speed control wire. 

Edited by PetrozPL
Posted
On 9/27/2020 at 6:01 AM, PetrozPL said:

I've decompiled the rockchip-rockpi4.dtb and find out that pwm is disabled by default.

I see the same issue with Orange Pi 5 - rk3588. How did you manage to decompile the dtb?

Posted (edited)

just use the dtc tool. Compiled devicetree has .dtb extension. To decompile it to .dts just call

 

dtc -I dtb -O dts <COMPILED_DTC>.dtb -o <OUTPUT_DTC>.dts

 

Edited by Petroz
Posted
Just now, Petroz said:

just use the dtc tool.

I missed this in this thread as well, I forgot to do the echo to export. The opi5 overlays work perfectly otherwise. But thanks for the reference - haven't found a lot of details on overlays

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...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines