sdcard write error

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

sdcard write error

1,457 次查看
jackerison
Contributor III

Hi everyone,

     I have a trouble about sdcard writing in MQX4.1,and my platform is k60d100m.I write somedata to a csv file, but sometimes later the file can't be opended, and the file pointer is NULL.

When I inserted the sdcard to my computer,I foud the file is error, it can't be deleted or copied.The only soultion is delete the via the shell command of my board.So it can write again,but it will occuer again.

I used the "C:\Freescale\Freescale_MQX_4_1\mfs\examples\sdcard\build\iar\mfs_sdcard_twrk60d100m" project to test the sdcard.Here is my code.

int32_t Shell_command_filetest(int32_t argc, char *argv[])

{

    MQX_FILE_PTR    fd_ptr;

    int32_t error_code;

    int i, j;

        

    fd_ptr = fopen("a:/my1.csv", "a");

    if(NULL == fd_ptr)

    {

        printf("open a:/my1.csv error!\n");

    }

   

    for( i =0; i< 3000; i++)

    {

      //for(j=0; j<100; j++)

      {

        fputc((0x30+j%10), fd_ptr);        //

        fputc(0x09, fd_ptr);

        //write(fd_ptr,"0123456789",10);

      }

      fputc(0x0D, fd_ptr);

    }

   

    /* Close the file: */

    error_code = fclose(fd_ptr);

 

  return 0;

}

/*TASK*-----------------------------------------------------------------

*

* Function Name  : sdcard_task

* Returned Value : void

* Comments       :

*

*END------------------------------------------------------------------*/

void sdcard_task(uint32_t temp)

{

    (void)          temp; /* suppress 'unused variable' warning */

    sdcard_init();

    char **argv;

    for(;;)

    {

        if(true ==sdcard_check())

        {

            write_inv_hist_head("love");

            //Shell_command_filetest(0,argv);

        }

        _time_delay (100);

    }

}

The attachment is my whole test code.

Original Attachment has been moved to: demo.c.txt.zip

0 项奖励
回复
6 回复数

1,061 次查看
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi Jack,

You might be fulfilling the buffers too fast and there is no time for MQX to write them down. I would recommend to try a fflush() on every loop.

Hope this solves the issue. If don't then an open/close on every loop can help as well. The inconvenience of that is the extra time/processing you will need to perform.


Regards,
Garabo

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

1,061 次查看
jackerison
Contributor III

Hi Garabo,

     I test it again,but maybe it's not the reason.Because when I restart the board,it would open the file fail again at the beginging.And my problem is the "Shell_command_filetest" can write a file to 100MB,but the "write_inv_hist_head" only can write to 5 MB.I realy don't know this why.

int32_t write_inv_hist_head(uint8_t *name)

{

    MQX_FILE_PTR fd_ptr;

    _mqx_int     error_code;

   

    uint8_t file_name[32]={0};

    uint8_t data_buffer[200]={0};

    sprintf(data_buffer,

            "SN.,Time,"

            "Pdc,Pac,Sac,Qac,"

            "Status,Error_msg,Warn_msg,"

            "E_today,E_total,H_total,"

            "Vpv1,Vpv2,Vpv3,"

            "Ipv1,Ipv2,Ipv3,"

            "Vac_r,Vac_s,Vac_t,"

            "Iac_r,Iac_s,Iac_t,"

            "Temp1,Temp2,Cosphi\r\n");

    sprintf(file_name,"a:/%s.csv",name);

    /* Open file on disk in the current directory and write to it: */

    fd_ptr = fopen(file_name, "a");

    if(NULL == fd_ptr)

    {

        printf("open %s error!\n",file_name);

        return 0;

    }

     write(fd_ptr, data_buffer, strlen(data_buffer));

    /* Close the file: */

    error_code = fclose(fd_ptr);

    return 0;

}

0 项奖励
回复

1,061 次查看
jackerison
Contributor III

Hi Garabo,

     Thanks your reply,but i don't think it's the problem.Because when the file reach the size,it would open fail.if I restart the board it will open fail again at the begining.The "Shell_command_filetest" function can write a file reach to 100MB,but the "write_inv_hist_head" function can only write to 5MB.The following is the "write_inv_hist_head" function.

0 项奖励
回复

1,061 次查看
juanandujar
Contributor I

I have read this thread and I have a similar trouble .

I am testing  the twr-k60120 with the mqx OS. I am loading the example code which provides mqx (mqx4.1/mfs/sdcard). The point is that I get an error when I run this example.

Concretly in this line : 

"filesystem_handle = fopen(filesystem_name, NULL);"

with the answer

Error opening filesystem: Unknown error .

I am using a micro sd card without any partition ,namely, it is fully formatted  in FAT32 and empty.

I don't know if the sd card has to be set up before starting with a partition or doing anything before.

Someone could help with this issue.

BR.

0 项奖励
回复

1,061 次查看
Luis_Garabo
NXP TechSupport
NXP TechSupport

Hi Juan,

Have you tried different memories? Different formats? Have you tried to debug and take a look to the TAD to find what is the error the task is reporting?


Regards,
Garabo

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复

1,061 次查看
juanandujar
Contributor I

Yesterday, I rebuild the mqx 4.1 and I have configured new features on the user_config.h. Then I tried to run it again and it seems to work properly.

Anyway, tk for your fast reply.

BR

0 项奖励
回复