PYNQ: PYTHON PRODUCTIVITY

Read entire array

I have an IP/overlay which saves data to an array: ap_uint<14> usr_gpio[32].
Now, once the IP has finished its run, I go ahead and read the values from PS.

Loading the overlay

overlay = Overlay('./my_ip.bit')
self.my_ol = overlay.my_overlay

And I know the array starts at 0x40 and I also know that each read
self.my_ol.read(0x40)
returns 2 elements of the array, i.e. 14 bits and 4 adresses. So in order for me to read entire array I have to loop 16 times through

for k in range(0, 64, 4):
    value = self.my_ol.read(0x40 + k)

Whatever…

My question is, is there a way to read the entire array in one go? E.g. adding length to the read function. I’ve seen some topics/examples using MMIO which I couldn’t really fit in to my issue.

Each device driver has a .mmio property which gives you direct access to the MMIO instance which you could then use with the other examples. In your case the point of interest is probably using my_ol.mmio.array which will be a numpy array of the memory mapped region.

Note that you use array indices rather than addresses to access the memory - so my_ol.mmio.array[0x10:0x20]

On Zynq Ultrascale+ you have to be very careful with memory alignment when accessing memory in this way. Zynq-7000 is slightly more forgiving.

Peter

2 Likes

Thanks. I know I tried that before but was reading 0. Now I kept reading through adresses and finally hit some data. It seems addressing of the MMIO it is weird… I read like 0 four times, and on the fifth address (having offset the adresses by 4 each time) I read all four previous values which read() returned.

But this is great, I’ll def work on this.
Thanks again