<?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: serial usart adding rts/cts flow control to libmaple</title>
		<link>http://forums.leaflabs.com/topic.php?id=2372</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:13:40 +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=2372" rel="self" type="application/rss+xml" />

		<item>
			<title>ethanb on "serial usart adding rts/cts flow control to libmaple"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2372#post-21984</link>
			<pubDate>Mon, 14 Jan 2013 00:02:03 +0000</pubDate>
			<dc:creator>ethanb</dc:creator>
			<guid isPermaLink="false">21984@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello!&#60;br /&#62;
I was able to find some RTS/CTS definitions in a header file, but I didn't find any code for initializing hardware flow control.&#60;br /&#62;
Did any of the implementation get checked in? Are we flow-control capable?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>cleemesser on "serial usart adding rts/cts flow control to libmaple"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2372#post-12454</link>
			<pubDate>Wed, 15 Aug 2012 15:12:53 +0000</pubDate>
			<dc:creator>cleemesser</dc:creator>
			<guid isPermaLink="false">12454@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I'll add in the others #defines the next time I have a chance to sit down. It strikes me that the beginFlowControl() might be the most pleasant approach.&#60;/p&#62;
&#60;p&#62;By the way, I don't have an F2 board, but I do have the F4Discovery which is very nice. I wonder if anyone could convince STM to opensource their design. Does the maple 2 have an ETA?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "serial usart adding rts/cts flow control to libmaple"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2372#post-12382</link>
			<pubDate>Mon, 13 Aug 2012 12:10:11 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12382@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
(See attached patch. I might be able to figure out how to do as a pull request if you would prefer.)
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;A forum post is enough for small patches like these. Thanks!&#60;/p&#62;
&#60;p&#62;Any chance you could add them for Maple Mini and Maple Native? That would save me some work.&#60;/p&#62;
&#60;p&#62;Please note that we do need signed-off commits when merging more significant patches (such as adding new features like USART flow control) into libmaple. The &#60;a href=&#34;http://leaflabs.com/docs/libmaple/contributing.html&#34;&#62;libmaple contributing doc&#60;/a&#62; has all the details, but basically, you'll need to include a line in the commit log message that says:&#60;/p&#62;
&#60;p&#62;Signed-off-by: Your Real Name &#38;lt;your.email@example.com&#38;gt;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>cleemesser on "serial usart adding rts/cts flow control to libmaple"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2372#post-12378</link>
			<pubDate>Mon, 13 Aug 2012 11:00:44 +0000</pubDate>
			<dc:creator>cleemesser</dc:creator>
			<guid isPermaLink="false">12378@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks. &#60;/p&#62;
&#60;p&#62;I've done the easy part: I've added the pin information for the ret6 and the maple board definitions. (See attached patch. I might be able to figure out how to do as a pull request if you would prefer.)&#60;br /&#62;
It should work with the above macro. I haven't added the NOT_A_PIN or #ifndef yet. My testing has started to catch up with my transition to the command line tools and I now have a pure-command line version of my test code. I used the template from your (mbolivar's) example-libmaple-project git repo). I can put that on github too if anyone is interested.&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;/p&#62;
&#60;p&#62;diff --git a/wirish/boards/maple/include/board/board.h b/wirish/boards/maple/include/board/board.h&#60;br /&#62;
index e675806..09e6a53 100644&#60;br /&#62;
--- a/wirish/boards/maple/include/board/board.h&#60;br /&#62;
+++ b/wirish/boards/maple/include/board/board.h&#60;br /&#62;
@@ -48,11 +48,19 @@&#60;br /&#62;
 /* USART pin numbers. */&#60;br /&#62;
 #define BOARD_USART1_TX_PIN     7&#60;br /&#62;
 #define BOARD_USART1_RX_PIN     8&#60;br /&#62;
+#define BOARD_USART1_CK_PIN     6&#60;br /&#62;
+&#60;br /&#62;
 #define BOARD_USART2_TX_PIN     1&#60;br /&#62;
 #define BOARD_USART2_RX_PIN     0&#60;br /&#62;
+#define BOARD_USART2_CK_PIN     10&#60;br /&#62;
+#define BOARD_USART2_CTS_PIN    2&#60;br /&#62;
+#define BOARD_USART2_RTS_PIN    3&#60;br /&#62;
+&#60;br /&#62;
 #define BOARD_USART3_TX_PIN     29&#60;br /&#62;
 #define BOARD_USART3_RX_PIN     30&#60;br /&#62;
-&#60;br /&#62;
+#define BOARD_USART3_CK_PIN     31&#60;br /&#62;
+#define BOARD_USART3_CTS_PIN    32&#60;br /&#62;
+#define BOARD_USART3_RTS_PIN    33&#60;br /&#62;
 /* Number of SPI ports broken out to headers. */&#60;br /&#62;
 #define BOARD_NR_SPI            2&#60;/p&#62;
&#60;p&#62;diff --git a/wirish/boards/maple_RET6/include/board/board.h b/wirish/boards/maple_RET6/include/board/board.h&#60;br /&#62;
index 7c6851b..d51b61d 100644&#60;br /&#62;
--- a/wirish/boards/maple_RET6/include/board/board.h&#60;br /&#62;
+++ b/wirish/boards/maple_RET6/include/board/board.h&#60;br /&#62;
@@ -46,10 +46,19 @@&#60;br /&#62;
 #define BOARD_NR_USARTS         3&#60;br /&#62;
 #define BOARD_USART1_TX_PIN     7&#60;br /&#62;
 #define BOARD_USART1_RX_PIN     8&#60;br /&#62;
+#define BOARD_USART1_CK_PIN     6&#60;br /&#62;
+&#60;br /&#62;
 #define BOARD_USART2_TX_PIN     1&#60;br /&#62;
 #define BOARD_USART2_RX_PIN     0&#60;br /&#62;
+#define BOARD_USART2_CK_PIN     10&#60;br /&#62;
+#define BOARD_USART2_CTS_PIN    2&#60;br /&#62;
+#define BOARD_USART2_RTS_PIN    3&#60;br /&#62;
+&#60;br /&#62;
 #define BOARD_USART3_TX_PIN     29&#60;br /&#62;
 #define BOARD_USART3_RX_PIN     30&#60;br /&#62;
+#define BOARD_USART3_CK_PIN     31&#60;br /&#62;
+#define BOARD_USART3_CTS_PIN    32&#60;br /&#62;
+#define BOARD_USART3_RTS_PIN    33&#60;/p&#62;
&#60;p&#62; /* Note:&#60;br /&#62;
  *&#60;br /&#62;
&#60;/code&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "serial usart adding rts/cts flow control to libmaple"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2372#post-12292</link>
			<pubDate>Fri, 10 Aug 2012 16:54:19 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12292@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Interesting stuff; thanks for posting.&#60;/p&#62;
&#60;p&#62;Since you've got a Maple RET6 ed.., you'll likely want to commit any changes to libmaple proper into the libmaple/stm32f1 USART files. For portability, please only put patches into the top-level libmaple/usart.c and libmaple/include/libmaple/usart.h files if you've tested them on STM32F2.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
I noticed that the HardwareSerial classes in wirish have private members, which seems to make it difficult to subclass them. Is this truly what is desired? Would using the protected attribute make more sense?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;In the current libmaple master, you can get your hands on all the private members with inline accessor functions, so there should be no performance or usability problems with subclassing.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
3. Is there any easy way to allow the user to reference the correct pins for cts and rts for a given board and USART number. I notice that you use macros and the PIN_MAP to do this in HardwareSerial.cpp&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;The corresponding macros for hardware flow control pins (these would be named something like BOARD_USART1_CTS_PIN and BOARD_USART1_RTS_PIN) are currently missing from the board headers (under wirish/boards). I'd take patches that added them.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Alternatively, the functionality could be added directly to HardwareSerial&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;That's reasonable. I'd review any such patches.&#60;/p&#62;
&#60;p&#62;Note that some boards don't break out some flow control pins (e.g. &#60;a href=&#34;http://leaflabs.com/docs/hardware/maple.html#usart-pin-map&#34;&#62;Maple doesn't break out USART1 CTS/RTS&#60;/a&#62;). For these, you'd need some sort of feature-test macro. This would be along the lines of &#60;code&#62;BOARD_HAVE_USART1&#60;/code&#62; (see wirish/include/wirish/boards.h), except it'd need a name like &#60;code&#62;BOARD_HAVE_USART1_FLOW_CTRL&#60;/code&#62; (although a better name would be nice ;)).&#60;/p&#62;
&#60;p&#62;One implementation (feel free to go about it this way or any other way that seems more reasonable to you) would add a HardwareSerial constructor that passed cts_pin and rts_pin arguments. For backwards compatibility, the existing constructor would set them to invalid values[1] that &#60;code&#62;HardwareSerial::begin()&#60;/code&#62; would check for. Then HardwareSerial.cpp could define the &#60;code&#62;SerialN&#60;/code&#62; based on the feature test macros. The result would look something like this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;#ifndef BOARD_HAVE_USART1_FLOW_CTRL
#define BOARD_USART1_CTS_PIN NOT_A_PIN
#define BOARD_USART1_RTS_PIN NOT_A_PIN
#endif

// ... etc for the other USARTs

#define DEFINE_HWSERIAL(name, n)                                   \
    HardwareSerial name(USART##n,                                  \
                        BOARD_USART##n##_TX_PIN,                   \
                        BOARD_USART##n##_RX_PIN,                   \
                        BOARD_USART##n##_CTS_PIN,                  \
                        BOARD_USART##n##_RTS_PIN)&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I think the default behavior should ignore flow control pins, for simplicity and backwards compatibility. Perhaps you could add a &#60;code&#62;HardwareSerial::beginFlowControl()&#60;/code&#62; method (name suggestions?) that configures the pins properly and turns on flow control checking. Or you could add a boolean argument to &#60;code&#62;HardwareSerial::begin()&#60;/code&#62; that turned on flow control, and set it to false by default. Other proposals?&#60;/p&#62;
&#60;p&#62;[1] We need a standard &#60;code&#62;NOT_A_PIN&#60;/code&#62; value and a &#60;code&#62;pin_t&#60;/code&#62; type to make this easier, I think. (Wiring has already accepted this proposal.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>feurig on "serial usart adding rts/cts flow control to libmaple"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2372#post-12285</link>
			<pubDate>Fri, 10 Aug 2012 13:13:25 +0000</pubDate>
			<dc:creator>feurig</dc:creator>
			<guid isPermaLink="false">12285@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Nice! Hopefully mbolivar or one of the close to the core people will look at it.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>cleemesser on "serial usart adding rts/cts flow control to libmaple"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2372#post-12265</link>
			<pubDate>Thu, 09 Aug 2012 19:15:03 +0000</pubDate>
			<dc:creator>cleemesser</dc:creator>
			<guid isPermaLink="false">12265@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello, I want to thank you for creating the Maple. I've been learning a lot with my RET6.&#60;/p&#62;
&#60;p&#62;I've been working on different ways to stream data to and from the maple. One method I've been looking at is the USARTs. I've been testing them at 2Mb/s with both the FT232RL and FT2232H USB-to-serial solutions. The good news is that it seems to work well and in my tests I get around 180KB/s pretty consistently. I had noticed that intermittently I'm getting errors with the FT232RL approaches. I haven't ever seen it happen with the FT2232H but my sample is limited to a few runs with the longest being about 5 hours. I'm not certain what the cause is because the mean failure time is around every 90 million bytes transferred with a wide variation. &#60;/p&#62;
&#60;p&#62;Anyway, I'm not seeking to debug the problem in this post (another day), but to motivate why I thought to add hardware flow control. I have taken a stab at it and done some basic tests with it working when specialized to USART3.&#60;/p&#62;
&#60;p&#62;Now I am asking for some help with a few questions:&#60;/p&#62;
&#60;p&#62;1. I noticed that the HardwareSerial classes in wirish have private members, which seems to make it difficult to subclass them. Is this truly what is desired? Would using the protected attribute make more sense? I ended up creating HardwareSerialFlowControl as a subclass of Print because of this and duplicated a lot of the code in HardwareSerial.&#60;/p&#62;
&#60;p&#62;Alternatively, the functionality could be added directly to HardwareSerial&#60;/p&#62;
&#60;p&#62;2. In order to enable the rts/cts for the different USARTs I need something that allows the code to select the correct register bits. Right now, I use the &#34;backdoor&#34; to usart_dev in my main.cpp code to activate USART3 on the maple or maple-ret6. The HardwareSerial class relies upon  usart_enable(this-&#38;gt;usart_device) so should this go in libmaple proper in order to do the right thing.&#60;/p&#62;
&#60;p&#62;3. Is there any easy way to allow the user to reference the correct pins for cts and rts for a given board and USART number. I notice that you use macros and the PIN_MAP to do this in HardwareSerial.cpp&#60;/p&#62;
&#60;p&#62;I've forked libmaple on github and added my work-in-progress files:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/cleemesser/libmaple/blob/master/wirish/include/wirish/HardwareSerialFlowControl.h&#34; rel=&#34;nofollow&#34;&#62;https://github.com/cleemesser/libmaple/blob/master/wirish/include/wirish/HardwareSerialFlowControl.h&#60;/a&#62;&#60;br /&#62;
&#60;a href=&#34;https://github.com/cleemesser/libmaple/blob/master/wirish/HardwareSerialFlowControl.cpp&#34; rel=&#34;nofollow&#34;&#62;https://github.com/cleemesser/libmaple/blob/master/wirish/HardwareSerialFlowControl.cpp&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;In case someone wants to look at them.&#60;br /&#62;
Thanks again&#60;br /&#62;
-Chris
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
