Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't try and print if usb not connected for vcp #2

Open
plusk01 opened this issue Feb 10, 2018 · 0 comments
Open

don't try and print if usb not connected for vcp #2

plusk01 opened this issue Feb 10, 2018 · 0 comments

Comments

@plusk01
Copy link
Owner

plusk01 commented Feb 10, 2018

Currently, if using VCP and trying to write, but no one is consuming the data on the other side, there is a timeout and it can take block, particularly when using printf (which isn't a huge problem as printf is only for debugging). There is also a barely-noticeable delay when using the VCP::write() method.

It seems that it is the fault of the following USB_TIMEOUT code:

void VCP::write(uint8_t* ch, uint8_t len)
{
  if (!usbIsConnected() || !usbIsConfigured()) return;

  uint32_t start = millis();
  while (len > 0)
  {
    uint32_t num_bytes_sent = CDC_Send_DATA(ch, len);
    len -= num_bytes_sent;
    ch += num_bytes_sent;

    if (len == 0 || millis() > (start + USB_TIMEOUT))
      break;
  }
}

It would be better if there was a way to say "If the host USB device is not ready to consume data, don't even try and send." Although I'm not sure if there is an easy way to know that (but I feel like there should be).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant