That library has been ported from the official Arduino Ethernet library.
As additional reference served the lib from Vassilis Serasidis: https://github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/STM32F1/libraries/Ethernet_STM
This library runs only on the STM32F1 and F4 family micro-controllers, in conjunction with these cores:
The library supports only W5500 Ethernet controllers, and uses 8 sockets.
This library was tested on a W5500-based module like: https://www.aliexpress.com/item/Free-shipping-W5500-Ethernet-network-module-hardware-TCP-IP-51-STM32-microcontroller-program-over-W5100/32505484781.html?spm=a2g0s.9042311.0.0.pWrBlQ
- Unzip the file Ethernet_STM32-master.zip into your Arduino IDE libraries directory
arduino/libraries
and rename the folder Ethernet_STM32-master to Ethernet_STM32
- Including this library in your sketch
#include <Ethernet_STM32.h>
#include <SPI.h>
- The library needs to know the SPI port on which you connected the W5500 chip, and the corresponding chip select pin. Therefore you have to declare an SPI class object with appropriate SPI port number (1..2 for F1, 1..3 for F4)
SPIClass mSpi(1); // you can use 1..2 for F1, 1..3 for F4)
- Then you need to call the following function in setup() before Ethernet.begin():
Ethernet.init(mSpi, PA4); // SPI class object, chip select pin on your choice
This will start the SPI transaction at maximum supported speed (36MHz on SPI1 for F1, 42MHz for F4).
-
The rest of functions / commands have the same syntax with the stock Arduino Ethernet library.
-
Here a typical example:
#include <Ethernet_STM32.h>
#include <SPI.h>
...
SPIClass mSpi(1); // you can use 1..2 for STM32F1, 1..3 for STM32F4)
...
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(112500);
while (!Serial) ; // wait for serial port to connect. Needed for native USB port only
delay(1000);
// init interface and hardware using SPI class object and chip select pin on your choice
Ethernet.init(mSpi, PA4); // alternatively it is possible use the default SPI object
// start the Ethernet connection:
Serial.println("Initialize Ethernet with DHCP:");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip, myDns);
} else {
Serial.print(" DHCP assigned IP ");
Serial.println(Ethernet.localIP());
}
}
...
void loop()
{
// do something
...
}