Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

persistent modify PWM, report IOCTL error, and hung #12

Open
fly-studio opened this issue Sep 12, 2021 · 1 comment
Open

persistent modify PWM, report IOCTL error, and hung #12

fly-studio opened this issue Sep 12, 2021 · 1 comment

Comments

@fly-studio
Copy link

fly-studio commented Sep 12, 2021

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):

Additional context

@fly-studio fly-studio changed the title persistent modify PWM, report IOCTL error, and hanged persistent modify PWM, report IOCTL error, and hung Sep 12, 2021
@fly-studio
Copy link
Author

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
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant