USBUART Question

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

cross mob
Anonymous
Not applicable

The sample code suggests code like this...

   

/* Wait until component is ready to send data to host. */
while (0u == USBUART_CDCIsReady())
{
}

   

Is it possible to get stuck in this loop if there is a problem with the USB connection?

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum!

   

You can get stuck depending on the state of the USBUART.

   

I would suggest you to modify one of the example projects for your need. Right click on the USBUART component (on your topdesign or in component catalog) and select "Find Code Example".

   

 

   

Happy coding

   

Bob

0 Likes
Anonymous
Not applicable

That is the example code for USBFS_UART.  Is there another example project?

   

Can a timer be used as a way to get unstuck?  What is a reasonable duration?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Does the unmodified example project get stuck in USBFS-UART?

   

What changes did you exactly make?

   

Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
Anonymous
Not applicable
        I did not modify the code and it has not gotten stuck, but that while statement looks vulnerable. Your initial response makes me more worried.   
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Sorry, this is a misunderstanding.

   

The while-loop you questioned in your first post will indeed wait until the connection is OK. In a real project you may of course try it only once and ask to connect when failed. But how to "ask" when using a prototyping kit? (Light an LED, try in a while until OK, then switch off the LED.) You cannot proceed with the project when the USB connection is not established.

   

 

   

Bob

0 Likes