Skip to content

stevstrong/Ethernet_STM32

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

W5500 Ethernet library for STM32F1 and STM32F4 micro-controllers

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

https://ae01.alicdn.com/kf/HTB1_UFSKXXXXXXIXFXXq6xXFXXXd/W5500-Ethernet-network-module-hardware-TCP-IP-51-STM32-microcontroller-program-over-W5100.jpg

Library installation

  • 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

Using the Ethernet_STM32 library

  1. Including this library in your sketch
#include <Ethernet_STM32.h>
#include <SPI.h>
  1. 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)

  1. 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).

  1. The rest of functions / commands have the same syntax with the stock Arduino Ethernet library.

  2. 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
  ...
}

About

Ethernet library for STM32F1 and F4 based on W5500

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published