sd-driver 1.2.0 from github

Dependents:   Saver2

Committer:
SDesign2018
Date:
Thu Apr 12 01:36:31 2018 +0000
Revision:
0:f72b3e7f1ec8
Same stuff;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SDesign2018 0:f72b3e7f1ec8 1 # mbed OS SDCard Driver (sd-driver) for FAT32 Filesystem Support
SDesign2018 0:f72b3e7f1ec8 2
SDesign2018 0:f72b3e7f1ec8 3
SDesign2018 0:f72b3e7f1ec8 4 Simon Hughes
SDesign2018 0:f72b3e7f1ec8 5
SDesign2018 0:f72b3e7f1ec8 6 20170329
SDesign2018 0:f72b3e7f1ec8 7
SDesign2018 0:f72b3e7f1ec8 8 Version 0.1.1
SDesign2018 0:f72b3e7f1ec8 9
SDesign2018 0:f72b3e7f1ec8 10
SDesign2018 0:f72b3e7f1ec8 11 # Executive Summary
SDesign2018 0:f72b3e7f1ec8 12
SDesign2018 0:f72b3e7f1ec8 13 The purpose of this document is to describe how to use the mbed OS SDCard
SDesign2018 0:f72b3e7f1ec8 14 driver (sd-driver) so applications can read/write
SDesign2018 0:f72b3e7f1ec8 15 data to flash storage cards using the standard POSIX File API
SDesign2018 0:f72b3e7f1ec8 16 programming interface. The sd-driver uses the SDCard SPI-mode of operation
SDesign2018 0:f72b3e7f1ec8 17 which is a subset of possible SDCard functionality.
SDesign2018 0:f72b3e7f1ec8 18
SDesign2018 0:f72b3e7f1ec8 19 This repository contains the mbed-os SDCard driver for generic SPI
SDesign2018 0:f72b3e7f1ec8 20 SDCard support and other resources, as outlined below:
SDesign2018 0:f72b3e7f1ec8 21
SDesign2018 0:f72b3e7f1ec8 22 - `SDBlockDevice.h` and `SDBlockDevice.cpp`. This is the SDCard driver module presenting
SDesign2018 0:f72b3e7f1ec8 23 a Block Device API (derived from BlockDevice) to the underlying SDCard.
SDesign2018 0:f72b3e7f1ec8 24 - POSIX File API test cases for testing the FAT32 filesystem on SDCard.
SDesign2018 0:f72b3e7f1ec8 25 - basic.cpp, a basic set of functional test cases.
SDesign2018 0:f72b3e7f1ec8 26 - fopen.cpp, more functional tests reading/writing greater volumes of data to SDCard, for example.
SDesign2018 0:f72b3e7f1ec8 27 - `mbed_lib.json` mbed-os application configuration file with SPI pin configurations for the CI shield and overrides for specific targets.
SDesign2018 0:f72b3e7f1ec8 28 This file allows the SPI pins to be specified for the target without having to edit the implementation files.
SDesign2018 0:f72b3e7f1ec8 29 - This README which includes [Summary of POSIX File API Documentation](#summary-posix-api-documentation)
SDesign2018 0:f72b3e7f1ec8 30 including detailed instruction on how to use the FAT filesystem and SDBlockDevice driver.
SDesign2018 0:f72b3e7f1ec8 31
SDesign2018 0:f72b3e7f1ec8 32 The SDCard driver is maintained in this repository as a component separate from the main mbed OS repository.
SDesign2018 0:f72b3e7f1ec8 33 Hence the 2 repositories (mbed-os and sd-driver) have to be used together
SDesign2018 0:f72b3e7f1ec8 34 to deliver the FAT32 Filesystem/SDCard support. This document explains how to do this.
SDesign2018 0:f72b3e7f1ec8 35
SDesign2018 0:f72b3e7f1ec8 36
SDesign2018 0:f72b3e7f1ec8 37 # Introduction
SDesign2018 0:f72b3e7f1ec8 38
SDesign2018 0:f72b3e7f1ec8 39 ### Overview
SDesign2018 0:f72b3e7f1ec8 40
SDesign2018 0:f72b3e7f1ec8 41 The scope of this document is to describe how applications use the FAT filesystem and sd-driver
SDesign2018 0:f72b3e7f1ec8 42 components to persistently store data on SDCards. The document is intended to help developers adopt the
SDesign2018 0:f72b3e7f1ec8 43 mbed OS POSIX File API support, and in particular to help explain:
SDesign2018 0:f72b3e7f1ec8 44
SDesign2018 0:f72b3e7f1ec8 45 - How the software components work together to deliver the storage functionality.
SDesign2018 0:f72b3e7f1ec8 46 - How to work with the sd-driver and mbed OS to build the examples. The example code can easily
SDesign2018 0:f72b3e7f1ec8 47 be copied into your new application code.
SDesign2018 0:f72b3e7f1ec8 48 - How to work with the CI Test Shield, which adds an SDCard slot to those targets that do not have already have one.
SDesign2018 0:f72b3e7f1ec8 49 - How to run the POSIX File API mbed Greentea test cases, which provide further example code of how to use
SDesign2018 0:f72b3e7f1ec8 50 the POSIX File API.
SDesign2018 0:f72b3e7f1ec8 51
SDesign2018 0:f72b3e7f1ec8 52 Section 1 provides an Executive Summary, describing the purpose of the sd-driver, the supporting
SDesign2018 0:f72b3e7f1ec8 53 software, examples, test cases and documentation.
SDesign2018 0:f72b3e7f1ec8 54
SDesign2018 0:f72b3e7f1ec8 55 Section 2 provides an an overview of the material covered including descriptions of the major sections.
SDesign2018 0:f72b3e7f1ec8 56
SDesign2018 0:f72b3e7f1ec8 57 Section 3 provides an overview of the mbed OS filesystem software components,
SDesign2018 0:f72b3e7f1ec8 58 including the inter-relationships between the application, POSIX file API, the standard c-library,
SDesign2018 0:f72b3e7f1ec8 59 the mbed OS filesystem and the SDCard driver (sd-driver).
SDesign2018 0:f72b3e7f1ec8 60
SDesign2018 0:f72b3e7f1ec8 61 Section 4 describes how to build and run an example application for reading
SDesign2018 0:f72b3e7f1ec8 62 and writing data to an SDCard using the POSIX File API. The example begins by describing
SDesign2018 0:f72b3e7f1ec8 63 the procedure for building and testing on the K64F target. The final sub-sections
SDesign2018 0:f72b3e7f1ec8 64 describe how to use the test shield to add an SDCard slot to any mbed target,
SDesign2018 0:f72b3e7f1ec8 65 and hence enable the persistent storage of data on any supported target.
SDesign2018 0:f72b3e7f1ec8 66
SDesign2018 0:f72b3e7f1ec8 67 Section 5 describes an example application which uses the raw
SDesign2018 0:f72b3e7f1ec8 68 BlockDevice API to read and write data to the SDCard.
SDesign2018 0:f72b3e7f1ec8 69
SDesign2018 0:f72b3e7f1ec8 70 Section 6 describes how to build and run the SDCard POSIX File API mbed Greentea test cases.
SDesign2018 0:f72b3e7f1ec8 71 There are a number of functional test cases demonstrating how to use the
SDesign2018 0:f72b3e7f1ec8 72 mbed OS POSIX File API.
SDesign2018 0:f72b3e7f1ec8 73
SDesign2018 0:f72b3e7f1ec8 74 Section 7 describes the POSIX File API and provides links to useful API documentation web pages.
SDesign2018 0:f72b3e7f1ec8 75
SDesign2018 0:f72b3e7f1ec8 76
SDesign2018 0:f72b3e7f1ec8 77 ### Known mbed-os and sd-driver Compatible Versions
SDesign2018 0:f72b3e7f1ec8 78
SDesign2018 0:f72b3e7f1ec8 79 The following versions of the mbed-os and sd-driver repositories are known to work together:
SDesign2018 0:f72b3e7f1ec8 80
SDesign2018 0:f72b3e7f1ec8 81 - {mbed-os, sd-driver} = {mbed-os-5.4.0-rc2, sd-driver-0.0.1-mbed-os-5.4.0-rc2}.
SDesign2018 0:f72b3e7f1ec8 82 `K64F`, `NUCLEO_F429ZI` and `UBLOX_EVK_ODIN_W2` fopen and basic filesystem tests working.
SDesign2018 0:f72b3e7f1ec8 83 - {mbed-os, sd-driver} = {mbed-os-5.4.0, sd-driver-0.0.2-mbed-os-5.4.0}.
SDesign2018 0:f72b3e7f1ec8 84 `K64F`, `NUCLEO_F429ZI` and `UBLOX_EVK_ODIN_W2` fopen and basic filesystem tests working.
SDesign2018 0:f72b3e7f1ec8 85 - {mbed-os, sd-driver} = {mbed-os-5.4.1, sd-driver-0.0.3-mbed-os-5.4.1}.
SDesign2018 0:f72b3e7f1ec8 86 - {mbed-os, sd-driver} = {mbed-os-5.5.1, sd-driver-0.1.0-mbed-os-5.5.1}.
SDesign2018 0:f72b3e7f1ec8 87 - {mbed-os, sd-driver} = {mbed-os-5.5.4, sd-driver-0.1.1-mbed-os-5.5.4}.
SDesign2018 0:f72b3e7f1ec8 88 - {mbed-os, sd-driver} = {mbed-os-5.6.1, sd-driver-0.1.2-mbed-os-5.6.1}.
SDesign2018 0:f72b3e7f1ec8 89
SDesign2018 0:f72b3e7f1ec8 90 To find the latest compatible versions, use the following command to see the messages attached to the tags
SDesign2018 0:f72b3e7f1ec8 91 in the sd-driver repository:
SDesign2018 0:f72b3e7f1ec8 92
SDesign2018 0:f72b3e7f1ec8 93 ex_app7/$ cd sd-driver
SDesign2018 0:f72b3e7f1ec8 94 ex_app7/sd-driver$ git tag -n
SDesign2018 0:f72b3e7f1ec8 95 sd-driver-0.0.1-mbed-os-5.3.4 Version compatible with mbed-os-5.3.4, and private_mbedos_filesystems-0.0.1-mbed-os-5.3.4.
SDesign2018 0:f72b3e7f1ec8 96 sd-driver-0.0.2-mbed-os-5.4.0 Updated README.md to include worked exmaples and restructuring of information.
SDesign2018 0:f72b3e7f1ec8 97 sd-driver-0.0.3-mbed-os-5.4.1 Version compatible with mbed-os-5.4.1.
SDesign2018 0:f72b3e7f1ec8 98 sd-driver-0.1.1-mbed-os-5.5.4 Version compatible with mbed-os-5.5.4
SDesign2018 0:f72b3e7f1ec8 99 sd-driver-0.1.2-mbed-os-5.6.1 Version compatible with mbed-os-5.6.1
SDesign2018 0:f72b3e7f1ec8 100
SDesign2018 0:f72b3e7f1ec8 101
SDesign2018 0:f72b3e7f1ec8 102 ### Known Issues With This Document
SDesign2018 0:f72b3e7f1ec8 103
SDesign2018 0:f72b3e7f1ec8 104 There are no known issues with this document.
SDesign2018 0:f72b3e7f1ec8 105
SDesign2018 0:f72b3e7f1ec8 106
SDesign2018 0:f72b3e7f1ec8 107 # Overview of mbed OS Filesystem Software Component Stack
SDesign2018 0:f72b3e7f1ec8 108
SDesign2018 0:f72b3e7f1ec8 109
SDesign2018 0:f72b3e7f1ec8 110 ------------------------
SDesign2018 0:f72b3e7f1ec8 111 | |
SDesign2018 0:f72b3e7f1ec8 112 | Application | // This application uses the POSIX File API
SDesign2018 0:f72b3e7f1ec8 113 | | // to read/write data to persistent storage backends.
SDesign2018 0:f72b3e7f1ec8 114 ------------------------
SDesign2018 0:f72b3e7f1ec8 115
SDesign2018 0:f72b3e7f1ec8 116 ------------------------ // POSIX File API (ISO).
SDesign2018 0:f72b3e7f1ec8 117
SDesign2018 0:f72b3e7f1ec8 118 ------------------------
SDesign2018 0:f72b3e7f1ec8 119 | |
SDesign2018 0:f72b3e7f1ec8 120 | libc | // The standard c library implementation
SDesign2018 0:f72b3e7f1ec8 121 | | // e.g. newlib.
SDesign2018 0:f72b3e7f1ec8 122 ------------------------
SDesign2018 0:f72b3e7f1ec8 123
SDesign2018 0:f72b3e7f1ec8 124 ------------------------ // sys_xxx equivalent API.
SDesign2018 0:f72b3e7f1ec8 125
SDesign2018 0:f72b3e7f1ec8 126 ------------------------
SDesign2018 0:f72b3e7f1ec8 127 | |
SDesign2018 0:f72b3e7f1ec8 128 | mbed_retarget.cpp | // Target specific mapping layer.
SDesign2018 0:f72b3e7f1ec8 129 | |
SDesign2018 0:f72b3e7f1ec8 130 ------------------------
SDesign2018 0:f72b3e7f1ec8 131
SDesign2018 0:f72b3e7f1ec8 132 ------------------------ // Filesystem Upper Edge API.
SDesign2018 0:f72b3e7f1ec8 133
SDesign2018 0:f72b3e7f1ec8 134 ------------------------
SDesign2018 0:f72b3e7f1ec8 135 | |
SDesign2018 0:f72b3e7f1ec8 136 | File System | // File system wrappers and implementation.
SDesign2018 0:f72b3e7f1ec8 137 | |
SDesign2018 0:f72b3e7f1ec8 138 ------------------------
SDesign2018 0:f72b3e7f1ec8 139
SDesign2018 0:f72b3e7f1ec8 140 ------------------------ // FS Lower Edge API (Block Store Interface).
SDesign2018 0:f72b3e7f1ec8 141
SDesign2018 0:f72b3e7f1ec8 142 ------------------------
SDesign2018 0:f72b3e7f1ec8 143 | Block API |
SDesign2018 0:f72b3e7f1ec8 144 | Device Driver | // The SDCard driver, for example.
SDesign2018 0:f72b3e7f1ec8 145 | e.g. sd-driver |
SDesign2018 0:f72b3e7f1ec8 146 ------------------------
SDesign2018 0:f72b3e7f1ec8 147
SDesign2018 0:f72b3e7f1ec8 148 ------------------------ // SPI.h interface.
SDesign2018 0:f72b3e7f1ec8 149
SDesign2018 0:f72b3e7f1ec8 150 ------------------------
SDesign2018 0:f72b3e7f1ec8 151 | |
SDesign2018 0:f72b3e7f1ec8 152 | SPI | // SPI subsystem (C++ classes and C-HAL implementation).
SDesign2018 0:f72b3e7f1ec8 153 | |
SDesign2018 0:f72b3e7f1ec8 154 ------------------------
SDesign2018 0:f72b3e7f1ec8 155
SDesign2018 0:f72b3e7f1ec8 156 Figure 1. mbedOS generic architecture of filesystem software stack.
SDesign2018 0:f72b3e7f1ec8 157
SDesign2018 0:f72b3e7f1ec8 158 The figure above shows the mbed OS software component stack used for data
SDesign2018 0:f72b3e7f1ec8 159 storage on SDCard:
SDesign2018 0:f72b3e7f1ec8 160
SDesign2018 0:f72b3e7f1ec8 161 - At the top level is the application component which uses the standard POSIX File API
SDesign2018 0:f72b3e7f1ec8 162 to read and write application data to persistent storage.
SDesign2018 0:f72b3e7f1ec8 163 - The newlib standard library (libc) stdio.h interface (POSIX File API)
SDesign2018 0:f72b3e7f1ec8 164 implementation is used as it's optimised for resource limited embedded systems.
SDesign2018 0:f72b3e7f1ec8 165 - mbed_retarget.cpp implements the libc back-end file OS handlers and maps them
SDesign2018 0:f72b3e7f1ec8 166 to the FileSystem.
SDesign2018 0:f72b3e7f1ec8 167 - The File System code (hosted in mbed-os) is composed of 2 parts:
SDesign2018 0:f72b3e7f1ec8 168 - The mbed OS file system wrapper classes (e.g. FileSystem, File, FileBase classes)
SDesign2018 0:f72b3e7f1ec8 169 which are used to present a consistent API to the retarget module for different
SDesign2018 0:f72b3e7f1ec8 170 (third-party) file system implementations.
SDesign2018 0:f72b3e7f1ec8 171 - The FAT filesystem implementation code.
SDesign2018 0:f72b3e7f1ec8 172 The [FATFS: Generic FAT File System Module](http://elm-chan.org/fsw/ff/00index_e.html)
SDesign2018 0:f72b3e7f1ec8 173 (ChanFS) has been integrated within mbed-os.
SDesign2018 0:f72b3e7f1ec8 174 - The Block API Device Driver. The SDCard driver is an example of a persistent storage driver.
SDesign2018 0:f72b3e7f1ec8 175 It's maintained as a separate component from the mbed OS repository (in this repository).
SDesign2018 0:f72b3e7f1ec8 176 - The SPI module provides the mbed OS generic SPI API. This functionality is maintained in
SDesign2018 0:f72b3e7f1ec8 177 mbed OS.
SDesign2018 0:f72b3e7f1ec8 178
SDesign2018 0:f72b3e7f1ec8 179
SDesign2018 0:f72b3e7f1ec8 180 # SDCard POSIX File API Example App for Reading/Writing Data
SDesign2018 0:f72b3e7f1ec8 181
SDesign2018 0:f72b3e7f1ec8 182 Refer to [SD driver Example](https://github.com/ARMmbed/mbed-os-example-sd-driver)
SDesign2018 0:f72b3e7f1ec8 183
SDesign2018 0:f72b3e7f1ec8 184
SDesign2018 0:f72b3e7f1ec8 185 ### <a name="testing-with-an-sdcard-on-target-xyx"></a> Testing with an SDCard on Target XYZ
SDesign2018 0:f72b3e7f1ec8 186
SDesign2018 0:f72b3e7f1ec8 187 The standard way to test is with the mbed CI Test Shield plugged into the
SDesign2018 0:f72b3e7f1ec8 188 target board. This pin mapping for this configuration is parameterised in
SDesign2018 0:f72b3e7f1ec8 189 the `mbed_lib.json` file.
SDesign2018 0:f72b3e7f1ec8 190
SDesign2018 0:f72b3e7f1ec8 191 The following is an example of the `mbed_lib.json` file available in the repository:
SDesign2018 0:f72b3e7f1ec8 192
SDesign2018 0:f72b3e7f1ec8 193 {
SDesign2018 0:f72b3e7f1ec8 194 "config": {
SDesign2018 0:f72b3e7f1ec8 195 "UART_RX": "D0",
SDesign2018 0:f72b3e7f1ec8 196 "UART_TX": "D1",
SDesign2018 0:f72b3e7f1ec8 197 "DIO_0": "D0",
SDesign2018 0:f72b3e7f1ec8 198 "DIO_1": "D1",
SDesign2018 0:f72b3e7f1ec8 199 "DIO_2": "D2",
SDesign2018 0:f72b3e7f1ec8 200 "DIO_3": "D3",
SDesign2018 0:f72b3e7f1ec8 201 "DIO_4": "D4",
SDesign2018 0:f72b3e7f1ec8 202 "DIO_5": "D5",
SDesign2018 0:f72b3e7f1ec8 203 "DIO_6": "D6",
SDesign2018 0:f72b3e7f1ec8 204 "DIO_7": "D7",
SDesign2018 0:f72b3e7f1ec8 205 "DIO_8": "D8",
SDesign2018 0:f72b3e7f1ec8 206 "DIO_9": "D9",
SDesign2018 0:f72b3e7f1ec8 207 "SPI_CS": "D10",
SDesign2018 0:f72b3e7f1ec8 208 "SPI_MOSI": "D11",
SDesign2018 0:f72b3e7f1ec8 209 "SPI_MISO": "D12",
SDesign2018 0:f72b3e7f1ec8 210 "SPI_CLK": "D13",
SDesign2018 0:f72b3e7f1ec8 211 "I2C_SDA": "D14",
SDesign2018 0:f72b3e7f1ec8 212 "I2C_SCL": "D15",
SDesign2018 0:f72b3e7f1ec8 213 "I2C_TEMP_ADDR":"0x90",
SDesign2018 0:f72b3e7f1ec8 214 "I2C_EEPROM_ADDR":"0xA0",
SDesign2018 0:f72b3e7f1ec8 215 "AIN_0": "A0",
SDesign2018 0:f72b3e7f1ec8 216 "AIN_1": "A1",
SDesign2018 0:f72b3e7f1ec8 217 "AIN_2": "A2",
SDesign2018 0:f72b3e7f1ec8 218 "AIN_3": "A3",
SDesign2018 0:f72b3e7f1ec8 219 "AIN_4": "A4",
SDesign2018 0:f72b3e7f1ec8 220 "AIN_5": "A5",
SDesign2018 0:f72b3e7f1ec8 221 "AOUT" : "A5",
SDesign2018 0:f72b3e7f1ec8 222 "PWM_0": "D3",
SDesign2018 0:f72b3e7f1ec8 223 "PWM_1": "D5",
SDesign2018 0:f72b3e7f1ec8 224 "PWM_2": "D6",
SDesign2018 0:f72b3e7f1ec8 225 "PWM_3": "D9",
SDesign2018 0:f72b3e7f1ec8 226 "DEBUG_MSG": 0,
SDesign2018 0:f72b3e7f1ec8 227 "DEVICE_SPI": 1,
SDesign2018 0:f72b3e7f1ec8 228 "FSFAT_SDCARD_INSTALLED": 1
SDesign2018 0:f72b3e7f1ec8 229 },
SDesign2018 0:f72b3e7f1ec8 230 "target_overrides": {
SDesign2018 0:f72b3e7f1ec8 231 "DISCO_F051R8": {
SDesign2018 0:f72b3e7f1ec8 232 "SPI_MOSI": "SPI_MOSI",
SDesign2018 0:f72b3e7f1ec8 233 "SPI_MISO": "SPI_MISO",
SDesign2018 0:f72b3e7f1ec8 234 "SPI_CLK": "SPI_SCK",
SDesign2018 0:f72b3e7f1ec8 235 "SPI_CS": "SPI_CS"
SDesign2018 0:f72b3e7f1ec8 236 },
SDesign2018 0:f72b3e7f1ec8 237 "K20D50M": {
SDesign2018 0:f72b3e7f1ec8 238 "SPI_MOSI": "PTD2",
SDesign2018 0:f72b3e7f1ec8 239 "SPI_MISO": "PTD3",
SDesign2018 0:f72b3e7f1ec8 240 "SPI_CLK": "PTD1",
SDesign2018 0:f72b3e7f1ec8 241 "SPI_CS": "PTC2"
SDesign2018 0:f72b3e7f1ec8 242 },
SDesign2018 0:f72b3e7f1ec8 243 "KL22F": {
SDesign2018 0:f72b3e7f1ec8 244 "SPI_MOSI": "PTD6",
SDesign2018 0:f72b3e7f1ec8 245 "SPI_MISO": "PTD7",
SDesign2018 0:f72b3e7f1ec8 246 "SPI_CLK": "PTD5",
SDesign2018 0:f72b3e7f1ec8 247 "SPI_CS": "PTD4"
SDesign2018 0:f72b3e7f1ec8 248 },
SDesign2018 0:f72b3e7f1ec8 249 "KL25Z": {
SDesign2018 0:f72b3e7f1ec8 250 "SPI_MOSI": "PTD2",
SDesign2018 0:f72b3e7f1ec8 251 "SPI_MISO": "PTD3",
SDesign2018 0:f72b3e7f1ec8 252 "SPI_CLK": "PTD1",
SDesign2018 0:f72b3e7f1ec8 253 "SPI_CS": "PTD0"
SDesign2018 0:f72b3e7f1ec8 254 },
SDesign2018 0:f72b3e7f1ec8 255 "KL43Z": {
SDesign2018 0:f72b3e7f1ec8 256 "SPI_MOSI": "PTD6",
SDesign2018 0:f72b3e7f1ec8 257 "SPI_MISO": "PTD7",
SDesign2018 0:f72b3e7f1ec8 258 "SPI_CLK": "PTD5",
SDesign2018 0:f72b3e7f1ec8 259 "SPI_CS": "PTD4"
SDesign2018 0:f72b3e7f1ec8 260 },
SDesign2018 0:f72b3e7f1ec8 261 "KL46Z": {
SDesign2018 0:f72b3e7f1ec8 262 "SPI_MOSI": "PTD6",
SDesign2018 0:f72b3e7f1ec8 263 "SPI_MISO": "PTD7",
SDesign2018 0:f72b3e7f1ec8 264 "SPI_CLK": "PTD5",
SDesign2018 0:f72b3e7f1ec8 265 "SPI_CS": "PTD4"
SDesign2018 0:f72b3e7f1ec8 266 },
SDesign2018 0:f72b3e7f1ec8 267 "K64F": {
SDesign2018 0:f72b3e7f1ec8 268 "SPI_MOSI": "PTE3",
SDesign2018 0:f72b3e7f1ec8 269 "SPI_MISO": "PTE1",
SDesign2018 0:f72b3e7f1ec8 270 "SPI_CLK": "PTE2",
SDesign2018 0:f72b3e7f1ec8 271 "SPI_CS": "PTE4"
SDesign2018 0:f72b3e7f1ec8 272 },
SDesign2018 0:f72b3e7f1ec8 273 "K66F": {
SDesign2018 0:f72b3e7f1ec8 274 "SPI_MOSI": "PTE3",
SDesign2018 0:f72b3e7f1ec8 275 "SPI_MISO": "PTE1",
SDesign2018 0:f72b3e7f1ec8 276 "SPI_CLK": "PTE2",
SDesign2018 0:f72b3e7f1ec8 277 "SPI_CS": "PTE4"
SDesign2018 0:f72b3e7f1ec8 278 },
SDesign2018 0:f72b3e7f1ec8 279 "LPC11U37H_401": {
SDesign2018 0:f72b3e7f1ec8 280 "SPI_MOSI": "SDMOSI",
SDesign2018 0:f72b3e7f1ec8 281 "SPI_MISO": "SDMISO",
SDesign2018 0:f72b3e7f1ec8 282 "SPI_CLK": "SDSCLK",
SDesign2018 0:f72b3e7f1ec8 283 "SPI_CS": "SDSSEL"
SDesign2018 0:f72b3e7f1ec8 284 },
SDesign2018 0:f72b3e7f1ec8 285 "LPC2368": {
SDesign2018 0:f72b3e7f1ec8 286 "SPI_MOSI": "p11",
SDesign2018 0:f72b3e7f1ec8 287 "SPI_MISO": "p12",
SDesign2018 0:f72b3e7f1ec8 288 "SPI_CLK": "p13",
SDesign2018 0:f72b3e7f1ec8 289 "SPI_CS": "p14"
SDesign2018 0:f72b3e7f1ec8 290 },
SDesign2018 0:f72b3e7f1ec8 291 "NUCLEO_L031K6": {
SDesign2018 0:f72b3e7f1ec8 292 "SPI_MOSI": "SPI_MOSI",
SDesign2018 0:f72b3e7f1ec8 293 "SPI_MISO": "SPI_MISO",
SDesign2018 0:f72b3e7f1ec8 294 "SPI_CLK": "SPI_SCK",
SDesign2018 0:f72b3e7f1ec8 295 "SPI_CS": "SPI_CS"
SDesign2018 0:f72b3e7f1ec8 296 },
SDesign2018 0:f72b3e7f1ec8 297 "nRF51822": {
SDesign2018 0:f72b3e7f1ec8 298 "SPI_MOSI": "p12",
SDesign2018 0:f72b3e7f1ec8 299 "SPI_MISO": "p13",
SDesign2018 0:f72b3e7f1ec8 300 "SPI_CLK": "p15",
SDesign2018 0:f72b3e7f1ec8 301 "SPI_CS": "p14"
SDesign2018 0:f72b3e7f1ec8 302 },
SDesign2018 0:f72b3e7f1ec8 303 "RZ_A1H": {
SDesign2018 0:f72b3e7f1ec8 304 "SPI_MOSI": "P8_5",
SDesign2018 0:f72b3e7f1ec8 305 "SPI_MISO": "P8_6",
SDesign2018 0:f72b3e7f1ec8 306 "SPI_CLK": "P8_3",
SDesign2018 0:f72b3e7f1ec8 307 "SPI_CS": "P8_4"
SDesign2018 0:f72b3e7f1ec8 308 }
SDesign2018 0:f72b3e7f1ec8 309 }
SDesign2018 0:f72b3e7f1ec8 310 }
SDesign2018 0:f72b3e7f1ec8 311
SDesign2018 0:f72b3e7f1ec8 312 Note the following things about the `mbed_lib.json` file:
SDesign2018 0:f72b3e7f1ec8 313
SDesign2018 0:f72b3e7f1ec8 314 - The `mbed_lib.json` file is used to define target specific symbols for the SPI pins connecting the SDCard slot to the target MCU:
SDesign2018 0:f72b3e7f1ec8 315 - "SPI\_CS". This is the Chip Select line.
SDesign2018 0:f72b3e7f1ec8 316 - "SPI\_MOSI". This is the Master Out Slave In data line.
SDesign2018 0:f72b3e7f1ec8 317 - "SPI\_MISO". This is the Master In Slave Out data line.
SDesign2018 0:f72b3e7f1ec8 318 - "SPI\_CLK". This is the serial Clock line.
SDesign2018 0:f72b3e7f1ec8 319 - The default configuration defined in the "config" section is for the standard Arduino header pin mappings for the SPI bus.
SDesign2018 0:f72b3e7f1ec8 320 The "config" section defines a dictionary mapping functional names to target board Arduino header pins:
SDesign2018 0:f72b3e7f1ec8 321 - "SPI\_CS": "D10". This causes the MBED\_CONF\_APP\_SPI\_CS symbol to be defined in mbed\_config.h as D10, which is used in the filesystem test implementation.
SDesign2018 0:f72b3e7f1ec8 322 D10 is defined in the target specific PinNames.h file.
SDesign2018 0:f72b3e7f1ec8 323 - "SPI\_MOSI": "D11". This causes the MBED\_CONF\_APP\_SPI\_MOSI symbol to be defined in mbed\_config.h.
SDesign2018 0:f72b3e7f1ec8 324 - "SPI\_MISO": "D12". This causes the MBED\_CONF\_APP\_SPI\_MISO symbol to be defined in mbed\_config.h.
SDesign2018 0:f72b3e7f1ec8 325 - "SPI\_CLK": "D13". This causes the MBED\_CONF\_APP\_SPI\_CLK symbol to be defined in mbed\_config.h.
SDesign2018 0:f72b3e7f1ec8 326 - The `"target_overrides"` section is used to override the "SPI\_xxx" symbols for specific target boards, which may have an SDCard slot, for example.
SDesign2018 0:f72b3e7f1ec8 327 This is the case for the K64F, where the "SPI\_xxx" are mapped to the pin names for the on-board SDCard.
SDesign2018 0:f72b3e7f1ec8 328
SDesign2018 0:f72b3e7f1ec8 329 ```
SDesign2018 0:f72b3e7f1ec8 330 "K64F": {
SDesign2018 0:f72b3e7f1ec8 331 "SPI_MOSI": "PTE3",
SDesign2018 0:f72b3e7f1ec8 332 "SPI_MISO": "PTE1",
SDesign2018 0:f72b3e7f1ec8 333 "SPI_CLK": "PTE2",
SDesign2018 0:f72b3e7f1ec8 334 "SPI_CS": "PTE4"
SDesign2018 0:f72b3e7f1ec8 335 }
SDesign2018 0:f72b3e7f1ec8 336 ```
SDesign2018 0:f72b3e7f1ec8 337 - Thus, in the absence of any target specific definitions in the `"target_overrides"` section, all boards will default to
SDesign2018 0:f72b3e7f1ec8 338 using the Arduino header configuration. For those platforms with a `"target_overrides"` section then this configuration
SDesign2018 0:f72b3e7f1ec8 339 will be used in preference.
SDesign2018 0:f72b3e7f1ec8 340 - Hence in the case that you want to test a platform with an SDCard inserted into a
SDesign2018 0:f72b3e7f1ec8 341 fitted CI test shield (rather than the on-board SDCard slot)
SDesign2018 0:f72b3e7f1ec8 342 and there is a `"target_overrides"` section present in the `mbed_lib.json` file, you must then delete the `"target_overrides"`
SDesign2018 0:f72b3e7f1ec8 343 section before building. This will result in the default configuration being used (suitable for the CI
SDesign2018 0:f72b3e7f1ec8 344 Test Shield).
SDesign2018 0:f72b3e7f1ec8 345 - Note when inserting the v1.0.0 CI Test Shield into the Arduino header of the target platform, the shield pins D0 and
SDesign2018 0:f72b3e7f1ec8 346 D1 should be bent to be parallel to the shield PCB so they are not inserted into the Arduino header. This is because
SDesign2018 0:f72b3e7f1ec8 347 some boards use the same UART on DAPLINK and D0/D1, which means the serial debug channel breaks and hence the mbed greentea
SDesign2018 0:f72b3e7f1ec8 348 test suite will not work correctly. This is mainly on older ST boards and should not be a problem on
SDesign2018 0:f72b3e7f1ec8 349 `K64F`, `NUCLEO_F429ZI` and `UBLOX_EVK_ODIN_W2`. Note also that the v2.0.0 CI Test Shield doesn't suffer from this
SDesign2018 0:f72b3e7f1ec8 350 problem and the pins don't need to be bent.
SDesign2018 0:f72b3e7f1ec8 351 - When inserting the SDCard into the card slot on the CI test shield, make sure the card is fully inserted.
SDesign2018 0:f72b3e7f1ec8 352 On insertion, there should be a small clicking sound when the card registers, and the back edge of the card
SDesign2018 0:f72b3e7f1ec8 353 should protrude no more than ~1mm over the edge of the CI test shield PCB. If the SDCard fails to register,
SDesign2018 0:f72b3e7f1ec8 354 try gently pushing the metal flexible strip in the shape of a spade at the top edge of the SDCard metal slot
SDesign2018 0:f72b3e7f1ec8 355 casing with a pair of tweezers, bending it a little to lower it into the slot casing. This helps with the
SDesign2018 0:f72b3e7f1ec8 356 insertion mechanism.
SDesign2018 0:f72b3e7f1ec8 357
SDesign2018 0:f72b3e7f1ec8 358 ### Wiring instructions for target NUCLEO_F429ZI with CI Test Shield
SDesign2018 0:f72b3e7f1ec8 359 ![alt text](docs/pics/NUCLEO_F429ZI_wiring_with_ci_test_shield.png "unseen title text")
SDesign2018 0:f72b3e7f1ec8 360
SDesign2018 0:f72b3e7f1ec8 361 **Figure 3. The figure shows how to connect the NUCLEO_F429ZI platform with the CI shield.**
SDesign2018 0:f72b3e7f1ec8 362
SDesign2018 0:f72b3e7f1ec8 363 The above figure shows how to connect the NUCLEO_F429ZI with the v1.0.0 CI test shield. Note:
SDesign2018 0:f72b3e7f1ec8 364
SDesign2018 0:f72b3e7f1ec8 365 - To get the SD Card to work with this platform the CI test shield cannot be connected directly to this board, instead follow the instructions above.
SDesign2018 0:f72b3e7f1ec8 366 - Any SD-card adapter will work as long as you connect all the relevant pins (MOSI, MISO, SCLK, CS, 3.3V and GND) as illustrated in figure 3.
SDesign2018 0:f72b3e7f1ec8 367 - The SDCard is fully inserted into the slot and overhangs the PCB by ~1mm.
SDesign2018 0:f72b3e7f1ec8 368
SDesign2018 0:f72b3e7f1ec8 369 # SDBlockDevice Example Application
SDesign2018 0:f72b3e7f1ec8 370
SDesign2018 0:f72b3e7f1ec8 371 The following sample code illustrates how to use the sd-driver Block Device API:
SDesign2018 0:f72b3e7f1ec8 372
SDesign2018 0:f72b3e7f1ec8 373 ``` cpp
SDesign2018 0:f72b3e7f1ec8 374 #include "mbed.h"
SDesign2018 0:f72b3e7f1ec8 375 #include "SDBlockDevice.h"
SDesign2018 0:f72b3e7f1ec8 376
SDesign2018 0:f72b3e7f1ec8 377 // Instantiate the SDBlockDevice by specifying the SPI pins connected to the SDCard
SDesign2018 0:f72b3e7f1ec8 378 // socket. The PINS are:
SDesign2018 0:f72b3e7f1ec8 379 // MOSI (Master Out Slave In)
SDesign2018 0:f72b3e7f1ec8 380 // MISO (Master In Slave Out)
SDesign2018 0:f72b3e7f1ec8 381 // SCLK (Serial Clock)
SDesign2018 0:f72b3e7f1ec8 382 // CS (Chip Select)
SDesign2018 0:f72b3e7f1ec8 383 SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
SDesign2018 0:f72b3e7f1ec8 384 uint8_t block[512] = "Hello World!\n";
SDesign2018 0:f72b3e7f1ec8 385
SDesign2018 0:f72b3e7f1ec8 386 int main()
SDesign2018 0:f72b3e7f1ec8 387 {
SDesign2018 0:f72b3e7f1ec8 388 // call the SDBlockDevice instance initialisation method.
SDesign2018 0:f72b3e7f1ec8 389 if ( 0 != sd.init()) {
SDesign2018 0:f72b3e7f1ec8 390 printf("Init failed \n");
SDesign2018 0:f72b3e7f1ec8 391 return -1;
SDesign2018 0:f72b3e7f1ec8 392 }
SDesign2018 0:f72b3e7f1ec8 393 printf("sd size: %llu\n", sd.size());
SDesign2018 0:f72b3e7f1ec8 394 printf("sd read size: %llu\n", sd.get_read_size());
SDesign2018 0:f72b3e7f1ec8 395 printf("sd program size: %llu\n", sd.get_program_size());
SDesign2018 0:f72b3e7f1ec8 396 printf("sd erase size: %llu\n", sd.get_erase_size());
SDesign2018 0:f72b3e7f1ec8 397
SDesign2018 0:f72b3e7f1ec8 398 // set the frequency
SDesign2018 0:f72b3e7f1ec8 399 if ( 0 != sd.frequency(5000000)) {
SDesign2018 0:f72b3e7f1ec8 400 printf("Error setting frequency \n");
SDesign2018 0:f72b3e7f1ec8 401 }
SDesign2018 0:f72b3e7f1ec8 402
SDesign2018 0:f72b3e7f1ec8 403 if ( 0 != sd.erase(0, sd.get_erase_size())) {
SDesign2018 0:f72b3e7f1ec8 404 printf("Error Erasing block \n");
SDesign2018 0:f72b3e7f1ec8 405 }
SDesign2018 0:f72b3e7f1ec8 406
SDesign2018 0:f72b3e7f1ec8 407 // Write some the data block to the device
SDesign2018 0:f72b3e7f1ec8 408 if ( 0 == sd.program(block, 0, 512)) {
SDesign2018 0:f72b3e7f1ec8 409 // read the data block from the device
SDesign2018 0:f72b3e7f1ec8 410 if ( 0 == sd.read(block, 0, 512)) {
SDesign2018 0:f72b3e7f1ec8 411 // print the contents of the block
SDesign2018 0:f72b3e7f1ec8 412 printf("%s", block);
SDesign2018 0:f72b3e7f1ec8 413 }
SDesign2018 0:f72b3e7f1ec8 414 }
SDesign2018 0:f72b3e7f1ec8 415
SDesign2018 0:f72b3e7f1ec8 416 // call the SDBlockDevice instance de-initialisation method.
SDesign2018 0:f72b3e7f1ec8 417 sd.deinit();
SDesign2018 0:f72b3e7f1ec8 418 }
SDesign2018 0:f72b3e7f1ec8 419 ```
SDesign2018 0:f72b3e7f1ec8 420
SDesign2018 0:f72b3e7f1ec8 421 # SDCard POSIX File API mbed Greentea Test Cases
SDesign2018 0:f72b3e7f1ec8 422
SDesign2018 0:f72b3e7f1ec8 423 This section describes how to build and run the POSIX file API test cases.
SDesign2018 0:f72b3e7f1ec8 424 The following steps are covered:
SDesign2018 0:f72b3e7f1ec8 425
SDesign2018 0:f72b3e7f1ec8 426 - [Create the FAT/SDCard Application Project](#create-fat-sdcard-application-project).
SDesign2018 0:f72b3e7f1ec8 427 This section describes how to git clone the mbed OS and sd-driver repositories containing the
SDesign2018 0:f72b3e7f1ec8 428 code and test cases of interest.
SDesign2018 0:f72b3e7f1ec8 429 - [Build the mbed OS Test Cases](#build-the-mbedos-test-cases). This section
SDesign2018 0:f72b3e7f1ec8 430 describes how to build the mbed OS test cases.
SDesign2018 0:f72b3e7f1ec8 431 - [Insert a microSD Card Into the K64F for Greentea Testing](#greentea-insert-sdcard-into-k64f).This section
SDesign2018 0:f72b3e7f1ec8 432 describes how to format (if required) a microSD card prior to running the tests.
SDesign2018 0:f72b3e7f1ec8 433 - [Run the POSIX File Test Case](#run-the-posix-file-test-cases).This section
SDesign2018 0:f72b3e7f1ec8 434 describes how to run the POSIX file test cases.
SDesign2018 0:f72b3e7f1ec8 435
SDesign2018 0:f72b3e7f1ec8 436
SDesign2018 0:f72b3e7f1ec8 437 ### <a name="create-fat-sdcard-application-project"></a> Create the FAT/SDCard Application Project
SDesign2018 0:f72b3e7f1ec8 438
SDesign2018 0:f72b3e7f1ec8 439 This section describes how to create an application project combining the mbed-os and
SDesign2018 0:f72b3e7f1ec8 440 sd-driver repositories into a single project.
SDesign2018 0:f72b3e7f1ec8 441 In summary the following steps will be covered in this section:
SDesign2018 0:f72b3e7f1ec8 442
SDesign2018 0:f72b3e7f1ec8 443 - A top level application project directory is created. The directory name is ex_app1.
SDesign2018 0:f72b3e7f1ec8 444 - In the ex_app1 directory, the mbed-os repository is cloned.
SDesign2018 0:f72b3e7f1ec8 445 - In the ex_app1 directory at the same level as the mbed-os directory, the sd-driver repository is cloned.
SDesign2018 0:f72b3e7f1ec8 446 - The `mbed_lib.json` file is copied from the `sd-driver/config/mbed_lib.json` to the ex_app1 directory.
SDesign2018 0:f72b3e7f1ec8 447
SDesign2018 0:f72b3e7f1ec8 448 First create the top level application directory ex_app1 and move into it:
SDesign2018 0:f72b3e7f1ec8 449
SDesign2018 0:f72b3e7f1ec8 450 shell:/d/demo_area$ mkdir ex_app1
SDesign2018 0:f72b3e7f1ec8 451 shell:/d/demo_area$ pushd ex_app1
SDesign2018 0:f72b3e7f1ec8 452
SDesign2018 0:f72b3e7f1ec8 453 Next, get a clone of public mbed OS repository in the following way:
SDesign2018 0:f72b3e7f1ec8 454
SDesign2018 0:f72b3e7f1ec8 455 shell:/d/demo_area/ex_app1$ git clone git@github.com:/armmbed/mbed-os
SDesign2018 0:f72b3e7f1ec8 456 <trace removed>
SDesign2018 0:f72b3e7f1ec8 457 shell:/d/demo_area/ex_app1$
SDesign2018 0:f72b3e7f1ec8 458
SDesign2018 0:f72b3e7f1ec8 459 Next, get a clone of the sd-driver repository:
SDesign2018 0:f72b3e7f1ec8 460
SDesign2018 0:f72b3e7f1ec8 461 shell:/d/demo_area/ex_app1$ git clone git@github.com:/armmbed/sd-driver
SDesign2018 0:f72b3e7f1ec8 462 <trace removed>
SDesign2018 0:f72b3e7f1ec8 463 shell:/d/demo_area/ex_app1$
SDesign2018 0:f72b3e7f1ec8 464
SDesign2018 0:f72b3e7f1ec8 465 Note: The `mbed_lib.json` file specifies the SPI bus pin configuration for different targets,
SDesign2018 0:f72b3e7f1ec8 466 and is discussed in the [Testing with an SDCard on Target XYZ](#testing-with-an-sdcard-on-target-xyx) section.
SDesign2018 0:f72b3e7f1ec8 467
SDesign2018 0:f72b3e7f1ec8 468 ### <a name="build-the-mbedos-test-cases"></a> Build the mbed OS Test Cases
SDesign2018 0:f72b3e7f1ec8 469
SDesign2018 0:f72b3e7f1ec8 470 Build the test cases for the K64F target using the following command:
SDesign2018 0:f72b3e7f1ec8 471
SDesign2018 0:f72b3e7f1ec8 472 shell:/d/demo_area/ex_app1$ mbed -v test --compile -t GCC_ARM -m K64F
SDesign2018 0:f72b3e7f1ec8 473 <trace removed>
SDesign2018 0:f72b3e7f1ec8 474 shell:/d/demo_area/ex_app1$
SDesign2018 0:f72b3e7f1ec8 475
SDesign2018 0:f72b3e7f1ec8 476 The build trace is quite extensive but on a successful build you should see the following output at the end of the log:
SDesign2018 0:f72b3e7f1ec8 477
SDesign2018 0:f72b3e7f1ec8 478 Build successes:
SDesign2018 0:f72b3e7f1ec8 479 * K64F::GCC_ARM::MBED-BUILD
SDesign2018 0:f72b3e7f1ec8 480 * K64F::GCC_ARM::MBED-OS-FEATURES-FEATURE_LWIP-TESTS-MBEDMICRO-NET-CONNECTIVITY
SDesign2018 0:f72b3e7f1ec8 481 <trace removed>
SDesign2018 0:f72b3e7f1ec8 482 * K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-FAT_FILE_SYSTEM
SDesign2018 0:f72b3e7f1ec8 483 * K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-HEAP_BLOCK_DEVICE
SDesign2018 0:f72b3e7f1ec8 484 * K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-UTIL_BLOCK_DEVICE
SDesign2018 0:f72b3e7f1ec8 485 <trace removed>
SDesign2018 0:f72b3e7f1ec8 486 * K64F::GCC_ARM::SD-DRIVER-TESTS-FILESYSTEM-BASIC
SDesign2018 0:f72b3e7f1ec8 487 * K64F::GCC_ARM::SD-DRIVER-TESTS-FILESYSTEM-FOPEN
SDesign2018 0:f72b3e7f1ec8 488 * K64F::GCC_ARM::SD-DRIVER-TESTS-BLOCK_DEVICE-BASIC
SDesign2018 0:f72b3e7f1ec8 489
SDesign2018 0:f72b3e7f1ec8 490 Build skips:
SDesign2018 0:f72b3e7f1ec8 491 * K64F::GCC_ARM::MBED-OS-FEATURES-FEATURE_LWIP-TESTS-MBEDMICRO-NET-TCP_PACKET_PRESSURE
SDesign2018 0:f72b3e7f1ec8 492 <trace removed>
SDesign2018 0:f72b3e7f1ec8 493
SDesign2018 0:f72b3e7f1ec8 494
SDesign2018 0:f72b3e7f1ec8 495 Notice the following tests in the sd-driver tree are listed above:
SDesign2018 0:f72b3e7f1ec8 496
SDesign2018 0:f72b3e7f1ec8 497 - `K64F::GCC_ARM::SD-DRIVER-TESTS-FILESYSTEM-BASIC`
SDesign2018 0:f72b3e7f1ec8 498 - `K64F::GCC_ARM::SD-DRIVER-TESTS-FILESYSTEM-FOPEN`
SDesign2018 0:f72b3e7f1ec8 499 - `K64F::GCC_ARM::SD-DRIVER-TESTS-BLOCK_DEVICE-BASIC`
SDesign2018 0:f72b3e7f1ec8 500
SDesign2018 0:f72b3e7f1ec8 501 The FAT32/SDCard test cases are at following locations in the source code tree:
SDesign2018 0:f72b3e7f1ec8 502
SDesign2018 0:f72b3e7f1ec8 503 /d/demo_area/ex_app1/sd-driver/TESTS/filesystem/basic/basic.cpp
SDesign2018 0:f72b3e7f1ec8 504 /d/demo_area/ex_app1/sd-driver/TESTS/filesystem/fopen/fopen.cpp
SDesign2018 0:f72b3e7f1ec8 505 /d/demo_area/ex_app1/sd-driver/TESTS/block_device/basic/basic.cpp
SDesign2018 0:f72b3e7f1ec8 506
SDesign2018 0:f72b3e7f1ec8 507 #### <a name="settting-repos-to-compatible-versions"></a> Setting mbed-os/sd-driver Repositories To Compatible Versions
SDesign2018 0:f72b3e7f1ec8 508
SDesign2018 0:f72b3e7f1ec8 509 The sd-driver master HEAD and the mbed-os master HEAD should be compatible
SDesign2018 0:f72b3e7f1ec8 510 with one another and therefore no specific tagged versions need to be checked out.
SDesign2018 0:f72b3e7f1ec8 511 However, in the case that you experience problems building, checkout out the compatible
SDesign2018 0:f72b3e7f1ec8 512 tagged version of each repository, as shown below:
SDesign2018 0:f72b3e7f1ec8 513
SDesign2018 0:f72b3e7f1ec8 514 shell:/d/demo_area/ex_app1$ pushd mbed-os
SDesign2018 0:f72b3e7f1ec8 515 shell:/d/demo_area/ex_app1$ git checkout tags/mbed-os-5.4.0
SDesign2018 0:f72b3e7f1ec8 516 shell:/d/demo_area/ex_app1$ popd
SDesign2018 0:f72b3e7f1ec8 517 shell:/d/demo_area/ex_app1$ pushd sd-driver
SDesign2018 0:f72b3e7f1ec8 518 shell:/d/demo_area/ex_app1$ git checkout tags/sd-driver-0.0.2-mbed-os-5.4.0
SDesign2018 0:f72b3e7f1ec8 519 shell:/d/demo_area/ex_app1$ popd
SDesign2018 0:f72b3e7f1ec8 520
SDesign2018 0:f72b3e7f1ec8 521 In the above:
SDesign2018 0:f72b3e7f1ec8 522
SDesign2018 0:f72b3e7f1ec8 523 - `mbed-os-5.4.0` should be replaced with the latest mbed-os release tag.
SDesign2018 0:f72b3e7f1ec8 524 - For an mbed-os release tag `mbed-os-x.y.z`, use the equivalent sd-driver tag `sd-driver-a.b.c-mbed-os-x.y.z`
SDesign2018 0:f72b3e7f1ec8 525 where `a.b.c` is the latest version code for the `mbed-os-x.y.z` tag.
SDesign2018 0:f72b3e7f1ec8 526
SDesign2018 0:f72b3e7f1ec8 527 ### <a name="greentea-insert-sdcard-into-k64f"></a> Insert SDCard into K64F for Greentea Testing
SDesign2018 0:f72b3e7f1ec8 528
SDesign2018 0:f72b3e7f1ec8 529 See the previous section for [Insert SDCard into K64F](#insert-sdcard-into-k64f) for details.
SDesign2018 0:f72b3e7f1ec8 530
SDesign2018 0:f72b3e7f1ec8 531
SDesign2018 0:f72b3e7f1ec8 532 ### <a name="run-the-posix-file-test-cases"></a> Run the POSIX File Test Case
SDesign2018 0:f72b3e7f1ec8 533
SDesign2018 0:f72b3e7f1ec8 534 To setup for running the test cases, connect the K64F development board to your
SDesign2018 0:f72b3e7f1ec8 535 PC using a suitable USB cable.
SDesign2018 0:f72b3e7f1ec8 536
SDesign2018 0:f72b3e7f1ec8 537 All tests can be run using the following command:
SDesign2018 0:f72b3e7f1ec8 538
SDesign2018 0:f72b3e7f1ec8 539 shell:/d/demo_area/ex_app1$ mbedgt -VS
SDesign2018 0:f72b3e7f1ec8 540 <trace removed>
SDesign2018 0:f72b3e7f1ec8 541
SDesign2018 0:f72b3e7f1ec8 542 However, it's possible to run a particular test case using the following form of the mbedgt command:
SDesign2018 0:f72b3e7f1ec8 543
SDesign2018 0:f72b3e7f1ec8 544 shell:/d/demo_area/ex_app1$ mbedgt -VS --test-by-names=<test-name>
SDesign2018 0:f72b3e7f1ec8 545
SDesign2018 0:f72b3e7f1ec8 546 The names of the tests can be listed using:
SDesign2018 0:f72b3e7f1ec8 547
SDesign2018 0:f72b3e7f1ec8 548 shell:/d/demo_area/ex_app1$ mbedgt -VS --list
SDesign2018 0:f72b3e7f1ec8 549
SDesign2018 0:f72b3e7f1ec8 550 For example, to run the basic test use:
SDesign2018 0:f72b3e7f1ec8 551
SDesign2018 0:f72b3e7f1ec8 552 shell:/d/demo_area/ex_app1$ mbedgt -VS --test-by-names=sd-driver-tests-filesystem-basic
SDesign2018 0:f72b3e7f1ec8 553
SDesign2018 0:f72b3e7f1ec8 554 To run the fopen test use:
SDesign2018 0:f72b3e7f1ec8 555
SDesign2018 0:f72b3e7f1ec8 556 shell:/d/demo_area/ex_app1$ mbedgt -VS --test-by-names=sd-driver-tests-filesystem-fopen
SDesign2018 0:f72b3e7f1ec8 557
SDesign2018 0:f72b3e7f1ec8 558 On a successful run, results similar to the following will be shown:
SDesign2018 0:f72b3e7f1ec8 559
SDesign2018 0:f72b3e7f1ec8 560 mbedgt: test suite report:
SDesign2018 0:f72b3e7f1ec8 561 +--------------+---------------+-------------------------------------------+--------+--------------------+-------------+
SDesign2018 0:f72b3e7f1ec8 562 | target | platform_name | test suite | result | elapsed_time (sec) | copy_method |
SDesign2018 0:f72b3e7f1ec8 563 +--------------+---------------+-------------------------------------------+--------+--------------------+-------------+
SDesign2018 0:f72b3e7f1ec8 564 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | OK | 151.46 | shell |
SDesign2018 0:f72b3e7f1ec8 565 +--------------+---------------+-------------------------------------------+--------+--------------------+-------------+
SDesign2018 0:f72b3e7f1ec8 566 mbedgt: test suite results: 1 OK
SDesign2018 0:f72b3e7f1ec8 567 mbedgt: test case report:
SDesign2018 0:f72b3e7f1ec8 568 +--------------+---------------+------------------------------------+----------------------------------------------------------------------------------------+--------+--------+--------+--------------------+
SDesign2018 0:f72b3e7f1ec8 569 | target | platform_name | test suite | test case | passed | failed | result | elapsed_time (sec) |
SDesign2018 0:f72b3e7f1ec8 570 +--------------+---------------+------------------------------------+----------------------------------------------------------------------------------------+--------+--------+--------+--------------------+
SDesign2018 0:f72b3e7f1ec8 571 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_01: fopen()/fwrite()/fclose() directories/file in multi-dir filepath. | 1 | 0 | OK | 7.57 |
SDesign2018 0:f72b3e7f1ec8 572 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_02: fopen(r) pre-existing file try to write it. | 1 | 0 | OK | 0.2 |
SDesign2018 0:f72b3e7f1ec8 573 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_03: fopen(w+) pre-existing file try to write it. | 1 | 0 | OK | 0.41 |
SDesign2018 0:f72b3e7f1ec8 574 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_04: fopen() with a filename exceeding the maximum length. | 1 | 0 | OK | 0.11 |
SDesign2018 0:f72b3e7f1ec8 575 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_06: fopen() with bad filenames (minimal). | 1 | 0 | OK | 0.1 |
SDesign2018 0:f72b3e7f1ec8 576 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_07: fopen()/errno handling. | 1 | 0 | OK | 0.07 |
SDesign2018 0:f72b3e7f1ec8 577 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_08: ferror()/clearerr()/errno handling. | 1 | 0 | OK | 0.1 |
SDesign2018 0:f72b3e7f1ec8 578 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_09: ftell() handling. | 1 | 0 | OK | 0.17 |
SDesign2018 0:f72b3e7f1ec8 579 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_10: remove() test. | 1 | 0 | OK | 1.28 |
SDesign2018 0:f72b3e7f1ec8 580 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_11: rename(). | 1 | 0 | OK | 2.3 |
SDesign2018 0:f72b3e7f1ec8 581 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_12: opendir(), readdir(), closedir() test. | 1 | 0 | OK | 3.57 |
SDesign2018 0:f72b3e7f1ec8 582 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_13: mkdir() test. | 1 | 0 | OK | 1.21 |
SDesign2018 0:f72b3e7f1ec8 583 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_14: stat() test. | 1 | 0 | OK | 1.47 |
SDesign2018 0:f72b3e7f1ec8 584 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_15: format() test. | 1 | 0 | OK | 26.12 |
SDesign2018 0:f72b3e7f1ec8 585 | K64F-GCC_ARM | K64F | sd-driver-tests-filesystem-fopen | FSFAT_FOPEN_TEST_16: write/check n x 25kB data files. | 1 | 0 | OK | 87.11 |
SDesign2018 0:f72b3e7f1ec8 586 +--------------+---------------+------------------------------------+----------------------------------------------------------------------------------------+--------+--------+--------+--------------------+
SDesign2018 0:f72b3e7f1ec8 587 mbedgt: test case results: 15 OK
SDesign2018 0:f72b3e7f1ec8 588 mbedgt: completed in 152.35 sec
SDesign2018 0:f72b3e7f1ec8 589
SDesign2018 0:f72b3e7f1ec8 590
SDesign2018 0:f72b3e7f1ec8 591 # <a name="summary-posix-api-documentation"></a> Summary of POSIX File API Documentation
SDesign2018 0:f72b3e7f1ec8 592
SDesign2018 0:f72b3e7f1ec8 593 ### POSIX File API
SDesign2018 0:f72b3e7f1ec8 594
SDesign2018 0:f72b3e7f1ec8 595 mbed OS supports a subset of the POSIX File API, as outlined below:
SDesign2018 0:f72b3e7f1ec8 596
SDesign2018 0:f72b3e7f1ec8 597 - [clearerr()](https://linux.die.net/man/3/clearerr).
SDesign2018 0:f72b3e7f1ec8 598 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 599 - [fclose()](https://linux.die.net/man/3/fclose).
SDesign2018 0:f72b3e7f1ec8 600 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 601 - [ferror()](https://linux.die.net/man/3/clearerr).
SDesign2018 0:f72b3e7f1ec8 602 - STATUS: Basic testing implemented.
SDesign2018 0:f72b3e7f1ec8 603 - STATUS: GCC_ARM: Working.
SDesign2018 0:f72b3e7f1ec8 604 - STATUS: ARMCC: ARMCC has problem with ferror(filep) where filep is NULL. Appears to work for non-NULL pointer.
SDesign2018 0:f72b3e7f1ec8 605 - [fgetc()](https://linux.die.net/man/3/fgets).
SDesign2018 0:f72b3e7f1ec8 606 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 607 - [fgets()](https://linux.die.net/man/3/fgets).
SDesign2018 0:f72b3e7f1ec8 608 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 609 - [fputc()](https://linux.die.net/man/3/fputs).
SDesign2018 0:f72b3e7f1ec8 610 - STATUS: Unknown.
SDesign2018 0:f72b3e7f1ec8 611 - [fputs()](https://linux.die.net/man/3/fputs).
SDesign2018 0:f72b3e7f1ec8 612 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 613 - [fprintf()](https://linux.die.net/man/3/fprintf).
SDesign2018 0:f72b3e7f1ec8 614 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 615 - [fopen()](https://linux.die.net/man/3/fopen).
SDesign2018 0:f72b3e7f1ec8 616 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 617 - [freopen()](https://linux.die.net/man/3/fopen).
SDesign2018 0:f72b3e7f1ec8 618 - STATUS: This is not tested.
SDesign2018 0:f72b3e7f1ec8 619 - [fread()](https://linux.die.net/man/3/fread).
SDesign2018 0:f72b3e7f1ec8 620 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 621 - STATUS: n x 25kB stress test working.
SDesign2018 0:f72b3e7f1ec8 622 - [ftell()](https://linux.die.net/man/3/ftell).
SDesign2018 0:f72b3e7f1ec8 623 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 624 - [fwrite()](https://linux.die.net/man/3/fwrite).
SDesign2018 0:f72b3e7f1ec8 625 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 626 - STATUS: n x 25kB stress test working.
SDesign2018 0:f72b3e7f1ec8 627 - [fseek()](https://linux.die.net/man/3/fseek)
SDesign2018 0:f72b3e7f1ec8 628 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 629 - [getc()](https://linux.die.net/man/3/fgets).
SDesign2018 0:f72b3e7f1ec8 630 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 631 - [gets()](https://linux.die.net/man/3/fgets).
SDesign2018 0:f72b3e7f1ec8 632 - STATUS: Unknown.
SDesign2018 0:f72b3e7f1ec8 633 - [putc()](https://linux.die.net/man/3/fputs).
SDesign2018 0:f72b3e7f1ec8 634 - STATUS: Unknown.
SDesign2018 0:f72b3e7f1ec8 635 - [puts()](https://linux.die.net/man/3/fputs).
SDesign2018 0:f72b3e7f1ec8 636 - STATUS: Unknown.
SDesign2018 0:f72b3e7f1ec8 637 - [remove()](https://linux.die.net/man/3/remove)
SDesign2018 0:f72b3e7f1ec8 638 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 639 - [rewind()](https://linux.die.net/man/3/rewind).
SDesign2018 0:f72b3e7f1ec8 640 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 641 - [stat()](https://linux.die.net/man/2/stat)
SDesign2018 0:f72b3e7f1ec8 642 - STATUS: Implemented. Working.
SDesign2018 0:f72b3e7f1ec8 643 - STATUS: Not supported by ARMCC/IAR libc.
SDesign2018 0:f72b3e7f1ec8 644 - [tmpfile()](https://linux.die.net/man/3/tmpfile).
SDesign2018 0:f72b3e7f1ec8 645 - STATUS: Not implemented.
SDesign2018 0:f72b3e7f1ec8 646 - [tmpnam()](https://linux.die.net/man/3/tmpnam).
SDesign2018 0:f72b3e7f1ec8 647 - STATUS: Not implemented.
SDesign2018 0:f72b3e7f1ec8 648
SDesign2018 0:f72b3e7f1ec8 649 Supported directory related operations are as follows:
SDesign2018 0:f72b3e7f1ec8 650
SDesign2018 0:f72b3e7f1ec8 651 - [closedir()](https://linux.die.net/man/3/closedir).
SDesign2018 0:f72b3e7f1ec8 652 - STATUS: Implemented. Working.
SDesign2018 0:f72b3e7f1ec8 653 - [mkdir()](https://linux.die.net/man/3/mkdir).
SDesign2018 0:f72b3e7f1ec8 654 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 655 - [opendir()](https://linux.die.net/man/3/opendir).
SDesign2018 0:f72b3e7f1ec8 656 - STATUS: Implemented. Working.
SDesign2018 0:f72b3e7f1ec8 657 - [readdir()](https://linux.die.net/man/3/readdir).
SDesign2018 0:f72b3e7f1ec8 658 - STATUS: Implemented. Working.
SDesign2018 0:f72b3e7f1ec8 659 - [remove()](https://linux.die.net/man/3/remove).
SDesign2018 0:f72b3e7f1ec8 660 - STATUS: Basic testing implemented. Working.
SDesign2018 0:f72b3e7f1ec8 661 - [rename()](https://linux.die.net/man/3/rename).
SDesign2018 0:f72b3e7f1ec8 662 - STATUS: Implemented. Not tested.
SDesign2018 0:f72b3e7f1ec8 663 - [rewinddir()](https://linux.die.net/man/3/rewinddir).
SDesign2018 0:f72b3e7f1ec8 664 - STATUS: Implemented. Found not to work. Test case not present in repo.
SDesign2018 0:f72b3e7f1ec8 665 - [seekdir()](https://linux.die.net/man/3/seekdir).
SDesign2018 0:f72b3e7f1ec8 666 - STATUS: Implemented. Found not to work. Test case not present in repo.
SDesign2018 0:f72b3e7f1ec8 667 - [telldir()](https://linux.die.net/man/3/telldir).
SDesign2018 0:f72b3e7f1ec8 668 - STATUS: Implemented. Found not to work. Test case not present in repo.
SDesign2018 0:f72b3e7f1ec8 669
SDesign2018 0:f72b3e7f1ec8 670 ### errno
SDesign2018 0:f72b3e7f1ec8 671
SDesign2018 0:f72b3e7f1ec8 672 Basic errno reporting is supported, tested and known to be working.
SDesign2018 0:f72b3e7f1ec8 673
SDesign2018 0:f72b3e7f1ec8 674
SDesign2018 0:f72b3e7f1ec8 675 # Related Projects Resources
SDesign2018 0:f72b3e7f1ec8 676
SDesign2018 0:f72b3e7f1ec8 677 The following are related mbed storage projects and useful resources:
SDesign2018 0:f72b3e7f1ec8 678
SDesign2018 0:f72b3e7f1ec8 679 - The [mbed-os](https://github.com/ARMmbed/mbed-os) main repository.
SDesign2018 0:f72b3e7f1ec8 680 - The [mbed-os-example-fat-filesystem](https://github.com/ARMmbed/mbed-os-example-fat-filesystem) repository.
SDesign2018 0:f72b3e7f1ec8 681 This is an example project for the mbed OS FAT filesystem.
SDesign2018 0:f72b3e7f1ec8 682 - The [spiflash-driver](https://github.com/armmbed/spiflash-driver) repository.
SDesign2018 0:f72b3e7f1ec8 683 - The [i2ceeprom-driver](https://github.com/ARMmbed/i2ceeprom-driver.git) repository.
SDesign2018 0:f72b3e7f1ec8 684 - The [ci-test-shield](https://github.com/ARMmbed/ci-test-shield) repository. This is the project describing
SDesign2018 0:f72b3e7f1ec8 685 the mbed-os Continuous Integration test shield, together with standard tests.
SDesign2018 0:f72b3e7f1ec8 686 - The [mbed-HDK](https://github.com/ARMmbed/mbed-HDK) repository containing Hardware Development Kit resources
SDesign2018 0:f72b3e7f1ec8 687 including the schematics for the CI test shield.
SDesign2018 0:f72b3e7f1ec8 688 - [POSIX File Interface ISO/IEC 9899:TC2 Documentation](http://www.eng.utah.edu/~cs5785/slides-f10/n1124.pdf).
SDesign2018 0:f72b3e7f1ec8 689 - [FATFS: Generic FAT File System Module used in mbed OS](http://elm-chan.org/fsw/ff/00index_e.html)
SDesign2018 0:f72b3e7f1ec8 690