11/*
2- * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
@@ -297,6 +297,7 @@ Test USB Host Asynchronous API single client
297297*/
298298static void host_lib_task (void * arg )
299299{
300+ TaskHandle_t pending_task = (TaskHandle_t )arg ;
300301 while (1 ) {
301302 // Start handling system events
302303 uint32_t event_flags ;
@@ -306,10 +307,12 @@ static void host_lib_task(void *arg)
306307 TEST_ASSERT_EQUAL (ESP_ERR_NOT_FINISHED , usb_host_device_free_all ());
307308 }
308309 if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE ) {
310+ printf ("All devices freed\n" );
309311 break ;
310312 }
311313 }
312-
314+ // Notify the main task that the host library task is done
315+ xTaskNotifyGive (pending_task );
313316 printf ("Deleting host_lib_task\n" );
314317 vTaskDelete (NULL );
315318}
@@ -330,13 +333,16 @@ TEST_CASE("Test USB Host multiconfig client (single client)", "[usb_host][full_s
330333 xTaskNotifyGive (client_task );
331334
332335 TaskHandle_t host_lib_task_hdl ;
333- xTaskCreatePinnedToCore (host_lib_task , "host lib" , 4096 , NULL , 2 , & host_lib_task_hdl , 0 );
336+ // Get Current task handle
337+ TaskHandle_t pending_task = xTaskGetCurrentTaskHandle ();
338+ xTaskCreatePinnedToCore (host_lib_task , "host lib" , 4096 , (void * )pending_task , 2 , & host_lib_task_hdl , 0 );
334339 TEST_ASSERT_NOT_NULL_MESSAGE (host_lib_task_hdl , "Failed to create host lib task" );
335340
336341 // Wait for the device to be open
337342 xSemaphoreTake (dev_open_smp , portMAX_DELAY );
338343 multiconf_client_get_conf_desc ();
339-
344+ // Wait for the host library task to finish
345+ ulTaskNotifyTake (pdTRUE , portMAX_DELAY );
340346 // Cleanup
341347 vSemaphoreDelete (dev_open_smp );
342348}
0 commit comments