<?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>The function that could get the data from the computer in nRF5 SDK at any time</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/90500/the-function-that-could-get-the-data-from-the-computer-in-nrf5-sdk-at-any-time</link><description>Hi, 
 I use the modified version of the USBD example(nRF5_SDK_17.1.0_ddde560\examples\peripheral\usbd) in nRF5 SDK from here . (My development kit is nRF52840DK.) 
 And I would like to add some funtions like the peripheral_uart sample(ncs\v1.7.0\nrf\samples</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 12 Sep 2022 05:31:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/90500/the-function-that-could-get-the-data-from-the-computer-in-nrf5-sdk-at-any-time" /><item><title>RE: The function that could get the data from the computer in nRF5 SDK at any time</title><link>https://devzone.nordicsemi.com/thread/385626?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 05:31:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ff7148d-336e-4e7c-8243-a89285e1e8cc</guid><dc:creator>425Ning</dc:creator><description>&lt;p style="text-align:left;"&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p style="text-align:left;"&gt;OK. I&amp;#39;ll try both the FIFO library and the USB CDC ACM example.&lt;/p&gt;
&lt;p style="text-align:left;"&gt;Thanks for your replying!&amp;nbsp;&lt;/p&gt;
&lt;p style="text-align:left;"&gt;Best regards,&lt;/p&gt;
&lt;p style="text-align:left;"&gt;Ning&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function that could get the data from the computer in nRF5 SDK at any time</title><link>https://devzone.nordicsemi.com/thread/384062?ContentTypeID=1</link><pubDate>Wed, 31 Aug 2022 08:06:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a620ad39-022a-403a-98a5-0405058bbdba</guid><dc:creator>Einar Thorsrud</dc:creator><description>[quote user="425Ning"]&lt;p&gt;I found that the use of the FIFO library in nRF5 is for UART data transfer, but what I need is&lt;/p&gt;
&lt;p&gt;• a function that can handle data transfer between the computer and the board through the &lt;strong&gt;USB endpoint&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;p&gt;&lt;span&gt;•&amp;nbsp;any action or function that could call the&amp;nbsp;NRF_DRV_USBD_EVT_EPTRANSFER event, so that the receive_custom_data() function can work&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;I see, so the question here is about buffering data that is to be&lt;span&gt;&amp;nbsp;&lt;/span&gt;sent&lt;span&gt;&amp;nbsp;&lt;/span&gt;via USB, and/or received via USB? In that case, you can use same as you did with UART. For instance, for outgoing data you have:&lt;/p&gt;
&lt;p&gt;&amp;lt;data source&amp;gt; --&amp;gt; &amp;lt;FIFO buffer&amp;gt; --&amp;gt; &amp;lt;Transport out (e.g. UART or USB)&amp;gt;&lt;/p&gt;
&lt;p&gt;The buffering part here is independent.&lt;/p&gt;
&lt;p&gt;Referring to your code snippet from the example I see you have a&amp;nbsp;&lt;code&gt;receive_custom_data()&lt;/code&gt; function where you added a comment &amp;quot;//here&amp;quot;. Does that mean that it is at this point you wan to buffer incoming data for instance? If so, you can use the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_fifo.html"&gt;FIFO library&lt;/a&gt;. The logic around it to do whatever you want to do with the data is up to you.&lt;/p&gt;
[quote user="425Ning"]Another problem I have is that the RTT Viewer seems to only be able to transfer&amp;nbsp;data through the JLINK CDC UART Port and cannot&amp;nbsp;transfer data through the nRF5 USB port.[/quote]
&lt;p&gt;RTT works by storing data in RAM, and the Segger debugger reading it out. It is not possible to use RTT via the USB port.&lt;/p&gt;
[quote user="425Ning"]If I understand it correctly, is there any other tool that can transfer data through the nRF5 USB port?[/quote]
&lt;p&gt;If you want to do logging via USB you need something else, for instance CDC-ACM, as demonstrated by the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/usbd_cdc_acm_example.html"&gt;USB CDC ACM Example&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function that could get the data from the computer in nRF5 SDK at any time</title><link>https://devzone.nordicsemi.com/thread/383980?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 16:04:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94242787-855a-431d-81f5-9fe5a62dace9</guid><dc:creator>425Ning</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I use nRF5 SDK. And the example that I use is from &lt;a title="usbd-custom-hid-ep_example" href="https://github.com/too1/nrf52-usbd-custom-hid-ep"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I found that the use of the FIFO library in nRF5 is for UART data transfer, but what I need is&lt;/p&gt;
&lt;p&gt;&amp;bull; a function that can handle data transfer between the computer and the board through the &lt;strong&gt;USB endpoint&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;bull;&amp;nbsp;any action or function that could call the&amp;nbsp;NRF_DRV_USBD_EVT_EPTRANSFER event, so that the receive_custom_data() function can work&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void usbd_event_handler(nrf_drv_usbd_evt_t const * const p_event)
{
    switch (p_event-&amp;gt;type)
    {
    ...
    case NRF_DRV_USBD_EVT_EPTRANSFER:
        if (NRF_DRV_USBD_EPIN2 == p_event-&amp;gt;data.eptransfer.ep)
        {
            NRF_LOG_INFO(&amp;quot;EP2IN transfer complete&amp;quot;);
        }
        else if (NRF_DRV_USBD_EPOUT2 == p_event-&amp;gt;data.eptransfer.ep)
        {
            NRF_LOG_INFO(&amp;quot;EP2OUT transfer complete&amp;quot;);
            receive_custom_data();  //here
        }
        ...
        break;
    ...
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Another problem I have is that the RTT Viewer seems to only be able to transfer&amp;nbsp;data through the JLINK CDC UART Port and cannot&amp;nbsp;transfer data through the nRF5 USB port.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Is my understanding correct?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If I understand it correctly, is there any other tool that can transfer data through the nRF5 USB port?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If I understand it wrong, how should I use it correctly?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Ning&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function that could get the data from the computer in nRF5 SDK at any time</title><link>https://devzone.nordicsemi.com/thread/383955?ContentTypeID=1</link><pubDate>Tue, 30 Aug 2022 13:45:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a22b710f-1e42-4f2a-8a80-1c397be497d8</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Ning,&lt;/p&gt;
&lt;p&gt;I am a bit confused as I see both nRF5 SDK and nRF Connect SDK code referred here. What do you want to use? And is it so that the question is how you can use a buffer/queue/FIFO? Please elaborate.&lt;/p&gt;
&lt;p&gt;Also, I see you added screenshots of RTT logger, but not of what else you do nor what you would expect to be logged.&lt;/p&gt;
&lt;p&gt;In short, please try to describe in more detail:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What do you want to accomplish?&lt;/li&gt;
&lt;li&gt;How have you done it?&lt;/li&gt;
&lt;li&gt;In which way does it not work?&lt;/li&gt;
&lt;li&gt;What have you found while debugging?&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function that could get the data from the computer in nRF5 SDK at any time</title><link>https://devzone.nordicsemi.com/thread/383737?ContentTypeID=1</link><pubDate>Mon, 29 Aug 2022 16:08:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac706775-7df1-43b5-b9ba-d8497982bf0d</guid><dc:creator>425Ning</dc:creator><description>&lt;p&gt;Sorry for the late reply...&lt;/p&gt;
&lt;p&gt;Both of the functions I would like to add to my project.&lt;/p&gt;
&lt;p&gt;According to your suggestions, I add the program below to my main function.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int main(void)
{
    ...
    // Create a FIFO structure
    app_fifo_t my_fifo;
    // Create a buffer for the FIFO
    uint16_t buffer_size = 8;
    uint8_t buffer[buffer_size];
    // Initialize FIFO structure
    uint32_t err_code = app_fifo_init(&amp;amp;my_fifo, buffer, (uint16_t)sizeof(buffer));
    if(!app_fifo_get(&amp;amp;my_fifo, buffer))
    {
        NRF_LOG_INFO(&amp;quot;fifoget %d = NRF_SUCCESS&amp;quot;, buffer[0]);
    }
    ...
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then I test it on RTT Viewer to confirm whether the board receive the data that I send.&lt;/p&gt;
&lt;p&gt;I select the &amp;quot;USB&amp;quot; option, and then click &amp;quot;OK&amp;quot; as the picture below.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1661788157989v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;However, it only shows the warning messages but not the success messages.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1661788125164v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;It seems like the board didn&amp;#39;t get any data from the PC.&lt;/p&gt;
&lt;p&gt;How could I solve this problem? Or...Should I use another function?&lt;/p&gt;
&lt;p&gt;And I also need a thread functionality. Thanks!!&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Ning&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The function that could get the data from the computer in nRF5 SDK at any time</title><link>https://devzone.nordicsemi.com/thread/379289?ContentTypeID=1</link><pubDate>Fri, 29 Jul 2022 11:01:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:48549de5-8d96-4969-add4-7b2d7d1ea78d</guid><dc:creator>AHaug</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;Could you verify what functions you would like to add to your nRF5 project? Is it the thread functionality that handles data transmission over Bluetooth with NUS, or is it the k_fifo-functionality? If it is the latter, then I would recommend you take a look at&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.0.0%2Flib_fifo.html"&gt;the fifo library in nRF5&lt;/a&gt;&amp;nbsp;documentation for more info!&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Let me know if this solves your issue!&lt;/p&gt;
&lt;p&gt;Kind regarrds,&lt;br /&gt;Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>