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>
pull/12200/head
Daniël van de Giessen 2023-06-29 14:55:34 +02:00 zatwierdzone przez Damien George
rodzic ba8aad3d1d
commit f8bd6778c8
6 zmienionych plików z 26 dodań i 13 usunięć

Wyświetl plik

@ -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);

Wyświetl plik

@ -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();

Wyświetl plik

@ -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);

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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