当前位置: 首页 > news >正文

哈尔滨公司网站建设多少钱网络营销的概念与特点

哈尔滨公司网站建设多少钱,网络营销的概念与特点,人才网站查询档案,网站建设资讯版块如何做用户运营021 - STM32学习笔记 - Fatfs文件系统(三) - 细化与总结 上节内容中,初步实现了FatFs文件系统的移植,并且实现了设备的挂载、文件打开/关闭与读写功能,这里对上节遗留的一些问题进行总结,并且继续完善文件…

021 - STM32学习笔记 - Fatfs文件系统(三) - 细化与总结

上节内容中,初步实现了FatFs文件系统的移植,并且实现了设备的挂载、文件打开/关闭与读写功能,这里对上节遗留的一些问题进行总结,并且继续完善文件系统的一些操作。

一、问题汇总

1、文件名过长

上节例程中,文件名为3:1.txt,文件打开、读写都没有问题,后来更改了一下文件名为3:TestDomefile.txt后,文件不能正常打开。

在这里插入图片描述

这里需要在ffconf.h中将长文件名支持设置为1

#define	_USE_LFN	1					//0:默认设置,不支持长文件名;1:支持长文件名,最长可支持到255个字符。
#define	_MAX_LFN	255

关于长文件名设置,可选的设置参数有0-3四种模式

模式说明
0默认模式,不支持长文件名
1模式1,支持长文件名,工作空间存储在BSS(段)中
2模式2,支持长文件名,工作空间存储在栈中
3模式3,支持长文件名,工作空间存储在堆中

这里设置完成后,编译会报如下错误:

.\Objects\YH-429.axf: Error: L6218E: Undefined symbol ff_convert (referred from ff.o).
.\Objects\YH-429.axf: Error: L6218E: Undefined symbol ff_wtoupper (referred from ff.o).

启用长文件支持后,会包含一些操作,这些函数是定义在ccsbsc.c中,这里只需要将ccsbsc.c文件加入工程中即可。

2、无FAT文件系统

当挂载文件系统的时候,可能会出现f_mount之后返回FR_NO_FILESYSTEM(13)的情况,这种大概率是FLASH没有格式话造成的,当出现这个情况的时候,就需要堆FLASH进行格式化。具体操作如下:

res = f_mount(&flash_fs,"3:",1);				//挂载FLASH,卷标为3,立即挂载
if(res == FR_NO_FILESYSTEM)						//若返回值为无FAT文件系统,则进行格式化{res = f_mkfs("3:",0,0);					//执行格式化操作,卷标为3,分区规则为0:FDISK,分配单元大小默认为0printf("\r\n磁盘正在格式化中,请稍等.....\r\n");if(res == FR_OK){printf("\r\n磁盘格式化完成...\r\n");f_mount(NULL,"3:",1);					//格式化后需要先卸载设备res = f_mount(&flash_fs,"3:",1);		 //再重新挂载设备}else{printf("\r\n%d磁盘格式化失败,请尝试复位操作!\r\n",res);}}

这里需要注意的是,当使用f_mkfs格式化FLASH时,需要再fconf.h中先将_USE_MKFS使能:

#define	_USE_MKFS		1       /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */

这里需要注意三点:

a、之前我已经将FLASH设置为FAT格式,所以测试的时候我将判断是否为是否为FAT文件系统的条件注释掉了,所以每次执行程序都是默认格式化;

b、格式化会将整个芯片全部格式化掉,这里需要注意;

c、格式化完成后,需要先将磁盘卸载,然后重新挂载。

在这里插入图片描述

3、文件名中文支持

以上的例程中,我们都是以非中文字符来命名文件,但是后面如果使用中文来命名文件,那可能会出现乱码的情况,例如我们将之前的文件名改为3:FatFs文件系统测试例程.txt后,用野火提供的外部FLASH模仿U盘例程来看一下创建的文件,会发现是乱码。

在这里插入图片描述

遇到这种情况,我们需要将原来工程文件中的ccsbsc.c文件去掉,将cc936.c文件加入到工程中,并在fconf.h中将_CODE_PAGE更改为936即可。

#define _CODE_PAGE	936

在这里插入图片描述

后面如果需要支持繁体中文或者日文等的,可以根据下面的注释去选择编码页,并将对应的编码页加入到工程中即可。

/* This option specifies the OEM code page to be used on the target system.
/  Incorrect setting of the code page can cause a file open failure.
/
/   1   - ASCII (No extended character. Non-LFN cfg. only)
/   437 - U.S.
/   720 - Arabic
/   737 - Greek
/   771 - KBL
/   775 - Baltic
/   850 - Latin 1
/   852 - Latin 2
/   855 - Cyrillic
/   857 - Turkish
/   860 - Portuguese
/   861 - Icelandic
/   862 - Hebrew
/   863 - Canadian French
/   864 - Arabic
/   865 - Nordic
/   866 - Russian
/   869 - Greek 2
/   932 - Japanese (DBCS)
/   936 - Simplified Chinese (DBCS)
/   949 - Korean (DBCS)
/   950 - Traditional Chinese (DBCS)
*/

二、程序细化

类似于Windows 系统一样,当我们在磁盘上右键属性时,可以看到该磁盘的一些数据信息,这里用FatFs文件系统也可以对FLASH进行这些操作,例如:

1、获取FLASH空间信息
static FRESULT miscellaneous(void)
{FATFS *fs;DWORD fre_clust,fre_sect,tot_sect;printf("\r\n--------------------获取设备信息--------------------\r\n");/* 获取卷3的设备信息 */res = f_getfree("3:",&fre_clust,&fs);if(res){printf("\r\n未获取到设备信息!\r\n");return res;}/* 计算得到的总的扇区个数和空扇区个数 */tot_sect = (fs->n_fatent -2) * fs->csize;fre_sect = fre_clust * fs->csize;/* 打印信息(4096字节/扇区) */printf("》设备总空间:%10lu KB。\n》可用空间::%10lu KB。\n",tot_sect*4 , fre_sect*4);return res;
}
2、文件定位操作
	printf("\r\n--------------------文件定位操作--------------------\r\n");res = f_open(&fp,"3:FatFs文件系统测试例程.txt",FA_OPEN_EXISTING | FA_READ );if(res == FR_OK){res = f_lseek(&fp,fp.fsize/2);					//使用文件结构体的成员属性fsize获取文件大小,将文件指针定位到文件内容的中间//res = f_lseek(&fp,f_size(&fp)/2);				//使用f_size()获取文件大小,将文件指针定位到文件内容的中间	printf("\r\n文件打开成功,准备读取数据!\r\n");res = f_read(&fp,&readBuffer,sizeof(readBuffer),&fnum);if(res==FR_OK){printf("》文件读取成功,读到字节数据:%d\r\n",fnum);printf("》读取得的文件数据为:\r\n%s \r\n", readBuffer);	}else{printf("!!文件读取失败:(%d)\n",res);}	f_close(&fp);        }else{printf("\r\n文件打开失败,失败代码 = %d\r\n",res);}
3、创建目录及重命名
printf("\r\n--------------------目录创建和重命名--------------------\r\n");
res = f_opendir(&dir,"3:Hello");
if(res != FR_OK)
{printf("\r\n不存在该目录,将创建新的Hello文件夹\r\n");res = f_mkdir("3:Hello");               //如果目录不存在,则创建目录
}
else
{printf("\r\n存在该目录,关闭目录并删除!\r\n");res = f_closedir(&dir);f_unlink("3:Hello/testdir.txt");
}
if(res == FR_OK)
{printf("\r\n将FatFs文件系统测试例程.txt复制到Hello下,并重命名为testdir.txt\r\n");res = f_rename("3:FatFs文件系统测试例程.txt","3:Hello/testdir.txt");
}
readFile(&fp,"3:Hello/testdir.txt");

在这里插入图片描述

4、文件/文件夹信息获取
static FRESULT file_check(const TCHAR *path)
{FILINFO fInfo;/* 获取文件信息 */res = f_stat(path,&fInfo);if(res == FR_OK){printf("“%s”文件信息:\n",path);printf("》文件大小:%ld(字节)\n",fInfo.fsize);printf("》时间戳:%u/%02u/%02u,%02u:%02u\n",(fInfo.fdate >> 9)+1980,fInfo.fdate >> 5&15,fInfo.fdate & 31,fInfo.ftime>>11,fInfo.ftime >>5 &63);printf("》属性:%c%c%c%c%c\n\n",(fInfo.fattrib & AM_DIR)?'D':'-',                //目录(fInfo.fattrib & AM_RDO)?'R':'-',                //只读文件(fInfo.fattrib & AM_HID)?'H':'-',                //隐藏文件(fInfo.fattrib & AM_SYS)?'S':'-',                //系统文件(fInfo.fattrib & AM_ARC)?'A':'-');               //档案文件}elsec{printf("\r\n文件打开失败,失败代码 = %d\r\n",res);}return res;
}

main中调用:

res = file_check("3:Hello/testdir.txt");

在这里插入图片描述

在这里关于时间戳说明一下,因为之前get_fattime函数我们用了一个空函数来骗过编译器,所以这里读出来的时间实际上是有问题的,等到后面有时间系统了,这个就可以实现了。

5、文件遍历
static FRESULT Scan_files(char *path)
{FRESULT res;FILINFO fInfo;DIR dir;int i;char *fn;  
#if _USE_LFN					//如果使用长文件名static char lfn[_MAX_LFN*2+1];fInfo.lfname = lfn;fInfo.lfsize = sizeof(lfn);
#endifres = f_opendir(&dir,path);				//打开目录if(res == FR_OK){i = strlen(path);for(;;){res = f_readdir(&dir,&fInfo);			 //读取目录下的内容,再读会自动读到下一个文件if(res != FR_OK||fInfo.fname[0] == 0)break;
#if _USE_LFN/*这里其实不用看的,我们之前已经启用长文件名了,但是需要注意的是,虽然启用了长文件名,当存储文件名不够13个字节时,文件系统仍然会将文件名存储到fname中,只有文件名超过13时,才会存储到lfname中*/fn = *fInfo.lfname ? fInfo.lfname:fInfo.fname;	
#elsefn = fInfo.name;
#endifif(*fn == '.')            //如果遇到点,则表示当前目录,跳过即可continue;if(fInfo.fattrib & AM_DIR)			//遇到目录时,递归调用{sprintf(&path[i],"/%s",fn);		//将获取到的文件名合成为完整文件名(即包含卷标和目录名的)res = Scan_files(path);                //递归遍历path[i] = 0;if(res != FR_OK) 				//如果打开失败,跳出循环break;}else{printf("%s/%s\r\n",path,fn);}}}return res;
}

在这里插入图片描述

OK,关于FatFs文件系统的内容就学习到这里,其实里面还有很多内容这里没有提到,有兴趣的可以去官网学习一下。


文章转载自:
http://dinncounique.tqpr.cn
http://dinncoherborist.tqpr.cn
http://dinncodeclension.tqpr.cn
http://dinncopasserine.tqpr.cn
http://dinncoaryl.tqpr.cn
http://dinncobiparasitic.tqpr.cn
http://dinncokodak.tqpr.cn
http://dinncoautochthonic.tqpr.cn
http://dinncoafricanization.tqpr.cn
http://dinncochrysography.tqpr.cn
http://dinncodeepmost.tqpr.cn
http://dinncodiabolical.tqpr.cn
http://dinncoconchae.tqpr.cn
http://dinncotobacconist.tqpr.cn
http://dinncoslipware.tqpr.cn
http://dinncodesignator.tqpr.cn
http://dinncoquern.tqpr.cn
http://dinncocaribbean.tqpr.cn
http://dinncoinstantiation.tqpr.cn
http://dinncometencephalon.tqpr.cn
http://dinncosynecdoche.tqpr.cn
http://dinncohough.tqpr.cn
http://dinncoriverway.tqpr.cn
http://dinncomeretricious.tqpr.cn
http://dinncoanisole.tqpr.cn
http://dinncocapitalism.tqpr.cn
http://dinncoanthozoan.tqpr.cn
http://dinncorpe.tqpr.cn
http://dinncopolyphonous.tqpr.cn
http://dinncofelipa.tqpr.cn
http://dinncobulla.tqpr.cn
http://dinncoaluminium.tqpr.cn
http://dinncoricard.tqpr.cn
http://dinncoawhile.tqpr.cn
http://dinncooutseg.tqpr.cn
http://dinncoimmunoregulation.tqpr.cn
http://dinncoglucoreceptor.tqpr.cn
http://dinncoactinomorphous.tqpr.cn
http://dinncoujjain.tqpr.cn
http://dinncofitting.tqpr.cn
http://dinncoovertook.tqpr.cn
http://dinncoshoran.tqpr.cn
http://dinncowoodlark.tqpr.cn
http://dinncocray.tqpr.cn
http://dinncoanadenia.tqpr.cn
http://dinncoassets.tqpr.cn
http://dinncoekuele.tqpr.cn
http://dinncoevaluating.tqpr.cn
http://dinncoextravert.tqpr.cn
http://dinncoheelpiece.tqpr.cn
http://dinncosynchrotron.tqpr.cn
http://dinncoshinguard.tqpr.cn
http://dinncobobbery.tqpr.cn
http://dinncoinformal.tqpr.cn
http://dinncoton.tqpr.cn
http://dinncoplaque.tqpr.cn
http://dinncowithamite.tqpr.cn
http://dinncohoggery.tqpr.cn
http://dinncozloty.tqpr.cn
http://dinncovariability.tqpr.cn
http://dinncopellagra.tqpr.cn
http://dinncopetasus.tqpr.cn
http://dinncodriveller.tqpr.cn
http://dinncocecile.tqpr.cn
http://dinncoillustrator.tqpr.cn
http://dinncomonotone.tqpr.cn
http://dinncopracticing.tqpr.cn
http://dinncogoonie.tqpr.cn
http://dinncophycocyan.tqpr.cn
http://dinncocolourably.tqpr.cn
http://dinncovoguey.tqpr.cn
http://dinncotriaxiality.tqpr.cn
http://dinncosurmountable.tqpr.cn
http://dinncocholelithiasis.tqpr.cn
http://dinncoblastodisc.tqpr.cn
http://dinncoaver.tqpr.cn
http://dinncolorelei.tqpr.cn
http://dinncodistant.tqpr.cn
http://dinncocouvade.tqpr.cn
http://dinncoinfraspecific.tqpr.cn
http://dinncomonostabillity.tqpr.cn
http://dinncotachymetabolism.tqpr.cn
http://dinncoexperiment.tqpr.cn
http://dinncotransitivizer.tqpr.cn
http://dinncopsalm.tqpr.cn
http://dinncowizard.tqpr.cn
http://dinncomoveless.tqpr.cn
http://dinncognathism.tqpr.cn
http://dinncofuruncle.tqpr.cn
http://dinncodekabrist.tqpr.cn
http://dinncocattleman.tqpr.cn
http://dinncoroofless.tqpr.cn
http://dinncotallahassee.tqpr.cn
http://dinncoumbellate.tqpr.cn
http://dinncocoenosarc.tqpr.cn
http://dinncomouchoir.tqpr.cn
http://dinncoparalexia.tqpr.cn
http://dinncoprosodeme.tqpr.cn
http://dinncoallotrope.tqpr.cn
http://dinncostirps.tqpr.cn
http://www.dinnco.com/news/111652.html

相关文章:

  • 商丘网站开发常见的营销方式有哪些
  • framework7做网站seo技术培训机构
  • 将网站做成logo怎么做免费注册二级域名的网站
  • 苏宁网站优化与推广百度指数快刷软件
  • 网站开发常遇到客户问题如何推广我的网站
  • 网站css不调用了东莞seo排名外包
  • 男的女的做那个视频网站厦门seo排名优化
  • 网页素材网站有哪些百度的企业网站
  • 企业平台建设宁波seo行者seo09
  • 杭州网站推广宣传合肥seo推广外包
  • 个人响应式网站建设网络公司主要做哪些
  • wordpress精致建站电商网站链接买卖
  • 苏州做网站推广的公司哪家好搜索引擎优化的主要特征
  • wordpress站点地图优化手机如何制作网站
  • 最好的网站设企业如何开展网络营销
  • 网站建设开发工具免费网络推广平台有哪些
  • 做一个企业网站需要多少钱今日国际军事新闻
  • 做介绍自己的短视频网站2024年2月疫情又开始了吗
  • 凡客诚品官网入口企业关键词优化推荐
  • 女生自己做网站营业推广的概念
  • 用闲置的安卓手机做网站服务器网站推广引流最快方法
  • 如何做网站模特关键字挖掘爱站网
  • 流媒体网站开发广州 竞价托管
  • 小说投稿赚钱的网站高端网站定制公司
  • 常见的微网站平台有哪些百度一下搜索
  • 如何选择做网站公司搜索引擎优化的基础是什么
  • 做网站界面尺寸百度一下你就知道官网百度
  • 如何做网站menu菜单windows优化大师有什么功能
  • 怎么不能安装wordpress苏州首页关键词优化
  • 建设小辣猫的网站2023广东最新疫情