Use a multimeter to verify PH5 is high.
Set PH5 to input mode with pull-down
kickpi@kickpi:~$ gpio mode 0 in
kickpi@kickpi:~$ gpio mode 0 down
kickpi@kickpi:~$ gpio read 0
0
kickpi@kickpi:~$ // Short pins 3 and 4
kickpi@kickpi:~$ gpio read 0
1
Set PH2 to PWM mode
root@kickpi:~# gpio mode 3 pwm #Default output frequency 23475Hz Square wave with duty cycle 50%
Adjust duty cycle
PWM duty cycle = CCR/ARR
CCR range: 0~65535 (default 512)
ARR range: 1~65536 (default 1024)
gpio pwmr 3 2048 //Set ARR to 2048 Duty cycle to 512/2048=25%
gpio pwm 3 1024 //Set CCR to 1024 Duty cycle to 1024/2048=50%
Adjust frequency
gpio mode 3 pwm //The default output frequency is 23475Hz
//Set the frequency division coefficient to 5, then the output frequency is 23475/5=4695Hz, the actual frequency is 4688Hz, the error can be ignored
gpio pwmc 3 5
gpio pwmTone 3 20000 //Directly set the frequency to 20000Hz
sys GPIO Control
Step 1: Release GPIO via /sys/class/gpio
Ensure the target GPIO is in UNCLAIMED state:
If pins are claimed (e.g., PH2/PH3 used as UART5), modify the device tree to disable default functions:
Edit device tree files:
vim longan/device/config/chips/h618/configs/p2/linux-5.4/board-*.dts // Android
vim source/kernel/linux-5.4-h618/arch/arm64/boot/dts/sunxi/sun50iw9-kickpi-k2b.dts // Linux
Step 2: Rebuild and flash the firmware.Step 3: Confirm GPIO is unclaimed: