aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter D. Gray2017-12-20 10:31:05 -0500
committerDamien George2017-12-22 15:37:17 +1100
commit7a46d9ae7313d4f92e9c32bf4dcc1e161a56d7ff (patch)
tree94df4b34c7451034069672c6aec1e8d3cc2e5520
parentc73360bfdbecb0e2143147a7e7223c8161938456 (diff)
stm32/uart: Add support for 7-bit modes: 7N1 and 7N2.
-rw-r--r--ports/stm32/uart.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/ports/stm32/uart.c b/ports/stm32/uart.c
index 0b46d4f04..b2962984f 100644
--- a/ports/stm32/uart.c
+++ b/ports/stm32/uart.c
@@ -500,7 +500,14 @@ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k
if (!self->is_enabled) {
mp_printf(print, "UART(%u)", self->uart_id);
} else {
- mp_int_t bits = (self->uart.Init.WordLength == UART_WORDLENGTH_8B ? 8 : 9);
+ mp_int_t bits;
+ switch (self->uart.Init.WordLength) {
+ #ifdef UART_WORDLENGTH_7B
+ case UART_WORDLENGTH_7B: bits = 7; break;
+ #endif
+ case UART_WORDLENGTH_8B: bits = 8; break;
+ case UART_WORDLENGTH_9B: default: bits = 9; break;
+ }
if (self->uart.Init.Parity != UART_PARITY_NONE) {
bits -= 1;
}
@@ -580,6 +587,10 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const
init->WordLength = UART_WORDLENGTH_8B;
} else if (bits == 9) {
init->WordLength = UART_WORDLENGTH_9B;
+ #ifdef UART_WORDLENGTH_7B
+ } else if (bits == 7) {
+ init->WordLength = UART_WORDLENGTH_7B;
+ #endif
} else {
mp_raise_ValueError("unsupported combination of bits and parity");
}