|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | /* DESCRIPTION: |
8 | | - * This example contains code to make ESP32-S3 based device recognizable by USB-hosts as a USB Mass Storage Device. |
| 8 | + * This example contains code to make ESP32 based device recognizable by USB-hosts as a USB Mass Storage Device. |
9 | 9 | * It either allows the embedded application i.e. example to access the partition or Host PC accesses the partition over USB MSC. |
10 | 10 | * They can't be allowed to access the partition at the same time. |
11 | 11 | * For different scenarios and behaviour, Refer to README of this example. |
12 | 12 | */ |
13 | 13 |
|
14 | 14 | #include <errno.h> |
15 | 15 | #include <dirent.h> |
| 16 | +#include <stdlib.h> |
16 | 17 | #include "esp_console.h" |
17 | 18 | #include "esp_check.h" |
18 | 19 | #include "esp_partition.h" |
|
24 | 25 | #include "diskio_sdmmc.h" |
25 | 26 | #endif |
26 | 27 |
|
| 28 | +/* |
| 29 | + * We warn if a secondary serial console is enabled. A secondary serial console is always output-only and |
| 30 | + * hence not very useful for interactive console applications. If you encounter this warning, consider disabling |
| 31 | + * the secondary serial console in menuconfig unless you know what you are doing. |
| 32 | + */ |
| 33 | +#if SOC_USB_SERIAL_JTAG_SUPPORTED |
| 34 | +#if !CONFIG_ESP_CONSOLE_SECONDARY_NONE |
| 35 | +#warning "A secondary serial console is not useful when using the console component. Please disable it in menuconfig." |
| 36 | +#endif |
| 37 | +#endif |
| 38 | + |
27 | 39 | static const char *TAG = "example_main"; |
| 40 | +static esp_console_repl_t *repl = NULL; |
28 | 41 |
|
29 | 42 | /* TinyUSB descriptors |
30 | 43 | ********************************************************************* */ |
@@ -255,8 +268,9 @@ static int console_exit(int argc, char **argv) |
255 | 268 | { |
256 | 269 | tinyusb_msc_unregister_callback(TINYUSB_MSC_EVENT_MOUNT_CHANGED); |
257 | 270 | tinyusb_msc_storage_deinit(); |
258 | | - printf("Application Exiting\n"); |
259 | | - exit(0); |
| 271 | + tinyusb_driver_uninstall(); |
| 272 | + printf("Application Exit\n"); |
| 273 | + repl->del(repl); |
260 | 274 | return 0; |
261 | 275 | } |
262 | 276 |
|
@@ -407,18 +421,30 @@ void app_main(void) |
407 | 421 | ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg)); |
408 | 422 | ESP_LOGI(TAG, "USB MSC initialization DONE"); |
409 | 423 |
|
410 | | - esp_console_repl_t *repl = NULL; |
411 | 424 | esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); |
412 | 425 | /* Prompt to be printed before each line. |
413 | 426 | * This can be customized, made dynamic, etc. |
414 | 427 | */ |
415 | 428 | repl_config.prompt = PROMPT_STR ">"; |
416 | 429 | repl_config.max_cmdline_length = 64; |
417 | | - esp_console_register_help_command(); |
| 430 | + |
| 431 | + // Init console based on menuconfig settings |
| 432 | +#if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) || defined(CONFIG_ESP_CONSOLE_UART_CUSTOM) |
418 | 433 | esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); |
419 | 434 | ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl)); |
| 435 | + |
| 436 | + // USJ console can be set only on esp32p4, having separate USB PHYs for USB_OTG and USJ |
| 437 | +#elif defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) && defined(CONFIG_IDF_TARGET_ESP32P4) |
| 438 | + esp_console_dev_usb_serial_jtag_config_t hw_config = ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT(); |
| 439 | + ESP_ERROR_CHECK(esp_console_new_repl_usb_serial_jtag(&hw_config, &repl_config, &repl)); |
| 440 | + |
| 441 | +#else |
| 442 | +#error Unsupported console type |
| 443 | +#endif |
| 444 | + |
420 | 445 | for (int count = 0; count < sizeof(cmds) / sizeof(esp_console_cmd_t); count++) { |
421 | 446 | ESP_ERROR_CHECK(esp_console_cmd_register(&cmds[count])); |
422 | 447 | } |
| 448 | + |
423 | 449 | ESP_ERROR_CHECK(esp_console_start_repl(repl)); |
424 | 450 | } |
0 commit comments