pico-sdk icon indicating copy to clipboard operation
pico-sdk copied to clipboard

Add networking stack from TinyUSB.

Open luigifcruz opened this issue 3 years ago • 9 comments

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.

luigifcruz avatar Apr 12 '21 01:04 luigifcruz

Rebased to the latest branch. :)

luigifcruz avatar Jan 25 '23 05:01 luigifcruz

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?

peterharperuk avatar Mar 15 '23 20:03 peterharperuk

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.

luigifcruz avatar Mar 15 '23 20:03 luigifcruz

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"?

kilograham avatar Mar 15 '23 21:03 kilograham

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 avatar Mar 16 '23 10:03 peterharperuk

@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.

peterharperuk avatar Mar 16 '23 10:03 peterharperuk

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. :sweat_smile:

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.)

mordae avatar Mar 18 '23 11:03 mordae

@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 avatar Mar 23 '23 14:03 peterharperuk

@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.

peterharperuk avatar Mar 23 '23 14:03 peterharperuk