2013-02-13 08:00 AM
I am interested in techniques for synchronizing the STMF4 I2S clock with an incoming audio stream on the USB. The clock on the source and the clock on the STM32 board will always be slightly out of sync causing either its DMA to the codec to be ahead or behind the stream. Dropping / stuffing samples or re-sampling the stream are not preferred solutions.
Thanks, Tony #stm32f4-i2s #streaming2015-11-06 10:32 PM
And the remain part of quiz.
static uint8_t usbd_audio_IN_Incplt (void *pdev){ if ((SOF_num>((1<<SOF_RATE)-1))&&flag) {flag=0; DCD_EP_Flush(pdev,AUDIO_IN_EP); }; return USBD_OK;}2015-11-09 09:27 AM
I've been working on the Isoc incomplete issue... And got pretty good idea, which solved this problem. At the isoc incomplete interrupt, I mark the current pid (last bit of frame number). At the SOF interrupt, I test if current frame has the same parity, and when it's true, transmit the feedback endpoint data. This way is 100% working.
static uint8_t usbd_audio_IN_Incplt (void *pdev){ //This ISR is executed every time when IN token received with ''wrong'' PID. It's necessary //to flush IN EP (feedback EP), get parity value from DSTS, and store this info for SOF handler. //SOF handler should skip one frame with ''wrong'' PID and attempt a new transfer a frame later. USB_OTG_DSTS_TypeDef FS_DSTS; FS_DSTS.d32 = USB_OTG_READ_REG32(&(((USB_OTG_CORE_HANDLE*)pdev)->regs.DREGS->DSTS)); dpid=(FS_DSTS.b.soffn)&0x1; if (flag) {flag=0; DCD_EP_Flush(pdev,AUDIO_IN_EP); STM_EVAL_LEDToggle(LED4); }; return USBD_OK;} static uint8_t usbd_audio_SOF (void *pdev){ uint8_t res;static uint16_t n;USB_OTG_DSTS_TypeDef FS_DSTS; /* Check if there are available data in stream buffer. In this function, a single variable (PlayFlag) is used to avoid software delays. The play operation must be executed as soon as possible after the SOF detection. */if (usbd_audio_AltSet==1){ if (PlayFlag) { gap=(IsocOutWrPtr-IsocOutRdPtr); tmpxx=(DMA1_Stream7->NDTR); if (gap<0) gap+=(AUDIO_OUT_PACKET * OUT_PACKET_NUM); dgap=gap+tmpxx; }; accum+=(TIM2->CCR1); SOF_num++; if (SOF_num==(1<<SOF_RATE)) {if (SOF_RATE>6) {feedback_data+=accum>>(SOF_RATE-6);} else {feedback_data+=accum<<(6-SOF_RATE);}; feedback_data>>=1; SOF_num=0; accum=0; } if ((!flag)) { FS_DSTS.d32 = USB_OTG_READ_REG32(&(((USB_OTG_CORE_HANDLE*)pdev)->regs.DREGS->DSTS)); if (((FS_DSTS.b.soffn)&0x1) == dpid) { DCD_EP_Tx (pdev, AUDIO_IN_EP, (uint8_t *) &feedback_data, 3); flag=1; }; }; }return USBD_OK;}The code in IN handler is the same. This scheme detects right PID and always sends feedback data.2016-08-01 06:00 AM
First of all, I would like to thanks Roman to have shared all the above code.
I'm trying, for a DIY audio project, to set-up an Async USB interface from PC to stm32, with feedback endpoint. Would there be some a ''complete example'' of such thing somewhere ? I have only little experience of USB. I succeeded to get the CubeMX audio standalone application, but I definitly need the feedback EP definition and associated code. Best regards, JMF2016-08-31 02:29 AM
Hi,
Did you ever find a complete example including Romans code? I would be nice to know which file version Roman has modified.The usbd_audio_core.c version I have is this:file usbd_audio_core.cauthor MCD Application Teamversion V1.1.0date 19-March-2012/KimFrom: fourneron.jean_marcPosted: Monday, August 01, 2016 3:00 PMSubject: Audio streaming clock sync
First of all, I would like to thanks Roman to have shared all the above code.
I'm trying, for a DIY audio project, to set-up an Async USB interface from PC to stm32, with feedback endpoint. Would there be some a ''complete example'' of such thing somewhere ?I have only little experience of USB. I succeeded to get the CubeMX audio standalone application, but I definitly need the feedback EP definition and associated code.Best regards,JMF