This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem with keil flash file system

hi to all,
i am creating a something like file explorer with lpc1788,with keil v5.11a as compiler.
keil flash file system work correctly and good when i want read any file from memory card,but when i want write to it,some thing happened that surprised(and confused) me!!!!
please look at on function of my code(that will copy a file from usb flash disk to memory card) :

unsigned char Copy_File_Flash_To_Sd(char *Dest,char *Source)
{
        FILE* myDest;
        FRESULT fResult;
        BYTE res = 0x00;
        char copyRes = 1;
        UINT tmp = 1;
        FIL mySource;

        //checking that source file exist or no
        if(f_stat(Source + 4,0x00) != FR_OK)
                return 0;

        myDest = fopen(Dest,"w");

        //checking for errors when opening file
        if(myDest == NULL)
        {
                char i = 0;
                //re initlie flash fs(try in three time)
                for(i = 0;i < 3;i++)
                {
                        if(finit(0) == 0)
                                break;
                }

                //re open file
                myDest = fopen(Dest,"w");
                if(myDest == NULL)
                        return 0;
        }

        //opening source file for read(+4 skim "U0:\" part of path)
        if(f_open(&mySource,Source + 4,FA_READ) != FR_OK)
        {
                //closing opened file in sd card
                fclose(myDest);

                //reporting that proccess was faild
                return 0;
        }

        //creating a delay
        msDelay(50);

        //hitherto all thing is true

        //reading all byte of source file
        while(1)
        {
                //reading one byte from flash disk
                fResult = f_read(&mySource,&res,1,&tmp);

                //check that file_read,read any thing or no
                if(tmp != 0 || fResult)
                {
                        /*            ..::**** problem is here ****::..
                        problem  is here,that when i want to write res to opened file in
                        sd card only write 4KB of file in it and then fputc return error!!!
                        Surprisingly when change res in below line with '15'(an const int
                        number) it write it correctly(!!!).
                        note that res has valid value,i check it.
                        */
                        if(fputc(res,myDest) == EOF)
                        {
                                copyRes = 0;
                                break;
                        }
                }
                else
                        break;
        }

        //closing opened files
        for(res = 0;res < 3;res++)
        {
                if(f_close(&mySource) == FR_OK)
                        break;
                else if(res == 2)
                        copyRes = 0;
        }

        for(res = 0;res < 3;res++)
        {
                if(fclose(myDest) == 0)
                        break;
                if(res == 3)
                {
                        return 0;
                }
        }

        if(copyRes == 1)
                return 1;
        else
                return 0;
}

now any one can help me to fix this problem,any one has any experience with keil flash file system?????
Excuse me for long question,i did not know how make it shorter.

regards,alireza sd.

Parents
  • as i explained in above,problem appear when i want write to sd/mmc card with keil flash file system(while reading process from it done well).
    look at below line :

    if(fputc(res,myDest) == EOF)
    


    in above res is one byte that was readed from opened file from usb flash disk,in above fputc work only for 4KB(4096) byte and in byte 4097 it return EOF.
    and that's what made me confused is that when in above function,in above line when i change res with '0x0F'(an const integer),it write correctly n(n is size of file that must be copy in byte) '0x0F' in file.
    why it work for for const integer and no for a variable?????

Reply
  • as i explained in above,problem appear when i want write to sd/mmc card with keil flash file system(while reading process from it done well).
    look at below line :

    if(fputc(res,myDest) == EOF)
    


    in above res is one byte that was readed from opened file from usb flash disk,in above fputc work only for 4KB(4096) byte and in byte 4097 it return EOF.
    and that's what made me confused is that when in above function,in above line when i change res with '0x0F'(an const integer),it write correctly n(n is size of file that must be copy in byte) '0x0F' in file.
    why it work for for const integer and no for a variable?????

Children