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

app_scheduler and app_usbd_event_queue_process()

Hi,

I am wondering how to let these both run together.

If I understand the sdk_config correctly the app_scheduler event queue can be used for the USB directly. But how should this be done?
If I do #define APP_USBD_CONFIG_EVENT_QUEUE_ENABLE 0 I am getting errors that an isr_handler for USB is missing?

But in the commend of this define you write:

// <i> Disable it when an external queue is used like app_scheduler or if you wish to process all events inside interrupts.
// <i> Processing all events from the interrupt level adds requirement not to call any functions that modifies the USBD library state from the context higher than USB interrupt context.
// <i> Functions that modify USBD state are functions for sleep, wakeup, start, stop, enable, and disable.

But it does not state something on how to handle USB events in app_scheduler. I am getting performance and throughput
issues if I let it run together.

Kind regards,

Constantin

Parents
  • Hi Constantin,

    You need to provide an usb event handler yourself in this case, and pu tthe event into the scheduler queue. This is demonstrated by the USB bootloader example. You can see how it is done in components\libraries\bootloader\serial_dfu\nrf_dfu_serial_usb.c.

    Essentially you provide your own event handler when configuring the app_usbd module, and that event handler could be a copy of the one from the bootloader:

    static void usbd_event_handler(app_usbd_internal_evt_t const * const p_event)
    {
        ret_code_t ret_code;
        if (p_event->type == APP_USBD_EVT_DRV_SOF)
        {
            app_usbd_event_execute(p_event);
        }
        else
        {
            ret_code = app_sched_event_put(p_event,
                                           sizeof(app_usbd_internal_evt_t),
                                           usbd_sched_event_handler);
    
            if (ret_code != NRF_SUCCESS)
            {
                NRF_LOG_ERROR("Could not schedule USB event!");
            }
        }
    }
    

    Einar

Reply
  • Hi Constantin,

    You need to provide an usb event handler yourself in this case, and pu tthe event into the scheduler queue. This is demonstrated by the USB bootloader example. You can see how it is done in components\libraries\bootloader\serial_dfu\nrf_dfu_serial_usb.c.

    Essentially you provide your own event handler when configuring the app_usbd module, and that event handler could be a copy of the one from the bootloader:

    static void usbd_event_handler(app_usbd_internal_evt_t const * const p_event)
    {
        ret_code_t ret_code;
        if (p_event->type == APP_USBD_EVT_DRV_SOF)
        {
            app_usbd_event_execute(p_event);
        }
        else
        {
            ret_code = app_sched_event_put(p_event,
                                           sizeof(app_usbd_internal_evt_t),
                                           usbd_sched_event_handler);
    
            if (ret_code != NRF_SUCCESS)
            {
                NRF_LOG_ERROR("Could not schedule USB event!");
            }
        }
    }
    

    Einar

Children
No Data
Related