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

pmem example code incorrect #2

Open
martin2250 opened this issue May 12, 2021 · 3 comments
Open

pmem example code incorrect #2

martin2250 opened this issue May 12, 2021 · 3 comments

Comments

@martin2250
Copy link

martin2250 commented May 12, 2021

I think there is an error in the pmem example for MapAsPOD.

package main

import (
	"log"

	"periph.io/x/host/v3/pmem"
)

func main() {
	// Let's say the CPU has 4 x 32 bits memory mapped registers at the address
	// 0xDEADBEEF.
	var reg *[4]uint32
	if err := pmem.MapAsPOD(0xDEADBEAF, reg); err != nil {
		log.Fatal(err)
	}
	// reg now points to physical memory.
}

It only works when I add a referencing operator to the function call, like so: pmem.MapAsPOD(0xDEADBEAF, &reg), so this code works for me:

var reg *[SMC_MEM_LEN / 2]uint16
if err := pmem.MapAsPOD(SMC_MEM_START, &reg); err != nil {

Otherwise, I get an error during runtime: pmem: require Ptr to Ptr, got invalid (or got slice/got array).

In case this is relevant, I'm compiling for an AT91SAM9G45 with Linux 3.0.0.

@maruel
Copy link
Member

maruel commented May 12, 2021

Small note; "periph.io/x/host/v3/pmem"

@martin2250
Copy link
Author

right, I updated the code snippet.

@kaisawind
Copy link

kaisawind commented Dec 27, 2021

same.
Linux 5.4.164-1-MANJARO #1 SMP PREEMPT Wed Dec 8 09:53:07 UTC 2021 x86_64 GNU/Linux

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

3 participants