Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB Mass Storage Class example doesn't flash properly (IDFGH-10215) #11481

Closed
3 tasks done
fulalas opened this issue May 23, 2023 · 13 comments
Closed
3 tasks done

USB Mass Storage Class example doesn't flash properly (IDFGH-10215) #11481

fulalas opened this issue May 23, 2023 · 13 comments
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@fulalas
Copy link

fulalas commented May 23, 2023

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.2-dev-703-gefe919275e

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

Development Kit.

ESP32-S3

Power Supply used.

USB

What is the expected behavior?

I compiled this project and successfully flashed it to /dev/ttyACM0, but then it seems the ESP32-S3 didn't restart properly (blank screen) and the build process got stuck waiting for the device to restart. I tried to unplug ESP32-S3 and plug again, but nothing changed. I can't flash the project anymore because /dev/ttyACM0 doesn't exist anymore (A fatal error occurred: Could not open /dev/ttyACM0, the port doesn't exist).

What is the actual behavior?

The program should run and read the text file from the USB stick that is connected to ESP32-S3.

Steps to reproduce.

Just install the dev enviroment and build this project using idf.py -p /dev/ttyACM0 flash monitor

Debug Logs.

No response

More Information.

I'm using Slackware 15.0.

@fulalas fulalas added the Type: Bug bugs in IDF label May 23, 2023
@espressif-bot espressif-bot added the Status: Opened Issue is new label May 23, 2023
@github-actions github-actions bot changed the title USB Mass Storage Class example doesn't flash properly USB Mass Storage Class example doesn't flash properly (IDFGH-10215) May 23, 2023
@tore-espressif
Copy link
Collaborator

Hello @fulalas , what development board did you use? The symptoms indicate that you flash the program via USB-Serial-JTAG.

USB features and USB-Serial-JTAG are mutually exclusive. Either you use USB for flashing of ESP32-S3, or you use USB-OTG features, such as the MSC driver

@fulalas
Copy link
Author

fulalas commented May 23, 2023

Hi! I have the ESP32-S3-USB-OTG_SUB V2.0 one.

Yeah, there's a USB dev and a USB-UART0 (mini-USB) ports. I'm not sure how to proceed.

@tore-espressif
Copy link
Collaborator

For this particular case, you have to use the USB-UART0 connector for program flashing, and the USB host connector for interfacing your flash drive.

As you can see from the schematic you will need extra steps to configure your board for USB Host mode. We provide helper function in ESP32-S3-USB-OTG Board Support Package.
You must call bsp_usb_mode_select_host() and bsp_usb_host_power_mode(BSP_USB_HOST_POWER_MODE_USB_DEV, true)

I'm sorry for the inconvenience, we are working on more seamless experimenting with USB Host examples

@fulalas
Copy link
Author

fulalas commented May 24, 2023

OK. I adapted the code to include the 2 methods you mentioned. This is the relevant part (hint: // Configure board for host mode):

void app_main(void)
{
    msc_host_device_handle_t msc_device;
    msc_host_vfs_handle_t vfs_handle;
    msc_host_device_info_t info;
    BaseType_t task_created;

    const gpio_config_t input_pin = {
        .pin_bit_mask = BIT64(USB_DISCONNECT_PIN),
        .mode = GPIO_MODE_INPUT,
        .pull_up_en = GPIO_PULLUP_ENABLE,
    };
    ESP_ERROR_CHECK( gpio_config(&input_pin) );

    usb_flags = xEventGroupCreate();
    assert(usb_flags);
    
    // Configure board for host mode
    bsp_usb_mode_select_host();
    bsp_usb_host_power_mode(BSP_USB_HOST_POWER_MODE_USB_DEV, false);

    [...]

It compiles and flashes to the device, however the output is stuck at I (467) example: Waiting for USB stick to be connected. I tried to unplug and plug the USB stick and also resetting the device, but the output doesn't change.

@tore-espressif
Copy link
Collaborator

Could you please set the second argument of this call bspp_usb_host_power_mode(BSP_USB_HOST_POWER_MODE_USB_DEV, false); to true?

@fulalas
Copy link
Author

fulalas commented May 24, 2023

I tried it, but the result is the same. :(

@tore-espressif
Copy link
Collaborator

I tried it, but the result is the same. :(

I'm sorry I forgot one last thing: this call bsp_usb_host_power_mode(BSP_USB_HOST_POWER_MODE_USB_DEV, true); configures the board that the USB host port is powered from USB device port. So in your case you must:

  1. Plug the USB device connector to PC
  2. Connect to USB-UART0 connector with USB cable to PC
  3. Plug USB flash disk to USB host connector

@fulalas
Copy link
Author

fulalas commented May 24, 2023

I see now. It's working, finally! So the USB A connector powers the USB stick while the mini-USB is to flash the application?

@tore-espressif
Copy link
Collaborator

I see now. It's working, finally! So the USB A connector powers the USB stick while the mini-USB is to flash the application?

Correct, I'm happy it works now :) Can we close this issue?

@espressif-bot espressif-bot added Status: Reviewing Issue is being reviewed and removed Status: Opened Issue is new labels May 24, 2023
@fulalas
Copy link
Author

fulalas commented May 24, 2023

Sure. Thanks!

@fulalas fulalas closed this as completed May 24, 2023
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: Reviewing Issue is being reviewed labels May 24, 2023
@porteux
Copy link

porteux commented May 26, 2023

Sorry to bring this up again, but is there any similar example using Rust?

@georgik
Copy link
Collaborator

georgik commented May 26, 2023

@porteux Regarding Rust no_std, you can find some examples with initial USB support here: https://github.com/esp-rs/esp-hal/tree/main/esp32s3-hal/examples
The implementation is still in progress. The current state of support for Rust Bare Metal peripherals is here: esp-rs/esp-hal#19

If you're targeting Rust std with ESP-IDF, then it should be possible to use API from ESP-IDF, but no USB-related examples have been published by the community yet: https://github.com/esp-rs/esp-idf-hal/tree/master/examples

@porteux
Copy link

porteux commented May 30, 2023

@georgik, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

5 participants