Search code examples
gousbuarttty

ttyusb/uart sends 'USB' during transfer


I am using Go for a project and am transmitting data to an embedded device via the serial port (ttyusb). During fast and "large" transfers I've noticed that the transmitted data did not match the values I'd wanted to send.

I've tried various available libraries, in the end they all read and write using syscalls. So I've attached a Logic Analyzer to see what's going on.

Then I noticed that the data mismatch in the output had a clear pattern: Instead of sending my data the serial port would interleave my data with the following values:

0x55, 0x53, 0x42, 0x53, 0x70, 0x02

Followed by zeros (0x00). In total 22 Bytes. The total number of bytes transmitted via the serial line did match the number of bytes I wanted to write > so essentially my data was masked with these 22 Byte-Blocks. The weird thing is that I can translate those bytes to ASCII

0x55, 0x53, 0x42, 0x53, 0x70 = "USBSp"

Now my Question is: Can't I send arbitrary data (HEX values) over the serial port or are there some control characters that I should be aware of that would make the serial port send out Identity information or the like?

[EDIT]: Additional Information:

  • Host is MacOS running Go v1.10; tried with go.bug.st/serial.v1 and github.com/tarm/serial, various communication settings (bitrate etc.)

  • Target is nRF52840 preview development kit, using Nordic nRF5 SDK v12.3.0_d7731ad (not the newest, I know, but the only one supporting other boards too). Using app_uart_x API


Solution

  • you have to configure the serial port. the settings for both devices for baud rate, start/stop bits, ... have to match. then there are libraries in go like https://github.com/jacobsa/go-serial that enable standard serial port communication with that you can also use any hex values.

    i can not say why the USBSp is sent because you did not post any code and gave no information what libraries you use. very likely this is not generated by the kernel module and instead by higher layer software because the kernel module used is usb-serial and USBSp does not appear in the source code :

    https://elixir.bootlin.com/linux/v4.0/source/drivers/usb/serial/usb-serial.c

    also not in kernel module ftdi-sio ( if you use ftdi chip )

    https://elixir.bootlin.com/linux/v4.0/source/drivers/usb/serial/ftdi_sio.c

    and also not in https://elixir.bootlin.com/linux/v3.3/source/drivers/usb/core/urb.c