analogdevicesinc/libiio

Serial Backend Issues on Windows

BrentK-ADI opened this issue · 8 comments

When installed on Windows, the serial backend fails to correctly communicate with some USB CDC Serial interfaces. Specifically the Closed Loop Design CDC library (http://www.cld-llc.com/adi.html), running on a ADSP-SC589 Processor (ARM Core).

Running with a normal terminal emulator (VS Code Serial Monitor), the ADSP-SC589 with USB CDC responds correctly when "PRINT" is issued. However, when using iio_info, the commands are never received by the device, and it times out.

Devices running the Maxim MAXUSB stack (https://github.com/Analog-Devices-MSDK/msdk/tree/main/Libraries/MAXUSB) as CDC respond correctly to libiio, including iio_info.

Libserialport version 0.1.1 was re-built from source using MS Visual Studio (VS 2022 v143, Windows SDK 10.0, x64 target) and replaced the libserialport-0.dll provided by the libiio installer. With this rebuilt DLL, everything works as expected.

It is unclear why the provided DLL does not function with all devices.

rgetz commented

I'm assuming it's not something like the default baud rate, or assumption about 8n1? should be something like serial:/dev/ttyUSB0,115200,8n1 as the uri for the entire thing...

If that's as simple as updating the libserialport DLL, that's easy to do. We just need to make sure that we don't introduce new dependencies (notably towards the VS runtime).

Just to clarify, in relation to @rgetz comment. This is the CDC-ACM USB stack running directly on a USB enabled MCU/DSP, not a USB-UART bridge (FTDI-like chip). So in this case, running Windows, my device is COM#, and the baud and comm settings are effectively ignored. But for robustness, I confirmed they had no effect if changed .

This actually opened up a different set of issues, attempting to work with either of my USB enabled MCUs in Linux. The devices are /dev/ttyACM# as opposed to the chipset specific /dev/ttyUSB# devices. Both the MAXUSB and ADI/CLD Stack fails with the following error:

sudo iio_info -u serial:/dev/ttyACM0
Unable to create IIO context serial:/dev/ttyACM0: Inappropriate ioctl for device (25)

I'll see if I can carve out some time to see which ioctl fails, and determine if its a minor fix, or something more, where these ACM based devices are just not supported.

rgetz commented

@BrentK-ADI : I have seen differences even with CDC-ACM having the "wrong" baud rate - I can't explain why, but if I rememeber properly - it did make a difference. On Windows, it's just : serial:comm3,115200,8n1

Maybe @mhennerich can try with Pluto or M2k, on Linux's CDC gadget driver to see if the problem is in libiio, or in your MCU CDC stacks somewhere, ... Michael? (I think they show up as ttyACM# ?)

Maybe @mhennerich can try with Pluto or M2k, on Linux's CDC gadget driver to see if the problem is in libiio, or in your MCU CDC stacks somewhere, ... Michael? (I think they show up as ttyACM# ?)

Sure - works for me on both Linux and Windows

On the target start iiod in USB gadget serial: (since I had iiod already running - I started iiod on a different port)

root@analog:~# systemctl stop serial-getty@ttyGS0.service 

root@analog:~# iiod -s /dev/ttyGS0 -p 2222
Starting IIO Daemon version 0.24.8ab3029c
IPv6 support enabled
Attempting to start Avahi
ERROR: host analog
Avahi: Registered 'iiod on analog #2:2222' to ZeroConf server avahi 0.8
Avahi: Started.
Avahi: Service 'iiod on analog #2:2222' successfully established.

On my desktop Linux:

michael@xxxxxxxxxxx:$ iio_info -u serial:/dev/ttyACM0,115200,8n1 | less
iio_info version: 0.25 (git tag:cfb6249c)
Libiio version: 0.25 (git tag: cfb6249) backends: local xml ip usb serial
IIO context created with serial backend.
Backend version: 0.24 (git tag: 8ab3029)
Backend description string: Linux analog 6.1.0-20981-gb4b289b97539-dirty #445 SMP Thu Oct 26 11:14:06 CEST 2023 aarch64
IIO context has 7 attributes:
hdl_system_id: t on [ng] git branch d t git d clean [2022-10-12 15:19:33] UTC
hw_carrier: Analog Devices, Inc. Jupiter SDR
unique_id: 10400030fc0b0012110018000c17a3a87f
local,kernel: 6.1.0-20981-gb4b289b97539-dirty
uri: serial:/dev/ttyACM0,115200,8n1n
serial,port: /dev/ttyACM0
serial,description: IIO-USB-CDC-ACM - 12345678
IIO context has 10 devices:
hwmon0: ltc2945

On my desktop Windows

C:\Users\xxxxxxxxxxx>iio_info -u serial:COM6,115200,8n1
Library version: 0.24 (git tag: c4498c2)
Compiled with backends: xml ip usb serial
IIO context created with serial backend.
Backend version: 0.24 (git tag: 8ab3029)
Backend description string: COM6: Generic Serial Console (COM6)
IIO context has 5 attributes:
hdl_system_id: t on [ng] git branch d t git d clean [2022-10-12 15:19:33] UTC
hw_carrier: Analog Devices, Inc. Jupiter SDR
unique_id: 10400030fc0b0012110018000c17a3a87f
local,kernel: 6.1.0-20981-gb4b289b97539-dirty
uri: serial:COM6,115200,8n1n
IIO context has 10 devices:

Note: iio_info -u serial:COM6 works equally well.

I was also running into:
ERROR: Unable to create local context: Inappropriate ioctl for device (25)

strace:

lstat64("/sys/class/tty/ttyGS0", {st_mode=S_IFLNK|0777, st_size=0, ...}) = 0
readlink("/sys/class/tty/ttyGS0", "../../devices/virtual/tty/ttyGS0", 4096) = 32
openat(AT_FDCWD, "/dev/ttyGS0", O_RDWR|O_NOCTTY|O_NONBLOCK|O_LARGEFILE) = 4
ioctl(4, TCGETS, {B9600 opost isig icanon echo ...}) = 0
ioctl(4, TIOCMGET, 0xff875974)          = -1 ENOTTY (Inappropriate ioctl for device)
close(4)                                = 0
write(2, "ERROR: Unable to create local co"..., 75ERROR: Unable to create local context: Inappropriate ioctl for device (25)
) = 75
close(3)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++

But that error was causes by getty running on ttyGS0.
After I stopped that service, iiod started normally.

rgetz commented

@mhennerich : Thanks alot.

I think that shows it's not a libiio issue, not a host issue, and is a device stack issue...

@BrentK-ADI - you agree?

rgetz commented

@BrentK-ADI : I'm assuming that since you have not commented in 3 weeks - you are looking for the problem in your USB stacks?

Closing as a result of compatibility issues within USB stacks.