|
35 | 35 | #include "py/stream.h"
|
36 | 36 | #include "py/mperrno.h"
|
37 | 37 | #include "modmachine.h"
|
| 38 | +#include "uart.h" |
38 | 39 |
|
39 | 40 | #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 1, 0)
|
40 | 41 | #define UART_INV_TX UART_INVERSE_TXD
|
@@ -151,6 +152,10 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
|
151 | 152 |
|
152 | 153 | if (args[ARG_txbuf].u_int >= 0 || args[ARG_rxbuf].u_int >= 0) {
|
153 | 154 | // must reinitialise driver to change the tx/rx buffer size
|
| 155 | + if (self->uart_num == MICROPY_HW_UART_REPL) { |
| 156 | + mp_raise_ValueError(MP_ERROR_TEXT("UART buffer size is fixed")); |
| 157 | + } |
| 158 | + |
154 | 159 | if (args[ARG_txbuf].u_int >= 0) {
|
155 | 160 | self->txbuf = args[ARG_txbuf].u_int;
|
156 | 161 | }
|
@@ -291,12 +296,6 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
|
291 | 296 | mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("UART(%d) does not exist"), uart_num);
|
292 | 297 | }
|
293 | 298 |
|
294 |
| - // Attempts to use UART0 from Python has resulted in all sorts of fun errors. |
295 |
| - // FIXME: UART0 is disabled for now. |
296 |
| - if (uart_num == UART_NUM_0) { |
297 |
| - mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("UART(%d) is disabled (dedicated to REPL)"), uart_num); |
298 |
| - } |
299 |
| - |
300 | 299 | // Defaults
|
301 | 300 | uart_config_t uartcfg = {
|
302 | 301 | .baud_rate = 115200,
|
@@ -338,14 +337,17 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
|
338 | 337 | #endif
|
339 | 338 | }
|
340 | 339 |
|
341 |
| - // Remove any existing configuration |
342 |
| - uart_driver_delete(self->uart_num); |
| 340 | + // Only reset the driver if it's not the REPL UART. |
| 341 | + if (uart_num != MICROPY_HW_UART_REPL) { |
| 342 | + // Remove any existing configuration |
| 343 | + uart_driver_delete(self->uart_num); |
343 | 344 |
|
344 |
| - // init the peripheral |
345 |
| - // Setup |
346 |
| - uart_param_config(self->uart_num, &uartcfg); |
| 345 | + // init the peripheral |
| 346 | + // Setup |
| 347 | + uart_param_config(self->uart_num, &uartcfg); |
347 | 348 |
|
348 |
| - uart_driver_install(uart_num, self->rxbuf, self->txbuf, 0, NULL, 0); |
| 349 | + uart_driver_install(uart_num, self->rxbuf, self->txbuf, 0, NULL, 0); |
| 350 | + } |
349 | 351 |
|
350 | 352 | mp_map_t kw_args;
|
351 | 353 | mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
|
|
0 commit comments