examples: support USB_CDC and USB_SERIAL_JTAG in basic console example

Related to https://github.com/espressif/esp-idf/issues/8738
Related to https://github.com/espressif/esp-idf/issues/8879

Doesn’t implement USB_CDC (over USB_OTG peripheral) for ESP32-S3 yet;
this only works on ESP32-S2 for now. On ESP32-S3 it is now possible to
use USB_SERIAL_JTAG console.
This commit is contained in:
Ivan Grokhotkov
2022-05-03 19:47:38 +02:00
parent 11c67d175f
commit 3390d2a2d1
2 changed files with 52 additions and 47 deletions

View File

@@ -1,4 +1,4 @@
/* Console example
/* Basic console example (esp_console_repl API)
This example code is in the Public Domain (or CC0 licensed, at your option.)
@@ -16,10 +16,6 @@
#include "esp_vfs_fat.h"
#include "nvs.h"
#include "nvs_flash.h"
#ifdef CONFIG_ESP_CONSOLE_USB_CDC
#error This example is incompatible with USB CDC console. Please try "console_usb" example instead.
#endif // CONFIG_ESP_CONSOLE_USB_CDC
#include "cmd_system.h"
#include "cmd_wifi.h"
#include "cmd_nvs.h"
@@ -65,7 +61,6 @@ void app_main(void)
{
esp_console_repl_t *repl = NULL;
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
/* Prompt to be printed before each line.
* This can be customized, made dynamic, etc.
*/
@@ -88,7 +83,21 @@ void app_main(void)
register_wifi();
register_nvs();
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
#if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) || defined(CONFIG_ESP_CONSOLE_UART_CUSTOM)
esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl));
#elif defined(CONFIG_ESP_CONSOLE_USB_CDC)
esp_console_dev_usb_cdc_config_t hw_config = ESP_CONSOLE_DEV_CDC_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_console_new_repl_usb_cdc(&hw_config, &repl_config, &repl));
#elif defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG)
esp_console_dev_usb_serial_jtag_config_t hw_config = ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_console_new_repl_usb_serial_jtag(&hw_config, &repl_config, &repl));
#else
#error Unsupported console type
#endif
ESP_ERROR_CHECK(esp_console_start_repl(repl));
}