Change to USB Serial to not require DTR set by the host

Post Reply
User avatar
RogerClark
Posts: 7482
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Change to USB Serial to not require DTR set by the host

Post by RogerClark » Sun Jul 16, 2017 1:41 am

It seems that our USB Serial functionality differs from the normal e.g AVR and SAM functionality in that we do not send data unless the USB connection DTR is set

I made a change for this in the ZUMspot branch to support the Ham radio community, where it does not check for DTR

See

https://github.com/rogerclarkmelbourne/ ... re/ZUMspot


If our functionality differs from the norm, perhaps I should merge this change into the Master branch

Edit.

I've tested this, including leaving the Arduino terminal window open and I don't see any negative effects of the is change.

So I think I will update the master repo unless anyone has any objections

User avatar
RogerClark
Posts: 7482
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Change to USB Serial to not require DTR set by the host

Post by RogerClark » Sun Jul 16, 2017 4:04 am

Actually, there does seem to be a side effect of this change

If I close the terminal window and wait a while, by sketch seem to stop while waiting for the USB to send the data to the PC (as there multiple Serial.println () lines in the graphic test)

So perhaps we can't do this after all. Well, not unless we prevent it from stopping in Serial.print etc if the host its not available

I'll do some more testing to confirm this phenomenon

stevestrong
Posts: 1829
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Change to USB Serial to not require DTR set by the host

Post by stevestrong » Sun Jul 16, 2017 8:02 am

RogerClark wrote:
Sun Jul 16, 2017 4:04 am
If I close the terminal window and wait a while, by sketch seem to stop while waiting for the USB to send the data to the PC (as there multiple Serial.println () lines in the graphic test)
Same issue currently for F4 too: https://github.com/rogerclarkmelbourne/ ... issues/306
The problem is that I don't know hot to fix it because the new USB lib (SPL from ST) has no function "usb_is_connected()"

User avatar
RogerClark
Posts: 7482
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Change to USB Serial to not require DTR set by the host

Post by RogerClark » Sun Jul 16, 2017 10:23 am

The F1 only has this issue if I remove the check for DTR

I looked at why this may be happening, and it looks like its because the TX buffer gets filled and returns zero

https://github.com/rogerclarkmelbourne/ ... acm.c#L428

So it stays in this while loop

https://github.com/rogerclarkmelbourne/ ... #L127-L129

I don't know the best fix for this. I presume that the best way to handle this, is for the oldest item in the buffer to be removed and just keep the newest, ready for when the USB Host is ready for the data.

We can probably do this my modifying the ring buffers in usb_cdcacm.c

Post Reply