当前位置:网站首页>RT thread -- FTP of LwIP (2)

RT thread -- FTP of LwIP (2)

2022-07-06 03:32:00 rou252051452

RT-Thread--Lwip And FTP_rou252051452 The blog of -CSDN Blog This description is based on RTT Based on the completion of network communication function , See another tutorial for specific network implementation .https://blog.csdn.net/rou252051452/article/details/123084492https://blog.csdn.net/rou252051452/article/details/1230844921、 Package enable open RT-ThreadSetting Install the software package , Save effective documents 2、FTP Function initialization The main function contains ...https://blog.csdn.net/rou252051452/article/details/123086671        In the previous document FTP Enable and connect , But there is no file system in the development board , No catalog for FTP Visit , So in this chapter, we discuss the file system (spi flash) The implementation of the .

1、 Hardware enable

        According to the schematic configuration of punctual atoms SPIflash The configuration is as follows :

 2、RT-Thread Setting Set up

  3、board.h File settings

        increase #define BSP_USING_SPI5 Macro definition

  4、 mount SPI  flash

        newly build drivers\drv_spiflash.c file , The contents are as follows

#include "board.h"
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_spi.h"
#include "drv_config.h"
#include <string.h>
#include "spi_flash_sfud.h"

static int rt_hw_spi_flash_init(void)
{
    __HAL_RCC_GPIOF_CLK_ENABLE();
    rt_hw_spi_device_attach("spi5", "spi50", GPIOF, GPIO_PIN_6);

    if (RT_NULL == rt_sfud_flash_probe("W25Q256", "spi50"))
    {
        return -RT_ERROR;
    };
    return RT_EOK;
}
/*  Export to automatic initialization  */
INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);

Compile and download , The serial port output is as follows

   5、 File system mount

        stay main.c The following functions are implemented in the file flash Mount the file system , The main function calls this function .

static int dfs_mount_init(void)
{
    if(dfs_mount("W25Q256", "/", "elm", 0, 0) == 0)
    {
        rt_kprintf("dfs mount success\r\n");
        return RT_EOK;
    }
    else
    {
        rt_kprintf("spi file system initialized faile\r\n");
        if(dfs_mkfs("elm", "W25Q256") == 0)
        {
            rt_kprintf("W25QXX file system initialized\r\n");
            if(dfs_mount("W25Q256", "/", "elm", 0, 0) == 0)
            {
                rt_kprintf("dfs mount success\r\n");
                return RT_EOK;
            }
            else
            {
                rt_kprintf("dfs mount success\r\n");
                return -RT_ERROR;
            }
        }
        else
        {
            rt_kprintf("dfs mount success\r\n");
            return -RT_ERROR;
        }
    }
}

        Download validation , The serial port output is as follows

    6、 Modification of the mount directory

        The above mounting process will flash Directly mounted to the root directory , If there are multiple mounted devices, we cannot distinguish . Therefore, you can mount different directories under the root directory through the following operations .

        modify rt-thread\components\def\filesystems\romfs\romfs.c The documents are as follows , We added sdcard and w25qxx Two directories .

#include <rtthread.h>
#include <dfs_romfs.h>
#include "dfs.h"

static const struct romfs_dirent _romfs_root[] =
{
    {ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0},
    {ROMFS_DIRENT_DIR, "w25qxx", RT_NULL, 0}
};

const struct romfs_dirent romfs_root =
{
    ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root)/sizeof(_romfs_root[0])
};


int mnt_init(void)
{
   if(dfs_mount (RT_NULL,"/","rom",0,&(romfs_root)) == 0)
   {
       rt_kprintf("ROM file system initializated;\n");
   }
   else
   {
        rt_kprintf("ROM file system initializate failed;\n");
   }
   return 0;
}
INIT_ENV_EXPORT(mnt_init);




        Synchronous to main.c Medium dfs_mount_init Make changes

        

static int dfs_mount_init(void)
{
    if(dfs_mount("W25Q256", "/w25qxx", "elm", 0, 0) == 0)
    {
        rt_kprintf("dfs mount success\r\n");
        return RT_EOK;
    }
    else
    {
        rt_kprintf("spi file system initialized faile\r\n");
        if(dfs_mkfs("elm", "W25Q256") == 0)
        {
            rt_kprintf("W25QXX file system initialized\r\n");
            if(dfs_mount("W25Q256", "/w25qxx", "elm", 0, 0) == 0)
            {
                rt_kprintf("dfs mount success\r\n");
                return RT_EOK;
            }
            else
            {
                rt_kprintf("dfs mount success\r\n");
                return -RT_ERROR;
            }
        }
        else
        {
            rt_kprintf("dfs mount success\r\n");
            return -RT_ERROR;
        }
    }
}

Download validation , The serial port is as follows

FTP View the information as follows :

原网站

版权声明
本文为[rou252051452]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060319452366.html