FAT library bug

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

Moderator: Benj

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

FAT library bug

Post by leagaston »

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 269 times
test.csv
(56.65 KiB) Downloaded 242 times

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

Re: FAT library bug

Post by Benj »

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.
http://www.matrixtsl.com/mmforums/viewt ... 63&t=18209

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

Re: FAT library bug

Post by Benj »

The error seems to happen right on the boundary of 14 x 512 byte sectors? Hmm...
BinView.jpg
BinView.jpg (42.52 KiB) Viewed 7850 times

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

Re: FAT library bug

Post by leagaston »

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.

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

Re: FAT library bug

Post by Benj »

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

Post by leagaston »

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

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

Re: FAT library bug

Post by Benj »

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

Post by leagaston »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT library bug

Post by Benj »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT library bug

Post by Benj »

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 239 times
Let me know how you get on.

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

Re: FAT library bug

Post by Benj »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: FAT library bug

Post by Benj »

Found and fixed.
FAT.fcpx
(67.52 KiB) Downloaded 241 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

Post by leagaston »

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

Post Reply