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

Commit 2e8ee51

Browse files
authored
v1.2.0
### Releases v1.2.0 1. Add support to LAN8720 Ethernet for many STM32F4 (F407xx, NUCLEO_F429ZI) and STM32F7 (DISCO_F746NG, NUCLEO_F746ZG, UCLEO_F756ZG) boards. 2. Add LAN8720 examples 3. Add Packages' Patches for STM32 to use LAN8720 with STM32Ethernet and LwIP libraries
1 parent 1ce7389 commit 2e8ee51

File tree

80 files changed

+6381
-268
lines changed

Some content is hidden

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

80 files changed

+6381
-268
lines changed

examples/STM32_LAN8720/AdvancedWebServer_LAN8720/AdvancedWebServer_LAN8720.ino

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@
3939
*****************************************************************************************************************************/
4040
/*
4141
Currently support
42-
1) STM32 boards with built-in Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
42+
1) STM32 boards with built-in LAN8742A Ethernet (to use USE_BUILTIN_ETHERNET = true) such as :
4343
- Nucleo-144 (F429ZI, F767ZI)
4444
- Discovery (STM32F746G-DISCOVERY)
4545
- 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)
47-
2) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
48-
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
47+
2) STM32 boards with LAN8720 Ethernet (to use USE_BUILTIN_ETHERNET and USING_LAN8720 = true) such as :
48+
- BLACK_F407XX (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE-mini), NUCLEO_F429ZI, DISCO_F746NG,
49+
NUCLEO_F7x6ZG
50+
3) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running ENC28J60 shields (to use USE_BUILTIN_ETHERNET = false)
51+
4) STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 shields
4952
*/
5053

5154
#include "defines.h"
@@ -79,7 +82,7 @@ body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Col
7982
</head>\
8083
<body>\
8184
<h2>Hi from EthernetWebServer!</h2>\
82-
<h3>on %s</h3>\
85+
<h3>on %s using LAN8720</h3>\
8386
<p>Uptime: %d d %02d:%02d:%02d</p>\
8487
<img src=\"/test.svg\" />\
8588
</body>\
@@ -139,41 +142,12 @@ void setup(void)
139142
digitalWrite(led, 0);
140143

141144
Serial.begin(115200);
145+
146+
delay(2000);
147+
142148
Serial.println("\nStart AdvancedWebServer_LAN8720 on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE));
143149
Serial.println(ETHERNET_WEBSERVER_STM32_VERSION);
144150

145-
ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
146-
147-
ET_LOGWARN(F("Default SPI pinout:"));
148-
ET_LOGWARN1(F("MOSI:"), MOSI);
149-
ET_LOGWARN1(F("MISO:"), MISO);
150-
ET_LOGWARN1(F("SCK:"), SCK);
151-
ET_LOGWARN1(F("SS:"), SS);
152-
ET_LOGWARN(F("========================="));
153-
154-
#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
155-
// For other boards, to change if necessary
156-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
157-
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
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-
// You have to add initialization for your Custom Ethernet here
171-
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
172-
//Ethernet.init(USE_THIS_SS_PIN);
173-
174-
#endif //( ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
175-
#endif
176-
177151
// start the ethernet connection and the server:
178152
// Use DHCP dynamic IP and random mac
179153
uint16_t index = millis() % NUMBER_OF_MAC;

examples/STM32_LAN8720/AdvancedWebServer_LAN8720/defines.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
#ifndef defines_h
1414
#define defines_h
1515

16-
#if !( defined(STM32F4) || defined(STM32F7) )
17-
#error This code is designed to run on STM32F4 and STM32F7 platform! Please check your Tools->Board setting.
16+
#if !( defined(ARDUINO_BLACK_F407VE) || defined(ARDUINO_BLACK_F407VG) || defined(ARDUINO_BLACK_F407ZE) || defined(ARDUINO_BLACK_F407ZG) || \
17+
defined(ARDUINO_BLUE_F407VE_Mini) || defined(ARDUINO_DIYMORE_F407VGT) || defined(ARDUINO_FK407M1) || defined(ARDUINO_NUCLEO_F429ZI) || \
18+
defined(ARDUINO_DISCO_F746NG) || defined(ARDUINO_NUCLEO_F746ZG) || defined(ARDUINO_NUCLEO_F756ZG) || defined(ARDUINO_NUCLEO_H743ZI) )
19+
#error This code is designed to run on some STM32F407XX NUCLEO-F429ZI, STM32F746 and STM32F756 platform! Please check your Tools->Board setting.
1820
#endif
1921

2022
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
@@ -180,6 +182,6 @@ byte mac[][NUMBER_OF_MAC] =
180182
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
181183
};
182184
// Select the IP address according to your local network
183-
IPAddress ip(192, 168, 2, 232);
185+
IPAddress ip(192, 168, 2, 220);
184186

185187
#endif //defines_h
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// Note: Must replace
2+
// .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h
3+
// as described in README.md
4+
15
#define HAL_ETH_MODULE_ENABLED
26

3-
#if LAN8742A_PHY_ADDRESS
4-
#undef LAN8742A_PHY_ADDRESS
5-
#define LAN8742A_PHY_ADDRESS 0x01U
6-
#endif
7+
#define LAN8742A_PHY_ADDRESS 0x01U
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/****************************************************************************************************************************
2+
BasicAuthGet_LAN8720.ino - Simple Arduino web server sample for Ethernet shield
3+
4+
For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
5+
6+
EthernetWebServer_STM32 is a library for the STM32 running 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+
GET client with HTTP basic authentication for ArduinoHttpClient library
13+
Connects to server once every five seconds, sends a GET request
14+
15+
created 14 Feb 2016
16+
by Tom Igoe
17+
modified 3 Jan 2017 to add HTTP basic authentication
18+
by Sandeep Mistry
19+
modified 22 Jan 2019
20+
by Tom Igoe
21+
*****************************************************************************************************************************/
22+
23+
#include "defines.h"
24+
25+
char serverAddress[] = "192.168.2.112"; // server address
26+
int port = 8080;
27+
28+
EthernetClient client;
29+
EthernetHttpClient httpClient(client, serverAddress, port);
30+
31+
void setup()
32+
{
33+
Serial.begin(115200);
34+
delay(2000);
35+
36+
Serial.print("\nStarting BasicAuthGet_LAN8720 on " + String(BOARD_NAME));
37+
Serial.println(" with " + String(SHIELD_TYPE));
38+
Serial.println(ETHERNET_WEBSERVER_STM32_VERSION);
39+
40+
// start the ethernet connection and the server:
41+
// Use DHCP dynamic IP and random mac
42+
uint16_t index = millis() % NUMBER_OF_MAC;
43+
// Use Static IP
44+
//Ethernet.begin(mac[index], ip);
45+
Ethernet.begin(mac[index]);
46+
47+
Serial.print(F("Using mac index = "));
48+
Serial.println(index);
49+
50+
Serial.print(F("Connected! IP address: "));
51+
Serial.println(Ethernet.localIP());
52+
}
53+
54+
void loop()
55+
{
56+
Serial.println("making GET request with HTTP basic authentication");
57+
httpClient.beginRequest();
58+
httpClient.get("/secure");
59+
httpClient.sendBasicAuth("username", "password"); // send the username and password for authentication
60+
httpClient.endRequest();
61+
62+
// read the status code and body of the response
63+
int statusCode = httpClient.responseStatusCode();
64+
String response = httpClient.responseBody();
65+
66+
Serial.print("Status code: ");
67+
Serial.println(statusCode);
68+
Serial.print("Response: ");
69+
Serial.println(response);
70+
71+
Serial.println("Wait five seconds");
72+
delay(5000);
73+
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/****************************************************************************************************************************
2+
defines.h
3+
4+
For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
5+
6+
EthernetWebServer_STM32 is a library for the STM32 running 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+
13+
#ifndef defines_h
14+
#define defines_h
15+
16+
#if !( defined(ARDUINO_BLACK_F407VE) || defined(ARDUINO_BLACK_F407VG) || defined(ARDUINO_BLACK_F407ZE) || defined(ARDUINO_BLACK_F407ZG) || \
17+
defined(ARDUINO_BLUE_F407VE_Mini) || defined(ARDUINO_DIYMORE_F407VGT) || defined(ARDUINO_FK407M1) || defined(ARDUINO_NUCLEO_F429ZI) || \
18+
defined(ARDUINO_DISCO_F746NG) || defined(ARDUINO_NUCLEO_F746ZG) || defined(ARDUINO_NUCLEO_F756ZG) || defined(ARDUINO_NUCLEO_H743ZI) )
19+
#error This code is designed to run on some STM32F407XX NUCLEO-F429ZI, STM32F746 and STM32F756 platform! Please check your Tools->Board setting.
20+
#endif
21+
22+
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
23+
24+
// Debug Level from 0 to 4
25+
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 2
26+
27+
#define USING_LAN8720 true
28+
29+
// If USE_BUILTIN_ETHERNET == false and USE_UIP_ETHERNET == false =>
30+
// either use W5x00 with EthernetXYZ library
31+
// or ENC28J60 with EthernetENC library
32+
#define USE_BUILTIN_ETHERNET true
33+
//#define USE_BUILTIN_ETHERNET false
34+
35+
//#define USE_UIP_ETHERNET true
36+
#define USE_UIP_ETHERNET false
37+
38+
// To override the default CS/SS pin. Don't use unless you know exactly which pin to use
39+
// You can define here or customize for each board at same place with BOARD_TYPE
40+
//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15
41+
// Default pin 10 to SS/CS. To change according to your board, if necessary
42+
#define USE_THIS_SS_PIN 10
43+
44+
#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
45+
// Only one if the following to be true
46+
#define USE_ETHERNET false //true
47+
#define USE_ETHERNET2 false //true
48+
#define USE_ETHERNET3 false //true
49+
#define USE_ETHERNET_LARGE false
50+
#define USE_ETHERNET_ESP8266 false //true
51+
#define USE_ETHERNET_ENC true
52+
#define USE_CUSTOM_ETHERNET false
53+
#endif
54+
55+
#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC )
56+
#ifdef USE_CUSTOM_ETHERNET
57+
#undef USE_CUSTOM_ETHERNET
58+
#endif
59+
#define USE_CUSTOM_ETHERNET false //true
60+
#endif
61+
62+
#if (USE_BUILTIN_ETHERNET)
63+
#if USING_LAN8720
64+
#warning Using LAN8720A Ethernet & STM32Ethernet lib
65+
#define SHIELD_TYPE "LAN8720 Ethernet & STM32Ethernet Library"
66+
#else
67+
#warning Using LAN8742A Ethernet & STM32Ethernet lib
68+
#define SHIELD_TYPE "LAN8742A Ethernet & STM32Ethernet Library"
69+
#endif
70+
#elif (USE_UIP_ETHERNET)
71+
#warning Using ENC28J60 & UIPEthernet lib
72+
#define SHIELD_TYPE "ENC28J60 & UIPEthernet Library"
73+
#elif USE_ETHERNET3
74+
#include "Ethernet3.h"
75+
#warning Using W5x00 & Ethernet3 lib
76+
#define SHIELD_TYPE "W5x00 & Ethernet3 Library"
77+
#elif USE_ETHERNET2
78+
#include "Ethernet2.h"
79+
#warning Using W5x00 & Ethernet2 lib
80+
#define SHIELD_TYPE "W5x00 & Ethernet2 Library"
81+
#elif USE_ETHERNET_LARGE
82+
#include "EthernetLarge.h"
83+
#warning Using W5x00 & EthernetLarge lib
84+
#define SHIELD_TYPE "W5x00 & EthernetLarge Library"
85+
#elif USE_ETHERNET_ESP8266
86+
#include "Ethernet_ESP8266.h"
87+
#warning Using W5x00 & Ethernet_ESP8266 lib
88+
#define SHIELD_TYPE "W5x00 & Ethernet_ESP8266 Library"
89+
#elif USE_ETHERNET_ENC
90+
#include "EthernetENC.h"
91+
#warning Using ENC28J60 & EthernetENC lib
92+
#define SHIELD_TYPE "ENC28J60 & EthernetENC Library"
93+
#elif USE_CUSTOM_ETHERNET
94+
//#include "Ethernet_XYZ.h"
95+
#include "EthernetENC.h"
96+
#warning Using Custom Ethernet library. You must include a library and initialize.
97+
#define SHIELD_TYPE "Custom Ethernet & Ethernet_XYZ Library"
98+
#else
99+
#define USE_ETHERNET true
100+
#include "Ethernet.h"
101+
#warning Using Ethernet lib
102+
#define SHIELD_TYPE "W5x00 & Ethernet Library"
103+
#endif
104+
105+
#if defined(STM32F0)
106+
#warning STM32F0 board selected
107+
#define BOARD_TYPE "STM32F0"
108+
#elif defined(STM32F1)
109+
#warning STM32F1 board selected
110+
#define BOARD_TYPE "STM32F1"
111+
#elif defined(STM32F2)
112+
#warning STM32F2 board selected
113+
#define BOARD_TYPE "STM32F2"
114+
#elif defined(STM32F3)
115+
#warning STM32F3 board selected
116+
#define BOARD_TYPE "STM32F3"
117+
#elif defined(STM32F4)
118+
#warning STM32F4 board selected
119+
#define BOARD_TYPE "STM32F4"
120+
#elif defined(STM32F7)
121+
#warning STM32F7 board selected
122+
#define BOARD_TYPE "STM32F7"
123+
#elif defined(STM32L0)
124+
#warning STM32L0 board selected
125+
#define BOARD_TYPE "STM32L0"
126+
#elif defined(STM32L1)
127+
#warning STM32L1 board selected
128+
#define BOARD_TYPE "STM32L1"
129+
#elif defined(STM32L4)
130+
#warning STM32L4 board selected
131+
#define BOARD_TYPE "STM32L4"
132+
#elif defined(STM32H7)
133+
#warning STM32H7 board selected
134+
#define BOARD_TYPE "STM32H7"
135+
#elif defined(STM32G0)
136+
#warning STM32G0 board selected
137+
#define BOARD_TYPE "STM32G0"
138+
#elif defined(STM32G4)
139+
#warning STM32G4 board selected
140+
#define BOARD_TYPE "STM32G4"
141+
#elif defined(STM32WB)
142+
#warning STM32WB board selected
143+
#define BOARD_TYPE "STM32WB"
144+
#elif defined(STM32MP1)
145+
#warning STM32MP1 board selected
146+
#define BOARD_TYPE "STM32MP1"
147+
#else
148+
#warning STM32 unknown board selected
149+
#define BOARD_TYPE "STM32 Unknown"
150+
#endif
151+
152+
#ifndef BOARD_NAME
153+
#define BOARD_NAME BOARD_TYPE
154+
#endif
155+
156+
#include <EthernetHttpClient_STM32.h>
157+
#include <EthernetWebServer_STM32.h>
158+
159+
// Enter a MAC address and IP address for your controller below.
160+
#define NUMBER_OF_MAC 20
161+
162+
byte mac[][NUMBER_OF_MAC] =
163+
{
164+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x01 },
165+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x02 },
166+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x03 },
167+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x04 },
168+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x05 },
169+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x06 },
170+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x07 },
171+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x08 },
172+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x09 },
173+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0A },
174+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0B },
175+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0C },
176+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0D },
177+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0E },
178+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x0F },
179+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x10 },
180+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x11 },
181+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x12 },
182+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x13 },
183+
{ 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x14 },
184+
};
185+
// Select the IP address according to your local network
186+
IPAddress ip(192, 168, 2, 220);
187+
188+
#endif //defines_h
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Note: Must replace
2+
// .arduino15/packages/STM32/hardware/stm32/1.9.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h
3+
// as described in README.md
4+
5+
#define HAL_ETH_MODULE_ENABLED
6+
7+
#define LAN8742A_PHY_ADDRESS 0x01U

0 commit comments

Comments
 (0)