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

ChibiOS: UART: Add support for RS-485 Driver Enable RTS flow control #26930

Merged
merged 6 commits into from
May 27, 2024

Conversation

IamPete1
Copy link
Member

@IamPete1 IamPete1 commented Apr 30, 2024

This adds support for outputting a driver enable signal from the UART. That is a line that is held high for the duration of a transmit. This is used with RS-485 transceivers. The STM32 has hardware support for this, so we just need to set the pin to the correct alternative function and set the bit in the UART config.

The new flow control type can be set with the BRD_SERx_RTSCTS param.

This is MAVLink with it enabled:
image

image

Currently this just uses the default timings for the time the pin goes high before the transmit is started and the time it takes to go low after the transmit has finished. There are config registers we could use to change this if we needed to.

In order to know which alternate function to use the information must be passed in from the hwdef.

@IamPete1
Copy link
Member Author

IamPete1 commented Apr 30, 2024

Looks like this is not supported on F4's because there is no USART_CR3_DEM define. I guess we could ifdef the section based on that?

Edit: ifdef added.

@rmackay9
Copy link
Contributor

rmackay9 commented May 1, 2024

The Torqeedo (wiki, code) driver relies on using a TTL to 485 converter. I wonder if this change would change the requirement?

Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, I'd just like to do a bit of testing. I'll do that testing and get back to you

@IamPete1
Copy link
Member Author

IamPete1 commented May 1, 2024

The Torqeedo (wiki, code) driver relies on using a TTL to 485 converter. I wonder if this change would change the requirement?

Interesting, I did not think we supported and RS-485 devices currently. You would still need the converter. This PR would remove the need for the TRQD_DE_PIN and the manual handling of setting and un-setting that in the driver. It should also allow for much faster data rates and more reliable switching between TX and RX because its at the hardware level. However, the hardware support requires that we use the RTS pin for the UART. The Torqeedo uses the CTS pin and gives the option to us any other GPIO so you have more options for serial ports and flight controllers. I did try and get it working in software at the UART driver level but could not get it working reliably due to #26908.

@IamPete1
Copy link
Member Author

I have used this on both a CubeOrange and a MATEKL431 periph node (I had to add the RTS/CTS pins to the hwdef).

@tridge tridge merged commit e10b4ab into ArduPilot:master May 27, 2024
92 checks passed
@rmackay9
Copy link
Contributor

As discussed on the dev call, at some point I hope to rework the Torqeedo library to make use of this because it could improve reliability and/or allow higher data rates. We need to be careful though that it works on all processors (even the lower end ones). It's probably not supported on Linux board either.

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

Successfully merging this pull request may close these issues.

None yet

4 participants