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

Parents Reply
  • sudharsan said:
    Are you suggesting me to use Termite?

     No, just saying that perhaps the DTR is the part that is blocking you. I don't know whether this is an option, or whether it is enabled by default in Terraterm. That is for you to research.

     

    sudharsan said:
    No need of UART configuration right?...In my custom board UART hardware provision is not available.

     No need. The UART is only for logging.

    Perhaps you can try to use Putty? You need to set up these putty settings. Remember to apply both the settings from the section "Terminal settings" and the section "UART and USB settings".

    In addition, add the setting:

    Then, if you see the text that you type into Putty, it means they are echoed back. If it doesn't work, it will not be possible to type anything to the Putty window.

    Best regards,

    Edvin

Children
No Data
Related