1. W5100S/W5500+RP2040 Raspberry Pi Pico<Static configuration network information>

Article directory

  • 1 Introduction
  • 2. Related network information
    • 2.1 Introduction
    • 2.2 Advantages
    • 2.3 Application
  • 3. WIZnet Ethernet chip
  • 4. Static IP network setting example explanation and usage
    • 4.1 Program flow chart
    • 4.2 Test preparation
    • 4.3 Connection method
    • 4.4 Related code
    • 4.5 Compile and burn
  • 5. Precautions

1. Preface

Starting from this chapter, we will use WIZnet’s W5100S/W5500 Ethernet chip combined with the PR2040 Raspberry Pi Pico. Through simple explanations and demonstration examples, we will let everyone get started quickly and better apply WIZnet’s products to facilitate rapid development.

2. Related network information

2.1 Introduction

  • MAC address (Media Access Control Address): The MAC address is the unique identification of a network device in the local area network. It is a 48-bit address composed of 6 groups of 2 hexadecimal digits. For example: 00:0A:95:9D:68:16. A MAC address is typically assigned to each network interface card (NIC) by the hardware manufacturer for unique identification within a local area network. MAC addresses are used to define communications at the data link layer and are only valid within the same LAN.
  • IP address (Internet Protocol Address): The IP address is the unique identification of a network device in the global Internet. It consists of four numbers between 0 and 255, and is divided into a network part and a host part. For example: 192.168.1.1. IP addresses are used to define communications at the network layer and can be valid anywhere on the Internet. IP addresses are divided into public IP and private IP. Public IP is unique globally, while private IP is used in the internal network.
  • Subnet Mask: The subnet mask is used to divide the network address and the host address. In IPv4, a subnet mask usually consists of consecutive 1s and 0s, where consecutive 1s represent the network part and consecutive 0s represent the host part. For example, the common subnet mask 255.255.255.0 means that the first three digits are the network part (i.e. 24 bits) and the last digit is the host part (i.e. 8 bits). Subnet masks can be used to determine whether two IP addresses are on the same network.
  • Gateway: A gateway is a device that connects different networks and can transmit data from one network to another. In a LAN, the gateway is usually a router or a switch with routing functionality. For every IP address, there is a default gateway, which is the device through which packets must pass when leaving the current network. When the packet reaches the destination network, the destination network’s device sends the packet back to the original network, through the original network’s gateway and back to the original device.
  • DNS (Domain Name System): DNS is the Domain Name System, which is used to convert easy-to-remember domain names into IP addresses that computers can understand. For example, when you type www.example.com into your browser, DNS will resolve the domain name www.example.com to the corresponding IP address (which may be 192.168.1.1 or other). DNS is typically provided by a DNS server, which can be set up on a public DNS server (such as Google’s 8.8.8.8) or a private DNS server (such as one running on your own network).

2.2 Advantages

  • Convenient remote access: Because the static IP address is fixed, it is very convenient for remote access.
  • Suitable for servers: Static IP addresses are suitable for servers and other scenarios that require stable operation for a long time.
  • Easy to manage: Because static IP addresses are fixed, they are easy to manage and maintain.

2.3 Application

Major servers, remote office, security monitoring, VoIP phones and some occasions where the IP address is fixed and does not need to be changed frequently.

3. WIZnet Ethernet chip

WIZnet mainstream hardware protocol stack Ethernet chip parameter comparison

Model Embedded Core Host I/F TX/RX Buffer HW Socket Network Performance
W5100S TCP/IPv4, MAC & PHY 8bit BUS, SPI 16KB 4 Max 25Mbps
W6100 TCP/IPv4/IPv6, MAC & PHY 8bit BUS, Fast SPI 32KB 8 Max 25Mbps
W5500 TCP/IPv4, MAC & PHY Fast SPI 32KB 8 Max 15Mbps
  • W5100S/W6100 supports 8-bit data bus interface, and the network transmission speed will be better than W5500.
  • W6100 supports IPV6 and is compatible with W5100S hardware. If users who already use W5100S need to support IPv6, they can be Pin to Pin compatible.
  • W5500 has more Sockets and send and receive buffers than W5100S

4. Static IP network setting example explanation and usage

4.1 Program flow chart

4.2 Test preparation

Software:

  • Visual Studio Code
  • WIZnet UartTool

Hardware:

  • W5100SIO module + RP2040 Raspberry Pi Pico development board or WIZnet W5100S-EVB-Pico development board
  • Micro USB interface data cable
  • TTL to USB
  • cable

4.3 Connection method

  • Connect the USB port of the PC through the data cable (mainly used for burning programs, but can also be used as a virtual serial port)
  • Convert TTL serial port to USB and connect the default pin of UART0:
    • RP2040 GPIO0 (UART0 TX) <----> USB_TTL_RX
    • RP2040 GPIO1 (UART0 RX) <----> USB_TTL_TX
  • When using the module to connect RP2040 for wiring
    • RP2040 GPIO 16 <----> W5100S MISO
    • RP2040 GPIO 17 <----> W5100S CS
    • RP2040 GPIO 18 <----> W5100S SCK
    • RP2040 GPIO 19 <----> W5100S MOSI
    • RP2040 GPIO 20 <----> W5100S RST
  • Directly connect to the PC network port through a network cable (or: both the PC and the device are connected to the switch or router LAN port through a network cable)

4.4 related code

We directly open the network_install.c file (path: examples/network_install/network_install.c) to see the specific implementation: first, we use a structure variable to initialize our basic network information, including MAC address, IP address, and subnet mask. , gateway, DNS address; and then declare a structure variable to read back the configuration information and print it out through the serial port, so that we can see through the serial port whether our configuration information is configured successfully.

The main function is carried out according to our flow chart. First, the system is initialized, then our chip is initialized, the configuration information is written, read back and printed out through the serial port, and then the phy link is detected. Note that PHY has been performed when initializing the chip. Detection is done here after configuring the information to ensure that the next test is normal; after the PHY detection abnormality times out, an error will be reported and then it will enter the while loop to block. If it is normal, the PHY working mode will be printed, 10M/100M, half-duplex/ Full duplex, and prompts us to perform the PING command operation, and then enters blocking; the whole is relatively simple, as shown below:

/* Network information to be configured. */
wiz_NetInfo net_info = {<!-- -->
    .mac = {<!-- -->0x00, 0x08, 0xdc, 0x1e, 0xed, 0x2e}, // Configured MAC address
    .ip = {<!-- -->192, 168, 1, 10}, // Configured IP address
    .sn = {<!-- -->255, 255, 255, 0}, // Configured subnet mask
    .gw = {<!-- -->192, 168, 1, 1}, // Configured gateway
    .dns = {<!-- -->8, 8, 8, 8}, // Configured domain address
};

/* This parameter is used to receive the configuration information read back. */
wiz_NetInfo get_info;

int main()
{<!-- -->
    uint8_t link_status;
    wiz_PhyConf phyconf;
    uint32_t count = 0;
    
    stdio_init_all(); // Initialize the main control peripheral
    wizchip_initialize(); // Chip initialization

    printf("wiznet chip network install example.\r\\
");
    wizchip_setnetinfo( & amp;net_info); // Write configuration information
    print_network_information( & amp;get_info); // Read the configuration information and print it
    
    do
    {<!-- -->
        link_status = wizphy_getphylink();
        if (link_status == PHY_LINK_OFF)
        {<!-- -->
            count + + ;
            if (count > 10)
            {<!-- -->
                printf("Link failed of Internal PHY.\r\\
");
                break;
            }
        }
        sleep_ms(500);

    } while (link_status == PHY_LINK_OFF);

    if (link_status == PHY_LINK_ON)
    {<!-- -->
        wizphy_getphyconf( & amp;phyconf);
        printf("Link OK of Internal PHy.\r\\
");
        printf("the %d Mbtis speed of Internal PHYrn.\r\\
", phyconf.speed == PHY_SPEED_100 ? 100 : 10);
        printf("The %s Duplex Mode of the Internal PHy.\r\\
", phyconf.duplex == PHY_DUPLEX_HALF ? "Half-Duplex" : "Full-Duplex");

        printf("\r\\
Try ping the ip:%d.%d.%d.%d.\r\\
", get_info.ip[0], get_info.ip[1], get_info .ip[2], get_info.ip[3]);
    }
    else
    {<!-- -->
        printf("\r\\
Please check whether the network cable is loose or disconnected.\r\\
");
    }

    while(true)
    {<!-- -->
    }
}

4.5 Compiling and burning

Compile, generate

  1. Click CMake on the left

  2. Find the corresponding project network_install under examples

  3. Click Generate on the right to start compilation, as shown in the figure below:

Burning

  1. Click the resource manager on the left: After compilation is completed, the .uf2 file will be generated under the corresponding project folder (path: build/examples/network_install) in the examples folder under the build folder. This is the binary we need for burning document

  2. Find the corresponding network_install.uf2 file under the corresponding project file

  3. Right-click and select Show in File Explorer, as shown below:

  1. Next, burn. After the board is connected to the computer with a data cable through the USB interface, press the boot button, then press reset to power on and enter the program burning mode.

  2. Then you can see the USB disk virtualized by the development board. If you do not see the USB disk virtualized, try the first step again.

  3. Then drag the .uf2 file to be burned and copy it to the virtual USB disk to complete the burning, as shown in the figure below:

Phenomena

  1. Open WIZ UartTool, select the corresponding COM port, fill in the parameters: baud rate 115200, 8 data bits, 1 stop bit, no parity bit, no flow control, click open after filling in the parameters.

  2. Press the reset key and you can see the readback printed configuration information, etc.; after we press “Windows + R” and enter “cmd” to open the cmd terminal

  3. Use the PING command based on the information printed on the serial port to PING the IP configured under it. You can see the PING reply with successful PING, as shown below:

5. Notes

  • Static configured IP settings should avoid IP duplication causing IP conflicts.

  • If WIZnet’s W5500 is used to implement the example in this chapter, we only need to modify two places.

  1. Find the wizchip_conf.h header file under library/ioLibrary_Driver/Ethernet/ and modify the WIZCHIP macro definition to W5500;
  2. Find the CMakeLists.txt file under the library and set COMPILE_SEL to ON. OFF is W5100S and ON is W5500.

WIZnet official website

WIZnet official library link

Routine link in this chapter

If you want to know more, leave a comment!