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

General • Re: Trying to get USB audio working with I2S on RP2040 with PIO

$
0
0
I have the TinyUSB configured for 32bit 48KHz and I have made some changes to the PIO code because my BCK and LRCK pins arent adjascent(cant use side set 2).

Code:

frameL:             ;        ||    set pins, 0       side 0b0    set x, 30         side 0b1    pull noblock      side 0b0 ; One clock after edge change with no datadataL:    out pins, 1       side 0b1    jmp x-- dataL     side 0b0
This won't work, you can't have 33 BLCK cycles for 32 data bits. One fix would be to just remove the "pull noblock" instruction (and adjusting the sidesets again of course) and enabling autopull. That would change the behaviour of the program if the FIFO ever runs out of data - the SM would block and not send out any BLCK anymore at all which is probably bad but it's generally possible to ensure this never happens at the slow data rates of audio. The original program's behaviour in that case wasn't great either, "pull noblock" uses the value of the X register if there's no data in the FIFO, so 30. The smarter way would've been to use Y as the loop counter and preload X with some sensible default like 0 for silence.
Alternatively you could delays and run the SM at 4x BCK, so the 3 instruction starting with pull would look like "pull noblock side 0b1 [1]" and take 2 cycles instead of 1.

Regarding DMA, it's really not that complicated to setup once all the individual pieces are working. Start with just feeding the PIO with static, hardcoded data from a buffer in SRAM. There's some example code for that in the official repo: https://github.com/raspberrypi/pico-exa ... hannel_irq
Once that works you can switch to double buffering, with 2 buffers containing different data so it's audible. And then switch to the data from USB.

Statistics: Posted by Tharre — Sat Jun 14, 2025 12:03 am



Viewing all articles
Browse latest Browse all 8041

Trending Articles