I just tried setting the alignment to 2048 and now it works exactly as expected! Thank you so much!It doesn't just need to be aligned to 64 bits - it needs to be aligned to the entire buffer size if you are using ring mode, so aligned(2048) here since the buffer is 1024 2-byte samples.the one saying to align the capture buffer to 64 bits, but while that solution prevents hardfaulting, it doesn't seem to solve the issue of DMA getting stuck.
To understand why: ring mode just keeps the high order bits of the address constant, and wraps the low order bits from 000 to fff (number of bits depending on the RING_SIZE). So the start address of the buffer has to have all the low order bits zero.
If you don't like that limitation, it's not hard to avoid ring mode and use two DMA channels - the first one is set up to run the whole buffer once, and on completion chains to the second channel which simply writes the starting address back into the WRITE_ADDR_TRIG of the first channel which starts it over again (DON'T set the chain bit on this second channel - use chaining or trigger registers, never both at once). This lets you have the buffer anywhere you like, and also avoids the max 32Kbyte limitation of ring mode.
It's not actually much disadvantage using two channels, at least on RP2040 where there's no infinite transfer count and so you probably need a second channel to keep it running, or else the complication of taking an interrupt after 0xffffffff transfers. RP2350 does have the infinite count support, but the alignment issue is still there - so in general I regard ring mode as most useful on fairly small buffers and use two channels for larger ones.
I must admit, I feel a bit dumb to not have realized that the alignment had to do with buffer size when I consulted the forum, but I was clearly not paying enough attention. I am transitioning my projects from STM32 to the Pico and I don't remember having to align my buffers (if I had to guess, I'd say the HAL handles it? But I'm not sure honestly). Not complaining at all, though! I just really should have read the datasheet more in depth
I also wanted to thank you for the in-depth explanation about how DMA address wrapping works, and the alternative to a ring buffer.
Once again, thank you very much!
Statistics: Posted by NizyBoxer03 — Sat Apr 26, 2025 11:09 pm