This repository contains a library for interfacing with the WIZnet W5500 Ethernet controller using an STM32 microcontroller. The library includes functions for SPI initialization, PHY status checking, and retrieving the current network configuration.
To use this library in your STM32 project, follow the steps below:
- w5500 module:
You can change
3.3V 3.3 GND GND MISO PA6 RST PA0 MOSI PA7 SCS PA1 SCLK PA5
RST
andSCS
pins via the header file w5500_spi.h.
Copy w5500
directory to the Core/Src/ .
Initialize the W5500 by calling the initialization function defined in w5500_spi.h
.
#include "w5500_spi.h"
// Call this function to initialize the W5500
w5500_init();
main.c file contains an example on how to use the library.
This project can be used as a ready-to-use template.
void w5500_init()
- Description: Initializes the W5500 module.
- Details: This function sets up the necessary SPI configuration and initializes the W5500 hardware for communication.
-
void check_cable_presence()
- Description: Checks if the Ethernet cable is connected.
- Details: Verifies the physical presence of the Ethernet cable and returns the status.
-
void check_phy_status()
- Description: Checks the PHY status of the W5500.
- Details: Retrieves and prints the current PHY status, including link status, speed, and duplex mode.
-
void print_current_host_configuration()
- Description: Prints the current network configuration of the host.
- Details: Retrieves and displays the MAC address, IP address, subnet mask, gateway, and DNS server currently configured on the W5500.
-
void static_host_configuration(uint8_t mac[6], uint8_t ip[4], uint8_t sn[4], uint8_t gw[4], uint8_t dns[4])
- Description: Configures the W5500 with a static IP address.
- Details: Sets up the network parameters including MAC address, IP address, subnet mask, gateway, and DNS server for a static network configuration.
-
void dynamic_host_configuration(uint8_t mac[6])
- Description: Configures the W5500 using DHCP for dynamic IP assignment.
- Details: Sets up the MAC address and initiates the DHCP process to obtain an IP address, subnet mask, gateway, and DNS server from a DHCP server.
- If you are configuring with cubeMX, remember adding the below line of code to the
MX_SPI1_Init()
function__HAL_SPI_ENABLE(&hspi1);
- Remember to include
dhcp.h
header tostm32fxxxx.c
file and add the below code toSysTick_Handler()
function:static uint16_t ticks = 0; ticks++; if(ticks == 1000) { DHCP_time_handler(); ticks = 0; }
- Modify includes for your microcontroller in below files:
- w5500_phy.c
- w5500_spi.c
This project is licensed under the MIT License. See the LICENSE file for details.