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

nRF52 crashes with longer strings in .print() #57

Open
zjwhitehead opened this issue Apr 22, 2020 · 2 comments
Open

nRF52 crashes with longer strings in .print() #57

zjwhitehead opened this issue Apr 22, 2020 · 2 comments
Labels
Bug Something isn't working

Comments

@zjwhitehead
Copy link

Describe the bug
Passing in strings over a certain length freezes the device.
May be related to buffer overflow? looks like it crashes after 64 characters.

Set up (please complete the following information)

  • nRF52840 Feather Express
  • TinyUSB library version: 0.8.2
  • MacOS 10.15.4
  • Chrome 83

To Reproduce
Steps to reproduce the behavior:

  1. Open webusb_serial example here
  2. change line 79 from
    if ( connected ) usb_web.println("TinyUSB WebUSB Serial example");
    to
    if ( connected ) usb_web.println("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
  3. Compiles & upload as expected
  4. Connect via https://adafruit.github.io/Adafruit_TinyUSB_Arduino/examples/webusb-serial/
  5. Notice expected string gets only partially returned and devices is unresponsive.

Expected behavior
Full string is printed out via web_usb without crashing

Screenshots
If applicable, add screenshots to help explain your problem.
image

Additional context
Seems to work as expected on SAMD21 boards

Tested in Chrome 83.0.4103.14 and Brave browser (Chromium)

@zjwhitehead
Copy link
Author

Looks like this is still happening. Im also experiencing the issue on the RP2040.

The following code hangs when connected to the webserial example.
The main fix is just sending less than 64 bytes but obviously sometimes you need to send more than that...
Changing 200 to 64 below changes how many bytes are sent.

#include "Adafruit_TinyUSB.h"

// USB WebUSB object
Adafruit_USBD_WebUSB usb_web;

// Landing Page: scheme (0: http, 1: https), url
WEBUSB_URL_DEF(landingPage, 1 /*https*/, "adafruit.github.io/Adafruit_TinyUSB_Arduino/examples/webusb-serial/index.html");

int led_pin = LED_BUILTIN;

// the setup function runs once when you press reset or power the board
void setup()
{
#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
  // Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
  TinyUSB_Device_Init(0);
#endif
  
  usb_web.setLandingPage(&landingPage);
  usb_web.setLineStateCallback(line_state_callback);
  //usb_web.setStringDescriptor("TinyUSB WebUSB");
  usb_web.begin();

  Serial.begin(115200);

  // wait until device mounted
  while( !TinyUSBDevice.mounted() ) delay(1);

  Serial.println("TinyUSB WebUSB Serial example");
}

void loop(){}

void line_state_callback(bool connected){
  if ( connected ) {
    for (int i = 0; i < 200; i++) {
    int digit = i % 10;
    Serial.print(digit);
    usb_web.print(digit);
    usb_web.flush();
    }
  }
}

Any thoughts on how to overcome this?

@zjwhitehead
Copy link
Author

This is still happening on 1.18.3 😢
Any updated on how to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant