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. 

  • This is good to hear, thanks for confirming. The example has been tested quite extensively by the SDK team so I think it's likely that I too did something wrong when I tested it earlier. 

  • I stumble into a similar problem, using SDK 16.0.0. After trying and failing with many experiments, I found a workaround that worked for me.
    In my case the first RX worked fine but (seemingly somewhat depending on what was done in the processing of the RX), the next byte was missing form the next RX "lines" from USB. The processing did send data back to USB with app_usbd_cdc_acm_write()

    Adding a app_usbd_cdc_acm_read_any() call to "case APP_USBD_CDC_ACM_USER_EVT_TX_DONE:" handling solved the issue and now I'm getting also the first character of the line.


            case APP_USBD_CDC_ACM_USER_EVT_TX_DONE:
                //bsp_board_led_invert(LED_CDC_ACM_TX);
                ret = app_usbd_cdc_acm_read_any(&m_app_cdc_acm,
                                            m_rx_buffer,
                                            1);
                break;



  • 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!

Related