Skip to content

net: replace CFG_TUD_NET_ENDPOINT_SIZE with actual descriptor-based ep size#3568

Open
Copilot wants to merge 10 commits intomasterfrom
copilot/upgrade-net-lwip-webserver-descriptors
Open

net: replace CFG_TUD_NET_ENDPOINT_SIZE with actual descriptor-based ep size#3568
Copilot wants to merge 10 commits intomasterfrom
copilot/upgrade-net-lwip-webserver-descriptors

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 22, 2026

CFG_TUD_NET_ENDPOINT_SIZE used a compile-time TUD_OPT_HIGH_SPEED flag to pick between 512 and 64, which is incorrect when a device supports both speeds. ZLP decisions must be based on the actual negotiated endpoint size.

Changes

  • Remove CFG_TUD_NET_ENDPOINT_SIZE from net_device.h
  • ecm_rndis_device.c / ncm_device.c: Add uint16_t ep_size to the interface struct; populate it during netd_open() by reading wMaxPacketSize directly from the bulk endpoint descriptor via tu_edpt_packet_size() (IN and OUT assumed equal, matching the pattern in mtp_device.c)
  • ZLP logic: Use stored ep_size instead of runtime tud_speed_get() with hardcoded values
// Before: compile-time assumption
#define CFG_TUD_NET_ENDPOINT_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)

// After: read actual wMaxPacketSize from descriptor at open time
_netd_itf.ep_size = tu_edpt_packet_size((tusb_desc_endpoint_t const *) p_desc);
// ...then in xfer_cb:
if (xferred_bytes && (0 == (xferred_bytes % _netd_itf.ep_size))) { /* send ZLP */ }

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

… bInterval to TUD_CDC_NCM_DESCRIPTOR

Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hathach/tinyusb/sessions/e212b526-e279-4a83-88bf-a742df293165
@HiFiPhile
Copy link
Copy Markdown
Collaborator

@copilot remove submodules

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 22, 2026

@copilot remove submodules

Done, removed in cec6ea2.

Copilot AI requested a review from HiFiPhile March 22, 2026 19:49
@HiFiPhile
Copy link
Copy Markdown
Collaborator

@copilot Remove CFG_TUD_NET_ENDPOINT_SIZE, manage zlp based on real speed in drivers

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 22, 2026

@copilot Remove CFG_TUD_NET_ENDPOINT_SIZE, manage zlp based on real speed in drivers

Done in c843e5e. Removed CFG_TUD_NET_ENDPOINT_SIZE from net_device.h and replaced its compile-time usage in both ecm_rndis_device.c and ncm_device.c with a local ep_size variable derived from tud_speed_get() at runtime.

Copilot AI changed the title Upgrading net_lwip_webserver example with separate descriptors for FS and HS Upgrade net_lwip_webserver example with separate FS/HS descriptors and improve NCM/ECM ZLP handling Mar 22, 2026
…coding 64/512

Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hathach/tinyusb/sessions/4c20b579-db28-4643-b062-81881adcf6c1
Copilot AI changed the title Upgrade net_lwip_webserver example with separate FS/HS descriptors and improve NCM/ECM ZLP handling net: replace CFG_TUD_NET_ENDPOINT_SIZE with actual descriptor-based ep size Mar 22, 2026
@HiFiPhile HiFiPhile marked this pull request as ready for review March 22, 2026 20:12
Copilot AI review requested due to automatic review settings March 22, 2026 20:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes network class ZLP handling by basing decisions on the negotiated bulk endpoint wMaxPacketSize read from descriptors at netd_open() time, instead of compile-time or hardcoded speed assumptions (important for dual-speed devices).

Changes:

  • Remove CFG_TUD_NET_ENDPOINT_SIZE and store actual bulk EP max packet size in the network interface state for ECM/RNDIS and NCM.
  • Update ZLP decision logic to use the stored descriptor-derived endpoint size.
  • Update the net_lwip_webserver example to provide distinct FS/HS configuration descriptors and add HS support descriptors (device qualifier / other-speed config callbacks).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/device/usbd.h Extends the CDC-NCM descriptor template macro to include an interrupt bInterval parameter.
src/class/net/net_device.h Removes the compile-time endpoint size macro previously used for ZLP decisions.
src/class/net/ncm_device.c Stores bulk EP max packet size from descriptors and uses it for ZLP insertion logic.
src/class/net/ecm_rndis_device.c Stores bulk EP max packet size from descriptors and uses it for ZLP decisions.
examples/device/net_lwip_webserver/src/usb_descriptors.c Splits FS/HS configurations (64 vs 512), adds device qualifier + other-speed configuration callbacks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 22, 2026

Size Difference Report

Because TinyUSB code size varies by port and configuration, the metrics below represent the averaged totals across all example builds.

Note: If there is no change, only one value is shown.

Changes >1% in size

No entries.

Changes <1% in size

file .text .rodata .data .bss size % diff
ecm_rndis_device.c 1037 ➙ 1047 (+10) 0 1 2858 ➙ 2862 (+4) 3896 ➙ 3910 (+14) +0.4%
ncm_device.c 1538 ➙ 1553 (+15) 28 718 ➙ 722 (+4) 5843 7395 ➙ 7409 (+14) +0.2%
usbh.c 4653 ➙ 4649 (-4) 55 99 961 5734 ➙ 5731 (-3) -0.1%
TOTAL 7228 ➙ 7249 (+21) 83 818 ➙ 822 (+4) 9662 ➙ 9666 (+4) 17025 ➙ 17050 (+25) +0.1%
No changes
file .text .rodata .data .bss size % diff
audio_device.c 2897 0 1260 1627 4518 +0.0%
cdc_device.c 1252 16 1106 684 1935 +0.0%
cdc_host.c 6617 487 15 1498 8327 +0.0%
dcd_ch32_usbfs.c 1473 0 0 2444 3917 +0.0%
dcd_ch32_usbhs.c 1469 0 0 448 1917 +0.0%
dcd_ci_fs.c 1925 0 0 1290 3215 +0.0%
dcd_ci_hs.c 1759 0 0 1344 2538 +0.0%
dcd_da146xx.c 3067 0 0 144 3211 +0.0%
dcd_dwc2.c 4176 25 0 265 4465 +0.0%
dcd_eptri.c 2271 0 0 259 2530 +0.0%
dcd_ft9xx.c 3276 0 0 172 3448 +0.0%
dcd_khci.c 1953 0 0 1290 3243 +0.0%
dcd_lpc17_40.c 1474 0 0 648 1798 +0.0%
dcd_lpc_ip3511.c 1463 0 0 264 1683 +0.0%
dcd_mm32f327x_otg.c 1478 0 0 1290 2768 +0.0%
dcd_msp430x5xx.c 1798 0 0 176 1974 +0.0%
dcd_musb.c 2445 0 0 160 2605 +0.0%
dcd_nrf5x.c 2918 0 0 292 3210 +0.0%
dcd_nuc120.c 1094 0 0 78 1172 +0.0%
dcd_nuc121.c 1168 0 0 101 1269 +0.0%
dcd_nuc505.c 0 0 1531 157 1688 +0.0%
dcd_rp2040.c 836 20 604 655 2115 +0.0%
dcd_rusb2.c 2919 0 0 156 3075 +0.0%
dcd_samd.c 1034 0 0 266 1300 +0.0%
dcd_samg.c 1320 0 0 72 1392 +0.0%
dcd_stm32_fsdev.c 2558 0 0 291 2849 +0.0%
dfu_device.c 777 28 712 140 916 +0.0%
dfu_rt_device.c 157 0 134 0 157 +0.0%
dwc2_common.c 602 30 0 0 618 +0.0%
ehci.c 2763 0 0 6043 7597 +0.0%
fsdev_common.c 180 0 0 0 180 +0.0%
hcd_ch32_usbfs.c 2484 0 0 498 2982 +0.0%
hcd_ci_hs.c 184 0 0 0 184 +0.0%
hcd_dwc2.c 4994 33 1 513 5540 +0.0%
hcd_khci.c 2442 0 0 449 2891 +0.0%
hcd_musb.c 3073 0 0 157 3230 +0.0%
hcd_pio_usb.c 262 0 240 0 502 +0.0%
hcd_rp2040.c 976 73 416 384 1849 +0.0%
hcd_rusb2.c 2923 0 0 245 3168 +0.0%
hcd_samd.c 2220 0 0 324 2544 +0.0%
hcd_stm32_fsdev.c 3287 0 1 420 3708 +0.0%
hid_device.c 1125 44 997 119 1244 +0.0%
hid_host.c 1240 0 0 1251 2491 +0.0%
hub.c 1384 8 8 30 1418 +0.0%
midi_device.c 1151 0 1007 623 1772 +0.0%
midi_host.c 1341 7 7 3635 4979 +0.0%
msc_device.c 2525 108 2286 547 3071 +0.0%
msc_host.c 1587 0 0 394 1982 +0.0%
mtp_device.c 1696 22 735 588 2292 +0.0%
ohci.c 1940 0 0 2414 4353 +0.0%
printer_device.c 830 0 706 566 1394 +0.0%
rp2040_usb.c 120 75 669 4 868 +0.0%
rusb2_common.c 160 0 16 0 176 +0.0%
tusb.c 451 0 383 3 453 +0.0%
tusb_fifo.c 841 0 480 0 836 +0.0%
typec_stm32.c 820 8 2 12 842 +0.0%
usbc.c 420 2 20 166 608 +0.0%
usbd.c 3224 ➙ 3225 (+1) 57 88 275 3564 +0.0%
usbd_control.c 538 0 484 79 616 +0.0%
usbtmc_device.c 2196 24 68 316 2544 +0.0%
vendor_device.c 641 0 534 565 1204 +0.0%
video_device.c 4443 5 1235 479 4914 +0.0%
TOTAL 110637 ➙ 110638 (+1) 1072 15745 37310 149849 +0.0%

Copilot AI and others added 3 commits March 22, 2026 20:25
…OTHER_SPEED_CONFIG and fix SEED typo

Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hathach/tinyusb/sessions/3d21b8d3-b2df-4603-a426-2bcfdb408f04
Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
Agent-Logs-Url: https://github.com/hathach/tinyusb/sessions/3d21b8d3-b2df-4603-a426-2bcfdb408f04
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 22, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants