stm32/machine_uart: Allow re-init'ing a static UART object.
Just disallow changing the rxbuf which will be some static RAM (can't free it and soft-reset would lose any dynamically allocated buffer).
This commit is contained in:
parent
88971342b1
commit
9ae50d22c9
|
@ -237,11 +237,6 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const
|
|||
mp_arg_parse_all(n_args, pos_args, kw_args,
|
||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&args);
|
||||
|
||||
// static UARTs are used for internal purposes and shouldn't be reconfigured
|
||||
if (self->is_static) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("UART is static and can't be init'd"));
|
||||
}
|
||||
|
||||
// baudrate
|
||||
uint32_t baudrate = args.baudrate.u_int;
|
||||
|
||||
|
@ -306,20 +301,28 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, size_t n_args, const
|
|||
self->timeout_char = min_timeout_char;
|
||||
}
|
||||
|
||||
// setup the read buffer
|
||||
m_del(byte, self->read_buf, self->read_buf_len << self->char_width);
|
||||
if (args.rxbuf.u_int >= 0) {
|
||||
// rxbuf overrides legacy read_buf_len
|
||||
args.read_buf_len.u_int = args.rxbuf.u_int;
|
||||
}
|
||||
if (args.read_buf_len.u_int <= 0) {
|
||||
// no read buffer
|
||||
uart_set_rxbuf(self, 0, NULL);
|
||||
if (self->is_static) {
|
||||
// Static UARTs have fixed memory for the rxbuf and can't be reconfigured.
|
||||
if (args.rxbuf.u_int >= 0) {
|
||||
mp_raise_ValueError(MP_ERROR_TEXT("UART is static and rxbuf can't be changed"));
|
||||
}
|
||||
uart_set_rxbuf(self, self->read_buf_len, self->read_buf);
|
||||
} else {
|
||||
// read buffer using interrupts
|
||||
size_t len = args.read_buf_len.u_int + 1; // +1 to adjust for usable length of buffer
|
||||
uint8_t *buf = m_new(byte, len << self->char_width);
|
||||
uart_set_rxbuf(self, len, buf);
|
||||
// setup the read buffer
|
||||
m_del(byte, self->read_buf, self->read_buf_len << self->char_width);
|
||||
if (args.rxbuf.u_int >= 0) {
|
||||
// rxbuf overrides legacy read_buf_len
|
||||
args.read_buf_len.u_int = args.rxbuf.u_int;
|
||||
}
|
||||
if (args.read_buf_len.u_int <= 0) {
|
||||
// no read buffer
|
||||
uart_set_rxbuf(self, 0, NULL);
|
||||
} else {
|
||||
// read buffer using interrupts
|
||||
size_t len = args.read_buf_len.u_int + 1; // +1 to adjust for usable length of buffer
|
||||
uint8_t *buf = m_new(byte, len << self->char_width);
|
||||
uart_set_rxbuf(self, len, buf);
|
||||
}
|
||||
}
|
||||
|
||||
// compute actual baudrate that was configured
|
||||
|
|
Loading…
Reference in New Issue