-
Notifications
You must be signed in to change notification settings - Fork 521
Add USB NCM #3265
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
Open
functionpointer
wants to merge
7
commits into
earlephilhower:master
Choose a base branch
from
functionpointer:usb_ncm_new
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+705
−1
Open
Add USB NCM #3265
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8e3432f
NCM (Network Control Model) is the newest
functionpointer 5aa6573
Recompile libpico
functionpointer 57f3700
Merge branch 'master' into usb_ncm_new
earlephilhower 7aa5371
USB_NCM: Add weak definition to fix build when not using NCM
functionpointer 26f8ae1
USB_NCM: Fix spelling in comment
functionpointer e8b5545
USB_NCM: Add IPv6 support for the examples
functionpointer bfab3b4
USB_NCM: fix formatting in USB.cpp
functionpointer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| **/.pio/ | ||
| **/.vscode/ |
Empty file.
7 changes: 7 additions & 0 deletions
7
libraries/lwIP_USB_NCM/examples/WiFiClient-NCMEthernet-platformio/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
Empty file.
Empty file.
31 changes: 31 additions & 0 deletions
31
libraries/lwIP_USB_NCM/examples/WiFiClient-NCMEthernet-platformio/platformio.ini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
136 changes: 136 additions & 0 deletions
136
libraries/lwIP_USB_NCM/examples/WiFiClient-NCMEthernet-platformio/src/main.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(ð.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; | ||
| } |
Empty file.
135 changes: 135 additions & 0 deletions
135
libraries/lwIP_USB_NCM/examples/WiFiClient-NCMEthernet/WiFiClient-NCMEthernet.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(ð.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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| ####################################### |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.