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

PCA10056 USB CDC Demo, no polling

Hello, I am trying to modify the usbd_cdc_acm_modified example project in the SDK to do the following:

  1. Echo the received character back to the terminal.
  2. Get rid of the main while loop polling while (app_usbd_event_queue_process()) so that everything is handled within interrupts. This should be possible based on this statement in the USB Device Library documentation:

"After starting the library, the whole stack starts to work. All processing required by the standard is done in the interrupts. It means that no more processing in any main loop is required for the USB to work."

I was able to accomplish #1 easily enough. I am still stuck on #2.

I modified power_usb_event_handler to implement the following statement:

"This may be done inside USB power event handler. USBD library should be enabled on NRF_DRV_POWER_USB_EVT_DETECTED and started on NRF_DRV_POWER_USB_EVT_READY."

Here is the modified function:


static void power_usb_event_handler(nrf_drv_power_usb_evt_t event) {

switch (event)
{
    case NRF_DRV_POWER_USB_EVT_DETECTED:
        NRF_LOG_INFO("USB power detected");

        if (!nrf_drv_usbd_is_enabled())
        {
            app_usbd_enable();
        }
        break;
    case NRF_DRV_POWER_USB_EVT_REMOVED:
        NRF_LOG_INFO("USB power removed");
        m_usb_connected = false;
					
    app_usbd_stop();
        break;
    case NRF_DRV_POWER_USB_EVT_READY:
        NRF_LOG_INFO("USB ready");
        m_usb_connected = true;
			
    app_usbd_start();				
        break;
    default:
        ASSERT(false);
}

}

Notice I added app_usbd_stop() and app_usbd_start()...

This still does not work unless app_usbd_event_queue_process() is called within the while() loop in main. I tried to comment it out, and set

#define APP_USBD_EVENT_QUEUE_ENABLE 0

but I don't get any received characters.

I am using Keil, PCA10056 and the latest SDK 14.2.0

Any help would be appreciated!

Parents
  • Hey, there. I don't know if I'm years late or not. I was looking at USB CDC example and got it working per the infocenter statement:

    "This may be done inside USB power event handler. USBD library should be enabled on NRF_DRV_POWER_USB_EVT_DETECTED and started on NRF_DRV_POWER_USB_EVT_READY."

    What I had to do is to go on the project sdk_config.h and set APP_USBD_CONFIG_SOF_HANDLING_MODE to 2 (events are handled within interrupt context). Also, set APP_USBD_CONFIG_EVENT_QUEUE_ENABLE to 0.

    I hope it is of any help to someone wondering the same when looking at USB ACM example.

    Best regards, 
    LuisF

Reply
  • Hey, there. I don't know if I'm years late or not. I was looking at USB CDC example and got it working per the infocenter statement:

    "This may be done inside USB power event handler. USBD library should be enabled on NRF_DRV_POWER_USB_EVT_DETECTED and started on NRF_DRV_POWER_USB_EVT_READY."

    What I had to do is to go on the project sdk_config.h and set APP_USBD_CONFIG_SOF_HANDLING_MODE to 2 (events are handled within interrupt context). Also, set APP_USBD_CONFIG_EVENT_QUEUE_ENABLE to 0.

    I hope it is of any help to someone wondering the same when looking at USB ACM example.

    Best regards, 
    LuisF

Children
No Data
Related