usbd: hold RX_PENDING in every build, not only with OSAL_MUTEX_REQUIRED One state bit and one code path regardless of OS/core config, so a class driver that claims an OUT endpoint from xfer_cb without consuming misbehaves the same way on bare-metal as under an RTOS, and test_usbd covers it without forcing TUP_MCU_MULTIPLE_CORE.
diff --git a/src/common/tusb_private.h b/src/common/tusb_private.h index e333651..f45273f 100644 --- a/src/common/tusb_private.h +++ b/src/common/tusb_private.h
@@ -145,7 +145,7 @@ // Start an usb transfer if endpoint is not busy uint32_t tu_edpt_stream_read_xfer(tu_edpt_stream_t *s); -#if CFG_TUD_ENABLED && OSAL_MUTEX_REQUIRED +#if CFG_TUD_ENABLED // Release an OUT endpoint's RX_PENDING hold once its buffer is consumed, allowing it to be claimed void usbd_edpt_rx_consume(uint8_t rhport, uint8_t ep_addr); #else
diff --git a/src/device/usbd.c b/src/device/usbd.c index 29ad0ee..6878208 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c
@@ -403,10 +403,8 @@ #if OSAL_MUTEX_REQUIRED static osal_mutex_def_t _ubsd_mutexdef; static osal_mutex_t _usbd_mutex; - #define USBD_RX_PENDING TU_EDPT_STATE_RX_PENDING #else #define _usbd_mutex NULL - #define USBD_RX_PENDING 0u // no other task can claim an OUT endpoint while its xfer_cb runs #endif TU_ATTR_ALWAYS_INLINE static inline bool queue_event(dcd_event_t const * event, bool in_isr) { @@ -763,7 +761,7 @@ // Clear busy + claimed. A class OUT endpoint goes straight to RX_PENDING, so no other task can claim // and re-arm it before its buffer is consumed (#1292) - uint8_t const rx_pending = (0 != epnum && ep_dir == TUSB_DIR_OUT) ? USBD_RX_PENDING : 0u; + uint8_t const rx_pending = (0 != epnum && ep_dir == TUSB_DIR_OUT) ? TU_EDPT_STATE_RX_PENDING : 0u; _usbd_dev.ep_status[epnum][ep_dir] = (uint8_t) ( (_usbd_dev.ep_status[epnum][ep_dir] & ~(TU_EDPT_STATE_BUSY | TU_EDPT_STATE_CLAIMED)) | rx_pending); @@ -1598,7 +1596,6 @@ return tu_edpt_release(&_usbd_dev.ep_status[epnum][dir], _usbd_mutex); } -#if OSAL_MUTEX_REQUIRED void usbd_edpt_rx_consume(uint8_t rhport, uint8_t ep_addr) { (void) rhport; @@ -1613,7 +1610,6 @@ } (void) osal_mutex_unlock(_usbd_mutex); } -#endif bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes, bool is_isr) { rhport = _usbd_rhport; @@ -1637,7 +1633,7 @@ // Set busy first since the actual transfer can be complete before dcd_edpt_xfer() // could return and USBD task can preempt and clear the busy _usbd_dev.ep_status[epnum][dir] = - (uint8_t) ((_usbd_dev.ep_status[epnum][dir] & ~USBD_RX_PENDING) | TU_EDPT_STATE_BUSY); + (uint8_t) ((_usbd_dev.ep_status[epnum][dir] & ~TU_EDPT_STATE_RX_PENDING) | TU_EDPT_STATE_BUSY); if (dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes, is_isr)) { return true; @@ -1671,7 +1667,7 @@ // Set busy first since the actual transfer can be complete before dcd_edpt_xfer() could return // and usbd task can preempt and clear the busy _usbd_dev.ep_status[epnum][dir] = - (uint8_t) ((_usbd_dev.ep_status[epnum][dir] & ~USBD_RX_PENDING) | TU_EDPT_STATE_BUSY); + (uint8_t) ((_usbd_dev.ep_status[epnum][dir] & ~TU_EDPT_STATE_RX_PENDING) | TU_EDPT_STATE_BUSY); if (dcd_edpt_xfer_fifo(rhport, ep_addr, ff, total_bytes, is_isr)) { TU_LOG_USBD("OK\r\n");
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index d7cb9cc..a68e7f4 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h
@@ -75,7 +75,7 @@ // Claim an endpoint before submitting a transfer. // If caller does not make any transfer, it must release endpoint for others. // From an OUT xfer_cb, call usbd_edpt_rx_consume() (common/tusb_private.h) before claiming, or re-arm with -// usbd_edpt_xfer() directly: with OSAL_MUTEX_REQUIRED the claim is refused until the buffer is consumed. +// usbd_edpt_xfer() directly: the claim is refused until the buffer is consumed. bool usbd_edpt_claim(uint8_t rhport, uint8_t ep_addr); // Release claimed endpoint without submitting a transfer
diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index d58ad1a..06cff5b 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt
@@ -120,7 +120,6 @@ "${CEEDLING_WORKDIR}/../../src/tusb.c;${CEEDLING_WORKDIR}/../../src/device/usbd.c;${CEEDLING_WORKDIR}/../../src/common/tusb_fifo.c" "${CEEDLING_BUILD_DIR}/test/mocks/test_usbd/mock_dcd.c;${CEEDLING_BUILD_DIR}/test/mocks/test_usbd/mock_msc_device.c" ) -target_compile_definitions(test_usbd PRIVATE TUP_MCU_MULTIPLE_CORE=1) add_ceedling_test( test_msc_device
diff --git a/test/unit-test/project.yml b/test/unit-test/project.yml index 02e341c..599dabc 100644 --- a/test/unit-test/project.yml +++ b/test/unit-test/project.yml
@@ -132,8 +132,6 @@ - CFG_TUD_EDPT_DEDICATED_HWFIFO=1 - CFG_TUSB_FIFO_HWFIFO_DATA_STRIDE=6 - CFG_TUSB_FIFO_HWFIFO_ADDR_STRIDE=0 - :test_usbd: - - TUP_MCU_MULTIPLE_CORE=1 # OSAL_MUTEX_REQUIRED with osal_none, exercising the endpoint claim mutex :test_audio_host: - CFG_TUH_ENABLED=1 - CFG_TUH_AUDIO=1