1. Install FTP_Server_W6100 on Github
https://github.com/TeddyWiz/FTP_Server_W6100.git
2. open STM32CubeIDE
3. set hardware
- NUCLEO-F401RE, W6100 Ethernet Shield, SD card
4. set peripheral
- ADD SPI
- ADD FatFs
5. Environment
- Set Include files
6. Code
- Include header
#include "wizchip_conf.h"
#include "W6100.h"
#include <stdio.h>
#include <string.h>
#include "ftpd.h"
#include "Application.h"
#include "wizchip_init.h"
#include "ff_func.h"
- User Global Variables
wiz_NetInfo gWIZNETINFO = { .mac = {0x00,0x08,0xdc,0xff,0xff,0xff},
.ip = {192,168,50,125},
.sn = {255, 255, 255, 0},
.gw = {192, 168, 0, 1},
.dns = {168, 126, 63, 1},
.lla = {0xfe,0x80, 0x00,0x00,
0x00,0x00, 0x00,0x00,
0x02,0x08, 0xdc,0xff,
0xfe,0xff, 0xff,0xff},
.gua={0x20,0x01,0x02,0xb8,
0x00,0x10,0x00,0x01,
0x02,0x08,0xdc,0xff,
0xfe,0xff,0xff,0xff},
.sn6={0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,
0x00,0x00,0x00, 0x00,
0x00,0x00,0x00,0x00},
.gw6={0xfe, 0x80, 0x00,0x00,
0x00,0x00,0x00,0x00,
0x02,0x00, 0x87,0xff,
0xfe,0x08, 0x4c,0x81}
};
uint8_t WIZ_Dest_IP[4] = {192, 168, 50, 59}; //DST_IP Address
uint8_t DestIP6_L[16] = {0xfe,0x80, 0x00,0x00,
0x00,0x00, 0x00,0x00,
0x31,0x71,0x98,0x05,
0x70,0x24,0x4b,0xb1
};
uint8_t DestIP6_G[16] = {0x20,0x01,0x02,0xb8,
0x00,0x10,0x00,0x01,
0x31,0x71,0x98,0x05,
0x70,0x24,0x4b,0xb1
};
uint8_t Router_IP[16]= {0xff,0x02,0x00,0x00,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x02
};
uint8_t data_buf[2048];
uint8_t gFTPBUF[_FTP_MAX_MSG_SIZE_];
- User Function(SD Card, Network Info)
void print_network_information(void)
{
wizchip_getnetinfo(&gWIZNETINFO);
printf("Mac address: %02x:%02x:%02x:%02x:%02x:%02x\n\r",gWIZNETINFO.mac[0],gWIZNET INFO.mac[1],gWIZNETINFO.mac[2],gWIZNETINFO.mac[3],gWIZNETINFO.mac[4],gWIZNETINFO.mac[5]);
printf("IP address : %d.%d.%d.%d\n\r",gWIZNETINFO.ip[0],gWIZNETINFO.ip[1],gWIZNETINFO.ip[2],gWIZNETINFO.ip[3]);
printf("SN Mask : %d.%d.%d.%d\n\r",gWIZNETINFO.sn[0],gWIZNETINFO.sn[1],gWIZNETINFO.sn[2],gWIZNETINFO.sn[3]);
printf("Gate way : %d.%d.%d.%d\n\r",gWIZNETINFO.gw[0],gWIZNETINFO.gw[1],gWIZNETINFO.gw[2],gWIZNETINFO.gw[3]);
printf("DNS Server : %d.%d.%d.%d\n\r",gWIZNETINFO.dns[0],gWIZNETINFO.dns[1],gWIZNETINFO.dns[2],gWIZNETINFO.dns[3]);
printf("LLA : %.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X\r\n",gWIZNETINFO.lla[0],gWIZNETINFO.lla[1],gWIZNETINFO.lla[2],gWIZNETINFO.lla[3],\
gWIZNETINFO.lla[4],gWIZNETINFO.lla[5],gWIZNETINFO.lla[6],gWIZNETINFO.lla[7],\
gWIZNETINFO.lla[8],gWIZNETINFO.lla[9],gWIZNETINFO.lla[10],gWIZNETINFO.lla[11],\
gWIZNETINFO.lla[12],gWIZNETINFO.lla[13],gWIZNETINFO.lla[14],gWIZNETINFO.lla[15]);
printf("GUA : %.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X\n\r",gWIZNETINFO.gua[0],gWIZNETINFO.gua[1],gWIZNETINFO.gua[2],gWIZNETINFO.gua[3],\
gWIZNETINFO.gua[4],gWIZNETINFO.gua[5],gWIZNETINFO.gua[6],gWIZNETINFO.gua[7],\
gWIZNETINFO.gua[8],gWIZNETINFO.gua[9],gWIZNETINFO.gua[10],gWIZNETINFO.gua[11],\
gWIZNETINFO.gua[12],gWIZNETINFO.gua[13],gWIZNETINFO.gua[14],gWIZNETINFO.gua[15]);
printf("SN6 : %.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X\n\r",gWIZNETINFO.sn6[0],gWIZNETINFO.sn6[1],gWIZNETINFO.sn6[2],gWIZNETINFO.sn6[3],\
gWIZNETINFO.sn6[4],gWIZNETINFO.sn6[5],gWIZNETINFO.sn6[6],gWIZNETINFO.sn6[7],\
gWIZNETINFO.sn6[8],gWIZNETINFO.sn6[9],gWIZNETINFO.sn6[10],gWIZNETINFO.sn6[11],\
gWIZNETINFO.sn6[12],gWIZNETINFO.sn6[13],gWIZNETINFO.sn6[14],gWIZNETINFO.sn6[15]);
printf("GW6 : %.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X:%.2X%.2X\r\n",gWIZNETINFO.gw6[0],gWIZNETINFO.gw6[1],gWIZNETINFO.gw6[2],gWIZNETINFO.gw6[3],\
gWIZNETINFO.gw6[4],gWIZNETINFO.gw6[5],gWIZNETINFO.gw6[6],gWIZNETINFO.gw6[7],\
gWIZNETINFO.gw6[8],gWIZNETINFO.gw6[9],gWIZNETINFO.gw6[10],gWIZNETINFO.gw6[11],\
gWIZNETINFO.gw6[12],gWIZNETINFO.gw6[13],gWIZNETINFO.gw6[14],gWIZNETINFO.gw6[15]);
}
int sdCard_Init(void)
{
FATFS fs;
FATFS *pfs;
FIL fil;
FRESULT fres;
DSTATUS res;
DWORD fre_clust;
uint32_t totalSpace, freeSpace, blocks;
/* Wait for SD module reset */
HAL_Delay(500);
if((res =disk_initialize((BYTE) 0)) != RES_OK)
{
printf("disk_init Error[%d]\r\n", res);
}
/* Mount SD Card */
printf(" mount \r\n");
if((fres = f_mount(&fs, "", 0)) != FR_OK)
{
printf("mount Error[%d]!\r\n", fres);
return -1;
}
/* Check freeSpace space */
#if 1
printf(" Check freeSpace space \r\n");
if((fres = f_getfree("", &fre_clust, &pfs)) != FR_OK)
{
printf("get free Error[%d]!\r\n", fres);
return -3;
}
#endif
totalSpace = (uint32_t)((pfs->n_fatent - 2) * pfs->csize * 0.5);
freeSpace = (uint32_t)(fre_clust * pfs->csize * 0.5);
/* free space is less than 1kb */
if(freeSpace < 1)
{
printf("freeSpace Error[%ld]!\r\n", freeSpace);
return -4;
}
printf("toral : %ld , free : %ld \r\n", totalSpace, freeSpace);
}
- Local Variables
uint8_t syslock = SYS_NET_LOCK;
FATFS fs;
FRESULT fres;
DSTATUS res;
- main Function
AL_UART_Receive_IT(&huart2, rxData, 1);
printf("< W6100EVB Hal Driver FTP TEST!! >\r\n");
HAL_GPIO_WritePin(W6100_CS_PORT, W6100_CS_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
#if 1
W6100Initialze();
ctlwizchip(CW_SYS_UNLOCK,& syslock);
ctlnetwork(CN_SET_NETINFO,&gWIZNETINFO);
printf("VERSION(%x) = %.2x \r\n", _VER_,getVER());
print_network_information();
#endif
ftpd_init("user10", "pass10", 21);
sdCard_Init();
scan_files("/", scan_file_buf, &temp_len);
printf("buf[%d]:%s[end]\r\n", temp_len, scan_file_buf);
while (1)
{
ftpd_run(gFTPBUF);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
7. Program Download
8. Program log
9. FTP Client
files upload, download
Comments