Copy a big file: Neither the shell command nor the custom code work

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy a big file: Neither the shell command nor the custom code work

986 Views
arnogir
Senior Contributor II

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

7 Replies

646 Views
arnogir
Senior Contributor II

I havn't success with my problem:smileycry:

0 Kudos

646 Views
arnogir
Senior Contributor II

Does someone can do a test with the example Shell to copy a large file to an USB stick? (With a K70 and MQX 4.1.1):smileygrin:

0 Kudos

646 Views
RadekS
NXP Employee
NXP Employee

I tried replicating your case however everything works correctly on my side.

I combined mfs_usb and mfs_nandflash examples and copy 1MB file several times between USB stick and NAND flash at TWR-K70F120M board.

I just copy mfs_nandflash example code into shell_task.c file in mfs_usb example and made some small modifications (just one shell_task function, nandflash as “c:”). Additionally I add ffs library into project.

After build I was able load it into MCU and run.

I used commands “ffs_open”, “format” and “write” to create 1MB file.

After that I copy this file between disks “c:” (NAND flash) and “a:” (USB disk) several times - always without any problem.

Also read works correctly.

Note: I used IAR compiler and Debug target

I attached my project (modified mfs_usb example).

Unfortunately I do not see any obvious issue in your code. Everything seems to be correct.

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

646 Views
RadekS
NXP Employee
NXP Employee

Could you please try disabling cache for avoid influence of this feature?

Please add _DCACHE_DISABLE(); command into task prior you call _io_nandflash_wl_install().

646 Views
arnogir
Senior Contributor II

Hello

I finally got to test today.


But in fact, When I try with exactly the same soft, all run correctly now, I don't touch the code since my last post!:smileyblush:

Than Test with/without DCASH_DISABLE now will not be a good test today!

So all work correctly now (I don't know why), but if problem resurface again, I will test to disable cash!

Thank:smileyhappy:

0 Kudos

646 Views
arnogir
Senior Contributor II

Hello

Sorry for the Late, I fully occupied on another subject.

I will try I think the next week and keep you informed.

Many tnahk:smileyhappy:

0 Kudos

646 Views
arnogir
Senior Contributor II

Hi

Anybody have some idea?:smileyblush:

0 Kudos