problems with ESDHC driver and MFS

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

problems with ESDHC driver and MFS

898 Views
botaoyang
Contributor II

I want to use MFS on SD card, and I built a MQX project, but I can creat a flie or read a file in SD card, the main prosses in as below:

  

com_handle = fopen("esdhc:", 0);

if (NULL == com_handle)
{
    printf("Error opening communication handle %s, check your user_config.h.\n");//, SDCARD_COM_CHANNEL);
    _task_block();
}
else
{
   printf("success opening communication handle.\n");
}

   

/* Install SD card device */
error_code = _io_sdcard_install("sdcard:", (pointer)&_bsp_sdcard0_init, com_handle);
if ( error_code != MQX_OK )
{
    printf("Error installing SD card device (0x%x)\n", error_code);
    _task_block();
}
else
{
   printf("success installing SD card device.\n");
}

/* Open the device which MFS will be installed on */
sdcard_handle = fopen("sdcard:", 0);
if (sdcard_handle == NULL)
{
    printf("Unable to open SD card device.\n");
           // continue;
}
else
{
    printf("success to open SD card device.\n");
}
  

   

error_code = _io_mfs_install(sdcard_handle, filesystem_name, 0);
if (error_code != MFS_NO_ERROR)
{
    printf("Error initializing MFS over partition: %s\n", MFS_Error_text((uint_32)error_code));
}
else
{
    printf("success initializing MFS.\n");
}   

   

char buffer1[100] = "111111111111.\n" ;
char buffer2[100];
uint32_t i;

   

mfs_fd_ptr = fopen(filesystem_name,NULL);
if (mfs_fd_ptr == NULL)
{
    printf("Error opening MFS device driver. %s\n");
}
else
{
    printf("success opening MFS device driver.\n");
}   

   

//error_code = ioctl(mfs_fd_ptr,IO_IOCTL_DELETE_FILE,"myfile.txt");

   

fd_ptr = fopen("a:myfile.txt","a+");
write(fd_ptr,buffer1,strlen(buffer1));
read(fd_ptr,buffer2,strlen(buffer1));

   

    the return message is all correct, but I can open myflie.txt correctly.

    I want to know what is the problem and how to solve it, thank you !

0 Kudos
6 Replies

479 Views
DavidS
NXP Employee
NXP Employee

Hi Botao,

Are you using MQX_4.1.1?

Which Kinetis device are you using?

Have you tried running the following example?

What development tool are you using?  CW10.6? Other>

C:\Freescale\Freescale_MQX_4_1_1\mfs\examples\sdcard

Regards,

David

0 Kudos

479 Views
botaoyang
Contributor II

I am using MQX_4.0, on TWR_K60D100M,.codewarrior 10.5 ,

.yes, I have run the example. now i am trying to build my own project, the code was copyed from the example project,

the return message shows that MFS was installed on the SD card successfully, but I still can't write or read a file in SD card.

0 Kudos

479 Views
DavidS
NXP Employee
NXP Employee

Hi Botao,

You are successful with demo on TWR-K60D100M read and write to SD Card.  Correct?

Have you tried different SD Cards and different size cards?  What card and size are you using?

For your own hardware, are you using the same processor that is on TWR-K60D100M or a derivative processor?

Regards,

David

0 Kudos

479 Views
thiagow
Contributor III

David,

Why did you say about testing different SD Cards and Differente sizes?

I did some tests here using C:\Freescale\Freescale_MQX_4_1_1\mfs\examples\sdcard  with MQX 4.1.1 and frdm-k64f           and realized  the error below only using a different brand of SD card of 2 GB, for example, using kingston brand the problem doesn't occours, but using sandisk brand there is this problem when opening filesystem:

  /* Open file system */

    filesystem_handle = fopen(filesystem_name, NULL);

    error_code = ferror(filesystem_handle);

    if (error_code == MFS_NOT_A_DOS_DISK)

    {

      pDEBUG("NOT A DOS DISK! You must format to continue.\n");

    }

    else if (error_code != MFS_NO_ERROR)

    {

      pDEBUG("Error opening filesystem:%d - %s\n", error_code, MFS_Error_text((uint32_t)error_code));

      return 1;

    }

The error code returned when I'm opening the filesystem  is equal -1.    After this error occours, there is no more possible to use SD card (inclusive using kingston brand) to record data. There is necessary restart MFS stack (restarting MQX).

I believe that there is a problem in the moment of open the filesystem after partition manager is installed sucessfully. Starnge is occours only using sandisk brand.

Do you know any problem with MQX MFS about using different SD cards brands?

0 Kudos

479 Views
botaoyang
Contributor II

No, I am not successful with demo on TWR-K60D100M read and write to SD Card. is there anything  I need to do to change the user_config.h?

0 Kudos

479 Views
DavidS
NXP Employee
NXP Employee

Hi Botao,

Attached are my user_config.h and twrk60d100m.h header files for the BSP.

I am using the TWR-SER card to connect DB9 serial interface to my USB2Serial cable so my laptop terminal untility will be my console.

Attached are also pictures of my boards so you may compare jumper settings.

My terminal console :

SD card demo

Shell (build: Apr 13 2015)

Copyright (c) 2013 Freescale Semiconductor;

shell>

shell> Installing MFS over SD card driver...

SD card installed to a:

shell>

shell> dir

SEYMOUR            0 04-30-2015 10:44:24    V  SEYMOUR

shell>

shell> write test1025.txt 1025

shell>

shell> dir

SEYMOUR            0 04-30-2015 10:44:24    V  SEYMOUR

TEST1025.TXT    1025 01-01-1980 00:00:30      A TEST1025.TXT

shell>

shell> type test1025.txt

0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`a

shell>

shell>

Regards,

David