13. W5100S/W5500+RP2040 Raspberry Pi Pico<FTP Server>

Article directory

  • 1 Introduction
  • 2. Related introduction
    • 2.1 Brief description
    • 2.2 Principle
    • 2.3 Advantages
    • 2.4 Application
  • 3. WIZnet Ethernet chip
  • 4. FTP Server running test
    • 4.1 Program flow chart
    • 4.2 Test preparation
    • 4.3 Connection method
    • 4.4 Related code
    • 4.5 Test phenomena
  • 5. Precautions
  • 6. Related links

1. Preface

In today’s information age, the Internet has become an indispensable part of people’s lives and work. As an important application on the Internet, FTP server plays an important role in file transfer and sharing. FTP is File Transfer Protocol, which defines a set of standard procedures that allow users to send and receive files on the network. The FTP server is a computer system that provides FTP services. It allows other computers to communicate with the server through the FTP protocol to achieve file upload, download, deletion and other operations.
This chapter will use W5100S/W5500 + Raspberry Pi RP2040 for FTP Server testing.

W5100S/W5500 is an embedded Ethernet controller integrating a full hardware TCP/IP protocol stack. It is also an industrial-grade Ethernet control chip. Using the W5100S/W5500 in Ethernet applications makes it easier for users to connect and communicate remotely between devices.

2. Related introduction

2.1 Brief description

FTP server is a computer system that provides file storage and access services on the Internet. It uses the FTP protocol, which is a protocol specifically used to transfer files, allowing other computers to communicate with the server through the FTP protocol to achieve file upload, download, deletion and other operations.

FTP server usually consists of a server software that supports FTP protocol and one or more computers that provide file services. FTP server software can use different operating systems and configurations, such as Windows, Linux, Unix, etc.

On an FTP server, users can authenticate with an account and password and gain access to files on the server. FTP servers can set different access levels and permissions to protect the security and integrity of files.

FTP servers usually use the TCP protocol to communicate because the TCP protocol can provide reliable data transmission. The FTP protocol has two ports: a data port and a command port (also called a control port). The command port is used to send FTP commands, while the data port is used to transfer file data.

In short, FTP server is a convenient and reliable file transfer method that can be used for file sharing and transfer between individuals and businesses.

2.2 Principle

The FTP protocol is an application layer protocol based on the TCP protocol. FTP uses a client-server model. The FTP server generally runs on ports 20 and 21. One is a data connection, used for data transmission; the other is a control connection, used to transmit control information (commands and responses). This idea of transmitting commands and data separately greatly improves the efficiency of FTP.

FTP data transmission has two connections, namely active mode and passive mode:

? In active mode, the client randomly opens an N port greater than 1024 to initiate a connection to the server’s command port (port 21), and at the same time opens the N + 1 port for listening, and informs the server to let the server connect from its own data port (port 20) Actively connect to the data port N + 1 specified by the client; for the client’s firewall, the data transmission channel is a connection from the outside to the inside and may be blocked;

? In passive mode, the client randomly opens two local ports N and N + 1 larger than 1024. The first port initiates a connection to the server’s command port (port 21). After submitting the PASV command, the server will return information to inform the client. Randomly open a data port P greater than 1024, and then the client uses N + 1 port to connect to the data port P specified by the server; this solves the problem that in active mode, the server may be blocked by the client firewall when it connects to the client to establish a data channel. The problem.

2.3 Advantages

  • Wide network coverage: FTP is completely network-based, with wide coverage and more flexible operation, allowing more people to know and benefit.
  • Perfect user rights management: The FTP server provides an access authorization mechanism based on account and password, which can ensure the security of data, and user rights can also be set to avoid misoperations.
  • High data transmission security: The FTP server can use SSL and SSH2 for security encryption to ensure that data is not illegally intercepted and has high security.
  • Fast data transfer speed: The FTP server supports data resumption and concurrent transmission, which can ensure fast, efficient and barrier-free file sharing between various departments while ensuring data integrity.

2.4 Application

  • File sharing and transfer: The most basic application of FTP server is to realize file sharing and transfer. Users can upload files to the FTP server or download required files from the server, realizing file sharing and transmission.
  • Installation and updates of software and applications: FTP servers can be used for installation and updates of software and applications. Developers can upload updated software or applications to the FTP server, and users can download and install new software or applications by accessing the server.
  • Website maintenance and development: FTP servers can also be used for website maintenance and development. Developers can upload website files through the FTP server to update and maintain the website. At the same time, users can also download website files through the FTP server for website development and construction.
  • Data backup and recovery: FTP server can be used for data backup and recovery. Users can upload important data to the FTP server to prevent data loss. At the same time, if data is damaged or lost, users can also restore it by downloading the backup data from the FTP server.

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 8 bit BUS, SPI 16 KB 4 Max 25 Mbps
W6100 TCP/IPv4/IPv6, MAC & PHY 8 bit BUS, Fast SPI 32 KB 8 Max 25 Mbps
W5500 TCP/IPv4, MAC & PHY Fast SPI 32 KB 8 Max 15 Mbps
  1. W5100S/W6100 supports 8-bit data bus interface, and the network transmission speed will be better than W5500.
  2. W6100 supports IPv6 and is Pin to Pin compatible with W5100S. If users who already use W5100S need to support IPv6, they can directly switch to it.
  3. W5500 has more sockets and send and receive buffers than W5100S

4. FTP Server running test

4.1 Program flow chart

4.2 Test preparation

Software:

  • Visual Studio Code
  • WIZnet UartTool
  • FileZilla

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 GPIO 0 (UART0 TX) <----> USB_TTL_RX
    • RP2040 GPIO 1 (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

? Open the ftp_server.c file (path: examples/ftp_server/ftp_server.c) to see the specific implementation:

? You can see that the network information is configured in dhcp mode. Therefore, after the master control and W5100S are initialized, DHCP initialization will be performed, and then a timer initialization will be added for timing during the dhcp process for timeout processing; then Enter dhcp to configure network information. If successful, it will directly enter the loop to call the loopback test function. If it fails, use the static network information we initialized to configure, then initialize the ftp server and then enter the loop to call the test function to run the ftp server, as shown below:

/* Network information to be configured. */
wiz_NetInfo net_info = {<!-- -->
    .mac = {<!-- -->0x00, 0x08, 0xdc, 0x11, 0x22, 0x33}, // 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
    .dhcp = NETINFO_DHCP}; // Configured dhcp model,NETINFO_DHCP:use dhcp; NETINFO_STATIC: use static ip.

static uint8_t ethernet_buf[ETHERNET_BUF_MAX_SIZE] = {<!-- -->
    0,
}; // Send and receive cachestatic
static uint8_t uart_buf[ETHERNET_BUF_MAX_SIZE] = {<!-- -->
    0,
};
static uint8_t local_ip[4];
static uint8_t breakout_flag = 0; // Define the DHCP acquisition flag

int main()
{<!-- -->
    struct repeating_timer timer; // Define the timer structure
    wiz_NetInfo get_info;
    /* MCU init */
    stdio_init_all(); // Initialize the main control peripheral
    wizchip_initialize(); // Initialize the chip interface

    /*dhcp init*/
    DHCP_init(SOCKET_ID, ethernet_buf); // DHCP initialization
    add_repeating_timer_ms(1000, repeating_timer_callback, NULL, & timer); // Add DHCP 1s Tick Timer handler

    printf("wiznet chip ftp server example.\r\\
");
    network_init( & amp;net_info); // Configuring Network Information
    print_network_information( & amp;get_info); // Read back the configuration information and print it

    getIPfromDHCP(local_ip); // Get the local IP address
    ftpd_init(local_ip);

    while(true)
    {<!-- -->
        ftpd_run(ethernet_buf); // Run FTP Server
    }
}

The ftpd_init initialization function needs to pass in the local IP, and the ftpd_run running function needs to pass in a data transceiver cache. According to the ftp protocol, two sockets need to be run as the command port and the data port, so the initialization needs to open the two socket ports in TCP mode. ,As follows:

void ftpd_init(uint8_t * src_ip)
{<!-- -->
ftp.state = FTPS_NOT_LOGIN;
ftp.current_cmd = NO_CMD;
ftp.dsock_mode = ACTIVE_MODE;

ftp.ID_Enable = STATUS_USED;
ftp.PW_Enable = STATUS_USED;

if(ftp.ID_Enable == STATUS_USED)
{<!-- -->
strcpy(ftp.username, ftp_ID);
printf(" FTP ID[%d]:%s \r\\
", strlen(ftp.username), ftp.username);
}
if(ftp.PW_Enable == STATUS_USED)
{<!-- -->
strcpy(ftp.userpassword, ftp_PW);
printf(" FTP PW[%d]:%s \r\\
", strlen(ftp.userpassword), ftp.userpassword);
}
\t


local_ip.cVal[0] = src_ip[0];
local_ip.cVal[1] = src_ip[1];
local_ip.cVal[2] = src_ip[2];
local_ip.cVal[3] = src_ip[3];
local_port = 35000;
\t
strcpy(ftp.workingdir, "/");

socket(CTRL_SOCK, Sn_MR_TCP, IPPORT_FTP, 0x0);
    socket(CTRL_SOCK1, Sn_MR_TCP, IPPORT_FTP, 0x0);
}

4.5 Test phenomenon

? After the hardware connection is correct, compile the burning program, open WIZ UartTool, select the corresponding COM port, and fill in the parameters: baud rate 115200, 8 data bits, 1 stop bit, no parity bit, no flow control, fill in After completing the parameters, click open to open and observe the information printed by the serial port to obtain the device running status; after opening the FTP Server connection debugging tool filezilla, fill in the host, user name, and password in order according to the information printed by the serial port. If the port is not filled in, the default is 21 ( Port 21 is used to transmit control flow between the FTP client and server, and port 20 is used to transmit data flow). After filling in, click Quick Connect. You can see that after successful login, a list of directories that have been read successfully is listed as follows. As shown in the figure:

5. Notes

  • The number of socket ports of W5100S and W5500 is different. Please pay attention to the port number when using multiple sockets.
  • If we want to use WIZnet’s W5500 to implement the example in this chapter, we only need to modify two places:
  1. Find the header file wizchip_conf.h under library/ioLibrary_Driver/Ethernet/, and change 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.

    6. Related links

    WIZnet official website

    WIZnet official library link

    Routine link in this chapter