Skip to content

Commit d4c4db5

Browse files
AnHardtfpistm
authored andcommitted
Get Errorstate from FatFS
Signed-off-by: AnHardt <[email protected]>
1 parent 78a020a commit d4c4db5

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/SD.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ File SDClass::open(const char *filepath, uint8_t mode /* = FA_READ */)
149149
mode = mode | FA_CREATE_ALWAYS;
150150
}
151151

152-
if (f_open(file._fil, filepath, mode) != FR_OK) {
152+
file._res = f_open(file._fil, filepath, mode);
153+
if ( file._res != FR_OK) {
153154
free(file._fil);
154155
file._fil = NULL;
155-
if (f_opendir(&file._dir, filepath) != FR_OK) {
156+
file._res = f_opendir(&file._dir, filepath);
157+
if (file._res != FR_OK) {
156158
free(file._name);
157159
file._name = NULL;
158160
}
@@ -179,10 +181,11 @@ File SDClass::openRoot(void)
179181
return open(_fatFs.getRoot());
180182
}
181183

182-
File::File()
184+
File::File(FRESULT result /* = FR_OK */)
183185
{
184186
_name = NULL;
185187
_fil = NULL;
188+
_res = result;
186189
}
187190

188191
/** List directory contents to Serial.
@@ -595,7 +598,7 @@ File File::openNextFile(uint8_t mode)
595598
while (1) {
596599
res = f_readdir(&_dir, &fno);
597600
if (res != FR_OK || fno.fname[0] == 0) {
598-
return File();
601+
return File(res);
599602
}
600603
if (fno.fname[0] == '.') {
601604
continue;
@@ -618,7 +621,7 @@ File File::openNextFile(uint8_t mode)
618621
free(fullPath);
619622
return filtmp;
620623
} else {
621-
return File();
624+
return File(FR_NOT_ENOUGH_CORE);
622625
}
623626
}
624627
}

src/STM32SD.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ uint8_t const LS_R = 4;
3232

3333
class File {
3434
public:
35-
File(void);
35+
File(FRESULT res = FR_OK);
3636
virtual size_t write(uint8_t);
3737
virtual size_t write(const uint8_t *buf, size_t size);
3838
virtual size_t write(const char *buf, size_t size);
@@ -72,6 +72,9 @@ class File {
7272
char *_name = NULL; //file or dir name
7373
FIL *_fil = NULL; // underlying file object structure pointer
7474
DIR _dir = {}; // init all fields to 0
75+
FRESULT _res = FR_OK;
76+
77+
FRESULT getErrorstate(void) {return _res;}
7578

7679
};
7780

0 commit comments

Comments
 (0)