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

How to use USB CDC transfer API in zephyr

Hello experts,

I would like to get my mind clear on this.

I am using NRF52833 for our custom board we are using Zephyr RTOS (NCS v1.4.99) and IDE is segger embedded studio.

I am using USBD_CDC driver. I am able to detect the USB power. I want to transfer data via USB. In our board UART provision is not provided. We would like to use USB debug.

I have used this following code. But not able to see the data on screen. What will be the end point Address? My code is below here. Is that right ?

static struct device *dev_usb;

void init_USB(void)
{
      int ret;

      dev_usb = device_get_binding("CDC_ACM_0");
      if (!dev_usb) {
              //LOG_ERR("CDC ACM device not found");
              return;
      }

      ret = usb_enable(NULL);
      if (ret != 0) {
              //LOG_ERR("Failed to enable USB");
              return;
      }
}

  ... 
  {
      usb_write(dev_usb, usb_data_buf, 5, NULL);
      k_sleep(K_MSEC(1000));
  }
  ...
/**
 * @brief Write data to the specified endpoint
 *
 * Function to write data to the specified endpoint. The supplied
 * usb_ep_callback will be called when transmission is done.
 *
 * @param[in]  ep        Endpoint address corresponding to the one listed in the
 *                       device configuration table
 * @param[in]  data      Pointer to data to write
 * @param[in]  data_len  Length of data requested to write. This may be zero for
 *                       a zero length status packet.
 * @param[out] bytes_ret Bytes written to the EP FIFO. This value may be NULL if
 *                       the application expects all bytes to be written
 *
 * @return 0 on success, negative errno code on fail
 */

Regards

Sudharsan

Related