当前位置:网站首页>RT-Thread--Lwip之FTP(2)
RT-Thread--Lwip之FTP(2)
2022-07-06 03:20:00 【rou252051452】
RT-Thread--Lwip之FTP_rou252051452的博客-CSDN博客本说明基于在RTT下搭建完成网络通信功能基础上完成,具体网络实现参见另外一个教程。https://blog.csdn.net/rou252051452/article/details/123084492https://blog.csdn.net/rou252051452/article/details/1230844921、软件包使能 打开RT-ThreadSetting进行软件包安装,保存生效文件2、FTP功能的初始化 主函数通过包含...https://blog.csdn.net/rou252051452/article/details/123086671 上一个文档中完成了FTP的使能及连接,但是开发板中无文件系统,无目录供FTP进行访问,所以我们本章进行文件系统(spi flash)的实现。
1、硬件使能
根据正点原子的原理图配置进行SPIflash的配置如下:

2、RT-Thread Setting设置


3、board.h文件设置
增加#define BSP_USING_SPI5宏定义
4、挂载SPI flash
新建drivers\drv_spiflash.c文件,内容如下
#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;
}
/* 导出到自动初始化 */
INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);
编译下载,串口输出如下

5、文件系统挂载
在main.c文件中实现如下函数进行flash下文件系统的挂载,主函数调用该函数。
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;
}
}
}下载验证,串口输出如下

6、挂载目录的修改
上述挂载过程将flash直接挂载到了根目录,若存在多个挂载设备我们无法进行区分。所以通过下操作来实现根目录下不同目录的挂载。
修改rt-thread\components\def\filesystems\romfs\romfs.c文件如下,我们在根目录下增加了sdcard和w25qxx两个目录。
#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);
同步对main.c中的dfs_mount_init进行修改
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;
}
}
}下载验证,串口如下

FTP查看信息如下:

边栏推荐
- Leetcode problem solving -- 108 Convert an ordered array into a binary search tree
- Pytorch基础——(2)张量(tensor)的数学运算
- 【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板
- Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
- Introduction to DeNO
- February 14, 2022 Daily: Google long article summarizes the experience of building four generations of TPU
- 数据分析——seaborn可视化(笔记自用)
- [risc-v] external interrupt
- Leetcode problem solving -- 99 Restore binary search tree
- My C language learning record (blue bridge) -- under the pointer
猜你喜欢

Who is the winner of PTA

【SLAM】ORB-SLAM3解析——跟踪Track()(3)

Computer graduation project asp Net fitness management system VS development SQLSERVER database web structure c programming computer web page source code project

蓝色样式商城网站页脚代码

ESBuild & SWC浅谈: 新一代构建工具

EDCircles: A real-time circle detector with a false detection control 翻译

Record the process of reverse task manager

pytorch加载数据

教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )

NR modulation 1
随机推荐
The next industry outlet: NFT digital collection, is it an opportunity or a foam?
【SLAM】lidar-camera外参标定(港大MarsLab)无需二维码标定板
Quartz misfire missed and compensated execution
SD card reports an error "error -110 whilst initializing SD card
1、工程新建
How to write compile scripts compatible with arm and x86 (Makefile, cmakelists.txt, shell script)
jsscript
EDCircles: A real-time circle detector with a false detection control 翻译
JS音乐在线播放插件vsPlayAudio.js
Pytorch基础——(1)张量(tensor)的初始化
适合程序员学习的国外网站推荐
Audio-AudioRecord Binder通信机制
教你用Pytorch搭建一个自己的简单的BP神经网络( 以iris数据集为例 )
ESBuild & SWC浅谈: 新一代构建工具
Custom attribute access__ getattribute__/ Settings__ setattr__/ Delete__ delattr__ method
MySQL Server层四个日志
The real machine cannot access the shooting range of the virtual machine, and the real machine cannot Ping the virtual machine
【SLAM】ORB-SLAM3解析——跟踪Track()(3)
施努卡:3d视觉检测应用行业 机器视觉3d检测
What are the principles of software design (OCP)