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

USBD_CDC_ACM behaves different between SEGGER and Keil compiles

Hello Technical Support team,

I have a strange problem at the moment. I am currently using the USBD_CDC_ACM driver on the nRF52480 dongle hardware. Software SDK version is 15.2. Softdevice S140

The application basically sends plain text data packets to a serial terminal. If I compile the application in SEGGER Embedded Studio the transmission of data works fine, but the same code compiled under Keil I get some wrong characters coming out on the terminal as shown in the picture below.

Do you have any ideas on how this can occur? I suspect is something to do with flow control. I tried to look in the driver to see where the communications parameters are set in code but are unable to find them. Can you please lead me into the right direction.

Regards,

Jes

Parents Reply Children
  • Hi Henry,

    I am not sure what you want to see but here is the setup of the CDC driver. I can't show too much of the code because it is company code and can't share in a public forum. The code is based on the usbd_ble_uart example all of the settings are default. How can I hard code the baudrate parity and handshaking for the CDC driver? I can't seem to find code to do that in the examples. Under Segger environment everything works well.

    Regards,

    Jes

    #ifdef USB_CDC_ACM_UART //jd

    // USB DEFINES START
    static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
    app_usbd_cdc_acm_user_event_t event);

    #define CDC_ACM_COMM_INTERFACE 0
    #define CDC_ACM_COMM_EPIN NRF_DRV_USBD_EPIN2

    #define CDC_ACM_DATA_INTERFACE 1
    #define CDC_ACM_DATA_EPIN NRF_DRV_USBD_EPIN1
    #define CDC_ACM_DATA_EPOUT NRF_DRV_USBD_EPOUT1
    #define CDC_ACM_DATABLOCK_RX_SIZE 64


    /** @brief CDC_ACM class instance */
    APP_USBD_CDC_ACM_GLOBAL_DEF(m_app_cdc_acm,
                                                                         cdc_acm_user_ev_handler,
                                                                         CDC_ACM_COMM_INTERFACE,
                                                                         CDC_ACM_DATA_INTERFACE,
                                                                         CDC_ACM_COMM_EPIN,
                                                                         CDC_ACM_DATA_EPIN,
                                                                         CDC_ACM_DATA_EPOUT,
                                                                         APP_USBD_CDC_COMM_PROTOCOL_AT_V250);
                                                                        //APP_USBD_CDC_COMM_PROTOCOL_NONE);

    // USB DEFINES END

    #ifdef USB_CDC_ACM_UART
               static const app_usbd_config_t usbd_config = {
    .                    ev_state_proc = usbd_user_ev_handler
                         };

    #endif

    void UART_open(void)
    {
              ret_code_t ret;
    #ifndef USB_CDC_ACM_UART
                           ret = nrf_serial_init(&serial0_uarte, &m_uarte0_drv_config, &serial0_config);
                           APP_ERROR_CHECK(ret);
    #else

     // TODO: this is not ideal. Application needs a rewrite to handle UART and USB
    // communications differently. Issue here on a non response to the shake message
    // the application would want to restart comms. Need to find a way to restart USB
    // driver nicely.
    if(!receiver_ready)
    {
                app_usbd_serial_num_generate();

                  ret = nrf_drv_clock_init();
                   NRF_LOG_INFO("Here_B10 ret 0x%X", ret);
                  //if(ret != NRF_ERROR_MODULE_ALREADY_INITIALIZED)
                  //{
                       // NRF_LOG_INFO("Here_B11");
                       // APP_ERROR_CHECK(ret);
                  //}
                  //else
                  //{
                         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);
    }
    #endif

    gapRcvDataNumber = 0;
    gapInTxData = FALSE;
    gapTxStartTime = 0;

    app_timer_start(uart_polling_timer, APP_TIMER_TICKS(TIMER_CHK_BUFFER_DELAY), NULL);
    }

  • Hi! Jes:

    It's okay. However, the debug rule is quite different between different IDE.

    It seems like okay. In your initialization. But I applied CDC in keil & SES C before. I think the driver is okay. So that I doubt the bug in your side. But my SDK version is 17.0.2.

Related