FAT library bug

A forums to allow bugs and problems with Flowcode v7 to be reported and resolved.

Moderator: Benj

leagaston
Posts: 5
Joined: Thu Dec 08, 2016 4:11 pm
Been thanked: 2 times
Contact:

FAT library bug

Postby leagaston » Thu Dec 08, 2016 4:20 pm

Hello, everyone, this is my first post and I am trying to learn how to use Flowcode. I am trying to write an SD card with data for a future maybe to do a data logger. I'm using an Arduino Nano and Flowcode 7. The problem is that I try to write a fixed data, and this is not always the correct one. It seems to be a bug in the FAT library. I tried with different cards and the same thing happens. I attach the program I have used and the file where the result is recorded. I hope someone can help solve this problem. Thanks!
Attachments
logger nano.fcfx
(10.36 KiB) Downloaded 83 times
test.csv
(58.59 KiB) Downloaded 81 times

User avatar
Benj
Matrix Staff
Posts: 14307
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4400 times
Been thanked: 4126 times
Contact:

Re: FAT library bug

Postby Benj » Thu Dec 08, 2016 6:26 pm

Hello,

Yes I see the problem, that's interesting.

I see you are putting 30 bytes into your 30 byte string. What happens if you make some more room in the string variable. Say increase it to at least 31 bytes. This just gives room for the string end null byte which may help.

If this doesn't help then I'll investigate the code and see if I can find any anomalies.

Out of interest have you applied the update here as this contains a FAT component fix.
viewtopic.php?f=63&t=18209

User avatar
Benj
Matrix Staff
Posts: 14307
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4400 times
Been thanked: 4126 times
Contact:

Re: FAT library bug

Postby Benj » Thu Dec 08, 2016 6:41 pm

The error seems to happen right on the boundary of 14 x 512 byte sectors? Hmm...

BinView.jpg
BinView.jpg (42.52 KiB) Viewed 3809 times

leagaston
Posts: 5
Joined: Thu Dec 08, 2016 4:11 pm
Been thanked: 2 times
Contact:

Re: FAT library bug

Postby leagaston » Thu Dec 08, 2016 7:25 pm

Hi, thanks for the prompt reply. I have tried before what you have suggested and the results are the same, anyway I will try again now, to be more sure. I've also noticed that this behavior manifests every 512 bytes, but not always starting at the same offset if I change the length of the string I want to write. Thank you, I will do some tests and I expect some new suggestions.
These users thanked the author leagaston for the post:
Benj (Thu Dec 08, 2016 8:40 pm)
Rating: 5.26%
 

User avatar
Benj
Matrix Staff
Posts: 14307
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4400 times
Been thanked: 4126 times
Contact:

Re: FAT library bug

Postby Benj » Fri Dec 09, 2016 12:01 pm

Hello,

I've had a good look through the code for the append string function and so far I haven't been able to spot anything wrong.

Would it be possible for you to try the AppendByteToFile function and see if that is producing the same problem.

leagaston
Posts: 5
Joined: Thu Dec 08, 2016 4:11 pm
Been thanked: 2 times
Contact:

Re: FAT library bug

Postby leagaston » Sat Dec 10, 2016 2:51 pm

Hello, excuse the delay to answer. I've also tried using AppendByteToFile, and it produces the same error, in addition to being quite slower. I also downloaded version 6 of Flowcode, with equal results ... I also tried using a PIC18F4550 in replacement of the Arduino Nano..and the result is the same ... I hope you can orientate me ... Thanks
These users thanked the author leagaston for the post:
Benj (Mon Dec 12, 2016 1:14 pm)
Rating: 5.26%
 

User avatar
Benj
Matrix Staff
Posts: 14307
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4400 times
Been thanked: 4126 times
Contact:

Re: FAT library bug

Postby Benj » Mon Dec 12, 2016 2:06 pm

Investigating this now for you...

I've managed to replicate the problem but so far I've not found the cause.

The problems always seem to happen after address 7168 which is hex 0x1C00 or file sector 14.

Interestingly if I change the max concurrent files property from 1 to 2 then the error shifts from line 240 to line 385.

Another interesting thing is I changed the byte count from 30 to 32 and the error remained on the same line in the file 240 so it could somehow be down to how many times the function is being called.

One test file brought some of the file header into the file itself which really shouldn't happen and suggests stack corruption. Still investigating...

leagaston
Posts: 5
Joined: Thu Dec 08, 2016 4:11 pm
Been thanked: 2 times
Contact:

Re: FAT library bug

Postby leagaston » Mon Dec 12, 2016 6:24 pm

Hi, thank you very much for the effort. I can not think of any more ideas, this problem is out of my knowledge for now ... so I look forward to some possible solution ... or some suggestion to do tests.

User avatar
Benj
Matrix Staff
Posts: 14307
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4400 times
Been thanked: 4126 times
Contact:

Re: FAT library bug

Postby Benj » Wed Dec 14, 2016 1:50 pm

Hello,

Right I'm still investigating this issue. It seems that writing 256 lines of 30 bytes to a file is fine. Writing the 257th line is what is causing the problems.

If you only write 256 lines to any one file then it should all work correctly.

I'm now trying to work out how/why the 257th call is causing issues.

User avatar
Benj
Matrix Staff
Posts: 14307
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4400 times
Been thanked: 4126 times
Contact:

Re: FAT library bug

Postby Benj » Wed Dec 14, 2016 2:20 pm

Problem now found and fixed.

It seemed the problem occurred when an append function was called and the last sector of the file was perfectly full. The component was writing to the start of the existing end sector rather than creating a new one.

If you copy the attached file to your "Flowcode 7/components" directory and restart Flowcode then the problem should be fixed.

FAT.fcpx
(66.51 KiB) Downloaded 72 times


Let me know how you get on.

User avatar
Benj
Matrix Staff
Posts: 14307
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4400 times
Been thanked: 4126 times
Contact:

Re: FAT library bug

Postby Benj » Wed Dec 14, 2016 6:55 pm

Looks like I spoke too soon, Still investigating but now I get a problem after writing 3532 lines of 30 bytes.

So it's much better but still not perfect. I'll keep investigating...

User avatar
Benj
Matrix Staff
Posts: 14307
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4400 times
Been thanked: 4126 times
Contact:

Re: FAT library bug

Postby Benj » Wed Dec 14, 2016 7:19 pm

Found and fixed.

FAT.fcpx
(67.53 KiB) Downloaded 86 times


I'm going to leave a file of 10 Million lines of 30 bytes writing tonight and fingers crossed this should be fine tomorrow using this latest component.

We shall see...

Edit: Looks good, can't see any more problems.

leagaston
Posts: 5
Joined: Thu Dec 08, 2016 4:11 pm
Been thanked: 2 times
Contact:

Re: FAT library bug

Postby leagaston » Fri Dec 16, 2016 12:25 pm

Hi Ben, great news !!! I've been busy, but with this problem in my head ... hopeful that it could be solved. Right now I'm going to try out my sample program. Thank you so much. :D