This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

USB MSC Corruption

Hello,

I have been experiencing corruption using a similar implementation to the USBD_MSC example. Even after the various SDK fixes suggested to the same problem outlined in the forum.

I have edited the example to use a repeating timer with the scheduler to write an incrementing index, and two random numbers to a log_data.txt file.

i.e. sprintf(log_record, "%d,%d,%d\r\n", record_number,rand(),rand());

1,3542,16169

2,16521,11936

3,6713,17489

etc...

However, randomly in the log, symbols such as ' ' will replace anywhere between 8 and 18ish lines of data with symbols.

Using FATFS, the first few lines of a log was randomly being deleted/replaced with these non-characters, and symbols.

Upon switching to exFAT, as suggested by another user, the corruption still occurs, but somewhere in the middle of the log.

I have included the application for the nRF52840 DK with my function 'log_data_write_handler'.

Running this on the PCA10056 will create a log every 500ms. It is very reproducable that I have corruption happen anywhere between 200 and 1000 logs in. The corruption is shown in corrupt_log.txt by line 854.

1,32225,17543
2,25089,21183
3,25137,25566
4,26966,4978
5,20495,10311
6,11367,30054
7,17031,13145
8,19882,25736
9,30524,28505
10,28394,22102
11,24851,19067
12,12754,11653
13,6561,27096
14,13628,15188
15,32085,4143
16,6967,31406
17,24165,13403
18,25562,24834
19,31353,920
20,10444,24803
21,7962,19318
22,1422,31327
23,10457,1945
24,14479,29983
25,18751,3894
26,18670,8259
27,16248,7757
28,15629,13306
29,28606,13990
30,11738,12516
31,1414,5262
32,17116,22825
33,3181,13134
34,25343,8022
35,11233,7536
36,9760,9979
37,29071,1201
38,21336,13061
39,22160,24005
40,30729,7644
41,27475,31693
42,25514,14139
43,22088,26521
44,5202,9171
45,4434,28317
46,24582,6815
47,4586,9653
48,26306,7174
49,18451,23448
50,6473,32434
51,8193,14110
52,24748,28210
53,29320,32049
54,12956,14162
55,4166,14997
56,7793,32310
57,21391,19799
58,7926,14905
59,25885,2582
60,15610,5000
61,8052,30965
62,20120,32380
63,15639,26204
64,24385,12475
65,15725,17265
66,3214,19471
67,11376,4697
68,25543,23297
69,14619,23087
70,3123,31549
71,18065,24256
72,18973,20901
73,25613,6157
74,9899,9267
75,22413,9598
76,18526,13711
77,10046,14566
78,18536,15988
79,19878,13626
80,4273,8387
81,1171,32017
82,3752,12388
83,21191,11483
84,18122,11744
85,18528,15585
86,5363,20159
87,5641,18176
88,9575,28578
89,27363,27685
90,29344,19489
91,17713,5511
92,21461,22626
93,8645,3496
94,26703,6270
95,13870,11529
96,27499,4500
97,8607,5808
98,15725,12457
99,16542,16474
100,11531,17222
101,3952,17024
102,19894,24015
103,18247,11276
104,26278,19365
105,8746,21976
106,18092,25851
107,29088,29163
108,2231,26233
109,29732,21106
110,5411,9874
111,5448,9344
112,27589,17574
113,1191,6789
114,695,11735
115,20364,17040
116,17892,5035
117,26979,1092
118,850,12390
119,20195,668
120,20531,29989
121,12281,23902
122,12970,32186
123,19571,3680
124,7261,26187
125,28529,24190
126,446,24233
127,13708,11863
128,6681,6001
129,2499,3786
130,5214,25829
131,1322,25907
132,19628,13192
133,7505,5990
134,20129,10875
135,19829,31591
136,12388,6042
137,9833,1775
138,4719,342
139,28994,31392
140,20509,31313
141,20677,1282
142,11511,4795
143,3474,6469
144,2750,879
145,30989,30134
146,29752,28364
147,4880,5629
148,2235,21332
149,24145,3356
150,5243,3079
151,3988,807
152,24979,31357
153,914,21187
154,3540,14022
155,10149,609
156,29009,24833
157,16696,5432
158,24999,28863
159,16369,28676
160,24077,7701
161,1691,19840
162,28703,16515
163,22229,32420
164,19817,16264
165,19324,29343
166,1462,28929
167,3546,17043
168,18967,325
169,12683,15634
170,6322,16642
171,25395,11612
172,22864,29910
173,21985,23126
174,13988,685
175,6978,31050
176,16476,6365
177,21126,4193
178,8681,11011
179,23058,1249
180,31247,24731
181,28650,20774
182,7980,20833
183,27868,7778
184,23624,11115
185,1645,15892
186,29408,7939
187,17285,16202
188,28018,11334
189,4058,7062
190,3784,11901
191,6684,14289
192,27141,16702
193,26853,13458
194,28528,23363
195,21087,19052
196,31235,15109
197,17075,11755
198,10675,288
199,32053,14157
200,5758,5222
201,17488,18945
202,10294,11200
203,5171,14305
204,7951,6601
205,23608,7214
206,6377,13865
207,25369,27215
208,8030,177
209,16849,11337
210,2699,23099
211,8531,11517
212,17567,28479
213,9966,2597
214,14885,12341
215,15227,27149
216,785,29615
217,6476,20753
218,4236,7730
219,19668,21210
220,27519,27608
221,5142,6999
222,20449,14246
223,18638,2941
224,12481,23726
225,16738,26047
226,28947,3300
227,21639,17996
228,23866,14785
229,27571,25356
230,12633,27289
231,20551,20312
232,14426,7357
233,8056,16252
234,20410,2384
235,4353,2029
236,23579,27882
237,31882,21577
238,31368,11502
239,18902,21012
240,31365,30379
241,14256,19244
242,27870,13365
243,9619,27665
244,21293,29441
245,19484,12759
246,15400,6211
247,4144,15335
248,22704,32520
249,23789,32121
250,21913,23571
251,12369,2770
252,1594,887
253,18093,32317
254,11188,27640
255,4295,12490
256,25859,3106
257,24786,17097
258,5062,27943
259,31247,12292
260,16846,3962
261,28479,27584
262,21352,32044
263,31695,16498
264,4714,9737
265,17346,28482
266,24064,24946
267,9822,19265
268,2868,12792
269,3990,19561
270,16959,9917
271,29754,22104
272,25745,30347
273,25825,11980
274,18338,12465
275,25490,24541
276,20599,8097
277,26677,510
278,15347,14667
279,16316,10673
280,8163,14647
281,12817,29965
282,28871,16485
283,6846,29937
284,6241,5861
285,24670,28166
286,26879,27445
287,30407,11638
288,31113,11101
289,22516,28014
290,13898,21452
291,8117,1364
292,12926,20465
293,13845,25032
294,1696,18585
295,13455,92
296,18288,31755
297,29167,27412
298,25030,31717
299,24842,28572
300,26393,27828
301,11805,3660
302,5838,9046
303,18182,23772
304,12354,15377
305,14885,22759
306,22934,1903
307,6159,26145
308,10045,26847
309,17401,29783
310,4167,781
311,24287,2347
312,23402,19964
313,14711,10637
314,20693,29417
315,30937,24313
316,15541,2528
317,23019,21618
318,3716,5402
319,16270,18242
320,8468,22045
321,30602,18286
322,30559,22674
323,25146,1019
324,31243,20197
325,26870,7908
326,448,7327
327,28485,17622
328,14890,10883
329,10943,1201
330,10701,24682
331,3524,8895
332,27276,24798
333,12511,25522
334,24311,25209
335,26359,2912
336,28759,17148
337,26683,2877
338,8571,12334
339,16331,7324
340,577,635
341,26663,17061
342,20451,9544
343,16984,28693
344,19975,10519
345,21472,19641
346,9349,23391
347,30563,22184
348,19958,41
349,27666,23363
350,25344,2410
351,28635,1006
352,20068,26660
353,20562,29323
354,13764,21307
355,7773,10683
356,9013,8216
357,28834,15571
358,15241,2303
359,24754,928
360,3417,32048
361,12018,19931
362,17621,22209
363,14669,21098
364,20555,4662
365,12444,22109
366,16760,25574
367,14544,18339
368,30610,18189
369,24549,18320
370,24081,25264
371,6022,24847
372,19521,24628
373,7552,26278
374,20873,4029
375,32489,13359
376,31352,30279
377,8717,20560
378,23189,8583
379,795,10687
380,26339,23935
381,3988,27703
382,27958,10212
383,19567,10553
384,13368,32047
385,13068,20611
386,4154,23429
387,28895,13393
388,30908,5960
389,30169,5462
390,27323,23929
391,32149,29305
392,9149,32724
393,32584,6224
394,413,26281
395,12389,11357
396,4887,17532
397,1555,12299
398,9490,26460
399,24911,14183
400,22704,17412
401,20961,20382
402,3608,5811
403,7168,20794
404,12286,13771
405,27844,6684
406,11255,29227
407,26960,27448
408,9086,8526
409,1211,26131
410,8645,11552
411,18627,26110
412,25149,17828
413,32048,12559
414,29668,4167
415,23050,15588
416,17746,28929
417,12410,791
418,25985,18737
419,13952,8576
420,1375,18485
421,24922,16941
422,1557,10700
423,31408,1826
424,8213,32301
425,23680,30161
426,28390,22500
427,32716,7768
428,28079,31599
429,18949,31357
430,12421,27804
431,17717,16490
432,26228,30112
433,12016,9512
434,28751,1015
435,2553,19164
436,6200,30464
437,7859,22212
438,13806,15444
439,5710,27377
440,19417,21994
441,7341,32706
442,26839,9707
443,13593,22820
444,23236,7254
445,11688,5003
446,32203,8788
447,23915,1199
448,13424,24408
449,6490,27655
450,21593,13310
451,3072,12038
452,5087,1697
453,23526,7448
454,17497,15802
455,19649,30555
456,25891,1020
457,18267,14366
458,23408,12848
459,29762,22042
460,23252,31440
461,21810,32626
462,19088,13158
463,2370,2156
464,13213,22434
465,10193,2541
466,887,8766
467,24112,27574
468,12206,22418
469,15373,22113
470,1582,7670
471,23202,18714
472,13897,32731
473,19105,20253
474,24201,29608
475,29918,4338
476,11064,1366
477,22970,15723
478,20907,32202
479,23379,1626
480,29779,9206
481,32365,11539
482,15233,29614
483,19999,23205
484,12028,26186
485,20029,16343
486,7237,10497
487,10377,14564
488,5540,23808
489,152,28918
490,22011,15693
491,6790,16740
492,5446,18015
493,16473,18604
494,6645,15225
495,4662,29999
496,4842,9674
497,11590,32687
498,1616,10566
499,21862,4489
500,24865,19266
501,3473,4785
502,29558,1746
503,19213,23410
504,25997,19171
505,12120,17891
506,29084,15895
507,29905,23336
508,28248,25699
509,31271,6254
510,30276,619
511,6274,1956
512,14266,23192
513,12403,10234
514,14779,8191
515,6556,25114
516,8566,15090
517,24863,1065
518,17561,15202
519,712,380
520,5211,5371
521,2297,29210
522,11590,253
523,16217,3574
524,6085,8667
525,25660,8169
526,1393,17558
527,1232,11377
528,5916,23512
529,28685,18476
530,30617,4304
531,27738,23058
532,22353,1488
533,7168,17781
534,5255,9896
535,15439,14266
536,7270,8896
537,11154,5589
538,20688,27895
539,25012,17798
540,32485,23871
541,18351,20053
542,12885,20469
543,6584,3662
544,29030,24321
545,16428,32381
546,11716,4274
547,19256,17192
548,30220,6230
549,32075,975
550,13335,1180
551,4157,18148
552,1031,30635
553,8508,19786
554,28690,17662
555,28539,10640
556,7441,4358
557,22937,3818
558,13255,20093
559,17873,5107
560,4850,13708
561,24807,25893
562,5652,4252
563,24526,8980
564,31998,31484
565,12313,26733
566,16417,27959
567,17192,13234
568,23956,13107
569,24591,12467
570,27364,10250
571,10309,7627
572,30623,21416
573,15121,18656
574,3231,17961
575,9140,24600
576,21527,19695
577,32343,4700
578,13919,23942
579,32691,15245
580,30591,21049
581,19330,6281
582,8573,21617
583,17833,16092
584,18279,4304
585,18978,21574
586,27935,4369
587,30635,16881
588,8169,22430
589,31024,24431
590,2998,6382
591,31225,20853
592,6446,11941
593,12436,6233
594,24703,8297
595,11392,2637
596,31976,24197
597,21150,13657
598,3332,2624
599,13400,25882
600,27607,26619
601,11662,18492
602,28314,22285
603,30021,29113
604,13126,27487
605,3342,12750
606,19426,1222
607,15160,706
608,21133,36
609,31669,1366
610,12875,24125
611,5069,18699
612,12431,31833
613,13444,23574
614,908,15007
615,22476,24356
616,316,11308
617,17515,6350
618,13101,11510
619,25770,17626
620,23310,31076
621,23491,6967
622,13309,9129
623,1544,19127
624,31886,740
625,20435,25482
626,5531,30713
627,3889,28030
628,16846,9261
629,19533,9720
630,20975,28035
631,9374,8625
632,18926,27866
633,13520,20018
634,19120,8643
635,13683,3853
636,19610,2084
637,13926,29409
638,30430,27534
639,9474,15371
640,8072,5213
641,2310,14636
642,16455,10901
643,9285,10591
644,27644,27255
645,24849,10295
646,4356,1766
647,15206,23931
648,5190,21885
649,4310,27809
650,4347,8301
651,824,24587
652,18752,14871
653,23056,3075
654,4957,11885
655,3773,9592
656,20435,11785
657,28517,2166
658,13351,3850
659,1185,27239
660,30321,32690
661,9703,29707
662,9635,18112
663,26811,32569
664,15002,11662
665,22165,29779
666,11750,28651
667,5521,906
668,7770,19894
669,28633,13783
670,21586,6719
671,26066,4532
672,11719,25949
673,14089,20382
674,16148,6735
675,3548,23116
676,13445,12371
677,14824,5804
678,16549,18696
679,9526,12194
680,9028,22660
681,28708,24960
682,5450,13109
683,24597,323
684,9535,7544
685,3288,15251
686,20630,14587
687,30937,18297
688,26044,27603
689,10,2270
690,31461,7516
691,18831,24263
692,1425,25812
693,10284,6482
694,24288,1463
695,5487,21360
696,16539,21976
697,13213,11360
698,1790,26948
699,605,7407
700,17223,8150
701,12838,25713
702,27391,28826
703,17002,18813
704,12299,3810
705,22143,10860
706,19825,17706
707,27986,6544
708,21739,8621
709,26570,309
710,18734,20675
711,2557,2905
712,4343,16641
713,25365,18730
714,3802,27919
715,18433,22084
716,27082,26439
717,19675,29607
718,21095,787
719,26908,22138
720,20747,14339
721,12930,9857
722,26771,6833
723,23228,26720
724,6637,1877
725,23515,20365
726,5222,23079
727,32633,13334
728,7857,20856
729,11431,10264
730,1206,30095
731,10392,26875
732,5664,8772
733,13838,10350
734,421,3678
735,16264,26918
736,6420,27822
737,30760,27478
738,18976,744
739,8038,25837
740,22510,21060
741,21367,402
742,8544,11736
743,7803,26208
744,31,23220
745,10857,13665
746,3179,5563
747,18363,19660
748,20898,6980
749,13017,15870
750,16273,3188
751,17478,14394
752,25726,20057
753,30604,25377
754,15345,16071
755,29928,25840
756,7750,23283
757,2486,4219
758,7412,13265
759,15259,30445
760,22427,19501
761,25204,22845
762,5583,15499
763,29953,13679
764,12711,14528
765,29777,27535
766,7940,21325
767,8685,13934
768,7073,6782
769,27844,29723
770,21471,27463
771,16602,31264
772,2126,5593
773,9647,29058
774,32763,12295
775,22384,30326
776,21372,12636
777,18144,30691
778,23740,13560
779,11268,4764
780,22407,32047
781,6033,25690
782,32468,5344
783,12054,4730
784,13014,10901
785,32745,124
786,29633,351
787,5331,29239
788,15708,4975
789,14971,5597
790,3915,17012
791,7827,12723
792,11802,12728
793,13764,29069
794,26889,9722
795,5210,4106
796,28826,1801
797,9647,22421
798,2523,24357
799,28249,14103
800,10868,29717
801,17683,26236
802,18799,22024
803,11884,22252
804,28874,44
805,18225,27334
806,23486,26384
807,27035,12636
808,11725,4282
809,31033,8817
810,3726,4744
811,412,5491
812,13880,4295
813,5060,28792
814,14064,7189
815,3661,19195
816,3794,2167
817,15449,83
818,20161,6713
819,30524,28151
820,25071,9353
821,14058,22899
822,16939,30162
823,15649,14889
824,9454,11737
825,18262,25288
826,27940,22938
827,29537,18062
828,28090,28896
829,17128,22077
830,18667,4519
831,27019,12510
832,30795,5425
833,20948,9273
834,18832,23274
835,1245,14607
836,23587,25853
837,24766,18206
838,27499,8882
839,18877,19666
840,29140,1166
841,16949,1739
842,28833,13865
843,5442,787
844,26743,6605
845,50,11291
846,20133,25043
847,1707,1914
848,2868,25534
849,23964,9318
850,19378,276
851,6372,30190
852,14015,16896
853,1989,5373
854,19540,3216     ! #$$(!"(  & 0 20040808,007    	
 ! "$$ ("!,!"!0 0004802(8948        "!  (  ((!&  00241802(0105        ""$! ("), "#00 0044820,966       !    &'(	
($!,"0021$14000
854,   
	 !    $'  (	(&' 10104$0010	868       
   # $  (! #$!
000 01610(28056
           $$!( "( $$&0005$30100,169   886,1157,18874
887,16387,19236
888,16020,22748
889,26692,22275
890,763,32367
891,25467,15948
892,19840,26168
893,25577,29306
894,7862,10664
895,16196,26318
896,23559,23803
897,2991,18630
898,9347,21013
899,8026,17501
900,9836,11543
901,24313,20488
902,16765,9924
903,1766,15469
904,510,6295
905,23317,993
906,16521,11936
907,27067,5544
908,29337,23330
909,19646,6380
910,30680,26606
911,5595,25465
912,28709,16766
913,20889,8254
914,26215,22480
915,19697,24964
916,23572,12552
917,2490,6891
918,384,2501
919,3542,16169
920,9958,7999
921,31007,32130
922,12856,32549
923,3599,23303
924,9638,31032
925,6449,9102
926,752,3751
927,25419,28277
928,5996,31529
929,6728,13078
930,31958,13277
931,23784,10504
932,23259,30689
933,21798,28699
934,13668,20148
935,3436,15378
936,21411,4172
937,27769,30
938,3038,21238
939,1038,22047
940,32766,23282
941,7772,7578
942,5846,26570
943,13869,3704
944,15925,31606
945,17876,15236
946,16810,30513
947,6358,16546
948,16922,10777
949,3157,6352
950,6659,11657
951,27200,22494
952,14989,11063
953,19260,17389
954,19797,26892
955,11089,2729
956,9977,14022
957,7509,3654
958,22115,6480
959,18713,1596
960,23766,20444
961,8277,28609
962,23226,3782
963,30291,2571
964,15655,3113
965,26206,23106
966,14387,14909
967,13546,29511
968,6652,19319
969,6016,32039
970,17012,23646
971,3952,14429
972,19439,24367
973,17204,30923
974,12398,9520
975,678,21623
976,30633,8660
977,25058,518
978,14814,17300
979,5881,8953
980,860,32392
981,1626,30121
982,25806,25799
983,10753,11011
984,15432,26756
985,16221,23556
986,787,9189
987,26626,23283
988,11321,17058
989,10515,23650
990,24527,26978
991,30061,13282
992,7941,14038
993,11924,8329
994,7407,14993
995,18526,25893
996,22544,32174
997,31585,10301
998,16555,31008
999,12829,22475
1000,30666,5591
1001,7402,3260
1002,29451,4760
1003,6304,10787
1004,4397,27545
1005,21512,13377
1006,27486,8159
1007,24581,6966
1008,28482,28760
1009,5762,30083
1010,3523,29880
1011,1051,26183
1012,2715,8724
1013,16523,11061
1014,14499,7999
1015,25048,3672
1016,11993,744
1017,30272,14214
1018,16946,22384
1019,12513,6565
1020,20517,140
1021,13612,30625
1022,9716,24223
1023,11528,15657
1024,4280,19412
1025,5573,10028
1026,25140,20223
1027,28615,30743
1028,30294,8241
1029,15599,13259
1030,1420,23325
1031,31176,8032
1032,20429,31534
1033,32118,156
1034,27746,32100
1035,27743,22833
1036,19064,17394
1037,10646,6586
1038,11879,6041
1039,29452,2164
1040,14272,25282
1041,5237,22460
1042,15385,606
1043,23803,10316
1044,663,18558
1045,17318,29493
1046,11328,3249
1047,26246,6044
1048,21758,26145
1049,20645,2100
1050,14706,27500
1051,12976,21631
1052,28030,5187
1053,31327,2500
1054,28561,6341
1055,29866,10191
1056,9393,27289
1057,26282,9579
1058,2378,9165
1059,18767,16544
1060,8888,1906
1061,5063,5805
1062,32150,28660
1063,16553,16324
1064,17604,18234
1065,31205,27272
1066,15674,25729
1067,5997,13127
1068,12944,27640
1069,23711,13047
1070,8265,3100
1071,8313,498
1072,9187,13522
1073,19579,10865
1074,927,9286
1075,24155,18122
1076,22032,25989
1077,22635,18281
1078,5734,7388
1079,19659,7312
1080,12664,15856
1081,28494,16334
1082,22419,1946
1083,23085,22848
1084,7940,24968
1085,29038,31883
1086,17255,30613
1087,4370,14741
1088,3502,12003
1089,29185,32006
1090,12528,20670
1091,29110,31874
1092,10231,1840
1093,10410,10915
1094,24456,1892
1095,31618,28344
1096,14704,1467
1097,4855,7231
1098,13395,20400
1099,26249,26148
1100,17460,10092
1101,17891,18872
1102,10179,15656
1103,3341,11632
1104,18026,25159
1105,28500,12130
1106,25366,21039
1107,1273,24447
1108,12230,11499
1109,1948,24977
1110,3540,32642
1111,26982,13044
1112,1798,30228
1113,13049,4116
1114,19284,5050
1115,21529,13738
1116,16247,3099
1117,21271,31157
1118,26678,6862
1119,1793,30778
1120,15984,29812
1121,18571,20412
1122,14312,11664
1123,17852,10619
1124,4307,13101
1125,25688,2412
1126,8739,12590
1127,24337,8699
1128,20625,627
1129,2412,10115
1130,24685,1713
1131,26228,24457
1132,14885,31246
1133,32290,26556
1134,27543,10879
1135,7559,28845
1136,29206,9954
1137,28095,26702
1138,6462,17370
1139,3478,20524
1140,31352,4718
usbd_msc.zip

Any help would be appreciated as the same problem is occuring on an audit trail for a production unit.

Thanks,

Jeff

  • Hello Jeff. Did you try the main.c file in your project, or an unmodified usbd_msc example from SDK15.2.0? Can you try with an unmodified version of this example? And to be completely sure, unzip a fresh copy of SDK15.2.0

    I did the same test, and I do not get the corrupted messages with this example. Please note that this example doesn't by default delete the old file, so connect the device with the usbd, and delete the LOG_DATA.txt file. Also note that some .txt readers cache the old files, so make sure to close this file (e.g. if you use notepad/notepad++), and then re-open it to see the latest version.

    Best regards,

    Edvin

  • Edvin,

    On the first nRF52840 development kit I was using the corruption still occurred when using the provided noirq example. A second development kit seemed to work up to the 5000 records I tested, but it still seems pretty flakey. When re-running the test (deleting the file and restarting) on the 2nd board, I sometimes did see corruption of a very long string of ÿ's in the beginning/middle of the log.

    When re-testing the first development kit, I noticed the fatfs_ls function returned this:

    [00:00:00.000,000] <info> app: 
    Listing directory: /
       <DIR>   ÿÿÿÿÿÿÿÿ.ÿÿÿ
       // Truncated for Readability
       <DIR>   ÿÿÿÿÿÿÿÿ.ÿÿÿ
       120812  log_data.txt
       <DIR>   System Volume Information
    Entries count: 259
    

    After re-formatting the drive using Windows it seemed to get rid of this, and the corruption didn't happen the next test.

    It seems that removing the writes from an interrupt base has sometimes helped us pass over the first discovered 13825th byte boundary, but this solution does not work all of the time. 

    Attached is a corrupted file with the noirq code:

    �����������������������������������������������������������������������1,16838,5758
    2,10113,17515
    3,31051,5627
    4,23010,7419
    5,16212,4086
    6,2749,12767
    7,9084,12060
    8,32225,17543
    9,25089,21183
    10,25137,25566
    11,26966,4978
    12,20495,10311
    13,11367,30054
    14,17031,13145
    15,19882,25736
    16,30524,28505
    17,28394,22102
    18,24851,19067
    19,12754,11653
    20,6561,27096
    21,13628,15188
    22,32085,4143
    23,6967,31406
    24,24165,13403
    25,25562,24834
    26,31353,920
    27,10444,24803
    28,7962,19318
    29,1422,31327
    30,10457,1945
    31,14479,29983
    32,18751,3894
    33,18670,8259
    34,16248,7757
    35,15629,13306
    36,28606,13990
    37,11738,12516
    38,1414,5262
    39,17116,22825
    40,3181,13134
    41,25343,8022
    42,11233,7536
    43,9760,9979
    44,29071,1201
    45,21336,13061
    46,22160,24005
    47,30729,7644
    48,27475,31693
    49,25514,14139
    50,22088,26521
    51,5202,9171
    52,4434,28317
    53,24582,6815
    54,4586,9653
    55,26306,7174
    56,18451,23448
    57,6473,32434
    58,8193,14110
    59,24748,28210
    60,29320,32049
    61,12956,14162
    62,4166,14997
    63,7793,32310
    64,21391,19799
    65,7926,14905
    66,25885,2582
    67,15610,5000
    68,8052,30965
    69,20120,32380
    70,15639,26204
    71,24385,12475
    72,15725,17265
    73,3214,19471
    74,11376,4697
    75,25543,23297
    76,14619,23087
    77,3123,31549
    78,18065,24256
    79,18973,20901
    80,25613,6157
    81,9899,9267
    82,22413,9598
    83,18526,13711
    84,10046,14566
    85,18536,15988
    86,19878,13626
    87,4273,8387
    88,1171,32017
    89,3752,12388
    90,21191,11483
    91,18122,11744
    92,18528,15585
    93,5363,20159
    94,5641,18176
    95,9575,28578
    96,27363,27685
    97,29344,19489
    98,17713,5511
    99,21461,22626
    100,8645,3496
    101,26703,6270
    102,13870,11529
    103,27499,4500
    104,8607,5808
    105,15725,12457
    106,16542,16474
    107,11531,17222
    108,3952,17024
    109,19894,24015
    110,18247,11276
    111,26278,19365
    112,8746,21976
    113,18092,25851
    114,29088,29163
    115,2231,26233
    116,29732,21106
    117,5411,9874
    118,5448,9344
    119,27589,17574
    120,1191,6789
    121,695,11735
    122,20364,17040
    123,17892,5035
    124,26979,1092
    125,850,12390
    126,20195,668
    127,20531,29989
    128,12281,23902
    129,12970,32186
    130,19571,3680
    131,7261,26187
    132,28529,24190
    133,446,24233
    134,13708,11863
    135,6681,6001
    136,2499,3786
    137,5214,25829
    138,1322,25907
    139,19628,13192
    140,7505,5990
    141,20129,10875
    142,19829,31591
    143,12388,6042
    144,9833,1775
    145,4719,342
    146,28994,31392
    147,20509,31313
    148,20677,1282
    149,11511,4795
    150,3474,6469
    151,2750,879
    152,30989,30134
    153,29752,28364
    154,4880,5629
    155,2235,21332
    156,24145,3356
    157,5243,3079
    158,3988,807
    159,24979,31357
    160,914,21187
    161,3540,14022
    162,10149,609
    163,29009,24833
    164,16696,5432
    165,24999,28863
    166,16369,28676
    167,24077,7701
    168,1691,19840
    169,28703,16515
    170,22229,32420
    171,19817,16264
    172,19324,29343
    173,1462,28929
    174,3546,17043
    175,18967,325
    176,12683,15634
    177,6322,16642
    178,25395,11612
    179,22864,29910
    180,21985,23126
    181,13988,685
    182,6978,31050
    183,16476,6365
    184,21126,4193
    185,8681,11011
    186,23058,1249
    187,31247,24731
    188,28650,20774
    189,7980,20833
    190,27868,7778
    191,23624,11115
    192,1645,15892
    193,29408,7939
    194,17285,16202
    195,28018,11334
    196,4058,7062
    197,3784,11901
    198,6684,14289
    199,27141,16702
    200,26853,13458
    201,28528,23363
    202,21087,19052
    203,31235,15109
    204,17075,11755
    205,10675,288
    206,32053,14157
    207,5758,5222
    208,17488,18945
    209,10294,11200
    210,5171,14305
    211,7951,6601
    212,23608,7214
    213,6377,13865
    214,25369,27215
    215,8030,177
    216,16849,11337
    217,2699,23099
    218,8531,11517
    219,17567,28479
    220,9966,2597
    221,14885,12341
    222,15227,27149
    223,785,29615
    224,6476,20753
    225,4236,7730
    226,19668,21210
    227,27519,27608
    228,5142,6999
    229,20449,14246
    230,18638,2941
    231,12481,23726
    232,16738,26047
    233,28947,3300
    234,21639,17996
    235,23866,14785
    236,27571,25356
    237,12633,27289
    238,20551,20312
    239,14426,7357
    240,8056,16252
    241,20410,2384
    242,4353,2029
    243,23579,27882
    244,31882,21577
    245,31368,11502
    246,18902,21012
    247,31365,30379
    248,14256,19244
    249,27870,13365
    250,9619,27665
    251,21293,29441
    252,19484,12759
    253,15400,6211
    254,4144,15335
    255,22704,32520
    256,23789,32121
    257,21913,23571
    258,12369,2770
    259,1594,887
    260,18093,32317
    261,11188,27640
    262,4295,12490
    263,25859,3106
    264,24786,17097
    265,5062,27943
    266,31247,12292
    267,16846,3962
    268,28479,27584
    269,21352,32044
    270,31695,16498
    271,4714,9737
    272,17346,28482
    273,24064,24946
    274,9822,19265
    275,2868,12792
    276,3990,19561
    277,16959,9917
    278,29754,22104
    279,25745,30347
    280,25825,11980
    281,18338,12465
    282,25490,24541
    283,20599,8097
    284,26677,510
    285,15347,14667
    286,16316,10673
    287,8163,14647
    288,12817,29965
    289,28871,16485
    290,6846,29937
    291,6241,5861
    292,24670,28166
    293,26879,27445
    294,30407,11638
    295,31113,11101
    296,22516,28014
    297,13898,21452
    298,8117,1364
    299,12926,20465
    300,13845,25032
    301,1696,18585
    302,13455,92
    303,18288,31755
    304,29167,27412
    305,25030,31717
    306,24842,28572
    307,26393,27828
    308,11805,3660
    309,5838,9046
    310,18182,23772
    311,12354,15377
    312,14885,22759
    313,22934,1903
    314,6159,26145
    315,10045,26847
    316,17401,29783
    317,4167,781
    318,24287,2347
    319,23402,19964
    320,14711,10637
    321,20693,29417
    322,30937,24313
    323,15541,2528
    324,23019,21618
    325,3716,5402
    326,16270,18242
    327,8468,22045
    328,30602,18286
    329,30559,22674
    330,25146,1019
    331,31243,20197
    332,26870,7908
    333,448,7327
    334,28485,17622
    335,14890,10883
    336,10943,1201
    337,10701,24682
    338,3524,8895
    339,27276,24798
    340,12511,25522
    341,24311,25209
    342,26359,2912
    343,28759,17148
    344,26683,2877
    345,8571,12334
    346,16331,7324
    347,577,635
    348,26663,17061
    349,20451,9544
    350,16984,28693
    351,19975,10519
    352,21472,19641
    353,9349,23391
    354,30563,22184
    355,19958,41
    356,27666,23363
    357,25344,2410
    358,28635,1006
    359,20068,26660
    360,20562,29323
    361,13764,21307
    362,7773,10683
    363,9013,8216
    364,28834,15571
    365,15241,2303
    366,24754,928
    367,3417,32048
    368,12018,19931
    369,17621,22209
    370,14669,21098
    371,20555,4662
    372,12444,22109
    373,16760,25574
    374,14544,18339
    375,30610,18189
    376,24549,18320
    377,24081,25264
    378,6022,24847
    379,19521,24628
    380,7552,26278
    381,20873,4029
    382,32489,13359
    383,31352,30279
    384,8717,20560
    385,23189,8583
    386,795,10687
    387,26339,23935
    388,3988,27703
    389,27958,10212
    390,19567,10553
    391,13368,32047
    392,13068,20611
    393,4154,23429
    394,28895,13393
    395,30908,5960
    396,30169,5462
    397,27323,23929
    398,32149,29305
    399,9149,32724
    400,32584,6224
    401,413,26281
    402,12389,11357
    403,4887,17532
    404,1555,12299
    405,9490,26460
    406,24911,14183
    407,22704,17412
    408,20961,20382
    409,3608,5811
    410,7168,20794
    411,12286,13771
    412,27844,6684
    413,11255,29227
    414,26960,27448
    415,9086,8526
    416,1211,26131
    417,8645,11552
    418,18627,26110
    419,25149,17828
    420,32048,12559
    421,29668,4167
    422,23050,15588
    423,17746,28929
    424,12410,791
    425,25985,18737
    426,13952,8576
    427,1375,18485
    428,24922,16941
    429,1557,10700
    430,31408,1826
    431,8213,32301
    432,23680,30161
    433,28390,22500
    434,32716,7768
    435,28079,31599
    436,18949,31357
    437,12421,27804
    438,17717,16490
    439,26228,30112
    440,12016,9512
    441,28751,1015
    442,2553,19164
    443,6200,30464
    444,7859,22212
    445,13806,15444
    446,5710,27377
    447,19417,21994
    448,7341,32706
    449,26839,9707
    450,13593,22820
    451,23236,7254
    452,11688,5003
    453,32203,8788
    454,23915,1199
    455,13424,24408
    456,6490,27655
    457,21593,13310
    458,3072,12038
    459,5087,1697
    460,23526,7448
    461,17497,15802
    462,19649,30555
    463,25891,1020
    464,18267,14366
    465,23408,12848
    466,29762,22042
    467,23252,31440
    468,21810,32626
    469,19088,13158
    470,2370,2156
    471,13213,22434
    472,10193,2541
    473,887,8766
    474,24112,27574
    475,12206,22418
    476,15373,22113
    477,1582,7670
    478,23202,18714
    479,13897,32731
    480,19105,20253
    481,24201,29608
    482,29918,4338
    483,11064,1366
    484,22970,15723
    485,20907,32202
    486,23379,1626
    487,29779,9206
    488,32365,11539
    489,15233,29614
    490,19999,23205
    491,12028,26186
    492,20029,16343
    493,7237,10497
    494,10377,14564
    495,5540,23808
    496,152,28918
    497,22011,15693
    498,6790,16740
    499,5446,18015
    500,16473,18604
    501,6645,15225
    502,4662,29999
    503,4842,9674
    504,11590,32687
    505,1616,10566
    506,21862,4489
    507,24865,19266
    508,3473,4785
    509,29558,1746
    510,19213,23410
    511,25997,19171
    512,12120,17891
    513,29084,15895
    514,29905,23336
    515,28248,25699
    516,31271,6254
    517,30276,619
    518,6274,1956
    519,14266,23192
    520,12403,10234
    521,14779,8191
    522,6556,25114
    523,8566,15090
    524,24863,1065
    525,17561,15202
    526,712,380
    527,5211,5371
    528,2297,29210
    529,11590,253
    530,16217,3574
    531,6085,8667
    532,25660,8169
    533,1393,17558
    534,1232,11377
    535,5916,2351 "00    2',  (# 03 06     28   $08$ ! 6$
    4009 0$ !$    	 0 "" 0)  4   1  (	
    5 ( 2   &  5 40$   
    3  (,2  %$0( !100   0  0   4204 $$0"8 "$04" 
     05 (442$ 0(15!$ !( 4 ! ( 	 0(0  ! 2 $ !0 "( 5$ $	!0!22  ! 	 5 05( 0  	(! 1 304
     ,08  $  $ ($"$   4"   4  0!  (  "0  !8  !  %0  460 5! 5
    $04850,13708
    568,24807,25893
    569,5652,4252
    570,24526,8980
    571,31998,31484
    572,12313,26733
    573,16417,27959
    574,17192,13234
    575,23956,13107
    576,24591,12467
    577,27364,10250
    578,10309,7627
    579,30623,21416
    580,15121,18656
    581,3231,17961
    582,9140,24600
    583,21527,19695
    584,32343,4700
    585,13919,23942
    586,32691,15245
    587,30591,21049
    588,19330,6281
    589,8573,21617
    590,17833,16092
    591,18279,4304
    592,18978,21574
    593,27935,4369
    594,30635,16881
    595,8169,22430
    596,31024,24431
    597,2998,6382
    598,31225,20853
    599,6446,11941
    600,12436,6233
    601,24703,8297
    602,11392,2637
    603,31976,24197
    604,21150,13657
    605,3332,2624
    606,13400,25882
    607,27607,26619
    608,11662,18492
    609,28314,22285
    610,30021,29113
    611,13126,27487
    612,3342,12750
    613,19426,1222
    614,15160,706
    615,21133,36
    616,31669,1366
    617,12875,24125
    618,5069,18699
    619,12431,31833
    620,13444,23574
    621,908,15007
    622,22476,24356
    623,316,11308
    624,17515,6350
    625,13101,11510
    626,25770,17626
    627,23310,31076
    628,23491,6967
    629,13309,9129
    630,1544,19127
    631,31886,740
    632,20435,25482
    633,5531,30713
    634,3889,28030
    635,16846,9261
    636,19533,9720
    637,20975,28035
    638,9374,8625
    639,18926,27866
    640,13520,20018
    641,19120,8643
    642,13683,3853
    643,19610,2084
    644,13926,29409
    645,30430,27534
    646,9474,15371
    647,8072,5213
    648,2310,14636
    649,16455,10901
    650,9285,10591
    651,27644,27255
    652,24849,10295
    653,4356,1766
    654,15206,23931
    655,5190,21885
    656,4310,27809
    657,4347,8301
    658,824,24587
    659,18752,14871
    660,23056,3075
    661,4957,11885
    662,3773,9592
    663,20435,11785
    664,28517,2166
    665,13351,3850
    666,1185,27239
    667,30321,32690
    668,9703,29707
    669,9635,18112
    670,26811,32569
    671,15002,11662
    672,22165,29779
    673,11750,28651
    674,5521,906
    675,7770,19894
    676,28633,13783
    677,21586,6719
    678,26066,4532
    679,11719,25949
    680,14089,20382
    681,16148,6735
    682,3548,23116
    683,13445,12371
    684,14824,5804
    685,16549,18696
    686,9526,12194
    687,9028,22660
    688,28708,24960
    689,5450,13109
    690,24597,323
    691,9535,7544
    692,3288,15251
    693,20630,14587
    694,30937,18297
    695,26044,27603
    696,10,2270
    697,31461,7516
    698,18831,24263
    699,1425,25812
    700,10284,6482
    701,24288,1463
    702,5487,21360
    703,16539,21976
    704,13213,11360
    705,1790,26948
    706,605,7407
    707,17223,8150
    708,12838,25713
    709,27391,28826
    710,17002,18813
    711,12299,3810
    712,22143,10860
    713,19825,17706
    714,27986,6544
    715,21739,8621
    716,26570,309
    717,18734,20675
    718,2557,2905
    719,4343,16641
    720,25365,18730
    721,3802,27919
    722,18433,22084
    723,27082,26439
    724,19675,29607
    725,21095,787
    726,26908,22138
    727,20747,14339
    728,12930,9857
    729,26771,6833
    730,23228,26720
    731,6637,1877
    732,23515,20365
    733,5222,23079
    734,32633,13334
    735,7857,20856
    736,11431,10264
    737,1206,30095
    738,10392,26875
    739,5664,8772
    740,13838,10350
    741,421,3678
    742,16264,26918
    743,6420,27822
    744,30760,27478
    745,18976,744
    746,8038,25837
    747,22510,21060
    748,21367,402
    749,8544,11736
    750,7803,26208
    751,31,23220
    752,10857,13665
    753,3179,5563
    754,18363,19660
    755,20898,6980
    756,13017,15870
    757,16273,3188
    758,17478,14394
    759,25726,20057
    760,30604,25377
    761,15345,16071
    762,29928,25840
    763,7750,23283
    764,2486,4219
    765,7412,13265
    766,15259,30445
    767,22427,19501
    768,25204,22845
    769,5583,15499
    770,29953,13679
    771,12711,14528
    772,29777,27535
    773,7940,21325
    774,8685,13934
    775,7073,6782
    776,27844,29723
    777,21471,27463
    778,16602,31264
    779,2126,5593
    780,9647,29058
    781,32763,12295
    782,22384,30326
    783,21372,12636
    784,18144,30691
    785,23740,13560
    786,11268,4764
    787,22407,32047
    788,6033,25690
    789,32468,5344
    790,12054,4730
    791,13014,10901
    792,32745,124
    793,29633,351
    794,5331,29239
    795,15708,4975
    796,14971,5597
    797,3915,17012
    798,7827,12723
    799,11802,12728
    800,13764,29069
    801,26889,9722
    802,5210,4106
    803,28826,1801
    804,9647,22421
    805,2523,24357
    806,28249,14103
    807,10868,29717
    808,17683,26236
    809,18799,22024
    810,11884,22252
    811,28874,44
    812,18225,27334
    813,23486,26384
    814,27035,12636
    815,11725,4282
    816,31033,8817
    817,3726,4744
    818,412,5491
    819,13880,4295
    820,5060,28792
    821,14064,7189
    822,3661,19195
    823,3794,2167
    824,15449,83
    825,20161,6713
    826,30524,28151
    827,25071,9353
    828,14058,22899
    829,16939,30162
    830,15649,14889
    831,9454,11737
    832,18262,25288
    833,27940,22938
    834,29537,18062
    835,28090,28896
    836,17128,22077
    837,18667,4519
    838,27019,12510
    839,30795,5425
    840,20948,9273
    841,18832,23274
    842,1245,14607
    843,23587,25853
    844,24766,18206
    845,27499,8882
    846,18877,19666
    847,29140,1166
    848,16949,1739
    849,28833,13865
    850,5442,787
    851,26743,6605
    852,50,11291
    853,20133,25043
    854,1707,1914
    855,2868,25534
    856,23964,9318
    857,19378,276
    858,6372,30190
    859,14015,16896
    860,1989,5373
    861,19540,32169
    862,27655,9743
    863,32470,11344
    864,30700,24240
    865,20703,16172
    866,16087,26297
    867,967,6661
    868,1211,4426
    869,8948,2706
    870,6212,10630
    871,30694,22932
    872,9160,20241
    873,13057,20911
    874,8428,7755
    875,21785,22539
    876,23318,8265
    877,9664,29358
    878,11414,16023
    879,16975,22679
    880,25235,14000
    881,4533,26523
    882,29623,18746
    883,10498,7169
    884,30106,8450
    885,27826,26076
    886,31984,11706
    887,31418,30763
    888,21617,28276
    889,10580,28081
    890,13963,26589
    891,9867,24469
    892,30154,16954
    893,1157,18874
    894,16387,19236
    895,16020,22748
    896,26692,22275
    897,763,32367
    898,25467,15948
    899,19840,26168
    900,25577,29306
    901,7862,10664
    902,16196,26318
    903,23559,23803
    904,2991,18630
    905,9347,21013
    906,8026,17501
    907,9836,11543
    908,24313,20488
    909,16765,9924
    910,1766,15469
    911,510,6295
    912,23317,993
    913,16521,11936
    914,27067,5544
    915,29337,23330
    916,19646,6380
    917,30680,26606
    918,5595,25465
    919,28709,16766
    920,20889,8254
    921,26215,22480
    922,19697,24964
    923,23572,12552
    924,2490,6891
    925,384,2501
    926,3542,16169
    927,9958,7999
    928,31007,32130
    929,12856,32549
    930,3599,23303
    931,9638,31032
    932,6449,9102
    933,752,3751
    934,25419,28277
    935,5996,31529
    936,6728,13078
    937,31958,13277
    938,23784,10504
    939,23259,30689
    940,21798,28699
    941,13668,20148
    942,3436,15378
    943,21411,4172
    944,27769,30
    945,3038,21238
    946,1038,22047
    947,32766,23282
    948,7772,7578
    949,5846,26570
    950,13869,3704
    951,15925,31606
    952,17876,15236
    953,16810,30513
    954,6358,16546
    955,16922,10777
    956,3157,6352
    957,6659,11657
    958,27200,22494
    959,14989,11063
    960,19260,17389
    961,19797,26892
    962,11089,2729
    963,9977,14022
    964,7509,3654
    965,22115,6480
    966,18713,1596
    967,23766,20444
    968,8277,28609
    969,23226,3782
    970,30291,2571
    971,15655,3113
    972,26206,23106
    973,14387,14909
    974,13546,29511
    975,6652,19319
    976,6016,32039
    977,17012,23646
    978,3952,14429
    979,19439,24367
    980,17204,30923
    981,12398,9520
    982,678,21623
    983,30633,8660
    984,25058,518
    985,14814,17300
    986,5881,8953
    987,860,32392
    988,1626,30121
    989,25806,25799
    990,10753,11011
    991,15432,26756
    992,16221,23556
    993,787,9189
    994,26626,23283
    995,11321,17058
    996,10515,23650
    997,24527,26978
    998,30061,13282
    999,7941,14038
    1000,11924,8329
    1001,7407,14993
    1002,18526,25893
    1003,22544,32174
    1004,31585,10301
    1005,16555,31008
    1006,12829,22475
    1007,30666,5591
    1008,7402,3260
    1009,29451,4760
    1010,6304,10787
    1011,4397,27545
    1012,21512,13377
    1013,27486,8159
    1014,24581,6966
    1015,28482,28760
    1016,5762,30083
    1017,3523,29880
    1018,1051,26183
    1019,2715,8724
    1020,16523,11061
    1021,14499,7999
    1022,25048,3672
    1023,11993,744
    1024,30272,14214
    1025,16946,22384
    1026,12513,6565
    1027,20517,140
    1028,13612,30625
    1029,9716,24223
    1030,11528,15657
    1031,4280,19412
    1032,5573,10028
    1033,25140,20223
    1034,28615,30743
    1035,30294,8241
    1036,15599,13259
    1037,1420,23325
    1038,31176,8032
    1039,20429,31534
    1040,32118,156
    1041,27746,32100
    1042,27743,22833
    1043,19064,17394
    1044,10646,6586
    1045,11879,6041
    1046,29452,2164
    1047,14272,25282
    1048,5237,22460
    1049,15385,606
    1050,23803,10316
    1051,663,18558
    1052,17318,29493
    1053,11328,3249
    1054,26246,6044
    1055,21758,26145
    1056,20645,2100
    1057,14706,27500
    1058,12976,21631
    1059,28030,5187
    1060,31327,2500
    1061,28561,6341
    1062,29866,10191
    1063,9393,27289
    1064,26282,9579
    1065,2378,9165
    1066,18767,16544
    1067,8888,1906
    1068,5063,5805
    1069,32150,28660
    1070,16553,16324
    1071,17604,18234
    1072,31205,27272
    1073,15674,25729
    1074,5997,13127
    1075,12944,27640
    1076,23711,13047
    1077,8265,3100
    1078,8313,498
    1079,9187,13522
    1080,19579,10865
    1081,927,9286
    1082,24155,18122
    1083,22032,25989
    1084,22635,18281
    1085,5734,7388
    1086,19659,7312
    1087,12664,15856
    1088,28494,16334
    1089,22419,1946
    1090,23085,22848
    1091,7940,24968
    1092,29038,31883
    1093,17255,30613
    1094,4370,14741
    1095,3502,12003
    1096,29185,32006
    1097,12528,20670
    1098,29110,31874
    1099,10231,1840
    1100,10410,10915
    1101,24456,1892
    1102,31618,28344
    1103,14704,1467
    1104,4855,7231
    1105,13395,20400
    1106,26249,26148
    1107,17460,10092
    1108,17891,18872
    1109,10179,15656
    1110,3341,11632
    1111,18026,25159
    1112,28500,12130
    1113,25366,21039
    1114,1273,24447
    1115,12230,11499
    1116,1948,24977
    1117,3540,32642
    1118,26982,13044
    1119,1798,30228
    1120,13049,4116
    1121,19284,5050
    1122,21529,13738
    1123,16247,3099
    1124,21271,31157
    1125,26678,6862
    1126,1793,30778
    1127,15984,29812
    1128,18571,20412
    1129,14312,11664
    1130,17852,10619
    1131,4307,13101
    1132,25688,2412
    1133,8739,12590
    1134,24337,8699
    1135,20625,627
    1136,2412,10115
    1137,24685,1713
    1138,26228,24457
    1139,14885,31246
    1140,32290,26556
    1141,27543,10879
    1142,7559,28845
    1143,29206,9954
    1144,28095,26702
    1145,6462,17370
    1146,3478,20524
    1147,31352,4718
    1148,6647,15212
    1149,26956,9313
    1150,20761,12423
    1151,22634,14927
    1152,15463,27333
    1153,886,14220
    1154,3379,14203
    1155,27030,30652
    1156,6171,27396
    1157,25789,25138
    1158,6967,10624
    1159,27062,22281
    1160,15112,32591
    1161,15600,20997
    1162,25120,1356
    1163,10252,24359
    1164,28561,3273
    1165,31783,15634
    1166,24598,3919
    1167,27879,18720
    1168,24068,24082
    1169,4167,4419
    1170,25582,19766
    1171,3875,10142
    1172,24091,22212
    1173,21123,5087
    1174,30377,29034
    1175,14759,32354
    1176,30845,5878
    1177,9430,28935
    1178,29938,13969
    1179,24807,18895
    1180,6205,3771
    1181,16268,15161
    1182,22690,11018
    1183,26722,30303
    1184,27736,418
    1185,11961,23247
    1186,12861,27763
    1187,30755,18474
    1188,31034,31286
    1189,32702,28031
    1190,21108,21285
    1191,577,12901
    1192,23095,11645
    1193,7881,5594
    1194,9123,3508
    1195,30817,7903
    1196,13076,20090
    1197,25683,15055
    1198,13139,11378
    1199,12593,9603
    1200,20862,20909
    1201,21154,14120
    1202,27575,7403
    1203,32238,13275
    1204,32399,8336
    1205,839,30985
    1206,32049,5479
    1207,28637,9353
    1208,78,15642
    1209,17568,4470
    1210,30668,28781
    1211,19923,18126
    1212,19246,21822
    1213,26453,13260
    1214,5313,30781
    1215,14766,22021
    1216,25484,18027
    1217,15324,9540
    1218,12277,8788
    1219,1500,24871
    1220,28467,4363
    1221,16375,7286
    1222,29047,15082
    1223,15057,8774
    1224,30426,15367
    1225,31795,4306
    1226,9989,117
    1227,19603,17940
    1228,22434,10303
    1229,4457,31271
    1230,19846,12069
    1231,49,9052
    1232,25755,21524
    1233,30270,30
    1234,19087,31847
    1235,325,25222
    1236,14398,3808
    1237,25765,6589
    1238,21984,612
    1239,10103,5397
    1240,13810,7290
    1241,30554,7398
    1242,4837,7042
    1243,27643,15658
    1244,15241,18613
    1245,30567,15832
    1246,23096,11744
    1247,3856,17665
    1248,706,27360
    

    I appreciate the help, It looks like we are making some progress but this still needs a little more attention,
    Jeff

  • JeffW: Please let us know what is version of your DK?

  • Jakub, 

    PCA10056 1.0.0  2018.20

    SDK 15.2 w/ soft device 6.1.

    --Jeff

  • Hello Jeff,

    Can you try the attached file:

    /**
     * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    #include <stdint.h>
    #include <stdbool.h>
    #include <stddef.h>
    #include <inttypes.h>
    #include <stdlib.h>
    
    #include "nrf.h"
    #include "nrf_block_dev.h"
    #include "nrf_block_dev_ram.h"
    #include "nrf_block_dev_empty.h"
    #include "nrf_block_dev_qspi.h"
    #include "nrf_block_dev_sdc.h"
    #include "nrf_drv_usbd.h"
    #include "nrf_drv_clock.h"
    #include "nrf_gpio.h"
    #include "nrf_atomic.h"
    #include "nrf_drv_power.h"
    
    #include "ff.h"
    #include "diskio_blkdev.h"
    
    #include "app_scheduler.h"
    #include "app_usbd.h"
    #include "app_usbd_core.h"
    #include "app_usbd_string_desc.h"
    #include "app_usbd_msc.h"
    #include "app_error.h"
    #include "app_timer.h"
    
    #include "bsp.h"
    
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    /**@file
     * @defgroup usbd_msc_example main.c
     * @{
     * @ingroup usbd_msc_example
     * @brief USBD MSC example
     *
     */
    APP_TIMER_DEF(msg_timing_id);
    
    #define LED_USB_RESUME   (BSP_BOARD_LED_0)
    #define LED_USB_START    (BSP_BOARD_LED_1)
    
    #define BTN_RANDOM_FILE  0
    #define BTN_LIST_DIR     1
    #define BTN_MKFS         2
    
    #define KEY_EV_RANDOM_FILE_MSK (1U << BTN_RANDOM_FILE)
    #define KEY_EV_LIST_DIR_MSK    (1U << BTN_LIST_DIR   )
    #define KEY_EV_MKFS_MSK        (1U << BTN_MKFS       )
    
    /**
     * @brief Enable power USB detection
     *
     * Configure if example supports USB port connection
     */
    #ifndef USBD_POWER_DETECTION
    #define USBD_POWER_DETECTION true
    #endif
    
    /**
     * @brief SD card enable/disable
     */
    #define USE_SD_CARD       0
    
    /**
     * @brief FatFS for QPSI enable/disable
     */
    #define USE_FATFS_QSPI    1
    
    /**
     * @brief Mass storage class user event handler
     */
    static void msc_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                    app_usbd_msc_user_event_t     event);
    
    
    /**
     * @brief Ram block device size
     *
     * @note Windows fails to format volumes smaller than 190KB
     */
    #define RAM_BLOCK_DEVICE_SIZE (380 * 512)
    
    /**
     * @brief  RAM block device work buffer
     */
    static uint8_t m_block_dev_ram_buff[RAM_BLOCK_DEVICE_SIZE];
    
    /**
     * @brief  RAM block device definition
     */
    NRF_BLOCK_DEV_RAM_DEFINE(
        m_block_dev_ram,
        NRF_BLOCK_DEV_RAM_CONFIG(512, m_block_dev_ram_buff, sizeof(m_block_dev_ram_buff)),
        NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "RAM", "1.00")
    );
    
    
    /**
     * @brief Empty block device definition
     */
    NRF_BLOCK_DEV_EMPTY_DEFINE(
        m_block_dev_empty,
        NRF_BLOCK_DEV_EMPTY_CONFIG(512, 1024 * 1024),
        NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "EMPTY", "1.00")
    );
    
    
    /**
     * @brief  QSPI block device definition
     */
    NRF_BLOCK_DEV_QSPI_DEFINE(
        m_block_dev_qspi,
        NRF_BLOCK_DEV_QSPI_CONFIG(
            512,
            NRF_BLOCK_DEV_QSPI_FLAG_CACHE_WRITEBACK,
            NRF_DRV_QSPI_DEFAULT_CONFIG
         ),
         NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "QSPI", "1.00")
    );
    
    #if USE_SD_CARD
    
    #define SDC_SCK_PIN     (27)        ///< SDC serial clock (SCK) pin.
    #define SDC_MOSI_PIN    (26)        ///< SDC serial data in (DI) pin.
    #define SDC_MISO_PIN    (2)         ///< SDC serial data out (DO) pin.
    #define SDC_CS_PIN      (32 + 15)   ///< SDC chip select (CS) pin.
    
    /**
     * @brief  SDC block device definition
     */
    NRF_BLOCK_DEV_SDC_DEFINE(
        m_block_dev_sdc,
        NRF_BLOCK_DEV_SDC_CONFIG(
            SDC_SECTOR_SIZE,
            APP_SDCARD_CONFIG(SDC_MOSI_PIN, SDC_MISO_PIN, SDC_SCK_PIN, SDC_CS_PIN)
         ),
         NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "SDC", "1.00")
    );
    
    
    /**
     * @brief Block devices list passed to @ref APP_USBD_MSC_GLOBAL_DEF
     */
    #define BLOCKDEV_LIST() (                                   \
        NRF_BLOCKDEV_BASE_ADDR(m_block_dev_ram, block_dev),     \
        NRF_BLOCKDEV_BASE_ADDR(m_block_dev_empty, block_dev),   \
        NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev),    \
        NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, block_dev)      \
    )
    
    #else
    //#define BLOCKDEV_LIST() (                                   \
    //    NRF_BLOCKDEV_BASE_ADDR(m_block_dev_ram, block_dev),     \
    //    NRF_BLOCKDEV_BASE_ADDR(m_block_dev_empty, block_dev),   \
    //    NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev)     \
    //)
    #define BLOCKDEV_LIST() ( NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev) )
    #endif
    
    /**
     * @brief Endpoint list passed to @ref APP_USBD_MSC_GLOBAL_DEF
     */
    #define ENDPOINT_LIST() APP_USBD_MSC_ENDPOINT_LIST(1, 1)
    
    /**
     * @brief Mass storage class work buffer size
     */
    #define MSC_WORKBUFFER_SIZE (1024)
    
    /*lint -save -e26 -e64 -e123 -e505 -e651*/
    /**
     * @brief Mass storage class instance
     */
    APP_USBD_MSC_GLOBAL_DEF(m_app_msc,
                            0,
                            msc_user_ev_handler,
                            ENDPOINT_LIST(),
                            BLOCKDEV_LIST(),
                            MSC_WORKBUFFER_SIZE);
    
    /*lint -restore*/
    
    /**
     * @brief Events from keys
     */
    static nrf_atomic_u32_t m_key_events;
    
    /**
     * @brief  USB connection status
     */
    static bool m_usb_connected = false;
    
    
    #if USE_FATFS_QSPI
    
    static FATFS m_filesystem;
    
    static bool fatfs_init(void)
    {
        FRESULT ff_result;
        DSTATUS disk_state = STA_NOINIT;
    
        memset(&m_filesystem, 0, sizeof(FATFS));
    
        // Initialize FATFS disk I/O interface by providing the block device.
        static diskio_blkdev_t drives[] =
        {
            DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_qspi, block_dev), NULL)
        };
    
        diskio_blockdev_register(drives, ARRAY_SIZE(drives));
    
        NRF_LOG_INFO("Initializing disk 0 (QSPI)...");
        disk_state = disk_initialize(0);
        if (disk_state)
        {
            NRF_LOG_ERROR("Disk initialization failed.");
            return false;
        }
    
        NRF_LOG_INFO("Mounting volume...");
        ff_result = f_mount(&m_filesystem, "", 1);
        if (ff_result != FR_OK)
        {
            if (ff_result == FR_NO_FILESYSTEM)
            {
                NRF_LOG_ERROR("Mount failed. Filesystem not found. Please format device.");
            }
            else
            {
                NRF_LOG_ERROR("Mount failed: %u", ff_result);
            }
            return false;
        }
    
        return true;
    }
    
    static void fatfs_mkfs(void)
    {
        FRESULT ff_result;
    
        if (m_usb_connected)
        {
            NRF_LOG_ERROR("Unable to operate on filesystem while USB is connected");
            return;
        }
    
        NRF_LOG_INFO("\r\nCreating filesystem...");
        static uint8_t buf[512];
        ff_result = f_mkfs("", FM_FAT, 4096, buf, sizeof(buf));
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("Mkfs failed. ff_res:%d", ff_result);
            return;
        }
    
        NRF_LOG_INFO("Mounting volume...");
        ff_result = f_mount(&m_filesystem, "", 1);
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("Mount failed.");
            return;
        }
    
        NRF_LOG_INFO("Done");
    }
    
    static void fatfs_ls(void)
    {
        DIR dir;
        FRESULT ff_result;
        FILINFO fno;
    
        if (m_usb_connected)
        {
            NRF_LOG_ERROR("Unable to operate on filesystem while USB is connected");
            return;
        }
    
        NRF_LOG_INFO("\r\nListing directory: /");
        ff_result = f_opendir(&dir, "/");
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("Directory listing failed: %u", ff_result);
            return;
        }
    
        uint32_t entries_count = 0;
        do
        {
            ff_result = f_readdir(&dir, &fno);
            if (ff_result != FR_OK)
            {
                NRF_LOG_ERROR("Directory read failed: %u", ff_result);
                return;
            }
    
            if (fno.fname[0])
            {
                if (fno.fattrib & AM_DIR)
                {
                    NRF_LOG_RAW_INFO("   <DIR>   %s\r\n",(uint32_t)fno.fname);
                }
                else
                {
                    NRF_LOG_RAW_INFO("%9lu  %s\r\n", fno.fsize, (uint32_t)fno.fname);
                }
            }
    
            ++entries_count;
            NRF_LOG_FLUSH();
        } while (fno.fname[0]);
    
    
        NRF_LOG_RAW_INFO("Entries count: %u\r\n", entries_count);
    }
    
    static void fatfs_create_test_file(void)
    {
        FRESULT ff_result;
        FIL file;
        uint32_t file_size = 0;
    
        ff_result = f_open(&file, "log_data.txt", FA_READ);
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("log_data.txt Does not exist\r\n");
            NRF_LOG_INFO("Creating log_data.txt");
            ff_result = f_open(&file, "log_data.txt", FA_CREATE_ALWAYS | FA_WRITE);
            if (ff_result != FR_OK)
            {
                if(!m_usb_connected)
                    NRF_LOG_ERROR("Unable to open or create file: log_data.txt");
                NRF_LOG_FLUSH();
                return;
            }
        }
    
        ff_result = f_close(&file);
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("Unable to close file: %u \r\n", ff_result);
            NRF_LOG_FLUSH();
            return;
        }
    
        file_size = f_size(&file);
        NRF_LOG_INFO("log_data.txt create SUCCESSFUL; file size = %d\r\n", file_size);
    }
    
    static uint32_t record_number = 0;
    
    static volatile bool write_file = false;
    static void log_data_write_handler(void * p_context)
    {
        write_file = true;
    }
    
    static void write()
    {
        int i = 0;
        char log_record[128] = {0};
        char log_record_r[128] = {0};
    
        FRESULT ff_result;
        FIL file;
        uint32_t fileSize;
    
        ff_result = f_open(&file, "log_data.txt", FA_OPEN_APPEND | FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
        if (ff_result != FR_OK)
        {
            if(!m_usb_connected)
                NRF_LOG_INFO("Unable to open or create log_data.txt: %u", ff_result);
            NRF_LOG_FLUSH();
            return;
        }
    
        ++record_number;
    //    sprintf(log_record, "%d,%d,%d\r\n", record_number,rand(),rand());
        sprintf(log_record, "1234567890123456789012345678901234567890%d\r\n", record_number+10000000);
        //if (record_number>276 && record_number<290)
    
        FSIZE_t ptr = f_tell(&file);
    //    NRF_LOG_INFO("Pointer: %lu", ptr);
        i = f_printf(&file, log_record);
    //    if (i != 50)
    //    {
    //      NRF_LOG_INFO("f_printf != EOF, %d, %d, %d", i, record_number, sizeof(log_record));
    //    }
    //    NRF_LOG_INFO("AW: Pointer: %lu",f_tell(&file));
    //    f_lseek(&file, ptr);
    //    NRF_LOG_INFO("LS: Pointer: %lu",f_tell(&file));
    
    //    if (record_number>2)
    //    {
    //        f_gets(log_record_r, 50, &file);
    //        if (strcmp(log_record, log_record_r) != 0) {
    //
    //            NRF_LOG_INFO("Records are corrupted");
    //        }
    //
    //    }
    
        i = f_close(&file);
        if (i != 0)
        {
          NRF_LOG_INFO("f_close != 0, %d, %d", i, record_number);
        }
    
        NRF_LOG_INFO("Wrote Data Record: %d", record_number);
    }
    
    static void fatfs_file_create(void)
    {
        FRESULT ff_result;
        FIL file;
        char filename[16];
    
        if (m_usb_connected)
        {
            NRF_LOG_ERROR("Unable to operate on filesystem while USB is connected");
            return;
        }
    
        (void)snprintf(filename, sizeof(filename), "%08x.txt", rand());
    
        NRF_LOG_RAW_INFO("Creating random file: %s ...", (uint32_t)filename);
        NRF_LOG_FLUSH();
    
        ff_result = f_open(&file, filename, FA_CREATE_ALWAYS | FA_WRITE);
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("\r\nUnable to open or create file: %u", ff_result);
            NRF_LOG_FLUSH();
            return;
        }
    
        ff_result = f_close(&file);
        if (ff_result != FR_OK)
        {
            NRF_LOG_ERROR("\r\nUnable to close file: %u", ff_result);
            NRF_LOG_FLUSH();
            return;
        }
        NRF_LOG_RAW_INFO("done\r\n");
    }
    
    static void fatfs_uninit(void)
    {
        NRF_LOG_INFO("Un-initializing disk 0 (QSPI)...");
        UNUSED_RETURN_VALUE(disk_uninitialize(0));
    }
    #else //USE_FATFS_QSPI
    #define fatfs_init()        false
    #define fatfs_mkfs()        do { } while (0)
    #define fatfs_ls()          do { } while (0)
    #define fatfs_file_create() do { } while (0)
    #define fatfs_uninit()      do { } while (0)
    #endif
    
    /**
     * @brief Class specific event handler.
     *
     * @param p_inst    Class instance.
     * @param event     Class specific event.
     */
    static void msc_user_ev_handler(app_usbd_class_inst_t const * p_inst,
                                    app_usbd_msc_user_event_t     event)
    {
        UNUSED_PARAMETER(p_inst);
        UNUSED_PARAMETER(event);
    }
    
    /**
     * @brief USBD library specific event handler.
     *
     * @param event     USBD library event.
     */
    static void usbd_user_ev_handler(app_usbd_event_type_t event)
    {
        switch (event)
        {
            case APP_USBD_EVT_DRV_SUSPEND:
                bsp_board_led_off(LED_USB_RESUME);
                break;
            case APP_USBD_EVT_DRV_RESUME:
                bsp_board_led_on(LED_USB_RESUME);
                break;
            case APP_USBD_EVT_STARTED:
                bsp_board_led_on(LED_USB_START);
                break;
            case APP_USBD_EVT_STOPPED:
                UNUSED_RETURN_VALUE(fatfs_init());
                app_usbd_disable();
                bsp_board_leds_off();
                break;
            case APP_USBD_EVT_POWER_DETECTED:
                NRF_LOG_INFO("USB power detected");
    
                if (!nrf_drv_usbd_is_enabled())
                {
                    fatfs_uninit();
                    app_usbd_enable();
                }
                break;
            case APP_USBD_EVT_POWER_REMOVED:
                NRF_LOG_INFO("USB power removed");
                app_usbd_stop();
                m_usb_connected = false;
                break;
            case APP_USBD_EVT_POWER_READY:
                NRF_LOG_INFO("USB ready");
                app_usbd_start();
                m_usb_connected = true;
                break;
            default:
                break;
        }
    }
    
    static void bsp_event_callback(bsp_event_t ev)
    {
        switch (ev)
        {
            /* Just set a flag to be processed in the main loop */
            case CONCAT_2(BSP_EVENT_KEY_, BTN_RANDOM_FILE):
                UNUSED_RETURN_VALUE(nrf_atomic_u32_or(&m_key_events, KEY_EV_RANDOM_FILE_MSK));
                break;
    
            case CONCAT_2(BSP_EVENT_KEY_, BTN_LIST_DIR):
                UNUSED_RETURN_VALUE(nrf_atomic_u32_or(&m_key_events, KEY_EV_LIST_DIR_MSK));
                break;
    
            case CONCAT_2(BSP_EVENT_KEY_, BTN_MKFS):
                UNUSED_RETURN_VALUE(nrf_atomic_u32_or(&m_key_events, KEY_EV_MKFS_MSK));
                break;
    
            default:
                return; // no implementation needed
        }
    }
    
    int main(void)
    {
        ret_code_t ret;
    
        APP_SCHED_INIT(32, 20);
    
        static const app_usbd_config_t usbd_config = {
            .ev_state_proc = usbd_user_ev_handler
        };
    
        ret = NRF_LOG_INIT(app_usbd_sof_timestamp_get);
        APP_ERROR_CHECK(ret);
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        ret = nrf_drv_clock_init();
        APP_ERROR_CHECK(ret);
    
        /* Fill whole RAM block device buffer */
        for (size_t i = 0; i < sizeof(m_block_dev_ram_buff); ++i)
        {
            m_block_dev_ram_buff[i] = i;
        }
    
        /* Configure LEDs and buttons */
        nrf_drv_clock_lfclk_request(NULL);
        ret = app_timer_init();
    
        ret = app_timer_create(&msg_timing_id,
                                APP_TIMER_MODE_REPEATED,
                                log_data_write_handler);
        APP_ERROR_CHECK(ret);
    
    
    
        APP_ERROR_CHECK(ret);
        ret = bsp_init(BSP_INIT_BUTTONS, bsp_event_callback);
        APP_ERROR_CHECK(ret);
        bsp_board_init(BSP_INIT_LEDS);
    
        if (fatfs_init())
        {
            fatfs_ls();
    //        fatfs_file_create();
            fatfs_create_test_file();
        }
    
        ret = app_usbd_init(&usbd_config);
        APP_ERROR_CHECK(ret);
    
        app_usbd_class_inst_t const * class_inst_msc = app_usbd_msc_class_inst_get(&m_app_msc);
        ret = app_usbd_class_append(class_inst_msc);
        APP_ERROR_CHECK(ret);
    
        NRF_LOG_INFO("USBD MSC example started.");
    
        if (USBD_POWER_DETECTION)
        {
            ret = app_usbd_power_events_enable();
            APP_ERROR_CHECK(ret);
        }
        else
        {
            NRF_LOG_INFO("No USB power detection enabled\r\nStarting USB now");
    
            app_usbd_enable();
            app_usbd_start();
            m_usb_connected = true;
        }
    
        ret = app_timer_start(msg_timing_id, APP_TIMER_TICKS(500), NULL);
        APP_ERROR_CHECK(ret);
    
        while (true)
        {
            if(!app_usbd_event_queue_process())
            {
                app_sched_execute();
            }
            if (write_file) {
                write_file = false;
                write();
            }
    
            /* Process BSP key events flags.*/
            uint32_t events = nrf_atomic_u32_fetch_store(&m_key_events, 0);
    //        if (events & KEY_EV_RANDOM_FILE_MSK)
    //        {
    //            fatfs_file_create();
    //        }
    //
            if (events & KEY_EV_LIST_DIR_MSK)
            {
                fatfs_ls();
            }
    //
            if (events & KEY_EV_MKFS_MSK)
            {
                fatfs_mkfs();
                record_number = 0;
            }
    //
            NRF_LOG_FLUSH();
            /* Sleep CPU only if there was no interrupt since last loop processing */
            __WFE();
        }
    }
    
    /** @} */

    Changed: ff_result = f_mkfs("", FM_FAT, 4096, buf, sizeof(buf));

    Then format the device as FAT (not exFAT), and allocation unit size 4096 bytes. 

    I ran this test now for 5004 records (each record 50 bytes long), and did not encounter any corrupted data.

    BR,

    Edvin

Related