summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-12-04 19:16:16 +1100
committerDamien George <damien.p.george@gmail.com>2018-12-04 19:16:16 +1100
commit9262f541389d9dc3bb6e1ff06e00b8250b22b671 (patch)
treebfc0b52742a6089c1e1f022f8641058ac160860e
parentda1d849ad19eb04f3dea27e24ca723343225824e (diff)
stm32/uart: Always show the flow setting when printing a UART object.
Also change the order of printing of flow so it is after stop (so bits, parity, stop are one after the other), and reduce code size by using mp_print_str instead of mp_printf where possible. See issue #1981.
-rw-r--r--ports/stm32/uart.c21
-rw-r--r--tests/pyb/uart.py.exp4
2 files changed, 16 insertions, 9 deletions
diff --git a/ports/stm32/uart.c b/ports/stm32/uart.c
index 775d868b8..ace6f3175 100644
--- a/ports/stm32/uart.c
+++ b/ports/stm32/uart.c
@@ -587,20 +587,27 @@ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k
self->uart_id, self->uart.Init.BaudRate, bits);
if (self->uart.Init.Parity == UART_PARITY_NONE) {
mp_print_str(print, "None");
+ } else if (self->uart.Init.Parity == UART_PARITY_EVEN) {
+ mp_print_str(print, "0");
} else {
- mp_printf(print, "%u", self->uart.Init.Parity == UART_PARITY_EVEN ? 0 : 1);
+ mp_print_str(print, "1");
}
- if (self->uart.Init.HwFlowCtl) {
- mp_printf(print, ", flow=");
+ mp_printf(print, ", stop=%u, flow=",
+ self->uart.Init.StopBits == UART_STOPBITS_1 ? 1 : 2);
+ if (self->uart.Init.HwFlowCtl == UART_HWCONTROL_NONE) {
+ mp_print_str(print, "0");
+ } else {
if (self->uart.Init.HwFlowCtl & UART_HWCONTROL_RTS) {
- mp_printf(print, "RTS%s", self->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS ? "|" : "");
+ mp_print_str(print, "RTS");
+ if (self->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
+ mp_print_str(print, "|");
+ }
}
if (self->uart.Init.HwFlowCtl & UART_HWCONTROL_CTS) {
- mp_printf(print, "CTS");
+ mp_print_str(print, "CTS");
}
}
- mp_printf(print, ", stop=%u, timeout=%u, timeout_char=%u, read_buf_len=%u)",
- self->uart.Init.StopBits == UART_STOPBITS_1 ? 1 : 2,
+ mp_printf(print, ", timeout=%u, timeout_char=%u, read_buf_len=%u)",
self->timeout, self->timeout_char,
self->read_buf_len == 0 ? 0 : self->read_buf_len - 1); // -1 to adjust for usable length of buffer
}
diff --git a/tests/pyb/uart.py.exp b/tests/pyb/uart.py.exp
index b5fe0cd0b..434cdfeeb 100644
--- a/tests/pyb/uart.py.exp
+++ b/tests/pyb/uart.py.exp
@@ -12,8 +12,8 @@ UART XB
UART YA
UART YB
ValueError Z
-UART(1, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, timeout_char=3, read_buf_len=64)
-UART(1, baudrate=2400, bits=8, parity=None, stop=1, timeout=1000, timeout_char=7, read_buf_len=64)
+UART(1, baudrate=9600, bits=8, parity=None, stop=1, flow=0, timeout=1000, timeout_char=3, read_buf_len=64)
+UART(1, baudrate=2400, bits=8, parity=None, stop=1, flow=0, timeout=1000, timeout_char=7, read_buf_len=64)
0
3
4