<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Freeze of nrf52840 USB Dongle due to USB CDC-ACM data transfer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59762/freeze-of-nrf52840-usb-dongle-due-to-usb-cdc-acm-data-transfer</link><description>I&amp;#39;m experiencing a freeze - at least from user&amp;#39;s perspective - when using a slightly modified &amp;quot;usbd_cdc_acm&amp;quot;-example and applying some human generated load (meaning: hitting the keyboard for a couple of seconds, incl. &amp;#39;\n&amp;#39; every now and then in order</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Apr 2020 21:45:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59762/freeze-of-nrf52840-usb-dongle-due-to-usb-cdc-acm-data-transfer" /><item><title>RE: Freeze of nrf52840 USB Dongle due to USB CDC-ACM data transfer</title><link>https://devzone.nordicsemi.com/thread/244199?ContentTypeID=1</link><pubDate>Thu, 09 Apr 2020 21:45:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:219ec875-b20a-4757-8831-2c2fbf2db3d1</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I don&amp;#39;t have an answer, but there does seem to be an inconsistency in that the first location is never used and the &amp;#39;\r&amp;#39; terminator doesn&amp;#39;t terminate unless followed by another character which is then&amp;nbsp;followed&amp;nbsp;by inserting a 0 which could be past the end of the buffer as it is not checked:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;This line pre-increments m_rx_buffer_pos before the call, so m_rx_buffer[0] is never populated
+ &amp;amp;m_rx_buffer[++m_rx_buffer_pos], READ_SIZE);

This line looks at the previous character received, not the most recent
+ if(m_rx_buffer[m_rx_buffer_pos-1] == &amp;#39;\r&amp;#39;)
+ {
// This line replaces the chracter after the most recent with 0
+ m_rx_buffer[++m_rx_buffer_pos] = &amp;#39;\0&amp;#39;;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So .. termination is by &amp;#39;\r&amp;#39;,[anything], otherwise the buffer will eventually overflow.&amp;nbsp;&lt;em&gt;m_rx_buffer[0]&lt;/em&gt; will never be set but will contain whatever anything else writing to this buffer last put there.&lt;/p&gt;
&lt;p&gt;\r will only terminate immediately when hit if the terminal is configured to append - say - \n after every \r.&lt;/p&gt;
&lt;p&gt;Using an 8-bit index to a 9-bit (512) element array will also not work as intended:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;+static uint8_t m_rx_buffer_pos = 0;
+static char m_rx_buffer[512];&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Freeze of nrf52840 USB Dongle due to USB CDC-ACM data transfer</title><link>https://devzone.nordicsemi.com/thread/244194?ContentTypeID=1</link><pubDate>Thu, 09 Apr 2020 21:19:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58e9e956-341b-4e36-b618-1944f2cd7440</guid><dc:creator>daten</dc:creator><description>&lt;p&gt;I allow myself to push a bit for a solution. This is a hard blocker for us and currently halting rollout.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Freeze of nrf52840 USB Dongle due to USB CDC-ACM data transfer</title><link>https://devzone.nordicsemi.com/thread/242949?ContentTypeID=1</link><pubDate>Wed, 01 Apr 2020 12:12:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fa680237-d1d7-420a-b9ce-aa34d79b5d40</guid><dc:creator>daten</dc:creator><description>&lt;p&gt;After rethinking the issue, its potential causes and occurrences, I don&amp;#39;t think increasing READ_SIZE would help much, if at all:&lt;/p&gt;
&lt;p&gt;a) Looking at the log output I posted the freeze in this very case already occurred after 2 loop cycles, which really isn&amp;#39;t a lot, so even if I heavily increase READ_SIZE I most likely will still have more than 1 loop cycle.&lt;/p&gt;
&lt;p&gt;b) The freeze seems not to happen within the loop, but when / after leaving it. Potentially related to re-setting the buffer array index to 0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Freeze of nrf52840 USB Dongle due to USB CDC-ACM data transfer</title><link>https://devzone.nordicsemi.com/thread/242893?ContentTypeID=1</link><pubDate>Wed, 01 Apr 2020 09:58:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:48e1f557-60f6-4af2-b4a5-d2c95548bb65</guid><dc:creator>daten</dc:creator><description>&lt;p&gt;Hello and thanks for your reply. I could change the code accordingly (and adjust READ_SIZE to sth. like 8 I suppose), however that rather sounds like the issue occurring &amp;quot;less likely&amp;quot; due to less loop cycles, as in hiding it instead of solving the issue.&lt;/p&gt;
&lt;p&gt;The freeze is a state I don&amp;#39;t know how to recover from and I can&amp;#39;t risk it happening - even if it&amp;#39;s &amp;quot;less likely&amp;quot; due to reading &amp;gt;1byte per loop cycle.&lt;/p&gt;
&lt;p&gt;So I&amp;#39;d really like to know what&amp;#39;s happening and how to get rid of the freeze for good.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Freeze of nrf52840 USB Dongle due to USB CDC-ACM data transfer</title><link>https://devzone.nordicsemi.com/thread/242821?ContentTypeID=1</link><pubDate>Wed, 01 Apr 2020 03:48:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5f521ce-f267-46e6-a037-290b8204ca62</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;I am having issues with something similar, and pushed it to one side. In this case the example only reads a singe byte at a time (what a strange example ..) and I see you modified that to attempt to read more, however this is now an issue:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ret = app_usbd_cdc_acm_read(&amp;amp;m_app_cdc_acm, &amp;amp;m_rx_buffer[++m_rx_buffer_pos], READ_SIZE);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I would suggest trying:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;m_rx_buffer_pos += READ_SIZE;
ret = app_usbd_cdc_acm_read(&amp;amp;m_app_cdc_acm, &amp;amp;m_rx_buffer[m_rx_buffer_pos], READ_SIZE);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;or:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ret = app_usbd_cdc_acm_read(&amp;amp;m_app_cdc_acm, &amp;amp;m_rx_buffer[m_rx_buffer_pos], READ_SIZE);
m_rx_buffer_pos += READ_SIZE;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Assuming each invocation reads READ_SIZE bytes from the USN buffer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>