Hello
I'm working on a Kinetis K70 and use MQX 4.1.1.
I have an external NandFlash and an USB key connected.
I mount the Nandflash and USB on a System file (like in exemple)
Then with Shell command, I can read both disk (a: for NandFlash, c: for USB)
I copy file from one to the other without any problem (For small file)
But when I try with a big file (512Kbytes) the copy (take some time) and then the copied file is bad, size is "0".
I try with the following custom code (which is an extract of Shell_Copy command) but the result is same.
MQX_FILE_PTR in_fd = NULL;
MQX_FILE_PTR out_fd = NULL;
MFS_DATE_TIME_PARAM FileDate;
int32_t ReadSize = 0;
int32_t WriteSize = 0;
int32_t copysize = 8192;
uint16_t DateValue;
uint16_t TimeValue;
char* copybuffer = NULL;
/* Open source file */
in_fd = fopen(SourcePtr, "r");
if (in_fd == NULL)
{
printf("CT_USB_CopyFile, source file not found: %s\n", SourcePtr);
return(1);
}
/* Open destination file */
out_fd = fopen(DestPtr, "w");
if (in_fd == NULL)
{
printf("CT_USB_CopyFile, Dest file not found: %s\n", DestPtr);
return(2);
}
/* Allocate Buffer */
do {
copybuffer = _mem_alloc(copysize);
if (copybuffer != NULL) break;
else copysize >>= 1;
} while (copysize >= 512);
if (copybuffer == NULL)
{
printf("CT_USB_CopyFile: Warning, unable to allocate copy buffer\n" );
return(3);
/* Shell code use a slower method in this case... */
}
else
{
do
{
ReadSize = read(in_fd, copybuffer, copysize);
if (ReadSize > 0)
{
WriteSize = write(out_fd, copybuffer, ReadSize);
}
else
{
break;
}
} while (WriteSize == ReadSize);
fflush(out_fd);
/* Set File Date/Time */
FileDate.DATE_PTR = &DateValue;
FileDate.TIME_PTR = &TimeValue;
ioctl(in_fd, IO_IOCTL_GET_DATE_TIME,(uint32_t *) &FileDate);
ioctl(out_fd, IO_IOCTL_SET_DATE_TIME,(uint32_t *) &FileDate);
}
if (copybuffer) _mem_free(copybuffer);
if (in_fd) fclose(in_fd);
if (out_fd) fclose(out_fd);
return(0);
Do you know why this not work? May be I must flush other then File only (fflush(out_fd); )
Thank