It is possible to access the register map for IP in the overlay directly. This functionality requires that the .hwh
file is distributed along with the bitstream. This can be generated from Vivado.
In this example we are going us the GPIO blocks controlling the buttons and LEDs to demonstrate how to explore and interact with the register map.
First we need to import the base overlay
In [1]:
from pynq.overlays.base import BaseOverlay
base = BaseOverlay('base.bit')
Next we get the drivers for
In [2]:
btns = base.btns_gpio
leds = base.leds_gpio
We can now print the register map and the current values of the registers by printing the representation of the .register_map
.
In [3]:
btns.register_map
Out[3]:
To access values programmatically we can walk the object model
In [4]:
btns.register_map.GPIO_DATA.Channel_1_GPIO_DATA
Out[4]:
If there any more information on a register is available it can be accessed using help
. This will list any description of the register available as well as the subfields. Here we see that the IP_IER
register the interrupt enable register and contains two fields - one for each channel.
In [5]:
help(btns.register_map.IP_IER)
Writing can be performed either to registers or fields. Note that register slice access are performed using the RTL conventions of hi:lo inclusive to match the format commonly seen in data sheets rather than the lo:hi inclusive-exclusive more common in Python ranges.
In [6]:
leds.register_map.GPIO_DATA.Channel_1_GPIO_DATA = 8
leds.register_map.GPIO_DATA[2:0] = 5
At present this functionality is limited to scalar registers in IP that has the attached metadata. This includes most IP in the Xilinx IP catelog and any HLS-generated IP that uses AXI-lite for control registers.