Commit c03dd3b2 authored by Ryan Shaw's avatar Ryan Shaw Committed by Damien George
Browse files

stmhal: Fix uart off by 1 circular buffer size.

parent 54a1d9ec
...@@ -429,7 +429,8 @@ STATIC void pyb_uart_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k ...@@ -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)", mp_printf(print, ", stop=%u, timeout=%u, timeout_char=%u, read_buf_len=%u)",
self->uart.Init.StopBits == UART_STOPBITS_1 ? 1 : 2, 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 ...@@ -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); __HAL_UART_DISABLE_IT(&self->uart, UART_IT_RXNE);
} else { } else {
// read buffer using interrupts // read buffer using interrupts
self->read_buf_len = args[7].u_int; self->read_buf_len = args[7].u_int + 1; // +1 to adjust for usable length of buffer
self->read_buf = m_new(byte, args[7].u_int << self->char_width); self->read_buf = m_new(byte, self->read_buf_len << self->char_width);
__HAL_UART_ENABLE_IT(&self->uart, UART_IT_RXNE); __HAL_UART_ENABLE_IT(&self->uart, UART_IT_RXNE);
HAL_NVIC_SetPriority(self->irqn, IRQ_PRI_UART, IRQ_SUBPRI_UART); HAL_NVIC_SetPriority(self->irqn, IRQ_PRI_UART, IRQ_SUBPRI_UART);
HAL_NVIC_EnableIRQ(self->irqn); HAL_NVIC_EnableIRQ(self->irqn);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment