-
Notifications
You must be signed in to change notification settings - Fork 521
Pr3265 #3266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Pr3265 #3266
Conversation
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.
|
|
||
| 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
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
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
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
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
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
discardFrame
Show autofix suggestion
Hide autofix suggestion
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:
- 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.
- 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. - 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
voidto 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 tovoidat the callsite inreadFrame. - 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.
-
Copy modified line R110
| @@ -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; | ||
| } | ||
|
|
| 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
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.
No description provided.