<?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>52840 USB CDC missed first byte in RX event</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/40431/52840-usb-cdc-missed-first-byte-in-rx-event</link><description>Hi, 
 
 I used 52840DK and SDK15.2 to test usb cdc, every thing goes will, but in rx event, it always missed first byte, for example, if send &amp;quot;123456&amp;quot;, it just received &amp;quot;23456&amp;quot;, if send just &amp;quot;1&amp;quot;, there is no rx event. though I can see the first byte right</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 05 Aug 2020 17:42:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/40431/52840-usb-cdc-missed-first-byte-in-rx-event" /><item><title>RE: 52840 USB CDC missed first byte in RX event</title><link>https://devzone.nordicsemi.com/thread/263307?ContentTypeID=1</link><pubDate>Wed, 05 Aug 2020 17:42:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ca26aa9-cbe9-4266-978b-cf361c04caf6</guid><dc:creator>OPCODE</dc:creator><description>&lt;p&gt;I have a similar issue with the SDK17 with&amp;nbsp;&lt;/p&gt;
&lt;p&gt;APP_USBD_CONFIG_EVENT_QUEUE_ENABLE = 0&lt;/p&gt;
&lt;p&gt;APP_USBD_CONFIG_SOF_HANDLING_MODE = 2&lt;/p&gt;
&lt;p&gt;On carriage return, the next character is lost.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                    app_usbd_cdc_acm_user_event_t event)
{
    app_usbd_cdc_acm_t const * p_cdc_acm = app_usbd_cdc_acm_class_get(p_inst);

    switch (event)
    {
        case APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN:
        {
            /*Set up the first transfer*/
            ret_code_t ret = app_usbd_cdc_acm_read(&amp;amp;m_app_cdc_acm, m_cdc_data_array, 1); // necessary it seems
            //NRF_LOG_INFO(&amp;quot;CDC ACM port opened&amp;quot;);
            break;
        }

        case APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE:
            //NRF_LOG_INFO(&amp;quot;CDC ACM port closed&amp;quot;);
            break;

        case APP_USBD_CDC_ACM_USER_EVT_TX_DONE:
            break;

        case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
        {
            ret_code_t ret;
            nrf_gpio_pin_write(LED_2,0);
            do{
                    ret = app_usbd_cdc_acm_read(&amp;amp;m_app_cdc_acm, &amp;amp;m_cdc_data_array[buffer_available_idx++], 1);  
            }while (ret == NRF_SUCCESS);
            nrf_gpio_pin_write(LED_2,1);
            break;
        }
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In the main loop i have something like&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        if (buffer_available_idx){
                app_usbd_cdc_acm_write(&amp;amp;m_app_cdc_acm, m_cdc_data_array, strlen(m_cdc_data_array));
                memset(m_cdc_data_array, 0, RECV_BUF_LEN);
                buffer_available_idx=0;
        }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If I type alot of characters they are all echoed fine by the above code. Only when I press carriage return, the next character after CR is lost. Tried this with 2 terminal programs.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 52840 USB CDC missed first byte in RX event</title><link>https://devzone.nordicsemi.com/thread/234443?ContentTypeID=1</link><pubDate>Fri, 14 Feb 2020 14:13:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c8ee15c-ce29-4187-acc7-9ecb89478c47</guid><dc:creator>Pertti Kasanen</dc:creator><description>&lt;p&gt;I stumble into a similar problem, using SDK 16.0.0. After trying and failing with many experiments, I found a workaround that worked for me.&lt;br /&gt;In my case the first RX worked fine but (seemingly somewhat depending on what was done in the processing of the RX), the next byte was missing form the next RX &amp;quot;lines&amp;quot; from USB. The processing did send data back to USB with app_usbd_cdc_acm_write()&lt;/p&gt;
&lt;p&gt;Adding a app_usbd_cdc_acm_read_any() call to &amp;quot;case APP_USBD_CDC_ACM_USER_EVT_TX_DONE:&amp;quot; handling solved the issue and now I&amp;#39;m getting also the first character of the line.&lt;/p&gt;
&lt;pre&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;        case APP_USBD_CDC_ACM_USER_EVT_TX_DONE:
            //bsp_board_led_invert(LED_CDC_ACM_TX);
            ret = app_usbd_cdc_acm_read_any(&amp;amp;m_app_cdc_acm,
                                        m_rx_buffer,
                                        1);
            break;&lt;/pre&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 52840 USB CDC missed first byte in RX event</title><link>https://devzone.nordicsemi.com/thread/168667?ContentTypeID=1</link><pubDate>Wed, 30 Jan 2019 11:08:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e61f148f-c6dc-4e9a-afe3-b4e50de2a2d3</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;This is good to hear, thanks for confirming. The example has been tested quite extensively by the SDK team so I think it&amp;#39;s likely that I too did something wrong when I tested it earlier.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 52840 USB CDC missed first byte in RX event</title><link>https://devzone.nordicsemi.com/thread/168654?ContentTypeID=1</link><pubDate>Wed, 30 Jan 2019 10:14:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5d0de82-f790-4e2d-95ec-1948f68e3f60</guid><dc:creator>Juan</dc:creator><description>&lt;p&gt;Yes, it is working for me now. Actually, there was not a bug. It was a concept mistake. But now things are clear for me.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 52840 USB CDC missed first byte in RX event</title><link>https://devzone.nordicsemi.com/thread/168628?ContentTypeID=1</link><pubDate>Wed, 30 Jan 2019 08:56:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:710eff92-363e-4d6d-aea1-c97dcc4ccb06</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/yqin15"&gt;yqin15&lt;/a&gt;,&lt;a href="https://devzone.nordicsemi.com/members/drk_5f00_tg"&gt;drk_tg&lt;/a&gt;,&amp;nbsp; @Juan, for some reason I&amp;#39;m not able to replicate this issue anymore, nor is the developer who is tasked with&amp;nbsp;fixing it. This is how I&amp;#39;m testing it:&lt;/p&gt;
&lt;p&gt;- First I build and program the example from SDK 15.2.0 using SES then open a separate serial terminal to view the debug log&lt;/p&gt;
&lt;p&gt;- Use realterm serial client to send a text string through the nRF USB&lt;/p&gt;
&lt;p&gt;- Check if all data gets received by inspecting the debug log&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/6443.Capture.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;Please let me know if you are testing it differently so that I can try the same here.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the .hex file used:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/usbd_5F00_cdc_5F00_acm_5F00_pca10056.hex"&gt;devzone.nordicsemi.com/.../usbd_5F00_cdc_5F00_acm_5F00_pca10056.hex&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 52840 USB CDC missed first byte in RX event</title><link>https://devzone.nordicsemi.com/thread/165686?ContentTypeID=1</link><pubDate>Tue, 15 Jan 2019 09:54:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29badeb1-c96f-4956-8830-bd76833379ff</guid><dc:creator>drk_tg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Any updates about this issue? &lt;span class="tlid-translation translation"&gt;&lt;span class="" title=""&gt;Will the patch be available in the next release of the SDK?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="tlid-translation translation"&gt;&lt;span class="" title=""&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="tlid-translation translation"&gt;&lt;span class="" title=""&gt;Best,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="tlid-translation translation"&gt;&lt;span class="" title=""&gt;Chris&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 52840 USB CDC missed first byte in RX event</title><link>https://devzone.nordicsemi.com/thread/164311?ContentTypeID=1</link><pubDate>Mon, 07 Jan 2019 14:37:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f695967-5915-4c28-8714-44bb3a0ffb8a</guid><dc:creator>Juan</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have the same problem reported by Brian. I have solved it with the &amp;quot;solution&amp;quot; you provided. However, you mention that this is not recommended.&lt;/p&gt;
&lt;p&gt;Is there any recomended solution? We are developing a prototype and we would like to have a stable code as soon as possible.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;JuanFran&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: 52840 USB CDC missed first byte in RX event</title><link>https://devzone.nordicsemi.com/thread/157119?ContentTypeID=1</link><pubDate>Tue, 13 Nov 2018 14:18:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ddc4401-ae0b-4120-a3cb-a8b0452e3ed8</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Brian,&lt;/p&gt;
&lt;p&gt;Was able to reproduce the exact same behavior here and it seems to be caused by a logical error in the app_usbd_cdc_acm.c-&amp;gt;cdc_acm_rx_block_finished() implementation. It &amp;quot;worked&amp;quot; when I commented out the following lines:&lt;/p&gt;
&lt;p&gt;// First buffer is full&lt;br /&gt; p_cdc_acm_ctx-&amp;gt;last_read = p_cdc_acm_ctx-&amp;gt;bytes_read; &lt;strong&gt;//+ bytes_to_cpy;&lt;/strong&gt;&lt;br /&gt; p_cdc_acm_ctx-&amp;gt;bytes_read = 0;&lt;br /&gt; p_cdc_acm_ctx-&amp;gt;bytes_left = bytes_read; &lt;strong&gt;// - bytes_to_cpy;&lt;/strong&gt;&lt;br /&gt; p_cdc_acm_ctx-&amp;gt;p_copy_pos = p_cdc_acm_ctx-&amp;gt;internal_rx_buf&lt;strong&gt;;// + bytes_to_cpy;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;However, it breaks the buffer switching so would not suggest to make this change. I have reported it as a bug internally.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>