Skip to content
Closed

Pr3265 #3266

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cores/rp2040/USB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,12 @@
product_rev[0] = 0;
}


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 3 days 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.

(void) size;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.

Copilot Autofix

AI 3 days 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.

return false;
}

#ifdef ENABLE_PICOTOOL_USB
// Support for Microsoft OS 2.0 descriptor
Expand Down
74 changes: 74 additions & 0 deletions cores/rp2040/sdkoverride/ncm_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Dummy shim to be overridden by lwip_usb_ncm
#include <Arduino.h>
#include "tusb_option.h"

#if (CFG_TUD_ENABLED && CFG_TUD_NCM)

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#include "device/usbd.h"
#include "device/usbd_pvt.h"

#include "../../../pico-sdk/lib/tinyusb/src/class/net/ncm.h"
#include "../../../pico-sdk/lib/tinyusb/src/class/net/net_device.h"


extern bool tud_network_can_xmit(uint16_t size) __attribute((weak));
bool tud_network_can_xmit(uint16_t size) {
(void) size;
return false;
}

extern void tud_network_xmit(void *ref, uint16_t arg) __attribute((weak));
void tud_network_xmit(void *ref, uint16_t arg) {
(void) ref;
(void) arg;
return;
}

extern void tud_network_recv_renew(void) __attribute((weak));
void tud_network_recv_renew(void) {
}

extern void netd_init(void) __attribute((weak));
void netd_init(void) {
}

extern bool netd_deinit(void) __attribute((weak));
bool netd_deinit(void) {
return true;
}

extern void netd_reset(uint8_t rhport) __attribute((weak));
void netd_reset(uint8_t rhport) {
(void) rhport;
}

extern uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) __attribute((weak));
uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len) {
(void) rhport;
(void) itf_desc;
(void) max_len;
return 0;
}

extern bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) __attribute((weak));
bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
(void) rhport;
(void) ep_addr;
(void) result;
(void) xferred_bytes;
return false;
}

extern bool netd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) __attribute((weak));
bool netd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request) {
(void) rhport;
(void) stage;
(void) request;
return false;
}

#endif // ( CFG_TUD_ENABLED && CFG_TUD_NCM )
24 changes: 24 additions & 0 deletions include/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#define CFG_TUD_MSC (1)
#define CFG_TUD_MIDI (1)
#define CFG_TUD_VENDOR (0)
#define CFG_TUD_NCM (1)

#define CFG_TUD_CDC_RX_BUFSIZE (256)
#define CFG_TUD_CDC_TX_BUFSIZE (256)
Expand All @@ -84,10 +85,33 @@
// HID buffer size Should be sufficient to hold ID (if any) + Data
#define CFG_TUD_HID_EP_BUFSIZE (64)


// MIDI
#define CFG_TUD_MIDI_RX_BUFSIZE (64)
#define CFG_TUD_MIDI_TX_BUFSIZE (64)

//--------------------------------------------------------------------
// NCM CLASS CONFIGURATION, SEE "ncm.h" FOR PERFORMANCE TUNING
//--------------------------------------------------------------------
#include "lwipopts.h"
// Must be >> MTU
// Can be set to 2048 without impact
#define CFG_TUD_NCM_IN_NTB_MAX_SIZE (2 * TCP_MSS + 100)

// Must be >> MTU
// Can be set to smaller values if wNtbOutMaxDatagrams==1
#define CFG_TUD_NCM_OUT_NTB_MAX_SIZE (2 * TCP_MSS + 100)

// Number of NCM transfer blocks for reception side
#ifndef CFG_TUD_NCM_OUT_NTB_N
#define CFG_TUD_NCM_OUT_NTB_N 1
#endif

// Number of NCM transfer blocks for transmission side
#ifndef CFG_TUD_NCM_IN_NTB_N
#define CFG_TUD_NCM_IN_NTB_N 1
#endif

#ifdef __cplusplus
}
#endif
Expand Down
Binary file modified lib/rp2040/liblwip-bt.a
Binary file not shown.
Binary file modified lib/rp2040/liblwip.a
Binary file not shown.
Binary file modified lib/rp2040/libpico.a
Binary file not shown.
Binary file modified lib/rp2350-riscv/liblwip-bt.a
Binary file not shown.
Binary file modified lib/rp2350-riscv/liblwip.a
Binary file not shown.
Binary file modified lib/rp2350-riscv/libpico.a
Binary file not shown.
Binary file modified lib/rp2350/liblwip-bt.a
Binary file not shown.
Binary file modified lib/rp2350/liblwip.a
Binary file not shown.
Binary file modified lib/rp2350/libpico.a
Binary file not shown.
2 changes: 2 additions & 0 deletions libraries/lwIP_USB_NCM/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/.pio/
**/.vscode/
Empty file added libraries/lwIP_USB_NCM/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
*/README

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = pico

[env:pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = rpipico
framework = arduino
board_build.core = earlephilhower
platform_packages =
framework-arduinopico@symlink://path/to/arduino-pico

;build_flags = -DLWIP_DEBUG=1 -DDEBUG_RP2040_PORT=Serial1

[env:pico2]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = rpipico2
framework = arduino
board_build.core = earlephilhower
platform_packages =
framework-arduinopico@symlink://path/to/arduino-pico

Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
This sketch establishes a TCP connection to a "quote of the day" service.
It sends a "hello" message, and then prints received data.
*/

#include <Arduino.h>
#include <NCMEthernetlwIP.h>

const char* host = "djxmmx.net";
const uint16_t port = 17;

NCMEthernetlwIP eth;
IPAddress my_static_ip_addr(192, 168, 137, 100);
IPAddress my_static_gateway_and_dns_addr(192, 168, 137, 1);

#define USE_REAL_UART

#if defined(USE_REAL_UART)
#define SER Serial1
#else
#define SER Serial
#endif

void setup() {
// enable Serial1 so it can be used by USE_REAL_UART or by DEBUG_RP2040_PORT
Serial1.end();
Serial1.setTX(16);
Serial1.setRX(17);
Serial1.begin(115200);

pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);

Serial.begin(115200);
delay(3000);
SER.println();
SER.println();
SER.println("Starting NCM Ethernet port");


//optional static config
// eth.config(my_static_ip_addr, my_static_gateway_and_dns_addr, IPAddress(255, 255, 255, 0), my_static_gateway_and_dns_addr);

// Start the Ethernet port
// This starts DHCP in case config() was not called before
bool ok = eth.begin();
delay(1000);
if (!ok) {
while (1) {
SER.println("Failed to initialize NCM Ethernet.");
delay(1000);
}
} else {
SER.println("NCM Ethernet started successfully.");
}

}

void loop() {
static unsigned long next_msg = 0;
static bool led_on = false;
if(millis() > next_msg) {
SER.println(".");
next_msg = millis() + 1000;
digitalWrite(LED_BUILTIN, led_on);
led_on ^=1;
}

static bool connected = false;
if(!eth.connected()) {
connected = false;
return;
} else if(!connected){
SER.println("");
SER.println("Ethernet connected");
SER.println("IP address: ");
SER.println(eth.localIP());
connected = true;
}

static bool wait = false;

SER.printf("connecting to %s:%i\n", host, port);

// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, port)) {
SER.println("connection failed");
delay(5000);
return;
}

// This will send a string to the server
SER.println("sending data to server");
if (client.connected()) {
client.println("hello from RP2040");
}

// wait for data to be available
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
SER.println(">>> Client Timeout !");
client.stop();
delay(60000);
return;
}
}

// Read all the lines of the reply from server and print them to Serial
SER.println("receiving from remote server");
// not testing 'client.connected()' since we do not need to send data here
while (client.available()) {
char ch = static_cast<char>(client.read());
SER.print(ch);
}

// Close the connection
SER.println();
SER.println("closing connection");
client.stop();

if (wait) {
delay(300000); // execute once every 5 minutes, don't flood remote service
}
wait = true;
}
Loading