Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for COM Port RS232/RS422/RS485 Configuration #15

Open
sp193 opened this issue Nov 18, 2022 · 1 comment
Open

Documentation for COM Port RS232/RS422/RS485 Configuration #15

sp193 opened this issue Nov 18, 2022 · 1 comment

Comments

@sp193
Copy link

sp193 commented Nov 18, 2022

Hi,

I have an UP Xtreme i11 box. The product specifications say that it has 2x COM ports that can operate in RS232/RS422/RS485 mode, but I cannot find any documentation for changing the operating mode.

There seems to be no setting in the BIOS for changing the port's operating mode. This thread in the forum suggests that the operating mode must be controlled by the OS because it is a USB to serial device, but what are the steps for configuring the operating mode? I am using Ubuntu Linux, and could not find any documentation on a standard procedure for doing this.

I have attempted to use the TIOCGRS485/TIOCSRS485 ioctl() calls to change the operating mode, but invoking ioctl() with TIOCSRS485 results in errno 25 (inappropriate ioctl for device) for /dev/ttyUSB0 or /dev/ttyUSB1.

My project involves an environmental sensor that is connected via half-duplex RS-485. With the same sensor and software, I am able to read values with another computer that runs Linux. So I am guessing that the COM ports on my UP Xtreme i11 are stuck in RS232 mode, which is why communication with the sensor is not possible.

Thanks for your help, in advance.

@sp193
Copy link
Author

sp193 commented Dec 4, 2022

It is probably as Roger from AAEON mentioned. There is no option for setting the operating mode in the BIOS and the operating mode needs to be configured from the driver because it is a USB to serial ports IC. COM3 for the UP Xtreme i11 corresponds to ttyUSB0, while COM4 corresponds to ttyUSB1.
Unfortunately, the F81534 kernel module from mainline Linux does not support such a move and this is an undocumented limitation. It can, however, load settings and configure the hardware for RS-232/RS-485/RS-422 mode, but just not change its settings.

Finktek appears to have attempted to commit support for the F81532/534 into the mainline Linux kernel around 2016. There were at least 11 revisions before we ended up with the final version we see today. It started off as a driver with the required support for the TIOCGRS485/TIOCSRS485 ioctl() calls, until somewhere around patch v7. That was when the Linux kernel folks suggested that a subset of the original driver be contributed, without the functionality for configuring the serial port operating mode. They hoped to have some universal design for all hardware with similar capabilities, but it has been 6 years since. It was suggested at the time that Fintek contribute a user-mode program for switching the operating mode, but this does not seem to have become part of any Linux distribution.

How about you drop mode-switching support completely for now (e.g.
gpiolib and rs485-ioctl) and focus on getting the basic functionality
right first?

You could also consider extending you user-space tool and use that to
switch modes (e.g. reprogram the device eeprom) through libudev, at
least until a generic interface is in place.

What Fintek appears to have done:

  1. Provide source code for a tool for changing the GPIO and operating mode for the F81532/F81534, but this is neither clearly explained nor linked to from their website. I found it from the same mailing list, but it was listed as containing sample code in their submission: https://bitbucket.org/hpeter/fintek-general/src/master/f81534/
  2. Provide their own, full version of the F81532/534 kernel module on their website, but they do not seem to have explained the difference from the version included with Linux and what they would recommend users to do.

UP/AAEON did not make any recommendation on their websites and the user manual.


I tried (1), by compiling Fintek's code with libusb-1.0-0-dev. With some trial-and-error, I got it to change the GPIO and serial port operating mode for RS-485. I was skeptical of whether that is the right thing to do because it is 5-year old code that makes changes to the flash storage of the device, so I feared it could cause a brick.

We need to use the -s option, to change both the UART and GPIO modes. Using -m to set the UART mode alone, did not allow the hardware to operate in RS-485 mode. I entered something like this to configure COM4:

./f81534_setting -s 3 -t ttyUSB1

It is possible to get it to list the current operating modes:

./f81534_setting -d -t ttyUSB1

After setting the GPIO and UART mode, I chose to reboot to let the F81534 module in the kernel read the new parameters from the device's flash storage. But there may be smarter ways to re-load the module.


I hope that we could have improved documentation in this area, or perhaps if UP/AAEON/Fintek can follow up with the Linux kernel folks to complete this incomplete feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant