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

Can nrf52840 usbd work with softdevice?

The nrf52840 usbd examples of peripheral in SDK 13.0.0 worked fine. I want usb work with BLE softdevice and there are lots of conflicts between nrf drv and softdevice. Is there any example of usbd working together with ble softdevice?

Parents
  • Hi,

    I just tested this without any problems. Only thing I had to do was to comment out the buttons_leds_init() function used in the ble_app_uart code, so it didn’t overwrite the button functionality used for the USBD part of the code. My main code looks like this:

    int main(void)
    {
        uint32_t err_code = 0;
        bool erase_bonds;
        
        uint32_t ret = 0;    
    
        // Initialize.
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
        uart_init();
        err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
        
        NRF_LOG_INFO("\r\nUART Start!\r\n");
        
        ret = nrf_drv_power_init(NULL);
        APP_ERROR_CHECK(ret);
        
        ret = nrf_drv_clock_init();
    
        APP_ERROR_CHECK(ret);
        
        
        NRF_LOG_INFO("Hello USB!\r\n");
    
        /* Configure LEDs */
        bsp_board_leds_init();
        bsp_board_buttons_init();
    
    
        serial_number_string_create();
        
        ret = app_usbd_init();
        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);
    
        bool last_usb_conn_status = false;
        usb_start();
    
        
        NRF_LOG_INFO("Enabling BLE part!\r\n");
        //buttons_leds_init(&erase_bonds);
        ble_stack_init();
        gap_params_init();
        services_init();
        advertising_init();
        conn_params_init();
       
        err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
        APP_ERROR_CHECK(err_code);
        
        // Enter main loop.
        for (;;)
        {
            
            last_usb_conn_status = usb_connection_handle(last_usb_conn_status);
    
            if (bsp_board_button_state_get(BTN_CDC_DATA_SEND))
            {
                static int  frame_counter;
    
                sprintf(m_tx_buffer, "Hello USB CDC FA demo: %u\r\n", frame_counter);
    
                ret = app_usbd_cdc_acm_write(&m_app_cdc_acm, m_tx_buffer, sizeof(m_tx_buffer));
                if (ret == NRF_SUCCESS)
                {
                    ++frame_counter;
                }
            }
    
            if (bsp_board_button_state_get(BTN_CDC_NOTIFY_SEND))
            {
                ret = app_usbd_cdc_acm_serial_state_notify(&m_app_cdc_acm,
                                                           APP_USBD_CDC_ACM_SERIAL_STATE_BREAK,
                                                           false);
                UNUSED_VARIABLE(ret);
            }
    
            UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
            
            
            power_manage();
        }
    }
    
  • Thanks for your example code.If I plug in the usb header after start the power the nrf52840, computer will not find the USB CDC device and the LED1's state do not change. Only when I plug in the use header first and then power on the nrf52840, or reset the chip, the computer will find the USB CDC device. In debug mode, it can be found that the function power_usb_event_handler() only work once when program start. After ble_stack_init(), it can not reach at power_usb_event_handler(). It is same with my code.

Reply
  • Thanks for your example code.If I plug in the usb header after start the power the nrf52840, computer will not find the USB CDC device and the LED1's state do not change. Only when I plug in the use header first and then power on the nrf52840, or reset the chip, the computer will find the USB CDC device. In debug mode, it can be found that the function power_usb_event_handler() only work once when program start. After ble_stack_init(), it can not reach at power_usb_event_handler(). It is same with my code.

Children
No Data
Related