Run Speaker With USB 2.0 Stack

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Run Speaker With USB 2.0 Stack

7,567 次查看
aniketmarkande
Contributor III

Hi,

I am working on SDK2.0 USB stack forK22 series micro-controllers.

My aim is to read .mp3 files from mass storage device and play it on speakers, so want the information.

I know that audio files are sent over Isochronous transfer type and i am using USB_HostAudioStreamSend() function send audio data. So the question is do i have to create timer of 125us and call USB_HostAudioStreamSend() function again to send complete data or callback function is called after 125us?

if i am missing something please let me know. Just want to know how implement in my code.

Regards

标签 (2)
标记 (1)
49 回复数

3,949 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi,

I'm also think that the D+/D- signal is strange. What test board do you use, NXP's TWR/FRDM board or you own board?

Regards,

jing

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hi Jing Pan,

I am using custom board and D+ and D- signals are strange, that's analyzer problem.

Please see the post later one ( Jan 24, 2018 7:03 AM), where i have explained the whats happening when playing sound and can you clarify the same?

Regards,

Aniket

0 项奖励
回复

3,949 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi Aniket,

It seems that you have 2 device. You read audio data from MSD device and send to audio device. I think it is ok. Ping-pong buffer is a good idea. Can you find any different on usb bus between reading full file and 1152 bytes?

Regards,

Jing

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hi Jing Pan,

"Can you find any different on usb bus between reading full file and 1152 bytes?" I did not know exactly what you mean?

I see that when i read from file when playing sound, SOF goes missing for like 8 ms or 10ms(not fixed). So my questions are:

1. is it possible to read from file when playing sound?

2. Why SOFs are missed when i am doing f_read() while playing sound? thats something strange. Have you observed this any time?

Regards,

Aniket

0 项奖励
回复

3,949 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi, Aniket
As we know, K22 USB module sends SOF automaticly. So I think this must be software reason. You read 1152 byte at a time. After you send this command, the USB mass storage device will send so much bytes continously. Since USB spec defined max block transmission size is 64 bytes (Full speed), 1152 bytes may be split into many continous piece. I guess the bus is fully occupied during this time, K22 has no chance to send SOF. USB full speed is 12Mbps, 1152 bytes need around 8ms to send. This is coicide to the phenomenon you find.
I think you can try to split your request into 128 byte. This may help K22 to send SOF on time.

Regards,

Jing

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hi Jing Pan,

I ran the code by just connecting hub to the host and no device, but then also SOF was missing. (Please check image)

i see SE0 and SE1 state periodically. What might me the cause?

I tried by reading 128bytes as you said, but still sound was unclear since SOF missing. 

Regards,

Aniket

0 项奖励
回复

3,949 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi aniket,

What kind of develop board do you use, customer board or NXP Tower board?

Regards,

Jing

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hi Jing Pan,

Its a custom board. It was ground issue that's why analyzer was showing incorrect data. Now i see that no SOFs are missing. :smileyhappy:

As i explained my logic earlier to play sound(ping pong logic), USB stack is not behaving the same way. When i am playing sound and trying to read from file, it does not happen.

It plays the sound from buffer completely and then only reads the file :smileysad:. Any solution for that?

Regards,

Aniket

0 项奖励
回复

3,949 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi Aniket,

It sounds like when playing sound, USB stack can not read MSD?

Regards,

Jing

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hi Jing pan,

Exactly. I checked the data on analyzer, stack will either play sound or read file from MSD.

Any solution for that?

Regards,

Aniket

0 项奖励
回复

3,949 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi Aniket,

No, I can find similar case. Would you mind to send me your code?

Regards,

Jing

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hi Jing Pan,

I am still waiting for some answers since I am on tight deadline now.

Just want to know how I can send over isochoronous endpoint and receive over bulk endpoint between SOFs.(I have added diagram on community question for reference, what I actually expecting)

Awaiting your reply.

Regards,

Aniket Markande

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hi Jing Pan,

What i want to achieve is as follows to run speaker

pastedImage_1.png

But whats happening is

pastedImage_2.png

Please guide me how i can achieve the 1st image scenario using USB stack, so that full USB bandwidth is utilized.

Thank you.

Regards,

Aniket

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hello,

Please reply ASAP

thank you

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hi Jing Pan,

Sorry, I cant share code.I hope you understand.

Please let me know if you find any similar case.

But i have shared audio_speaker.c in one of the above comments. Please have a look (i am reading file in main.c which i have not shared, sorry again).

Giving snippet of functionality in main.c

while(1)

{

       USB_HostKhciTaskFunction(g_HostHandle);
       USB_AudioTask(NULL);
       USB_HostMsdTask(&g_MsdFatfsInstance);
       USB_HostMsdTask(&g_MsdFatfsInstance_1);

        if( ((false != stat_bBuff_1_Empty) || (false != stat_bBuff_2_Empty))
                                && (false != bSendAudio))
         {
                ReadAudioFile();
          }

}

Regards,

Aniket

0 项奖励
回复

3,949 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi,

It seems that this the clock asynchronous problem. There is not much good way to deal with this problem. Please review the link https://community.nxp.com/thread/379414?commentID=607907#comment-607907. There is much discuss in it and it's link page.

When you excute case: kRunAudioSetCurSamplingFreq, there is an item you must take care: sync type. This is the information of what the synchronous type of the usb speaker. Then base on this value, you can adjust your feed strategy. Detail please find in the link.

Regards

Jing

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hi,

DAC chip PCM2706C uses Adaptive sync mode and my feed strategy is that i am sending 64 bytes every 1ms since my wav file is 32khz sampled with 16 bit PCM encoded data.

For 1ms i am using USB interrupt only.

Anything wrong with this strategy?

Thanks & Regards,

Aniket

0 项奖励
回复

3,949 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi,

Adaptive mode is: Recover clock based on data rate and adjust the clock just as synchronous method. This work should be done by usb device, not host. You may not get any feedback from device.

I'm not familiar with PCM3706. But since K65 works as a host, PCM2706 should try to fit your speed. If you config it properly, the sound should be ok. Have post your question to TI?

Regards

Jing

0 项奖励
回复

3,949 次查看
aniketmarkande
Contributor III

Hi,

Also is it correct to use USB interrupt for 1ms reference?

Regards,

Aniket

0 项奖励
回复

3,949 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi,

I'm not sure. Can PCM3706 buffer 64 bytes at a time?

Regards,

Jing

0 项奖励
回复