Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 9d5a201

Browse files
authored
v1.7.1 to use Ethernet_Generic library
### Releases v1.7.1 1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00. 2. Support SPI2 for ESP32 3. Add support to SPI1 for RP2040 using [arduino-pico core](https://github.com/earlephilhower/arduino-pico) 4. Use new function `waitForLink()` for Teensy 4.1 QNEthernet library v0.14.0+ 5. Rewrite all the examples to support those new features 6. Update `Packages' Patches`
1 parent c1547e4 commit 9d5a201

File tree

60 files changed

+1366
-1244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1366
-1244
lines changed

examples/Ethernet/Basic_Insert/Basic_Insert.ino

Lines changed: 44 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
// Select the static Local IP address according to your local network
6464
IPAddress ip(192, 168, 2, 222);
6565

66-
#define USING_HOST_NAME true
66+
#define USING_HOST_NAME false //true
6767

6868
#if USING_HOST_NAME
6969
// Optional using hostname, and Ethernet built-in DNS lookup
@@ -88,15 +88,9 @@ String INSERT_SQL = String("INSERT INTO ") + default_database + "." + default_ta
8888

8989
MySQL_Connection conn((Client *)&client);
9090

91-
void setup()
91+
void initEthernet()
9292
{
93-
Serial.begin(115200);
94-
while (!Serial); // wait for serial port to connect
95-
96-
MYSQL_DISPLAY3("\nStarting Basic_Insert on", BOARD_NAME, ", with", SHIELD_TYPE);
97-
MYSQL_DISPLAY(MYSQL_MARIADB_GENERIC_VERSION);
98-
99-
#if !(USE_ETHERNET_PORTENTA_H7)
93+
#if !(USE_ETHERNET_PORTENTA_H7 || USE_ETHERNET_LAN8742A || USE_ETHERNET_LAN8720)
10094

10195
MYSQL_LOGERROR(F("========================================="));
10296
MYSQL_LOGERROR(F("Default SPI pinout:"));
@@ -114,7 +108,7 @@ void setup()
114108

115109
MYSQL_LOGERROR1(F("ESP8266 setCsPin:"), USE_THIS_SS_PIN);
116110

117-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
111+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
118112
// For ESP8266
119113
// Pin D0(GPIO16) D1(GPIO5) D2(GPIO4) D3(GPIO0) D4(GPIO2) D8
120114
// Ethernet 0 X X X X 0
@@ -125,17 +119,8 @@ void setup()
125119
// D2 is safe to used for Ethernet, Ethernet2, Ethernet3, EthernetLarge libs
126120
// Must use library patch for Ethernet, EthernetLarge libraries
127121
Ethernet.init (USE_THIS_SS_PIN);
128-
129-
#elif USE_ETHERNET3
130-
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
131-
#ifndef ETHERNET3_MAX_SOCK_NUM
132-
#define ETHERNET3_MAX_SOCK_NUM 4
133-
#endif
134-
135-
Ethernet.setCsPin (USE_THIS_SS_PIN);
136-
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
137-
138-
#endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET_LARGE || USE_ETHERNET_ENC )
122+
123+
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
139124

140125
#elif defined(ESP32)
141126

@@ -154,24 +139,15 @@ void setup()
154139
MYSQL_LOGERROR1(F("ESP32 setCsPin:"), USE_THIS_SS_PIN);
155140

156141
// For other boards, to change if necessary
157-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
142+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
158143
// Must use library patch for Ethernet, EthernetLarge libraries
159144
// ESP32 => GPIO2,4,5,13,15,21,22 OK with Ethernet, Ethernet2, EthernetLarge
160145
// ESP32 => GPIO2,4,5,15,21,22 OK with Ethernet3
161146

162147
//Ethernet.setCsPin (USE_THIS_SS_PIN);
163148
Ethernet.init (USE_THIS_SS_PIN);
164149

165-
#elif USE_ETHERNET3
166-
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
167-
#ifndef ETHERNET3_MAX_SOCK_NUM
168-
#define ETHERNET3_MAX_SOCK_NUM 4
169-
#endif
170-
171-
Ethernet.setCsPin (USE_THIS_SS_PIN);
172-
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
173-
174-
#endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET_LARGE || USE_ETHERNET_ENC )
150+
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
175151

176152
#elif ETHERNET_USE_RPIPICO
177153

@@ -181,7 +157,7 @@ void setup()
181157
// ETHERNET_USE_RPIPICO, use default SS = 5 or 17
182158
#ifndef USE_THIS_SS_PIN
183159
#if defined(ARDUINO_ARCH_MBED)
184-
#define USE_THIS_SS_PIN 5 // For Arduino Mbed core
160+
#define USE_THIS_SS_PIN 17 // For Arduino Mbed core
185161
#else
186162
#define USE_THIS_SS_PIN 17 // For E.Philhower core
187163
#endif
@@ -190,7 +166,7 @@ void setup()
190166
MYSQL_LOGERROR1(F("RPIPICO setCsPin:"), USE_THIS_SS_PIN);
191167

192168
// For other boards, to change if necessary
193-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
169+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
194170
// Must use library patch for Ethernet, EthernetLarge libraries
195171
// For RPI Pico using Arduino Mbed RP2040 core
196172
// SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
@@ -200,17 +176,8 @@ void setup()
200176

201177
//Ethernet.setCsPin (USE_THIS_SS_PIN);
202178
Ethernet.init (USE_THIS_SS_PIN);
203-
204-
#elif USE_ETHERNET3
205-
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
206-
#ifndef ETHERNET3_MAX_SOCK_NUM
207-
#define ETHERNET3_MAX_SOCK_NUM 4
208-
#endif
209-
210-
Ethernet.setCsPin (USE_THIS_SS_PIN);
211-
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
212179

213-
#endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )
180+
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_LARGE )
214181

215182
#else //defined(ESP8266)
216183
// unknown board, do nothing, use default SS = 10
@@ -221,34 +188,35 @@ void setup()
221188
MYSQL_LOGERROR3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
222189

223190
// For other boards, to change if necessary
224-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
191+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
225192
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
226193

227194
Ethernet.init (USE_THIS_SS_PIN);
228-
229-
#elif USE_ETHERNET3
230-
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
231-
#ifndef ETHERNET3_MAX_SOCK_NUM
232-
#define ETHERNET3_MAX_SOCK_NUM 4
233-
#endif
234-
235-
Ethernet.setCsPin (USE_THIS_SS_PIN);
236-
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
237-
238-
#endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET_LARGE || USE_ETHERNET_ENC )
195+
196+
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
239197

240198
#endif //defined(ESP8266)
241199

242-
// Just info to know how to connect correctly
243-
MYSQL_LOGERROR(F("========================================="));
244-
MYSQL_LOGERROR(F("Currently Used SPI pinout:"));
245-
MYSQL_LOGERROR1(F("MOSI:"), MOSI);
246-
MYSQL_LOGERROR1(F("MISO:"), MISO);
247-
MYSQL_LOGERROR1(F("SCK:"), SCK);
248-
MYSQL_LOGERROR1(F("SS:"), SS);
249-
MYSQL_LOGERROR(F("========================================="));
200+
#if !(USE_ETHERNET_PORTENTA_H7 || USE_ETHERNET_LAN8742A || USE_ETHERNET_LAN8720)
201+
// Just info to know how to connect correctly
202+
#if defined(CUR_PIN_MISO)
203+
MYSQL_LOGERROR(F("Currently Used SPI pinout:"));
204+
MYSQL_LOGERROR1(F("MOSI:"), CUR_PIN_MOSI);
205+
MYSQL_LOGERROR1(F("MISO:"), CUR_PIN_MISO);
206+
MYSQL_LOGERROR1(F("SCK:"), CUR_PIN_SCK);
207+
MYSQL_LOGERROR1(F("SS:"), CUR_PIN_SS);
208+
#else
209+
MYSQL_LOGERROR(F("Currently Used SPI pinout:"));
210+
MYSQL_LOGERROR1(F("MOSI:"), MOSI);
211+
MYSQL_LOGERROR1(F("MISO:"), MISO);
212+
MYSQL_LOGERROR1(F("SCK:"), SCK);
213+
MYSQL_LOGERROR1(F("SS:"), SS);
214+
#endif
215+
216+
MYSQL_LOGERROR(F("========================="));
217+
#endif
250218

251-
#endif // #if !(USE_ETHERNET_PORTENTA_H7)
219+
#endif // #if !(USE_ETHERNET_PORTENTA_H7 || USE_ETHERNET_LAN8742A || USE_ETHERNET_LAN8720)
252220

253221
// start the ethernet connection and the server:
254222
// Use DHCP dynamic IP and random mac
@@ -259,6 +227,17 @@ void setup()
259227

260228
MYSQL_DISPLAY1("Using mac index =", index);
261229
MYSQL_DISPLAY1("Connected! IP address:", Ethernet.localIP());
230+
}
231+
232+
void setup()
233+
{
234+
Serial.begin(115200);
235+
while (!Serial && millis() < 5000); // wait for serial port to connect
236+
237+
MYSQL_DISPLAY3("\nStarting Basic_Insert on", BOARD_NAME, ", with", SHIELD_TYPE);
238+
MYSQL_DISPLAY(MYSQL_MARIADB_GENERIC_VERSION);
239+
240+
initEthernet();
262241

263242
MYSQL_DISPLAY3("Connecting to SQL Server @", server, ", Port =", server_port);
264243
MYSQL_DISPLAY5("User =", user, ", PW =", password, ", DB =", default_database);

examples/Ethernet/Basic_Insert/defines.h

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define MYSQL_DEBUG_PORT Serial
2222

2323
// Debug Level from 0 to 4
24-
#define _MYSQL_LOGLEVEL_ 1
24+
#define _MYSQL_LOGLEVEL_ 2
2525

2626
#if ( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) )
2727

@@ -40,8 +40,6 @@
4040
#define ETHERNET_USE_PORTENTA_H7 true
4141
#define USE_ETHERNET_PORTENTA_H7 true
4242

43-
#define USE_ETHERNET_WRAPPER false
44-
4543
#endif
4644

4745
#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \
@@ -239,7 +237,15 @@
239237

240238
#if defined(__IMXRT1062__)
241239
// For Teensy 4.1/4.0
242-
#define BOARD_TYPE "TEENSY 4.1/4.0"
240+
#if defined(ARDUINO_TEENSY41)
241+
#define BOARD_TYPE "TEENSY 4.1"
242+
// Use true for NativeEthernet Library, false if using other Ethernet libraries
243+
#define USE_NATIVE_ETHERNET true
244+
#elif defined(ARDUINO_TEENSY40)
245+
#define BOARD_TYPE "TEENSY 4.0"
246+
#else
247+
#define
248+
#endif
243249
#elif defined(__MK66FX1M0__)
244250
#define BOARD_TYPE "Teensy 3.6"
245251
#elif defined(__MK64FX512__)
@@ -313,9 +319,9 @@
313319
// Default pin 5 (in Mbed) or 17 to SS/CS
314320
#if defined(ARDUINO_ARCH_MBED)
315321
// For RPI Pico using Arduino Mbed RP2040 core
316-
// SCK: GP18, MOSI: GP19, MISO: GP16, SS/CS: GP17 or GP05
322+
// SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
317323

318-
#define USE_THIS_SS_PIN 17 //5
324+
#define USE_THIS_SS_PIN 17
319325

320326
#if defined(BOARD_NAME)
321327
#undef BOARD_NAME
@@ -333,11 +339,16 @@
333339

334340
#else
335341
// For RPI Pico using E. Philhower RP2040 core
336-
// SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17
337-
#define USE_THIS_SS_PIN 17
342+
#if (USING_SPI2)
343+
// SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1
344+
#define USE_THIS_SS_PIN 13
345+
#else
346+
// SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0
347+
#define USE_THIS_SS_PIN 17
348+
#endif
338349

339350
#endif
340-
351+
341352
#define SS_PIN_DEFAULT USE_THIS_SS_PIN
342353

343354
// For RPI Pico
@@ -370,47 +381,56 @@
370381
//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15
371382

372383
// Only one of the following to be true.
373-
#define USE_ETHERNET false
374-
#define USE_ETHERNET_LARGE false
375-
#define USE_ETHERNET2 false
376-
#define USE_ETHERNET3 false
384+
#define USE_ETHERNET_GENERIC true
377385
#define USE_ETHERNET_ESP8266 false
378386
#define USE_ETHERNET_ENC false
379387
#define USE_ETHERNET_LAN8742A false
380-
381-
// KH, from v1.0.1
388+
#define USE_ETHERNET_LAN8720 false
389+
#define USE_CUSTOM_ETHERNET false
382390
#define USE_UIP_ETHERNET false
383391
//////
384392

385-
#if USE_ETHERNET_PORTENTA_H7
386-
#warning Use Portenta Ethernet lib
387-
#define SHIELD_TYPE "Ethernet using Portenta_Ethernet Library"
388-
#elif USE_ETHERNET
389-
#warning Use Ethernet lib
390-
#define SHIELD_TYPE "W5x00 using Ethernet Library"
391-
#elif USE_ETHERNET_LARGE
392-
#warning Use EthernetLarge lib
393-
#define SHIELD_TYPE "W5x00 using EthernetLarge Library"
394-
#elif USE_ETHERNET2
395-
#warning Use Ethernet2 lib
396-
#define SHIELD_TYPE "W5x00 using Ethernet2 Library"
397-
#elif USE_ETHERNET3
398-
#warning Use Ethernet3 lib
399-
#define SHIELD_TYPE "W5x00 using Ethernet3 Library"
400-
#elif USE_ETHERNET_ESP8266
401-
#warning Using Ethernet_ESP8266 lib
402-
#define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library"
403-
#elif USE_ETHERNET_ENC
404-
#warning Using EthernetENC lib
405-
#define SHIELD_TYPE "ENC28J60 using EthernetENC Library"
406-
#elif USE_ETHERNET_LAN8742A
407-
#warning Using LAN8742A Ethernet & STM32Ethernet lib
408-
#define SHIELD_TYPE "LAN8742A Ethernet & STM32Ethernet Library"
409-
#else
410-
#define USE_ETHERNET true
411-
#include "Ethernet.h"
412-
#warning Use Ethernet lib
413-
#define SHIELD_TYPE "W5x00 using Ethernet Library"
393+
#if USE_CUSTOM_ETHERNET
394+
// You have to include an Ethernet library in your program
395+
//#include "Ethernet_XYZ.h"
396+
#include "EthernetLarge.h"
397+
398+
#define SHIELD_TYPE "Custom Ethernet using EthernetLarge Library"
399+
#endif
400+
401+
#if (_MYSQL_LOGLEVEL_ > 1)
402+
#if USE_ETHERNET_PORTENTA_H7
403+
#warning Use Portenta Ethernet lib
404+
#elif USE_QN_ETHERNET
405+
#warning Using QNEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error
406+
#elif USE_NATIVE_ETHERNET
407+
#warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error
408+
#elif USE_ETHERNET_GENERIC
409+
#warning Using Ethernet_Generic lib
410+
#elif USE_ETHERNET_ESP8266
411+
#warning Using Ethernet_ESP8266 lib
412+
#elif USE_ETHERNET_ENC
413+
#warning Using EthernetENC lib
414+
#elif USE_ETHERNET_LAN8742A
415+
#warning Using LAN8742A Ethernet & STM32Ethernet lib
416+
#elif USE_CUSTOM_ETHERNET
417+
#warning Using Custom Ethernet library
418+
#else
419+
#define USE_ETHERNET_GENERIC true
420+
421+
#warning Using Ethernet_Generic lib
422+
#endif
423+
#endif
424+
425+
#if !( USE_ETHERNET_ENC || USE_ETHERNET_ESP8266 || USE_UIP_ETHERNET || USE_ETHERNET_LAN8742A || USE_ETHERNET_LAN8720 || USE_NATIVE_ETHERNET || \
426+
USE_QN_ETHERNET || USE_CUSTOM_ETHERNET || USE_ETHERNET_PORTENTA_H7 || USE_CUSTOM_ETHERNET )
427+
#define USE_ETHERNET_GENERIC true
428+
#endif
429+
430+
#if USE_ETHERNET_GENERIC
431+
#define ETHERNET_LARGE_BUFFERS
432+
433+
#define _ETG_LOGLEVEL_ 1
414434
#endif
415435

416436
// Enter a MAC address and IP address for your controller below.

0 commit comments

Comments
 (0)