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

52840 USB CDC missed first byte in RX event

Hi,

I used 52840DK and SDK15.2 to test usb cdc, every thing goes will, but in rx event, it always missed first byte, for example, if send "123456", it just received "23456", if send just "1", there is no rx event. though I can see the first byte right in the internal_rx_buf, but how to make the rx event correctly receive first byte?

thanks!

Brian. 

Parents
  • I have a similar issue with the SDK17 with 

    APP_USBD_CONFIG_EVENT_QUEUE_ENABLE = 0

    APP_USBD_CONFIG_SOF_HANDLING_MODE = 2

    On carriage return, the next character is lost.

    static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                        app_usbd_cdc_acm_user_event_t event)
    {
        app_usbd_cdc_acm_t const * p_cdc_acm = app_usbd_cdc_acm_class_get(p_inst);
    
        switch (event)
        {
            case APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN:
            {
                /*Set up the first transfer*/
                ret_code_t ret = app_usbd_cdc_acm_read(&m_app_cdc_acm, m_cdc_data_array, 1); // necessary it seems
                //NRF_LOG_INFO("CDC ACM port opened");
                break;
            }
    
            case APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE:
                //NRF_LOG_INFO("CDC ACM port closed");
                break;
    
            case APP_USBD_CDC_ACM_USER_EVT_TX_DONE:
                break;
    
            case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
            {
                ret_code_t ret;
                nrf_gpio_pin_write(LED_2,0);
                do{
                        ret = app_usbd_cdc_acm_read(&m_app_cdc_acm, &m_cdc_data_array[buffer_available_idx++], 1);  
                }while (ret == NRF_SUCCESS);
                nrf_gpio_pin_write(LED_2,1);
                break;
            }
            default:
                break;
        }
    }

    In the main loop i have something like 

            if (buffer_available_idx){
                    app_usbd_cdc_acm_write(&m_app_cdc_acm, m_cdc_data_array, strlen(m_cdc_data_array));
                    memset(m_cdc_data_array, 0, RECV_BUF_LEN);
                    buffer_available_idx=0;
            }

    If I type alot of characters they are all echoed fine by the above code. Only when I press carriage return, the next character after CR is lost. Tried this with 2 terminal programs.

    Thanks!

Reply
  • I have a similar issue with the SDK17 with 

    APP_USBD_CONFIG_EVENT_QUEUE_ENABLE = 0

    APP_USBD_CONFIG_SOF_HANDLING_MODE = 2

    On carriage return, the next character is lost.

    static void cdc_acm_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                        app_usbd_cdc_acm_user_event_t event)
    {
        app_usbd_cdc_acm_t const * p_cdc_acm = app_usbd_cdc_acm_class_get(p_inst);
    
        switch (event)
        {
            case APP_USBD_CDC_ACM_USER_EVT_PORT_OPEN:
            {
                /*Set up the first transfer*/
                ret_code_t ret = app_usbd_cdc_acm_read(&m_app_cdc_acm, m_cdc_data_array, 1); // necessary it seems
                //NRF_LOG_INFO("CDC ACM port opened");
                break;
            }
    
            case APP_USBD_CDC_ACM_USER_EVT_PORT_CLOSE:
                //NRF_LOG_INFO("CDC ACM port closed");
                break;
    
            case APP_USBD_CDC_ACM_USER_EVT_TX_DONE:
                break;
    
            case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
            {
                ret_code_t ret;
                nrf_gpio_pin_write(LED_2,0);
                do{
                        ret = app_usbd_cdc_acm_read(&m_app_cdc_acm, &m_cdc_data_array[buffer_available_idx++], 1);  
                }while (ret == NRF_SUCCESS);
                nrf_gpio_pin_write(LED_2,1);
                break;
            }
            default:
                break;
        }
    }

    In the main loop i have something like 

            if (buffer_available_idx){
                    app_usbd_cdc_acm_write(&m_app_cdc_acm, m_cdc_data_array, strlen(m_cdc_data_array));
                    memset(m_cdc_data_array, 0, RECV_BUF_LEN);
                    buffer_available_idx=0;
            }

    If I type alot of characters they are all echoed fine by the above code. Only when I press carriage return, the next character after CR is lost. Tried this with 2 terminal programs.

    Thanks!

Children
No Data
Related