/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / FS_WriteFile() errors

Username:     
Password:     
             

Forum

# 1   2009-05-17 16:38:56 FS_WriteFile() errors

cwstoesz
New member
Registered: 2009-04-26
Posts: 5

FS_WriteFile() errors

I have noticed that there are errors with FS_WriteFile in CircleOS 3.7. 
This code works:
    u8 B[] = {'B','M','Z','U'};
    filepointer = 0;      // Initialize seek pointer
    FS_Seek(&file_info, filepointer);               // Set file to filepointer
    cr = FS_WriteFile(&file_info,&B, &successcount, 2); //Write data to file
    filepointer += 2;

This does not:
    u8 B[] = {'B','M'};
    filepointer = 0;      // Initialize seek pointer
    FS_Seek(&file_info, filepointer);               // Set file to filepointer
    cr = FS_WriteFile(&file_info,&B, &successcount, 2); //Write data to file
    filepointer += 2;

The only difference is the length of the array B[].  I found that if I assign B[] 4 bytes then FS_WriteFile() will properly write 2 bytes.  If I assign B[] only 3 bytes then only the first byte gets written.

Has anyone else run into this?

Last edited by cwstoesz (2009-05-17 17:54:24)

Offline

 

# 2   2009-05-18 02:44:22 FS_WriteFile() errors

jetcode
Member
Registered: 2009-04-03
Posts: 49

Re: FS_WriteFile() errors

'B' is already a pointer in both cases, the correct code should be &B[0] or B but not &B which as far as I can remember is a pointer to a pointer not pointer to an array. The file pointer increment code is wrong too. It should be += cr since the number of bytes written is returned for the write call.

Last edited by jetcode (2009-05-18 02:46:27)

Offline

 

# 3   2009-05-18 06:51:29 FS_WriteFile() errors

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: FS_WriteFile() errors

There are some messages about this issue:
http://www.stm32circle.com/forum/viewtopic.php?id=634
It seems that writing less than 512 bytes could be an issue.

Cwstoesz, did you define your array as automatic, or as a global variable ?
In any case, what you report seems very strange and looks more than a random side effect.

Offline

 

# 4   2009-05-18 12:43:25 FS_WriteFile() errors

cwstoesz
New member
Registered: 2009-04-26
Posts: 5

Re: FS_WriteFile() errors

I understand about the pointer.  I was trying just about anything I could think of to get it to work.

The array is locally defined.  I tried it with a structure array but couldn't get that to work at all. 

It is acting like somewhere there is a 4 byte buffer that isn't being flushed until full.

Offline

 

# 5   2009-05-18 16:47:35 FS_WriteFile() errors

jetcode
Member
Registered: 2009-04-03
Posts: 49

Re: FS_WriteFile() errors

I am going to do some testing on a modified version of the DFS this morning. I will be testing the case you presented above. I will let you know what I find.

Offline

 

# 6   2009-05-19 05:33:20 FS_WriteFile() errors

jetcode
Member
Registered: 2009-04-03
Posts: 49

Re: FS_WriteFile() errors

The problem is in the ST SD card library. The library uses 32 bit DMA for maximum efficiency. The number of 32 bit words to write is the number of bytes divided by 4. If the number of bytes to write is less than 4 the number of 32 bit words to write is 0. The data is dropped.

Last edited by jetcode (2009-05-19 05:34:41)

Offline

 

# 7   2009-05-19 06:31:16 FS_WriteFile() errors

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

Re: FS_WriteFile() errors

Hello,

Can this be the same for read??

Kasper

Offline

 

# 8   2009-05-19 13:11:46 FS_WriteFile() errors

cwstoesz
New member
Registered: 2009-04-26
Posts: 5

Re: FS_WriteFile() errors

jetcode, that is what I thought based on the way it was acting.  Thanks!!!

Offline

 

# 9   2009-05-19 15:37:44 FS_WriteFile() errors

jetcode
Member
Registered: 2009-04-03
Posts: 49

Re: FS_WriteFile() errors

Not so fast ... I went back this morning to verify and it appears the correct block size is being programmed (no divide by 4 as I first witnessed where is it I swear I saw it!).

I will post more as I discover more. I frequently make mistakes after a full day of surfing a new codebase.

Offline

 

# 10   2009-05-23 16:45:44 FS_WriteFile() errors

cwstoesz
New member
Registered: 2009-04-26
Posts: 5

Re: FS_WriteFile() errors

I have tried writing larger blocks of data (54 bytes).  What I have observed is that unless the data blocks are 4 bytes long there is a problem (56 bytes is good).   You can write any length you desire, but the data sent to be written must be in 4 byte blocks.

Offline

 

# 11   2009-05-25 04:06:19 FS_WriteFile() errors

jetcode
Member
Registered: 2009-04-03
Posts: 49

Re: FS_WriteFile() errors

this is most likely because the DMA is programmed to transfer in 32 bit integers

Offline

 

# 12   2009-05-25 22:19:12 FS_WriteFile() errors

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

Re: FS_WriteFile() errors

Hello,

Seems like we have same problem for the read, after long debugging i find the DMA transfer adress set to 0x20002B36, but it starts the DMA transfer at 20002B34, and therefore am i missing 2 bytes...

We just now need to find a solution for the problem, since i think we found the cause...

Kasper

Offline

 

# 13   2009-05-28 15:51:31 FS_WriteFile() errors

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

Re: FS_WriteFile() errors

All guys,

It seems that different problems appear around the filesystem functions (sectors size, 32 bits alignment, delete file..).
We would integrate into a new CircleOS version, a good new version of the filesystem, but the modifications to do are confused for us.
A synthesis of the situation will help us (problem list and associated fix).

Thanks for your contribution.

Yves

Offline

 

# 14   2009-05-28 15:53:23 FS_WriteFile() errors

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

Re: FS_WriteFile() errors

Hello,

I think many of the problems also relates to the SDIO driver when using DMA

Kasper

Offline

 

# 15   2009-05-30 00:42:03 FS_WriteFile() errors

jetcode
Member
Registered: 2009-04-03
Posts: 49

Re: FS_WriteFile() errors

In the next few weeks I will spend some more time with this.

Offline

 

# 16   2009-09-14 06:59:31 FS_WriteFile() errors

kubark42
Member
Registered: 2009-02-13
Posts: 46

Re: FS_WriteFile() errors

Hi, this might be a little late, but I think that in this post I might have solved your problem. I give code for a very easy modification to the sector variable, one that forces it to the 32-bit boundary. This is a bug in fs.c, and thus needs to be fiixed in CirlceOS (if it hasn't already).

EDIT: Nope, it hasn't been fixed yet. Francis, shouldn't this find it's way into an update of CircleOS?

Last edited by kubark42 (2009-09-14 07:04:23)

Offline

 

# 17   2009-09-14 10:35:29 FS_WriteFile() errors

cwstoesz
New member
Registered: 2009-04-26
Posts: 5

Re: FS_WriteFile() errors

Thanks.  I did the same thing in my code, force the write on a 32 bit boundry.  It solved all the write issues.  I have an even stranger lcd read issue I should probably post.

Offline

 

# 18   2009-09-15 15:46:53 FS_WriteFile() errors

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

Re: FS_WriteFile() errors

Hi,

We will take this fix into account for the next release of the CircleOS (probably the 4.0 version).

Thanks.

Offline

 

Board footer