<?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: STM32F303 serial send performance testing</title>
		<link>http://forums.leaflabs.com/topic.php?id=16468</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:13:00 +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=16468" rel="self" type="application/rss+xml" />

		<item>
			<title>Adam on "STM32F303 serial send performance testing"</title>
			<link>http://forums.leaflabs.com/topic.php?id=16468&amp;page=2#post-40763</link>
			<pubDate>Sun, 29 Sep 2013 19:29:13 +0000</pubDate>
			<dc:creator>Adam</dc:creator>
			<guid isPermaLink="false">40763@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@ventosus, I will send you a pull request with the working OVER8 code along with the Serial1 higher speed.&#60;/p&#62;
&#60;p&#62;@gbulmer, I was testing with a FTDI UM232H module, which has a FTDI 232H chip. It was in USB 2.0 high-speed mode. Re: the stop and parity bits, yes considering that it's pretty close to the max the STM32F303 can do.&#60;/p&#62;
&#60;p&#62;I wish ST would come out with an STM32 chip with an on-chip USB 2.0 HS PHY. But they don't have one yet. The SAM3X8E has an on-chip USB 2.0 HS PHY, and has a 4KB buffer too... &#60;/p&#62;
&#60;p&#62;So I just set up a similar test on the Arduino Due (using a slightly modified version of this code: &#60;a href=&#34;http://forum.arduino.cc/index.php/topic,154424.0.html)&#34; rel=&#34;nofollow&#34;&#62;http://forum.arduino.cc/index.php/topic,154424.0.html)&#60;/a&#62;. &#60;/p&#62;
&#60;p&#62;I reliably get about 3.6MB/s from the SerialUSB interface on the Arduino - 28.8 megabits/s !&#60;/p&#62;
&#60;p&#62;So for my current needs, it looks like a SAM3X8E-based board using Arduino software is probably the way to go...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "STM32F303 serial send performance testing"</title>
			<link>http://forums.leaflabs.com/topic.php?id=16468#post-33780</link>
			<pubDate>Thu, 26 Sep 2013 20:14:54 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">33780@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Adam - excellent progress!&#60;/p&#62;
&#60;p&#62;I have always assumed that the baud-rate includes start and stop bits.&#60;br /&#62;
So a UART using one start and one stop bit, 9Mbaud would be 7Mbit/s data, a loss of more than 20%. &#60;/p&#62;
&#60;p&#62;&#60;em&#62;&#34; I seem to be able to send FTDI to FTDI (with no flow control) at about 6.3Mbit/s&#34;&#60;/em&#62;&#60;br /&#62;
Is that the High-speed FTDI, or the Full-speed FTDI?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "STM32F303 serial send performance testing"</title>
			<link>http://forums.leaflabs.com/topic.php?id=16468#post-33256</link>
			<pubDate>Thu, 26 Sep 2013 06:54:29 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">33256@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@Adam, testing and pull-requests are more than welcome.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Adam on "STM32F303 serial send performance testing"</title>
			<link>http://forums.leaflabs.com/topic.php?id=16468#post-32922</link>
			<pubDate>Wed, 25 Sep 2013 23:25:27 +0000</pubDate>
			<dc:creator>Adam</dc:creator>
			<guid isPermaLink="false">32922@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;In case anyone's interested in the code...&#60;/p&#62;
&#60;p&#62;Here's the DMA to USART program:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/adamfeuer/maple_performance_testing/blob/master/maple/usart_dma.cpp&#34; rel=&#34;nofollow&#34;&#62;https://github.com/adamfeuer/maple_performance_testing/blob/master/maple/usart_dma.cpp&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Here's the write buffer to USART program:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/adamfeuer/maple_performance_testing/blob/master/maple/send_standard_blink_serial_buf.cpp&#34; rel=&#34;nofollow&#34;&#62;https://github.com/adamfeuer/maple_performance_testing/blob/master/maple/send_standard_blink_serial_buf.cpp&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Here's the PyFTDI Python program that reads from the PyFTDI chip via USB 2.0 HS:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/adamfeuer/maple_performance_testing/blob/master/python/receive_data_pyftdi.py&#34; rel=&#34;nofollow&#34;&#62;https://github.com/adamfeuer/maple_performance_testing/blob/master/python/receive_data_pyftdi.py&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Adam on "STM32F303 serial send performance testing"</title>
			<link>http://forums.leaflabs.com/topic.php?id=16468#post-32907</link>
			<pubDate>Wed, 25 Sep 2013 23:04:35 +0000</pubDate>
			<dc:creator>Adam</dc:creator>
			<guid isPermaLink="false">32907@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;ventosus,&#60;/p&#62;
&#60;p&#62;Thank you! I got it to work - I didn't see your post until now, but I wrote this very similar code instead in libmaple/stm32f3/usart.c:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;`&#60;br /&#62;
void usart_set_baud_rate(usart_dev *dev, uint32 clock_speed, uint32 baud) {&#60;br /&#62;
    /* Figure out the clock speed, if the user doesn't give one. */&#60;br /&#62;
    if (clock_speed == 0) {&#60;br /&#62;
        clock_speed = _usart_clock_freq(dev);&#60;br /&#62;
    }&#60;br /&#62;
    ASSERT(clock_speed);&#60;/p&#62;
&#60;p&#62;    if (baud &#38;lt;= 4500000UL) {&#60;br /&#62;
                // default is 16x oversampling mode&#60;br /&#62;
                uint32 divider = clock_speed / baud;&#60;br /&#62;
                uint32 tmpreg = clock_speed % baud;&#60;br /&#62;
                /* round divider : if fractional part is greater than 0.5 increment divider */&#60;br /&#62;
                if (tmpreg &#38;gt;= baud / 2)&#60;br /&#62;
                    divider++;&#60;/p&#62;
&#60;p&#62;                dev-&#38;gt;regs-&#38;gt;BRR = (uint16)divider;&#60;br /&#62;
                dev-&#38;gt;regs-&#38;gt;CR1 &#38;amp;= ~USART_CR1_OVER8;&#60;br /&#62;
    } else {&#60;br /&#62;
                /* use 8x oversampling mode to get faster speeds&#60;/p&#62;
&#60;p&#62;                  When OVER8==1&#60;br /&#62;
                  – BRR[2:0] = USARTDIV[3:0] shifted 1 bit to the right.&#60;br /&#62;
                  – BRR3 must be kept cleared.&#60;br /&#62;
                  – BRR[15:4] = USARTDIV[15:4]&#60;/p&#62;
&#60;p&#62;                 */&#60;br /&#62;
                uint32 divider = 2*clock_speed / baud;&#60;br /&#62;
                uint32 tmpreg = 2*clock_speed % baud;&#60;br /&#62;
                /* round divider : if fractional part is greater than 0.5 increment divider */&#60;br /&#62;
                if (tmpreg &#38;gt;= 2*baud / 2)&#60;br /&#62;
                    divider++;&#60;/p&#62;
&#60;p&#62;                uint16 brrValue = ((uint16)divider &#38;amp; 0xfff0) &#124; (((uint16)divider &#38;amp; 0x0f) &#38;gt;&#38;gt; 1) ;&#60;br /&#62;
                dev-&#38;gt;regs-&#38;gt;BRR = brrValue;&#60;br /&#62;
                dev-&#38;gt;regs-&#38;gt;CR1 &#124;= USART_CR1_OVER8;&#60;br /&#62;
    }&#60;br /&#62;
}&#60;br /&#62;
`&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Re: clock domains, yes, I re-read the clock section of the F3 reference manual and see you are right. I am currently using USART1 so that was just lucky I guess. I will change my code to make sure you can only use the higher baudrates on USART1.&#60;/p&#62;
&#60;p&#62;But the code above works with USART1, and I can get the serial port to set the baudrate up to 9Mbit/s. I would like to send you a pull request for this when I've fixed it up - will you let me know if you do want that?&#60;/p&#62;
&#60;p&#62;Now my problem is sending characters fast enough. The usart_tx() routine can only hit about 3.4Mbit/s. That's still too slow for me. &#60;/p&#62;
&#60;p&#62;I wrote a DMA to USART program, based on Marti's USART to DMA program. This can do about 5.3Mbit/s. Still too slow.&#60;/p&#62;
&#60;p&#62;Now I'm trying to figure out where the bottleneck is - in my DMA to USART program, or in the PyFTDI driver. I seem to be able to send FTDI to FTDI (with no flow control) at about 6.3Mbit/s - quite a bit faster but still not fast enough.&#60;/p&#62;
&#60;p&#62;The F303 reference manual implies that the DMA to USART approach should be able to transmit at the full rate of the USART, 9Mbit/s. I need to look at my programs to see what's actually happening. &#60;/p&#62;
&#60;p&#62;I have a couple of STM32F4 boards that are clocked at 168MHz. I may try this experiment with one of them to see if the faster clock speed makes a difference. There's the hassle of getting the F4 code working, though... I haven't gotten the F4 boards to work with libmaple yet...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "STM32F303 serial send performance testing"</title>
			<link>http://forums.leaflabs.com/topic.php?id=16468#post-32351</link>
			<pubDate>Wed, 25 Sep 2013 06:47:14 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">32351@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;EDIT: this should read:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;dev-&#38;gt;regs-&#38;gt;BRR = (divider &#38;amp; 0xfff0) &#124; ( (divider &#38;amp; 0xf) &#38;gt;&#38;gt; 1);&#60;/code&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "STM32F303 serial send performance testing"</title>
			<link>http://forums.leaflabs.com/topic.php?id=16468#post-32263</link>
			<pubDate>Wed, 25 Sep 2013 05:01:49 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">32263@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;iirc, &#60;em&#62;.max_baud = ...&#60;/em&#62; is only used in wirish to check for valid baud rate arguments, but not in libmaple. If you set up USART from wiriish, this has to changed indeed.&#60;/p&#62;
&#60;p&#62;Note, maximal baud rate depends on the clock domain of the peripheral: only USART1 is on the APB2 clock domain (72MHz), the other USARTs are on APB1 (36MHz).&#60;/p&#62;
&#60;p&#62;To change oversampling from the default 16 to 8, only setting the OVER8 bit will not do, as the divider (USARTDIV) must be written to the BRR register in a specific way. This is not implemented (yet) in the F3-port.&#60;/p&#62;
&#60;p&#62;When OVER8 = 0, BRR [3:0] = USARTDIV [3:0]&#60;br /&#62;
When OVER8 = 1, BRR [2:0] = USARTDIV [3:0] shifted 1 bit to the right. BRR [3] must be&#60;br /&#62;
kept cleared.&#60;/p&#62;
&#60;p&#62;The following modified function is not tested, but may do the trick.&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
libmaple/libmaple/stm32f3/usart.c&#60;br /&#62;
---------------------------------&#60;/p&#62;
&#60;p&#62;void usart_set_baud_rate(usart_dev *dev, uint32 clock_speed, uint32 baud) {&#60;br /&#62;
  /* Figure out the clock speed, if the user doesn't give one. */&#60;br /&#62;
  if (clock_speed == 0) {&#60;br /&#62;
    clock_speed = _usart_clock_freq(dev);&#60;br /&#62;
  }&#60;br /&#62;
  ASSERT(clock_speed);&#60;/p&#62;
&#60;p&#62;  int32 divider = clock_speed / baud;&#60;br /&#62;
  uint32 tmpreg = clock_speed % baud;&#60;br /&#62;
  /* round divider : if fractional part i greater than 0.5 increment divider */&#60;br /&#62;
  if (tmpreg &#38;gt;= baud / 2)&#60;br /&#62;
    divider++;&#60;/p&#62;
&#60;p&#62;  if (divider &#38;lt; 16) { // OVER8&#60;br /&#62;
    dev-&#38;gt;regs-&#38;gt;CR1 &#124;= USART_CR1_OVER8;&#60;br /&#62;
    divider *= 2;&#60;br /&#62;
    dev-&#38;gt;regs-&#38;gt;BRR = (divider &#38;amp; 0xff0) &#124; ( (divider &#38;amp; 0xf) &#38;gt;&#38;gt; 1);&#60;br /&#62;
  }&#60;br /&#62;
  else { // OVER16&#60;br /&#62;
    dev-&#38;gt;regs-&#38;gt;CR1 &#38;amp;= ~USART_CR1_OVER8;&#60;br /&#62;
    dev-&#38;gt;regs-&#38;gt;BRR = (uint16)divider;&#60;br /&#62;
  }&#60;br /&#62;
}&#60;br /&#62;
&#60;/code&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Adam on "STM32F303 serial send performance testing"</title>
			<link>http://forums.leaflabs.com/topic.php?id=16468#post-31830</link>
			<pubDate>Mon, 23 Sep 2013 22:34:08 +0000</pubDate>
			<dc:creator>Adam</dc:creator>
			<guid isPermaLink="false">31830@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Here's some preliminary results for some serial send performance testing I've been doing with an Orone Mini F3 connected to a Mac OS X 10.8 laptop.&#60;/p&#62;
&#60;p&#62;I can get about 50KB/s from a stock Maple Mini.&#60;br /&#62;
I can get about 300KB/s (about 2.4 Mbit/s) from an Orone Mini F3 using an FTDI FT232H board connected to Serial 1 (USART 1) using a Python program that uses the FTDI virtual com port drivers via PySerial. It's limited by Mac OS X kernel serial driver.&#60;/p&#62;
&#60;p&#62;I can get about 447KB/s (almost 3.6 Mbit/s) from an Orone Mini F3 using an FTDI FT232H board on Serial 1, using a Python program that does not use the FTDI virtual com port drivers, but instead talks directly to the FTDI chip via the PyFTDI module. &#60;/p&#62;
&#60;p&#62;I'll post detailed results and code tomorrow.&#60;/p&#62;
&#60;p&#62;It seems like I should be able to get the F3's USARTs to do almost 9Mbit/s, as that is what the STM32F303 reference manual says the hardware supports. The FT232H can do up to 12Mbit/s. &#60;/p&#62;
&#60;p&#62;But I run into problems if I set a baud rate on the Serial port that is higher than 4.5Mbit/s - the Orone Mini F3 hangs immediately. Does anyone know what might be wrong? I've looked at the usart.c file in the ibmaple/stm32f3/usart.c file - there's a max baud rate specified there, and I've changed that to &#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;&#60;code&#62;.max_baud = 9000000UL,&#60;/code&#62;&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;But that doesn't seem to stop the hangs.&#60;/p&#62;
&#60;p&#62;Does anyone have ideas on how to get closer to the maximum baud rate? For my application, I need to get about 8Mbit/s.&#60;/p&#62;
&#60;p&#62;&#60;strong&#62;Update&#60;/strong&#62;: it looks like the F1 and F3 have different ways of setting the baud rate - since the F3's USARTs are much faster. Looks like I will need to set the OVER8 (oversampling bit) in the USART status register, and calculate the dividers differently. I will check that out tomorrow...
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
