move or copy a file between multiple MFS (over SD and USB)

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

move or copy a file between multiple MFS (over SD and USB)

Jump to solution
3,546 Views
Angelillo
Contributor III

Hi,

In my MQX4.0 Project, I have installed two MFS, one MFS over SD Card and one MFS over USB device. I have used the shell to test all possible commands  successfully (dir, cd, copy, rename, ....).

Also, I have used Input/Output Control Commands for MFS (ioctl) to create subdirectories, to rename files, to move files,.. successfully without to use the shell.

Now, I'm trying to move one file from USB to SD Card but without succeed. As support I'm following the steps described in the post Re: Use USB msd class with SD card  but in this case they didn't use MQX.

I would be very grateful if anyone can help me sharing one demo application or any useful comments.

Thank you very much in advance,

Ángel G.

Labels (2)
1 Solution
2,436 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi Angel,

You could try this:

void my_task(uint_32)
{
char_ptr   ARGV[4];
char       CMD_LINE[40]="copy a:\\test.txt c:\\my.txt";

    /* create lwevent group */
    if (_lwevent_create(&lwevent_FS,0) != MQX_OK) {
    printf("\nMake event failed");
    _task_block();
    }

    while(TRUE)
    {
     snprintf(CMD_LINE, 28, "copy a:\\test.txt c:\\my.txt");
  if (_lwevent_wait_ticks(&lwevent_FS,0b11,TRUE,0) != MQX_OK)
  {
   printf("\nEvent Wait failed");
   _task_block();
  }
 
  printf("\nbefore copying\n");
  printf("%s",CMD_LINE);
  Shell_parse_command_line(CMD_LINE, ARGV);
  Shell_copy(3, ARGV);
  printf("\nafter copying\n");
 
  if (_lwevent_clear(&lwevent_FS,0b11) != MQX_OK) {
     printf("\nEvent Clear failed");
     _task_block();
  }
    }
}

The code is attached.

Best Regards,

-Garabo

View solution in original post

8 Replies
2,436 Views
amleng
Contributor IV

Hi guys,

Another related question:

I need to copy a file from one subdirectory(folder) to the root directory. I couldn't find any I/O control command (ioctl) to do it. Instead I used Shell_parse_command_line() and Shell_copy() to do the job. When I add this part in a task it works well but  I need to do it through a shell command. It looks like there is a confliction when I call Shell_parse_command_line() within a shell command!  any suggestion for me? Any other solution?

Cheers

0 Kudos
Reply
2,436 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi,

Actually there is not a IOCTL for copying files. You would need to open the source file in read mode. Open the destiny new file in write mode. Copy everything from one to another using a loop. You can find the source code from the sh_copy.c file very illustrative:

in_fd = fopen(abs_path, "r");

out_fd = fopen(abs_path, "w");

do {

size = read(in_fd, copybuffer, copysize);

if (size > 0) {

wsize = write(out_fd, copybuffer, size);

}

else

break;

} while (wsize == size);

I hope this helps.

Best Regards,

Garabo

0 Kudos
Reply
1,926 Views
WilliamLiSH
Contributor II

Hi Garabo,

I am using MQX5 with MFS V5.1(version number: 0x0501) and I try to copy file between SD card and USB disk on my hardware based on RT1050EVK board with above method. Here I met a very strange issue that when read or write more than 512 bytes from or to USB disk, the data is wrong randomly sometimes. However if the read / write data size is less than 512 bytes, there is no such issue. I noticed that the sector size of the USB disk is 512 bytes, so if the size is more than 512 bytes, it will invoke MFS_Read_device_sectors() / MFS_Write_device_sectors() and this code branch will cause such problem.

There is no such issue when read / write SD card with same MFS code.

I could not find the root cause and to avoid this issue I have to modify the copy data size less than 512 bytes which causes the slow copy speed and therefore long copy time.

Do you aware of such issue and could you help provide some solution?

 

best regards

William

0 Kudos
Reply
2,436 Views
amleng
Contributor IV

That helps. Thank you very much!

0 Kudos
Reply
2,436 Views
DavidS
NXP Employee
NXP Employee

Hi Angel,

I suspect the problem is in the path implementation.

My quick test is using the ramdish demo:

C:\Freescale\Freescale_MQX_4_0\mfs\examples\ramdisk

My hardware is the TWR-K60D100M tower kit with TWR-MEM card added to have access to MRAM.

The ramdisk demo is defaulted to using the MRAM but can be modified to use internal SRAM of the MCU.

I simply copy-n-pasted the Ram_disk_start() to MRam_disk_start() in Shell_Task.c, changed references to have "a: = SRAM" and "b:=MRAM".  I'll attach the source code.

I was then able via the shell to format each device, create a test file, then copy it to the other device.

Terminal Output:

ScreenHunter_02 Feb. 21 11.23.gif

Hope this shell example will allow you to get your embedded version working.

Regards,

David

2,436 Views
Angelillo
Contributor III

Hi David,

Thank you very much for your answer. Your explanations are useful for me if I decide to install multiple MFS in different kinds of memory simultaneously.

Best regards,

Ángel G.


0 Kudos
Reply
2,437 Views
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi Angel,

You could try this:

void my_task(uint_32)
{
char_ptr   ARGV[4];
char       CMD_LINE[40]="copy a:\\test.txt c:\\my.txt";

    /* create lwevent group */
    if (_lwevent_create(&lwevent_FS,0) != MQX_OK) {
    printf("\nMake event failed");
    _task_block();
    }

    while(TRUE)
    {
     snprintf(CMD_LINE, 28, "copy a:\\test.txt c:\\my.txt");
  if (_lwevent_wait_ticks(&lwevent_FS,0b11,TRUE,0) != MQX_OK)
  {
   printf("\nEvent Wait failed");
   _task_block();
  }
 
  printf("\nbefore copying\n");
  printf("%s",CMD_LINE);
  Shell_parse_command_line(CMD_LINE, ARGV);
  Shell_copy(3, ARGV);
  printf("\nafter copying\n");
 
  if (_lwevent_clear(&lwevent_FS,0b11) != MQX_OK) {
     printf("\nEvent Clear failed");
     _task_block();
  }
    }
}

The code is attached.

Best Regards,

-Garabo

2,436 Views
Angelillo
Contributor III

Hi,

Thank you very much Garabo. Now, my application it's working fine copying files from MFS1 over USB ("c:" drive) to MFS2 over SD Card ("a:" drive). Your answer has been very useful for me.

Best regards,

Ángel G.


0 Kudos
Reply