Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7512

General • Re: Trouble with DMA timings <> PIO <> PSRAM latency

$
0
0
It's probably a better idea to have 2 small-ish buffers in SRAM and write to them first. With DMA chaining this is fairly simple to do on the RP2350.
I've never done that, you mean something like:

Code:

bool double_transfer_in(rp2pio_statemachine_obj_t *self, uint8_t *psram_buff, size_t buff_size, uint8_t *sub_buffer, size_t sub_buffer_size) {    const uint8_t in_stride_in_bytes = 4;    const size_t chunk_size = buff_size / in_stride_in_bytes;    const size_t sub_chunk_size = sub_buffer_size / in_stride_in_bytes;    const volatile uint8_t *rx_source = (const volatile uint8_t *) &self->pio->rxf[self->state_machine];    uint8_t *buffers[2] = {        sub_buffer,        sub_buffer + sub_buffer_size    };    int chan_rx = dma_claim_unused_channel(true);    if (chan_rx < 0) {        debug("DMA allocation failed\n");        return false;    }    dma_channel_config c = dma_channel_get_default_config(chan_rx);    channel_config_set_transfer_data_size(&c, _stride_to_dma_size(in_stride_in_bytes));    channel_config_set_dreq(&c, self->rx_dreq);    channel_config_set_bswap(&c, false);    channel_config_set_read_increment(&c, false);    channel_config_set_write_increment(&c, true);    int current_buf = 0;    size_t chunks_written = 0;    bool first = true;    while ((chunks_written * sub_buffer_size) < buff_size) {        dma_channel_configure(chan_rx, &c,            buffers[current_buf],            rx_source,            sub_chunk_size,            true);        if (!first) {            memcpy(psram_buff + (chunks_written - 1) * sub_buffer_size, buffers[1 - current_buf], sub_buffer_size);        } else {            first = false;        }        dma_channel_wait_for_finish_blocking(chan_rx);        current_buf ^= 1;        ++chunks_written;    }    memcpy(psram_buff + (chunks_written - 1) * sub_buffer_size, buffers[1 - current_buf], sub_buffer_size);    dma_channel_unclaim(chan_rx);    return true;}
I tried various sub-buffer SRAM sizes and adjusting to the maximum seem to be the only way to keep up with the highest setting I can set on the camera (JPG/UXGA, ~700ko). So now I need to understand why I can't set higher resolutions to the camera (dma never responds) but that is another story probably linked to pclk/mclk freq and obscure OV5640 registers. Thank you so much !

Statistics: Posted by fabY — Thu Jun 05, 2025 9:01 am



Viewing all articles
Browse latest Browse all 7512

Trending Articles