sd reader testing
Dependencies: BD_SD_DISCO_F746NG
main.cpp
- Committer:
- long0020
- Date:
- 2020-01-31
- Revision:
- 4:73e7dc25c9be
- Parent:
- 3:7f991a3d4e71
File content as of revision 4:73e7dc25c9be:
/* Example file of using SD/MMC Block device Library for MBED-OS * Copyright 2017 Roy Krikke * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include "mbed.h" #include "FATFileSystem.h" #include "SDBlockDeviceDISCOF746NG.h" #include <stdio.h> #include <errno.h> // Instantiate the Block Device for sd card on DISCO-F746NG SDBlockDeviceDISCOF746NG bd; FATFileSystem fs ("fs"); int main () { printf("Start\n"); int error = 0; printf("Welcome to the filesystem example.\r\n" "Formatting a FAT, RAM-backed filesystem. "); error = FATFileSystem::format(&bd); printf("Mounting the filesystem on \"/fs\". "); error = fs.mount(&bd); //Write to file and create if not exist printf("Opening a new file, numbers.txt."); FILE* fd = fopen("/fs/numbers.txt", "w"); //Printing to file for (int i = 0; i < 20; i++) { printf("Writing decimal numbers to a file (%d/20)\r", i); fprintf(fd, "%d\r\n", i); } printf("Writing decimal numbers to a file (20/20) done.\r\n"); printf("Closing file."); fclose(fd); printf(" done.\r\n"); //Read file printf("Re-opening file read-only."); fd = fopen("/fs/numbers.txt", "r"); //close stream fclose(fd); printf("Closing file."); }