Skip to content

Commit 92a4d7f

Browse files
improved result handling to prevent false-positives in case of disk error in SDMMC_HelloWorld example. (#690)
1 parent 679f36a commit 92a4d7f

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

examples/SDMMC_HelloWorld/SDMMC_HelloWorld.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** Example of writing a "Hello World" to a text file on an SD Card
1+
/** Example of writing a "Hello World" to a text file on an SD Card
22
* If the SD Card is present, and writing is successful the onboard LED will blink rapidly.
33
* Otherwise, the SD Card will blink once every two seconds.
44
*/
@@ -25,7 +25,7 @@ int main(void)
2525
/** Initialize our hardware */
2626
hw.Init();
2727

28-
/** Initialize the SDMMC Hardware
28+
/** Initialize the SDMMC Hardware
2929
* For this example we'll use:
3030
* Medium (25MHz), 4-bit, w/out power save settings
3131
*/
@@ -41,12 +41,13 @@ int main(void)
4141
/** Get the reference to the FATFS Filesystem for use in mounting the hardware. */
4242
FATFS& fs = fsi.GetSDFileSystem();
4343

44-
/** default to a known error
44+
/** default to a known error
4545
* by the end of the next if-statement it should be FR_OK
4646
*/
47-
FRESULT res = FR_NO_FILESYSTEM;
47+
FRESULT write_res = FR_NO_FILESYSTEM;
48+
FRESULT close_res = FR_NO_FILESYSTEM;
4849

49-
/** mount the filesystem to the root directory
50+
/** mount the filesystem to the root directory
5051
* fsi.GetSDPath can be used when mounting multiple filesystems on different media
5152
*/
5253
if(f_mount(&fs, "/", 0) == FR_OK)
@@ -56,8 +57,8 @@ int main(void)
5657
{
5758
FixedCapStr<20> str = "Hello World!";
5859
UINT bytes_written;
59-
res = f_write(&file, str.Cstr(), str.Size(), &bytes_written);
60-
f_close(&file);
60+
write_res = f_write(&file, str.Cstr(), str.Size(), &bytes_written);
61+
close_res = f_close(&file);
6162
}
6263
}
6364

@@ -67,7 +68,8 @@ int main(void)
6768
{
6869
/** Very basic blink to indicate success or failure */
6970
uint32_t blink_rate;
70-
if(res == FR_OK)
71+
auto success = write_res == FR_OK && close_res == FR_OK;
72+
if(success)
7173
blink_rate = 125;
7274
else
7375
blink_rate = 1000;

0 commit comments

Comments
 (0)