dMA +Pio in Pico Board

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
PicoFan
Posts: 1
Joined: Sat Jul 02, 2022 10:39 am

dMA +Pio in Pico Board

Post by PicoFan » Sun Jul 03, 2022 3:04 pm

Hi,
I have a question according DMA settings on Pico Board.
I have programmed a DMA Transfer to PIO TX0 but can`t See any Action in the corrosponding Pin on Pico Board.
Can anyone say If something is missing in initialisation?
Thanks a Lot.


Code: Select all

from machine import Pi
import machine 
import rp_devices as devs
from rp2 import PIO, StateMachine, asm_pio
from utime import sleep
import uctypes


UART_BAUD = 5200
PIN_BASE = 10
NUM_UARTS = 6
led_onboard = Pin(26, Pin.OUT)
Trigger = Pin(9,Pin.OUT)
LED_PANEL_ARRAY = 20 #9840

DMA_BASE         = 0x50000000 
DMA_RD_ADR       = DMA_BASE + 0x00
DMA_WR_ADR       = DMA_BASE + 0x04
DMA_WR_CNT       = DMA_BASE + 0x08
DMA_WR_TRG       = DMA_BASE + 0x0C

PIO0_BASE = 0x50200000
PIO1_BASE = 0x50300000


machine.mem32(DMA_BASE)
TXF0 = 0x010
TXF1 = 0x014
TXF2 = 0x018
TXF3 = 0x01C
RXF0 = 0x020
RXF1 = 0x024
RXF2 = 0x028
RXF3 = 0x02C

picture_1 = bytearray('Hello Pico Board.', 'utf-8')
#picture_2 = bytearray[LED_PANEL_ARRAY]

ReadAD       = uctypes.bytearray_at(DMA_RD_ADR,uctypes.UINT32)
ReadAD       = uctypes.addressof(picture_1)
WriteAD      = uctypes.bytearray_at(DMA_WR_ADR,uctypes.UINT32)
WriteAD      = (PIO0_BASE+ TXF0)
WRCount      =  uctypes.bytearray_at(DMA_WR_CNT,uctypes.UINT32)
WRCount      = 40
WriteTrigger = uctypes.bytearray_at(DMA_WR_TRG,uctypes.UINT32)


IRQ_QUIET         = 0                        # No interrupt
        TREQ_SEL          = 0              # Wait for PIO_TC0
        CHAIN_TO          = 0                        # Do not chain
        RING_SEL          = 0                        # No ring selected
        RING_SIZE         = 0                        # No wrapping
        INCR_READ         = 1      # <-- Get         # Do not increment read address
        INCR_WRITE        = 0                        # Increment write address
        DATA_SIZE         = 1                        # Data size - 0=8-bit, 1=16-bit, 2=32-bit
        HIGH_PRIORITY     = 0                        # High priority
        ENABLE            = 1                        # Enabled   
        
DMA_WR_RIG_REG=    ((IRQ_QUIET    << 21) | # Initiate the transfer
                   (TREQ_SEL      << 15) |
                   (CHAIN_TO      << 11) |
                   (RING_SEL      << 10) |
                   (RING_SIZE     <<  9) |
                   (INCR_WRITE    <<  5) |
                   (INCR_READ     <<  4) |
                   (DATA_SIZE     <<  2) |
                   (HIGH_PRIORITY <<  1) |
                   (ENABLE        <<  0))
WriteTrigger = DMA_WR_RIG_REG        
        

def initDmaChannel(channel):
    
        
        print(ReadA)
        print(WRCount)
        WriteTrigger = DMA_WR_RIG_REG
        print(DMA_WR_RIG_REG)
        print(WriteTrigger)
        
        
        
@asm_pio(out_init=PIO.OUT_LOW, out_shiftdir=PIO.SHIFT_RIGHT,autopull=True,pull_thresh=16)
def spi_tx():
    # Block with TX deasserted until data available
    pull()
    
    wait(0,gpio,9)
    # Initialise bit counter, assert start bit for 8 cycles
    set(x, 7)         
    # Shift out 8 data bits, 8 execution cycles per bit
    label("bitloop")
    nop()
    out(pins, 1)      [5]
    jmp(x_dec, "bitloop") [5]
    

@asm_pio(sideset_init=PIO.OUT_LOW, out_init=PIO.OUT_LOW, out_shiftdir=PIO.SHIFT_RIGHT,autopull=True,pull_thresh=16)
def inittx():
    
    pull()
    
    wait(0,gpio,9) .side(0)  
    #Initialise bit counter, assert start bit for 8 cycles
    set(x, 7)         
    # Shift out 8 data bits, 8 execution cycles per bit
    label("bitloop")
    nop()             .side(1)
    out(pins, 1)      .side(1)   [5]
    
    jmp(x_dec, "bitloop")  .side(0) [5]
    

#--------------------------Main-Program----------------------------------------#
print("111")
led_onboard.off()
uarts = []

# Now we add 6 SPI_TXs, on pins 10 to 16. Use the same baud rate for all of them.
for i in range(NUM_UARTS):
    
    sm = StateMachine(i, spi_tx, freq=8 * UART_BAUD, out_base=Pin(PIN_BASE + i))
    sm.active(1)
    uarts.append(sm)


st = StateMachine(6, inittx, freq=8 * UART_BAUD, sideset_base=Pin(6), out_base=Pin(17))  
st.active(1)
h1="hello"
print(uarts)
while(1):
    print("\nBeginn Übertragung")
    Trigger.on()
    led_onboard.on()
    sleep(2)
    #dmaChannel0 = DmaTransferChannel(0,uctypes.addressof(picture_1),(PIO0_BASE+TXF0),20,devs.DREQ_PIO0_TX0)
    initDmaChannel(0)
    Trigger.off()
    
    
    sleep(1)
    print(ReadAD)

    print('WRCount ',WRCount)
    print(WriteTrigger)
    sleep(3)
  
        
    print("Fertig Übertragung")
    led_onboard.off()
Last edited by jimmo on Mon Jul 04, 2022 12:31 am, edited 1 time in total.
Reason: Add [code] formatting

tepalia02
Posts: 99
Joined: Mon Mar 21, 2022 5:13 am

Re: dMA +Pio in Pico Board

Post by tepalia02 » Fri Jul 15, 2022 11:30 am

I request you to check the values of TXFn and RXFn. Earlier from other threads, I noticed that the problem existed in these values.

Post Reply