microsoft / pxt-filesystem

File system - beta
https://pxt.microbit.org/pkg/microsoft/pxt-filesystem
MIT License
28 stars 18 forks source link

Corruption writing to file with accelerometer example #6

Closed simonmorrish closed 6 years ago

simonmorrish commented 7 years ago

When using the accelerometer example on the GitHub page, and reading the serial data using TeraTerm, the received data is corrupted, as enclosed. It looks to me like the kind of symptom you'd get with concurrent write access to the file or pointer overruns, but it may have another cause, of course. I don't believe it is corruption on reception of the serial data, because the string "MICROBIT_FS_1 " appears in the data, and it is hard to explain that except by corruption during either reading or writing the file.

Time    Acceleration
4580    704
4653    704
4658    672
4663    672
4735    720
4740    720
4813    720
4818    720
4891    688
ÿÿ      688ÿ!ÿÿÿ        ÿÿIÿ4973        %ÿ
ÿÿÿ•688
ÿÿïÿ    656ÿ=ÿÿÿ        656
5169    656
5174    656
5268    624
5273    624
5366    656
5371    656
5375    688
5470    624
5475    624
5569    672
5574    672
5668    640
5673    640
5767    624
5772    624
5776    624
5870    640
5875    640
5969    640
5974    ÿÿÿ6068 !ÿ
ÿÿÿI640
ÿ%ÿ     640ÿ•ÿÿÿ        640ÿ6177        =ÿ
6270    640
6275    640
6369    640
6374    640
6468    624
6473    624
6567    640
6572    640
6576    640
6670    624
6675    640
6770    640
6776    640
6870    640
6879    640
6972    624
6977    624
6981    624
7075    640
7080    640
7MICROBIT_FS_1  0@œ624
7277    624
7371    624
7376    640
7381    640
7475    640
7480    640
7574    640
7579    640
7673    624
7678    624
7772    640
7777    640
7781    640
7875    624
7880    624
7974    624
7979    640
8073    640
8079    640
8173    640
8179    640
8186    640
8280    62Time  Acceleration
                                8153    16
8158    16
8230    16
8235    16
8239    16
8312    112
8316    112
8388    32
8393    32
8465    32
8470    32
8542    32
                8546    32
8550
pelikhan commented 7 years ago

Could you share project in PXT and post the URL in this bug?

Tolyzor commented 7 years ago

This bug affects me too. Corruption begins at data index 116 when printed to serial, and becomes more prevalent after that: https://pxt.microbit.org/55832-64036-02150-34008

I get the corruption simonmorrish showed at line 25 and on using the file append line to write strings: https://pxt.microbit.org/96921-93818-70560-16976

Tolyzor commented 7 years ago

Two workarounds to the bug: 1) Output the data as two rows with multiple columns, rather than two columns with multiple rows: something about appendLine makes it cause corruption much sooner than appendString 2) Remove the radio or bluetooth package from the javascript explorer, the corruption starts later, at line 300 or so

Datalogging example storage strategy improvement (not related to filesystem bug): 1) Don't save timestamps in flash storage, generate them during data upload to save space

This example datalogging code can record 1300 samples, corruption free, using these three workarounds: https://pxt.microbit.org/04221-99382-95740-17742

pelikhan commented 6 years ago

Corruption is fixed through new heap allocator. Indeed BLE stack was silently corruption heap.