As Ian said, alignment and the size of the read are crucial. If you aren't reading (or writing) a word, naturally aligned then the mmu won't spot your access to IO area and you'll get garbage data,
https://github.com/davecheney/gpio/blob/master/rpi/gpio.go On Wednesday, 15 June 2016 06:40:45 UTC+10, Ian Lance Taylor wrote: > > On Tue, Jun 14, 2016 at 12:17 PM, Dave Mazzoni <dav...@gmail.com > <javascript:>> wrote: > > Hello all - I've been having a hard time getting syscall.Mmap to produce > the > > "right" values. I'm using 1.6.2 and cross-compiling for the ARM/Linux. > I'm > > trying to read from Arm memory at its device address 0x43c00000. > > > > Here's the scenario: I 'poke' values into memory using the C based > arm/linux > > 'poke' command: > > /var/ftp# poke 0x43c00000 0x03020100 > > /var/ftp# poke 0x43c00004 0x07060504 > > /var/ftp# poke 0x43c00008 0x0b0a0908 > > /var/ftp# poke 0x43c0000c 0x0f0e0d0c > > > > If I then 'read' from these memory locations with the C based peek > command I > > get this (as expected): > > /var/ftp# peek 0x43c00000 > > 0x03020100 > > /var/ftp# peek 0x43c00004 > > 0x07060504 > > /var/ftp# peek 0x43c00008 > > 0x0b0a0908 > > /var/ftp# peek 0x43c0000c > > 0x0f0e0d0c > > > > However, if I use a go based version to read this range, something is > wrong > > (peek_orig.go, attached), results in: > > /var/ftp# ./peekgo 0x43c00000 > > mem[0]:0x00 mem[1]:0x01 mem[2]:0x02 mem[3]:0x00 > mem[4]:0x04 > > mem[5]:0x00 mem[6]:0x00 mem[7]:0x00 > > mem[8]:0x08 mem[9]:0x00 mem[10]:0x00 mem[11]:0x00 > mem[12]:0x0c > > mem[13]:0x00 mem[14]:0x00 mem[15]:0x00 > > mem[16]:0x00 mem[17]:0x00 mem[18]:0x00 mem[19]:0x00 > mem[20]:0x00 > > mem[21]:0x00 mem[22]:0x00 mem[23]:0x00 > > mem[24]:0x00 mem[25]:0x00 mem[26]:0x00 mem[27]:0x00 > mem[28]:0x00 > > mem[29]:0x00 mem[30]:0x00 mem[31]:0x00 > > > > I'll also attach the equivalent C based version of peek (peek.c). > > > > I believe everything in the go version should work based on godoc -src > > syscall Mmap, which shows the actual call to the linux mmap function. > The go > > version returns a []byte, but they're not the correct values. > > > > Any help/suggestions would be very welcome! > > I don't know the answer. The results you are getting seem partially > correct. That suggests that one thing to try is to access the memory > as words rather than bytes. Some device memory is sensitive to the > size of the memory access. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.