Skip to content

Commit

Permalink
[Console] more secondary output choices
Browse files Browse the repository at this point in the history
  • Loading branch information
chipweinberger committed Nov 4, 2022
1 parent 84be4db commit 4565d02
Show file tree
Hide file tree
Showing 21 changed files with 189 additions and 91 deletions.
2 changes: 1 addition & 1 deletion components/app_trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ menu "Application Level Tracing"
bool "USB_CDC"
select APPTRACE_ENABLE
select APPTRACE_DEST_UART
depends on !ESP_CONSOLE_USB_CDC && (IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3) && !USB_ENABLED
depends on !ESP_CONSOLE_IS_USB_CDC_ENABLED && SOC_USB_OTG_SUPPORTED && !USB_ENABLED

config APPTRACE_DEST_UART_NONE
bool "None"
Expand Down
55 changes: 43 additions & 12 deletions components/bootloader_support/src/bootloader_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,22 @@
#include "esp_rom_sys.h"
#include "esp_rom_caps.h"

#ifdef CONFIG_ESP_CONSOLE_NONE
void bootloader_console_init(void)
//
// None
//
#if CONFIG_ESP_CONSOLE_IS_NONE_ENABLED
void bootloader_console_init_none(void)
{
esp_rom_install_channel_putc(1, NULL);
esp_rom_install_channel_putc(2, NULL);
}
#endif // CONFIG_ESP_CONSOLE_NONE
#endif // CONFIG_ESP_CONSOLE_IS_NONE_ENABLED

#ifdef CONFIG_ESP_CONSOLE_UART
void bootloader_console_init(void)
//
// UART
//
#if CONFIG_ESP_CONSOLE_IS_UART_ENABLED
void bootloader_console_init_uart(void)
{
const int uart_num = CONFIG_ESP_CONSOLE_UART_NUM;

Expand Down Expand Up @@ -90,13 +96,16 @@ void bootloader_console_init(void)
#endif
esp_rom_uart_set_clock_baudrate(uart_num, clock_hz, CONFIG_ESP_CONSOLE_UART_BAUDRATE);
}
#endif // CONFIG_ESP_CONSOLE_UART
#endif // CONFIG_ESP_CONSOLE_IS_UART_ENABLED

#ifdef CONFIG_ESP_CONSOLE_USB_CDC
//
// Usb CDC
//
#if CONFIG_ESP_CONSOLE_IS_USB_CDC_ENABLED
/* Buffer for CDC data structures. No RX buffer allocated. */
static char s_usb_cdc_buf[ESP_ROM_CDC_ACM_WORK_BUF_MIN];

void bootloader_console_init(void)
void bootloader_console_init_usb_cdc(void)
{
#ifdef CONFIG_IDF_TARGET_ESP32S2
/* ESP32-S2 specific patch to set the correct serial number in the descriptor.
Expand All @@ -109,12 +118,34 @@ void bootloader_console_init(void)
esp_rom_uart_set_as_console(ESP_ROM_UART_USB);
esp_rom_install_channel_putc(1, bootloader_console_write_char_usb);
}
#endif //CONFIG_ESP_CONSOLE_USB_CDC
#endif // CONFIG_ESP_CONSOLE_IS_USB_CDC_ENABLED

#ifdef CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
void bootloader_console_init(void)
//
// Usb Serial/JTAG
//
#if CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED
void bootloader_console_init_usb_serial_jtag(void)
{
UartDevice *uart = GetUartDevice();
uart->buff_uart_no = ESP_ROM_USB_SERIAL_DEVICE_NUM;
}
#endif //CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#endif // CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED

//
// Init All
//
void bootloader_console_init(void)
{
#if CONFIG_ESP_CONSOLE_IS_NONE_ENABLED
bootloader_console_init_none();
#endif
#if CONFIG_ESP_CONSOLE_IS_UART_ENABLED
bootloader_console_init_uart();
#endif
#if CONFIG_ESP_CONSOLE_IS_USB_CDC_ENABLED
bootloader_console_init_usb_cdc();
#endif
#if CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED
bootloader_console_init_usb_serial_jtag();
#endif
}
12 changes: 6 additions & 6 deletions components/bootloader_support/src/bootloader_console_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "esp32s3/rom/usb/usb_persist.h"
#endif

#ifdef CONFIG_ESP_CONSOLE_USB_CDC
#if CONFIG_ESP_CONSOLE_IS_USB_CDC_ENABLED
/* The following functions replace esp_rom_uart_putc, esp_rom_uart_tx_one_char,
* and uart_tx_one_char_uart ROM functions. The main difference is that
* uart_tx_one_char_uart calls cdc_acm_fifo_fill for each byte passed to it,
Expand Down Expand Up @@ -61,16 +61,16 @@ void bootloader_console_write_char_usb(char c)
bootloader_console_write_one_char_usb(c);
}
}
#endif //CONFIG_ESP_CONSOLE_USB_CDC
#endif // CONFIG_ESP_CONSOLE_IS_USB_CDC_ENABLED

void bootloader_console_deinit(void)
{
#ifdef CONFIG_ESP_CONSOLE_UART
#if CONFIG_ESP_CONSOLE_IS_UART_ENABLED
/* Ensure any buffered log output is displayed */
esp_rom_uart_flush_tx(CONFIG_ESP_CONSOLE_UART_NUM);
#endif // CONFIG_ESP_CONSOLE_UART
#endif // CONFIG_ESP_CONSOLE_IS_UART_ENABLED

#ifdef CONFIG_ESP_CONSOLE_USB_CDC
#if CONFIG_ESP_CONSOLE_IS_USB_CDC_ENABLED
bootloader_console_flush_usb();
usb_dc_prepare_persist();
chip_usb_set_persist_flags(USBDC_PERSIST_ENA);
Expand All @@ -79,5 +79,5 @@ void bootloader_console_deinit(void)
usb_dc_check_poll_for_interrupts();
}
esp_rom_install_channel_putc(1, NULL);
#endif
#endif // CONFIG_ESP_CONSOLE_IS_USB_CDC_ENABLED
}
10 changes: 5 additions & 5 deletions components/console/esp_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ typedef struct {
int rx_gpio_num; //!< GPIO number for RX path, -1 means using default one
} esp_console_dev_uart_config_t;

#ifdef CONFIG_ESP_CONSOLE_UART_CUSTOM
#if CONFIG_ESP_CONSOLE_UART_CUSTOM || CONFIG_ESP_CONSOLE_SECONDARY_UART_CUSTOM
#define ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT() \
{ \
.channel = CONFIG_ESP_CONSOLE_UART_NUM, \
Expand Down Expand Up @@ -108,7 +108,7 @@ typedef struct {
{ \
}

#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#if CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED
/**
* @brief Parameters for console device: USB-SERIAL-JTAG
*
Expand All @@ -121,7 +121,7 @@ typedef struct {

#define ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT() {}

#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#endif // CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED

/**
* @brief initialize console module
Expand Down Expand Up @@ -348,7 +348,7 @@ esp_err_t esp_console_new_repl_uart(const esp_console_dev_uart_config_t *dev_con
*/
esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl);

#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#if CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED
/**
* @brief Establish a console REPL (Read-eval-print loop) environment over USB-SERIAL-JTAG
*
Expand All @@ -369,7 +369,7 @@ esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *d
* - ESP_FAIL Parameter error
*/
esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_jtag_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl);
#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#endif // CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED

/**
* @brief Start REPL environment
Expand Down
12 changes: 6 additions & 6 deletions components/console/esp_console_repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ typedef struct {
static void esp_console_repl_task(void *args);
static esp_err_t esp_console_repl_uart_delete(esp_console_repl_t *repl);
static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl);
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#if CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED
static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *repl);
#endif //CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#endif // CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED
static esp_err_t esp_console_common_init(size_t max_cmdline_length, esp_console_repl_com_t *repl_com);
static esp_err_t esp_console_setup_prompt(const char *prompt, esp_console_repl_com_t *repl_com);
static esp_err_t esp_console_setup_history(const char *history_path, uint32_t max_history_len, esp_console_repl_com_t *repl_com);
Expand Down Expand Up @@ -120,7 +120,7 @@ esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *d
return ret;
}

#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#if CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED
esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_jtag_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl)
{
esp_console_repl_universal_t *usb_serial_jtag_repl = NULL;
Expand Down Expand Up @@ -198,7 +198,7 @@ esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_
}
return ret;
}
#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#endif // CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED

esp_err_t esp_console_new_repl_uart(const esp_console_dev_uart_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl)
{
Expand Down Expand Up @@ -442,7 +442,7 @@ static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl)
return ret;
}

#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#if CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED
static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *repl)
{
esp_err_t ret = ESP_OK;
Expand All @@ -462,7 +462,7 @@ static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *rep
_exit:
return ret;
}
#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#endif // CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED

static void esp_console_repl_task(void *args)
{
Expand Down
1 change: 1 addition & 0 deletions components/esp_gdbstub/esp32c3/gdbstub_esp32c3.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void esp_gdbstub_target_init()
{
}

// Note: we only interact with the primary console
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG

int esp_gdbstub_getchar()
Expand Down
1 change: 1 addition & 0 deletions components/esp_gdbstub/esp32c6/gdbstub_esp32c6.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void esp_gdbstub_target_init()
{
}

// Note: we only interact with the primary console
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG

int esp_gdbstub_getchar()
Expand Down
1 change: 1 addition & 0 deletions components/esp_gdbstub/esp32h2/gdbstub_esp32h2.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void esp_gdbstub_target_init()
{
}

// Note: we only interact with the primary console
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG

int esp_gdbstub_getchar()
Expand Down
1 change: 1 addition & 0 deletions components/esp_pm/pm_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ int esp_pm_impl_get_cpu_freq(pm_mode_t mode)

void esp_pm_impl_init(void)
{
// Note: we only interact with the primary console
#if defined(CONFIG_ESP_CONSOLE_UART)
//This clock source should be a source which won't be affected by DFS
uart_sclk_t clk_source = UART_SCLK_DEFAULT;
Expand Down
Loading

0 comments on commit 4565d02

Please sign in to comment.