Reading UART registers
Posted: Sun Mar 13, 2016 8:34 am
Hello,
I have a RPi2 and want to have access to the UART registers.
I've made my own PCB with as an interface board suited for my needs.
On this board there is a RS485 IC (MAX3485), but this needs an additional output to switch between RX/TX mode (half duplex communication).
So I have to check the TX buffer is empty AND the last byte is completely sent.
But I need some help to get it working and accessing the registers. I can not find the problem on my own.
So here is some python code, but at the end it reads 0.
I tested with /dev/mem instead of /dev/gpiomem to make it easy, I will change that afterwards.
As I understand RPi2 starts with base 0x3F000000.
I now need the offset towards the UART registers, there are 2 UART's. One is the mini UART and the other one the PL011 UART, from what I've read we are using the PL011.
I use the datasheet from the old pi: https://www.raspberrypi.org/documentati ... herals.pdf
On page 177 "The PL011 USRT is mapped on base adderss 0x7E20100."
So I think I need to add 0x3f000000 + 0x7E20100 and that is where the UART starts.
See also this thread: https://www.element14.com/community/thr ... hread=true
Since offset must be a multiple of the pagesize it will be 0x3F000000 + 0x7E20000 and we have 0x100 to do later.
This 0x100 I can do with seek with an additional offset of 0x18 to get into the flag register (32-bit) where I can find my data, so ending at 0x118 offset.
I read 4 bytes, little-endian and want this as unsigned integer but the value is 0.
I do not know what's wrong, or another good way to test the memory access is working as I think it should be.
While testing different offsets, ... data was not always 0 so something is read from the memory.
Thanks!
I have a RPi2 and want to have access to the UART registers.
I've made my own PCB with as an interface board suited for my needs.
On this board there is a RS485 IC (MAX3485), but this needs an additional output to switch between RX/TX mode (half duplex communication).
So I have to check the TX buffer is empty AND the last byte is completely sent.
But I need some help to get it working and accessing the registers. I can not find the problem on my own.
So here is some python code, but at the end it reads 0.
I tested with /dev/mem instead of /dev/gpiomem to make it easy, I will change that afterwards.
As I understand RPi2 starts with base 0x3F000000.
I now need the offset towards the UART registers, there are 2 UART's. One is the mini UART and the other one the PL011 UART, from what I've read we are using the PL011.
I use the datasheet from the old pi: https://www.raspberrypi.org/documentati ... herals.pdf
On page 177 "The PL011 USRT is mapped on base adderss 0x7E20100."
So I think I need to add 0x3f000000 + 0x7E20100 and that is where the UART starts.
See also this thread: https://www.element14.com/community/thr ... hread=true
Since offset must be a multiple of the pagesize it will be 0x3F000000 + 0x7E20000 and we have 0x100 to do later.
This 0x100 I can do with seek with an additional offset of 0x18 to get into the flag register (32-bit) where I can find my data, so ending at 0x118 offset.
I read 4 bytes, little-endian and want this as unsigned integer but the value is 0.
I do not know what's wrong, or another good way to test the memory access is working as I think it should be.
While testing different offsets, ... data was not always 0 so something is read from the memory.
Thanks!
Code: Select all
mem = os.open('/dev/mem', os.O_RDWR | os.O_SYNC)
off = 0x3f000000 + 0x7e20000
mem_mmap = mmap.mmap(mem, mmap.PAGESIZE, mmap.MAP_SHARED, mmap.PROT_READ | mmap.PROT_WRITE, offset=off)
os.close(mem)
mem_mmap.seek(0x118)
print unpack('<I', mem_mmap.read(4))