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

USBD CDC ACM can't get one byte

I use the example usbd_ble_uart with SDK_15.3.0. I need to send any byte received from the terminal via BLE. Do not wait until the buffer is full or the end of line character arrives. Here is a test example:

case APP_USBD_CDC_ACM_USER_EVT_RX_DONE:
{
char m_rx_buffer[256];
ret_code_t ret;

do
{


/*Setup next transfer*/
ret = app_usbd_cdc_acm_read_any(&m_app_cdc_acm, m_rx_buffer, sizeof(m_rx_buffer));

}while(ret == NRF_SUCCESS);

//----------------------------------------------------------------------
char cdc_data[256];
sprintf(cdc_data, "data: %s \n", m_rx_buffer);
app_usbd_cdc_acm_write(&m_app_cdc_acm, cdc_data, strlen(cdc_data));
memset(cdc_data, 0x00, 256);
memset(m_rx_buffer, 0x00, 256);
//----------------------------------------------------------------------
break;
}

When using the app_usbd_cdc_acm_read_any function in the APP_USBD_CDC_ACM_USER_EVT_RX_DONE interrupt, not all bytes are read. At first, everything is read, except for the first byte:

tx: test string

rx: est string

If you transfer more bytes, then I get a piece of the previous message:

tx: 12345

rx: hellow

tx: save

rx: hellow

Perhaps an error occurs in the internal buffer? However, there is no such problem on SDK_14.0.0. All the bytes that I sent, I get completely. In these two SDKs, the file structure is different. Maybe you can transfer the library to work with USB-CDC from SDK_14.0.0? Or how to make it correct to receive bytes separately in SDK_15.3.0?

Parents
  • Hi,

    If you don't  wait until the buffer is full or the end of line character arrives, you will get 1 BLE packet for each byte you send. It won't be very efficient, but it's possible to do. Starting from the default example in the SDK 15.3, I believe the only change you need to do is this:

    Diff:

    --- C:/SDK/nRF5_SDK_15.3.0_59ac345/nRF5_SDK_15.3.0_59ac345/examples/peripheral/usbd_ble_uart/main.c	ma mar 18 16:20:45 2019
    +++ C:/SDK/nRF5_SDK_15.3.0_59ac345/nRF5_SDK_15.3.0_59ac345/examples/peripheral/usbd_ble_uart/main_modified.c	ma mar 18 16:08:59 2019
    @@ -699,3 +699,3 @@ static void cdc_acm_user_ev_handler(app_usbd_class
    -                if ((m_cdc_data_array[index - 1] == '\n') ||
    -                    (m_cdc_data_array[index - 1] == '\r') ||
    -                    (index >= (m_ble_nus_max_data_len)))
    +                if (   (m_cdc_data_array[index - 1] == '\n') ||
    +                       (m_cdc_data_array[index - 1] == '\r') ||
    +                       (index >= (m_ble_nus_max_data_len))   ||    true      )
    @@ -703 +703 @@ static void cdc_acm_user_ev_handler(app_usbd_class
    -                    if (index > 1)
    +                    if (index >= 1)
    

Reply
  • Hi,

    If you don't  wait until the buffer is full or the end of line character arrives, you will get 1 BLE packet for each byte you send. It won't be very efficient, but it's possible to do. Starting from the default example in the SDK 15.3, I believe the only change you need to do is this:

    Diff:

    --- C:/SDK/nRF5_SDK_15.3.0_59ac345/nRF5_SDK_15.3.0_59ac345/examples/peripheral/usbd_ble_uart/main.c	ma mar 18 16:20:45 2019
    +++ C:/SDK/nRF5_SDK_15.3.0_59ac345/nRF5_SDK_15.3.0_59ac345/examples/peripheral/usbd_ble_uart/main_modified.c	ma mar 18 16:08:59 2019
    @@ -699,3 +699,3 @@ static void cdc_acm_user_ev_handler(app_usbd_class
    -                if ((m_cdc_data_array[index - 1] == '\n') ||
    -                    (m_cdc_data_array[index - 1] == '\r') ||
    -                    (index >= (m_ble_nus_max_data_len)))
    +                if (   (m_cdc_data_array[index - 1] == '\n') ||
    +                       (m_cdc_data_array[index - 1] == '\r') ||
    +                       (index >= (m_ble_nus_max_data_len))   ||    true      )
    @@ -703 +703 @@ static void cdc_acm_user_ev_handler(app_usbd_class
    -                    if (index > 1)
    +                    if (index >= 1)
    

Children
No Data
Related