ardupilot
ardupilot copied to clipboard
ChibiOS: UART: Add support for RS-485 Driver Enable RTS flow control
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:
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.
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.
The Torqeedo (wiki, code) driver relies on using a TTL to 485 converter. I wonder if this change would change the requirement?
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 https://github.com/ArduPilot/ardupilot/issues/26908.
I have used this on both a CubeOrange and a MATEKL431 periph node (I had to add the RTS/CTS pins to the hwdef).
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.