No Usb audio output when there is no input I2S, AEC application

Sub forums for various specialist XMOS applications. e.g. USB audio, motor control and robotics.
New User
Posts: 2
Joined: Wed Jan 08, 2020 3:19 pm

No Usb audio output when there is no input I2S, AEC application

Postby haceneusr » Fri Jan 10, 2020 10:28 am

Hi Xmos

I am using the XMOS vf3500 as part of our automatic speech recognition design configured as shown below.
<Tile Number="1" Reference="tile[1]">
<!-- USB -->
<Port Location="XS1_PORT_1H" Name="PORT_USB_TX_READYIN"/>
<Port Location="XS1_PORT_1J" Name="PORT_USB_CLK"/>
<Port Location="XS1_PORT_1K" Name="PORT_USB_TX_READYOUT"/>
<Port Location="XS1_PORT_1I" Name="PORT_USB_RX_READY"/>
<Port Location="XS1_PORT_1E" Name="PORT_USB_FLAG0"/>
<Port Location="XS1_PORT_1F" Name="PORT_USB_FLAG1"/>
<Port Location="XS1_PORT_1G" Name="PORT_USB_FLAG2"/>
<Port Location="XS1_PORT_8A" Name="PORT_USB_TXD"/>
<Port Location="XS1_PORT_8B" Name="PORT_USB_RXD"/>
<Port Location="XS1_PORT_16B" Name="PORT_MCLK_COUNT"/>
<Port Location="XS1_PORT_1C" Name="PORT_MCLK_IN2"/>
<Node Id="2" InPackageId="2" Type="XS2-L16A-512" SystemFrequency="500MHz" OscillatorSrc="1">
<Source Location="LINK" BootMode="4"/>
<Tile Number="0" Reference="tile[2]">
<!-- Audio Ports -->
<Port Location="XS1_PORT_1G" Name="PORT_MCLK_IN"/>
<Port Location="XS1_PORT_1L" Name="PORT_I2S_LRCLK"/>
<Port Location="XS1_PORT_1M" Name="PORT_I2S_BCLK"/>
<Port Location="XS1_PORT_1K" Name="PORT_I2S_ADC0"/>
<!-- Mics -->
<Port Location="XS1_PORT_1H" Name="PORT_PDM_CLK"/>
<Port Location="XS1_PORT_8B" Name="PORT_PDM_DATA"/>
<Port Location="XS1_PORT_1G" Name="PORT_PDM_MCLK"/>

we use the I2S as an input of the playback coming from the audio card and also playing on the speaker as an AEC reference.
When there is no audio in the I2S input (no playback on the speaker), I turn down the I2S (BCLK/LRCLK/DATA) and I keep the I2S MCLK (external clock) (CODEC_MASTER=1) and in this case we have no output data via usb.

How we can keep the chip running properly if there is no I2S (BCLK/LRCLK/DATA) ?
User avatar
XCore Legend
Posts: 1889
Joined: Thu Jun 10, 2010 11:43 am

Postby mon2 » Fri Jan 10, 2020 12:44 pm

Hi. Not an audio developer but believe there is confusion between the cpu master clock and i2s clock.

The cpu clock is always required to be running else cpu will lock due to this missing mandatory clock.

The i2s clock is generated by the i2s bus master and is used to clock in audio samples from an i2s slave. The i2s clock can be halted as required but CPU clock must keep running.

Believe that XMOS up creates the i2s master but check their IP for this detail.

Hope this is clear but post back if I have misunderstood your concern.
Active Member
Posts: 50
Joined: Mon Jan 08, 2018 4:14 pm

Postby fabriceo » Sat Jan 11, 2020 8:44 am

in the standard USB Audio application, the I2S mclk is the heart beat of the Audio task which is in charge of :
- I2S bit banging (ADC in/DAC out) .
- transfer requests for sending-receiving data to the usb_buffer task via the Decouple tasks (interrupt driven).
- transfer to spdif/adat tasks if exist.
- listening specific commands (originated by Endpoint0) to switch modes, change frequency divider or to start DFU handler.
So if there is no mclk then this is not running well. Hopefully the design of the usb_buffer and decouple task can accommodate this to some extend. But the best is to avoid this problem, when you stop the mclk, you can change the audio clock block setting so that it is sourced by the internal 100mhz clock and divided by N with following code inside Audio.xc:

Code: Select all

if (selfClocking) {
    /* Clock master clock-block from clock block 1 - ref 100mhz div 4 = 25mhz */
    configure_clock_ref(clk_audio_mclk, 2);  
} else {
    /* Clock master clock-block from master-clock port */
    configure_clock_src(clk_audio_mclk, p_mclk_in);
I have tried this with success.

But the mclk is also connected to "PORT_MCLK_IN2" and this is required for the calculation of the Feedback clock which is needed by the host usb driver to push/pull the usb packet (8khz) with the right quantity of data in each packet.
and then comes another issue.

you have to modify the calculation of the Feedback clock endpoint in the usb_buffer , in the "SOF" select case, and manage to return a default value to the host depending on the current frequency when you have no mclk on PORT_MCLK_IN2. you can let the decouple and audio task run at say 25mhz by the internal clocking and force a feedback endpoint value related to 44k or 48k without problems.
I ve done this type of things to integrate an spdif receiver locking at its own frequency so I can confirm this is a working option.
here is the piece of code to calculate the value of the feedback endpoint based on the current sampling frequency:

Code: Select all

#define fb_factor_HS (137438954)  // 2^24 * 8,192 multiplying the sampleFreq by 256 to get the 0xAABBBBxxxx format
#define fb_factor_FS (17179869)   // 2^24 * 8,192 / 8
      unsigned h, l;
      if  (usbSpeed == XUD_SPEED_HS)
      l = fb_factor_HS;
      else l = fb_factor_FS;
      {h, l} = mac(sampleFreq<<8, l, 0, 0);  // this calculate the 16:16:32 value for Feedback endpoint
      SET_SHARED_GLOBAL(fb_clocks, h );
hope this helps
New User
Posts: 2
Joined: Wed Jan 08, 2020 3:19 pm

Postby haceneusr » Mon Jan 13, 2020 2:48 pm

Hello fabriceo,

Thank you for your replay, and for the solution you suggested.

I want to clarify something about my use case. The I2S mclk is always ON, even if there is no data transfer (I mean the (BCLK/LRCLK/DATA) are off) to the XMOS.

The solution you suggested is in the case where there is no continuous I2S mclk.

In my opinion there is an other dependency to the I2S (BCLK/LRCLK/DATA) , which make the XMOS dosen't process the MICs data.

So I am looking to find a solution where the XMOS runs properly even if there is no I2S ref data (no I2S (BCLK/LRCLK/DATA)), and in this case the xmos will provides me the MICs data to the host without applying the AEC algorithm.

The config I use is similar to the ( vfst_base_usb_i2s_ref.xn) application example where the audio card is the Master ( CODEC_MASTER=1) used to deliver the AEC ref data to the XMOS as a slave and the processed data is delivered to the host via USB.

Best regards.

Who is online

Users browsing this forum: No registered users and 0 guests