diff options
author | Ryan Shaw <ryannathans@hotmail.com> | 2015-11-28 05:30:46 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-12-04 22:20:47 +0000 |
commit | c03dd3b2f94370b9126dfb1bcd5429beb4b6e76d (patch) | |
tree | 5213e4089a5cd00c83f60249863f51084f4c8d2f | |
parent | 54a1d9ecb79608abe3386347b46834f79be20fab (diff) |
stmhal: Fix uart off by 1 circular buffer size.
-rw-r--r-- | stmhal/uart.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/stmhal/uart.c b/stmhal/uart.c index d96c22850..c5b59522d 100644 --- a/stmhal/uart.c +++ b/stmhal/uart.c @@ -429,7 +429,8 @@ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k } mp_printf(print, ", stop=%u, timeout=%u, timeout_char=%u, read_buf_len=%u)", self->uart.Init.StopBits == UART_STOPBITS_1 ? 1 : 2, - self->timeout, self->timeout_char, self->read_buf_len); + self->timeout, self->timeout_char, + self->read_buf_len == 0 ? 0 : self->read_buf_len - 1); // -1 to adjust for usable length of buffer } } @@ -538,8 +539,8 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con __HAL_UART_DISABLE_IT(&self->uart, UART_IT_RXNE); } else { // read buffer using interrupts - self->read_buf_len = args[7].u_int; - self->read_buf = m_new(byte, args[7].u_int << self->char_width); + self->read_buf_len = args[7].u_int + 1; // +1 to adjust for usable length of buffer + self->read_buf = m_new(byte, self->read_buf_len << self->char_width); __HAL_UART_ENABLE_IT(&self->uart, UART_IT_RXNE); HAL_NVIC_SetPriority(self->irqn, IRQ_PRI_UART, IRQ_SUBPRI_UART); HAL_NVIC_EnableIRQ(self->irqn); |