mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 20:50:14 +01:00
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:
@@ -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_arg_parse_all(n_args, pos_args, kw_args,
|
||||||
MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&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
|
// baudrate
|
||||||
uint32_t baudrate = args.baudrate.u_int;
|
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;
|
self->timeout_char = min_timeout_char;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup the read buffer
|
if (self->is_static) {
|
||||||
m_del(byte, self->read_buf, self->read_buf_len << self->char_width);
|
// Static UARTs have fixed memory for the rxbuf and can't be reconfigured.
|
||||||
if (args.rxbuf.u_int >= 0) {
|
if (args.rxbuf.u_int >= 0) {
|
||||||
// rxbuf overrides legacy read_buf_len
|
mp_raise_ValueError(MP_ERROR_TEXT("UART is static and rxbuf can't be changed"));
|
||||||
args.read_buf_len.u_int = args.rxbuf.u_int;
|
}
|
||||||
}
|
uart_set_rxbuf(self, self->read_buf_len, self->read_buf);
|
||||||
if (args.read_buf_len.u_int <= 0) {
|
|
||||||
// no read buffer
|
|
||||||
uart_set_rxbuf(self, 0, NULL);
|
|
||||||
} else {
|
} else {
|
||||||
// read buffer using interrupts
|
// setup the read buffer
|
||||||
size_t len = args.read_buf_len.u_int + 1; // +1 to adjust for usable length of buffer
|
m_del(byte, self->read_buf, self->read_buf_len << self->char_width);
|
||||||
uint8_t *buf = m_new(byte, len << self->char_width);
|
if (args.rxbuf.u_int >= 0) {
|
||||||
uart_set_rxbuf(self, len, buf);
|
// 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
|
// compute actual baudrate that was configured
|
||||||
|
|||||||
Reference in New Issue
Block a user