From 3dfc52ff11859521b84881f717f303fb9013bec9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 17 Aug 2020 18:44:44 +0200 Subject: [PATCH 1/3] use transfer(wbuf,rbuf,count) also for read --- src/utility/w5100.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/utility/w5100.cpp b/src/utility/w5100.cpp index 4ae4ee7a..9b0cf1c8 100644 --- a/src/utility/w5100.cpp +++ b/src/utility/w5100.cpp @@ -413,9 +413,14 @@ uint16_t W5100Class::read(uint16_t addr, uint8_t *buf, uint16_t len) cmd[1] = addr & 0xFF; cmd[2] = (len >> 8) & 0x7F; cmd[3] = len & 0xFF; +#ifdef SPI_HAS_TRANSFER_BUF + SPI.transfer(cmd, NULL, 4); + SPI.transfer(NULL, buf, len); +#else SPI.transfer(cmd, 4); memset(buf, 0, len); SPI.transfer(buf, len); +#endif resetSS(); } else { // chip == 55 setSS(); @@ -457,9 +462,14 @@ uint16_t W5100Class::read(uint16_t addr, uint8_t *buf, uint16_t len) cmd[2] = ((addr >> 6) & 0xE0) | 0x18; // 2K buffers #endif } +#ifdef SPI_HAS_TRANSFER_BUF + SPI.transfer(cmd, NULL, 3); + SPI.transfer(NULL, buf, len); +#else SPI.transfer(cmd, 3); memset(buf, 0, len); SPI.transfer(buf, len); +#endif resetSS(); } return len; From f2daaae4817406a1b2c5eabb3997ed73bd55c212 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Wed, 8 Feb 2023 00:18:15 +0200 Subject: [PATCH 2/3] Allow redefining ETHERNET_MAX_SOCK_NUM, ETHERNET_SPI_SPEED --- src/Ethernet.h | 4 +++- src/utility/w5100.h | 40 +++++++++++++++------------------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/Ethernet.h b/src/Ethernet.h index 0045de88..4a883af7 100644 --- a/src/Ethernet.h +++ b/src/Ethernet.h @@ -33,7 +33,9 @@ // up to 4 sockets. W5200 & W5500 can have up to 8 sockets. Several bytes // of RAM are used for each socket. Reducing the maximum can save RAM, but // you are limited to fewer simultaneous connections. -#if defined(RAMEND) && defined(RAMSTART) && ((RAMEND - RAMSTART) <= 2048) +#if defined(ETHERNET_MAX_SOCK_NUM) +#define MAX_SOCK_NUM ETHERNET_MAX_SOCK_NUM +#elif defined(RAMEND) && defined(RAMSTART) && ((RAMEND - RAMSTART) <= 2048) #define MAX_SOCK_NUM 4 #else #define MAX_SOCK_NUM 8 diff --git a/src/utility/w5100.h b/src/utility/w5100.h index b2e8ec83..a3495e80 100644 --- a/src/utility/w5100.h +++ b/src/utility/w5100.h @@ -17,38 +17,28 @@ #include #include -// Safe for all chips -#define SPI_ETHERNET_SETTINGS SPISettings(14000000, MSBFIRST, SPI_MODE0) - -// Safe for W5200 and W5500, but too fast for W5100 -// Uncomment this if you know you'll never need W5100 support. -// Higher SPI clock only results in faster transfer to hosts on a LAN -// or with very low packet latency. With ordinary internet latency, -// the TCP window size & packet loss determine your overall speed. -//#define SPI_ETHERNET_SETTINGS SPISettings(30000000, MSBFIRST, SPI_MODE0) +#if defined(ETHERNET_SPI_SPEED) + // Good! Using the configured value. +#elif defined(ARDUINO_ARCH_ARC32) + // Arduino 101's SPI can not run faster than 8 MHz. + #define ETHERNET_SPI_SPEED 8000000 +#elif defined(__SAMD21G18A__) + // Arduino Zero can't use W5100-based shields faster than 8 MHz + // https://github.com/arduino-libraries/Ethernet/issues/37#issuecomment-408036848 + // W5500 does seem to work at 12 MHz. Delete this if only using W5500 + #define ETHERNET_SPI_SPEED 8000000 +#else + // Default. Safe for all chips. + #define ETHERNET_SPI_SPEED 14000000 +#endif +#define SPI_ETHERNET_SETTINGS SPISettings(ETHERNET_SPI_SPEED, MSBFIRST, SPI_MODE0) // Require Ethernet.h, because we need MAX_SOCK_NUM #ifndef ethernet_h_ #error "Ethernet.h must be included before w5100.h" #endif - -// Arduino 101's SPI can not run faster than 8 MHz. -#if defined(ARDUINO_ARCH_ARC32) -#undef SPI_ETHERNET_SETTINGS -#define SPI_ETHERNET_SETTINGS SPISettings(8000000, MSBFIRST, SPI_MODE0) -#endif - -// Arduino Zero can't use W5100-based shields faster than 8 MHz -// https://github.com/arduino-libraries/Ethernet/issues/37#issuecomment-408036848 -// W5500 does seem to work at 12 MHz. Delete this if only using W5500 -#if defined(__SAMD21G18A__) -#undef SPI_ETHERNET_SETTINGS -#define SPI_ETHERNET_SETTINGS SPISettings(8000000, MSBFIRST, SPI_MODE0) -#endif - - typedef uint8_t SOCKET; class SnMR { From 9e7b1df1f08acd984b25552308df590250225e87 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Wed, 8 Feb 2023 11:44:08 +0200 Subject: [PATCH 3/3] Revert "use transfer(wbuf,rbuf,count) also for read" --- src/utility/w5100.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/utility/w5100.cpp b/src/utility/w5100.cpp index d2866067..6e7dbd20 100644 --- a/src/utility/w5100.cpp +++ b/src/utility/w5100.cpp @@ -413,14 +413,9 @@ uint16_t W5100Class::read(uint16_t addr, uint8_t *buf, uint16_t len) cmd[1] = addr & 0xFF; cmd[2] = (len >> 8) & 0x7F; cmd[3] = len & 0xFF; -#ifdef SPI_HAS_TRANSFER_BUF - SPI.transfer(cmd, NULL, 4); - SPI.transfer(NULL, buf, len); -#else SPI.transfer(cmd, 4); memset(buf, 0, len); SPI.transfer(buf, len); -#endif resetSS(); } else { // chip == 55 setSS(); @@ -462,14 +457,9 @@ uint16_t W5100Class::read(uint16_t addr, uint8_t *buf, uint16_t len) cmd[2] = ((addr >> 6) & 0xE0) | 0x18; // 2K buffers #endif } -#ifdef SPI_HAS_TRANSFER_BUF - SPI.transfer(cmd, NULL, 3); - SPI.transfer(NULL, buf, len); -#else SPI.transfer(cmd, 3); memset(buf, 0, len); SPI.transfer(buf, len); -#endif resetSS(); } return len;