host icon indicating copy to clipboard operation
host copied to clipboard

persistent modify PWM, report IOCTL error, and hung

Open fly-studio opened this issue 4 years ago • 1 comments

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:

  1. 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)
		}
	}

}
  1. Run it.
  2. 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

fly-studio avatar Sep 12 '21 05:09 fly-studio

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
	}

fly-studio avatar Sep 12 '21 09:09 fly-studio