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

Commit

Permalink
v1.6.0 to add custom SPI support
Browse files Browse the repository at this point in the history
### 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`
  • Loading branch information
khoih-prog authored May 4, 2022
1 parent f6c7fdf commit 7023147
Show file tree
Hide file tree
Showing 67 changed files with 3,136 additions and 1,019 deletions.
32 changes: 23 additions & 9 deletions examples/AWS_IoT/AWS_IoT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,38 @@ void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial);
while (!Serial && millis() < 5000);

Serial.print("\nStart AWS_IoT on "); Serial.print(BOARD_NAME);
Serial.print(" with "); Serial.println(SHIELD_TYPE);

#if USE_ETHERNET_GENERIC
Serial.println(ETHERNET_GENERIC_VERSION);
#endif

Serial.println(ETHERNET_WEBSERVER_SSL_STM32_VERSION);

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

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

ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), MOSI);
ET_LOGWARN1(F("MISO:"), MISO);
ET_LOGWARN1(F("SCK:"), SCK);
ET_LOGWARN1(F("SS:"), SS);
ET_LOGWARN(F("========================="));
#if (USING_SPI2)
#if defined(CUR_PIN_MISO)
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
ET_LOGWARN1(F("SS:"), CUR_PIN_SS);
ET_LOGWARN(F("========================="));
#endif
#else
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), MOSI);
ET_LOGWARN1(F("MISO:"), MISO);
ET_LOGWARN1(F("SCK:"), SCK);
ET_LOGWARN1(F("SS:"), SS);
ET_LOGWARN(F("========================="));
#endif
#endif

#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
Expand Down
92 changes: 71 additions & 21 deletions examples/AWS_IoT/defines.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
/****************************************************************************************************************************
defines.h
For STM32F/L/H/G/WB/MP1 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
EthernetWebServer_SSL_STM32 is a library for STM32 using the Ethernet shields to run WebServer and Client with/without SSL
For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
Use SSLClient Library code from https://github.com/OPEnSLab-OSU/SSLClient
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_SSL_STM32
EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32
Licensed under MIT license
***************************************************************************************************************************************/

#ifndef defines_h
#define defines_h

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

#define DEBUG_ETHERNET_WEBSERVER_PORT Serial

// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 2
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3

// If USE_BUILTIN_ETHERNET == false and USE_UIP_ETHERNET == false =>
// either use W5x00 with EthernetXYZ library
// or ENC28J60 with EthernetENC library
#define USE_BUILTIN_ETHERNET true
//#define USE_BUILTIN_ETHERNET false
//#define USE_BUILTIN_ETHERNET true
#define USE_BUILTIN_ETHERNET false

//#define USE_UIP_ETHERNET true
#define USE_UIP_ETHERNET false
Expand Down Expand Up @@ -60,15 +60,9 @@
#elif (USE_UIP_ETHERNET)
#warning Using ENC28J60 & UIPEthernet lib
#define SHIELD_TYPE "ENC28J60 & UIPEthernet Library"
#elif USE_ETHERNET_GENERIC
#include "Ethernet_Generic.h"

#define ETHERNET_LARGE_BUFFERS

#define _ETG_LOGLEVEL_ 1

#elif USE_ETHERNET_GENERIC
#warning Using W5x00 & Ethernet_Generic lib
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
//#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
#elif USE_ETHERNET_ESP8266
#include "Ethernet_ESP8266.h"
#warning Using W5x00 & Ethernet_ESP8266 lib
Expand All @@ -83,12 +77,65 @@
#warning Using Custom Ethernet library. You must include a library and initialize.
#define SHIELD_TYPE "Custom Ethernet & Ethernet_XYZ Library"
#else
#define USE_ETHERNET_GENERIC true
#include "Ethernet_Generic.h"
#define USE_ETHERNET_GENERIC true
#warning Using default Ethernet_Generic lib
#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
//#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
#endif

//////////////////////////////////////////////////////////////////////////

#if USE_ETHERNET_GENERIC

#include <SPI.h>

// Be sure to use true only if necessary for your board, or compile error
#define USING_CUSTOM_SPI true

#if ( USING_CUSTOM_SPI )
// Currently test OK for F767ZI and L552ZE_Q
#define USING_SPI2 true

#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library and custom SPI"

#if (USING_SPI2)
// For L552ZE-Q, F767ZI, but you can change the pins for any other boards
// SCK: 23, MOSI: 22, MISO: 25, SS/CS: 24 for SPI1
#define CUR_PIN_MISO 25
#define CUR_PIN_MOSI 22
#define CUR_PIN_SCK 23
#define CUR_PIN_SS 24

#define SPI_NEW_INITIALIZED true

// Don't create the instance with CUR_PIN_SS, or Ethernet not working
// To change for other boards' SPI libraries
SPIClass SPI_New(CUR_PIN_MOSI, CUR_PIN_MISO, CUR_PIN_SCK);

//#warning Using USE_THIS_SS_PIN = CUR_PIN_SS = 24

#if defined(USE_THIS_SS_PIN)
#undef USE_THIS_SS_PIN
#endif
#define USE_THIS_SS_PIN CUR_PIN_SS //24

#endif

#else

#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"

#endif

#include "Ethernet_Generic.h"

#define ETHERNET_LARGE_BUFFERS

#define _ETG_LOGLEVEL_ 1

#endif

//////////////////////////////////////////////////////////////////////////

#if defined(STM32F0)
#warning STM32F0 board selected
#define BOARD_TYPE "STM32F0"
Expand Down Expand Up @@ -116,6 +163,9 @@
#elif defined(STM32L4)
#warning STM32L4 board selected
#define BOARD_TYPE "STM32L4"
#elif defined(STM32L5)
#warning STM32L5 board selected
#define BOARD_TYPE "STM32L5"
#elif defined(STM32H7)
#warning STM32H7 board selected
#define BOARD_TYPE "STM32H7"
Expand Down
36 changes: 26 additions & 10 deletions examples/AdvancedWebServer/AdvancedWebServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Col
</style>\
</head>\
<body>\
<h2>Hi from EthernetWebServer!</h2>\
<h2>Hi from EthernetWebServer_SSL_STM32!</h2>\
<h3>on %s</h3>\
<p>Uptime: %d d %02d:%02d:%02d</p>\
<img src=\"/test.svg\" />\
Expand Down Expand Up @@ -164,18 +164,34 @@ void setup()
digitalWrite(led, 0);

Serial.begin(115200);
Serial.println("\nStart AdvancedWebServer on " + String(BOARD_NAME) + ", using " + String(SHIELD_TYPE));
while (!Serial && millis() < 5000);

Serial.println("\nStart AdvancedWebServer on " + String(BOARD_NAME) + " with " + String(SHIELD_TYPE));

#if USE_ETHERNET_GENERIC
Serial.println(ETHERNET_GENERIC_VERSION);
#endif

Serial.println(ETHERNET_WEBSERVER_SSL_STM32_VERSION);

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

ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), MOSI);
ET_LOGWARN1(F("MISO:"), MISO);
ET_LOGWARN1(F("SCK:"), SCK);
ET_LOGWARN1(F("SS:"), SS);
ET_LOGWARN(F("========================="));
#if (USING_SPI2)
#if defined(CUR_PIN_MISO)
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
ET_LOGWARN1(F("SS:"), CUR_PIN_SS);
ET_LOGWARN(F("========================="));
#endif
#else
ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), MOSI);
ET_LOGWARN1(F("MISO:"), MISO);
ET_LOGWARN1(F("SCK:"), SCK);
ET_LOGWARN1(F("SS:"), SS);
ET_LOGWARN(F("========================="));
#endif
#endif

#if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET)
Expand Down
92 changes: 71 additions & 21 deletions examples/AdvancedWebServer/defines.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
/****************************************************************************************************************************
defines.h
For STM32F/L/H/G/WB/MP1 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
EthernetWebServer_SSL_STM32 is a library for STM32 using the Ethernet shields to run WebServer and Client with/without SSL
For STM32 with built-in Ethernet LAN8742A (Nucleo-144, DISCOVERY, etc) or W5x00/ENC28J60 shield/module
Use SSLClient Library code from https://github.com/OPEnSLab-OSU/SSLClient
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_SSL_STM32
EthernetWebServer_STM32 is a library for the STM32 running Ethernet WebServer
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
Built by Khoi Hoang https://github.com/khoih-prog/EthernetWebServer_STM32
Licensed under MIT license
***************************************************************************************************************************************/

#ifndef defines_h
#define defines_h

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

#define DEBUG_ETHERNET_WEBSERVER_PORT Serial

// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 2
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3

// If USE_BUILTIN_ETHERNET == false and USE_UIP_ETHERNET == false =>
// either use W5x00 with EthernetXYZ library
// or ENC28J60 with EthernetENC library
#define USE_BUILTIN_ETHERNET true
//#define USE_BUILTIN_ETHERNET false
//#define USE_BUILTIN_ETHERNET true
#define USE_BUILTIN_ETHERNET false

//#define USE_UIP_ETHERNET true
#define USE_UIP_ETHERNET false
Expand Down Expand Up @@ -60,15 +60,9 @@
#elif (USE_UIP_ETHERNET)
#warning Using ENC28J60 & UIPEthernet lib
#define SHIELD_TYPE "ENC28J60 & UIPEthernet Library"
#elif USE_ETHERNET_GENERIC
#include "Ethernet_Generic.h"

#define ETHERNET_LARGE_BUFFERS

#define _ETG_LOGLEVEL_ 1

#elif USE_ETHERNET_GENERIC
#warning Using W5x00 & Ethernet_Generic lib
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
//#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
#elif USE_ETHERNET_ESP8266
#include "Ethernet_ESP8266.h"
#warning Using W5x00 & Ethernet_ESP8266 lib
Expand All @@ -83,12 +77,65 @@
#warning Using Custom Ethernet library. You must include a library and initialize.
#define SHIELD_TYPE "Custom Ethernet & Ethernet_XYZ Library"
#else
#define USE_ETHERNET_GENERIC true
#include "Ethernet_Generic.h"
#define USE_ETHERNET_GENERIC true
#warning Using default Ethernet_Generic lib
#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
//#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
#endif

//////////////////////////////////////////////////////////////////////////

#if USE_ETHERNET_GENERIC

#include <SPI.h>

// Be sure to use true only if necessary for your board, or compile error
#define USING_CUSTOM_SPI true

#if ( USING_CUSTOM_SPI )
// Currently test OK for F767ZI and L552ZE_Q
#define USING_SPI2 true

#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library and custom SPI"

#if (USING_SPI2)
// For L552ZE-Q, F767ZI, but you can change the pins for any other boards
// SCK: 23, MOSI: 22, MISO: 25, SS/CS: 24 for SPI1
#define CUR_PIN_MISO 25
#define CUR_PIN_MOSI 22
#define CUR_PIN_SCK 23
#define CUR_PIN_SS 24

#define SPI_NEW_INITIALIZED true

// Don't create the instance with CUR_PIN_SS, or Ethernet not working
// To change for other boards' SPI libraries
SPIClass SPI_New(CUR_PIN_MOSI, CUR_PIN_MISO, CUR_PIN_SCK);

//#warning Using USE_THIS_SS_PIN = CUR_PIN_SS = 24

#if defined(USE_THIS_SS_PIN)
#undef USE_THIS_SS_PIN
#endif
#define USE_THIS_SS_PIN CUR_PIN_SS //24

#endif

#else

#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"

#endif

#include "Ethernet_Generic.h"

#define ETHERNET_LARGE_BUFFERS

#define _ETG_LOGLEVEL_ 1

#endif

//////////////////////////////////////////////////////////////////////////

#if defined(STM32F0)
#warning STM32F0 board selected
#define BOARD_TYPE "STM32F0"
Expand Down Expand Up @@ -116,6 +163,9 @@
#elif defined(STM32L4)
#warning STM32L4 board selected
#define BOARD_TYPE "STM32L4"
#elif defined(STM32L5)
#warning STM32L5 board selected
#define BOARD_TYPE "STM32L5"
#elif defined(STM32H7)
#warning STM32H7 board selected
#define BOARD_TYPE "STM32H7"
Expand Down
Loading

0 comments on commit 7023147

Please sign in to comment.