I am trying to use MFS to creat a file in SD card ,
I have run the demo project mfs_sdcard twrk60d100m, it does not work; then I add a line
"
fd_ptr = fopen("a:myfile.txt","w+"); |
"
in the project(this is learned from the MQX MFS Manual), this does not work too.
so I am preatty confused of using the MFS to creat a file.
I am using TWR K60D100m, Codewarrior10.6, MQX4.1
Hi Botao,
Please review the C:\Freescale\Freescale_MQX_4_1_1\demo\web_hvac project.
It has option to log data to USB stick but the process would be same if modified to use SD Card.
I'm attaching the logging_task.c file for reference.
Note it uses "a" and not "w+". I think I recall that version of MQX might have had issue with using "w+".
Regards,
David
Now, I think my problem can be more specific.
By my understanding, the process of using MFS over SD card is like this :
(1) install ESDHC driver;
(2) get the device pointer of SD card;
(3) install MFS over SD card;
(4) use MFS;
In this order, I have write a test MQX project, the main progress is as follows. the test result is I can not open the MFS by using this "MFS_fd = fopen("a:",NULL);", also the MFS installing progress returns a successful result wihout insert a SD card. still creating a file in SD card is failed, even using "a".
I am seeking the cause of this problem desperately, please pay enough attention to my question and give me same useful tips. I am anxious of this , for this problem have delayed the progress of my project.
thank you very much.
FILE_PTR esdhc_fd,MFS_fd;
ESDHC_COMMAND_STRUCT command;
bool sdhc;
_mqx_int error_code;
uint32_t param,rca,sector;
uint8_t buffer[512];
printf("*********************************\n");
printf("******sd card test project*******\n");
printf("*********************************\n");
esdhc_fd = fopen("esdhc:",NULL);
if(NULL==esdhc_fd)
{
printf("open esdhc failed.\n");
}
else
{
printf("open esdhc successed.\n");
}
/* Initialize and detect card */
if (ESDHC_OK != ioctl (esdhc_fd, IO_IOCTL_ESDHC_INIT, NULL))
{
printf("init esdhc failed.\n");
}
else
{
printf("init esdhc successed.\n");
}
/* SDHC check */
sdhc = FALSE;
param = 0;
if (ESDHC_OK != ioctl (esdhc_fd, IO_IOCTL_ESDHC_GET_CARD, ¶m))
{
printf("find no sd card.\n");
}
if ((ESDHC_CARD_SD == param) || (ESDHC_CARD_SDHC == param) || (ESDHC_CARD_SDCOMBO ==
param) || (ESDHC_CARD_SDHCCOMBO == param))
{
if ((ESDHC_CARD_SDHC == param) || (ESDHC_CARD_SDHCCOMBO == param))
{
sdhc = TRUE;
printf("find a sd card.\n");
}
}
else
{
/* Not SD memory card */
printf("find no sd card.\n");
}
/* Install MFS over SD card driver */
error_code = _io_mfs_install(esdhc_fd, "a:", (_file_size)0);
if ((error_code != MFS_NO_ERROR)&&(error_code != MFS_NOT_A_DOS_DISK))
{
printf("Error initializing MFS: %s\n", MFS_Error_text((uint32_t)error_code));
}
else
{
printf("intalll MFS over SD card successed.\n");
}
MFS_fd = fopen("a:",NULL);
if(NULL==MFS_fd)
{
printf("open MFS failed.\n");
}
else
{
printf("open MFS successed.\n");
}
fopen("a:myfile.txt","a");