# DMA, How to align memory?

**URL:** <https://discuss.pynq.io/t/dma-how-to-align-memory/3332>\
**Category:** Support\
**Created:** [November 22, 2021, 4:33pm UTC](https://discuss.pynq.io/t/dma-how-to-align-memory/3332 "2021-11-22T16:33:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charlie\_Meng](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/charlie_meng/32/2008_2.png) [@Charlie\_Meng](https://discuss.pynq.io/u/Charlie_Meng)\
**Post date:** [November 22, 2021, 4:33pm UTC](https://discuss.pynq.io/t/dma-how-to-align-memory/3332/1 "2021-11-22T16:33:07Z")

</div>

Hi,

When I use DMA to transfer data, at first, it is ok. when I change to data, it has an error like this.  
So I want to know how to align memory? When I define the address alignment using ‘allocate()’. Thank you! I have seen one answer to skip the alignment(modify in Vivado). But in my case, it is better to do the alignment.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/9/9ceeed05e996f6eadc2d01c6829f3a82fe955495.png)

![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/9/9bf09eb43dcec75752c533b78145ae8ac4daa682.png)

---

<div class="post-metadata">

**Author:** ![PeterOgden](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/peterogden/32/55_2.png) [@PeterOgden](https://discuss.pynq.io/u/PeterOgden)\
**Post date:** [November 22, 2021, 4:50pm UTC](https://discuss.pynq.io/t/dma-how-to-align-memory/3332/2 "2021-11-22T16:50:35Z")

</div>

That is a bug in the DMA driver - we’ve not tested widths that aren’t a power of 2 and in this case the alignment should be 4 or 8 not 6. All buffers from `allocate` will be at least page (i.e. 4096 byte) aligned. Would you be able to share your hwh file and we’ll come up with a workaround?

Peter

---

<div class="post-metadata">

**Author:** ![Charlie\_Meng](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/charlie_meng/32/2008_2.png) [@Charlie\_Meng](https://discuss.pynq.io/u/Charlie_Meng)\
**Post date:** [November 22, 2021, 5:10pm UTC](https://discuss.pynq.io/t/dma-how-to-align-memory/3332/3 "2021-11-22T17:10:21Z")

</div>

Thank you for reply. So, I will share.[ZCU104\_6\_L15\_SG\_9pin\_add\_time\_interpret\_48ohm\_unalign.hwh](https://discuss.pynq.io/uploads/short-url/qWgshHvUWKNqHsoVfUCYOxpc0gN.hwh) (369.2 KB)

---

<div class="post-metadata">

**Author:** ![PeterOgden](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/peterogden/32/55_2.png) [@PeterOgden](https://discuss.pynq.io/u/PeterOgden)\
**Post date:** [November 22, 2021, 5:21pm UTC](https://discuss.pynq.io/t/dma-how-to-align-memory/3332/4 "2021-11-22T17:21:32Z")

</div>

Can you edit the [pynq/lib/dma.py](https://github.com/Xilinx/PYNQ/blob/59515a9b5de6fad0ff0538bfc50010b16f53c9a8/pynq/lib/dma.py#L710) file on lines 710 and 727 from `6` to `data_width`. Looks like some refactoring introduced an error.

[Edit] Same with 652 and 669

Peter

---

<div class="post-metadata">

**Author:** ![Charlie\_Meng](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/charlie_meng/32/2008_2.png) [@Charlie\_Meng](https://discuss.pynq.io/u/Charlie_Meng)\
**Post date:** [November 22, 2021, 7:29pm UTC](https://discuss.pynq.io/t/dma-how-to-align-memory/3332/6 "2021-11-22T19:29:48Z")

</div>

It works. Thank you!

---

<div class="post-metadata">

**Author:** ![jancumps](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/jancumps/32/2140_2.png) [@jancumps](https://discuss.pynq.io/u/jancumps)\
**Post date:** [November 23, 2021, 9:40pm UTC](https://discuss.pynq.io/t/dma-how-to-align-memory/3332/7 "2021-11-23T21:40:48Z")

</div>

I created a [pull request](https://github.com/Xilinx/PYNQ/pull/1321) to rectify.
