Strange bytes prefix with HarwareSerial `println`

Hi all,
I have a strange error: when sending a string from my esp32 via uart to my rp2040-based board running micropython, there seems to be extra data prepended sometimes.

This is my esp32 code:

#include <Arduino.h>
#include <HardwareSerial.h>

HardwareSerial uart = HardwareSerial(2);

void setup() {
    uart.begin(250000, SERIAL_8N1, 16, 17);
    uart.setTimeout(100);
    uart.println("12345");
}

void loop() {}

on the receiving end:

from machine import Pin, UART

remote_connection: UART = UART(
    1,
    baudrate=250000,
    tx=Pin("GP4"),
    rx=Pin("GP5"),
    timeout=2**31 - 1,
    timeout_char=2**31 - 1,
)

inp = remote_connection.readline()
print(inp)

The output is b'\xff12345\r\n' instead of b'12345\r\n'. Occasionally, the correct string is received. Does anyone have an idea what the cause of this could be?

Regards,
Bruce

There is allready an object “Serial2”:

Change your sketch to

#include <Arduino.h>

void setup() {
    Serial2.begin(250000);
    Serial2.println("12345");
}

void loop() {}

I was able to test this successfully with two ESP32s (at a baud rate of 250000).

However, the error may also be on the RP2040 side or the UART library used there.

I tried using Serial2, and still the same result. I find it strange, that it works when I connect via tio from my PC and send the same string to the rp2040, it receives the correct string.

I have also tested receiving from the esp32 via pySerial from my PC:

import serial

with serial.Serial("/dev/ttyUSB0", 250000) as ser:
    while True:
        print(ser.read_until())

And it receives the correct string (b'12345\r\n').

Similarly, I have tried sending to the rp2040 from my PC via pySerial:

import serial
import time

with serial.Serial("/dev/ttyUSB0", 250000) as ser:
    while True:
        ser.write(b"12345\r\n")
        time.sleep(1)

Which also yields the correct string on the rp2040 (b'12345\r\n').

I am unsure how to debug this further, and any help or advice would be greatly appreciated.

Regards,
Bruce