Here's how I did something similar for one of my projects:
I don't know if that's the best approach, but it works fine for me. The main difference from what you posted is that it sends bytes to PIO, so everything is set up for byte transfers, but changing it to words should be trivial.
Code:
from machine import Pinfrom rp2 import DMA, StateMachine, PIO, asm_piofrom array import arrayimport uctypesdata = bytes([0x0, 0x1, 0x2, 0x3]) # test dataaddr_buf = array('L', [uctypes.addressof(data)]) # get address of data buffer@asm_pio(out_init=(PIO.OUT_LOW,) * 8, out_shiftdir=PIO.SHIFT_RIGHT, autopull=True, pull_thresh=8)def set_pins(): out(pins, 8) sm = StateMachine(0, set_pins, freq=100_000, out_base=Pin(2))sm.active(1)dma = DMA()dma2 = DMA()c = dma.pack_ctrl(size=0, inc_read=True, inc_write=False, treq_sel=0, chain_to=dma2.channel, enable=True)dma.config(ctrl=c)dma.read = datadma.write = smdma.count = len(data)c2 = dma2.pack_ctrl(size=2, inc_read=False, inc_write=False, chain_to=dma.channel, enable=True)dma2.config(ctrl=c2)dma2.read = addr_bufdma2.write = 0x50000000 + dma.channel * 0x40dma2.count = 1dma.active(1)
Statistics: Posted by horuable — Mon Jan 06, 2025 10:29 pm