<?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>Transparent CDC to NUS bridge</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/111038/transparent-cdc-to-nus-bridge</link><description>Hi I&amp;#39;m trying to create a transparent CDC to NUS bridge, this is based on the nrf52840 dongle. 
 
 The Aim of this is to send binary files to our device from a PC, our device is running NUS Peripheral. 
 
 The PC will control the chunk sizes and speed</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 15 May 2024 07:38:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/111038/transparent-cdc-to-nus-bridge" /><item><title>RE: Transparent CDC to NUS bridge</title><link>https://devzone.nordicsemi.com/thread/483402?ContentTypeID=1</link><pubDate>Wed, 15 May 2024 07:38:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:494dc014-59f2-4cd6-ac09-2ae2b1d01059</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Lee&lt;/p&gt;
&lt;p&gt;I will help Sigurd with this case as I have more experience with the nRF5 SDK.&amp;nbsp;&lt;/p&gt;
[quote user="sleeper"]&lt;p&gt;app_usbd_cdc_acm_read is called in&amp;nbsp;APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN&lt;/p&gt;
&lt;p&gt;I&amp;#39;m assuming this just sets up the buffer and transfer size ?&lt;/p&gt;[/quote]
&lt;p&gt;Correct. You need to provide a read buffer to the driver, and define the size of the buffer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the standard example the buffer is set to 1 byte, in order to provide an interrupt for every received byte. Did you try to increase this value?&amp;nbsp;&lt;/p&gt;
[quote user="sleeper"]So when data arrives you will get a&amp;nbsp;APP_USBD_CDC_ACM_USER_EVT_RX_DONE event, this means the data of transfer size was moved to the buffer that was specified ?[/quote]
&lt;p&gt;Correct. In case you provide a larger buffer I think you can also receive smaller updates (where the size is smaller than the buffer size), in case a small packet is sent from the host side, which is why you need to read the rx_size as shown in the example.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regarding your program flow,&amp;nbsp;you might want to consider using some kind of FIFO in main to buffer the data before you send it over BLE.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Technically it should be fine to call BLE functions directly from the callback, since the USB callback is run from main context through the call to&amp;nbsp;&lt;em&gt;app_usbd_event_queue_process(), &lt;/em&gt;but decoupling the BLE transmission from the callback still has advantages. For one thing it would allow you to wait to send anything over BLE until you have received enough data to&amp;nbsp;fully utilize the BLE data length (244 bytes ideally). Second, it would allow you to properly handle the case where the BLE send call fails because of full buffers in the SoftDevice.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transparent CDC to NUS bridge</title><link>https://devzone.nordicsemi.com/thread/483262?ContentTypeID=1</link><pubDate>Tue, 14 May 2024 11:51:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e9e9190-36ee-4814-993b-28582ab774f3</guid><dc:creator>sleeper</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/sigurd-hellesvik"&gt;Sigurd Hellesvik&lt;/a&gt;&amp;nbsp; can you help please&lt;/p&gt;
&lt;p&gt;app_usbd_cdc_acm_read is called in&amp;nbsp;APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN&lt;/p&gt;
&lt;p&gt;I&amp;#39;m assuming this just sets up the buffer and transfer size ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So when data arrives you will get a&amp;nbsp;APP_USBD_CDC_ACM_USER_EVT_RX_DONE event, this means the data of transfer size was moved to the buffer that was specified ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Surely it would be better to have this when&amp;nbsp;&lt;span&gt;APP_USBD_CDC_ACM_USER_EVT_RX_DONE&amp;nbsp;is triggered&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Query amount of data received, and then transfer that data to your buffer ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transparent CDC to NUS bridge</title><link>https://devzone.nordicsemi.com/thread/482844?ContentTypeID=1</link><pubDate>Fri, 10 May 2024 14:41:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af6ab7dc-24f2-4e96-9939-c9df24071c06</guid><dc:creator>sleeper</dc:creator><description>&lt;p&gt;This is not solved but it could be my understanding of the&amp;nbsp;APP_USBD_CDC_ACM_USER_EVT_RX_DONE event.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What I&amp;#39;m wanting to do is send a binary file. This will be sent in 64B(this could be bigger or smaller does not matter really) chunks.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;APP_USBD_CDC_ACM_USER_EVT_RX_DONE&amp;nbsp;seems to be call every byte&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transparent CDC to NUS bridge</title><link>https://devzone.nordicsemi.com/thread/482763?ContentTypeID=1</link><pubDate>Fri, 10 May 2024 10:26:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:53acb89d-8ae0-4c4f-945d-3e3dc8ad30d6</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;I see that you were able to solve this.&lt;/p&gt;
&lt;p&gt;Let us know if you need anything else, and feel free to press &amp;quot;verify as answer&amp;quot; on your solution to close this ticket&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Transparent CDC to NUS bridge</title><link>https://devzone.nordicsemi.com/thread/482652?ContentTypeID=1</link><pubDate>Thu, 09 May 2024 10:30:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da307230-bccc-4ffa-8a3f-e36de4e49ea1</guid><dc:creator>sleeper</dc:creator><description>&lt;p&gt;This seemed to work&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
            {
                ret_code_t ret;
                size_t total = 0;

                do
                {
                    /*Get amount of data transfered*/
                    size_t size = app_usbd_cdc_acm_rx_size(p_cdc_acm);

                    /* Fetch data until internal buffer is empty */
                    ret = app_usbd_cdc_acm_read(p_cdc_acm,
                                                &amp;amp;m_cdc_data_array[0],
                                                size);
                    total += size;

                } while (ret == NRF_SUCCESS);

                NRF_LOG_INFO(&amp;quot;CDC RX: size: %lu&amp;quot;, total);

                ret = ble_nus_c_string_send(&amp;amp;m_ble_nus_c,
                                        (uint8_t *)&amp;amp;m_cdc_data_array[0],
                                        total);

                NRF_LOG_INFO(&amp;quot;NUS TX: size: %lu&amp;quot;, total);
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>