Skip to content

Commit 0ac445c

Browse files
committed
feat(usb): add CherryUSB host msc example
1 parent 4366f11 commit 0ac445c

File tree

8 files changed

+433
-9
lines changed

8 files changed

+433
-9
lines changed

examples/peripherals/usb/device/cherryusb_serial_device/main/device_cdc_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,13 @@ void cdc_acm_task(void *arg)
422422

423423
void app_main(void)
424424
{
425-
#if EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
425+
#if CONFIG_EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
426426
reinit :
427427
#endif
428428

429429
xTaskCreatePinnedToCore(&cdc_acm_task, "cdc_acm_task", 1024 * 3, NULL, 10, &s_task_handle, 0);
430430

431-
#if EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
431+
#if CONFIG_EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
432432
for (int i = 10; i >= 0; i--) {
433433
ESP_LOGW(TAG, "Deinit usb after %d seconds...", i);
434434
vTaskDelay(1000 / portTICK_PERIOD_MS);

examples/peripherals/usb/host/cherryusb_host/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
(See the README.md file in the upper level 'examples' directory for more information about examples.)
77

8-
This example demonstrates how to use the CherryUSB host driver. Currently, this example supports communication with HID devices (such as Keyboard and Mouse) and serial port devices (such as CDC_ACM, CH34x, CP210x, PL2303, FTDI FT23x/FT423x devices).
8+
This example demonstrates how to use the CherryUSB host driver. Currently, this example supports communication with HID devices (such as Keyboard and Mouse), serial port devices (such as CDC_ACM, CH34x, CP210x, PL2303, FTDI FT23x/FT423x devices) and MSC (Mass Storage Class).
99

1010
## How to use example
1111

examples/peripherals/usb/host/cherryusb_host/main/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ if(CONFIG_CHERRYUSB_HOST_CDC_ACM OR CONFIG_CHERRYUSB_HOST_FTDI OR CONFIG_CHERRYU
99
list(APPEND srcs "cdc_acm.c")
1010
endif()
1111

12+
if(CONFIG_CHERRYUSB_HOST_MSC)
13+
list(APPEND srcs "msc.c")
14+
endif()
15+
1216
idf_component_register(SRCS ${srcs}
1317
INCLUDE_DIRS "."
18+
PRIV_REQUIRES esp_timer fatfs
1419
)
1520

1621
if(CONFIG_CHERRYUSB_HOST_HID)
@@ -42,3 +47,8 @@ if(CONFIG_CHERRYUSB_HOST_PL2303)
4247
# Make sure the definitions in hid.c are linked correctly
4348
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usbh_pl2303_run_real")
4449
endif()
50+
51+
if(CONFIG_CHERRYUSB_HOST_MSC)
52+
# Make sure the definitions in hid.c are linked correctly
53+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usbh_msc_run_real")
54+
endif()

examples/peripherals/usb/host/cherryusb_host/main/Kconfig.projbuild

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ menu "Example Configuration"
55
depends on IDF_TARGET_ESP32S3
66
default y
77

8+
config EXAMPLE_FORMAT_IF_MOUNT_FAILED
9+
bool "Format the card if mount failed"
10+
depends on CHERRYUSB_HOST_MSC
11+
default n
12+
help
13+
If this config item is set, format_if_mount_failed will be set to true and the card will be formatted if
14+
the mount has failed.
15+
816
config EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
917
bool "Perform init deinit of cherryusb stack in a loop"
1018
default n

examples/peripherals/usb/host/cherryusb_host/main/cdc_acm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "sdkconfig.h"
88
#include "freertos/FreeRTOS.h"
99
#include "freertos/task.h"
10-
#include "esp_timer.h"
1110
#include "esp_heap_caps.h"
1211
#include "esp_log.h"
1312

@@ -111,10 +110,12 @@ static void serial_in_cb(void *arg, int nbytes)
111110
esp_rom_printf("%c", data[i]);
112111
} else {
113112
esp_rom_printf("[%02x]", data[i]);
113+
if (data[i] == '\n') {
114+
esp_rom_printf("\n");
115+
}
114116
}
115117
}
116118

117-
esp_rom_printf("\r");
118119
serial_start_in(serial);
119120
}
120121

examples/peripherals/usb/host/cherryusb_host/main/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "freertos/task.h"
1111
#include "esp_log.h"
1212

13-
#if EXAMPLE_HAL_USE_ESP32_S3_USB_OTG
13+
#if CONFIG_EXAMPLE_HAL_USE_ESP32_S3_USB_OTG
1414
#include "driver/gpio.h"
1515
#define BOOST_EN 13
1616
#define DEV_VBUS_EN 12
@@ -25,7 +25,7 @@ static char *TAG = "HOST";
2525

2626
void app_main(void)
2727
{
28-
#if EXAMPLE_HAL_USE_ESP32_S3_USB_OTG
28+
#if CONFIG_EXAMPLE_HAL_USE_ESP32_S3_USB_OTG
2929
gpio_config_t io_conf = {
3030
.intr_type = GPIO_INTR_DISABLE,
3131
.mode = GPIO_MODE_OUTPUT,
@@ -40,13 +40,13 @@ void app_main(void)
4040
gpio_set_level(USB_SEL, 1);
4141
#endif
4242

43-
#if EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
43+
#if CONFIG_EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
4444
reinit:
4545
#endif
4646
usbh_initialize(0, ESP_USBH_BASE);
4747
ESP_LOGI(TAG, "Init usb");
4848

49-
#if EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
49+
#if CONFIG_EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
5050
for (int i = 10; i >= 0; i--) {
5151
ESP_LOGW(TAG, "Deinit usb after %d seconds...", i);
5252
vTaskDelay(1000 / portTICK_PERIOD_MS);

0 commit comments

Comments
 (0)