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 Reply Children
No Data
Related