Skip to content

Conversation

@earlephilhower
Copy link
Owner

No description provided.

functionpointer and others added 6 commits December 10, 2025 18:27
of three protocols for Ethernet over USB.

This implementation in arduino-pico
enables an Ethernet connection with a host PC
over USB without any extra hardware.
Other uses of USB like Serial,
Mouse or Keyboard continue to work in parallel.

It has been tested on Windows and Linux.
MacOS should also work.
The NCM buffers are only accessed in a single file and under very
limited circumstances.  Use a SDKOVERRIDE to make a weak ncm_device
with no memory usage, and put the TUSB ncd_device inside the lwip_usb
folder.

For apps which don't use NCM, this saves >6K of RAM.  For apps which use
NCM, there should be no change.
@earlephilhower earlephilhower mentioned this pull request Dec 10, 2025

extern "C" bool tud_network_recv_cb(const uint8_t *src, uint16_t size) __attribute__((weak));
extern "C" bool tud_network_recv_cb(const uint8_t *src, uint16_t size) {
(void) src;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.

Copilot Autofix

AI about 6 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

extern "C" bool tud_network_recv_cb(const uint8_t *src, uint16_t size) __attribute__((weak));
extern "C" bool tud_network_recv_cb(const uint8_t *src, uint16_t size) {
(void) src;
(void) size;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.

Copilot Autofix

AI about 6 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.


NCMEthernet::NCMEthernet(int8_t cs, arduino::SPIClass &spi, int8_t intrpin) {
(void) cs;
(void) spi;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.

Copilot Autofix

AI about 6 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

NCMEthernet::NCMEthernet(int8_t cs, arduino::SPIClass &spi, int8_t intrpin) {
(void) cs;
(void) spi;
(void) intrpin;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.

Copilot Autofix

AI about 6 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

}

bool NCMEthernet::begin(const uint8_t* mac_address, netif *net) {
(void) net;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.

Copilot Autofix

AI about 6 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.


if (data_len > bufsize) {
// Packet is bigger than buffer - drop the packet
discardFrame(data_len);

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect (because
discardFrame
has no external side effects).

Copilot Autofix

AI about 6 hours ago

To fix the problem, you should ensure that discardFrame(data_len); meaningfully performs the discard action. There are two potential approaches:

  1. If discardFrame is supposed to have an effect (i.e., drop the frame): Implement its logic so that it actually discards the data and affects program state.
  2. If discardFrame is intentionally a no-op for some target: Explicitly document that the result is deliberately ignored by casting to (void)discardFrame(data_len); to avoid misunderstandings and to silence CodeQL warnings.
  3. If the code is incomplete, and the implementation should be added later: Add a comment, and/or make the function [[maybe_unused]] or mark it as UNIMPLEMENTED.

Best practice for production code:

  • Implement the discardFrame() method to clear any buffers or update state so that the frame is actually discarded, if required.
  • If it is intentionally a no-op (for hardware or platform reasons), cast to void to document that, and add a code comment justifying the design choice.

What to change, specifically:

  • Insert a proper implementation of discardFrame() if you have access to it in the codebase; otherwise, cast to void at the callsite in readFrame.
  • No additional imports are required.
  • Edit only the file and code shown (libraries/lwIP_USB_NCM/src/utility/NCMEthernet.cpp, line 110).
  • Optionally, add a comment above or at the callsite for future maintainers.

Suggested changeset 1
libraries/lwIP_USB_NCM/src/utility/NCMEthernet.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/libraries/lwIP_USB_NCM/src/utility/NCMEthernet.cpp b/libraries/lwIP_USB_NCM/src/utility/NCMEthernet.cpp
--- a/libraries/lwIP_USB_NCM/src/utility/NCMEthernet.cpp
+++ b/libraries/lwIP_USB_NCM/src/utility/NCMEthernet.cpp
@@ -107,7 +107,7 @@
 
   if (data_len > bufsize) {
     // Packet is bigger than buffer - drop the packet
-    discardFrame(data_len);
+    (void)discardFrame(data_len);  // intentionally ignore result; discard packet if too large
     return 0;
   }
 
EOF
@@ -107,7 +107,7 @@

if (data_len > bufsize) {
// Packet is bigger than buffer - drop the packet
discardFrame(data_len);
(void)discardFrame(data_len); // intentionally ignore result; discard packet if too large
return 0;
}

Copilot is powered by AI and may make mistakes. Always verify output.
uint16_t readFrame(uint8_t* buffer, uint16_t bufsize);

void discardFrame(uint16_t ign) {
(void) ign;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.

Copilot Autofix

AI about 6 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants