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 2, 2022
1 parent 84be4db commit 9f6b5a3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 14 deletions.
4 changes: 2 additions & 2 deletions components/console/esp_console.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ typedef struct {
{ \
}

#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
/**
* @brief Parameters for console device: USB-SERIAL-JTAG
*
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_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
/**
* @brief Establish a console REPL (Read-eval-print loop) environment over USB-SERIAL-JTAG
*
Expand Down
6 changes: 3 additions & 3 deletions components/console/esp_console_repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ 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_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *repl);
#endif //CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
static esp_err_t esp_console_common_init(size_t max_cmdline_length, 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_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
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 @@ -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_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *repl)
{
esp_err_t ret = ESP_OK;
Expand Down
18 changes: 17 additions & 1 deletion components/esp_system/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,23 @@ menu "ESP System Settings"
- On chips with an USB serial/JTAG debug controller, selecting the option
for that redirects output to the CDC/ACM (serial port emulation) component
of that device.

config ESP_CONSOLE_UART_DEFAULT
bool "Default: UART0"

config ESP_CONSOLE_USB_CDC
bool "USB CDC"
# && !TINY_USB is because the ROM CDC driver is currently incompatible with TinyUSB.
depends on (IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3) && !TINY_USB

config ESP_CONSOLE_USB_SERIAL_JTAG
bool "USB Serial/JTAG Controller"
select ESPTOOLPY_NO_STUB if IDF_TARGET_ESP32C3 #ESPTOOL-252
depends on IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3

config ESP_CONSOLE_UART_CUSTOM
bool "Custom UART"

config ESP_CONSOLE_NONE
bool "None"
endchoice
Expand All @@ -246,16 +251,27 @@ menu "ESP System Settings"
non-blocking mode without using REPL. If you want to output in blocking mode with REPL or
input through this secondary port, please change the primary config to this port
in `Channel for console output` menu.

config ESP_CONSOLE_SECONDARY_NONE
bool "No secondary console"

config ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
bool "USB_SERIAL_JTAG PORT"
bool "USB Serial/JTAG Controller"
depends on !ESP_CONSOLE_USB_SERIAL_JTAG
help
This option supports output through USB_SERIAL_JTAG port when the UART0 port is not connected.
The output currently only supports non-blocking mode without using the console.
If you want to output in blocking mode with REPL or input through USB_SERIAL_JTAG port,
please change the primary config to ESP_CONSOLE_USB_SERIAL_JTAG above.

config ESP_CONSOLE_SECONDARY_UART_DEFAULT
bool "UART0 Default"
# Depends on UART0 not being in use by the primary console
depends on ! ESP_CONSOLE_UART_DEFAULT && ! ESP_CONSOLE_UART_CUSTOM_NUM_0

config ESP_CONSOLE_SECONDARY_USB_CDC
bool "USB CDC"
depends on ! ESP_CONSOLE_USB_CDC
endchoice


Expand Down
25 changes: 19 additions & 6 deletions components/esp_system/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,25 @@ static void panic_print_char_uart(const char c)
}
#endif // CONFIG_ESP_CONSOLE_UART

#if CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT
static uart_hal_context_t s_panic_uart_secondary_default = { .dev = &UART0 };

#if CONFIG_ESP_CONSOLE_USB_CDC
static void panic_print_char_usb_cdc(const char c)
static void panic_print_char_uart_secondary_default(const char c)
{
uint32_t sz = 0;
while (!uart_hal_get_txfifo_len(&s_panic_uart_secondary_default));
uart_hal_write_txfifo(&s_panic_uart_secondary_default, (uint8_t *) &c, 1, &sz);
}
#endif // CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT


#if CONFIG_ESP_CONSOLE_USB_CDC || CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC
void panic_print_char_usb_cdc(const char c)
{
esp_usb_console_write_buf(&c, 1);
/* result ignored */
}
#endif // CONFIG_ESP_CONSOLE_USB_CDC
#endif // CONFIG_ESP_CONSOLE_USB_CDC || CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC

#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
//Timeout; if there's no host listening, the txfifo won't ever
Expand All @@ -110,13 +121,15 @@ static void panic_print_char_usb_serial_jtag(const char c)
}
#endif //CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG


void panic_print_char(const char c)
{
#if CONFIG_ESP_CONSOLE_UART
panic_print_char_uart(c);
#endif
#if CONFIG_ESP_CONSOLE_USB_CDC
#if CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT
panic_print_char_uart_secondary_default(c);
#endif
#if CONFIG_ESP_CONSOLE_USB_CDC || CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC
panic_print_char_usb_cdc(c);
#endif
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
Expand Down Expand Up @@ -177,7 +190,7 @@ void esp_panic_handler_reconfigure_wdts(void)
{
wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0};
#if SOC_TIMER_GROUPS >= 2
// IDF-3825
// IDF-3825
wdt_hal_context_t wdt1_context = {.inst = WDT_MWDT1, .mwdt_dev = &TIMERG1};
#endif

Expand Down
24 changes: 22 additions & 2 deletions components/vfs/vfs_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const static char *primary_path = "/dev/cdcacm";
#endif

// Secondary register part.
#if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
#if (CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG || \
CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT || \
CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC)
const static char *secondary_path = "/dev/secondary";
static int secondary_vfs_index;
#endif // Secondary part
Expand All @@ -63,6 +65,10 @@ int console_open(const char * path, int flags, int mode)
// Secondary port open
#if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
vfs_console.fd_secondary = get_vfs_for_path(secondary_path)->vfs.open("/", flags, mode);
#elif CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT
vfs_console.fd_secondary = get_vfs_for_path(secondary_path)->vfs.open("/0", flags, mode);
#elif CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC
vfs_console.fd_secondary = get_vfs_for_path(secondary_path)->vfs.open("/", flags, mode);
#endif
return 0;
}
Expand All @@ -71,7 +77,9 @@ ssize_t console_write(int fd, const void *data, size_t size)
{
// All function calls are to primary, except from write and close, which will be forwarded to both primary and secondary.
get_vfs_for_index(primary_vfs_index)->vfs.write(vfs_console.fd_primary, data, size);
#if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
#if (CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG || \
CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT || \
CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC)
get_vfs_for_index(secondary_vfs_index)->vfs.write(vfs_console.fd_secondary, data, size);
#endif
return size;
Expand Down Expand Up @@ -210,6 +218,18 @@ esp_err_t esp_vfs_console_register(void)
if(err != ESP_OK) {
return err;
}
#elif CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT
const esp_vfs_t *uart_vfs = esp_vfs_uart_get_vfs();
err = esp_vfs_register_common(secondary_path, strlen(secondary_path), uart_vfs, NULL, &secondary_vfs_index);
if(err != ESP_OK) {
return err;
}
#elif CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC
const esp_vfs_t *cdcacm_vfs = esp_vfs_cdcacm_get_vfs();
err = esp_vfs_register_common(secondary_path, strlen(secondary_path), cdcacm_vfs, NULL, &secondary_vfs_index);
if(err != ESP_OK) {
return err;
}
#endif
err = esp_vfs_dev_console_register();
return err;
Expand Down

0 comments on commit 9f6b5a3

Please sign in to comment.