I run 64 bit python on a 64 bits arm processor. One on the AXI bus of this processor is connected to a FPGA (which does bus and clock domain changes down to a 32 bit wide bus). This piece of hardware does not like 64 bit accesses...
I am trying to access this FPGA via python mmap like this (within a class):
def __init__(self, base, len):
self.base = base
self.fd = open("/dev/mem", "r+")
self.lw = mmap.mmap(self.fd.fileno(),
len,
mmap.MAP_SHARED,
mmap.PROT_READ | mmap.PROT_WRITE,
offset=base)
def get_U32(self, offset):
s = self.lw[offset:offset+4]
return struct.unpack("<I", s)[0]
The idea was to that get_U32()
would read a 32 bit word from the bus (hence the offset to offset+4 reading).
Sadly, it seems that mmap performs a 64 bit access to the bus anyway (some kind of caching for performance optimization I assume) and then performs the 32 bit "casting". The underlying FPGA is not happy...
In a C program, I simply write:
data = *((uint32_t *) address);
...and the CPU seems to gently perform a 32 bit access on its AXI bus, which the underlying hardware prefers.... (so right now, I have a (slow) workaround, where python requires a C program to interface the Hardware, via pipes)
Is there a way to force 64 bits python to perform a 32 bit access, as the previous C line obviously succeeds with?
The question is written about reading 32 bits here, but of course, writing 32 bits is needed as well...