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

Commit 7023147

Browse files
authored
v1.6.0 to add custom SPI support
### Releases v1.6.0 1. Add support to any custom hardware / software `SPI` for W5x00 using [Ethernet_Generic Library](https://github.com/khoih-prog/Ethernet_Generic) 2. Add support to STM32L5 boards, such as `Nucleo-L552ZE-Q`
1 parent f6c7fdf commit 7023147

Some content is hidden

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

67 files changed

+3136
-1019
lines changed

examples/AWS_IoT/AWS_IoT.ino

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,38 @@ void setup()
132132
{
133133
// Open serial communications and wait for port to open:
134134
Serial.begin(115200);
135-
while (!Serial);
135+
while (!Serial && millis() < 5000);
136136

137137
Serial.print("\nStart AWS_IoT on "); Serial.print(BOARD_NAME);
138138
Serial.print(" with "); Serial.println(SHIELD_TYPE);
139+
140+
#if USE_ETHERNET_GENERIC
141+
Serial.println(ETHERNET_GENERIC_VERSION);
142+
#endif
143+
139144
Serial.println(ETHERNET_WEBSERVER_SSL_STM32_VERSION);
140145

141146
// Enable mutual TLS with SSLClient
142147
ethClientSSL.setMutualAuthParams(mTLS);
143148

144149
#if !(USE_BUILTIN_ETHERNET)
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("========================="));
150+
#if (USING_SPI2)
151+
#if defined(CUR_PIN_MISO)
152+
ET_LOGWARN(F("Default SPI pinout:"));
153+
ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
154+
ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
155+
ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
156+
ET_LOGWARN1(F("SS:"), CUR_PIN_SS);
157+
ET_LOGWARN(F("========================="));
158+
#endif
159+
#else
160+
ET_LOGWARN(F("Default SPI pinout:"));
161+
ET_LOGWARN1(F("MOSI:"), MOSI);
162+
ET_LOGWARN1(F("MISO:"), MISO);
163+
ET_LOGWARN1(F("SCK:"), SCK);
164+
ET_LOGWARN1(F("SS:"), SS);
165+
ET_LOGWARN(F("========================="));
166+
#endif
153167
#endif
154168

155169
#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)

examples/AWS_IoT/defines.h

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
/****************************************************************************************************************************
22
defines.h
33
4-
For STM32F/L/H/G/WB/MP1 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
5-
6-
EthernetWebServer_SSL_STM32 is a library for STM32 using the Ethernet shields to run WebServer and Client with/without SSL
4+
For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
75
8-
Use SSLClient Library code from https://github.com/OPEnSLab-OSU/SSLClient
9-
10-
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_SSL_STM32
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
1111
***************************************************************************************************************************************/
1212

1313
#ifndef defines_h
1414
#define defines_h
1515

1616
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
1717
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
18-
defined(STM32WB) || defined(STM32MP1) )
18+
defined(STM32WB) || defined(STM32MP1) || defined(STM32L5) )
1919
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
2020
#endif
2121

2222
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
2323

2424
// Debug Level from 0 to 4
25-
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 2
25+
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
2626

2727
// If USE_BUILTIN_ETHERNET == false and USE_UIP_ETHERNET == false =>
2828
// either use W5x00 with EthernetXYZ library
2929
// or ENC28J60 with EthernetENC library
30-
#define USE_BUILTIN_ETHERNET true
31-
//#define USE_BUILTIN_ETHERNET false
30+
//#define USE_BUILTIN_ETHERNET true
31+
#define USE_BUILTIN_ETHERNET false
3232

3333
//#define USE_UIP_ETHERNET true
3434
#define USE_UIP_ETHERNET false
@@ -60,15 +60,9 @@
6060
#elif (USE_UIP_ETHERNET)
6161
#warning Using ENC28J60 & UIPEthernet lib
6262
#define SHIELD_TYPE "ENC28J60 & UIPEthernet Library"
63-
#elif USE_ETHERNET_GENERIC
64-
#include "Ethernet_Generic.h"
65-
66-
#define ETHERNET_LARGE_BUFFERS
67-
68-
#define _ETG_LOGLEVEL_ 1
69-
63+
#elif USE_ETHERNET_GENERIC
7064
#warning Using W5x00 & Ethernet_Generic lib
71-
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
65+
//#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
7266
#elif USE_ETHERNET_ESP8266
7367
#include "Ethernet_ESP8266.h"
7468
#warning Using W5x00 & Ethernet_ESP8266 lib
@@ -83,12 +77,65 @@
8377
#warning Using Custom Ethernet library. You must include a library and initialize.
8478
#define SHIELD_TYPE "Custom Ethernet & Ethernet_XYZ Library"
8579
#else
86-
#define USE_ETHERNET_GENERIC true
87-
#include "Ethernet_Generic.h"
80+
#define USE_ETHERNET_GENERIC true
8881
#warning Using default Ethernet_Generic lib
89-
#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
82+
//#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
83+
#endif
84+
85+
//////////////////////////////////////////////////////////////////////////
86+
87+
#if USE_ETHERNET_GENERIC
88+
89+
#include <SPI.h>
90+
91+
// Be sure to use true only if necessary for your board, or compile error
92+
#define USING_CUSTOM_SPI true
93+
94+
#if ( USING_CUSTOM_SPI )
95+
// Currently test OK for F767ZI and L552ZE_Q
96+
#define USING_SPI2 true
97+
98+
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library and custom SPI"
99+
100+
#if (USING_SPI2)
101+
// For L552ZE-Q, F767ZI, but you can change the pins for any other boards
102+
// SCK: 23, MOSI: 22, MISO: 25, SS/CS: 24 for SPI1
103+
#define CUR_PIN_MISO 25
104+
#define CUR_PIN_MOSI 22
105+
#define CUR_PIN_SCK 23
106+
#define CUR_PIN_SS 24
107+
108+
#define SPI_NEW_INITIALIZED true
109+
110+
// Don't create the instance with CUR_PIN_SS, or Ethernet not working
111+
// To change for other boards' SPI libraries
112+
SPIClass SPI_New(CUR_PIN_MOSI, CUR_PIN_MISO, CUR_PIN_SCK);
113+
114+
//#warning Using USE_THIS_SS_PIN = CUR_PIN_SS = 24
115+
116+
#if defined(USE_THIS_SS_PIN)
117+
#undef USE_THIS_SS_PIN
118+
#endif
119+
#define USE_THIS_SS_PIN CUR_PIN_SS //24
120+
121+
#endif
122+
123+
#else
124+
125+
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
126+
127+
#endif
128+
129+
#include "Ethernet_Generic.h"
130+
131+
#define ETHERNET_LARGE_BUFFERS
132+
133+
#define _ETG_LOGLEVEL_ 1
134+
90135
#endif
91136

137+
//////////////////////////////////////////////////////////////////////////
138+
92139
#if defined(STM32F0)
93140
#warning STM32F0 board selected
94141
#define BOARD_TYPE "STM32F0"
@@ -116,6 +163,9 @@
116163
#elif defined(STM32L4)
117164
#warning STM32L4 board selected
118165
#define BOARD_TYPE "STM32L4"
166+
#elif defined(STM32L5)
167+
#warning STM32L5 board selected
168+
#define BOARD_TYPE "STM32L5"
119169
#elif defined(STM32H7)
120170
#warning STM32H7 board selected
121171
#define BOARD_TYPE "STM32H7"

examples/AdvancedWebServer/AdvancedWebServer.ino

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Col
7878
</style>\
7979
</head>\
8080
<body>\
81-
<h2>Hi from EthernetWebServer!</h2>\
81+
<h2>Hi from EthernetWebServer_SSL_STM32!</h2>\
8282
<h3>on %s</h3>\
8383
<p>Uptime: %d d %02d:%02d:%02d</p>\
8484
<img src=\"/test.svg\" />\
@@ -164,18 +164,34 @@ void setup()
164164
digitalWrite(led, 0);
165165

166166
Serial.begin(115200);
167-
Serial.println("\nStart AdvancedWebServer on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE));
167+
while (!Serial && millis() < 5000);
168+
169+
Serial.println("\nStart AdvancedWebServer on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE));
170+
171+
#if USE_ETHERNET_GENERIC
172+
Serial.println(ETHERNET_GENERIC_VERSION);
173+
#endif
174+
168175
Serial.println(ETHERNET_WEBSERVER_SSL_STM32_VERSION);
169176

170177
#if !(USE_BUILTIN_ETHERNET)
171-
ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
172-
173-
ET_LOGWARN(F("Default SPI pinout:"));
174-
ET_LOGWARN1(F("MOSI:"), MOSI);
175-
ET_LOGWARN1(F("MISO:"), MISO);
176-
ET_LOGWARN1(F("SCK:"), SCK);
177-
ET_LOGWARN1(F("SS:"), SS);
178-
ET_LOGWARN(F("========================="));
178+
#if (USING_SPI2)
179+
#if defined(CUR_PIN_MISO)
180+
ET_LOGWARN(F("Default SPI pinout:"));
181+
ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
182+
ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
183+
ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
184+
ET_LOGWARN1(F("SS:"), CUR_PIN_SS);
185+
ET_LOGWARN(F("========================="));
186+
#endif
187+
#else
188+
ET_LOGWARN(F("Default SPI pinout:"));
189+
ET_LOGWARN1(F("MOSI:"), MOSI);
190+
ET_LOGWARN1(F("MISO:"), MISO);
191+
ET_LOGWARN1(F("SCK:"), SCK);
192+
ET_LOGWARN1(F("SS:"), SS);
193+
ET_LOGWARN(F("========================="));
194+
#endif
179195
#endif
180196

181197
#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)

examples/AdvancedWebServer/defines.h

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
/****************************************************************************************************************************
22
defines.h
33
4-
For STM32F/L/H/G/WB/MP1 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
5-
6-
EthernetWebServer_SSL_STM32 is a library for STM32 using the Ethernet shields to run WebServer and Client with/without SSL
4+
For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
75
8-
Use SSLClient Library code from https://github.com/OPEnSLab-OSU/SSLClient
9-
10-
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_SSL_STM32
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
1111
***************************************************************************************************************************************/
1212

1313
#ifndef defines_h
1414
#define defines_h
1515

1616
#if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \
1717
defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \
18-
defined(STM32WB) || defined(STM32MP1) )
18+
defined(STM32WB) || defined(STM32MP1) || defined(STM32L5) )
1919
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
2020
#endif
2121

2222
#define DEBUG_ETHERNET_WEBSERVER_PORT Serial
2323

2424
// Debug Level from 0 to 4
25-
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 2
25+
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
2626

2727
// If USE_BUILTIN_ETHERNET == false and USE_UIP_ETHERNET == false =>
2828
// either use W5x00 with EthernetXYZ library
2929
// or ENC28J60 with EthernetENC library
30-
#define USE_BUILTIN_ETHERNET true
31-
//#define USE_BUILTIN_ETHERNET false
30+
//#define USE_BUILTIN_ETHERNET true
31+
#define USE_BUILTIN_ETHERNET false
3232

3333
//#define USE_UIP_ETHERNET true
3434
#define USE_UIP_ETHERNET false
@@ -60,15 +60,9 @@
6060
#elif (USE_UIP_ETHERNET)
6161
#warning Using ENC28J60 & UIPEthernet lib
6262
#define SHIELD_TYPE "ENC28J60 & UIPEthernet Library"
63-
#elif USE_ETHERNET_GENERIC
64-
#include "Ethernet_Generic.h"
65-
66-
#define ETHERNET_LARGE_BUFFERS
67-
68-
#define _ETG_LOGLEVEL_ 1
69-
63+
#elif USE_ETHERNET_GENERIC
7064
#warning Using W5x00 & Ethernet_Generic lib
71-
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
65+
//#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
7266
#elif USE_ETHERNET_ESP8266
7367
#include "Ethernet_ESP8266.h"
7468
#warning Using W5x00 & Ethernet_ESP8266 lib
@@ -83,12 +77,65 @@
8377
#warning Using Custom Ethernet library. You must include a library and initialize.
8478
#define SHIELD_TYPE "Custom Ethernet & Ethernet_XYZ Library"
8579
#else
86-
#define USE_ETHERNET_GENERIC true
87-
#include "Ethernet_Generic.h"
80+
#define USE_ETHERNET_GENERIC true
8881
#warning Using default Ethernet_Generic lib
89-
#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
82+
//#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
83+
#endif
84+
85+
//////////////////////////////////////////////////////////////////////////
86+
87+
#if USE_ETHERNET_GENERIC
88+
89+
#include <SPI.h>
90+
91+
// Be sure to use true only if necessary for your board, or compile error
92+
#define USING_CUSTOM_SPI true
93+
94+
#if ( USING_CUSTOM_SPI )
95+
// Currently test OK for F767ZI and L552ZE_Q
96+
#define USING_SPI2 true
97+
98+
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library and custom SPI"
99+
100+
#if (USING_SPI2)
101+
// For L552ZE-Q, F767ZI, but you can change the pins for any other boards
102+
// SCK: 23, MOSI: 22, MISO: 25, SS/CS: 24 for SPI1
103+
#define CUR_PIN_MISO 25
104+
#define CUR_PIN_MOSI 22
105+
#define CUR_PIN_SCK 23
106+
#define CUR_PIN_SS 24
107+
108+
#define SPI_NEW_INITIALIZED true
109+
110+
// Don't create the instance with CUR_PIN_SS, or Ethernet not working
111+
// To change for other boards' SPI libraries
112+
SPIClass SPI_New(CUR_PIN_MOSI, CUR_PIN_MISO, CUR_PIN_SCK);
113+
114+
//#warning Using USE_THIS_SS_PIN = CUR_PIN_SS = 24
115+
116+
#if defined(USE_THIS_SS_PIN)
117+
#undef USE_THIS_SS_PIN
118+
#endif
119+
#define USE_THIS_SS_PIN CUR_PIN_SS //24
120+
121+
#endif
122+
123+
#else
124+
125+
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
126+
127+
#endif
128+
129+
#include "Ethernet_Generic.h"
130+
131+
#define ETHERNET_LARGE_BUFFERS
132+
133+
#define _ETG_LOGLEVEL_ 1
134+
90135
#endif
91136

137+
//////////////////////////////////////////////////////////////////////////
138+
92139
#if defined(STM32F0)
93140
#warning STM32F0 board selected
94141
#define BOARD_TYPE "STM32F0"
@@ -116,6 +163,9 @@
116163
#elif defined(STM32L4)
117164
#warning STM32L4 board selected
118165
#define BOARD_TYPE "STM32L4"
166+
#elif defined(STM32L5)
167+
#warning STM32L5 board selected
168+
#define BOARD_TYPE "STM32L5"
119169
#elif defined(STM32H7)
120170
#warning STM32H7 board selected
121171
#define BOARD_TYPE "STM32H7"

0 commit comments

Comments
 (0)