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

Commit 86e3279

Browse files
authored
v1.4.0 to use Ethernet_Generic library
### Releases v1.4.0 1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00. 2. Rewrite all the examples to support new features 3. Add example [multiFileProject](examples/multiFileProject) to demo how to avoid `multiple-definitions` linker error for multiple-file project
1 parent a42c697 commit 86e3279

Some content is hidden

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

55 files changed

+1000
-3274
lines changed

examples/AdvancedWebServer/AdvancedWebServer.ino

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
/****************************************************************************************************************************
22
AdvancedWebServer.h - Dead simple web-server for Ethernet shields
3-
3+
44
For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
55
66
EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer
77
88
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
99
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32
1010
Licensed under MIT license
11-
11+
1212
Copyright (c) 2015, Majenko Technologies
1313
All rights reserved.
14-
14+
1515
Redistribution and use in source and binary forms, with or without modification,
1616
are permitted provided that the following conditions are met:
17-
17+
1818
Redistributions of source code must retain the above copyright notice, this
1919
list of conditions and the following disclaimer.
20-
20+
2121
Redistributions in binary form must reproduce the above copyright notice, this
2222
list of conditions and the following disclaimer in the documentation and/or
2323
other materials provided with the distribution.
24-
24+
2525
Neither the name of Majenko Technologies nor the names of its
2626
contributors may be used to endorse or promote products derived from
2727
this software without specific prior written permission.
28-
28+
2929
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
3030
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
3131
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -42,7 +42,7 @@
4242
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
4343
- Nucleo-144 (F429ZI, F767ZI)
4444
- Discovery (STM32F746G-DISCOVERY)
45-
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
45+
- STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet,
4646
- See How To Use Built-in Ethernet at (https://github.com/khoih-prog/EthernetWebServer_STM32/issues/1)
4747
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
4848
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
@@ -129,7 +129,7 @@ void drawGraph()
129129
"<g stroke=\"blue\">\n");
130130

131131
char temp[70];
132-
132+
133133
int y = rand() % 130;
134134

135135
for (int x = 10; x < 300; x += 10)
@@ -139,7 +139,7 @@ void drawGraph()
139139
out += temp;
140140
y = y2;
141141
}
142-
142+
143143
out += F("</g>\n</svg>\n");
144144

145145
ET_LOGDEBUG1(F("String Len = "), out.length());
@@ -149,7 +149,7 @@ void drawGraph()
149149
ET_LOGERROR3(F("String Len > "), previousStrLen, F(", extend to"), out.length() + 48);
150150

151151
previousStrLen = out.length() + 48;
152-
152+
153153
out.reserve(previousStrLen);
154154
}
155155
else
@@ -167,6 +167,7 @@ void setup()
167167
Serial.println("\nStart AdvancedWebServer on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE));
168168
Serial.println(ETHERNET_WEBSERVER_STM32_VERSION);
169169

170+
#if !(USE_BUILTIN_ETHERNET)
170171
ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
171172

172173
ET_LOGWARN(F("Default SPI pinout:"));
@@ -175,37 +176,31 @@ void setup()
175176
ET_LOGWARN1(F("SCK:"), SCK);
176177
ET_LOGWARN1(F("SS:"), SS);
177178
ET_LOGWARN(F("========================="));
179+
#endif
180+
181+
#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
182+
// For other boards, to change if necessary
183+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
184+
Ethernet.init (USE_THIS_SS_PIN);
185+
186+
#elif USE_CUSTOM_ETHERNET
187+
// You have to add initialization for your Custom Ethernet here
188+
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
189+
//Ethernet.init(USE_THIS_SS_PIN);
190+
191+
#endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
192+
#endif
178193

179-
#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
180-
// For other boards, to change if necessary
181-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
182-
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
183-
Ethernet.init (USE_THIS_SS_PIN);
184-
185-
#elif USE_ETHERNET3
186-
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
187-
#ifndef ETHERNET3_MAX_SOCK_NUM
188-
#define ETHERNET3_MAX_SOCK_NUM 4
189-
#endif
190-
191-
Ethernet.setCsPin (USE_THIS_SS_PIN);
192-
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
193-
194-
#elif USE_CUSTOM_ETHERNET
195-
// You have to add initialization for your Custom Ethernet here
196-
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
197-
//Ethernet.init(USE_THIS_SS_PIN);
198-
199-
#endif //( ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
200-
#endif
201-
202194
// start the ethernet connection and the server:
203195
// Use DHCP dynamic IP and random mac
204196
uint16_t index = millis() % NUMBER_OF_MAC;
205197
// Use Static IP
206198
//Ethernet.begin(mac[index], ip);
207199
Ethernet.begin(mac[index]);
208200

201+
Serial.print(F("Connected! IP address: "));
202+
Serial.println(Ethernet.localIP());
203+
209204
server.on("/", handleRoot);
210205
server.on("/test.svg", drawGraph);
211206
server.on("/inline", []()

examples/AdvancedWebServer/defines.h

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,13 @@
4141

4242
#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
4343
// Only one if the following to be true
44-
#define USE_ETHERNET false //true
45-
#define USE_ETHERNET2 false //true
46-
#define USE_ETHERNET3 false //true
47-
#define USE_ETHERNET_LARGE false
48-
#define USE_ETHERNET_ESP8266 false //true
49-
#define USE_ETHERNET_ENC true
44+
#define USE_ETHERNET_GENERIC true
45+
#define USE_ETHERNET_ESP8266 false
46+
#define USE_ETHERNET_ENC false
5047
#define USE_CUSTOM_ETHERNET false
5148
#endif
5249

53-
#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC )
50+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC )
5451
#ifdef USE_CUSTOM_ETHERNET
5552
#undef USE_CUSTOM_ETHERNET
5653
#endif
@@ -63,18 +60,15 @@
6360
#elif (USE_UIP_ETHERNET)
6461
#warning Using ENC28J60 & UIPEthernet lib
6562
#define SHIELD_TYPE "ENC28J60 & UIPEthernet Library"
66-
#elif USE_ETHERNET3
67-
#include "Ethernet3.h"
68-
#warning Using W5x00 & Ethernet3 lib
69-
#define SHIELD_TYPE "W5x00 & Ethernet3 Library"
70-
#elif USE_ETHERNET2
71-
#include "Ethernet2.h"
72-
#warning Using W5x00 & Ethernet2 lib
73-
#define SHIELD_TYPE "W5x00 & Ethernet2 Library"
74-
#elif USE_ETHERNET_LARGE
75-
#include "EthernetLarge.h"
76-
#warning Using W5x00 & EthernetLarge lib
77-
#define SHIELD_TYPE "W5x00 & EthernetLarge Library"
63+
#elif USE_ETHERNET_GENERIC
64+
#include "Ethernet_Generic.h"
65+
66+
#define ETHERNET_LARGE_BUFFERS
67+
68+
#define _ETG_LOGLEVEL_ 1
69+
70+
#warning Using W5x00 & Ethernet_Generic lib
71+
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
7872
#elif USE_ETHERNET_ESP8266
7973
#include "Ethernet_ESP8266.h"
8074
#warning Using W5x00 & Ethernet_ESP8266 lib
@@ -85,14 +79,14 @@
8579
#define SHIELD_TYPE "ENC28J60 & EthernetENC Library"
8680
#elif USE_CUSTOM_ETHERNET
8781
//#include "Ethernet_XYZ.h"
88-
#include "EthernetENC.h"
82+
#include "Ethernet.h"
8983
#warning Using Custom Ethernet library. You must include a library and initialize.
9084
#define SHIELD_TYPE "Custom Ethernet & Ethernet_XYZ Library"
9185
#else
92-
#define USE_ETHERNET true
93-
#include "Ethernet.h"
94-
#warning Using Ethernet lib
95-
#define SHIELD_TYPE "W5x00 & Ethernet Library"
86+
#define USE_ETHERNET_GENERIC true
87+
#include "Ethernet_Generic.h"
88+
#warning Using default Ethernet_Generic lib
89+
#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
9690
#endif
9791

9892
#if defined(STM32F0)

examples/HTTPClient/BasicAuthGet/BasicAuthGet.ino

Lines changed: 15 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,7 @@ void setup()
3737
Serial.println(" with " + String(SHIELD_TYPE));
3838
Serial.println(ETHERNET_WEBSERVER_STM32_VERSION);
3939

40-
#if USE_ETHERNET_WRAPPER
41-
42-
EthernetInit();
43-
44-
#else
45-
46-
#if USE_ETHERNET
47-
ET_LOGWARN(F("=========== USE_ETHERNET ==========="));
48-
#elif USE_ETHERNET2
49-
ET_LOGWARN(F("=========== USE_ETHERNET2 ==========="));
50-
#elif USE_ETHERNET3
51-
ET_LOGWARN(F("=========== USE_ETHERNET3 ==========="));
52-
#elif USE_ETHERNET_LARGE
53-
ET_LOGWARN(F("=========== USE_ETHERNET_LARGE ==========="));
54-
#elif USE_ETHERNET_ESP8266
55-
ET_LOGWARN(F("=========== USE_ETHERNET_ESP8266 ==========="));
56-
#else
57-
ET_LOGWARN(F("========================="));
58-
#endif
40+
ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
5941

6042
ET_LOGWARN(F("Default SPI pinout:"));
6143
ET_LOGWARN1(F("MOSI:"), MOSI);
@@ -64,149 +46,26 @@ void setup()
6446
ET_LOGWARN1(F("SS:"), SS);
6547
ET_LOGWARN(F("========================="));
6648

67-
#if defined(ESP8266)
68-
// For ESP8266, change for other boards if necessary
69-
#ifndef USE_THIS_SS_PIN
70-
#define USE_THIS_SS_PIN D2 // For ESP8266
71-
#endif
72-
73-
ET_LOGWARN1(F("ESP8266 setCsPin:"), USE_THIS_SS_PIN);
74-
75-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
76-
// For ESP8266
77-
// Pin D0(GPIO16) D1(GPIO5) D2(GPIO4) D3(GPIO0) D4(GPIO2) D8
78-
// Ethernet 0 X X X X 0
79-
// Ethernet2 X X X X X 0
80-
// Ethernet3 X X X X X 0
81-
// EthernetLarge X X X X X 0
82-
// Ethernet_ESP8266 0 0 0 0 0 0
83-
// D2 is safe to used for Ethernet, Ethernet2, Ethernet3, EthernetLarge libs
84-
// Must use library patch for Ethernet, EthernetLarge libraries
85-
Ethernet.init (USE_THIS_SS_PIN);
86-
87-
#elif USE_ETHERNET3
88-
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
89-
#ifndef ETHERNET3_MAX_SOCK_NUM
90-
#define ETHERNET3_MAX_SOCK_NUM 4
91-
#endif
92-
93-
Ethernet.setCsPin (USE_THIS_SS_PIN);
94-
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
95-
96-
#elif USE_CUSTOM_ETHERNET
97-
98-
// You have to add initialization for your Custom Ethernet here
99-
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
100-
Ethernet.init(USE_THIS_SS_PIN);
101-
102-
#endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )
103-
104-
#elif defined(ESP32)
105-
106-
// You can use Ethernet.init(pin) to configure the CS pin
107-
//Ethernet.init(10); // Most Arduino shields
108-
//Ethernet.init(5); // MKR ETH shield
109-
//Ethernet.init(0); // Teensy 2.0
110-
//Ethernet.init(20); // Teensy++ 2.0
111-
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
112-
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
113-
114-
#ifndef USE_THIS_SS_PIN
115-
#define USE_THIS_SS_PIN 22 // For ESP32
116-
#endif
117-
118-
ET_LOGWARN1(F("ESP32 setCsPin:"), USE_THIS_SS_PIN);
119-
120-
// For other boards, to change if necessary
121-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
122-
// Must use library patch for Ethernet, EthernetLarge libraries
123-
// ESP32 => GPIO2,4,5,13,15,21,22 OK with Ethernet, Ethernet2, EthernetLarge
124-
// ESP32 => GPIO2,4,5,15,21,22 OK with Ethernet3
125-
126-
//Ethernet.setCsPin (USE_THIS_SS_PIN);
127-
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-
#elif USE_CUSTOM_ETHERNET
139-
140-
// You have to add initialization for your Custom Ethernet here
141-
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
142-
Ethernet.init(USE_THIS_SS_PIN);
143-
144-
#endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )
145-
146-
#else //defined(ESP8266)
147-
// unknown board, do nothing, use default SS = 10
148-
#ifndef USE_THIS_SS_PIN
149-
#define USE_THIS_SS_PIN 10 // For other boards
150-
#endif
151-
152-
ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
153-
154-
// For other boards, to change if necessary
155-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
156-
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
157-
158-
Ethernet.init (USE_THIS_SS_PIN);
159-
160-
#elif USE_ETHERNET3
161-
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
162-
#ifndef ETHERNET3_MAX_SOCK_NUM
163-
#define ETHERNET3_MAX_SOCK_NUM 4
164-
#endif
165-
166-
Ethernet.setCsPin (USE_THIS_SS_PIN);
167-
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
168-
169-
#elif USE_CUSTOM_ETHERNET
170-
171-
// You have to add initialization for your Custom Ethernet here
172-
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
173-
Ethernet.init(USE_THIS_SS_PIN);
174-
175-
#endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )
176-
177-
#endif //defined(ESP8266)
178-
179-
180-
#endif //USE_ETHERNET_WRAPPER
181-
182-
49+
#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
50+
// For other boards, to change if necessary
51+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
52+
Ethernet.init (USE_THIS_SS_PIN);
53+
54+
#elif USE_CUSTOM_ETHERNET
55+
// You have to add initialization for your Custom Ethernet here
56+
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
57+
//Ethernet.init(USE_THIS_SS_PIN);
58+
59+
#endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
60+
#endif
61+
18362
// start the ethernet connection and the server:
18463
// Use DHCP dynamic IP and random mac
18564
uint16_t index = millis() % NUMBER_OF_MAC;
18665
// Use Static IP
18766
//Ethernet.begin(mac[index], ip);
18867
Ethernet.begin(mac[index]);
189-
190-
// Just info to know how to connect correctly
191-
Serial.println("=========================");
192-
Serial.println("Currently Used SPI pinout:");
193-
Serial.print("MOSI:");
194-
Serial.println(MOSI);
195-
Serial.print("MISO:");
196-
Serial.println(MISO);
197-
Serial.print("SCK:");
198-
Serial.println(SCK);
199-
Serial.print("SS:");
200-
Serial.println(SS);
201-
#if USE_ETHERNET3
202-
Serial.print("SPI_CS:");
203-
Serial.println(SPI_CS);
204-
#endif
205-
Serial.println(F("========================="));
206-
207-
Serial.print(F("Using mac index = "));
208-
Serial.println(index);
209-
68+
21069
Serial.print(F("Connected! IP address: "));
21170
Serial.println(Ethernet.localIP());
21271
}

0 commit comments

Comments
 (0)