Skip to content

Commit

Permalink
feat(console): more secondary output choices
Browse files Browse the repository at this point in the history
  • Loading branch information
chipweinberger committed Sep 30, 2023
1 parent 272b409 commit 1c66960
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 78 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 @@ -23,16 +23,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 @@ -79,13 +85,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 @@ -98,11 +107,33 @@ void bootloader_console_init(void)
esp_rom_uart_set_as_console(ESP_ROM_USB_OTG_NUM);
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)
{
esp_rom_uart_switch_buffer(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 @@ -80,7 +80,7 @@ typedef struct {
int rx_gpio_num; //!< GPIO number for RX path, -1 means using default one
} esp_console_dev_uart_config_t;

#if 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 @@ -113,7 +113,7 @@ typedef struct {
#define ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT() {}
#endif // CONFIG_ESP_CONSOLE_USB_CDC || (defined __DOXYGEN__ && SOC_USB_OTG_SUPPORTED)

#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED)
#if CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED)_ENABLED
/**
* @brief Parameters for console device: USB-SERIAL-JTAG
*
Expand All @@ -125,7 +125,7 @@ typedef struct {
} esp_console_dev_usb_serial_jtag_config_t;

#define ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT() {}
#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED)
#endif // CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED)

/**
* @brief initialize console module
Expand Down Expand Up @@ -358,7 +358,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);
#endif // CONFIG_ESP_CONSOLE_USB_CDC || (defined __DOXYGEN__ && SOC_USB_OTG_SUPPORTED)

#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED)
#if CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED)
/**
* @brief Establish a console REPL (Read-eval-print loop) environment over USB-SERIAL-JTAG
*
Expand All @@ -379,7 +379,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 || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED)
#endif // CONFIG_ESP_CONSOLE_IS_USB_SERIAL_JTAG_ENABLED || (defined __DOXYGEN__ && SOC_USB_SERIAL_JTAG_SUPPORTED)

/**
* @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 @@ -53,9 +53,9 @@ static esp_err_t esp_console_repl_uart_delete(esp_console_repl_t *repl);
#if CONFIG_ESP_CONSOLE_USB_CDC
static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl);
#endif // CONFIG_ESP_CONSOLE_USB_CDC
#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 @@ -126,7 +126,7 @@ esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *d
}
#endif // CONFIG_ESP_CONSOLE_USB_CDC

#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 @@ -201,7 +201,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

#if CONFIG_ESP_CONSOLE_UART_DEFAULT || CONFIG_ESP_CONSOLE_UART_CUSTOM
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 @@ -451,7 +451,7 @@ static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl)
}
#endif // CONFIG_ESP_CONSOLE_USB_CDC

#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 @@ -471,7 +471,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/src/gdbstub_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "hal/uart_ll.h"
#endif

// note: we only interact with usb serial jtag if it is enabled as the primary console
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG

int esp_gdbstub_getchar(void)
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 @@ -726,6 +726,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 1c66960

Please sign in to comment.