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

Playing does not start reliably #14

Closed
elagil opened this issue Mar 14, 2023 · 8 comments
Closed

Playing does not start reliably #14

elagil opened this issue Mar 14, 2023 · 8 comments

Comments

@elagil
Copy link

elagil commented Mar 14, 2023

Hello,

firstly, thanks a lot for your project. It fixes lots of issues with the ST-provided reference implementation.

I ported the functionality of your code into a fresh CubeMX project and got it playing correctly - the SOF mechanism works great.
However, playing does not start reliably, after stopping previously.

I noticed that - when that happens - I run into the USBD_AUDIO_IsoOutIncomplete() callback. Then, USBD_AUDIO_DataOut() is never reached again.

My assumption is that when hitting USBD_AUDIO_IsoOutIncomplete(), a previous receive failed. So, I assume that I need to USBD_LL_PrepareReceive() again, so that reception can restart successfully.

My solution looks as follows:

static uint8_t USBD_AUDIO_IsoOutIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum)
{
  UNUSED(epnum);

  USBD_AUDIO_HandleTypeDef *haudio;
  haudio = (USBD_AUDIO_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
  
  // Flush, just to be safe.
  USBD_LL_FlushEP(pdev, AUDIO_OUT_EP);

  // Prepare Out endpoint to receive first/next audio packet
  (void)USBD_LL_PrepareReceive(pdev, AUDIOOutEpAdd,
                                &haudio->buffer[haudio->wr_ptr],
                                AUDIO_OUT_PACKET);

  return (uint8_t)USBD_OK;
}

Have you encountered similar issues? The above fixes it for me. I never have problems restarting audio playback.

@har-in-air
Copy link
Owner

har-in-air commented Mar 15, 2023 via email

@elagil
Copy link
Author

elagil commented Mar 15, 2023

Are you saying you used CubeMX to install the required libraries as well ?

Yes, that's right! I only edited the minimum amount of files for enabling audio playback. In fact, I only had to add the usbd_audio module and kept the rest of the generated files for a USB Audio device. Also, it's still a Makefile project and does not differ too much in folder structure from your project. It is quite close to what CubeMX generates today.

However, I currently have a reduced feature set, because I don't need the extended functionality (only 16 bit/48 kHz, no volume control), as my DSP/amplifiers run at a fixed 48 kHz. I will create and share a template project, when I am finished.

@har-in-air
Copy link
Owner

har-in-air commented Mar 15, 2023 via email

@elagil
Copy link
Author

elagil commented Mar 15, 2023

Yes, I use Windows 11. Could be related to it, since this is essentially a fix for a host issue.

@har-in-air
Copy link
Owner

Added suggested fix

@elagil
Copy link
Author

elagil commented Mar 27, 2023

@har-in-air After two weeks of struggle, I still failed to get the current ST driver to send out my feedback value to the PC. It might be broken, as forum posts suggest.

I switched to the amazing ChibiOS HAL and RTOS, and implemented the functionality on that basis.
Find it here: https://github.com/elagil/usb-i2s-bridge

Documentation and functionality are not completely finished, but usable.

@har-in-air
Copy link
Owner

I was toying with the idea of migrating the project to an STM32CubeIDE project using the latest HAL libraries, and am now glad I stayed with a working snapshot of the library sources at the time.

@elagil
Copy link
Author

elagil commented Mar 28, 2023

I think that was a wise choice! ST also no longer includes any audio demo projects that I could find - so I assume that they never test for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants