Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide CFG_MEM_FORCE_... options for audio buffer placement via linker script #2974

Open
1 task done
not1337 opened this issue Feb 3, 2025 · 0 comments
Open
1 task done

Comments

@not1337
Copy link

not1337 commented Feb 3, 2025

Related area

Optimum audio buffer placement in RAM

Hardware specification

rp2350

Is your feature request related to a problem?

For rp2350 USE_LINEAR_BUFFER gets defined. This causes IN_SW_BUF_MEM_SECTION and OUT_SW_BUF_MEM_SECTION to be defined to nothing. Thus one can't specify a memory location for audio_ep_in_sw_buf_N as well as audio_ep_out_sw_buf_N.

Even if one could, this would be via a global CFG_TUD_MEM_SECTION which is shared for various allocations. This results in the following problems:

On rp2350 there's no way to do a zerocopy DMA transfer as there is always a CPU based copy between the linear buffer and the fifo buffer. Thus one wants to make the fifo buffer have a size and an address that makes direct DMA between audio interface and fifo possible to prevent further CPU burning. On rp2350 this requires a 2^n sized fifo the address of which must be 2^n aligned. In this case the DMA engine takes care of address wraps and can run in continous fifo to/from device mode.

As a side effect the buffers could be placed in memory with extra bus ports (2x4K scratch and optionally 16K from disabled XIP cache is available) which can give a little extra performance as the CPU (instruction port) is not stalled by DMA transfers.

As it is right now, the only solution is to either use an additional DMA channel for audio rx as well as tx to transfer to/from a proper aligned extra buffer or to burn further CPU with manual copying.

This does cost memory and DMA resources, as well as extra CPU resources to handle the additional DMA channels and may incur a processing speed penalty.

Describe the solution you'd like

It would be best to create different CFG_MEM_FORCE_... options for the various linear and fifo buffers in use and have them fallback to the current CFG_TUD_MEM_SECTION scheme if they're not defined. This way the optimum placement for buffers with respect do DMA and CPU can be selected via linker script.

As an afterthought it would be handy to have an optional CFG_... enabled user defined function that gets called when rx linear buffer is filled with new data from host and another function that gets called when the tx linear buffer is empty.
This way the CPU bound fifo copy could be bypassed through the user functions which typically would invoke DMA. Furthermore this would take load of tinyusb developers as DMA is then user responsibility.

I have checked existing issues, dicussion and documentation

  • I confirm I have checked existing issues, dicussion and documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant