NUCLEO-L476RG sdBlockDevice sample code. This is a test for the new SD-Block device driver using the latest MBED-OS dated 2017-05-22. This might not work when mbed-os make big changes in the library.
Fork of mbed-osSDBlockDevice_sampleCode by
main.cpp@10:423e0d0a7ef6, 2017-05-22 (annotated)
- Committer:
- mjm2016
- Date:
- Mon May 22 13:44:58 2017 +0000
- Revision:
- 10:423e0d0a7ef6
- Parent:
- 0:8df79c088b12
Sample code SD BlockDevice. Works with MBED-OS. ; Date for this test is 2017-05-22. As when MBED-OS changes, this might not work. Tested with NUCLEO-L476RG
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mjm2016 | 10:423e0d0a7ef6 | 1 | #include <mbed.h> |
mjm2016 | 10:423e0d0a7ef6 | 2 | #include <SDBlockDevice.h> |
mjm2016 | 10:423e0d0a7ef6 | 3 | #include <FATFileSystem.h> |
mbed_official | 0:8df79c088b12 | 4 | |
mjm2016 | 10:423e0d0a7ef6 | 5 | SDBlockDevice sd(PA_7, PA_6, PA_5, PB_6); |
mjm2016 | 10:423e0d0a7ef6 | 6 | ///SDBlockDevice sd(D11, D12, D13, D10); |
mjm2016 | 10:423e0d0a7ef6 | 7 | FATFileSystem fs("sd"); |
mjm2016 | 10:423e0d0a7ef6 | 8 | Serial pc(SERIAL_TX, SERIAL_RX); |
mbed_official | 0:8df79c088b12 | 9 | |
mjm2016 | 10:423e0d0a7ef6 | 10 | void testSDCard(){ |
mjm2016 | 10:423e0d0a7ef6 | 11 | pc.printf("\nWait for new connection...\n"); |
mjm2016 | 10:423e0d0a7ef6 | 12 | mkdir("/sd/mjm2016", 0777); |
mjm2016 | 10:423e0d0a7ef6 | 13 | FILE *fp = fopen("/sd/mjm2016/sdBlockDeviceTest.txt", "w"); |
mjm2016 | 10:423e0d0a7ef6 | 14 | if(fp == NULL) { |
mjm2016 | 10:423e0d0a7ef6 | 15 | pc.printf("Could not open file for write\n"); |
mjm2016 | 10:423e0d0a7ef6 | 16 | return ; |
mjm2016 | 10:423e0d0a7ef6 | 17 | } |
mjm2016 | 10:423e0d0a7ef6 | 18 | fprintf(fp, "sdBlockDeviceTest System say \"Hello, have fun!\" "); |
mjm2016 | 10:423e0d0a7ef6 | 19 | pc.printf("Writing to your SD-CARD finished. BYE!!"); |
mjm2016 | 10:423e0d0a7ef6 | 20 | fclose(fp); |
mjm2016 | 10:423e0d0a7ef6 | 21 | } |
mbed_official | 0:8df79c088b12 | 22 | |
mbed_official | 0:8df79c088b12 | 23 | int main() |
mbed_official | 0:8df79c088b12 | 24 | { |
mbed_official | 0:8df79c088b12 | 25 | sd.init(); |
mbed_official | 0:8df79c088b12 | 26 | fs.mount(&sd); |
mjm2016 | 10:423e0d0a7ef6 | 27 | testSDCard(); |
mbed_official | 0:8df79c088b12 | 28 | fs.unmount(); |
mbed_official | 0:8df79c088b12 | 29 | sd.deinit(); |
mjm2016 | 10:423e0d0a7ef6 | 30 | } |