1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
30
31
32
33
34
35
40
41
42
43
44
45
49
50
51
52
53
57
58
59
60
61
62
63
64
67
68
69
73
74
75
76
77
78
79
80
83
89
90
91
92
97
102
103
104
105
/* ... */
#include "main.h"
Includes
FATFS USBH_fatfs;
FIL MyFile;
FRESULT res;
uint32_t bytesWritten;
uint8_t rtext[200];
uint8_t wtext[] = "USB Host Library : Mass Storage Example";
Private define
/* ... */
void MSC_File_Operations(void)
{
uint32_t bytesread;
if (f_mount(&USBH_fatfs, "", 0) != FR_OK)
{
LCD_ErrLog("Cannot Initialize FatFs! \n");
}if (f_mount(&USBH_fatfs, "", 0) != FR_OK) { ... }
else
{
LCD_UsrLog("INFO : FatFs Initialized \n");
if (f_open(&MyFile, "0:USBHost.txt", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
LCD_ErrLog("Cannot Open 'USBHost.txt' file \n");
}if (f_open(&MyFile, "0:USBHost.txt", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { ... }
else
{
LCD_UsrLog("INFO : 'USBHost.txt' opened for write \n");
res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&bytesWritten);
f_close(&MyFile);
if ((bytesWritten == 0) || (res != FR_OK))
{
LCD_ErrLog("Cannot Write on the 'USBHost.txt' file \n");
...}
else
{
if (f_open(&MyFile, "0:USBHost.txt", FA_READ) != FR_OK)
{
LCD_ErrLog("Cannot Open 'USBHost.txt' file for read.\n");
}if (f_open(&MyFile, "0:USBHost.txt", FA_READ) != FR_OK) { ... }
else
{
LCD_UsrLog("INFO : Text written on the 'USBHost.txt' file \n");
res = f_read(&MyFile, rtext, sizeof(rtext), (void *)&bytesread);
if ((bytesread == 0) || (res != FR_OK))
{
LCD_ErrLog("Cannot Read from the 'USBHost.txt' file \n");
...}
else
{
LCD_UsrLog("Read Text : \n");
LCD_DbgLog((char *)rtext);
LCD_DbgLog("\n");
}else { ... }
f_close(&MyFile);
}else { ... }
if ((bytesread == bytesWritten))
{
LCD_UsrLog("INFO : FatFs data compare SUCCESS");
LCD_UsrLog("\n");
}if ((bytesread == bytesWritten)) { ... }
else
{
LCD_ErrLog("FatFs data compare ERROR");
LCD_ErrLog("\n");
}else { ... }
}else { ... }
}else { ... }
}else { ... }
}{ ... }