PetrozPL Posted September 26, 2020 Posted September 26, 2020 (edited) Armbianmonitor: http://ix.io/2yLI 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 September 26, 2020 by PetrozPL update regarding power on/off fan 0 Quote
Solution PetrozPL Posted September 27, 2020 Author Solution Posted September 27, 2020 (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 September 27, 2020 by PetrozPL typo fixed 2 Quote
Piscenois Posted February 7, 2021 Posted February 7, 2021 Hi @PetrozPL, I'm using Armbian buster 5.10.12 with RockPi 4C. I can't get your solution to work. Have you made any change since 2020 september ? Regards 0 Quote
PetrozPL Posted February 7, 2021 Author Posted February 7, 2021 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 0 Quote
Piscenois Posted February 7, 2021 Posted February 7, 2021 Thank you PetrozPL ! I tried pwm, pwm0, pwm1 but no pwm-gpio... Regards. 1 Quote
PetrozPL Posted February 8, 2021 Author Posted February 8, 2021 11 hours ago, Piscenois said: Thank you PetrozPL ! I tried pwm, pwm0, pwm1 but no pwm-gpio... Regards. Yhea, that makes two of us It took me some time and digging before I figured out the correct naming convention 0 Quote
Piscenois Posted February 8, 2021 Posted February 8, 2021 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 0 Quote
tony013 Posted May 5, 2021 Posted May 5, 2021 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. 0 Quote
PetrozPL Posted May 5, 2021 Author Posted May 5, 2021 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 1 Quote
lanefu Posted May 6, 2021 Posted May 6, 2021 Thanks @PetrozPL Added https://armbian.atlassian.net/browse/AR-735 1 Quote
tony013 Posted May 6, 2021 Posted May 6, 2021 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. 0 Quote
PetrozPL Posted May 6, 2021 Author Posted May 6, 2021 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. 0 Quote
tony013 Posted May 9, 2021 Posted May 9, 2021 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! 1 Quote
Fred Bloggs Posted March 31, 2023 Posted March 31, 2023 I have a okdo rock4 c+ with armbian on. I cannot get this to work, I can set pwm duty cycle, but fan speed on board does not change. Any help would be great. 0 Quote
PetrozPL Posted March 31, 2023 Author Posted March 31, 2023 (edited) Please, post pictures with your FAN connection to the board. EDIT : I've just checked and FAN in okdo is only 2-wire: 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 March 31, 2023 by PetrozPL 0 Quote
OttawaHacker Posted July 23, 2023 Posted July 23, 2023 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? 0 Quote
Petroz Posted July 25, 2023 Posted July 25, 2023 (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 July 25, 2023 by Petroz 0 Quote
OttawaHacker Posted July 25, 2023 Posted July 25, 2023 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 0 Quote
Xurd Jonquk Posted November 29 Posted November 29 Old thread but I moved into same problem while updating Rock 4C with Penta-SATA-HAT from legacy Debian 10 image to community maintained Debian 12 minimal image (Bookworm). I lost working OLED and fan did not work anymore. On boot.log I found: 18:45:23+0100 rock4c systemd: Started rockpi-penta.service - Rockpi SATA Hat. 18:45:25+0100 rock4c python3: File "/usr/bin/rockpi-penta/fan.py", line 24, in __init__ 18:45:25+0100 rock4c python3: File "/usr/bin/rockpi-penta/fan.py", line 98, in running 18:45:25+0100 rock4c python3: File "/usr/bin/rockpi-penta/fan.py", line 36, in period_us 18:45:25+0100 rock4c python3: File "/usr/bin/rockpi-penta/fan.py", line 32, in period 18:45:25+0100 rock4c python3: FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/pwm/pwmchip0/pwm0/period' 18:45:25+0100 rock4c python3: Waring: init pwm error 18:45:25+0100 rock4c systemd: rockpi-penta.service: Deactivated successfully. Those py-lines are pointing to some files which seems to be missing. It turned out that directory /sys/class/pwm/pwmchip0/pwm0 is missing at all. Based on thread information here and long search I found rock 4C pwm overlay rk3399-pwm1.dtbo at GitHub wich I copied as rockchip-rk3399-pwm1.dtbo to /boot/dtb/rockchip/overlay directory. I updated /boot/armbianEnv.txt by editing line containing overlays= rk3399-i2c7 rk3399-pwm1-by-rockpi-penta to overlays= rk3399-i2c7 rk3399-pwm1. I just rebooted machine and OLED as well as fan return back into working state. Missing directory pwm0 is back on it's place without any additional work. Now I'm able to continue OMV7 installation without further struggles. 0 Quote
PetrozPL Posted November 30 Author Posted November 30 Good to hear that someone still finds it useful 0 Quote
Recommended Posts
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.