Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Request on demo which retargets log to USB port

I'm studying with PCA10059,trying to build a gateway between BLE peripherals &  PC.

For PCA10059 has build-in USB socket,and I will plug them into PC's USB ports at last, it will be nice to output log to USB port too.

Would Nordic provide a demo on this?just re-target log to USB port,so can I go on base on that.

My basic thought:

1) application data & log sharing the same USB channel;

2) Differentiate them with packet type.

I can monitor BLE peripherals with this technical too.

  • I have enabled UART log output,but not traced into each line.

    OK, I will trace it later.

    close this ticket pls. 

    Thank you.

  • Tried, found something,but don't know why.

    First of all,we'd better devide the function into 2 parts:

    1)create instance

    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(&usbd_config);
        APP_ERROR_CHECK(ret);
        app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm);
        ret = app_usbd_class_append(class_cdc_acm);
        APP_ERROR_CHECK(ret);
    }

    2)start USB

    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("No USB power detection enabled\r\nStarting USB now");
    
            app_usbd_enable();
            app_usbd_start();
        }
    }

    In main.c, usb_init() must call before ble_stack_init() :

    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();
        }
    }

    I did not dig further,anyone interested can go on.

Related