persistent modify PWM, report IOCTL error, and hung
Describe the bug
run code, and after some indeterminate time, exit and report:
bcm283x-gpio (GPIO21): videocore: failed request to allocate memory: failed to send IOCTL: connection timed out
exit status 1
restart and hung when call PWM(duty > 0) , Ctrl+C will not works.
AND raspberry pi cannot restart normally via init 6, MUST shutdown the power
BUT RPi.GPIO(python) or wiringpi(C) can works normally with the same GPIO after hanged
To Reproduce Steps to reproduce the behavior:
- Run program
Pulse light
package main
import (
"fmt"
"log"
"periph.io/x/conn/v3/gpio"
"periph.io/x/conn/v3/physic"
"periph.io/x/host/v3"
"periph.io/x/host/v3/rpi"
"time"
)
func main() {
if _, err := host.Init(); err != nil {
panic(err.Error())
}
p := rpi.P1_40
i := 0
plus := true
for {
fmt.Printf("%d\n", i)
if err := p.PWM(gpio.DutyMax * gpio.Duty(i) / 100, 1000 * physic.Hertz); err != nil {
log.Fatal(err)
}
time.Sleep(10 * time.Millisecond)
if plus {
i++
} else {
i--
}
if i > 100 {
plus = !plus
i = 100
}
if i < 0 {
plus = !plus
i = 0
}
if err := p.Halt(); err != nil { // release gpu memory
log.Fatal(err)
}
}
}
- Run it.
- See error
Expected behavior
An pulse light effect
Platform (please complete the following information):
- OS: OpenFans aarch64 2.0 (https://github.com/openfans-community-offical/Debian-Pi-Aarch64)
- Board: Raspberry Pi 4B 4G
Additional context
I read the implement of startPWMbyDMA, I think a memory leak was caused by allocateCB to /dev/vcio
mailboxTx32(mbReleaseMemory, m.handle) maybe not work correctly
It'll not hung when useDMA=false,
so GPIO_13 GPIO_19 can works without hung
useDMA := false
switch p.number {
case 12, 40: // PWM0 alt0: disabled
useDMA = true
case 13, 41, 45: // PWM1
f = alt0
case 18: // PWM0 alt5: disabled
useDMA = true
case 19: // PWM1
f = alt5
default:
useDMA = true
}