From 6f46cd332ea7966052c52f2f1d16d3b84c0f8731 Mon Sep 17 00:00:00 2001 From: Tomas Rezucha Date: Fri, 8 Mar 2024 12:09:48 +0100 Subject: [PATCH] fix(usb/host): Fixed crash on MSC disk disconnection --- examples/peripherals/usb/host/msc/main/msc_example_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/peripherals/usb/host/msc/main/msc_example_main.c b/examples/peripherals/usb/host/msc/main/msc_example_main.c index c6be757d9c18..773a049281fe 100644 --- a/examples/peripherals/usb/host/msc/main/msc_example_main.c +++ b/examples/peripherals/usb/host/msc/main/msc_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -217,17 +217,19 @@ static void usb_task(void *args) }; ESP_ERROR_CHECK(msc_host_install(&msc_config)); + bool has_clients = true; while (true) { uint32_t event_flags; usb_host_lib_handle_events(portMAX_DELAY, &event_flags); // Release devices once all clients has deregistered if (event_flags & USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS) { + has_clients = false; if (usb_host_device_free_all() == ESP_OK) { break; }; } - if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE) { + if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE && !has_clients) { break; } }