Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private define
USBH_fatfs
MyFile
res
bytesWritten
rtext
wtext
MSC_File_Operations()
Files
loading...
CodeScopeSTM32 Libraries and SamplesDynamicSwitch_StandaloneSrc/file_operations.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file USB_Host/DynamicSwitch_Standalone/Src/file_operations.c * @author MCD Application Team * @brief Write/read file on the disk. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ 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 /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** * @brief Files operations: Read/Write and compare * @param None * @retval None *//* ... */ void MSC_File_Operations(void) { uint32_t bytesread; /* Register the file system object to the FatFs module */ 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)) /*EOF or Error*/ { 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)) /*EOF or Error*/ { 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 { ... } /* Compare read data with the expected data */ 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 { ... } }{ ... }