kinetis/serial: Enable RTS as GPIO for RS485CONTROL#18417
kinetis/serial: Enable RTS as GPIO for RS485CONTROL#18417xiaoxiang781216 merged 4 commits intoapache:masterfrom
Conversation
|
Thank you @ghnotgood :-)
|
|
So we discussed with @michallenc and collegues offline. (Thanks for the discussion!) The problem with However, an oscilloscope shows that The idea behind this PR is to set an GPIO to 1 when sending (
The current idea is that I will try to use Kinetis' timers (FTM or PIT or maybe LPTMR), but I have no experience with that and I am afraid that the lower-half drivers are not implemented. If anyone has any idea, I am happy for suggestions. @cederom I will include the required logs next time, sorry.
This PR applies only for CONFIG_UART?_RS485CONTROL, where RTS is used as RS-485 transmit enable. It should not affect receiving.
I expect something like the following in the which is implicilty the same as: but that is a responsibility of a developer, I think. |
When using CONFIG_UART?_RS485CONTROL, RTS pin is set high when sending data and low otherwise. PIN_UART?_RTS is defined in the board.h file as the appropriate ALT functionality of the chip's port. However, it may happen that PIN_UART?_RTS is wired to another pin of the chip that does not support the RTS as ALT functionality of the UART? in question. This commit addresses such a situation. When UART?_RS485CONTROL_RTSISGPIO is set in menuconfig for the given UART?, it is expected that the PIN_UART?_RTS is defined as GPIO_OUTPUT, and the PIN_UART?_RTS is set high when sending data and low otherwise. Signed-off-by: Jiri Vlasak <jvlasak@elektroline.cz>
|
I have reworked this MR to avoid delays, I am sorry for delay. The build log is: I also did another round of testing from computer to the board via RS485 (USB converter) with the following program: when writing 5 into the Let me know if I should add something more? |
When there are no data in the TX buffer, we can avoid call to the uart_xmitchars. Signed-off-by: Jiri Vlasak <jvlasak@elektroline.cz>
Because it is not needed anymore. The original code here is from the initial implementation in the commit 66b873e. Signed-off-by: Jiri Vlasak <jvlasak@elektroline.cz>
When a developer working on BSP wants UART1 with RTS, the following needs to be added in the BSP's include/board.h file: #define PIN_UART1_RTS PIN_UART1_RTS_1 which says that PIN_UART1_RTS_1 -- the first alternative pin with UART1 RTS function -- should be used for the UART1's RTS. There are no alternative pins for PIN_UART2_RTS, therefore a similar definition is not used for PIN_UART2_RTS. However, that is a complication when we want PIN_UART2_RTS to be defined as GPIO, for example: #define PIN_UART2_RTS (GPIO_OUTPUT | PIN_PORTB | PIN2) In such a case, PIN_UART2_RTS is later redefined to the only alternative function from hardware/kinetis_???pinmux.h file. This patch avoids the redefinition of already defined names. We considered renaming PIN_UART2_RTS to PIN_UART2_RTS_1 in the hardware/kinetis_???pinmux.h file, but that is breaking change. We try to avoid breaking change. Signed-off-by: Jiri Vlasak <jvlasak@elektroline.cz>
cederom
left a comment
There was a problem hiding this comment.
Thank you @ghnotgood :-)
When using CONFIG_UART?_RS485CONTROL, RTS pin is used as a transmit enable pin, i.e., it is set high when sending data and low otherwise. PIN_UART?_RTS is defined in the board.h file as the appropriate ALT functionality of the chip's port.
However, it may happen that PIN_UART?_RTS is wired to another pin of the chip that does not support the RTS as ALT functionality of the UART? in question. This commit addresses such a situation.
When UART?_RS485CONTROL_RTSISGPIO is set in menuconfig for the given UART?, it is expected that the PIN_UART?_RTS is defined as GPIO_OUTPUT, and the PIN_UART?_RTS is set high when sending data and low otherwise.
Summary
When working on NuttX port for our board, I found out that RTS of our UARTs 1, 2, and 3 are wired to Kinetis K60's pins that do not support RTS as an alternate functionality of the given UARTs. It looks like that in the original system of our board, RTSs were wired to GPIOs that were set to high when sending data and low otherwise. This is not considered in NuttX -- it is expected that only pins that support ALT functionality are used.
The commit in this PR allows any chip's pin that is defined as PIN_UART?_RTS and configured as GPIO_OUTPUT to work as RTS for the RS485CONTROL.
Impact
There is new UART configuration option UART?_RS485CONTROL_RTSISGPIO for each ? in 0 to 5. Each option depends on the appropriate UART?_RS485CONTROL.
The up_send procedure of the kinetis_serial.c is changed. If the configuration option is enabled for the given UART, the appropriate GPIO is set high before up_serialout and set low after 150 us delay when up_serialout returned.
Testing
On our board I work on, I configured CONFIG_UART1_RS485CONTROL_RTSISGPIO=y and CONFIG_UART2_RS485CONTROL_RTSISGPIO=y. UART0 is mapped to /dev/ttyS1 and UART1 is mapped to /dev/ttyS2. Then, I run the following test code:
and checked that the program finishes and the printed output makes sense.