/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / File write woes again...

Username:     
Password:     
             

Forum

# 1   2010-01-17 19:55:52 File write woes again...

logictechs
Member
Registered: 2009-05-07
Posts: 68

File write woes again...

Hi,

Trying to write a file about 56K in size not all at once because of the apparent memory size limit for and unsigned char variable.  I'm getting the glitches again.  Has anyone looked into this more and come up with an absolute tried and true solution?

Thanks,

LOGICTECHS

Offline

 

# 2   2010-01-25 00:48:32 File write woes again...

logictechs
Member
Registered: 2009-05-07
Posts: 68

Re: File write woes again...

Ok, I think I solved my write to file problem.  The trick is you need to have a buffer of a size 1 more than you really need and write it.  Then seek to the end of file - 1 to write your next chunk of data.  Here's an example that works assuming you've already opened a file:

u8 txt[1001];  // filled with whatever data
u32 cnt;  // byte counter for filling the txt variable

if(cnt == 1000)
        {   
            cr = FS_WriteFile(&file_info, &txt[0] , &successcount, cnt + 1);
            FS_Seek(&file_info, file_info.filelen - 1 );           
            cnt = 0;     
        }

Offline

 

Board footer