Bill Greiman
Well-known member
I have been running some tests using uSDFS with SDIO on a Tennsy 3.6.
Some files seem to have incorrect data. Here is a minimal test program that demonstrates the problem.
Could be a bug in my test program but I suspect it is a DMA byte alignment problem.
If I run the program with BUF_DIM less than 512, it works. Here is the output for BUF_DIM equal to 511.
Here is the output for BUF_DIM equal to 512.
Some files seem to have incorrect data. Here is a minimal test program that demonstrates the problem.
Could be a bug in my test program but I suspect it is a DMA byte alignment problem.
Code:
// Run on Teensy 3.6 with SDIO.
#include <wchar.h>
#include "ff.h"
// Works for BUF_DIM < 512.
const size_t BUF_DIM = 512;
uint16_t buf[BUF_DIM];
FRESULT rc; /* Result code */
FATFS fatfs; /* File system object */
FIL fil;
UINT wr;
void error(const char* msg) {
while (1) {
Serial.println(msg);
delay(1000);
}
}
void setup() {
Serial.begin(9600);
while (!Serial) {
delay(100);
}
Serial.println("Type any character to begin");
while (!Serial.available()) {
delay(100);
}
TCHAR *device = (TCHAR *)_T("0:/");
f_mount (&fatfs, device, 0);
f_unlink((TCHAR*)_T("uSDFS.bin"));
rc = f_open(&fil, (TCHAR*)_T("uSDFS.bin"), FA_WRITE | FA_CREATE_ALWAYS);
if (rc) error("f_open write");
uint8_t ff = 0XFF;
rc = f_write(&fil, &ff, 1, &wr);
if (rc) error("write ff");
for (size_t i = 0; i < BUF_DIM; i++) {
buf[i] = i;
}
rc = f_write(&fil, buf, sizeof(buf), &wr);
if (rc) error("write buf");
rc = f_close(&fil);
if (rc) error("close after write");
rc = f_open(&fil, (TCHAR*) _T("uSDFS.bin"), FA_READ);
if (rc) error("open read");
rc = f_read(&fil, &ff, 1, &wr);
if (rc) error("read ff");
if (ff != 0XFF) error("ff test");
for (size_t i = 0; i < BUF_DIM; i++) {
uint16_t n;
rc = f_read(&fil, &n, 2, &wr);
if (rc) error("read n ");
if (i != n) {
Serial.print(i);
Serial.print(" != ");
Serial.println(n);
}
}
rc = f_close(&fil);
if (rc) error("close after read");
Serial.println("Done");
}
void loop() {
// put your main code here, to run repeatedly:
}
If I run the program with BUF_DIM less than 512, it works. Here is the output for BUF_DIM equal to 511.
Code:
Type any character to begin
Done
Here is the output for BUF_DIM equal to 512.
Code:
Type any character to begin
255 != 65279
256 != 65280
257 != 0
258 != 257
259 != 513
260 != 769
261 != 1025
262 != 1281
263 != 1537
264 != 1793
265 != 2049
266 != 2305
267 != 2561
268 != 2817
269 != 3073
270 != 3329
271 != 3585
272 != 3841
273 != 4097
274 != 4353
275 != 4609
276 != 4865
277 != 5121
278 != 5377
279 != 5633
280 != 5889
281 != 6145
282 != 6401
283 != 6657
284 != 6913
285 != 7169
286 != 7425
287 != 7681
288 != 7937
289 != 8193
290 != 8449
291 != 8705
292 != 8961
293 != 9217
294 != 9473
295 != 9729
296 != 9985
297 != 10241
298 != 10497
299 != 10753
300 != 11009
301 != 11265
302 != 11521
303 != 11777
304 != 12033
305 != 12289
306 != 12545
307 != 12801
308 != 13057
309 != 13313
310 != 13569
311 != 13825
312 != 14081
313 != 14337
314 != 14593
315 != 14849
316 != 15105
317 != 15361
318 != 15617
319 != 15873
320 != 16129
321 != 16385
322 != 16641
323 != 16897
324 != 17153
325 != 17409
326 != 17665
327 != 17921
328 != 18177
329 != 18433
330 != 18689
331 != 18945
332 != 19201
333 != 19457
334 != 19713
335 != 19969
336 != 20225
337 != 20481
338 != 20737
339 != 20993
340 != 21249
341 != 21505
342 != 21761
343 != 22017
344 != 22273
345 != 22529
346 != 22785
347 != 23041
348 != 23297
349 != 23553
350 != 23809
351 != 24065
352 != 24321
353 != 24577
354 != 24833
355 != 25089
356 != 25345
357 != 25601
358 != 25857
359 != 26113
360 != 26369
361 != 26625
362 != 26881
363 != 27137
364 != 27393
365 != 27649
366 != 27905
367 != 28161
368 != 28417
369 != 28673
370 != 28929
371 != 29185
372 != 29441
373 != 29697
374 != 29953
375 != 30209
376 != 30465
377 != 30721
378 != 30977
379 != 31233
380 != 31489
381 != 31745
382 != 32001
383 != 32257
384 != 32513
385 != 32769
386 != 33025
387 != 33281
388 != 33537
389 != 33793
390 != 34049
391 != 34305
392 != 34561
393 != 34817
394 != 35073
395 != 35329
396 != 35585
397 != 35841
398 != 36097
399 != 36353
400 != 36609
401 != 36865
402 != 37121
403 != 37377
404 != 37633
405 != 37889
406 != 38145
407 != 38401
408 != 38657
409 != 38913
410 != 39169
411 != 39425
412 != 39681
413 != 39937
414 != 40193
415 != 40449
416 != 40705
417 != 40961
418 != 41217
419 != 41473
420 != 41729
421 != 41985
422 != 42241
423 != 42497
424 != 42753
425 != 43009
426 != 43265
427 != 43521
428 != 43777
429 != 44033
430 != 44289
431 != 44545
432 != 44801
433 != 45057
434 != 45313
435 != 45569
436 != 45825
437 != 46081
438 != 46337
439 != 46593
440 != 46849
441 != 47105
442 != 47361
443 != 47617
444 != 47873
445 != 48129
446 != 48385
447 != 48641
448 != 48897
449 != 49153
450 != 49409
451 != 49665
452 != 49921
453 != 50177
454 != 50433
455 != 50689
456 != 50945
457 != 51201
458 != 51457
459 != 51713
460 != 51969
461 != 52225
462 != 52481
463 != 52737
464 != 52993
465 != 53249
466 != 53505
467 != 53761
468 != 54017
469 != 54273
470 != 54529
471 != 54785
472 != 55041
473 != 55297
474 != 55553
475 != 55809
476 != 56065
477 != 56321
478 != 56577
479 != 56833
480 != 57089
481 != 57345
482 != 57601
483 != 57857
484 != 58113
485 != 58369
486 != 58625
487 != 58881
488 != 59137
489 != 59393
490 != 59649
491 != 59905
492 != 60161
493 != 60417
494 != 60673
495 != 60929
496 != 61185
497 != 61441
498 != 61697
499 != 61953
500 != 62209
501 != 62465
502 != 62721
503 != 62977
504 != 63233
505 != 63489
506 != 63745
507 != 64001
508 != 64257
509 != 64513
510 != 64769
511 != 257
Done