Re: DMA, adresses
Posted: Sun Feb 07, 2021 9:19 pm
The code is complete. It should work out of the box. I used the original 1.13 RP2 micropython version. Where would you expect a 'SetChannelData' method/function?
Code: Select all
@micropython.viper
def SetChannelData(self, readAddress : uint , writeAddress : uint, count: uint, trigger : bool):
ptr= ptr32(self.ReadRegister)
ptr2= ptr32(self.WriteRegister)
ptr3= ptr32(self.TransferCountRegister)
ptr[0] = readAddress
ptr2[0] = writeAddress
ptr3[0] = count
if trigger:
ptr4= ptr32(self.TriggerControlRegister)
ptr4[0] = uint(self.ControlValue)
Thanks. Your code supports a lot more of the various features than mine though. As I haven't put in any functions to change things like the ring values yet.rgcoldeman wrote: ↑Mon Feb 08, 2021 8:04 amThanks, it looks very neat!
I've posted a more detailed description of the project on https://www.instructables.com/Arbitrary ... ry-Pi-Pic/
Code: Select all
# Example using PIO to drive a 8080 type bus
from machine import Pin, mem32
from time import sleep_us
import rp2
import array
import uctypes
DMA_BASE = const(0x50000000)
READ_ADDR = const(0)
WRITE_ADDR = const(1)
TRANS_COUNT = const(2)
CTRL_TRIG = const(3)
AL1_CTRL = const(4)
PIO0_BASE = 0x50200000
PIO0_BASE_TXF0 = PIO0_BASE+0x10
NUM_WORDS = 259
@rp2.asm_pio(
sideset_init=(rp2.PIO.OUT_HIGH,) * 3,
out_init=(rp2.PIO.OUT_HIGH,) * 8,
out_shiftdir=rp2.PIO.SHIFT_RIGHT,
autopull=True,
pull_thresh=8)
def data_write():
# fmt: off
out(pins, 8) .side(0b111)
nop() .side(0b110)
# fmt: on
@micropython.viper
def startDMA(chan:uint, ar, nword:uint):
dma=ptr32(uint(DMA_BASE) + chan * 0x40)
dma[READ_ADDR] = uint(ptr32(ar))
dma[WRITE_ADDR] = uint(PIO0_BASE_TXF0)
dma[TRANS_COUNT] = nword
IRQ_QUIET = const(0x1) # do not generate an interrupt
TREQ_SEL = const(0x00) # wait for PIO0_TX0
CHAIN_TO = const(0) # do not chain
RING_SEL = const(0)
RING_SIZE = const(0) # no wrapping
INCR_WRITE = const(0) # for write to array
INCR_READ = const(1) # for read from array
DATA_SIZE = const(0) # 8-bit word transfer
HIGH_PRIORITY = const(1)
EN = const(1)
CTRL0 = const((IRQ_QUIET << 21) | (TREQ_SEL << 15) | (CHAIN_TO << 11) | (RING_SEL << 10) |
(RING_SIZE << 9) | (INCR_WRITE << 5) | (INCR_READ << 4) | (DATA_SIZE << 2) |
(HIGH_PRIORITY << 1) | (EN << 0))
dma[CTRL_TRIG] = uint(CTRL0)
def run():
ar = array.array("B", [_ for _ in range(NUM_WORDS)])
# Create the StateMachine with the data_write program, WR on Pin(5), data on pin 8++
sm = rp2.StateMachine(0, data_write, freq=125_000_000,
sideset_base=Pin(2), out_base=Pin(6))
sm.active(1)
startDMA(0, ar, len(ar) - 3)