Issue While Porting FAT32 Driver on Virtex -4

gupta123 wrote on Friday, May 11, 2012:

Dear Sir

I am getting issue While POrting FAT32 Driver using SDCard on Virtex-4 Code.is compile.At a run time i getting issue of File Write to SDCard.I am using Follwing code

Error:- Its shows NoValied FAT32  File System on SDCard…So please guide for fixed this issue

:-E- SendCmd18,0 (1)
Open File to write Failure…error = 13
-Open File fil.fs = 0
-Open File fil.id = 0
-Open File fil.dsect = 0
-Open File fil.clust = 0
-Open File fil.fsize = 0

Write a text data to the Card.
write file Failure…error = 9

Close the file writeen.
Open File to write…

void prvTaskD (void* pvParameters)
{

SPI_Int();

(void) pvParameters;                    // Just to stop compiler warnings.

    for (;:wink: {
    static FRESULT rc;   /* Result code */
        static FATFS fatfs;  /* File system object */
        static FIL fil;   /* File object */
        static DIR dir;   /* Directory object */
        static FILINFO fno;  /* File information object */
        int i ;
        char key ;

        static UINT bw, br, numread;
        static BYTE buff;
        BYTE Message = “HELLO from www.letrungthang.blogspot.com” ; // message’s content
        TCHAR *FilePath = “MESSAGE.TXT” ; // file path

        f_mount(0, &fatfs);  /* Register volume work area (never fails) */

        // File testing
        printf(“Open File to write…\n\r”);

        if( rc != FR_OK ) {
                  //  printf("-E- f_mount pb: 0x%X (%s)\n\r", rc);
                    return 0;
                }

               // Test if the disk is formated
                rc = f_opendir (&dir,STR_ROOT_DIRECTORY);
                if(rc == FR_OK ){

                    // erase sdcard to re-format it ?
                    printf("-I- The disk is already formated.\n\r");

                    // Display the file tree
                    printf("-I- Display files contained on the SDcard :\n\r");
                 //   FF_ScanDir(STR_ROOT_DIRECTORY);

                    printf("-I- Do you want to erase the sdcard to re-format disk ? (y/n)!\n\r");

                    key = ‘y’;
                    if( (key == ‘y’) ||  (key == ‘Y’))
                    {
                      for(i=0;i<100;i++) {
                  //    MEDSdcard_EraseBlock(&medias, i);
                      }
                      printf("-I- Erase the first 100 blocks complete !\n\r");
                      rc = FR_NO_FILESYSTEM;
                    }
                }

        //------------------------
        //------------------------
        rc = f_open(&fil, FilePath, FA_WRITE | FA_OPEN_ALWAYS); /* Create a file on the drive 0 */
        if(rc)  rc = f_open(&fil, FilePath, FA_WRITE | FA_OPEN_ALWAYS);// try again once

        if (!rc) {
          printf(“Open File to write successful…\n\r”);
        }else  {
          printf(“Open File to write Failure…error = %u\n\r”,rc);
        }
        printf("-Open File fil.fs = %d\n\r",fil.fs);
        printf("-Open File fil.id = %d\n\r",fil.id);
        printf("-Open File fil.dsect = %d\n\r",fil.dsect);
        printf("-Open File fil.clust = %d\n\r",fil.clust);
        printf("-Open File fil.fsize = %d\n\r",fil.fsize);

        printf("\nWrite a text data to the Card.\n\r");

        rc = f_write(&fil, Message, sizeof(Message)-1, &bw); // write file

        if (!rc) {
          printf(“write success. %u bytes written.\n\r”, bw);
        }else  {
          printf(“write file Failure…error = %u\n\r”,rc);
        }

        printf("\nClose the file writeen.\n\r");
        rc = f_close(&fil); // close file

        if (!rc) {
          printf(“File writeen closed success.\n\r”);
        }else  {
          printf(“File close writeen was failure…error = %u\n\r”,rc);
        }

        //------------------------
        //------------------------
        printf("\n\rOpen File to read…\n\r");
        rc = f_open(&fil, FilePath, FA_READ | FA_OPEN_EXISTING); /* Create a file on the drive 0 */
        if(rc)  rc = f_open(&fil, FilePath, FA_READ | FA_OPEN_EXISTING);// try again once

        printf("-Open File fil.fs = %d\n\r",fil.fs);
        printf("-Open File fil.id = %d\n\r",fil.id);
        printf("-Open File fil.dsect = %d\n\r",fil.dsect);
        printf("-Open File fil.clust = %d\n\r",fil.clust);
        printf("-Open File fil.fsize = %d\n\r",fil.fsize);

        if (!rc) {
          printf(“Open File to read successful…\n\r”);
        }else  {
          printf(“Open File to read Failure…error = %u\n\r”,rc);
        }

        printf("\nRead the file content from the Card:\n\r");
        for (;:wink: {
          rc = f_read(&fil, buff, sizeof(buff), &br);     /* Read a chunk of file */
          if (rc || !br) break;         /* Error or end of file */

      //    for (int i = 0; i < br; i++)                /* Type the data */
        //    putchar(buff_);

          numread += br ;
        }

        if (!rc) {
           printf("\n\r%u bytes read.\n\r", numread);
        }else  {
           printf(“read file Failure…error = %u\n\r”,rc);
         }

        printf("\nClose the file.\n\r");
        rc = f_close(&fil); // close file

        if (!rc) {
          printf(“File closed.\n\r”);
        }else  {
          printf(“File close Failure…error = %u\n\r”,rc);
        }
        //-------------------------
        //------------------------
        // Directory testing
        printf("\nOpen root directory.\n\r");
        rc = f_opendir(&dir, “”);

        if (!rc) {
          printf(“Open Dir OK.\n\r”);
        }else  {
          printf(“Open Dir Failure…error = %u\n\r”,rc);
        }

        printf("\nDirectory listing…\n\r");
        for (;:wink: {
          rc = f_readdir(&dir, &fno); /* Read a directory item */
          if (rc || !fno.fname) break; /* Error or end of dir */

          if (fno.fattrib & AM_DIR)
            printf("     %s\n\r", fno.fname); // is Directory
          else
            printf("%8lu  %s\n\r", fno.fsize, fno.fname); // is file
        }

        if (!rc) {
          printf(“Listing Dir complete.\n\r”);
        }else  {
          printf(“Listing Dir Failure…error = %u\n\r”,rc);
        }

        printf("\nTest completed.\n\r");
        f_mount(0, NULL);/* Unregister work area prior to discard it */

     //     vTaskDelay(1000);

    }
}_

rtel wrote on Friday, May 11, 2012:

Absolutely no idea.  This is not FreeRTOS code, a system I have never used, and has nothing to do with FreeRTOS as far as I can see.  Sorry, but I can’t help.  Where did you get the file system from?  I would recommend asking your questions there.

Regards.