Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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;
(void) size;
return false;
}

#ifdef ENABLE_PICOTOOL_USB
// Support for Microsoft OS 2.0 descriptor
Expand Down
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,136 @@
/*
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());
#if LWIP_IPV6
for(int i=0;i<LWIP_IPV6_NUM_ADDRESSES;i++) {
IPAddress address = IPAddress(&eth.getNetIf()->ip6_addr[i]);
if(!address.isSet()) {
continue;
}
SER.println(address);
}
#endif
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
This sketch establishes a TCP connection to a "quote of the day" service.
It sends a "hello" message, and then prints received data.
*/

#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());
#if LWIP_IPV6
for(int i=0;i<LWIP_IPV6_NUM_ADDRESSES;i++) {
IPAddress address = IPAddress(&eth.getNetIf()->ip6_addr[i]);
if(!address.isSet()) {
continue;
}
SER.println(address);
}
#endif
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;
}
18 changes: 18 additions & 0 deletions libraries/lwIP_USB_NCM/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#######################################
# Syntax Coloring Map
#######################################

#######################################
# Library (KEYWORD1)
#######################################

USB_NCM_lwIP KEYWORD1
NCMEthernet KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

#######################################
# Constants (LITERAL1)
#######################################
Loading
Loading