Sample of using USB memory and SD card on GR-PEACH
Dependencies: SDBlockDevice_GR_PEACH USBHost_custom
Fork of mbed-os-storage-access by
Diff: main.cpp
- Revision:
- 1:c1b5260c1491
- Parent:
- 0:392df152119c
--- a/main.cpp Thu Mar 16 09:28:46 2017 +0000 +++ b/main.cpp Tue Mar 21 04:10:37 2017 +0000 @@ -5,8 +5,8 @@ int main() { int i = 0; - int strage_type = 0; - char strage_str[16]; + int storage_type = 0; + char storage_str[16]; FATFileSystem fs("storage"); SDBlockDevice_GR_PEACH sd; @@ -14,17 +14,16 @@ while(1) { // try to connect a storage device - fs.unmount(); while (1) { if (sd.connect()) { - strage_type = 0; // SD - strcpy(strage_str, "SD card"); + storage_type = 0; // SD + strcpy(storage_str, "SD card"); fs.mount(&sd); break; } if (usb.connect()) { - strage_type = 1; // USB - strcpy(strage_str, "USB memory"); + storage_type = 1; // USB + strcpy(storage_str, "USB memory"); fs.mount(&usb); break; } @@ -38,7 +37,7 @@ FILE * fp = fopen("/storage/test1.txt", "a"); if (fp != NULL) { - fprintf(fp, "Hello %s World: %d!\r\n", strage_str, i++); + fprintf(fp, "Hello %s World: %d!\r\n", storage_str, i++); printf("Goodbye World!\r\n"); fclose(fp); } else { @@ -47,11 +46,12 @@ Thread::wait(500); // if device disconnected, try to connect again - if (strage_type == 0) { + if (storage_type == 0) { if (!sd.connected()) break; } else { if (!usb.connected()) break; } } + fs.unmount(); } }