<?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: Does SerialUSB.print() work during void setup() section?</title>
		<link>http://forums.leaflabs.com/topic.php?id=811</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:23:31 +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=811" rel="self" type="application/rss+xml" />

		<item>
			<title>mbolivar on "Does SerialUSB.print() work during void setup() section?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=811#post-4944</link>
			<pubDate>Fri, 03 Jun 2011 10:51:40 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4944@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;rbardsley,&#60;/p&#62;
&#60;p&#62;As crenn said, the debug println()s aren't &#34;skipped&#34;.  Here's a more detailed rundown on what's going on.&#60;/p&#62;
&#60;p&#62;When the bootloader finishes waiting, it jumps to user code.  Your call to USBSerial::println() defers to USBSerial::write() behind the scenes.  Here's the source for that function:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/0.0.11/wirish/usb_serial.cpp#L58&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/0.0.11/wirish/usb_serial.cpp#L58&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;As you can see, USBSerial::write() defers to the libmaple proper function usbSendBytes(), which is nonblocking.  If USBSerial::write() notices that USB_TIMEOUT (currently 50) milliseconds have gone by since the last time a call to usbSendBytes() successfully transmitted anything, it aborts.&#60;/p&#62;
&#60;p&#62;Probably we should change the return values of USBSerial::write() and the USBSerial::print() family to uint32 so you can tell that nothing was printed (or possibly add a USBSerial::blocking(bool) method which could let you disable timeout).&#60;/p&#62;
&#60;p&#62;The reason it exists is to make sure that stray println()s don't hang your program in case the USB host isn't connected or isn't asking for data.&#60;/p&#62;
&#60;p&#62;FWIW, I use the method I outlined earlier all the time, and it works fine.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Does SerialUSB.print() work during void setup() section?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=811#post-4937</link>
			<pubDate>Thu, 02 Jun 2011 21:14:44 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">4937@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;rbardsley, Every time you reset the Maple, it will 'disconnect' the serial port, 'connect' the DFU, if it doesn't get a response in x time or if BUT hasn't been pressed during start up, it then goes to run program, 'reconnecting' the serial port and 'disconnecting' the DFU. I was just trying to say that every time you open the serial console, the behaviour wanted is to start the program again, however this isn't the case for the Maple.&#60;/p&#62;
&#60;p&#62;Adding the delay shows that SerialUSB.print() is happening. Just I note, I usually put in a 5-15 second delay. It is possible to avoid the delay if you're very quick with PuTTy, that is if you have PuTTy with the setting in, upload the code, and when the Maple stops blinking, you can get PuTTy to start reading the serial port.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rbardsley on "Does SerialUSB.print() work during void setup() section?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=811#post-4936</link>
			<pubDate>Thu, 02 Jun 2011 19:26:42 +0000</pubDate>
			<dc:creator>rbardsley</dc:creator>
			<guid isPermaLink="false">4936@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks for the advice everyone. The delay seems to have helped a bit, though it isn't consistent. I haven't had time to test mbolivar's suggestion yet either. And crenn, it isn't just when I reconnect the Maple board to my USB cable. Any debug printlns I have in my setup() loop are skipped. Everything else is loaded, so I know that it has executed that code... just no Serial.print(). &#60;/p&#62;
&#60;p&#62;I'll keep trying.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Does SerialUSB.print() work during void setup() section?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=811#post-4908</link>
			<pubDate>Tue, 31 May 2011 11:04:32 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4908@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;rbardsley,&#60;/p&#62;
&#60;p&#62;Besides adding a delay, one thing you might try is just waiting for the host PC to send a character in setup() before printing anything, like so:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;void setup() {
    // wait for the user to send a character
    while (!SerialUSB.available())
        ;
    // consume the character sent
    SerialUSB.read();

    SerialUSB.println(&#38;quot;hello world!&#38;quot;);

    // do the rest of your setup
    ...
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>ala42 on "Does SerialUSB.print() work during void setup() section?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=811#post-4875</link>
			<pubDate>Sun, 29 May 2011 17:16:17 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">4875@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;During reset, the USB connection is disabled. It might take a while, until Windows redetects the device. Add a 2 seconds delay in setup() and check if this helps.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Does SerialUSB.print() work during void setup() section?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=811#post-4867</link>
			<pubDate>Sat, 28 May 2011 17:25:27 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">4867@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Unlike the Arduino, the Maple doesn't trigger a reset when you open a terminal window, so the messages are happening, just not while you have the window open. I believe this problem is still being looked at.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rbardsley on "Does SerialUSB.print() work during void setup() section?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=811#post-4866</link>
			<pubDate>Sat, 28 May 2011 12:00:15 +0000</pubDate>
			<dc:creator>rbardsley</dc:creator>
			<guid isPermaLink="false">4866@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I am new to Maple. I have successfully ported my current Arduino code over to my new Rev 5 Maple board, but I am missing something really simple. When my program starts up, it spits out a bunch of nice user-friendly messages during the setup() section of the program. This doesn't seem to work anymore. &#60;/p&#62;
&#60;p&#62;During the loop(), my SerialUSB.print statements work great. The same commands just don't seem to fire during setup().&#60;/p&#62;
&#60;p&#62;Is this a limitation? Am I doing something wrong?&#60;/p&#62;
&#60;p&#62;Thanks for your help. Loving my Maple so far!&#60;/p&#62;
&#60;p&#62;Ryan
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
