NRF52840 combine USBD CLI, USBD HID, COM port can not connect.

hi, I am working on to combine USBD CLI and RTT to USB HID with SDK 17.10, configuration as below

static void usbd_user_ev_handler(app_usbd_event_type_t event) {
    switch (event) {
        case APP_USBD_EVT_DRV_SOF:
            break;
        case APP_USBD_EVT_DRV_RESET:
            m_report_pending = false;
            break;
        case APP_USBD_EVT_DRV_SUSPEND:  // 3
            m_report_pending = false;
            app_usbd_suspend_req();  // Allow the library to put the peripheral into sleep mode
            break;
        case APP_USBD_EVT_DRV_RESUME:  // 4
            m_report_pending = false;
            kbd_status(); /* Restore LED state - during SUSPEND all LEDS are turned off */
            break;
        case APP_USBD_EVT_STARTED:  // 2
            m_report_pending = false;
            set_output(OUTPUT_USB);
            break;
        case APP_USBD_EVT_STOPPED:
            app_usbd_disable();
            break;
        case APP_USBD_EVT_POWER_DETECTED:  // 0
            NRF_LOG_INFO("USB power detected");
            if (!nrf_drv_usbd_is_enabled()) {
                app_usbd_enable();
            }
            break;
        case APP_USBD_EVT_POWER_REMOVED:
            NRF_LOG_INFO("USB power removed");
            app_usbd_stop();
            advertising_restart(false);
            (void)nrf_cli_uninit(&m_cli_cdc_acm);
            break;
        case APP_USBD_EVT_POWER_READY: {  // 1
            ret_code_t ret;
            NRF_LOG_INFO("USB ready");
            app_usbd_start();
            if (nrf_sdh_is_enabled()) ble_disconnect();
            set_output(OUTPUT_USB);
            ret = nrf_cli_init(&m_cli_cdc_acm, NULL, true, true, NRF_LOG_SEVERITY_INFO);
            APP_ERROR_CHECK(nrf_cli_task_create(&m_cli_cdc_acm));
            APP_ERROR_CHECK(ret);
        } break;
        default:
            break;
    }
}

void usb_keyboard_init(void) {
    ret_code_t                     ret;

    static const app_usbd_config_t usbd_config = {
        .ev_handler = app_usbd_event_execute,
        .ev_state_proc = usbd_user_ev_handler};

    ret = app_usbd_init(&usbd_config);
    APP_ERROR_CHECK(ret);

    app_usbd_class_inst_t const *class_inst_kbd;
    class_inst_kbd = app_usbd_hid_generic_class_inst_get(&m_app_hid_kbd);
    ret            = app_usbd_class_append(class_inst_kbd);
    APP_ERROR_CHECK(ret);

    app_usbd_class_inst_t const * class_cli_cdc_acm;
    class_cli_cdc_acm = app_usbd_cdc_acm_class_inst_get(&nrf_cli_cdc_acm);
    ret = app_usbd_class_append(class_cli_cdc_acm);
    APP_ERROR_CHECK(ret);

    NRF_LOG_INFO("USBD HID composite example started.");
    
    ret = nrf_cli_init(&m_cli_rtt, NULL, true, true, NRF_LOG_SEVERITY_INFO);
    APP_ERROR_CHECK(ret);
    
    APP_ERROR_CHECK(nrf_cli_task_create(&m_cli_rtt));
    
    nrf_delay_ms(50);
    ret = app_usbd_power_events_enable(); //make sure run it before all sub class all appended.
    APP_ERROR_CHECK(ret);
    
}

pls see below mainloop:

static void idle_state_handle(void * p_context)
{
    UNUSED_PARAMETER(p_context);
    for (;;) {
        if (NRF_LOG_PROCESS() == false) {
            nrf_pwr_mgmt_run();
        }
        task_yield();
    }
}

int main(void) {
    power_management_init();
    timers_init();    
    buttons_leds_init();
    usb_keyboard_init();    
    NRF_LOG_INFO("Dongle started");
    task_manager_start(idle_state_handle, (void *)NULL);
}

other codes are based on example of USBD Hidkeyboard and Ble CLi UART and peripheral CLI.

When run the program, USBD HIDkeyboard and RTT CLI both working good, but NRF serial terminal connecting COM port, no feedback, when disconnect COM, will display as below:

Pls help me to figure out what's wrong?

Parents
  • I don't see any code above that would use the USB CDC port. The NRF_LOG stuff only logs on one destination, which is RTT here.

    The disconnect error shown is a normal and expected for USB disconnect while the port was open.

  • hi, Turbo

    I figured  out this problem, I put the solution as below in order others encounter same problem.

    In my programm, Interface 0,1,2,3 and NRF_DRV_USBD_EPIN2, NRF_DRV_USBD_EPIN3, NRF_DRV_USBD_EPIN4, NRF_DRV_USBD_EPIN6 are allocated to other functions, so I gave Interface 7,8 and NRF_DRV_USBD_EPIN7, NRF_DRV_USBD_EPIN8,NRF_DRV_USBD_EPOUT8  to CLI CDC CAM, but happened above problem.

    After studied example carefully, as per example, I allocated Interface 1,2 and NRF_DRV_USBD_EPIN1, NRF_DRV_USBD_EPIN2, NRF_DRV_USBD_EPOUT2 to CLI CDC CAM.

    Then suddenly problem solved.

    Here is another questions, what's the real story behind of that?

Reply
  • hi, Turbo

    I figured  out this problem, I put the solution as below in order others encounter same problem.

    In my programm, Interface 0,1,2,3 and NRF_DRV_USBD_EPIN2, NRF_DRV_USBD_EPIN3, NRF_DRV_USBD_EPIN4, NRF_DRV_USBD_EPIN6 are allocated to other functions, so I gave Interface 7,8 and NRF_DRV_USBD_EPIN7, NRF_DRV_USBD_EPIN8,NRF_DRV_USBD_EPOUT8  to CLI CDC CAM, but happened above problem.

    After studied example carefully, as per example, I allocated Interface 1,2 and NRF_DRV_USBD_EPIN1, NRF_DRV_USBD_EPIN2, NRF_DRV_USBD_EPOUT2 to CLI CDC CAM.

    Then suddenly problem solved.

    Here is another questions, what's the real story behind of that?

Children
No Data
Related