sipeed / Maixduino

Arduino port on Maix board ( k210 )
https://maixduino.sipeed.com
Other
215 stars 95 forks source link

Serial interface drops characters #75

Open technoblogy opened 4 years ago

technoblogy commented 4 years ago

If you try to transfer more than about 960 characters from the Serial Monitor to the board via the serial interface it drops characters.

To demonstrate this run the following program that simply echoes characters to the Serial Monitor:

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("Ready");
}

int count = 0;

void loop() {
  if (count % 64 == 0) {
    Serial.println();
    Serial.print(count);
    Serial.write(' ');
  }
  while (!Serial.available());
  Serial.write((int)Serial.read());
  count++;
}

Select and copy the following text:

ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz*

The output looks like this; the red circles show the dropped characters.

Screen Shot 2020-03-04 at 17 09 56

Note: I'm running on a MacBook Pro using macOS High Sierra, with Arduino IDE 1.8.9, and Maixduino (k210) by Sipeed Boards Manager package 0.3.11.

technoblogy commented 4 years ago

I think I've fixed it myself. In the following file:

Maixduino/hardware/k210/0.3.11/cores/arduino/RingBuffer.h

change:

#define RING_BUFFER_SIZE 64

to:

#define RING_BUFFER_SIZE 256

The value 256 seems to be the one used in other cores, such as Adafruit's samd core.

Please can this change be incorporated into future releases of the core.

technoblogy commented 4 years ago

Actually I recommend a value of 1024.