Skip to content

Commit 2da0f66

Browse files
fix(usb_device): Fix console periheral, enable USJ Console on P4
1 parent 1889851 commit 2da0f66

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

examples/peripherals/usb/device/tusb_msc/main/tusb_msc_main.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
*/
66

77
/* 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.
99
* It either allows the embedded application i.e. example to access the partition or Host PC accesses the partition over USB MSC.
1010
* They can't be allowed to access the partition at the same time.
1111
* For different scenarios and behaviour, Refer to README of this example.
1212
*/
1313

1414
#include <errno.h>
1515
#include <dirent.h>
16+
#include <stdlib.h>
1617
#include "esp_console.h"
1718
#include "esp_check.h"
1819
#include "esp_partition.h"
@@ -24,7 +25,19 @@
2425
#include "diskio_sdmmc.h"
2526
#endif
2627

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+
2739
static const char *TAG = "example_main";
40+
static esp_console_repl_t *repl = NULL;
2841

2942
/* TinyUSB descriptors
3043
********************************************************************* */
@@ -255,8 +268,9 @@ static int console_exit(int argc, char **argv)
255268
{
256269
tinyusb_msc_unregister_callback(TINYUSB_MSC_EVENT_MOUNT_CHANGED);
257270
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);
260274
return 0;
261275
}
262276

@@ -407,18 +421,30 @@ void app_main(void)
407421
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
408422
ESP_LOGI(TAG, "USB MSC initialization DONE");
409423

410-
esp_console_repl_t *repl = NULL;
411424
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
412425
/* Prompt to be printed before each line.
413426
* This can be customized, made dynamic, etc.
414427
*/
415428
repl_config.prompt = PROMPT_STR ">";
416429
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)
418433
esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
419434
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+
420445
for (int count = 0; count < sizeof(cmds) / sizeof(esp_console_cmd_t); count++) {
421446
ESP_ERROR_CHECK(esp_console_cmd_register(&cmds[count]));
422447
}
448+
423449
ESP_ERROR_CHECK(esp_console_start_repl(repl));
424450
}

examples/peripherals/usb/device/tusb_msc/sdkconfig.defaults

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ CONFIG_WL_SECTOR_SIZE_512=y
1111
CONFIG_WL_SECTOR_MODE_PERF=y
1212

1313
CONFIG_FATFS_LFN_HEAP=y
14+
15+
# On chips with USB Serial JTAG, disable secondary console which does not make sense when using console component
16+
CONFIG_ESP_CONSOLE_SECONDARY_NONE=y

0 commit comments

Comments
 (0)