microSD Card control function for DISCO-F769NI based on BD_SD_DISCO_F746NG library by Roy Krikke

Dependencies:   BD_SD_DISCO_F769NI BSP_DISCO_F769NI

Fork of DISCO-F746NG_BLOCK_DEVICE_WITH_FAT_FILESYSTEM_ON_SDCARD by Roy Krikke

Please refer following my Notebook page.
/users/kenjiArai/notebook/sd-card-control-new/#

Committer:
roykrikke
Date:
Sat Mar 24 19:13:39 2018 +0000
Revision:
1:ffacc9d0b308
Parent:
0:4cdf28a602a8
Child:
2:993735af824b
Added license in main.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roykrikke 1:ffacc9d0b308 1 /* Example file of using SD/MMC Block device Library for MBED-OS
roykrikke 1:ffacc9d0b308 2 * Copyright 2017 Roy Krikke
roykrikke 1:ffacc9d0b308 3 *
roykrikke 1:ffacc9d0b308 4 * Licensed under the Apache License, Version 2.0 (the "License");
roykrikke 1:ffacc9d0b308 5 * you may not use this file except in compliance with the License.
roykrikke 1:ffacc9d0b308 6 * You may obtain a copy of the License at
roykrikke 1:ffacc9d0b308 7 *
roykrikke 1:ffacc9d0b308 8 * http://www.apache.org/licenses/LICENSE-2.0
roykrikke 1:ffacc9d0b308 9 *
roykrikke 1:ffacc9d0b308 10 * Unless required by applicable law or agreed to in writing, software
roykrikke 1:ffacc9d0b308 11 * distributed under the License is distributed on an "AS IS" BASIS,
roykrikke 1:ffacc9d0b308 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
roykrikke 1:ffacc9d0b308 13 * See the License for the specific language governing permissions and
roykrikke 1:ffacc9d0b308 14 * limitations under the License.
roykrikke 1:ffacc9d0b308 15 *
roykrikke 1:ffacc9d0b308 16 */
roykrikke 1:ffacc9d0b308 17
roykrikke 0:4cdf28a602a8 18 #include "mbed.h"
roykrikke 0:4cdf28a602a8 19 #include "BD_SD_DISCO_F746NG.h"
roykrikke 0:4cdf28a602a8 20
roykrikke 0:4cdf28a602a8 21 DigitalOut led (LED1);
roykrikke 0:4cdf28a602a8 22
roykrikke 0:4cdf28a602a8 23 // Instantiate the Block Device for sd card on DISCO-F746NG
roykrikke 0:4cdf28a602a8 24 BD_SD_DISCO_F746NG bd;
roykrikke 0:4cdf28a602a8 25 uint8_t block[512] = "Hello World!\n";
roykrikke 0:4cdf28a602a8 26
roykrikke 0:4cdf28a602a8 27 int
roykrikke 0:4cdf28a602a8 28 main () {
roykrikke 0:4cdf28a602a8 29 Serial pc (SERIAL_TX, SERIAL_RX);
roykrikke 0:4cdf28a602a8 30 pc.baud (115200);
roykrikke 0:4cdf28a602a8 31 printf ("Start\n");
roykrikke 0:4cdf28a602a8 32
roykrikke 0:4cdf28a602a8 33 // Call the BD_SD_DISCO_F746NG instance initialisation method.
roykrikke 0:4cdf28a602a8 34 printf ("sd card init...\n");
roykrikke 0:4cdf28a602a8 35 if (0 != bd.init ()) {
roykrikke 0:4cdf28a602a8 36 printf ("Init failed \n");
roykrikke 0:4cdf28a602a8 37 return -1;
roykrikke 0:4cdf28a602a8 38 }
roykrikke 0:4cdf28a602a8 39
roykrikke 0:4cdf28a602a8 40 printf ("sd size: %llu\n", bd.size ());
roykrikke 0:4cdf28a602a8 41 printf ("sd read size: %llu\n", bd.get_read_size ());
roykrikke 0:4cdf28a602a8 42 printf ("sd program size: %llu\n", bd.get_program_size ());
roykrikke 0:4cdf28a602a8 43 printf ("sd erase size: %llu\n\n", bd.get_erase_size ());
roykrikke 0:4cdf28a602a8 44
roykrikke 0:4cdf28a602a8 45 printf ("sd erase...\n");
roykrikke 0:4cdf28a602a8 46 if (0 != bd.erase (0, bd.get_erase_size ())) {
roykrikke 0:4cdf28a602a8 47 printf ("Error Erasing block \n");
roykrikke 0:4cdf28a602a8 48 }
roykrikke 0:4cdf28a602a8 49
roykrikke 0:4cdf28a602a8 50 // Write some the data block to the device
roykrikke 0:4cdf28a602a8 51 printf ("sd write: %s\n", block);
roykrikke 0:4cdf28a602a8 52 if (0 == bd.program (block, 0, 512)) {
roykrikke 0:4cdf28a602a8 53 // read the data block from the device
roykrikke 0:4cdf28a602a8 54 printf ("sd read: ");
roykrikke 0:4cdf28a602a8 55 if (0 == bd.read (block, 0, 512)) {
roykrikke 0:4cdf28a602a8 56 // print the contents of the block
roykrikke 0:4cdf28a602a8 57 printf ("%s", block);
roykrikke 0:4cdf28a602a8 58 }
roykrikke 0:4cdf28a602a8 59 }
roykrikke 0:4cdf28a602a8 60
roykrikke 0:4cdf28a602a8 61 // Call the BD_SD_DISCO_F746NG instance de-initialisation method.
roykrikke 0:4cdf28a602a8 62 printf ("sd card deinit...\n");
roykrikke 0:4cdf28a602a8 63 if (0 != bd.deinit ()) {
roykrikke 0:4cdf28a602a8 64 printf ("Deinit failed \n");
roykrikke 0:4cdf28a602a8 65 return -1;
roykrikke 0:4cdf28a602a8 66 }
roykrikke 0:4cdf28a602a8 67
roykrikke 0:4cdf28a602a8 68 // Blink led with 2 Hz
roykrikke 0:4cdf28a602a8 69 while (true) {
roykrikke 0:4cdf28a602a8 70 led = !led;
roykrikke 0:4cdf28a602a8 71 wait (0.5);
roykrikke 0:4cdf28a602a8 72 }
roykrikke 0:4cdf28a602a8 73 }