summaryrefslogtreecommitdiff
path: root/src/device
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2026-03-11 15:46:47 +0700
committerGitHub <[email protected]>2026-03-11 15:46:47 +0700
commitf2450788b13f8424b2f75e33240ed21329a875ad (patch)
treec0df9625e43ec91db095d92ada9c3dfd00199164 /src/device
parentae3a6255e59e9533f8a1f92b088680acb93ce24d (diff)
parent2e29388051b2d92d2d254e3ce5967bfec2b9720f (diff)
Merge pull request #3352 from hathach/ep0_direct
Use EP0 buffer directly if it's large enough
Diffstat (limited to 'src/device')
-rw-r--r--src/device/usbd_control.c10
-rw-r--r--src/device/usbd_pvt.h2
2 files changed, 10 insertions, 2 deletions
diff --git a/src/device/usbd_control.c b/src/device/usbd_control.c
index 47d58a1f9..87593d4a7 100644
--- a/src/device/usbd_control.c
+++ b/src/device/usbd_control.c
@@ -63,6 +63,10 @@ CFG_TUD_MEM_SECTION static struct {
TUD_EPBUF_DEF(buf, CFG_TUD_ENDPOINT0_BUFSIZE);
} _ctrl_epbuf;
+uint8_t* usbd_get_ctrl_buf(void) {
+ return _ctrl_epbuf.buf;
+}
+
//--------------------------------------------------------------------+
// Application API
//--------------------------------------------------------------------+
@@ -93,7 +97,7 @@ static bool data_stage_xact(uint8_t rhport) {
if (_ctrl_xfer.request.bmRequestType_bit.direction == TUSB_DIR_IN) {
ep_addr = EDPT_CTRL_IN;
- if (0u != xact_len) {
+ if (0u != xact_len && _ctrl_xfer.buffer != _ctrl_epbuf.buf) {
TU_VERIFY(0 == tu_memcpy_s(_ctrl_epbuf.buf, CFG_TUD_ENDPOINT0_BUFSIZE, _ctrl_xfer.buffer, xact_len));
}
}
@@ -169,7 +173,9 @@ bool usbd_control_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result,
if (_ctrl_xfer.request.bmRequestType_bit.direction == TUSB_DIR_OUT) {
TU_VERIFY(_ctrl_xfer.buffer);
- memcpy(_ctrl_xfer.buffer, _ctrl_epbuf.buf, xferred_bytes);
+ if (_ctrl_xfer.buffer != _ctrl_epbuf.buf) {
+ memcpy(_ctrl_xfer.buffer, _ctrl_epbuf.buf, xferred_bytes);
+ }
TU_LOG_MEM(CFG_TUD_LOG_LEVEL, _ctrl_xfer.buffer, xferred_bytes, 2);
}
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h
index 72323ac80..5f11ea481 100644
--- a/src/device/usbd_pvt.h
+++ b/src/device/usbd_pvt.h
@@ -72,6 +72,8 @@ void usbd_int_set(bool enabled);
void usbd_spin_lock(bool in_isr);
void usbd_spin_unlock(bool in_isr);
+uint8_t* usbd_get_ctrl_buf(void);
+
//--------------------------------------------------------------------+
// USBD Endpoint API
// Note: rhport should be 0 since device stack only support 1 rhport for now