Open rev1204 opened 2 years ago
https://github.com/espressif/esp-idf/issues/7505
But this may not be fixed in arduino-esp32 yet, also i didnt add code to to handle remove yet.
I have encountered the same problem. Using arduino-esp32#master can solve the problem of "crash when removing device".
However, there is a new problem. Re inserting the USB is not recognized
Thanks for reporting. Like i said, re-inserting is not pushed to repository yet. Here are files if anyone would like to test.
Thanks for reply, using arduino-esp32#master solve the crash problem. I tried re-inserting flash drive using usb_host @chegewara provided. But it doesn't work. The event_flags inside client_async_seq_task is always 0.
static void client_async_seq_task(void *param)
{
USBhost* host = (USBhost *)param;
printf("create async task\n");
while (1)
{
usb_host_client_handle_t client_hdl = host->client_hdl;
uint32_t event_flags;
if(client_hdl)usb_host_client_handle_events(client_hdl, 1);
if (ESP_OK == usb_host_lib_handle_events(0, &event_flags))
{
printf("usb evt flags: %d\n", event_flags); // <- it always 0
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS)
{
printf("No more clients\n");
do{
if(usb_host_device_free_all() != ESP_ERR_NOT_FINISHED) break;
}while(1);
usb_host_uninstall();
host->init(false);
}
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE)
{
printf("USB_HOST_LIB_EVENT_FLAGS_ALL_FREE\n");
usb_host_client_deregister(client_hdl);
host->client_hdl = NULL;
}
} else {
vTaskDelay(1);
}
}
printf("delete task\n");
vTaskDelete(NULL);
}
Hi, i am having few copies of this library, so maybe the one i provided is not complete. Here is esp-idf code that is working: https://github.com/espressif/esp-idf/issues/7920#issuecomment-971588802
I will try to update code soon.
Hello, thank you for your quick reply.
It should be noted that "usb_host_interface_release" is missing from "usb_acm. cpp". After I add it, I can run the "acm. Ino" example normally
Oh yes, it should be something like this:
// this is in class
bool USBacmDevice::deinit()
{
for (size_t n = 0; n < config_desc->bNumInterfaces; n++)
{
usb_host_interface_release(_host->clientHandle(), _host->deviceHandle(), n);
}
return true;
}
// this is in main.c
void client_event_callback(const usb_host_client_event_msg_t *event_msg, void *arg)
{
if (event_msg->event == USB_HOST_CLIENT_EVENT_NEW_DEV)
{
...
}
else
{
// TODO: release all interfaces claimed in device.init
device.deinit();
}
}
I didnt know which example you are testing, and i forgot to add that code.
Yes, I added almost the same code
I'm trying the example from examples/host/msc/msc.ino. Read & write function is working normally, but it crashed when removing the flash drive. The ESP print this error:
I'm using AI-Thinker dev module ESP-12K with 8MB PSRAM. Any idea why this happen? Do I need to do something before removing the device? Or maybe I need extra component? I'm connecting female USB port directly to pin 19, 20, VCC and GND.