Unverified Commit 5a949443 authored by Earle F. Philhower, III's avatar Earle F. Philhower, III Committed by GitHub

Fix USB crashes in FreeRTOS (#1419)

Fixes #1402

The global USB mutex is auto-shadowed with a FreeRTOS semaphore while in
FreeRTOS mode.  Unfortunately, while the core was using the proper
FreeRTOS semaphore to lock access to the USB port, the actual FreeRTOS
USB task was using the naked Pico SDK mutex, leading to cases where it
could acquire the mutex even though some other FreeRTOS task actually
owned the shadowed mutex.

Properly lock the shadowed Semaphore, not mutex_t, in the FreeRTOS
USB periodic task.
parent a9166951
......@@ -33,7 +33,9 @@ CoreMutex::CoreMutex(mutex_t *mutex, uint8_t option) {
if (_option & FromISR) {
__freertos_mutex_take_from_isr(m);
} else {
__freertos_mutex_take(m);
if (!__freertos_mutex_try_take(m)) {
return;
}
}
} else {
uint32_t owner;
......
......@@ -380,9 +380,10 @@ static void __usb(void *param) {
__usbInitted = true;
while (true) {
if (mutex_try_enter(&__usb_mutex, NULL)) {
auto m = __get_freertos_mutex_for_ptr(&__usb_mutex);
if (xSemaphoreTake(m, 0)) {
tud_task();
mutex_exit(&__usb_mutex);
xSemaphoreGive(m);
}
vTaskDelay(1 / portTICK_PERIOD_MS);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment