Power & Source of Big Ideas

CM3588: CPU Fan

Moderators: chensy, FATechsupport

I have connected the ZH1.5-2pin connector to the 5V CPU fan socket to a 40mm fan, however the fan does not turn on.

The fan works fine when powered from GPIO pins.

I've checked the voltage across 5V pins and it was only 0.10V.

Does this CPU fan need to be activated via /sys or GPIO somehow?

Thanks
This is making the trick for me :

Code: Select all

echo 59 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio59/direction
echo 1 > /sys/class/gpio/gpio59/direction


Should probably create a /etc/init.d for that?

Regards.
yaazzz wrote:
This is making the trick for me :

Code: Select all

echo 59 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio59/direction
echo 1 > /sys/class/gpio/gpio59/direction


Should probably create a /etc/init.d for that?

Regards.


Thank you for that, curious where did you find which GPIO pin to use?

I'm also curious to know how /sys/class/gpio/gpioXX maps to the pin# on 40-pin GPIO stack.

Also slight correction to your script:

Code: Select all

echo 59 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio59/direction
echo 1 > /sys/class/gpio/gpio59/value
I made it using the schematic and the formula found on a rk3588 wiki :
pin = bank*32 + group*8 + number;

GPIO1_D3 => Bank 1 pin
bank=1 => 1*32
group ∈ {(A=0), (B=1), (C=2), (D=3)} => group = 8*3 = 24

pin = 1*32 + 8*3 + 3 = 59

We are now at the same level ;)
yaazzz wrote:
I made it using the schematic and the formula found on a rk3588 wiki :
pin = bank*32 + group*8 + number;

GPIO1_D3 => Bank 1 pin
bank=1 => 1*32
group ∈ {(A=0), (B=1), (C=2), (D=3)} => group = 8*3 = 24

pin = 1*32 + 8*3 + 3 = 59

We are now at the same level ;)


Thank you
Here is the code I use to start the fan at startup. Probably usefull for all of the CM3588 users.

1 - Create a new init.d script, for example, /etc/init.d/gpio_setup:

Code: Select all

sudo nano /etc/init.d/gpio_setup


2. Add the following content to the script:

Code: Select all

#!/bin/sh
### BEGIN INIT INFO
# Provides:          gpio_setup
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Set up GPIO 59 as output with value 1
# Description:       Set up GPIO 59 as output and set its value to 1 during system startup.
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="GPIO setup script"
NAME=gpio_setup
DAEMON=/usr/local/bin/gpio_setup.sh

case "$1" in
  start)
    echo "Setting up GPIO 59 as output with value 1..."
    $DAEMON
    ;;
  stop)
    # No need to stop anything in this example
    ;;
  restart|force-reload)
    echo "Restarting GPIO setup script..."
    $DAEMON
    ;;
  *)
    echo "Usage: $NAME {start|stop|restart|force-reload}" >&2
    exit 1
    ;;
esac

exit 0


3. Save the file and exit the text editor.

4. Now, create the script that actually sets up the GPIO. Create a file named /usr/local/bin/gpio_setup.sh:

Code: Select all

sudo nano /usr/local/bin/gpio_setup.sh


5. Add the following content to the script:

Code: Select all

#!/bin/bash

# GPIO number
GPIO_NUMBER=59

# Set GPIO 59 as output
echo $GPIO_NUMBER > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$GPIO_NUMBER/direction

# Set the value to 1
echo 1 > /sys/class/gpio/gpio$GPIO_NUMBER/value

exit 0


6. Save the file and exit the text editor.

7. Make the init.d script and the setup script executable:

Code: Select all

sudo chmod +x /etc/init.d/gpio_setup
sudo chmod +x /usr/local/bin/gpio_setup.sh


8. Register the init.d script to start during the system boot:

Code: Select all

sudo update-rc.d gpio_setup defaults
This solution worked great on my CM3588 NAS kit. Thank you both for your contribution!
@yaazzz do you think it would be possible to control the fan speed by altering the voltage that the fan port sends out? By default it outputs 5V for 100% fan speed but I'd like to be able to adjust to 4 or 4.5V to slow down the fans and reduce noise.
yaazzz wrote:
Here is the code I use to start the fan at startup. Probably usefull for all of the CM3588 users.

1 - Create a new init.d script, for example, /etc/init.d/gpio_setup:

Code: Select all

sudo nano /etc/init.d/gpio_setup


2. Add the following content to the script:

Code: Select all

#!/bin/sh
### BEGIN INIT INFO
# Provides:          gpio_setup
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Set up GPIO 59 as output with value 1
# Description:       Set up GPIO 59 as output and set its value to 1 during system startup.
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="GPIO setup script"
NAME=gpio_setup
DAEMON=/usr/local/bin/gpio_setup.sh

case "$1" in
  start)
    echo "Setting up GPIO 59 as output with value 1..."
    $DAEMON
    ;;
  stop)
    # No need to stop anything in this example
    ;;
  restart|force-reload)
    echo "Restarting GPIO setup script..."
    $DAEMON
    ;;
  *)
    echo "Usage: $NAME {start|stop|restart|force-reload}" >&2
    exit 1
    ;;
esac

exit 0


3. Save the file and exit the text editor.

4. Now, create the script that actually sets up the GPIO. Create a file named /usr/local/bin/gpio_setup.sh:

Code: Select all

sudo nano /usr/local/bin/gpio_setup.sh


5. Add the following content to the script:

Code: Select all

#!/bin/bash

# GPIO number
GPIO_NUMBER=59

# Set GPIO 59 as output
echo $GPIO_NUMBER > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio$GPIO_NUMBER/direction

# Set the value to 1
echo 1 > /sys/class/gpio/gpio$GPIO_NUMBER/value

exit 0


6. Save the file and exit the text editor.

7. Make the init.d script and the setup script executable:

Code: Select all

sudo chmod +x /etc/init.d/gpio_setup
sudo chmod +x /usr/local/bin/gpio_setup.sh


8. Register the init.d script to start during the system boot:

Code: Select all

sudo update-rc.d gpio_setup defaults


Hi, i don't have this ZH1.5-2pin connector for the 5V CPU fan socket. This is why i want to use your skript with my GPIO pins.
Your skript is working fine and i adapted it to set the line 11 to LOW, and the line 12 to HIGH (those are the pins i where i want to connect my fan). Here is the output for gpioinfo gpiochip3:

gpiochip3 - 32 lines:
line 0: unnamed unused input active-high
line 1: unnamed unused input active-high
line 2: unnamed unused input active-high
line 3: unnamed unused input active-high
line 4: unnamed unused input active-high
line 5: unnamed "vcc3v3-host-32" output active-high [used]
line 6: unnamed unused input active-high
line 7: unnamed unused input active-high
line 8: unnamed unused input active-high
line 9: unnamed unused input active-high
line 10: unnamed unused input active-high
line 11: unnamed "sysfs" output active-high [used]
line 12: unnamed "sysfs" output active-high [used]
line 13: unnamed unused input active-high
line 14: unnamed unused input active-high
line 15: unnamed unused input active-high
line 16: unnamed unused input active-high
line 17: unnamed unused input active-high
line 18: unnamed unused input active-high
line 19: unnamed unused input active-high
line 20: unnamed unused input active-high
line 21: unnamed unused input active-high
line 22: unnamed unused input active-high
line 23: unnamed unused input active-high
line 24: unnamed unused input active-high
line 25: unnamed unused input active-high
line 26: unnamed unused input active-high
line 27: unnamed unused input active-high
line 28: unnamed unused input active-high
line 29: unnamed unused input active-high
line 30: unnamed unused input active-high
line 31: unnamed unused input active-high

As you can see, i am not able to set the line 11 to LOW. Do you have an idea what i can do about this?
@Gimli yes it's possible, you need to use PWM mode instead of GPIO mode

For that you must first unload the pwm-fan module (all commands in root)

Code: Select all

rmmod pwm-fan

or to permanently disable it

Code: Select all

echo "blacklist pwm-fan" > /etc/modprobe.d/pwm-fan.conf
reboot


Then you can do

Code: Select all

echo 0 > /sys/class/pwm/pwmchip0/export
echo 100000 > /sys/class/pwm/pwmchip0/pwm0/period
echo normal > /sys/class/pwm/pwmchip0/pwm0/polarity
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
echo 20000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle


You can change the duty_cycle from 0 to 100000 ns to change the fan speed, eg

Code: Select all

echo 0 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle # off
echo 25000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle # 25%
echo 50000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle # 50%
echo 75000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle # 75%
echo 100000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle # 100%


depending on your fan, you can try different period / duty_cycle combination, especially to reach slow PWM % with fan still running. With mine fan the best setting is period = 100000 ns with permit to reach PWM 2%
The initial OP said I also can't put to work a Noctua 5V 40mm with the ZH1.5-2pin connector and I was trying the commands before going to the init script method mentioned before.
inf wrote:

Code: Select all

echo 59 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio59/direction
echo 1 > /sys/class/gpio/gpio59/value


When doing

Code: Select all

sudo sh -c 'echo 59 > sudo /sys/class/gpio/export'
sudo sh -c 'echo out > /sys/class/gpio/gpio59/direction'

sh: 1: cannot create /sys/class/gpio/gpio59/direction: Directory nonexistent
'

Even if I do

Code: Select all

echo out > /sys/class/gpio/gpio59/direction

-bash: /sys/class/gpio/gpio59/direction: No such file or directory


These are the folders in `/sys/class/gpio`

Code: Select all

export  gpiochip0    gpiochip32   gpiochip64  unexport
gpio52  gpiochip128  gpiochip509  gpiochip96


Maybe I am asking a dumb question but is it supposed to create the folder?
TiagoSousa wrote:
The initial OP said I also can't put to work a Noctua 5V 40mm with the ZH1.5-2pin connector and I was trying the commands before going to the init script method mentioned before.

These are the folders in `/sys/class/gpio`

Code: Select all

export  gpiochip0    gpiochip32   gpiochip64  unexport
gpio52  gpiochip128  gpiochip509  gpiochip96


Maybe I am asking a dumb question but is it supposed to create the folder?


The first line that writes the number "59" to the "export" file should create the "gpio59" directory. Are you getting an error message, either on the shell or in "dmesg"?


Kind regards,
Stefan
cite wrote:
The first line that writes the number "59" to the "export" file should create the "gpio59" directory. Are you getting an error message, either on the shell or in "dmesg"?

No, I don't get an error by running the first command, just the second command gives me an error. Do I try to create the folder by myself?

Here is my console output:

Code: Select all

Tiago@openmediavault:/$ sudo sh -c 'echo 59 > sudo /sys/class/gpio/export'
[sudo] password for Tiago:
Tiago@openmediavault:/$ sudo sh -c 'echo out > /sys/class/gpio/gpio59/direction'
sh: 1: cannot create /sys/class/gpio/gpio59/direction: Directory nonexistent
Tiago@openmediavault:/$

Code: Select all

Tiago@openmediavault:/$ sudo sh -c 'echo 59 > sudo /sys/class/gpio/export'
[sudo] password for Tiago:
Tiago@openmediavault:/$ sudo sh -c 'echo out > /sys/class/gpio/gpio59/direction'


Your first line has an additional "sudo" there. The correct command is:

Code: Select all

sudo sh -c  'echo 59 > /sys/class/gpio/export'


However, with newer images, the fan should work out of the box, and get active at ~50°C. This is controlled by the DTS, see: https://github.com/friendlyarm/kernel-r ... 09.dts#L84

The "cooling levels" define a value between 0 and 255 (with 255 spinning up the fan to it's maximum RPM), and the below "temp trips" are millidegrees that trigger increased cooling. So at a temperature of 50°C (50000/1), the fan will spin up to about 13.7% (35/255*100). For me, that was too low (the fan didn't spin up, emitting a loud coil whine), so I changed that to 42 (and increased the first temp trip to 52°C). I then used the method described at https://wiki.friendlyelec.com/wiki/inde ... to_Compile to compile the kernel in a Docker container and flash it to the board afterwards. To find out what values are needed, just echo the value from 0 to 255 to the PWM control:

Code: Select all

echo 42 | sudo tee  /sys/devices/platform/pwm-fan/hwmon/hwmon13/pwm1



Kind regards,
Stefan
So... at this point I have a USB power header... I'd love to have it plugged into the board so it wasn't going 100% all the time, but for the life of me I can't even find the right plug for the fan socket to splice into my current fan. Does anyone have a link on a cable or a cheap fan that I could buy and cannibalize?

Who is online

In total there are 13 users online :: 0 registered, 0 hidden and 13 guests (based on users active over the past 5 minutes)
Most users ever online was 5185 on Wed Jan 22, 2020 1:44 pm

Users browsing this forum: No registered users and 13 guests