This is my test code which renders the expected (=correct) results on a Photon but not on the Argon
#define BUF_LIMIT 80
uint8_t buf[BUF_LIMIT];
int c;
#define txWAIT Serial1.flush()
//#define txWAIT delay(500)
void setup() {
Serial.begin();
Serial1.begin(115200);
memset(buf, 0, sizeof(buf));
for (char c = '0'; c < '0'+sizeof(buf)-2; c++)
buf[c-'0'] = c;
}
void loop() {
Serial.println();
while(Serial1.read() >= 0); // flush the RX buffer
Serial.printlnf("Should be 0 is %d", Serial1.available());
Serial1.write(buf, sizeof(buf)-1); // pre-fill RX buffer again
txWAIT;
Serial.printlnf("Content of RX buffer should be\r\n%s\r\nbut is", buf);
while((c = Serial1.read()) >= 0) // flush the RX buffer
Serial.write(c);
Serial.println();
Serial.printlnf("Trying to fill buffer with %d characters", sizeof(buf)-5);
Serial1.write(buf, sizeof(buf)-5); // pre-fill RX buffer
txWAIT;
Serial.printlnf("Should be %d is %d", min(sizeof(buf)-5, 63), Serial1.available());
for (int i = 0; i < 10; i++)
Serial.write(Serial1.read());
Serial.println();
Serial.printlnf("Should be %d is %d", min(sizeof(buf)-15, 63-10), Serial1.available());
Serial1.write(buf, 10); // re-fill RX buffer
txWAIT;
Serial.printlnf("Should be %d is %d", min(sizeof(buf)-5, 63), Serial1.available());
delay(1000);
}
It seems the RX buffer (which is supposed to be a circular or ring buffer) is not treated the same way as on Gen1&2 devices. Also the distance between head and tail of the buffer content is not calculated correctly - hence the erronous Serial1.available()
values.
It also seems you can fill the buffer beyond the expected 64 byte limit (on Gen1&2 it’s 64-1 byte to have a gap between head and tail).