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

Commit 4cf1f6c

Browse files
authored
Major Release v1.0.5
### Major Release v1.0.5 1. Add support to new [**`EthernetENC library`**](https://github.com/jandrassy/EthernetENC) for ENC28J60. 2. Add support to [`Ethernet2`](https://github.com/adafruit/Ethernet2), [`Ethernet3`](https://github.com/sstaub/Ethernet3) and [`EthernetLarge`](https://github.com/OPEnSLab-OSU/EthernetLarge) libraries on top of [`Ethernet`](https://www.arduino.cc/en/Reference/Ethernet). 2. Add debug feature. Clean up code. Restructure examples.
1 parent 80f3ffc commit 4cf1f6c

37 files changed

+2985
-1551
lines changed

README.md

Lines changed: 516 additions & 169 deletions
Large diffs are not rendered by default.

examples/AdvancedWebServer/AdvancedWebServer.ino

Lines changed: 87 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
11
/****************************************************************************************************************************
2-
AdvancedWebServer.h - Dead simple web-server for Ethernet shields
3-
4-
For STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 Ethernet
5-
6-
EthernetWebServer_STM32 is a library for the STM32 run built-in Ethernet WebServer
7-
8-
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
9-
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32
10-
Licensed under MIT license
11-
12-
Copyright (c) 2015, Majenko Technologies
13-
All rights reserved.
14-
15-
Redistribution and use in source and binary forms, with or without modification,
16-
are permitted provided that the following conditions are met:
17-
18-
Redistributions of source code must retain the above copyright notice, this
19-
list of conditions and the following disclaimer.
20-
21-
Redistributions in binary form must reproduce the above copyright notice, this
22-
list of conditions and the following disclaimer in the documentation and/or
23-
other materials provided with the distribution.
24-
25-
Neither the name of Majenko Technologies nor the names of its
26-
contributors may be used to endorse or promote products derived from
27-
this software without specific prior written permission.
28-
29-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
33-
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
36-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39-
40-
Version: 1.0.4
41-
42-
Version Modified By Date Comments
43-
------- ----------- ---------- -----------
44-
1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60
45-
1.0.1 K Hoang 28/02/2020 Add W5x00 Ethernet shields using Ethernet library
46-
1.0.2 K Hoang 05/03/2020 Remove dependency on functional-vlpp
47-
1.0.3 K Hoang 22/07/2020 Fix bug not closing client and releasing socket. Add features.
48-
1.0.4 K Hoang 23/07/2020 Add support to all STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash.
2+
AdvancedWebServer.h - Dead simple web-server for Ethernet shields
3+
4+
For STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 Ethernet
5+
6+
EthernetWebServer_STM32 is a library for the STM32 run built-in Ethernet WebServer
7+
8+
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
9+
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32
10+
Licensed under MIT license
11+
12+
Copyright (c) 2015, Majenko Technologies
13+
All rights reserved.
14+
15+
Redistribution and use in source and binary forms, with or without modification,
16+
are permitted provided that the following conditions are met:
17+
18+
Redistributions of source code must retain the above copyright notice, this
19+
list of conditions and the following disclaimer.
20+
21+
Redistributions in binary form must reproduce the above copyright notice, this
22+
list of conditions and the following disclaimer in the documentation and/or
23+
other materials provided with the distribution.
24+
25+
Neither the name of Majenko Technologies nor the names of its
26+
contributors may be used to endorse or promote products derived from
27+
this software without specific prior written permission.
28+
29+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
33+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
36+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39+
40+
Version: 1.0.5
41+
42+
Version Modified By Date Comments
43+
------- ----------- ---------- -----------
44+
1.0.0 K Hoang 26/02/2020 Initial coding for STM32 with built-in Ethernet (Nucleo-144, DISCOVERY, etc) and ENC28J60
45+
1.0.1 K Hoang 28/02/2020 Add W5x00 Ethernet shields using Ethernet library
46+
1.0.2 K Hoang 05/03/2020 Remove dependency on functional-vlpp
47+
1.0.3 K Hoang 22/07/2020 Fix bug not closing client and releasing socket. Add features.
48+
1.0.4 K Hoang 23/07/2020 Add support to all STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash.
49+
1.0.5 K Hoang 16/09/2020 Add support to Ethernet2, Ethernet3, Ethernet Large for W5x00
50+
Add support to new EthernetENC library for ENC28J60. Add debug feature.
4951
*****************************************************************************************************************************/
5052
/*
5153
Currently support
@@ -58,115 +60,10 @@
5860
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
5961
*/
6062

61-
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
62-
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
63-
defined(STM32WB) || defined(STM32MP1) )
64-
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
65-
#endif
66-
67-
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
68-
69-
// Debug Level from 0 to 4
70-
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 1
71-
72-
#define USE_BUILTIN_ETHERNET false
73-
// If don't use USE_BUILTIN_ETHERNET, and USE_UIP_ETHERNET => use W5x00 with Ethernet library
74-
#define USE_UIP_ETHERNET false //false
75-
76-
#if (USE_BUILTIN_ETHERNET)
77-
#define ETHERNET_NAME "Built-in LAN8742A Ethernet"
78-
#elif (USE_UIP_ETHERNET)
79-
#define ETHERNET_NAME "ENC28J60 Ethernet Shield"
80-
#else
81-
#define ETHERNET_NAME "W5x00 Ethernet Shield"
82-
#endif
83-
84-
#if defined(STM32F0)
85-
#warning STM32F0 board selected
86-
#define BOARD_TYPE "STM32F0"
87-
#elif defined(STM32F1)
88-
#warning STM32F1 board selected
89-
#define BOARD_TYPE "STM32F1"
90-
#elif defined(STM32F2)
91-
#warning STM32F2 board selected
92-
#define BOARD_TYPE "STM32F2"
93-
#elif defined(STM32F3)
94-
#warning STM32F3 board selected
95-
#define BOARD_TYPE "STM32F3"
96-
#elif defined(STM32F4)
97-
#warning STM32F4 board selected
98-
#define BOARD_TYPE "STM32F4"
99-
#elif defined(STM32F7)
100-
#warning STM32F7 board selected
101-
#define BOARD_TYPE "STM32F7"
102-
#elif defined(STM32L0)
103-
#warning STM32L0 board selected
104-
#define BOARD_TYPE "STM32L0"
105-
#elif defined(STM32L1)
106-
#warning STM32L1 board selected
107-
#define BOARD_TYPE "STM32L1"
108-
#elif defined(STM32L4)
109-
#warning STM32L4 board selected
110-
#define BOARD_TYPE "STM32L4"
111-
#elif defined(STM32H7)
112-
#warning STM32H7 board selected
113-
#define BOARD_TYPE "STM32H7"
114-
#elif defined(STM32G0)
115-
#warning STM32G0 board selected
116-
#define BOARD_TYPE "STM32G0"
117-
#elif defined(STM32G4)
118-
#warning STM32G4 board selected
119-
#define BOARD_TYPE "STM32G4"
120-
#elif defined(STM32WB)
121-
#warning STM32WB board selected
122-
#define BOARD_TYPE "STM32WB"
123-
#elif defined(STM32MP1)
124-
#warning STM32MP1 board selected
125-
#define BOARD_TYPE "STM32MP1"
126-
#else
127-
#warning STM32 unknown board selected
128-
#define BOARD_TYPE "STM32 Unknown"
129-
#endif
130-
131-
#ifndef BOARD_NAME
132-
#define BOARD_NAME BOARD_TYPE
133-
#endif
134-
135-
#include <EthernetWebServer_STM32.h>
136-
137-
// Enter a MAC address and IP address for your controller below.
138-
#define NUMBER_OF_MAC 20
139-
140-
byte mac[][NUMBER_OF_MAC] =
141-
{
142-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
143-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
144-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
145-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
146-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
147-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
148-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
149-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
150-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
151-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
152-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
153-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
154-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
155-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
156-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
157-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
158-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
159-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
160-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
161-
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
162-
};
163-
// Select the IP address according to your local network
164-
IPAddress ip(192, 168, 2, 232);
63+
#include "defines.h"
16564

16665
EthernetWebServer server(80);
16766

168-
int reqCount = 0; // number of requests received
169-
17067
const int led = 13;
17168

17269
void handleRoot()
@@ -252,17 +149,45 @@ void setup(void)
252149
digitalWrite(led, 0);
253150

254151
Serial.begin(115200);
255-
Serial.println("\nStart AdvancedWebServer on " + String(BOARD_NAME) + " board, running " + String(ETHERNET_NAME));
256-
257-
// start the ethernet connection and the server
258-
// Use random mac
259-
srand(1);
260-
uint16_t index = rand() % NUMBER_OF_MAC;
261-
//uint16_t index = random(NUMBER_OF_MAC);
262-
152+
Serial.println("\nStart AdvancedWebServer on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE));
153+
154+
ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
155+
156+
ET_LOGWARN(F("Default SPI pinout:"));
157+
ET_LOGWARN1(F("MOSI:"), MOSI);
158+
ET_LOGWARN1(F("MISO:"), MISO);
159+
ET_LOGWARN1(F("SCK:"), SCK);
160+
ET_LOGWARN1(F("SS:"), SS);
161+
ET_LOGWARN(F("========================="));
162+
163+
#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
164+
// For other boards, to change if necessary
165+
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
166+
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
167+
Ethernet.init (USE_THIS_SS_PIN);
168+
169+
#elif USE_ETHERNET3
170+
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
171+
#ifndef ETHERNET3_MAX_SOCK_NUM
172+
#define ETHERNET3_MAX_SOCK_NUM 4
173+
#endif
174+
175+
Ethernet.setCsPin (USE_THIS_SS_PIN);
176+
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
177+
178+
#elif USE_CUSTOM_ETHERNET
179+
// You have to add initialization for your Custom Ethernet here
180+
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
181+
//Ethernet.init(USE_THIS_SS_PIN);
182+
183+
#endif //( ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
184+
#endif
185+
186+
// start the ethernet connection and the server:
187+
// Use DHCP dynamic IP and random mac
188+
uint16_t index = millis() % NUMBER_OF_MAC;
263189
// Use Static IP
264190
//Ethernet.begin(mac[index], ip);
265-
// Use DHCP dynamic IP and random mac
266191
Ethernet.begin(mac[index]);
267192

268193
server.on("/", handleRoot);

0 commit comments

Comments
 (0)