Skip to content

[AVR] Send USB ZLP if required #5802

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

Merged
merged 2 commits into from
Mar 16, 2017
Merged

[AVR] Send USB ZLP if required #5802

merged 2 commits into from
Mar 16, 2017

Conversation

facchinm
Copy link
Member

@facchinm facchinm commented Jan 4, 2017

Fixes #5732 , "reverts" #4864

Tested with all the following problematic code on Linux, WinXp and Win10

https://github.com/NicoHood/HID/blob/master/examples/RawHID/RawHID/RawHID.ino (only on Linux)

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  if (Serial) {
    if (Serial.available() > 0) {
      Serial.read();
      char buff[65] = "D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE";
      Serial.write(buff,64);
      Serial.flush();
    }
  }
}
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  if (Serial) {
    if (Serial.available() > 0) {
      Serial.read();
      char buff[129] = "D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPED_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE";
      Serial.write(buff,128);
      Serial.flush();
    }
  }
}
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  if (Serial) {
    if (Serial.read() == 'h'){
      Serial.write("Hello ");
      Serial.flush();
      Serial.write("World!\r\n");
      Serial.flush();
    }
  }
}

Comments are really appreciated (as the USB core is still really convoluted, I'm probably missing something important)

@NicoHood @sandeepmistry @matthijskooijman @embmicro

cmaglie
cmaglie previously requested changes Jan 4, 2017
@@ -273,12 +271,15 @@ int USB_Send(u8 ep, const void* d, int len)
}

int r = len;

bool sendZlp = (len % USB_EP_SIZE) == 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is the wrong way to handle ZLP since the buffer could be filled in multiple rounds, for example this sketch still fails after the patch:

void setup() { }
void loop() {
  if (Serial) {
    if (Serial.available() > 0) {
      Serial.read();
      char buff[65] = "<--3456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABC-->";
      Serial.write(buff,32);
      Serial.write(buff+32,32);
      Serial.flush();
    }
  }
}

@cmaglie cmaglie dismissed their stale review January 4, 2017 17:49

Pushed another solution on the same branch

@facchinm facchinm added USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) labels Jan 20, 2017
@facchinm facchinm added this to the Release 1.8.2 milestone Feb 8, 2017
@cmaglie cmaglie merged commit 3c0f26d into arduino:master Mar 16, 2017
@cmaglie cmaglie deleted the send_zlp branch March 16, 2017 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Architecture: AVR Applies only to the AVR microcontrollers (Uno, etc.) USB: CDC serial Serial interface used by MCUs with native USB (e.g. Leonardo) to communicate with the computer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants