Browse Source

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.
pull/4088/head
Damien George 6 years ago
parent
commit
9262f54138
  1. 21
      ports/stm32/uart.c
  2. 4
      tests/pyb/uart.py.exp

21
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
}

4
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

Loading…
Cancel
Save