summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniël van de Giessen <daniel@dvdgiessen.nl>2023-06-29 14:55:34 +0200
committerDamien George <damien@micropython.org>2023-09-01 21:01:26 +1000
commitf8bd6778c85322b33008d749ae4021cafa067044 (patch)
treef5325c1f4c371d517e4fe86b8385bc95e2bf0804
parentba8aad3d1dbc25a397c9b23b1428018c5a7be505 (diff)
esp32: Support JTAG console, free up UART.
CONFIG_USB_OTG_SUPPORTED is automatically set by the ESP-IDF when the chip supports USB-OTG, which is the case for the ESP32-S2 and ESP32-S3. When trying to use the JTAG console with these chips, it would not work because our USB implementation will take over control over the USB port, breaking the JTAG console in the process. Thus, when the board is configured to use the JTAG console, we should not enable our USB console support. Additionally, this change also frees up UART0 when an USB-based console is configured, since there's no reason to prevent (re)configuration of UART0 for other uses in that case. Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
-rw-r--r--ports/esp32/machine_uart.c7
-rw-r--r--ports/esp32/main.c6
-rw-r--r--ports/esp32/mphalport.c6
-rw-r--r--ports/esp32/uart.c10
-rw-r--r--ports/esp32/uart.h6
-rw-r--r--ports/esp32/usb.c4
6 files changed, 26 insertions, 13 deletions
diff --git a/ports/esp32/machine_uart.c b/ports/esp32/machine_uart.c
index e7b2b8376..541d7ccc5 100644
--- a/ports/esp32/machine_uart.c
+++ b/ports/esp32/machine_uart.c
@@ -153,9 +153,11 @@ STATIC void machine_uart_init_helper(machine_uart_obj_t *self, size_t n_args, co
if (args[ARG_txbuf].u_int >= 0 || args[ARG_rxbuf].u_int >= 0) {
// must reinitialise driver to change the tx/rx buffer size
+ #if MICROPY_HW_ENABLE_UART_REPL
if (self->uart_num == MICROPY_HW_UART_REPL) {
mp_raise_ValueError(MP_ERROR_TEXT("UART buffer size is fixed"));
}
+ #endif
if (args[ARG_txbuf].u_int >= 0) {
self->txbuf = args[ARG_txbuf].u_int;
@@ -353,8 +355,11 @@ STATIC mp_obj_t machine_uart_make_new(const mp_obj_type_t *type, size_t n_args,
#endif
}
+ #if MICROPY_HW_ENABLE_UART_REPL
// Only reset the driver if it's not the REPL UART.
- if (uart_num != MICROPY_HW_UART_REPL) {
+ if (uart_num != MICROPY_HW_UART_REPL)
+ #endif
+ {
// Remove any existing configuration
uart_driver_delete(self->uart_num);
diff --git a/ports/esp32/main.c b/ports/esp32/main.c
index a6346b027..1420dd579 100644
--- a/ports/esp32/main.c
+++ b/ports/esp32/main.c
@@ -89,10 +89,10 @@ void mp_task(void *pvParameter) {
#if MICROPY_PY_THREAD
mp_thread_init(pxTaskGetStackStart(NULL), MP_TASK_STACK_SIZE / sizeof(uintptr_t));
#endif
- #if CONFIG_USB_OTG_SUPPORTED
- usb_init();
- #elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
+ #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
usb_serial_jtag_init();
+ #elif CONFIG_USB_OTG_SUPPORTED
+ usb_init();
#endif
#if MICROPY_HW_ENABLE_UART_REPL
uart_stdout_init();
diff --git a/ports/esp32/mphalport.c b/ports/esp32/mphalport.c
index 63a674c24..d7003a143 100644
--- a/ports/esp32/mphalport.c
+++ b/ports/esp32/mphalport.c
@@ -111,10 +111,10 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) {
if (release_gil) {
MP_THREAD_GIL_EXIT();
}
- #if CONFIG_USB_OTG_SUPPORTED
- usb_tx_strn(str, len);
- #elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
+ #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
usb_serial_jtag_tx_strn(str, len);
+ #elif CONFIG_USB_OTG_SUPPORTED
+ usb_tx_strn(str, len);
#endif
#if MICROPY_HW_ENABLE_UART_REPL
uart_stdout_tx_strn(str, len);
diff --git a/ports/esp32/uart.c b/ports/esp32/uart.c
index 358d43470..fc69e279e 100644
--- a/ports/esp32/uart.c
+++ b/ports/esp32/uart.c
@@ -26,14 +26,16 @@
* THE SOFTWARE.
*/
-#include <stdio.h>
-
-#include "hal/uart_hal.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "uart.h"
+#if MICROPY_HW_ENABLE_UART_REPL
+
+#include <stdio.h>
+#include "hal/uart_hal.h"
+
// Backwards compatibility for when MICROPY_HW_UART_REPL was a ESP-IDF UART
// driver enum. Only UART_NUM_0 was supported with that version of the driver.
#define UART_NUM_0 0
@@ -118,3 +120,5 @@ STATIC void IRAM_ATTR uart_irq_handler(void *arg) {
}
}
}
+
+#endif // MICROPY_HW_ENABLE_UART_REPL
diff --git a/ports/esp32/uart.h b/ports/esp32/uart.h
index 6410db24c..3d88eed82 100644
--- a/ports/esp32/uart.h
+++ b/ports/esp32/uart.h
@@ -30,9 +30,11 @@
// Whether to enable the REPL on a UART.
#ifndef MICROPY_HW_ENABLE_UART_REPL
-#define MICROPY_HW_ENABLE_UART_REPL (!CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG)
+#define MICROPY_HW_ENABLE_UART_REPL (!CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG)
#endif
+#if MICROPY_HW_ENABLE_UART_REPL
+
#ifndef MICROPY_HW_UART_REPL
#define MICROPY_HW_UART_REPL (0)
#endif
@@ -44,4 +46,6 @@
void uart_stdout_init(void);
int uart_stdout_tx_strn(const char *str, size_t len);
+#endif // MICROPY_HW_ENABLE_UART_REPL
+
#endif // MICROPY_INCLUDED_ESP32_UART_H
diff --git a/ports/esp32/usb.c b/ports/esp32/usb.c
index b9d99676d..2e417755c 100644
--- a/ports/esp32/usb.c
+++ b/ports/esp32/usb.c
@@ -28,7 +28,7 @@
#include "py/mphal.h"
#include "usb.h"
-#if CONFIG_USB_OTG_SUPPORTED
+#if CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#include "esp_timer.h"
#ifndef NO_QSTR
@@ -97,4 +97,4 @@ void usb_tx_strn(const char *str, size_t len) {
}
}
-#endif // CONFIG_USB_OTG_SUPPORTED
+#endif // CONFIG_USB_OTG_SUPPORTED && !CONFIG_ESP_CONSOLE_USB_CDC && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG