<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: SerialUSB flow control</title>
		<link>http://forums.leaflabs.com/topic.php?id=13641</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:20:43 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=13641" rel="self" type="application/rss+xml" />

		<item>
			<title>ala42 on "SerialUSB flow control"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13641#post-29456</link>
			<pubDate>Sat, 07 Sep 2013 09:27:08 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">29456@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;&#38;gt; The nice (int) cast is to avoid the millis overflow issue every fifty days.&#60;br /&#62;
No, it makes no change at all. Subtracting two unsigned values just works out of the box.&#60;br /&#62;
As an example 0x10 - 0xfffffff0 is 0x20, no matter to what you cast this result later.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "SerialUSB flow control"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13641#post-29130</link>
			<pubDate>Fri, 06 Sep 2013 18:45:30 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">29130@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The major problem as ala points out is that every print command can be turned into&#60;br /&#62;
several low level usb write commands. And every low level command is sent as a separate&#60;br /&#62;
transaction and if the previous transaction is not sent in time it silently fails.&#60;/p&#62;
&#60;p&#62;There is a new experimental usb_serial code (&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=13461&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=13461&#60;/a&#62;)&#60;br /&#62;
that has a 64 byte buffer that can be filled while the previous transaction is beeing sent, or is waiting for the host to get ready.&#60;/p&#62;
&#60;p&#62;At the moment the pending call reflects the number of bytes in the PMA (hardware) buffer and not the number of bytes in the write buffer. But it might help and testing is welcome.&#60;/p&#62;
&#60;p&#62;Regards&#60;br /&#62;
Magnus
&#60;/p&#62;</description>
		</item>
		<item>
			<title>SevenW on "SerialUSB flow control"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13641#post-29129</link>
			<pubDate>Fri, 06 Sep 2013 16:44:06 +0000</pubDate>
			<dc:creator>SevenW</dc:creator>
			<guid isPermaLink="false">29129@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;OK, println() resutls in three calls to write. Despite testing on SerialUSB.pending(), for the second or third call to write(), pending() may have become true. In usbserial.cpp this  has resulted in a timeout. So besides increasing the timeout in usbserial, I could handle the CRLF myself and do a single call to write.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;buffer[i++]=&#38;#39;\r&#38;#39;;   //append &#38;#39;\r&#38;#39;
buffer[i++]=&#38;#39;\n&#38;#39;;   //append &#38;#39;\n&#38;#39;
buffer[i]=(char)0;  //write c-style string termination

while (SerialUSB.pending()) delayMicroseconds(50);
SerialUSB.write(buffer);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Actually my test is a little more elaborate. The nice (int) cast is to avoid the millis overflow issue every fifty days. Ser = SerialUSB:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#define SER_TIMEOUT 10000 //10s timeout for USB communication

uint32 start = millis();
while ((Ser.pending() &#124;&#124; !Ser.getRTS() &#124;&#124; !Ser.getDTR()) &#38;amp;&#38;amp;
       ((int)(millis() - start) &#38;lt; SER_TIMEOUT)) delayMicroseconds(50);
Ser.write(buffer);&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>ala42 on "SerialUSB flow control"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13641#post-28920</link>
			<pubDate>Thu, 05 Sep 2013 20:35:38 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">28920@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;&#38;gt;The newline thing is very strange. It differs in that println sends \r\n, where I send \n only.&#60;br /&#62;
While this is a difference, it is not important. The main difference is that println sends three data blocks, the buffer, CR, LF. Each block write has a timeout of 50ms, after which the data is lost.&#60;br /&#62;
To increase the timeout of currently 50ms change the line&#60;br /&#62;
#define USB_TIMEOUT 50&#60;br /&#62;
in usb_serial.cpp
&#60;/p&#62;</description>
		</item>
		<item>
			<title>SevenW on "SerialUSB flow control"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13641#post-28919</link>
			<pubDate>Thu, 05 Sep 2013 18:16:45 +0000</pubDate>
			<dc:creator>SevenW</dc:creator>
			<guid isPermaLink="false">28919@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@mlundinse: Thanks for the pointers. After a lot of experimenting I concluded that RTS was not laying a role, but the pending state did. It looks like I have the connection reliably working. There might be issues on the maple side, but I am not sure.&#60;/p&#62;
&#60;p&#62;This works:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;while (SerialUSB.pending()) delayMicroseconds(50);
SerialUSB.print(buffer); // or SerialUSB.write(buffer);
while (SerialUSB.pending()) delayMicroseconds(50);
SerialUSB.write(&#38;#39;\n&#38;#39;);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;This does not work:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;while (SerialUSB.pending()) delayMicroseconds(50);
SerialUSB.println(buffer);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;The SerialUSB.pending() is essential. I did not experiment a lot with the delay.&#60;/p&#62;
&#60;p&#62;The newline thing is very strange. It differs in that println sends \r\n, where I send \n only.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mlundinse on "SerialUSB flow control"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13641#post-28918</link>
			<pubDate>Thu, 05 Sep 2013 13:14:02 +0000</pubDate>
			<dc:creator>mlundinse</dc:creator>
			<guid isPermaLink="false">28918@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The low level USB has hardware handshaking on both host and device as part of the basic USB protocol. The host, your Pi, will only request the next USB IN packet when the USB drivers are ready to receive them.&#60;/p&#62;
&#60;p&#62;The receiving application must be able to handle the incoming packets from the kernel USB drivers, or the serial buffers can overflow and data will get lost.&#60;/p&#62;
&#60;p&#62;On the Maple side data can get lost if the host doesn't ask for IN packets, then the USBSerial::write() will timeout and silently drop the data. On Maple you can use SerialUSB.pending() to check that the IN buffers are empty and ready to receive more data.&#60;br /&#62;
This will not help if the USB serial kernel drivers on the host overflows before your application can handle the data.&#60;/p&#62;
&#60;p&#62;It is possible to use the virtual RTS line to implement serial protocol handshaking. On the host it is controlled in the same way as a hardware RTS line, on Maple you can check the status of RTS with SerialUSB.getRTS() before sending any more data.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>SevenW on "SerialUSB flow control"</title>
			<link>http://forums.leaflabs.com/topic.php?id=13641#post-28846</link>
			<pubDate>Thu, 05 Sep 2013 06:46:30 +0000</pubDate>
			<dc:creator>SevenW</dc:creator>
			<guid isPermaLink="false">28846@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I have a small application that on request can echo the content of a log file through SerialUSB to a Raspberry Pi. The problem is that I loose some of the lines sent. Before diving too deep into linux cdc-acm drivers or the node.js serialport implementation I want to see whether the issue is on the maple side of things. &#60;/p&#62;
&#60;p&#62;Is HW handshaking always handled by the USB layer, or do I take care of it in my applicaiton program? Now I loop over the file, and per line I call:&#60;/p&#62;
&#60;p&#62;SerialUSB.println(msg);&#60;/p&#62;
&#60;p&#62;I loose about 12 lines of 140 lines per second, which BTW is due to a periodic task performed at the receiver side.&#60;/p&#62;
&#60;p&#62;Should I check on RTS myself?&#60;/p&#62;
&#60;p&#62;if SerialUSB.getRTS()&#60;br /&#62;
  SerialUSB.println(msg);
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
