-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Operating System
Windows 11
Commit SHA
esp-idf v5.5.0
Board
esp32p4
Firmware
bool msc_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const *cb_data)
{
if (cb_data->csw != NULL)
{
if (cb_data->csw->status == 0)
{
if (xSemaphoreGive(msc_completion_sem) != pdTRUE)
{
ESP_LOGE("MSC", "Failed to give msc_completion_sem");
}
}
else
{
ESP_LOGE("MSC", "Command failed with status: %d", cb_data->csw->status);
xSemaphoreGive(msc_completion_sem);
}
}
return true;
}
static DRESULT usb_disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
{
uint8_t dev_addr = pdrv;
if (!tuh_msc_read10(dev_addr, 0, buff, sector, (uint16_t)count, msc_complete_cb, 0))
{
ESP_LOGE("USB_DISK", "Failed to start read operation");
return RES_ERROR;
}
xSemaphoreTake(msc_completion_sem, portMAX_DELAY);
return RES_OK;
}
static DRESULT usb_disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
{
uint8_t dev_addr = pdrv;
if (!tuh_msc_write10(dev_addr, 0, buff, sector, (uint16_t)count, msc_complete_cb, 0))
{
ESP_LOGE("USB_DISK", "Failed to start write operation");
return RES_ERROR;
}
xSemaphoreTake(msc_completion_sem, portMAX_DELAY);
return RES_OK;
}What happened ?
When using TinyUSB USB Host with both MSC and HID devices mounted simultaneously, the MSC transfer completion callbacks stop being triggered randomly during file operations through the FatFS layer.
This causes the application to hang indefinitely when waiting for the callback to signal a semaphore. The issue occurs even when the HID device has NO ACTIVE EVENTS - simply having an HID device mounted is enough to trigger the problem.
So the problem is not triggered by the semaphore, it occurs sometime because the tuh_msc_write10 callback is not triggered (probably due to an issue in msch_xfer_cb ??).
Note that when I don't have an HID mounted, everything works fine as expected. I can provide you my HID code but I don't think it's really useful.
How to reproduce ?
With an USB Hub (ESP32-P4-Function-EV-Board).
Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)
Log look great:
[...]
on EP 02 with 4096 bytes: OK
MSC xfer callback
Queue EP 81 with 13 bytes ...
OK
on EP 81 with 13 bytes: OK
MSC xfer callback
[2] Claimed EP 0x02
Queue EP 02 with 31 bytes ...
OK
on EP 02 with 31 bytes: OK
MSC xfer callback
Queue EP 02 with 4096 bytes ...
OK
on EP 02 with 4096 bytes: OK
MSC xfer callback
Queue EP 81 with 13 bytes ...
OK
on EP 81 with 13 bytes: OK
MSC xfer callback
[2] Claimed EP 0x02
Queue EP 02 with 31 bytes ...
OK
on EP 02 with 31 bytes: OK
MSC xfer callback
Queue EP 02 with 4096 bytes ...
OK
on EP 02 with 4096 bytes: OK
MSC xfer callback
Queue EP 81 with 13 bytes ...
OK
on EP 81 with 13 bytes: OK
MSC xfer callback
[2] Claimed EP 0x02
Queue EP 02 with 31 bytes ...
OK
on EP 02 with 31 bytes: OK
MSC xfer callback
Queue EP 02 with 4096 bytes ...
OK
on EP 02 with 4096 bytes: OK
MSC xfer callback
Queue EP 81 with 13 bytes ...
OK
on EP 81 with 13 bytes: OK
MSC xfer callback
[2] Claimed EP 0x02
Queue EP 02 with 31 bytes ...
OK
on EP 02 with 31 bytes: OK
MSC xfer callback
Queue EP 02 with 4096 bytes ...
OK
on EP 02 with 4096 bytes: OK
MSC xfer callback
Queue EP 81 with 13 bytes ...
OK
on EP 81 with 13 bytes: OK
MSC xfer callback
[2] Claimed EP 0x02
Queue EP 02 with 31 bytes ...
OK
on EP 02 with 31 bytes: OK
MSC xfer callback
Queue EP 02 with 4096 bytes ...
OK
// blocked
Screenshots
No response
I have checked existing issues, discussion and documentation
- I confirm I have checked existing issues, discussion and documentation.