12. W5100S/W5500+RP2040 Raspberry Pi Pico<FTP Client>
12. W5100S/W5500+RP2040 Raspberry Pi Pico<FTP Client>
1 Introduction
Generally speaking, the primary purpose of using the Internet is to share information, and file transfer is a very important part of information sharing. We know that the Internet is a very complex computer environment, and file exchange issues between various devices and operating systems require the establishment of a unified file transfer protocol, which is the FTP protocol.
W5100S/W5500 is an embedded Ethernet controller integrating a full hardware TCP/IP protocol stack. It is also an industrial-grade Ethernet control chip. This tutorial will introduce the basic principles, usage steps, application examples and precautions of W5100S/W5500 Ethernet FTP application to help readers better master this technology.
2 Introduction
2.1 What is FTP?
FTP is a protocol used to control the two-way transfer of files over the Internet. It specifies how to transfer files on the Internet and can be used for uploading and downloading server program files. Simply put, FTP is a tool that allows users to transfer files on the Internet.
2.2 Advantages of FTP
High file transfer efficiency: The FTP protocol uses binary mode to transfer files and directly transfers binary data. Compared with other transfer protocols, it has a higher transfer speed.
Supports multiple platforms: FTP is a cross-platform application and supports operating systems such as Windows and Linux.
Good security: FTP supports encrypted transmission mode, which can effectively ensure the security of file transmission. In addition, the FTP protocol can control file access permissions and ensure file security.
Easy to use: FTP has a simple and intuitive graphical user interface, which is easy to use and convenient to operate.
Support large file transfer: FTP supports large file transfer and can handle the upload and download of large files.
Completely based on the network: FTP is completely based on the network and has network file upload and download features, such as support for resumed uploads, and is not restricted by work groups and IP addresses.
Has a complete user rights management system: FTP has a complete user rights management system. Compared with network sharing, each user's permissions can be set in detail, such as only uploading, not modification or deletion, etc.
2.3 Client mode
2.4 Process of transferring files using FTP protocol
Client connects to server
The client can choose to GET files on the server or PUSH files to the server.
2.4 FTP application scenarios
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 ARP network setting example overview and usage
4.1 Flowchart
The running block diagram of the program is as follows:
4.2 Core preparation work
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 wiring using module connection RP2040
RP2040 GPIO16 <----> W5100S MISO
RP2040 GPIO17 <----> W5100S CS
RP2040 GPIO18 <----> W5100S SCK
RP2040 GPIO19 <----> W5100S MOSI
RP2040 GPIO20 <----> W5100S RST
Connect the PC and device to the router LAN port through network cables
4.4 Main code overview
We are using the official ioLibrary_Driver library of WIZnet. The library supports rich protocols and is easy to operate. The chip integrates the TCP/IP protocol stack on the hardware. The library also encapsulates the protocols above the TCP/IP layer. We only need to simply call the corresponding function to complete the application of the protocol. .
Step 1: Reference the corresponding library file in the ftp_client.c file.
Step 2: Define the macros required for DHCP configuration.
Step 3: Define network address information.
Step 4: Write a timer callback function to handle DHCP timeout information.
Step 5: The main function first initializes the serial port and SPI and detects the link. Then set the network address of W5100S. First use DHCP to obtain it. If it fails, use the preset static IP address, and then enter the initialization of the FTP client. After the initialization is completed, the FTP client will run.
// Use dhcp
// Use socket
// Use ftp
// Socket number
// Send and receive cache size
// DHCP retry times
/* 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
.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 uint8_t destip[4]={192, 168, 1, 2}; // udp destination ip
static uint8_t uart_buf[ETHERNET_BUF_MAX_SIZE] = {
0,
};
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_client 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
ftpc_init(local_ip); // Initialize FTP Client
while (true)
{
ftpc_run(ethernet_buf); // Run FTP Client
}
}
4.5 Results demonstration
5 Precautions
The socket number must be socket0 and make it work in MACRAM mode.
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 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 library and set COMPILE_SEL to ON. OFF is W5100S and ON is W5500.