From c900c951a339758d8ec34368b226a900e3f22ac0 Mon Sep 17 00:00:00 2001 From: Diego Ismirlian Date: Tue, 4 Jul 2017 19:09:39 -0300 Subject: USBH: MSD: Rework to prevent race conditions on unload --- testhal/STM32/STM32F4xx/USB_HOST/main.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'testhal/STM32/STM32F4xx/USB_HOST') diff --git a/testhal/STM32/STM32F4xx/USB_HOST/main.c b/testhal/STM32/STM32F4xx/USB_HOST/main.c index ece9fd5..7cf14e1 100644 --- a/testhal/STM32/STM32F4xx/USB_HOST/main.c +++ b/testhal/STM32/STM32F4xx/USB_HOST/main.c @@ -19,7 +19,7 @@ #include "ff.h" #include -#define UVC_TO_MSD_PHOTOS_CAPTURE TRUE +#define UVC_TO_MSD_PHOTOS_CAPTURE FALSE #if HAL_USBH_USE_FTDI || HAL_USBH_USE_AOA @@ -340,7 +340,7 @@ static void ThreadTestMSD(void *p) { FATFS *fsp; DWORD clusters; FRESULT res; - blkstate_t state; + #if !UVC_TO_MSD_PHOTOS_CAPTURE BaseSequentialStream * const chp = (BaseSequentialStream *)&USBH_DEBUG_SD; systime_t st, et; @@ -351,11 +351,15 @@ start: for(;;) { chThdSleepMilliseconds(100); - chSysLock(); - state = blkGetDriverState(&MSBLKD[0]); - chSysUnlock(); - if (state != BLK_READY) + if (blkGetDriverState(&MSBLKD[0]) == BLK_ACTIVE) { + usbDbgPuts("BLK: Active, connect...."); + usbhmsdLUNConnect(&MSBLKD[0]); + } + if (blkGetDriverState(&MSBLKD[0]) != BLK_READY) { continue; + } + + usbDbgPuts("BLK: Ready."); #if !UVC_TO_MSD_PHOTOS_CAPTURE //raw read test -- cgit v1.2.3