SD card and FAT16

According to the beginners guide FEZ can handle both FAT16 and FAT32 but Im running in to problems with SD cards formatted with as FAT16.

On a SD card I have a text file named Waypoint.txt that has 231 lines of GPS coordinates (with line number in column 2). Ill paste the complete file at the end of this post.

When reading specific line numbers I ran in to problems and had a hard time resolving them. It seems that a SD card formatted as FAT16 (default unit size) gives an error on reading some lines like this;
W 057 058.86546!:05.80380
W 076 058.8624!:005.80023
W 095 058.862!: 005.80280
W 114 058.86!:5 005.80669
W 133 058.8!:05 005.80793
W 152 058.!:419 005.80501
W 171 058!:6539 005.80905
W 190 05!:86652 005.81224

As you can see there is a ‘!: shifting to the left??

If I formatted the SD with FAT32 (default unit size) the reading of the file is flawless. I have tried two different SD cards and they behave the same. With FAT16 errors occurs and with FAT32 it works fine. I have done several reformattings and the errors seems consistent.

This is my test program. (running on a FEZ Domino on a tinkerer board)


using System;
using System.Threading;
using System.Text;
using System.IO;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;

namespace SD_ReadTest
{
    public class Program
    {
        public static PersistentStorage sdPS;
        public static string WPfileName;
        public static int WPcount = 0;
        public static int CurrentWPno;

        public static void Main()
        {
            Debug.EnableGCMessages(false);
            Mount();
            WPcount = GetWPcount();


            for (CurrentWPno = 0; CurrentWPno < WPcount; CurrentWPno++)
            {
                Debug.Print(GetWP(CurrentWPno));
            }

            UnMount();

            Thread.Sleep(-1);
        }

        static string GetWP(int WPno)
        {
            byte[] data = new byte[25];
            FileStream FileHandle = new FileStream(WPfileName, FileMode.Open, FileAccess.Read);

            FileHandle.Position = 27 * WPno;
            int read_count = FileHandle.Read(data, 0, data.Length);
            FileHandle.Close();
            string line = new string(Encoding.UTF8.GetChars(data), 0, read_count);
            
            return line;
        }

        static int GetWPcount()
        {
            int Count = 0;
            FileInfo f = new FileInfo(WPfileName);
            Count = (int)(f.Length + 2) / 27;
            return Count;
        }


        static void Mount()
        {
            sdPS = new PersistentStorage("SD");
            sdPS.MountFileSystem();
            string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
            WPfileName = rootDirectory + @ "\Waypoint.txt";
        }

        static void UnMount()
        {
            sdPS.UnmountFileSystem();
            sdPS.Dispose();
        }


    }
}


Is there a problem with my code or can anyone verify this?

This is the Waypoint.txt file

H 000 058.87178 005.81159
L 001 058.87178 005.81159
W 002 058.87133 005.81008
W 003 058.87089 005.81019
W 004 058.87083 005.80934
W 005 058.87032 005.80860
W 006 058.86982 005.80786
W 007 058.86988 005.80872
W 008 058.86944 005.80884
W 009 058.86938 005.80798
W 010 058.86893 005.80810
W 011 058.86899 005.80896
W 012 058.86905 005.80981
W 013 058.86861 005.80993
W 014 058.86855 005.80908
W 015 058.86849 005.80822
W 016 058.86843 005.80736
W 017 058.86798 005.80748
W 018 058.86754 005.80760
W 019 058.86710 005.80772
W 020 058.86665 005.80784
W 021 058.86621 005.80796
W 022 058.86659 005.80698
W 023 058.86704 005.80686
W 024 058.86748 005.80674
W 025 058.86792 005.80663
W 026 058.86786 005.80577
W 027 058.86837 005.80651
W 028 058.86887 005.80724
W 029 058.86931 005.80713
W 030 058.86925 005.80627
W 031 058.86881 005.80639
W 032 058.86875 005.80553
W 033 058.86830 005.80565
W 034 058.86824 005.80480
W 035 058.86780 005.80491
W 036 058.86774 005.80406
W 037 058.86723 005.80332
W 038 058.86685 005.80430
W 039 058.86730 005.80418
W 040 058.86736 005.80503
W 041 058.86742 005.80589
W 042 058.86697 005.80601
W 043 058.86691 005.80515
W 044 058.86653 005.80613
W 045 058.86609 005.80624
W 046 058.86647 005.80527
W 047 058.86641 005.80441
W 048 058.86603 005.80539
W 049 058.86597 005.80453
W 050 058.86552 005.80465
W 051 058.86590 005.80368
W 052 058.86635 005.80356
W 053 058.86679 005.80344
W 054 058.86673 005.80258
W 055 058.86629 005.80270
W 056 058.86584 005.80282
W 057 058.86546 005.80380
W 058 058.86502 005.80391
W 059 058.86457 005.80403
W 060 058.86451 005.80318
W 061 058.86496 005.80306
W 062 058.86540 005.80294
W 063 058.86534 005.80208
W 064 058.86489 005.80220
W 065 058.86445 005.80232
W 066 058.86439 005.80147
W 067 058.86483 005.80135
W 068 058.86433 005.80061
W 069 058.86395 005.80158
W 070 058.86388 005.80073
W 071 058.86344 005.80085
W 072 058.86338 005.79999
W 073 058.86382 005.79987
W 074 058.86332 005.79914
W 075 058.86288 005.79925
W 076 058.86249 005.80023
W 077 058.86205 005.80035
W 078 058.86167 005.80132
W 079 058.86173 005.80218
W 080 058.86211 005.80120
W 081 058.86256 005.80108
W 082 058.86294 005.80011
W 083 058.86300 005.80097
W 084 058.86350 005.80170
W 085 058.86356 005.80256
W 086 058.86401 005.80244
W 087 058.86407 005.80330
W 088 058.86413 005.80415
W 089 058.86363 005.80341
W 090 058.86318 005.80353
W 091 058.86312 005.80268
W 092 058.86306 005.80182
W 093 058.86262 005.80194
W 094 058.86217 005.80206
W 095 058.86268 005.80280
W 096 058.86274 005.80365
W 097 058.86230 005.80377
W 098 058.86223 005.80291
W 099 058.86185 005.80389
W 100 058.86141 005.80401
W 101 058.86135 005.80315
W 102 058.86179 005.80303
W 103 058.86129 005.80230
W 104 058.86084 005.80241
W 105 058.86090 005.80327
W 106 058.86052 005.80424
W 107 058.86058 005.80510
W 108 058.86065 005.80596
W 109 058.86071 005.80681
W 110 058.86121 005.80755
W 111 058.86172 005.80829
W 112 058.86166 005.80743
W 113 058.86159 005.80657
W 114 058.86115 005.80669
W 115 058.86109 005.80584
W 116 058.86153 005.80572
W 117 058.86103 005.80498
W 118 058.86097 005.80413
W 119 058.86147 005.80486
W 120 058.86191 005.80474
W 121 058.86236 005.80463
W 122 058.86280 005.80451
W 123 058.86286 005.80536
W 124 058.86242 005.80548
W 125 058.86198 005.80560
W 126 058.86204 005.80646
W 127 058.86210 005.80731
W 128 058.86254 005.80719
W 129 058.86248 005.80634
W 130 058.86292 005.80622
W 131 058.86299 005.80707
W 132 058.86343 005.80696
W 133 058.86305 005.80793
W 134 058.86349 005.80781
W 135 058.86355 005.80867
W 136 058.86399 005.80855
W 137 058.86406 005.80940
W 138 058.86450 005.80929
W 139 058.86444 005.80843
W 140 058.86438 005.80757
W 141 058.86393 005.80769
W 142 058.86387 005.80684
W 143 058.86337 005.80610
W 144 058.86331 005.80524
W 145 058.86324 005.80439
W 146 058.86369 005.80427
W 147 058.86375 005.80513
W 148 058.86381 005.80598
W 149 058.86431 005.80672
W 150 058.86425 005.80586
W 151 058.86470 005.80574
W 152 058.86419 005.80501
W 153 058.86464 005.80489
W 154 058.86508 005.80477
W 155 058.86514 005.80563
W 156 058.86558 005.80551
W 157 058.86564 005.80636
W 158 058.86615 005.80710
W 159 058.86571 005.80722
W 160 058.86526 005.80734
W 161 058.86520 005.80648
W 162 058.86476 005.80660
W 163 058.86482 005.80746
W 164 058.86532 005.80819
W 165 058.86488 005.80831
W 166 058.86494 005.80917
W 167 058.86500 005.81002
W 168 058.86545 005.80990
W 169 058.86595 005.81064
W 170 058.86589 005.80979
W 171 058.86539 005.80905
W 172 058.86577 005.80807
W 173 058.86583 005.80893
W 174 058.86627 005.80881
W 175 058.86633 005.80967
W 176 058.86678 005.80955
W 177 058.86672 005.80869
W 178 058.86716 005.80857
W 179 058.86722 005.80943
W 180 058.86766 005.80931
W 181 058.86760 005.80846
W 182 058.86805 005.80834
W 183 058.86811 005.80919
W 184 058.86817 005.81005
W 185 058.86772 005.81017
W 186 058.86728 005.81029
W 187 058.86684 005.81040
W 188 058.86640 005.81052
W 189 058.86646 005.81138
W 190 058.86652 005.81224
W 191 058.86696 005.81212
W 192 058.86690 005.81126
W 193 058.86734 005.81114
W 194 058.86740 005.81200
W 195 058.86747 005.81285
W 196 058.86753 005.81371
W 197 058.86803 005.81445
W 198 058.86797 005.81359
W 199 058.86841 005.81347
W 200 058.86886 005.81335
W 201 058.86930 005.81324
W 202 058.86974 005.81312
W 203 058.87019 005.81300
W 204 058.86968 005.81226
W 205 058.86924 005.81238
W 206 058.86880 005.81250
W 207 058.86873 005.81164
W 208 058.86829 005.81176
W 209 058.86835 005.81262
W 210 058.86791 005.81274
W 211 058.86785 005.81188
W 212 058.86779 005.81102
W 213 058.86823 005.81091
W 214 058.86867 005.81079
W 215 058.86912 005.81067
W 216 058.86918 005.81152
W 217 058.86962 005.81141
W 218 058.87000 005.81043
W 219 058.86956 005.81055
W 220 058.86950 005.80969
W 221 058.86994 005.80958
W 222 058.87038 005.80946
W 223 058.87045 005.81031
W 224 058.87006 005.81129
W 225 058.87013 005.81214
W 226 058.87051 005.81117
W 227 058.87057 005.81202
W 228 058.87101 005.81191
W 229 058.87095 005.81105
W 230 058.87141 005.81095

Sorry to bump my own thread, but does no one have any comment on this?
Is my program faulty or is this a Microsoft or a GHI bug?

As I can see it happens every 19 lines?
Looks to me like some sort of a buffer issue.

That might be so, but where is the problem?
In NETMF or in the SD card it self?
I have tried two different SD cards and they both behave the same. These cards have been used in cameras with FAT16 formatting with no issue what so ever.

GHI never ignore questions. If no answer is there yet then we have this on the todo list still.

I think it is in MF. Every 19 lines 27 chars it is about 512 bytes buffer.

Thanks for the feedback Gus
As there were no comments for 3 days, I thought it might have slipped by you guys :slight_smile:

Then I can continue my work and hope for a fix within the next couple of months. This is for a boat that will go for hours logging water depths and GPS locations so I need a reliable file system.

Is the todo list public anywhere?

Geir, I had an issue I felt was important and didn’t hear anything for a few days and started to get worried that I had fallen through the cracks - I should have known better with these guys. This morning I got a response and possible resolution and it was really worth the wait!

I know, the GHI team is amazing with its level of support but you know how it is. When you feel that you project might grind to a holt its easy to get impatient. And with absolutely no response from anyone I got a bit worried. :slight_smile:

Oh, believe me, I do know what you mean.

Please try firmware in Beta page.
Note that this is not a full SDK just a new USBizi firmware. So you need the full non-beta SDK first and then download the beta firmware.

Thank you Mike
That seems to fix my FAT16 read problem!! :clap: