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
x/exp/io/spi: spi.Devfs.MaxSpeed may be ignored in certain case #16551
Comments
MaxSpeed is documented as setting the max speed only; it seems like it's defensible, if a bit silly, for the kernel to choose 312kHz when you request 10MHz. It looks like Go is just passing the requested speed on to the kernel. |
@quentinmit Please reread my comment. When using my own code, the kernel correctly choose the closest clock speed, which is 6.25mhz. |
Can you show the output of "strace" on both programs? |
I think the devfs_READ and devfs_WRITE constants are reversed. With existing values (https://github.com/golang/exp/blob/master/io/spi/devfs.go#L19):
From the C header files:
|
These constants looks suspicious but all other writes (in the scope of my use cases) are succeeding. strace output would be useful between the two. |
I just want to confirm that we have had to swap devfs_READ and devfs_WRITE to get the code to work. This should really just be fixed. |
I would like to confirm the same findings. The platform that I am developing on is an RPi Zero v1.3. The Linux kernel is 4.9.59+, and the SPI kernel module is spi_bcm2835. I suspected also that READ and WRITE were reversed and came across this thread after a few days of debugging. I inserted some fmt.Println statements in devfs.go and found that the referenced value was being "rejected." Both setting the speed and setting the SPI mode bits were broken, and investigation with a high speed logic analyzer was showing a clock around 100 MHz and no change in phase when I set up the peripheral with different parameters. The following is a snippet of what I used to debug in devfs.go. "m before:" for instance would be 2, and "m after:" would be 0.
|
I recommend https://periph.io/x/periph/conn/spi/spireg, which will be supported going forward. I'll keep this bug open for documentation purposes but I'm unsubscribing for notifications so @ me directly if you want me to see the message. |
I don't plan to make any change here. |
go version
)?go version go1.7rc3 linux/arm
go env
)?Raspberry Pi 3
$ go env
GOARCH="arm"
GOBIN=""
GOEXE=""
GOHOSTARCH="arm"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/pi/src/gopath"
GORACE=""
GOROOT="/home/pi/src/golang"
GOTOOLDIR="/home/pi/src/golang/pkg/tool/linux_arm"
CC="gcc"
GOGCCFLAGS="-fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build544338587=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
$ cd $GOPATH/src/golang.org/x/exp && git rev-parse HEAD
fac9e6d4e3a4bd9d3dd6f47b3c79027a6b64dd0a
https://play.golang.org/p/BWhX4aQ9G6
which was extracted from https://github.com/maruel/spiperf/blob/master/gio/gio.go
Clock frequency to be 10mhz or a somewhat lower value, as supported by the linux SPI driver.
Observed clock frequency is 312khz as seen via oscilloscope. When testing a with one-off code, I get 6.25mhz.
The text was updated successfully, but these errors were encountered: