joseph adamu / Mbed OS CW_final_thr

Fork of CW_copy by Calvin Kalintra

Committer:
joseph_adamu
Date:
Wed Jan 10 09:50:29 2018 +0000
Revision:
1:dc648c5624b9
version for export

Who changed what in which revision?

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