how to interface SDcard fat file system into ethernet to serial project

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

how to interface SDcard fat file system into ethernet to serial project

1,082 Views
sudhakarp
Contributor V

Hi,

i am using KDS 2.0 and KSDK 1.1.0 and FRDMK64F120 controller.

i want to modify ethernet to serial project. here i want to write whatever data coming from UART(serial) into SDcard.(with FATfile system).

for that which example will be useful.

I SAW sd_card demo example project but there using RAW data writing and reading. but i need FAT file system.

in MFS example there are using SHELL command.

is possible to interface FATFS file into ethernet_to_serial project?

otherwise give some idea..

regards,

sudhakar p

0 Kudos
4 Replies

587 Views
sudhakarp
Contributor V

hi,

     i dnt want MFS file syatem. i want to interface FATFS file only. for that what are changes i want to do.

what are the files or library i want to add ? if you mention initialization process it will useful to me. just give some idea remaining part i will take care.

     project requirement:

               i want to write ETHERNET received data into SD card (with file system) not RAW data.  i want all read/write/delete functions.

regards,

sudhakar p

0 Kudos

587 Views
sudhakarp
Contributor V

Hi,

I tried to add FATFS files into my project but am getting following error. i dnt know why?

i added image here.,

pastedImage_0.png

0 Kudos

587 Views
sudhakarp
Contributor V

hi,

i solved "no such file or directory problem". and i initialized Sd card SPI pins

but i cant read/write any data from SD card . this is my code: when i try to open file its giving "FR_INVALID_OBJECT" error.

UINT8 sd_card_function()

{

     sdhc_host_t host = {0};

    sdhc_user_config_t config = {0};

                 uint32_t i, status;

                uint8_t proceed;

                char f_name[]="test.txt";

                char fr_name[]="read.txt";

                char f_data[]="1A2B3C4D";

                FILE_PTR ser_device;

                char ret,fle; 

    ser_device = fopen(SERIAL_DEVICE, "w");

  

        CLOCK_SYS_EnableSdhcClock(0); // enable SDHC module instance

       GPIO_DRV_Init(sdhcCdPin, NULL); //for card detection

            // initialize user sdhc configuration structure

            config.transMode = kSdhcTransModeAdma2;

          //  config.clock = SDMMC_CLK_100KHZ;

            config.cdType = kSdhcCardDetectGpio;

            printf("This demo is going to access data on card\r\n");

            // initialize the SDHC driver with the user configuration

           if (SDHC_DRV_Init(BOARD_SDHC_INSTANCE, &host, &config) != kStatus_SDHC_NoError)

            {

                //me return kTestResultFailed;

                 printf("FAILED SD CARD\r\n");

            }

            printf("SD init DONE\r\n");

            // wait for a card detection

          //  sdhc_cd_irqhandler();

           sdcard_disk_initialize(0);

            printf("SD DISK DONE\r\n");

           ret=f_open(fle,"read.txt",'r');

            if(ret==FR_OK)

             {

                   printf("open SUCCESS\r\n");

              }

               else

               {

                 printf("open failed\r\n");     /*****************here am getting error*****************/

                 printf("error=%d",ret);

               }

          //  ret=f_write(f_name,f_data,8,1);        //write

            ret=f_read(ret,&f_data,4,1);            //read

            if(ret==FR_OK)

            {

                printf("WRITE SUCCESS\r\n");

            }

            else

                printf("WRITE failed\r\n");

}

can you give some solution for this.

regards,

sudhakar p

0 Kudos

587 Views
adyr
Contributor V

Hi sudhakar,

I'm not sure if this helps but I let FATFS do the initialisation of the card driver and use the file system as follows:

FATFS fs;
memset( &fs, 0, sizeof(FATFS) );
f_mount( 1, &fs );

FIL fp;
memset( &fp, 0, sizeof(FIL) );

if (f_open( &fp, "1:\\read.txt", FA_READ ) == FR_OK)
{
  f_close( &fp );
}

FATFS expects drive 0 to be USB and drive 1 to be the SD card. Therefore when FATFS finds the 1 in mount and f_open it initialises and mounts the SD card.

Best regards,

Adrian.