ghnotgood opened a new pull request, #18417:
URL: https://github.com/apache/nuttx/pull/18417
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
*Update this section, where applicable, on how change affects users,
build process, hardware, documentation, security, compatibility, etc.*
- 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.
## Testin
On our board I work on, I configured CONFIG_KINETIS_UART0=y and
CONFIG_KINETIS_UART1=y. UART0 is mapped to /dev/ttyS1 and UART1 is mapped to
/dev/ttyS2. Then, I run the following test code:
```
static const char *devusart1 = "/dev/ttyS1";
static const char *devusart2 = "/dev/ttyS2";
int main(int argc, char **argv)
{
_info("test from %s to %s", devusart1, devusart2);
int from = open(devusart1, O_RDWR);
if (0 > from) {
_err("ERROR: failed to open %s: %s", devusart1,
strerror(errno));
return 1;
} else {
_info("from is %d", from);
}
int to = open(devusart2, O_RDWR);
if (0 > to) {
_err("ERROR: failed to open %s: %s", devusart2,
strerror(errno));
return 1;
} else {
_info("to is %d", to);
}
int i, r;
uint8_t sb, rb;
for (i = 0; i < 260; i++) {
sb = i;
r = write(from, &sb, 1);
_info("(%d.) wrote %d byte(s): %d", i, r, sb);
_info("now, try to read it");
r = read(to, &rb, 1);
_info("read %d byte(s): %d", r, rb);
rb++;
_info("incremented what was read, sending back");
r = write(to, &rb, 1);
_info("back %d byte(s): %d", r, rb);
_info("now, try to back-read it");
r = read(from, &sb, 1);
_info("back-read %d byte(s): %d", r, sb);
if (1 + i == sb && 1 + i == rb) {
_info("GOOD %d -> %d == %d", i, sb, rb);
} else {
_info("BAAD %d -> %d == %d", i, sb, rb);
}
}
close(from);
close(to);
return 0;
}
```
and checked that the program finishes and the printed output makes sense.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]