/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / FS_WriteFile

Username:     
Password:     
             

Forum

# 1   2009-02-27 11:04:40 FS_WriteFile

andriams
New member
Registered: 2009-01-21
Posts: 4

FS_WriteFile

Hello
I tried to use this function but when i call it, the application freeze. I used FS_opendirectory with Write mode.

Offline

 

# 2   2009-02-27 22:07:34 FS_WriteFile

sjoerd
Member
From: Stad aan het Haringvliet
Registered: 2008-09-04
Posts: 65

Re: FS_WriteFile

I'm seeing similar things here. Sometimes a file is written and sometimes it hangs in the SDIO driver.

A quick look shows that for some reason the IRQ prio isn't set (or I can't find it)

You can put it in the app init function for testing:
NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

Perhaps Timer2 causes some problems here as well (also in USB MS).
I haven't tried disabling Timer2.. will do that asap

Offline

 

# 3   2009-02-28 14:47:39 FS_WriteFile

andriams
New member
Registered: 2009-01-21
Posts: 4

Re: FS_WriteFile

here is my code:
void store(char *Filename)
{
    FILEINFO file_info;
    u32 bread,res;
    u8 file[MAX_PATH_LENGTH];
    u8 *header="HELLO";
    u32 i=0;

    if (res=FS_OpenFile(&volume_info, Filename, FS_WRITE, &file_info))
   {
        DRAW_DisplayString(0,120,"Err op: Op",13);
        return;
   }

   FS_WriteFile(&file_info,header, &i, strlen(header));
   DRAW_DisplayString(0,10,header,strlen(header));
}
I'd like to write the header on my file but it doesn't works on my primer 2

Offline

 

# 4   2009-03-01 14:46:59 FS_WriteFile

sjoerd
Member
From: Stad aan het Haringvliet
Registered: 2008-09-04
Posts: 65

Re: FS_WriteFile

The following code works fine for me: (i'm using CircleOs v3.6)

in the App init handler:

Code:

      NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQChannel;
      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
      NVIC_Init(&NVIC_InitStructure);

Main code:

Code:

        TIM_Cmd( TIM2, DISABLE );
      
        // fille buffer with some data
        for (i=0;i<240;i++)
        {
          DataBuffer[i] = (u8) i;   
        }
        memset((void *) &file_info,0,sizeof(file_info));
        retval = FS_OpenFile(&volume_info,"TEST2.TXT",FS_WRITE,&file_info);
        retval = FS_WriteFile(&file_info,DataBuffer,&count,200);
        retval = FS_Seek(&file_info,0);

        // verify written data in memory debug window
        memset(DataBuffer,0,sizeof(DataBuffer));
        retval = FS_ReadFile(&file_info,DataBuffer,&count,200);

        /* TIM2 enable counter */
        TIM_Cmd( TIM2, ENABLE );

In a couple of tests i've seen that fat entries are overwritten so files already on MMCSD card are lost! I'll do some furthur investigation

Offline

 

# 5   2009-03-01 16:14:36 FS_WriteFile

andriams
New member
Registered: 2009-01-21
Posts: 4

Re: FS_WriteFile

Thank you for your answer this is my test for storing data :

Code:

enum MENU_code Application_Ini ( void )
    {
        NVIC_InitTypeDef* NVIC_InitStruct;
       
   if(strcmp(UTIL_GetVersion(), NEEDEDVERSION) < 0)
   {
      return MsgVersion();
   }       
   ///////
    NVIC_InitStruct->NVIC_IRQChannel = SDIO_IRQChannel;
  NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStruct->NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStruct->NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStruct);
  ///////
test();

    return MENU_CONTINUE_COMMAND;
    }

void test()
{
    int i,count;
    u8 DataBuffer[240];
      FILEINFO file_info;
   u32 retval;

  TIM_Cmd( TIM2, DISABLE );
      
        // fille buffer with some data
        for (i=0;i<240;i++)
        {
          DataBuffer[i] = (u8) i;   
        }
        memset((void *) &file_info,0,sizeof(file_info));
        retval = FS_OpenFile(&volume_info,"TEST2.TXT",FS_WRITE,&file_info);
        retval = FS_WriteFile(&file_info,DataBuffer,&count,200);
        retval = FS_Seek(&file_info,0);

        // verify written data in memory debug window
        memset(DataBuffer,0,sizeof(DataBuffer));
        retval = FS_ReadFile(&file_info,DataBuffer,&count,200);

        // TIM2 enable counter 
        TIM_Cmd( TIM2, ENABLE );
    

}

When i comment the test function it works but when i use it, TEXT2 file is created but it cannot be open and the application crashes. Do you think it's a problem of SDCard? I use CircleOS 3.6 too

Last edited by andriams (2009-03-01 16:16:55)

Offline

 

# 6   2009-03-01 17:40:00 FS_WriteFile

sjoerd
Member
From: Stad aan het Haringvliet
Registered: 2008-09-04
Posts: 65

Re: FS_WriteFile

You should also mount the MMCSD card in the init function like this:

Code:

 
   u32 StartMBR;

 // mount MMCSD 
   StartMBR=FS_Mount(MMCSD_SDIO);   

      NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQChannel;
      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
      NVIC_Init(&NVIC_InitStructure);


   if (StartMBR == 0xFFFFFFFF)
   {
       DRAW_DisplayString(0,100,"No SDCARD",19);
       return MENU_CONTINUE_COMMAND;
   }

   // Open volume on first partition (0)
   if (FS_GetVolumeInfo(0, StartMBR, &volume_info))
   {
     DRAW_DisplayString(0,100,"Err: GetVolInfo",15);
     return MENU_CONTINUE_COMMAND;
   }

   // Open root directory
   if (FS_OpenDirectory(&volume_info, "", &directory_info))
   {
     DRAW_DisplayString(0,100,"Err: Open Root",15);
     return MENU_CONTINUE_COMMAND;
   }

Offline

 

# 7   2009-03-01 20:06:32 FS_WriteFile

andriams
New member
Registered: 2009-01-21
Posts: 4

Re: FS_WriteFile

it works finally thank you so much !!!!!!!! great!!!!

Offline

 

Board footer