Skip to content

Add networking stack from TinyUSB. #334

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
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

luigifcruz
Copy link

I'm not sure if this is a path the maintainers want to pursue. But I added a tinyusb_net target on CMakeLists to import the necessary headers and files to make it possible to use the Pico as a network device based on the RNDIS example from TinyUSB.

As of now, I use these patches to build my PiccoloSDR project without known problems.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Contributor

@kilograham kilograham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be useful; not sure why some things are on tinyusb_common, and some on tinyusb_host and none on tinyusb_net!

@kilograham kilograham added this to the none milestone Jun 1, 2021
@kilograham kilograham changed the base branch from master to develop October 4, 2021 18:08
@kilograham kilograham modified the milestones: none, 1.5.0 Jun 30, 2022
@luigifcruz
Copy link
Author

Rebased to the latest branch. :)

@@ -93,6 +94,13 @@ if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH})
${PICO_TINYUSB_PATH}/src/class/vendor/vendor_host.c
)

add_library(tinyusb_net INTERFACE)
target_sources(tinyusb_host INTERFACE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presumably you meant tinyusb_net here

@peterharperuk
Copy link
Contributor

I've been playing around with the rndis stuff in tiny usb. I can't really see the point of running a dhcp server on the device. What would you use this for?

It would be nicer if dhcp could somehow obtain an address for the pico and use that as a network to get access to the internet. But I can't really get network sharing to work reliably. It looks like it sort of works on Windows if you're lucky. I'm not sure I can get it to work at all on Ubuntu.

Unless this is easy to use, I can't really see this being worth it?

@luigifcruz
Copy link
Author

I mean, this is not the easiest way to get data out of the Pico. But, unfortunately, it's the only way to do it with a decent speed without extra hardware. I can get a stable 5 Mbps running an iperf3 server on the Pico using the TinyUSB interface. This enables projects like my PiccoloSDR that require large amounts of data to be transferred to the computer. I also can think about a few projects that would require the bandwidth offered by this stack. For example, digital signal analyzer using the PIO, digital oscilloscope, high-sampling rate sensors, etc.

Regarding compatibility, the current version of the PiccoloSDR, which uses this PR, works very well with Linux and macOS (including Apple Silicon). You plug it in, an IP is automatically assigned, and you can access it with zero configuration. I never tested this on Windows, but looks like Microsoft added support to USB NCM on Windows 11. This theoretically solves support for Windows.

While developing PiccoloSDR, a major hurdle was patching the SDK to give me the right headers and binaries. The actual development of the network application was trivial. This PR comes at almost zero cost for those who don't use this feature while significantly facilitating the development process of network apps for those who need it.

@kilograham
Copy link
Contributor

i'm just confused by the PR in general; why are existing libraries being modified; can you just not add a new "tinyusb_net library"?

@peterharperuk
Copy link
Contributor

peterharperuk commented Mar 16, 2023

can you just not add a new "tinyusb_net library"?

I guess you could, but tiny usb already seems to pile everything into tinyusb_device_base? What's more confusing is that this doesn't live in the pico-sdk anymore.

We're missing networking/rndis_reports.c and the include folder lib/networking, which are easy enough to add to your own project.

I'm more interested in knowing if we can use this for real.

@peterharperuk
Copy link
Contributor

@luigifcruz Sorry, I missed your comment. So your use case is just to connect two computers and communicate with IP stacks. The IP address comes from the Pico - effectively a small private network.

@mordae
Copy link

mordae commented Mar 18, 2023

I am trying to build a subsampling receiver, learning as I go, and to my surprise the excellent demo from luigifcruz wouldn't work with stock SDK. 😅

Now seriously, using UDP to stream data over USB is a decent idea and with DHCP server it works out-of-box. I believe that USB tethering on Android works like that as well. It saves you the hassle of configuring network interfaces manually or writing specific device drivers.

I can imagine using it like that in a classroom setting.

(Sorry for butting in just to +1.)

@peterharperuk
Copy link
Contributor

@luigifcruz @mordae Did you test by connecting to Windows or a Linux PC? I still don't seem to get an IP address when connecting to Linux.

@peterharperuk
Copy link
Contributor

@luigifcruz @mordae Did you test by connecting to Windows or a Linux PC? I still don't seem to get an IP address when connecting to Linux.

Ignore me - I had a static IP address assigned. It worked ok after I removed this.

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

Successfully merging this pull request may close these issues.

None yet

5 participants