Page 1 of 1

FAT library bug

Posted: Thu Dec 08, 2016 4:20 pm
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!

Re: FAT library bug

Posted: Thu Dec 08, 2016 6:26 pm
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.flowcode.co.uk/mmforums/viewt ... 63&t=18209

Re: FAT library bug

Posted: Thu Dec 08, 2016 6:41 pm
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 9328 times

Re: FAT library bug

Posted: Thu Dec 08, 2016 7:25 pm
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.

Re: FAT library bug

Posted: Fri Dec 09, 2016 12:01 pm
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.

Re: FAT library bug

Posted: Sat Dec 10, 2016 2:51 pm
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

Re: FAT library bug

Posted: Mon Dec 12, 2016 2:06 pm
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...

Re: FAT library bug

Posted: Mon Dec 12, 2016 6:24 pm
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.

Re: FAT library bug

Posted: Wed Dec 14, 2016 1:50 pm
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.

Re: FAT library bug

Posted: Wed Dec 14, 2016 2:20 pm
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 327 times
Let me know how you get on.

Re: FAT library bug

Posted: Wed Dec 14, 2016 6:55 pm
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...

Re: FAT library bug

Posted: Wed Dec 14, 2016 7:19 pm
by Benj
Found and fixed.
FAT.fcpx
(67.52 KiB) Downloaded 374 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.

Re: FAT library bug

Posted: Fri Dec 16, 2016 12:25 pm
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