<?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>Request on demo which retargets log to USB port</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/118673/request-on-demo-which-retargets-log-to-usb-port</link><description>I&amp;#39;m studying with PCA10059,trying to build a gateway between BLE peripherals &amp;amp; PC. 
 For PCA10059 has build-in USB socket,and I will plug them into PC&amp;#39;s USB ports at last, it will be nice to output log to USB port too. 
 Would Nordic provide a demo on</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 08 Feb 2025 05:20:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/118673/request-on-demo-which-retargets-log-to-usb-port" /><item><title>RE: Request on demo which retargets log to USB port</title><link>https://devzone.nordicsemi.com/thread/522076?ContentTypeID=1</link><pubDate>Sat, 08 Feb 2025 05:20:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d3bcadd-ff88-42f1-a967-3a5fc579a667</guid><dc:creator>OldXiao</dc:creator><description>&lt;p&gt;Tried, found something,but don&amp;#39;t know why.&lt;/p&gt;
&lt;p&gt;First of all,we&amp;#39;d better devide the function into 2 parts:&lt;/p&gt;
&lt;p&gt;1)create instance&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void usb_init(void)
{
	
	  ret_code_t ret;
    static const app_usbd_config_t usbd_config = {
        .ev_state_proc = usbd_user_ev_handler
    };
	
    app_usbd_serial_num_generate();
    ret = app_usbd_init(&amp;amp;usbd_config);
    APP_ERROR_CHECK(ret);
    app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&amp;amp;m_app_cdc_acm);
    ret = app_usbd_class_append(class_cdc_acm);
    APP_ERROR_CHECK(ret);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;2)start USB&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void usb_start(void)
{
    ret_code_t ret;
	
		if (USBD_POWER_DETECTION)
    {
        ret = app_usbd_power_events_enable();
        APP_ERROR_CHECK(ret);
    }
    else
    {
        NRF_LOG_INFO(&amp;quot;No USB power detection enabled\r\nStarting USB now&amp;quot;);

        app_usbd_enable();
        app_usbd_start();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In main.c, usb_init() must call before&amp;nbsp;ble_stack_init() :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int main(void)
{
    log_init();
    timer_init();
    leds_init();
    buttons_init();
    power_management_init();
	
	  usb_init();//must before ble_stack_init();
	
    ble_stack_init();
    gatt_init();
    db_discovery_init();
    gtoi_c_init();
    ble_conn_state_init();
    scan_init();
    scan_start();
	
		usb_start();

    for (;;)
    {
			  while (app_usbd_event_queue_process())
        {
            /* Nothing to do */
        }
				
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I did not dig further,anyone interested can go on.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Request on demo which retargets log to USB port</title><link>https://devzone.nordicsemi.com/thread/522073?ContentTypeID=1</link><pubDate>Sat, 08 Feb 2025 03:01:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:933e57a1-6ae3-4156-b8ea-4c3baa6933fd</guid><dc:creator>OldXiao</dc:creator><description>&lt;p&gt;I have enabled UART log output,but not traced into each line.&lt;/p&gt;
&lt;p&gt;OK, I will trace it later.&lt;/p&gt;
&lt;p&gt;close this ticket pls.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Request on demo which retargets log to USB port</title><link>https://devzone.nordicsemi.com/thread/522017?ContentTypeID=1</link><pubDate>Fri, 07 Feb 2025 15:50:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0039ccad-d7ca-4679-a91b-5de8e4003abe</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I&amp;#39;m not sure I understand the last question and it is also hard to tell where it is failing without more information. But if you are going to do any active development, I strongly recommend you get a DK, or at least and external debug probe that you can connect to the dongle&amp;nbsp;so you can debug the code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Request on demo which retargets log to USB port</title><link>https://devzone.nordicsemi.com/thread/521920?ContentTypeID=1</link><pubDate>Fri, 07 Feb 2025 12:27:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3cc0b723-caa0-4961-ae77-12b770fd834e</guid><dc:creator>OldXiao</dc:creator><description>&lt;p&gt;Get it.&lt;/p&gt;
&lt;p&gt;How about my last question?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Request on demo which retargets log to USB port</title><link>https://devzone.nordicsemi.com/thread/521853?ContentTypeID=1</link><pubDate>Fri, 07 Feb 2025 06:30:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f5503fd-bba2-4879-932c-59b4bfab034f</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Unfortunately, the logger module does not have a USB CDC backend, only UART and RTT. If you want this, you would need to implement this yourself.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Request on demo which retargets log to USB port</title><link>https://devzone.nordicsemi.com/thread/521849?ContentTypeID=1</link><pubDate>Fri, 07 Feb 2025 03:57:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df303fbd-2174-43fe-8fab-c9f192e592c9</guid><dc:creator>OldXiao</dc:creator><description>&lt;p&gt;I understand your meaning.&lt;/p&gt;
&lt;p&gt;I can output my log to USB with USB write function, but I have to replace your log macro with mine to do so. So,it is impossible for me to replace all those log call in SDK functions. The right solution is retargeting the native log function/macro(NRF_LOG_INFO,e.g.) to USB in some low level.&lt;/p&gt;
&lt;p&gt;Maybe&amp;nbsp;we can add switch in configure file , then retarget the&amp;nbsp;real output to USB.&lt;/p&gt;
&lt;p&gt;I just followed the calling route to nrf_log_frontend.c, but not found the real output channel,tell me where to replace the call to UART transfer or RTT if possible.&lt;/p&gt;
&lt;p&gt;There is a question:&lt;/p&gt;
&lt;p&gt;Ref to the example, USB VCP rised in Win10 with code in main.c:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int main(void)
{
	  ret_code_t ret;
    static const app_usbd_config_t usbd_config = {
        .ev_state_proc = usbd_user_ev_handler
    };
	
    log_init();
    timer_init();
    leds_init();
    buttons_init();

    //ret = nrf_drv_clock_init();
    //APP_ERROR_CHECK(ret);
    app_usbd_serial_num_generate();
    ret = app_usbd_init(&amp;amp;usbd_config);
    APP_ERROR_CHECK(ret);
    app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&amp;amp;m_app_cdc_acm);
    ret = app_usbd_class_append(class_cdc_acm);
    APP_ERROR_CHECK(ret);

    power_management_init();
	
	
    ble_stack_init();
    gatt_init();
    db_discovery_init();
    gtoi_c_init();
    ble_conn_state_init();
    scan_init();
    scan_start();

    if (USBD_POWER_DETECTION)
    {
        ret = app_usbd_power_events_enable();
        APP_ERROR_CHECK(ret);
    }
    else
    {
        NRF_LOG_INFO(&amp;quot;No USB power detection enabled\r\nStarting USB now&amp;quot;);

        app_usbd_enable();
        app_usbd_start();
    }
		
	  //usbd_init();

    for (;;)
    {
			  while (app_usbd_event_queue_process())
        {
            /* Nothing to do */
        }
				
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But it will trigger error(after start BLE scan) if I collect all code related to USB in one function and call it at the end:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int main(void)
{
 	  /*  
	  ret_code_t ret;
    static const app_usbd_config_t usbd_config = {
        .ev_state_proc = usbd_user_ev_handler
    };
	  */
    log_init();
    timer_init();
    leds_init();
    buttons_init();

	  /*
    //ret = nrf_drv_clock_init();
    //APP_ERROR_CHECK(ret);
    app_usbd_serial_num_generate();
    ret = app_usbd_init(&amp;amp;usbd_config);
    APP_ERROR_CHECK(ret);
    app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&amp;amp;m_app_cdc_acm);
    ret = app_usbd_class_append(class_cdc_acm);
    APP_ERROR_CHECK(ret);
    */
    power_management_init();
	
	
    ble_stack_init();
    gatt_init();
    db_discovery_init();
    gtoi_c_init();
    ble_conn_state_init();
    scan_init();
    scan_start();
    /*
    if (USBD_POWER_DETECTION)
    {
        ret = app_usbd_power_events_enable();
        APP_ERROR_CHECK(ret);
    }
    else
    {
        NRF_LOG_INFO(&amp;quot;No USB power detection enabled\r\nStarting USB now&amp;quot;);

        app_usbd_enable();
        app_usbd_start();
    }
		*/
	  usbd_init();

    for (;;)
    {
			  while (app_usbd_event_queue_process())
        {
            /* Nothing to do */
        }
				
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I think some initializations not completed, what is the basic rule to call those functions?&lt;/p&gt;
&lt;p&gt;Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Request on demo which retargets log to USB port</title><link>https://devzone.nordicsemi.com/thread/521714?ContentTypeID=1</link><pubDate>Thu, 06 Feb 2025 12:29:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6c76827-6135-476b-ae4f-645bc7817925</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Please have a look at the sample project posted here:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/85185/nrf52840-dongle-usb-cdc-acm"&gt;nRF52840 dongle usb cdc acm&lt;/a&gt;&amp;nbsp;. It is based on the&amp;nbsp;&lt;a title="USBD BLE UART Example" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/usbd_ble_uart_example.html?cp=8_1_4_6_50_1"&gt;USBD BLE UART Example&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>