This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

questions on usbd_cdc_acm example

Hi,

two days ago I started checking the usbd_cdc_acm example in order to add usb serial comm functionality to my project. and I have some fundamental (newbie) questions.

1. Why nrf_drv_clock_lfclk_request(NULL) is being used outside the usbd library? And how does the program "know" that the lfclck is being used for the usbd functionality since there is no link between those two? I assume that lfclk is used for the usb module  because when I remove this part the USB does not function   :)   

    ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
    
    nrf_drv_clock_lfclk_request(NULL);

    while(!nrf_drv_clock_lfclk_is_running())
    {
        /* Just waiting */
    }

    ret = app_timer_init();
    APP_ERROR_CHECK(ret);

2. I don't understand the USBD_POWER_DETECTION part. If I place directly the  app_usbd_enable(); and  app_usbd_start(); directly in the code without the if case, the device is recognized as before without issues. So, why does if (USBD_POWER_DETECTION) case  exist? Also from the event handling function I see that the same app_usbd_start()/enable(); functions are being used so what is the difference and why this if/else case is being used in the first place?

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

3. If I place an nrf_delay_ms(500)  after the usbd_cdc_acm_write the device appears in the device manager, the terminal app I use is successfully connected to the device ( LED 2 = ON) but data do not appear on the terminal display and LED 4 is always off.

if(m_send_flag)
{
    static int  frame_counter;

    size_t size = sprintf(m_tx_buffer, "Hello USB CDC FA demo: %u\r\n", frame_counter);

    ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, size);
    if (ret == NRF_SUCCESS)
    {
        ++frame_counter;
    }
    nrf_delay_ms(500);    //      <<==================
}

4. If I erase the previous part included in if(m_send_flag)  and I just replace it with the following part to send cntr value (just a counter for test) every 150msec to the PC terminal app

the device is not recognized at all. Why is this happening

size_t size = sprintf(m_tx_buffer, "Counter Value: %u\r\n", cntr);
ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, size);
cntr++;
nrf_delay_ms(150);        
        

Best regards

Thank you for your time!

Related