Wiznet makers

ronpang

Published November 27, 2023 ©

125 UCC

10 WCC

32 VAR

0 Contests

1 Followers

0 Following

Original Link

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

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

COMPONENTS Hardware components

WIZnet - W5500-EVB-Pico

x 1


WIZnet - W5100S-EVB-Pico

x 1


PROJECT DESCRIPTION

1 Introduction

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

An 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 through accounts and passwords 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 Theory

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.

There are two connections for FTP data transmission, namely active mode and passive mode:

In active mode, the client randomly opens an N port larger than 1024 to initiate a connection to the server's command port (port 21). At the same time, it opens the N+1 port for listening, and informs the server to allow the server to actively connect from its own data port (port 20). 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 of its own 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. question.

2.3 Advantages

Wide network coverage: FTP is completely based on the network, 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 number 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 breakpoint 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.

Software and application installation and updates: FTP servers can be used for software and application installation and updates. 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

ModelEmbedded CoreHost I/FTX/RX BufferHW SocketNetwork Performance
W5100STCP/IPv4, MAC & PHY8 bit BUS, SPI16 KB4Max 25 Mbps
W6100TCP/IPv4/IPv6, MAC & PHY8 bit BUS, Fast SPI32 KB8Max 25 Mbps
W5500TCP/IPv4, MAC & PHYFast SPI32 KB8Max 15 Mbps

W5100S/W6100 supports 8-bit data bus interface, and the network transmission speed will be better than W5500.

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.

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 configures the network information. If it succeeds, it will directly enter the loop to call the loopback test function. If it fails, it will use the static network information we initialized to configure, and 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\n");
   network_init(&net_info);              // Configuring Network Information
   print_network_information(&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 Shown:

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\n", strlen(ftp.username), ftp.username);
}
if(ftp.PW_Enable == STATUS_USED)
{
strcpy(ftp.userpassword, ftp_PW);
printf(" FTP PW[%d]:%s \r\n", strlen(ftp.userpassword), ftp.userpassword);
}



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;

strcpy(ftp.workingdir, "/");

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

4.5 Test phenomena

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, complete After 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 (21 The port is used to transmit control flow between the FTP client and the server, and port 20 is for transmitting data flow). After filling in, click Quick Connect. You can see that after successful login, a list of directories that have been successfully read is listed, as shown below. Shown:

5. Precautions

The number of socket ports on 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:

Find the wizchip_conf.h header file under library/ioLibrary_Driver/Ethernet/ and modify the WIZCHIP macro definition to W5500.

Find the CMakeLists.txt file under the library and set COMPILE_SEL to ON. OFF is W5100S and ON is W5500.

Documents
  • Code for this article

  • WIZnet Official Website

  • WIZnet Official IO library

  • YouTube Demo

Comments Write