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

USBD on nRF52840 dongle

Hi,

I modified your USBD BLE UART Example by commenting out the button and LED code to run on a dongle with J-Link debugger soldered on.

I removed the bootloader and set NRF_UICR->REGOUT0 to 3.3V, to ensure proper voltage.

The example runs, all USBD-functions return NRF_SUCCESS when starting up. Also the virtual comport is listed on the PC.

When sending data from a terminal, nothing happens. the cdc_acm_user_ev_handler is never fired.

Is there someting I'm missing?

Working with nRF5_SDK_15.2.0 and debugging with SES.

Best regards

Gerry

Parents
  • Hi Gerry,

    It is clear that many things work since the device enumerates correctly on the PC. Can you upload your project here so that I can see what you have modified from the example? I suspect we will find an error there, though I do not have any specific ideas without knowing more.

  • Hi Einar

    Thanks for your support. I've attached the modified example.

    usbd_ble_uart.zip

  • Hi,

    Diffing your code to the example I do not see anything obvious:

    diff --git a/examples/peripheral/usbd_ble_uart/main.c b/examples/peripheral/usbd_ble_uart/main.c
    index d2c40e9..2b3a6ab 100644
    --- a/examples/peripheral/usbd_ble_uart/main.c
    +++ b/examples/peripheral/usbd_ble_uart/main.c
    @@ -666,22 +666,22 @@ static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                 ret_code_t ret = app_usbd_cdc_acm_read(&m_app_cdc_acm,
                                                        m_cdc_data_array,
                                                        1);
    -            UNUSED_VARIABLE(ret);
    -            ret = app_timer_stop(m_blink_cdc);
    -            APP_ERROR_CHECK(ret);
    -            bsp_board_led_on(LED_CDC_ACM_CONN);
    -            NRF_LOG_INFO("CDC ACM port opened");
    +//            UNUSED_VARIABLE(ret);
    +//            ret = app_timer_stop(m_blink_cdc);
    +//            APP_ERROR_CHECK(ret);
    +//            bsp_board_led_on(LED_CDC_ACM_CONN);
    +//            NRF_LOG_INFO("CDC ACM port opened");
                 break;
             }
     
             case APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE:
    -            NRF_LOG_INFO("CDC ACM port closed");
    +//            NRF_LOG_INFO("CDC ACM port closed");
                 if (m_usb_connected)
                 {
    -                ret_code_t ret = app_timer_start(m_blink_cdc,
    -                                                 APP_TIMER_TICKS(LED_BLINK_INTERVAL),
    -                                                 (void *) LED_CDC_ACM_CONN);
    -                APP_ERROR_CHECK(ret);
    +//                ret_code_t ret = app_timer_start(m_blink_cdc,
    +//                                                 APP_TIMER_TICKS(LED_BLINK_INTERVAL),
    +//                                                 (void *) LED_CDC_ACM_CONN);
    +//                APP_ERROR_CHECK(ret);
                 }
                 break;
     
    @@ -702,9 +702,9 @@ static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                     {
                         if (index > 1)
                         {
    -                        bsp_board_led_invert(LED_CDC_ACM_RX);
    -                        NRF_LOG_DEBUG("Ready to send data over BLE NUS");
    -                        NRF_LOG_HEXDUMP_DEBUG(m_cdc_data_array, index);
    +//                        bsp_board_led_invert(LED_CDC_ACM_RX);
    +//                        NRF_LOG_DEBUG("Ready to send data over BLE NUS");
    +//                        NRF_LOG_HEXDUMP_DEBUG(m_cdc_data_array, index);
     
                             do
                             {
    @@ -715,20 +715,20 @@ static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                     length += sizeof(ENDLINE_STRING);
                                 }
     
    -                            ret = ble_nus_data_send(&m_nus,
    -                                                    (uint8_t *) m_cdc_data_array,
    -                                                    &length,
    -                                                    m_conn_handle);
    +//                            ret = ble_nus_data_send(&m_nus,
    +//                                                    (uint8_t *) m_cdc_data_array,
    +//                                                    &length,
    +//                                                    m_conn_handle);
     
                                 if (ret == NRF_ERROR_NOT_FOUND)
                                 {
    -                                NRF_LOG_INFO("BLE NUS unavailable, data received: %s", m_cdc_data_array);
    +//                                NRF_LOG_INFO("BLE NUS unavailable, data received: %s", m_cdc_data_array);
                                     break;
                                 }
     
                                 if (ret == NRF_ERROR_RESOURCES)
                                 {
    -                                NRF_LOG_ERROR("BLE NUS Too many notifications queued.");
    +//                                NRF_LOG_ERROR("BLE NUS Too many notifications queued.");
                                     break;
                                 }
     
    @@ -745,7 +745,7 @@ static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
     
                     /*Get amount of data transferred*/
                     size_t size = app_usbd_cdc_acm_rx_size(p_cdc_acm);
    -                NRF_LOG_DEBUG("RX: size: %lu char: %c", size, m_cdc_data_array[index - 1]);
    +//                NRF_LOG_DEBUG("RX: size: %lu char: %c", size, m_cdc_data_array[index - 1]);
     
                     /* Fetch data until internal buffer is empty */
                     ret = app_usbd_cdc_acm_read(&m_app_cdc_acm,
    @@ -783,7 +783,7 @@ static void usbd_user_ev_handler(app_usbd_event_type_t event)
                 break;
     
             case APP_USBD_EVT_POWER_DETECTED:
    -            NRF_LOG_INFO("USB power detected");
    +//            NRF_LOG_INFO("USB power detected");
     
                 if (!nrf_drv_usbd_is_enabled())
                 {
    @@ -793,10 +793,10 @@ static void usbd_user_ev_handler(app_usbd_event_type_t event)
     
             case APP_USBD_EVT_POWER_REMOVED:
             {
    -            NRF_LOG_INFO("USB power removed");
    -            ret_code_t err_code = app_timer_stop(m_blink_cdc);
    -            APP_ERROR_CHECK(err_code);
    -            bsp_board_led_off(LED_CDC_ACM_CONN);
    +//            NRF_LOG_INFO("USB power removed");
    +//            ret_code_t err_code = app_timer_stop(m_blink_cdc);
    +//            APP_ERROR_CHECK(err_code);
    +//            bsp_board_led_off(LED_CDC_ACM_CONN);
                 m_usb_connected = false;
                 app_usbd_stop();
             }
    @@ -804,11 +804,11 @@ static void usbd_user_ev_handler(app_usbd_event_type_t event)
     
             case APP_USBD_EVT_POWER_READY:
             {
    -            NRF_LOG_INFO("USB ready");
    -            ret_code_t err_code = app_timer_start(m_blink_cdc,
    -                                                  APP_TIMER_TICKS(LED_BLINK_INTERVAL),
    -                                                  (void *) LED_CDC_ACM_CONN);
    -            APP_ERROR_CHECK(err_code);
    +//            NRF_LOG_INFO("USB ready");
    +//            ret_code_t err_code = app_timer_start(m_blink_cdc,
    +//                                                  APP_TIMER_TICKS(LED_BLINK_INTERVAL),
    +//                                                  (void *) LED_CDC_ACM_CONN);
    +//            APP_ERROR_CHECK(err_code);
                 m_usb_connected = true;
                 app_usbd_start();
             }
    @@ -824,15 +824,24 @@ static void usbd_user_ev_handler(app_usbd_event_type_t event)
     /** @brief Application main function. */
     int main(void)
     {
    +    if (NRF_UICR->REGOUT0 != 0xFFFFFFFD) {
    +	NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
    +	while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
    +	NRF_UICR->REGOUT0 = 0xFFFFFFFD; //3.3V
    +        while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
    +	NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
    +	while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
    +    }
    +
         ret_code_t ret;
         static const app_usbd_config_t usbd_config = {
             .ev_state_proc = usbd_user_ev_handler
         };
         // Initialize.
    -    log_init();
    +    //log_init();
         timers_init();
     
    -    buttons_leds_init();
    +    //buttons_leds_init();
     
         app_usbd_serial_num_generate();
     
    

    You disable logging and do not use the BSP (for LEDs). Then you add code for setting the REG0 voltage to 3.3 V to compensate for not calling the BSP code that does this. The BSP implementation sets 3.0 V (see gpio_output_voltage_setup() in components\boards\boards.c), but that should not matter.

    How have you verified that cdc_acm_user_ev_handler is never fired when it should? Could it be a problem with optimization or similar? What happens if you try to  toggle a GPIO in the event handler?

    (One other thing I notice is that the way you check REGOUT0 before setting it, the device would continue to write to it and reset forever if it was for instance set to 3 V initially (last three bits 0x4 which is "100"), since only 1's are converted to 0's when writing to flash). So if you have not performed a full chip erase that might be a problem, as 3 V is used by the firmware it ships with. This does not seem relevant though since it is done at the beginning of main() and it seems the nRF enumerates correctly).

  • Hi,

    I now replaced the code for 3.0V with gpio_output_voltage_setup() in components\boards\boards.c and made a chip erase ("Erase all" in SES)

    I also tried to toggle an LED in cdc_acm_user_ev_handler. This is really never fired.

    After some more debugging, I found, that if I connect BLE with the Nordic UART App. and send some characters, I end up in the nus_data_handler. When app_usbd_cdc_acm_write is called there, it returns 8 = NRF_ERROR_INVALID_STATE

            // Send data through CDC ACM
            ret_code_t ret = app_usbd_cdc_acm_write(&m_app_cdc_acm,
                                                    m_nus_data_array,
                                                    length);
            if(ret != NRF_SUCCESS)
            {
                NRF_LOG_INFO("CDC ACM unavailable, data received: %s", m_nus_data_array);
            }

    could it be a problem of the dongle? I have 2 brand new dongles here. Have you ever tried to run this on a nRF52840 dongle?

Reply
  • Hi,

    I now replaced the code for 3.0V with gpio_output_voltage_setup() in components\boards\boards.c and made a chip erase ("Erase all" in SES)

    I also tried to toggle an LED in cdc_acm_user_ev_handler. This is really never fired.

    After some more debugging, I found, that if I connect BLE with the Nordic UART App. and send some characters, I end up in the nus_data_handler. When app_usbd_cdc_acm_write is called there, it returns 8 = NRF_ERROR_INVALID_STATE

            // Send data through CDC ACM
            ret_code_t ret = app_usbd_cdc_acm_write(&m_app_cdc_acm,
                                                    m_nus_data_array,
                                                    length);
            if(ret != NRF_SUCCESS)
            {
                NRF_LOG_INFO("CDC ACM unavailable, data received: %s", m_nus_data_array);
            }

    could it be a problem of the dongle? I have 2 brand new dongles here. Have you ever tried to run this on a nRF52840 dongle?

Children
Related