cancel
Showing results for 
Search instead for 
Did you mean: 

USB Low-Full-High Speed Peripherals

Anonymous
Not applicable

Hi All:

I am working on a USB audio device(UAC 2.0) with multichannel input MIC and stereo output speaker,the format 48KHz,16bit.

I have write a project,but it doesn't work.

Do anyone have a similar example code?

Attached is my firmware, can anyone have some suggestion?

Thanks a lot.

Update2018.08.09

1.Two Clock uint descriptors are

;; Clock Source Descriptor

db     0x08                            ;; bLength                          

db     0x24                            ;; bDescriptorType           CS_Interface

db     0x0A                                     ;; bDescriptorSubType             Clock Source

db     0x10                            ;; bClockID  another ID is 0x11

db     0x05                            ;; bmAttributes                           Internal Fixed Clock Locked to SOF 8000Hz

db     0x03                            ;; bmControls

db     0x00                            ;; bAssociatedTerminal

db     0x00                            ;; iClockSource

The format descriptor is

;; FORMAT_TYPE_I descriptor   

db     06H                    ;; bLength

db     DSCR_AS_INTRFC             ;; bDescriptorType CS_INTERFACE

db     02H                    ;; bDescriptorSubType   FORMAT_TYPE

db     01H                    ;; bFormatType         FORMAT_TYPE_I

db     04H                    ;; bSubSlotSize

db     18H                    ;; bBitResolution 24bit

SOF interrupt service function looping the input(EP2)-output(EP6) is 

void ISR_Sof(void) interrupt 0

{

  int i;

  int count;

  IOA|=0x80; //output 1 on PA.7

  SYNCDELAY;

// Transfer EP6-OUT buffer to EP2-IN buffer when there is a packet in one of the EP6-OUT buffers, AND

// there is an available EP2-IN buffer. The FIFO status flags update after full packets are transferred.

// Therefore EP2-OUT "Not Empty" means a packet is available, and "EP6-IN "Not Full" means there is an

// available buffer. Using the flags this way handles any packet size and takes multiple buffering

// into account.

if(!(EP2468STAT & bmEP2EMPTY))           // Is EP2-OUT buffer not empty (has at least one packet)?

{

           if(!(EP2468STAT & bmEP6FULL))      // YES: Is EP6-IN buffer not full (room for at least 1 pkt)?

             {

APTR1H = MSB( &EP2FIFOBUF );

        APTR1L = LSB( &EP2FIFOBUF );

AUTOPTRH2 = MSB( &EP6FIFOBUF );

AUTOPTRL2 = LSB( &EP6FIFOBUF );

        count = (EP2BCH << 😎 + EP2BCL;

        // loop EP2OUT buffer data to EP6IN

        for( i = 0; i < 0x0200; i++ )

        {

            EXTAUTODAT2 = EXTAUTODAT1;      // Autopointers make block transfers easy...

        }

EP6BCH = 0x02;                  // Send the same number of bytes as received

SYNCDELAY; 

EP6BCL = 0x00;        // arm EP6IN

                             SYNCDELAY;                    //

                             EP2BCH = 0x02;    

                             SYNCDELAY;                    //

                             EP2BCL = 0x00;                // arm EP2OUT by writing byte count w/skip.

                             SYNCDELAY;

                      }

  }

//         for( i = 0; i < 192; i++ )

//    {

// EP6FIFOBUF = i+2;

//    }

// EP6BCH = 0x00;

// SYNCDELAY;                    //

//   EP6BCL = 0xC0;

// SYNCDELAY;

  IOA&=0x7F; //output 0 on PA.7

  SYNCDELAY;

EZUSB_IRQ_CLEAR();

   USBIRQ = bmSOF;            // Clear SOF IRQ

}

Under such conditions the device driver works well, but datas on endpoint(EP6) are not narmal, like log.file1.txt over bus hound

2、After I modified the SOF interrupt service function like below

void ISR_Sof(void) interrupt 0

{

  int i;

  int count;

  IOA|=0x80; //output 1 on PA.7

  SYNCDELAY;

// Transfer EP6-OUT buffer to EP2-IN buffer when there is a packet in one of the EP6-OUT buffers, AND

// there is an available EP2-IN buffer. The FIFO status flags update after full packets are transferred.

// Therefore EP2-OUT "Not Empty" means a packet is available, and "EP6-IN "Not Full" means there is an

// available buffer. Using the flags this way handles any packet size and takes multiple buffering

// into account.

//       if(!(EP2468STAT & bmEP2EMPTY))           // Is EP2-OUT buffer not empty (has at least one packet)?

//       {

//                 if(!(EP2468STAT & bmEP6FULL))      // YES: Is EP6-IN buffer not full (room for at least 1 pkt)?

//          {

// APTR1H = MSB( &EP2FIFOBUF );

// APTR1L = LSB( &EP2FIFOBUF );

// AUTOPTRH2 = MSB( &EP6FIFOBUF );

// AUTOPTRL2 = LSB( &EP6FIFOBUF );

// count = (EP2BCH << 😎 + EP2BCL;

//        // loop EP2OUT buffer data to EP6IN

// for( i = 0; i < 0x0200; i++ )

//        {

// EXTAUTODAT2 = EXTAUTODAT1;  // Autopointers make block transfers easy...

//        }

// EP6BCH = 0x02;               // Send the same number of bytes as received

// SYNCDELAY;

// EP6BCL = 0x00;        // arm EP6IN

//                                   SYNCDELAY;                    //

//                                   EP2BCH = 0x02;   

//                                   SYNCDELAY;                    //

//                                   EP2BCL = 0x00;                // arm EP2OUT by writing byte count w/skip.

//                                   SYNCDELAY;

//                            }

//  }

//     

   for( i = 0; i < 192; i++ )

    {

EP6FIFOBUF = i+2;

    }

  EP6BCH = 0x00;

SYNCDELAY;                    //

   EP6BCL = 0xC0;

  SYNCDELAY;

  IOA&=0x7F; //output 0 on PA.7

  SYNCDELAY;

EZUSB_IRQ_CLEAR();

   USBIRQ = bmSOF;            // Clear SOF IRQ

}

I got the logfile2.txt

3、If I modify the Format FORMAT_TYPE_I descriptor:

Before:

;; FORMAT_TYPE_I descriptor    

db     06H                    ;; bLength

db     DSCR_AS_INTRFC             ;; bDescriptorType CS_INTERFACE

db     02H                    ;; bDescriptorSubType   FORMAT_TYPE

db     01H                    ;; bFormatType         FORMAT_TYPE_I

db     04H                    ;; bSubSlotSize

db     18H                    ;; bBitResolution

After:

;; FORMAT_TYPE_I descriptor    

db     06H                    ;; bLength

db     DSCR_AS_INTRFC             ;; bDescriptorType CS_INTERFACE

db     02H                    ;; bDescriptorSubType   FORMAT_TYPE

db     01H                    ;; bFormatType         FORMAT_TYPE_I

db     02H                    ;; bSubSlotSize

db     10H                    ;; bBitResolution

Or if I modify Clock Source Des criptor and sampling rate(48KHz)

Before:

;; Clock Source Des criptor

db     0x08                            ;; bLength                          

db     0x24                            ;; bDescriptorType           CS_Interface

db     0x0A                                     ;; bDescriptorSubType             Clock Source

db     0x11                            ;; bClockID

db     0x05                            ;; bmAttributes                           Internal Fixed Clock Locked to SOF

db     0x03                            ;; bmControls

db     0x00                            ;; bAssociatedTerminal

db     0x00                            ;; iClockSource

After:

;; Clock Source Des criptor

db     0x08                            ;; bLength                          

db     0x24                            ;; bDescriptorType           CS_Interface

db     0x0A                                     ;; bDescriptorSubType             Clock Source

db     0x11                            ;; bClockID

db     0x03                            ;; bmAttributes                           Internal programmable Clock

db     0x07                            ;; bmControls

db     0x00                            ;; bAssociatedTerminal

db     0x00                            ;; iClockSource

The device can’t work , and I got the logfile3.txt, logfile4.txt and shortcuts Modify Format.PNG、Modify Format MIC.PNG.

BRs

Shoukuan

srnt

0 Likes
Reply
1 Solution
Moderator
Moderator

Hello Shoukuan,

By "Multichannel", do you mean different input devices onto FX2LP? If that is the case, the FX2LP FIFO interface has to be connected to both the channels using a common clock. FX2LP will not be aware of the number of channels the data is being inputted from. It acts as a pass through for the data it receives on the FIFO interface.

Best regards,

Srinath S

View solution in original post

0 Likes
Reply
5 Replies
Moderator
Moderator

Hello Shoukuan,

I find that you had referred to FX2LP - UAC Protoype Firmware

Upon looking into your firmware, I understand the following. Please correct me if I am wrong.

- You have tried to implement an USB Speaker and Mic on the same device with an OUT endpoint for speaker and an IN endpoint for mic.

- You have tried

          1. Looping back the data received on the OUT endpoint back to the IN endpoint to be received on the host PC.

          2. Loading a constant value of data onto the EP6FIFOBUF and transfer that data to the host PC.

Please let me know the host application that you are using to demonstrate this behavior. In the second method, the data is pre-loaded into the buffers whereas in the first method, the data needs to be sent by the host PC on the OUT endpoint. Please let me know if you have taken care of this.

Best regards,

Srinath S

0 Likes
Reply
Anonymous
Not applicable

Hi Srinath,

Yes, what you have understood  is right.

1:The host application I am using is "Bus Hound".

2:"In the second method, the data is pre-loaded into the buffers whereas in the first method, the data needs to be sent by the host PC on the OUT endpoint. "

In the second method, I just only want to test the IN endpoint if it sent data to PC host correctly.

The data can be initialized without having to be sent by PC.

BRs

Shoukuan

0 Likes
Reply
Anonymous
Not applicable

Hi Srinath,

What I confuse are the followings.

1.Why can't PC host recognize the format of the device once I modified the sample rate to 48K or modified the PCM format,like the pictures?

2.Why will the IN endpoint sent 0x00 to PC when looping?

BRs

Shoukuan

0 Likes
Reply
Anonymous
Not applicable

Hi Srinath,

I have solved some issues.

What I confuse are the followings.

1.Why can't PC host recognize the format of the device once I modified the sample rate to 48K or modified the PCM format,like the pictures?

After adding the corresponding host request reply, it was resolved.

2.Why will the IN endpoint sent 0x00 to PC when looping?

Because the IN endpoint Maximun packet size is too bigger than the number of bytes to be sent.

But I still have another issue, how to change the device to multiple channels?Do you have a similar case?

Thanks.

BRs

Shoukuan

0 Likes
Reply
Moderator
Moderator

Hello Shoukuan,

By "Multichannel", do you mean different input devices onto FX2LP? If that is the case, the FX2LP FIFO interface has to be connected to both the channels using a common clock. FX2LP will not be aware of the number of channels the data is being inputted from. It acts as a pass through for the data it receives on the FIFO interface.

Best regards,

Srinath S

View solution in original post

0 Likes
Reply