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

nRF52840 DK USB HID with SoftDevice Fails with nRF5_SDK_15.0.0_a53641a

Hello Nordic Experts,

I'd like to add the usb hid composite to one of BLE examples. I followed link below and combined the example usbd_hid_composite with ble_app_blinki_c. 

https://devzone.nordicsemi.com/f/nordic-q-a/28119/nrf52840-template-project-for-usb-and-ble/110929#110929

The BLE part works fine, but I use Bus Hound to monitor the USB and there is no sign of any USB device. Can you please help me understand what is wrong here.

I just copied/pasted all definitions&declarations from usbd_hid_composite (excluding CLI interface) to the ble example, and added all required path/files to the project. I then set

#define USBD_POWER_DETECTION false

and in sdk_config.h,

#define APP_USBD_CONFIG_POWER_EVENTS_PROCESS 0

#define POWER_ENABLED 0

#define USBD_ENABLED 1

#define APP_USBD_ENABLED 1

#define APP_USBD_VID 0x1915

#define APP_USBD_PID 0x520B

#define APP_USBD_HID_ENABLED 1

#define APP_USBD_HID_KBD_ENABLED 1

#define APP_USBD_HID_MOUSE_ENABLED 1

This is my main

int main(void)
{

ret_code_t ret;
static const app_usbd_config_t usbd_config = {
.ev_state_proc = usbd_user_ev_handler,
};
log_init();

ret = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(ret);

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

ret = app_timer_create(&m_mouse_move_timer, APP_TIMER_MODE_REPEATED, mouse_move_timer_handler);
APP_ERROR_CHECK(ret);

init_bsp();
//init_cli();

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

app_usbd_class_inst_t const * class_inst_mouse;
#if CONFIG_HAS_MOUSE
class_inst_mouse = app_usbd_hid_mouse_class_inst_get(&m_app_hid_mouse);
#else
class_inst_mouse = app_usbd_dummy_class_inst_get(&m_app_mouse_dummy);
#endif
ret = app_usbd_class_append(class_inst_mouse);
APP_ERROR_CHECK(ret);

app_usbd_class_inst_t const * class_inst_kbd;
#if CONFIG_HAS_KBD
class_inst_kbd = app_usbd_hid_kbd_class_inst_get(&m_app_hid_kbd);
#else
class_inst_kbd = app_usbd_dummy_class_inst_get(&m_app_kbd_dummy);
#endif
ret = app_usbd_class_append(class_inst_kbd);
APP_ERROR_CHECK(ret);

// Initialize.

//timer_init();
leds_init();
//buttons_init();
power_management_init();
ble_stack_init();
gatt_init();
db_discovery_init();
lbs_c_init();

// Start execution.
NRF_LOG_INFO("Blinky CENTRAL example started.");
scan_start();

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

// Turn on the LED to signal scanning.
bsp_board_led_on(CENTRAL_SCANNING_LED);

// Enter main loop.
for (;;)
{
idle_state_handle();
}
}

Thanks

Parents
  • Hi,

    In SDK 15.0 we added a USB+BLE example. You can find the source code and the project file of the example in the following folder: <SDK_InstallFolder>\examples\peripheral\usbd_ble_uart

    Please take a look at that example, to see how to combine USB and BLE/SoftDevice.

    Let me know if you still have issues with this after looking at that example.

    Side note: If you are working on SDK 15.0 and nRF52840 DK 1.0.0, then there is a bug you should be aware of. See this post.

Reply
  • Hi,

    In SDK 15.0 we added a USB+BLE example. You can find the source code and the project file of the example in the following folder: <SDK_InstallFolder>\examples\peripheral\usbd_ble_uart

    Please take a look at that example, to see how to combine USB and BLE/SoftDevice.

    Let me know if you still have issues with this after looking at that example.

    Side note: If you are working on SDK 15.0 and nRF52840 DK 1.0.0, then there is a bug you should be aware of. See this post.

Children
  • Thanks, I was not aware of that example. Totally helpful and resolved my issue.

  • hi,i compile the project usbd_ble_uart, i use pca10056 ,sdk is SDK 16.0 .when try to stop the ble stack in the project ,there will show a log :Fatal error . so if it is impossible to stop the sd in the usb project ?my code like this:

    /** @brief Application main function. */
    int main(void)
    {
        ret_code_t ret;
        static const app_usbd_config_t usbd_config = {
            .ev_state_proc = usbd_user_ev_handler
        };
        // Initialize.
        log_init();
        timers_init();
    
        buttons_leds_init();
    
        app_usbd_serial_num_generate();
    
        ret = nrf_drv_clock_init();
        APP_ERROR_CHECK(ret);
    
        NRF_LOG_INFO("USBD BLE UART example started.");
    
        ret = app_usbd_init(&usbd_config);
        APP_ERROR_CHECK(ret);
    
        app_usbd_class_inst_t const * class_cdc_acm = app_usbd_cdc_acm_class_inst_get(&m_app_cdc_acm);
        ret = app_usbd_class_append(class_cdc_acm);
        APP_ERROR_CHECK(ret);
    
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    
        // Start execution.
        advertising_start();
    
    
    
    //try to stop the  stack
        sd_ble_gap_adv_stop(m_advertising.adv_handle);
        uint32_t err_code;
        err_code = ble_conn_params_stop();
    	  NRF_LOG_INFO("err_code =%d",err_code);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_sdh_disable_request();
        APP_ERROR_CHECK(err_code);
        ASSERT(!nrf_sdh_is_enabled());
    
    
    
    
    
        ret = app_usbd_power_events_enable();
        APP_ERROR_CHECK(ret);
    
        // Enter main loop.
        for (;;)
        {
            while (app_usbd_event_queue_process())
            {
                /* Nothing to do */
            }
            idle_state_handle();
        }
    }

Related