/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Write File

Username:     
Password:     
             

Forum

# 1   2009-11-08 16:15:40 Write File

repzak
Member
Registered: 2008-03-05
Posts: 170

Write File

Hello,

Could anybody help me why i can not get the write function to work in circleos 3.8?

It looks like the sector is writen, but the fat tabe is not updated sad

[CODE]
                        // mount MMCSD
                StartMBR=FS_Mount(MMCSD_SDIO);
                if (StartMBR == 0xFFFFFFFF)
                    {
                    DRAW_Puts("\n No SDCARD");
                    return -1;
                    }

                // Open volume on first partition (0)
                if (FS_GetVolumeInfo(0, StartMBR, &volume_info))
                    {
                    DRAW_Puts("\nErr: GetVolInfo");
                    return -1;
                    }

                //Open selected file
                if (FS_OpenFile(&volume_info, "test2.txt",FS_WRITE, &file_info))
                    {
                    DRAW_Puts("\n Err op: File");
                    return MENU_Quit();
                    } 
       
       
       
        write_length =6;
       // FS_WriteFile (&file_info, (u8 *)ylog , &write_length,sizeof(ylog));
        FS_WriteFile (&file_info,(u8 *)"testte", &write_length,6);
       
       
        FS_Close (&file_info);
                FS_Unmount (MMCSD_SDIO);
[\CODE]

Offline

 

# 2   2009-11-09 07:10:22 Write File

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Write File

Hi Kazper,

Are you saying that the function does not work yet with 3.8 version of CircleOS ?

Offline

 

# 3   2009-11-09 08:42:24 Write File

repzak
Member
Registered: 2008-03-05
Posts: 170

Re: Write File

Hello,

I am not sure, since this is my first write project sad

But the Code above seems to create a sector with the text from the code + some text afterwards "requires circle os"..?

In the file browser window somtimes a txt file is showed but can not be opened, so seems like the file is not closed and FAT table updated.

The write length is updated with 6, as the file seems written ok.. i only set the variable to 6 before write as a test, so that is verified.

I use a 128Mb card i have used before to play MP3 files from, but only read.

1 thing i actually did not verify is the version is 3.8, but i uninstalled ride+arm and installed new one from the website... so i believe the right version was copied.

Maybe you could help me to verify my code in a new project, and if it works, send me a copy?

Thanks
Kasper

Last edited by repzak (2009-11-09 08:42:35)

Offline

 

# 4   2009-11-09 11:25:58 Write File

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Write File

Hi Kazper,

I checked your code into a virgin CircleOS application, and I saw you forgotten to open the root directory, before creating the file.

Here is my "MENU_code Application_Ini" code :

[CODE]

    VOLINFO volume_info;
    DIRINFO directory_info;
    DIRENT directory_entry;
    FILEINFO file_info;
    u32 StartMBR;
   
    // Ensure that the current OS version is recent enough
    if(strcmp(UTIL_GetVersion(), NEEDEDVERSION) < 0)
        {
        return MsgVersion();
        }

    // mount MMCSD
    StartMBR=FS_Mount(MMCSD_SDIO);
    if (StartMBR == 0xFFFFFFFF)
        {
        DRAW_Puts("\n No SDCARD");
        return -1;
        }

    // Open volume on first partition (0)
    if (FS_GetVolumeInfo(0, StartMBR, &volume_info))
        {
        DRAW_Puts("\nErr: GetVolInfo");
        return -1;
        }

    // Open root directory
    if (FS_OpenDirectory(&volume_info, "", &directory_info))
       {
       DRAW_Puts("\nErr: Open Root");
       return -1;
       }

    //Open selected file
    if (FS_OpenFile(&volume_info, "test2.txt",FS_WRITE, &file_info))
        {
        DRAW_Puts("\n Err op: File");
        return MENU_Quit();
        } 
       
    u32 write_length =6;
    // FS_WriteFile (&file_info, (u8 *)ylog , &write_length,sizeof(ylog));
    FS_WriteFile (&file_info,(u8 *)"testte", &write_length,6);

    FS_Close (&file_info);
    FS_Unmount (MMCSD_SDIO);

[\CODE]

So the file appeared on the windows explorer and can be opened, and visualized.
I checked with success with CircleOS v3.8 and both a 64Mb and a 2Gb SDCard.

For write example on a SDCard, take a look to the "Dictaphone" example.

Regards,
Yves

Offline

 

# 5   2009-11-09 11:35:15 Write File

repzak
Member
Registered: 2008-03-05
Posts: 170

Re: Write File

Hello,

Thank you very much smile

I think the dictaphone is litle confused due to the code is splitted up in several sections.

Maybe i will just make a quick project and upload.

Thanks again

Kasper

Offline

 

# 6   2009-11-09 18:51:01 Write File

repzak
Member
Registered: 2008-03-05
Posts: 170

Re: Write File

Hello,

Seems like it is the 128mb SD card it does not like sad 2GB working fine...

I tried to make 1 new file test2.txt, then change the code to tes3.txt, then i expected 2 files to be on the sd card, but it deletes the first and make a new file.... anyone knows this issue?

Kaser

Offline

 

# 7   2009-11-10 07:39:33 Write File

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Write File

Hi,

May be you should format your 128Mb card on your PC, before using it again ?
Anyway, it seems that there is some recurrent problems about FS_Write().
Take a look at this posts :
http://www.stm32circle.com/forum/viewtopic.php?id=684
http://www.stm32circle.com/forum/viewtopic.php?id=867
It seems that anybody found the solution !

Yves

Offline

 

Board footer