-
Notifications
You must be signed in to change notification settings - Fork 63
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
serial-unix: on linux, use the termios2 api to support arbitrary baud rates #49
Comments
I'm not sure when this was added, but there is a @dcuddeback I tried to use a baud rate of 187500 on OS X and I got an "Invalid argument" error. Is this what you mean by
I may be able to change the baud rate of of my chip, but its an embedded platform and I'd prefer to not use a bunch of clock dividers to get a standard rate. This may work on Raspbian Linux, which is my eventual target platform, but for now I'm having trouble getting the serial pins to behave, so I'm not sure when I'll get to test that. |
@TechnoSam Each platform has a different set of baud rates that it supports via serial-rs/serial-unix/src/tty.rs Lines 408 to 461 in cb28b14
Those are platform-specific baud rates, but not arbitrary baud rates. The plan is to support arbitrary baud rates, too, but that's not implemented yet. Arbitrary baud rates are also platform-specific. Linux (this ticket) is probably the easiest to support, because it provides the For Raspian, you would want to follow this ticket. For OS X, #37 is a complementary ticket. |
termios(3) definitions were added to libc in v0.2.3. Baud rate constants were added to libc in v0.2.21. Utilitizing the libc definitions for the termios API enables dropping the termios crate as a dependency. Fewer dependencies is nice in its own right, but this also paves the way for a simpler implementation of custom baud rates on Linux (#49). Custom baud rates on Linux are best implemented with the termios2 API provided by the Linux kernel, which is not part of the termios crate. This most likely means the Linux implementation will use the "unsafe" interfaces directly for termios2. Doing the same for other termios-based implementations allows the implementations to remain as similar as possible, which makes it easier to maintain both implementations in parallel.
The termios2 struct with TCSETS2/TCGETS2 ioctls is the modern way to set arbitrary baud rates on Linux. This commit does *not* implement custom baud rates (#49), but lays the groundwork for doing so by replacing the POSIX termios API with the Linux-specific termios2 API when Linux is the compilation target. Since this is an alternative to the termios(3) API, it was necessary to manually modify baud rates in c_cflags, c_ospeed, and c_ispeed members of termios2 in order to implement replacements for cfsetspeed(), cfgetispeed(), and cfgetospeed(). Helpful documentation can be found in Picocom's writeup of termios2 [1] and drivers/tty/tty_baudrate.c from the Linux kernel source [2]. No behavior should change due to this commit. The termios2 struct was added to libc in v0.2.33. [1]: https://github.com/npat-efault/picocom/blob/1acf1ddabaf3576b4023c4f6f09c5a3e4b086fb8/termios2.txt [2]: https://github.com/torvalds/linux/blob/ba4dbdedd3edc2798659bcd8b1a184ea8bdd04dc/drivers/tty/tty_baudrate.c#L49-L121
[close #49] Implements arbitrary baud rates for Linux by utilizing BOTHER and c_ospeed/c_ispeed in the termios2 struct.
termios(3) definitions were added to libc in v0.2.3. Baud rate constants were added to libc in v0.2.21. Utilitizing the libc definitions for the termios API enables dropping the termios crate as a dependency. Fewer dependencies is nice in its own right, but this also paves the way for a simpler implementation of custom baud rates on Linux (dcuddeback#49). Custom baud rates on Linux are best implemented with the termios2 API provided by the Linux kernel, which is not part of the termios crate. This most likely means the Linux implementation will use the "unsafe" interfaces directly for termios2. Doing the same for other termios-based implementations allows the implementations to remain as similar as possible, which makes it easier to maintain both implementations in parallel.
The termios2 struct with TCSETS2/TCGETS2 ioctls is the modern way to set arbitrary baud rates on Linux. This commit does *not* implement custom baud rates (dcuddeback#49), but lays the groundwork for doing so by replacing the POSIX termios API with the Linux-specific termios2 API when Linux is the compilation target. Since this is an alternative to the termios(3) API, it was necessary to manually modify baud rates in c_cflags, c_ospeed, and c_ispeed members of termios2 in order to implement replacements for cfsetspeed(), cfgetispeed(), and cfgetospeed(). Helpful documentation can be found in Picocom's writeup of termios2 [1] and drivers/tty/tty_baudrate.c from the Linux kernel source [2]. No behavior should change due to this commit. The termios2 struct was added to libc in v0.2.33. [1]: https://github.com/npat-efault/picocom/blob/1acf1ddabaf3576b4023c4f6f09c5a3e4b086fb8/termios2.txt [2]: https://github.com/torvalds/linux/blob/ba4dbdedd3edc2798659bcd8b1a184ea8bdd04dc/drivers/tty/tty_baudrate.c#L49-L121
[close dcuddeback#49] Implements arbitrary baud rates for Linux by utilizing BOTHER and c_ospeed/c_ispeed in the termios2 struct.
Picocom includes some documentation on it: https://github.com/npat-efault/picocom/blob/master/termios2.txt
Assuming underlying adapter support, using termios2 allows more flexible baud rate selection.
The text was updated successfully, but these errors were encountered: