Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
ChrisM
Level 1
Level 1
First like given First reply posted First question asked

I'm using the Position2Go development board with the XMC4700 and trying to stream ADC data to a PC over USB without requiring the PC to poll for individual frames. The demo firmware responds to messages received over USB to send one frame of data at a time. I understand that the board is no longer supported, but I do think it's a fundamental question about USB on XMC.

I'm trying to do this in an attempt to avoid any timing jitter or missed frames, etc caused by waiting for messages from the PC.

I attempted to do this by populating various incarnations of code like this code in the demo firmware's acq_completed_cb() in main.c. The if statement is simply an attempt to not attempt to transmit before the link is established.

uint16_t control_h2d = USBD_VCOM_cdc_interface.State.ControlLineStates.HostToDevice;
if (control_h2d & CDC_CONTROL_LINE_OUT_DTR) {
    protocol_send_header(1, 5);
    protocol_send_payload((uint8_t*)"Hello", 5);
    protocol_send_tail();
}

protocol_send* call Endpoint_Write_Stream_LE in usbd_endpoint_stream_xmc4000.c and end up getting trapped in an infinite loop (protocol_send_header returns, but then protocol_send_payload hangs) within:

if (ep->InInUse) {
    continue;
}

Somehow this doesn't seem to happen when the firmware is being used normally in response to messages from the host, but I'm kindof stuck as to what is causing this problem. I've found 3 other people on this forum reporting similar confusion about looping waiting for ep->InInUse with no solutions. I see where it should get cleared in usbd.c in response to XMC_USBD_EP_EVENT_IN, but I'm lost as to what is different about my code that is preventing this event from firing, but it's clear I'm misunderstanding how it should work.

I appreciate any advice, thanks!

 

0 Likes
1 Solution
sujatapatil
Moderator
Moderator
Moderator
10 likes received 100 sign-ins 25 solutions authored

Hi Chris,

USB is host initiated protocol so until request is sent from host,  communication channel/link will not be established . Link will be established when host request IN/OUT transfer and after completion of that request , link will be closed  between host and slave .  Since you are trying to send packet on closed pipe you are stuck.

The correct approach would be for this ,

use interrupt transfer and interval  for this interrupt transfer can be configured  considering ADC conversion time so that you will  not miss any data.  With this approach host will send IN packet at predetermined rate automatically  ( ADC conversion time) .

Hope i am able to answer and clarify issue.

Thanks

Sujata

l

 

View solution in original post

0 Likes
3 Replies
sujatapatil
Moderator
Moderator
Moderator
10 likes received 100 sign-ins 25 solutions authored

Hi Chris,

USB is host initiated protocol so until request is sent from host,  communication channel/link will not be established . Link will be established when host request IN/OUT transfer and after completion of that request , link will be closed  between host and slave .  Since you are trying to send packet on closed pipe you are stuck.

The correct approach would be for this ,

use interrupt transfer and interval  for this interrupt transfer can be configured  considering ADC conversion time so that you will  not miss any data.  With this approach host will send IN packet at predetermined rate automatically  ( ADC conversion time) .

Hope i am able to answer and clarify issue.

Thanks

Sujata

l

 

0 Likes

Sujata,

Thank you very much for your advice.

I believe I have been able to solve my problem but don't 100% understand what is happening due to my lack of familiarity with interrupts on this hardware.

I believe the problem is acq_completed_cb() is called from an interrupt  and protocol_send_header() either doesn't transmit or the interrupt never fires due to priority or other interrupt-related reasons.

I've solved my problem by performing my computation in acq_completed_cb and setting a flag that is detected by the run loop to actually transmit the data. Seems to work very well.

0 Likes
sujatapatil
Moderator
Moderator
Moderator
10 likes received 100 sign-ins 25 solutions authored

Hi Chris,

Great to hear that  your problem is solved . 

I am closing this case here. Please let us know f you need further assistance.

Thanks

Sujata