<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Saleae Logic &#8211; IoT Expert</title>
	<atom:link href="https://iotexpert.com/category/tools/saleae-logic/feed/" rel="self" type="application/rss+xml" />
	<link>https://iotexpert.com</link>
	<description>Engineering for the Internet of Things</description>
	<lastBuildDate>Sun, 13 Aug 2017 17:09:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://iotexpert.com/wp-content/uploads/2017/01/cropped-Avatar-32x32.jpg</url>
	<title>Saleae Logic &#8211; IoT Expert</title>
	<link>https://iotexpert.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Percepio Tracealyzer &#8211; Analyzing the PSoC Tracealyzer Streamport</title>
		<link>https://iotexpert.com/psoc-tracealyzer-streampoint/</link>
					<comments>https://iotexpert.com/psoc-tracealyzer-streampoint/#respond</comments>
		
		<dc:creator><![CDATA[Alan Hawse]]></dc:creator>
		<pubDate>Thu, 03 Aug 2017 10:00:37 +0000</pubDate>
				<category><![CDATA[FreeRTOS]]></category>
		<category><![CDATA[Saleae Logic]]></category>
		<category><![CDATA[Tracealyzer]]></category>
		<guid isPermaLink="false">https://iotexpert.com/?p=3945</guid>

					<description><![CDATA[Summary In the previous article I showed you how to make a PSoC Tracealyzer Streamport using the SCB based UART on a PSoC 4200M.  It didn&#8217;t take long for me to realize that 115200 baud was not going to cut it.   That realization lead me to figure out that the KitProg on the CY8CKIT-044 [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Summary</h1>
<p>In the previous article I showed you how to make a PSoC Tracealyzer Streamport using the SCB based UART on a PSoC 4200M.  It didn&#8217;t take long for me to realize that 115200 baud was not going to cut it.   That realization lead me to figure out that the KitProg on the CY8CKIT-044 was limited to 115200, which I worked around by using the Cypress USB Serial Bridge that I got from the CY8CKIT-049.  But when I look at the CPU graph I found out that it took 50% of the CPU to support streaming the data.  So now what?  In this Article lets analyze the data, both old school with a logic analyzer, and new school with PSoC Tracealyzer.</p>
<h1>Analyzing the PSoC Tracealyzer Data</h1>
<p>While I was capturing the streaming data from PSoC Tracealyzer I could see that the CPU was burning about 50% of the time just running the TzCntrl and blinking LED thread.  That isn&#8217;t good.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-29-at-3.19.43-PM.png"><img fetchpriority="high" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-29-at-3.19.43-PM.png" alt="PSoC Tracelyzer" width="597" height="332" class="alignnone wp-image-3923 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-29-at-3.19.43-PM.png 597w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-29-at-3.19.43-PM-300x167.png 300w" sizes="(max-width: 597px) 100vw, 597px" /></a></p>
<p>When you look at the PSoC Tracealyzer trace viewing you can see the problem is the TzCtrl task.  This task is running for 83 milliseconds and using 57.6% of the CPU.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-29-at-3.20.29-PM.png"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-29-at-3.20.29-PM.png" alt="PSoC Tracelyzer - analyzing the CPU Usage" width="778" height="849" class="alignnone wp-image-3922 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-29-at-3.20.29-PM.png 778w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-29-at-3.20.29-PM-600x655.png 600w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-29-at-3.20.29-PM-275x300.png 275w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-29-at-3.20.29-PM-768x838.png 768w" sizes="(max-width: 778px) 100vw, 778px" /></a></p>
<p>If you look at the data transmit function called &#8220;PSoC_Transmit&#8221;, there isn&#8217;t much going on.  Just a call to UART_SpiUartPutArray.  But if you look at the UART documentation you will find that SpiUartPutArray is a blocking function, meaning it doesn&#8217;t return until it is done.  If you calculate the time to transfer a block of 1024 bytes at 8bits/byte and 230400 baud you will find that just sending the data takes 35ms.</p>
<pre class="start-line:25 lang:c decode:true">int32_t PSoC_Transmit(void* data, uint32_t size, int32_t *numOfBytesSent )
{
    timing_Write(1);
    UART_SpiUartPutArray((uint8_t *)data,size);
    *numOfBytesSent=size;
    timing_Write(0);
    return 0; // Doesnt matter what you return... i dont think that it is checked
}</pre>
<p>I was not very sure why the task was taking 83 milliseconds to run when the data transfer was only taking 40ms.  To figure this out I added a toggle pin to the data write routine, just to make sure.  What I found is the data write routine is getting called about every 70ms takes ~30ms to run.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-12.28.03-PM.png"><img decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-12.28.03-PM.png" alt="Old school with Salae Logic" width="764" height="143" class="alignnone wp-image-3947 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-12.28.03-PM.png 764w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-12.28.03-PM-600x112.png 600w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-12.28.03-PM-300x56.png 300w" sizes="(max-width: 764px) 100vw, 764px" /></a></p>
<p>How is that possible, the calculation says that it should take 35ms.  It turns out that I configured the UART to have a 64 byte buffer.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-12.33.30-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-12.33.30-PM.png" alt="PSoC Creator SCB Configuration" width="497" height="195" class="alignnone wp-image-3948 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-12.33.30-PM.png 497w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-12.33.30-PM-300x118.png 300w" sizes="auto, (max-width: 497px) 100vw, 497px" /></a></p>
<p>When you remove the 64 bytes from the calculation you end up with 32ish milliseconds.  The other thing that this chart shows is that the TzCntrl task is calling the PSoC_Transmit function more frequently that I thought, at least twice per cycle.  You can also see from the plot that function is taking 30/70=42.8% of the CPU by itself.  Not good, but we are starting to understand what is going on.</p>
<p>As I typed this part of the Article I realized that toggling a GPIO probably wasn&#8217;t the best way to figure out what was happening.  In fact, that is the whole point of Tracealyzer, that is analyzing the performance of your program.  When I looked at the Tracealyzer documentation (I always hate doing that), I found a nice function called vTracePrintf.  I added a &#8220;toggle&#8221; aka printing a 0 and printing a 1 into trace channel 0.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="c">int32_t PSoC_Transmit(void* data, uint32_t size, int32_t *numOfBytesSent )
{
    timing_Write(1);
    vTracePrintF(0,"1");
    UART_SpiUartPutArray((uint8_t *)data,size);
    vTracePrintF(0,"0");
    timing_Write(0);
    *numOfBytesSent=size;
    
    return 0; // Doesnt matter what you return... i dont think that it is checked
}</pre>
<p>After running another trace, look what I get.  You can see the &#8220;1&#8221; printing at the start and the 0 printing at the end.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.19.13-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.19.13-PM.png" alt="PSoC Tracelyzer - Analyzing the CPU Usage with vTaskPrintF" width="640" height="822" class="alignnone wp-image-3952 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.19.13-PM.png 640w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.19.13-PM-600x771.png 600w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.19.13-PM-234x300.png 234w" sizes="auto, (max-width: 640px) 100vw, 640px" /></a></p>
<p>Even better, when I double clicked on the &#8220;[Default Channel] 0&#8221; it took me to this nice screen which shows when the events occurred.  The one that I clicked on started at 8.136.039 and ended at 8.176.176, in other words it took about 40ms</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.19.45-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.19.45-PM.png" alt="PSoC Tracelyzer - User Events from Tracelyzer" width="634" height="454" class="alignnone wp-image-3951 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.19.45-PM.png 634w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.19.45-PM-600x430.png 600w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.19.45-PM-300x215.png 300w" sizes="auto, (max-width: 634px) 100vw, 634px" /></a></p>
<p>After hand calculating the time, I realized that once again I should have done something even more obvious, let the ARM calculate the time.  the vTracePrintf will let you specify the output format, in this case a %d</p>
<pre class="start-line:26 EnlighterJSRAW" data-enlighter-language="c" ">int32_t PSoC_Transmit(void* data, uint32_t size, int32_t *numOfBytesSent )
{
    TickType_t time;
    
    timing_Write(1);
    
    time = xTaskGetTickCount();
    UART_SpiUartPutArray((uint8_t *)data,size);
    time = xTaskGetTickCount() - time;
    vTracePrintF(0,"%d",time);
    timing_Write(0);
    *numOfBytesSent=size;
    
    return 0; // Doesnt matter what you return... i dont think that it is checked
}</pre>
<p>When you look at the trace, you need to click on the &#8220;User Events&#8221; to see the print outs from the trace.</p>
<p><a href="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.33.32-PM.png"><img loading="lazy" decoding="async" src="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.33.32-PM.png" alt="PSoC Tracelyzer - CPU Usage" width="694" height="908" class="alignnone wp-image-3955 size-full" srcset="https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.33.32-PM.png 694w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.33.32-PM-600x785.png 600w, https://iotexpert.com/wp-content/uploads/2017/07/Screen-Shot-2017-07-30-at-1.33.32-PM-229x300.png 229w" sizes="auto, (max-width: 694px) 100vw, 694px" /></a></p>
<p>Now that we have a pretty good feel for what is going on, how do we fix it?  Simple, use the PSoC DMA take the CPU mostly out of the UART transmission path, which is the topic of the next Article.</p>
<p><span><p>As always you can find all of these projects on the <a href="https://github.com/iotexpert/PSoC-Tracelyzer" target="_blank" rel="noopener">IotExpert GitHub</a> site or git@github.com:iotexpert/PSoC-Tracelyzer.git</p>
<p><div class="table-responsive"><table  style="width:95%; "  class="easy-table easy-table-default " border="1">
<thead>
<tr><th >Article</th>
<th >Description</th>
</tr>
</thead>
<tbody>
<tr><td ><a href="https://iotexpert.com/2017/07/18/percepio-tracelyzer-psoc-4200m/">Percepio Tracealyzer &amp; PSoC</a></td>
<td >An Introduction to Percepio Tracealyzer on the Cypress PSoC</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/07/25/perception-tracelyzer-rtt-streamport-psoc4200m/">Percepio Tracealyzer RTT Streamport - PSoC4200M</a></td>
<td >Make the JLINK RTT Library work with Tracealyzer</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/08/01/percepio-tracelyzer-psoc-uart-streamport/">Percepio Tracealyzer PSoC UART Streamport</a></td>
<td >Creating a UART Streamport</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/08/03/psoc-tracelyzer-streampoint/">Percepio Tracealyzer - Analyzing the PSoC Tracealyzer Streamport</a></td>
<td >Figure out what is broken in the UART Streamport</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/08/08/percepio-tracelyzer-a-psoc-dma-streamport/">Percepio Tracealyzer - Using PSoC DMA to Fix the UART Streamport</a></td>
<td >Implementing PSoC DMA to improve the CPU Utilization</td>
</tr>

<tr><td ><a href="https://iotexpert.com/2017/08/15/percepio-tracealyzer-on-psoc6/">Percepio Tracealyzer - Running on PSoC6</a></td>
<td >Porting the Percepio Tracealyzer to PSoC6</td>
</tr>
</tbody></table></div></p></span></p>
]]></content:encoded>
					
					<wfw:commentRss>https://iotexpert.com/psoc-tracealyzer-streampoint/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
