/**
******************************************************************************
* File Name : exfuns.c
* Description : This file provides code for the configuration
* of the External Functions instances.
******************************************************************************
* @attention
*
*
© Copyright (c) 2019 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include
#include "malloc.h"
#include "fattester.h"
#include "usart.h"
#include "exfuns.h"
#include "ff.h"
#include "string.h"
//////////////////////////////////////////////////////////////////////////////////
//This program is for educational purposes only, without the author's permission, may not be used for any other purpose
//ALIENTEK STM32F4 Explorer Board
//FATFS Test code
//Hot Atomic @ALIENTEK
//Forum: www.openedv.com
//Date modified: 2015/9/12
//Version£ºV1.0
//All rights reserved pirated reserved.
//Copyright(C) Guangzhou wing electronic technology limited company 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//For disk registration area
//Path: a path on disk, such as "0:", "1:"
//MT:0, do not register (register later); 1, register now
//Return values: the results
u8 mf_mount(u8* path,u8 mt)
{
return f_mount(fs[2],(const TCHAR*)path,mt);
}
//Open the file path
//Path: path + file name
//mode: open the mode
//Return values: the results
u8 mf_open(u8*path,u8 mode)
{
u8 res;
res=f_open(file,(const TCHAR*)path,mode);//Open the folder
return res;
}
//Close the file
//Return values: the results
u8 mf_close(void)
{
f_close(file);
return 0;
}
//Read data
//Len: read the length of the
//Return values: the results
u8 mf_read(u16 len)
{
u16 i,t;
u8 res=0;
u16 tlen=0;
printf("\r\nRead file data is:\r\n");
for(i=0;in_fatent - 2) * fs1->csize;//Total number of sectors
fre_sect = fre_clust * fs1->csize; //Get number of spare sectors
#if _MAX_SS!=512
tot_sect*=fs1->ssize/512;
fre_sect*=fs1->ssize/512;
#endif
if(tot_sect<20480)//Total capacity is less than 10M
{
/* Print free space in unit of KB (assuming 512 bytes/sector) */
printf("\r\nThe total disk capacity:%d KB\r\n"
"Free space:%d KB\r\n",
tot_sect>>1,fre_sect>>1);
}else
{
/* Print free space in unit of KB (assuming 512 bytes/sector) */
printf("\r\nThe total disk capacity:%d MB\r\n"
"Free space:%d MB\r\n",
tot_sect>>11,fre_sect>>11);
}
}
return fre_sect;
}
//File read/write pointer offset
//offset:Relative offset of the first address
//Return value: the results of execution.
u8 mf_lseek(u32 offset)
{
return f_lseek(file,offset);
}
//Read the current position of the read/write pointer.
//Return value:location
u32 mf_tell(void)
{
return f_tell(file);
}
//Read the file size
//Return value: file size
u32 mf_size(void)
{
return f_size(file);
}
//Create a directory
//pname:Directory path + name
//Return values: the results
u8 mf_mkdir(u8*pname)
{
return f_mkdir((const TCHAR *)pname);
}
//Format
//path:Disk path, such as "0:", "1:"
//mode:mode
//au:Cluster size
//Return values: the results
//u8 mf_fmkfs(u8* path,u8 mode,u16 au)
//{
// return f_mkfs((const TCHAR*)path, mode, au, );//Format the drv: drive letter; mode: mode au: cluster size
//}
//Deleting files/directories
//PName: file/directory path + name
//Return values: the results
u8 mf_unlink(u8 *pname)
{
return f_unlink((const TCHAR *)pname);
}
//Modify file/directory names (if the directory is different, you can also move the file!)
//Oldname: previous names
//Newname new name
//Return values: the results
u8 mf_rename(u8 *oldname,u8* newname)
{
return f_rename((const TCHAR *)oldname,(const TCHAR *)newname);
}
//Gets the drive letter (disk name)
//Path: a path on disk, such as "0:", "1:"
void mf_getlabel(u8 *path)
{
u8 buf[20];
u32 sn=0;
u8 res;
res=f_getlabel ((const TCHAR *)path,(TCHAR *)buf,(DWORD*)&sn);
if(res==FR_OK)
{
printf("\r\nDisk%s Label:%s\r\n",path,buf);
printf("Disk%s Serial Number:%X\r\n\r\n",path,sn);
}else printf("\r\nFailed to get£¬Error code:%X\r\n",res);
}
//Set the drive letter (disk name), a maximum of 11 characters!! Support the combination of numbers and uppercase letters and Chinese characters
//path:Disk number + name£¬For example,"0:ALIENTEK"¡¢"1:OPENEDV"
void mf_setlabel(u8 *path)
{
u8 res;
res=f_setlabel ((const TCHAR *)path);
if(res==FR_OK)
{
printf("\r\nDisk drive letter set successfully:%s\r\n",path);
}else printf("\r\nDisk drive letter set£¬Error code:%X\r\n",res);
}
//Read a string from file
//size:To read the length of the
void mf_gets(u16 size)
{
TCHAR* rbuf;
rbuf=f_gets((TCHAR*)fatbuf,size,file);
if(*rbuf==0)return ;//No data to read
else
{
printf("\r\nThe String Readed Is:%s\r\n",rbuf);
}
}
//Need _USE_STRFUNC>=1
//Write a character to a file
//c:The character to write
//Return values: the results
u8 mf_putc(u8 c)
{
return f_putc((TCHAR)c,file);
}
//Write a string to a file
//c:The string to be written
//Return value: writes the length of the string
u8 mf_puts(u8*c)
{
return f_puts((TCHAR*)c,file);
}