RAKWireless / WisBlock

Quickstart, tutorials and examples for the RAKwireless WisBlock product line.
https://www.rakwireless.com
MIT License
158 stars 117 forks source link

USB Serial Issues #11

Closed IoTPanic closed 3 years ago

IoTPanic commented 3 years ago

Hope all is well,

I have noticed strange behavior when using USB serial with the wisblocks, if I don't send a serial message in quick enough intervals from the wisblock to my machine, the connection drops, then eventually there is a reset. I have the following video showing a basic demo to show the specific issue. If I dont have USB connected and have it break out of the while(!Serial) after a few seconds to run on a battery, there is no issue and it never resets even if it prints to serial during operation.

I have noticed this issue since I started using the wisblocks in the past week, but I was able to get around the issue by printing a UTF-8 blank character every few hundred milliseconds. I noticed that if I send serial data to the device, it seems like a buffer on the device side empties as shown in this video. If I need to update something, let me know, I have not noticed this issue with any other device on my desktop.

Setup

Demo Code

#include <Arduino.h>

// Value of 300ms is OK, 3 or 30 seconds not so much
#define INTERVAL 3000

unsigned long next = 0;
unsigned i = 0;

void setup() {
  pinMode(LED_BLUE, OUTPUT);
  digitalWrite(LED_BLUE, HIGH);
  Serial.begin(9600);
  while(!Serial) {
    // Need otherwise serial port is lost if I dont get to it fast enough
    Serial.println(); 
  }
  Serial.println("Hello! I'm starting now");
  digitalWrite(LED_BLUE, LOW);
}

void loop() {
  // Delays also have the same effect, I wanted any possible hidden timer or rtos setup to not be hindered
  if(millis()>=next) {
    digitalWrite(LED_BLUE, HIGH);
    Serial.print("Printing to usb serial ");
    Serial.println(i++);
    // So I can see the led with my human eyeballs
    delay(10); 
    digitalWrite(LED_BLUE, LOW);
    next = INTERVAL + millis();
  } 
}
beegee-tokyo commented 3 years ago

I am using WisBlock now for nearly a year and I never saw what you are reporting. I will ask RAK R&D to have a look into it.

jpmeijers commented 3 years ago

This issues sounds very similar to the behaviour that I have seen.

beegee-tokyo commented 3 years ago

Our HW team says they cannot see the problem. I tried as well, using exactly your code, but set the time between two Serial.print() to 10 seconds. Compiled on PlatformIO. Started test at 16:43:55 image and let it run for nearly two hours without any problem image

I tested on Windows 10 (no MAC around here). Not sure if that makes a difference.

jpmeijers commented 3 years ago

Ubuntu 20.04 here, using Arduino 1.8.13.

I've tried reproducing this issue today, but so far it keeps on working. I wonder if the bootloader upgrade didn't solve this issue for me.

IoTPanic commented 3 years ago

I went ahead and installed a Windows 10 VM in virtualbox and passed the USB device to the guest, works just fine there, while having the same issues in the linux host. @jpmeijers can you try with 10 second delay? If that happens to work fine could I have the output of uname -a and sudo cat /sys/kernel/debug/usb/devices?

beegee-tokyo commented 3 years ago

Closing at it is not related to WisBlock

IoTPanic commented 3 years ago

I disagree, other nRF52 systems do not experience these issues with my machine, the issue is specific to WisBlocks, we seem to be narrowing down the issue to be related to the host OS. If other people who also use nRF52 boards with linux then use WisBlocks, this will be the place they look to talk about the issue.