Ethernet2 (UDP) SPI transfers have a lot of dead time

AFAIK inlining prevents the compiler to add a prologue (push { registers}) and prologue (pop {registers} ) to a function call, so logically it should be faster at the price of a larger code size.

PDC DMA and AHB DMA are surely the best options on a DUE to speed up every time they are available.

Just a quick followup to this very old thread...

I recently released Ethernet library version 2.0.0, which brings my many optimizations originally written for Teensy to all Arduino boards, including Arduino Due.

W5200 & W5500 now utilize SPI.transfer(buffer, size). I made many other optimizations, including native register I/O to avoid the slow digitalWrite on Due, and important higher level optimizations. Details and benchmarks here:

https://www.pjrc.com/arduino-ethernet-library-2-0-0/

To get version 2.0.0, just use the library manager to update your Ethernet lib.

Do you have any like for like timing comparisons with the official wiznet library?

This library, right?

I installed the "Arduino IDE 1.5.x" version just now. It doesn't work with my Seeed W5500 shield (with w5100.h edited to select W5500 - this lib doesn't auto-detect which chip you have).

It does work with my Arduino Ethernet R3 shield. The speed measures 9.83 kbytes/sec. Ethernet 2.0.0 gets 109.73 kbytes/sec.

I switched to Arduino Uno. Wiznet's library does work with the Seeed W5500 shield when using Uno. The speed is 139.99 kbytes/sec. For comparison, Ethernet 2.0.0 gets 329.00 kbytes/sec on the same test with Uno, and 689.69 kbytes/sec with Due.

I also retested W5100 (Arduino Ethernet R3). Wiznet's library get 10.17 kbytes/sec (yes, slightly faster than 9.83 kbytes/sec it gets with Arduino Due). Ethernet 2.0.0 gets 82.66 kbytes/sec when using W5100 on Uno, and 109.73 kbytes/sec with Due.

Without a doubt, Ethernet 2.0.0 is much faster than Wiznet's library.

For one final test, I put the Arduino.org Ethernet2 shield on Arduino Due. Wiznet's library does work with this shield. I don't know why it fails on the Seeed W5500 shield. Both work on Due with Ethernet 2.0.0.

Arduino Due with the W5500-based Arduino.org Ethernet2 speed is 394.80 kbytes/sec. Ethernet 2.0.0 gets 695.35 kbytes/sec with that shield on Due.

Thanks for sharing those results. Is there a result for the wiznet library on the 5500/Due?

weird_dave:
Thanks for sharing those results. Is there a result for the wiznet library on the 5500/Due?

Yes.

"Arduino Due with the W5500-based Arduino.org Ethernet2 speed is 394.80 kbytes/sec. Ethernet 2.0.0 gets 695.35 kbytes/sec with that shield on Due."

With all these optimizations in Ethernet 2.0.0 (removing the many prior bottlenecks in the Ethernet library), I believe these benchmarks would at least doubled on Arduino Due if someone were to optimize the SPI.transfer(buffer, length) well. Much of the hard work for those SPI optimizations has been done in the messages on this thread. But hardly anyone will ever benefit until someone goes to the trouble of actually updating Due's SPI library.

OK, I took the Arduino.org Ethernet2 library not to mean the Wiznet library since they are different (or were last time I checked).
When I get some spare time, I'll give it a go, thanks for the effort :slight_smile:

I recently released Ethernet library version 2.0.0

Wait - you got all that improvement WITHOUT implementing write-only SPI functions?
Wow.
(Hmm. Not that I'm sure that a write-only SPI would be much faster. Mostly just ... easier? No more overwriting your output buffer (?))

Yup, the old Ethernet lib was horribly inefficient on every level.

Due's SPI library is still very inefficient, which holds back Due's performance to ~700 kbytes/sec. If someone were to improve the SPI lib, I believe Due could probably even outperform Teensy (where the SPI lib is highly optimized) on these tests, because Due is the only board that can actually produce a 14 MHz SPI clock. Pretty much all the others use 8 or 12 MHz when SPISettings asks for 14 MHz max.

The SPI lib on Due isn't my project. My dev cycles are funded by Teensy sales. All this optimization work came from Teensy's fork of Ethernet. Occasionally I try to contribute Teensy's improvements back to the rest of the Arduino community, so everyone can benefit. Hope everyone gets some good use from it. :slight_smile: