1 | typedef unsigned char BYTE;
|
2 |
|
3 | ...
|
4 |
|
5 | // SDCARD
|
6 | void sdcard_test (void) {
|
7 |
|
8 | FATFS fs[1]; /* Work area (file system object) for logical drives */
|
9 | FIL fsrc, fdst; /* file objects */
|
10 | BYTE buffer_sd[4096]; /* file copy buffer */
|
11 | FRESULT res; /* FatFs function common result code */
|
12 | UINT br, bw; /* File read/write count */
|
13 |
|
14 |
|
15 | disk_initialize(0);
|
16 |
|
17 | /* Register work area for each volume (Always succeeds regardless of disk status) */
|
18 | f_mount(0, &fs[0]);
|
19 |
|
20 | /* Open source file on the drive 1 */
|
21 | res = f_open(&fsrc, "0:my_test.txt", FA_OPEN_EXISTING | FA_READ);
|
22 | sprintf(&lcd.buffer[0],"Open Read res=%d",(UINT)res); //lcd.buffer ist global definiert
|
23 | printf_tft(1,15,lcd.buffer);
|
24 |
|
25 | /* Create destination file on the drive 0 */
|
26 | res = f_open(&fdst, "0:dstfile1.txt", FA_CREATE_ALWAYS | FA_WRITE);
|
27 | sprintf(&lcd.buffer[0],"Open Write res=%d",(UINT)res);
|
28 | printf_tft(1,30,lcd.buffer);
|
29 |
|
30 | /* Copy source to destination */
|
31 | for (;;) {
|
32 | res = f_read(&fsrc, buffer_sd, sizeof(buffer_sd), &br); /* Read a chunk of src file */
|
33 | sprintf(&lcd.buffer[0],"Read Anzahl: %d (res=%d)",br,(UINT)res);
|
34 | printf_tft(1,45,lcd.buffer);
|
35 | delay(100);
|
36 |
|
37 | if (res || br == 0) break; /* error or eof */
|
38 | res = f_write(&fdst, buffer_sd, br, &bw); /* Write it to the dst file */
|
39 | if (res || bw < br) break; /* error or disk full */
|
40 | }
|
41 |
|
42 | /* Close open files */
|
43 | f_close(&fsrc);
|
44 | f_close(&fdst);
|
45 |
|
46 | /* Unregister work area prior to discard it */
|
47 | f_mount(0, NULL);
|
48 | }
|