Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

Fork of gr-peach-opencv-project-sd-card by the do

Committer:
thedo
Date:
Fri Jul 21 01:26:02 2017 +0000
Revision:
166:240bc5a0f42a
gr-peach-opencv-project-sd-card

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 166:240bc5a0f42a 1 # mbed OS SDCard Driver (sd-driver) for FAT32 Filesystem Support
thedo 166:240bc5a0f42a 2
thedo 166:240bc5a0f42a 3
thedo 166:240bc5a0f42a 4 Simon Hughes
thedo 166:240bc5a0f42a 5
thedo 166:240bc5a0f42a 6 20170329
thedo 166:240bc5a0f42a 7
thedo 166:240bc5a0f42a 8 Version 1.00
thedo 166:240bc5a0f42a 9
thedo 166:240bc5a0f42a 10
thedo 166:240bc5a0f42a 11 # Executive Summary
thedo 166:240bc5a0f42a 12
thedo 166:240bc5a0f42a 13 The purpose of this document is to describe how to use the mbed OS SDCard
thedo 166:240bc5a0f42a 14 driver (sd-driver) so applications can read/write
thedo 166:240bc5a0f42a 15 data to flash storage cards using the standard POSIX File API
thedo 166:240bc5a0f42a 16 programming interface. The sd-driver uses the SDCard SPI-mode of operation
thedo 166:240bc5a0f42a 17 which is a subset of possible SDCard functionality.
thedo 166:240bc5a0f42a 18
thedo 166:240bc5a0f42a 19 This repository contains the mbed-os SDCard driver for generic SPI
thedo 166:240bc5a0f42a 20 SDCard support and other resources, as outlined below:
thedo 166:240bc5a0f42a 21
thedo 166:240bc5a0f42a 22 - `SDBlockDevice.h` and `SDBlockDevice.cpp`. This is the SDCard driver module presenting
thedo 166:240bc5a0f42a 23 a Block Device API (derived from BlockDevice) to the underlying SDCard.
thedo 166:240bc5a0f42a 24 - POSIX File API test cases for testing the FAT32 filesystem on SDCard.
thedo 166:240bc5a0f42a 25 - basic.cpp, a basic set of functional test cases.
thedo 166:240bc5a0f42a 26 - fopen.cpp, more functional tests reading/writing greater volumes of data to SDCard, for example.
thedo 166:240bc5a0f42a 27 - `mbed_app.json` mbed-os application configuration file with SPI pin configurations for the CI shield and overrides for specific targets.
thedo 166:240bc5a0f42a 28 This file allows the SPI pins to be specified for the target without having to edit the implementation files.
thedo 166:240bc5a0f42a 29 - This README which includes [Summary of POSIX File API Documentation](#summary-posix-api-documentation)
thedo 166:240bc5a0f42a 30 including detailed instruction on how to use the FAT filesystem and SDBlockDevice driver.
thedo 166:240bc5a0f42a 31
thedo 166:240bc5a0f42a 32 The SDCard driver is maintained in this repository as a component separate from the main mbed OS repository.
thedo 166:240bc5a0f42a 33 Hence the 2 repositories (mbed-os and sd-driver) have to be used together
thedo 166:240bc5a0f42a 34 to deliver the FAT32 Filesystem/SDCard support. This document explains how to do this.
thedo 166:240bc5a0f42a 35
thedo 166:240bc5a0f42a 36
thedo 166:240bc5a0f42a 37 # Introduction
thedo 166:240bc5a0f42a 38
thedo 166:240bc5a0f42a 39 ### Overview
thedo 166:240bc5a0f42a 40
thedo 166:240bc5a0f42a 41 The scope of this document is to describe how applications use the FAT filesystem and sd-driver
thedo 166:240bc5a0f42a 42 components to persistently store data on SDCards. The document is intended to help developers adopt the
thedo 166:240bc5a0f42a 43 mbed OS POSIX File API support, and in particular to help explain:
thedo 166:240bc5a0f42a 44
thedo 166:240bc5a0f42a 45 - How the software components work together to deliver the storage functionality.
thedo 166:240bc5a0f42a 46 - How to work with the sd-driver and mbed OS to build the examples. The example code can easily
thedo 166:240bc5a0f42a 47 be copied into your new application code.
thedo 166:240bc5a0f42a 48 - How to work with the CI Test Shield, which adds an SDCard slot to those targets that do not have already have one.
thedo 166:240bc5a0f42a 49 - How to run the POSIX File API mbed Greentea test cases, which provide further example code of how to use
thedo 166:240bc5a0f42a 50 the POSIX File API.
thedo 166:240bc5a0f42a 51
thedo 166:240bc5a0f42a 52 Section 1 provides an Executive Summary, describing the purpose of the sd-driver, the supporting
thedo 166:240bc5a0f42a 53 software, examples, test cases and documentation.
thedo 166:240bc5a0f42a 54
thedo 166:240bc5a0f42a 55 Section 2 provides an an overview of the material covered including descriptions of the major sections.
thedo 166:240bc5a0f42a 56
thedo 166:240bc5a0f42a 57 Section 3 provides an overview of the mbed OS filesystem software components,
thedo 166:240bc5a0f42a 58 including the inter-relationships between the application, POSIX file API, the standard c-library,
thedo 166:240bc5a0f42a 59 the mbed OS filesystem and the SDCard driver (sd-driver).
thedo 166:240bc5a0f42a 60
thedo 166:240bc5a0f42a 61 Section 4 describes how to build and run an example application for reading
thedo 166:240bc5a0f42a 62 and writing data to an SDCard using the POSIX File API. The example begins by describing
thedo 166:240bc5a0f42a 63 the procedure for building and testing on the K64F target. The final sub-sections
thedo 166:240bc5a0f42a 64 describe how to use the test shield to add an SDCard slot to any mbed target,
thedo 166:240bc5a0f42a 65 and hence enable the persistent storage of data on any supported target.
thedo 166:240bc5a0f42a 66
thedo 166:240bc5a0f42a 67 Section 5 describes an example application which uses the raw
thedo 166:240bc5a0f42a 68 BlockDevice API to read and write data to the SDCard.
thedo 166:240bc5a0f42a 69
thedo 166:240bc5a0f42a 70 Section 6 describes how to build and run the SDCard POSIX File API mbed Greentea test cases.
thedo 166:240bc5a0f42a 71 There are a number of functional test cases demonstrating how to use the
thedo 166:240bc5a0f42a 72 mbed OS POSIX File API.
thedo 166:240bc5a0f42a 73
thedo 166:240bc5a0f42a 74 Section 7 describes the POSIX File API and provides links to useful API documentation web pages.
thedo 166:240bc5a0f42a 75
thedo 166:240bc5a0f42a 76
thedo 166:240bc5a0f42a 77 ### Known mbed-os and sd-driver Compatible Versions
thedo 166:240bc5a0f42a 78
thedo 166:240bc5a0f42a 79 The following versions of the mbed-os and sd-driver repositories are known to work together:
thedo 166:240bc5a0f42a 80
thedo 166:240bc5a0f42a 81 - {mbed-os, sd-driver} = {mbed-os-5.4.0-rc2, sd-driver-0.0.1-mbed-os-5.4.0-rc2}.
thedo 166:240bc5a0f42a 82 `K64F`, `NUCLEO_F429ZI` and `UBLOX_EVK_ODIN_W2` fopen and basic filesystem tests working.
thedo 166:240bc5a0f42a 83 - {mbed-os, sd-driver} = {mbed-os-5.4.0, sd-driver-0.0.2-mbed-os-5.4.0}.
thedo 166:240bc5a0f42a 84 `K64F`, `NUCLEO_F429ZI` and `UBLOX_EVK_ODIN_W2` fopen and basic filesystem tests working.
thedo 166:240bc5a0f42a 85 - {mbed-os, sd-driver} = {mbed-os-5.4.1, sd-driver-0.0.3-mbed-os-5.4.1}.
thedo 166:240bc5a0f42a 86
thedo 166:240bc5a0f42a 87 To find the latest compatible versions, use the following command to see the messages attached to the tags
thedo 166:240bc5a0f42a 88 in the sd-driver repository:
thedo 166:240bc5a0f42a 89
thedo 166:240bc5a0f42a 90 ex_app7/$ cd sd-driver
thedo 166:240bc5a0f42a 91 ex_app7/sd-driver$ git tag -n
thedo 166:240bc5a0f42a 92 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.
thedo 166:240bc5a0f42a 93 sd-driver-0.0.2-mbed-os-5.4.0 Updated README.md to include worked exmaples and restructuring of information.
thedo 166:240bc5a0f42a 94 sd-driver-0.0.3-mbed-os-5.4.1 Version compatible with mbed-os-5.4.1.
thedo 166:240bc5a0f42a 95
thedo 166:240bc5a0f42a 96
thedo 166:240bc5a0f42a 97 ### Known Issues With This Document
thedo 166:240bc5a0f42a 98
thedo 166:240bc5a0f42a 99 There are no known issues with this document.
thedo 166:240bc5a0f42a 100
thedo 166:240bc5a0f42a 101
thedo 166:240bc5a0f42a 102 # Overview of mbed OS Filesystem Software Component Stack
thedo 166:240bc5a0f42a 103
thedo 166:240bc5a0f42a 104
thedo 166:240bc5a0f42a 105 ------------------------
thedo 166:240bc5a0f42a 106 | |
thedo 166:240bc5a0f42a 107 | Application | // This application uses the POSIX File API
thedo 166:240bc5a0f42a 108 | | // to read/write data to persistent storage backends.
thedo 166:240bc5a0f42a 109 ------------------------
thedo 166:240bc5a0f42a 110
thedo 166:240bc5a0f42a 111 ------------------------ // POSIX File API (ISO).
thedo 166:240bc5a0f42a 112
thedo 166:240bc5a0f42a 113 ------------------------
thedo 166:240bc5a0f42a 114 | |
thedo 166:240bc5a0f42a 115 | libc | // The standard c library implementation
thedo 166:240bc5a0f42a 116 | | // e.g. newlib.
thedo 166:240bc5a0f42a 117 ------------------------
thedo 166:240bc5a0f42a 118
thedo 166:240bc5a0f42a 119 ------------------------ // sys_xxx equivalent API.
thedo 166:240bc5a0f42a 120
thedo 166:240bc5a0f42a 121 ------------------------
thedo 166:240bc5a0f42a 122 | |
thedo 166:240bc5a0f42a 123 | mbed_retarget.cpp | // Target specific mapping layer.
thedo 166:240bc5a0f42a 124 | |
thedo 166:240bc5a0f42a 125 ------------------------
thedo 166:240bc5a0f42a 126
thedo 166:240bc5a0f42a 127 ------------------------ // Filesystem Upper Edge API.
thedo 166:240bc5a0f42a 128
thedo 166:240bc5a0f42a 129 ------------------------
thedo 166:240bc5a0f42a 130 | |
thedo 166:240bc5a0f42a 131 | File System | // File system wrappers and implementation.
thedo 166:240bc5a0f42a 132 | |
thedo 166:240bc5a0f42a 133 ------------------------
thedo 166:240bc5a0f42a 134
thedo 166:240bc5a0f42a 135 ------------------------ // FS Lower Edge API (Block Store Interface).
thedo 166:240bc5a0f42a 136
thedo 166:240bc5a0f42a 137 ------------------------
thedo 166:240bc5a0f42a 138 | Block API |
thedo 166:240bc5a0f42a 139 | Device Driver | // The SDCard driver, for example.
thedo 166:240bc5a0f42a 140 | e.g. sd-driver |
thedo 166:240bc5a0f42a 141 ------------------------
thedo 166:240bc5a0f42a 142
thedo 166:240bc5a0f42a 143 ------------------------ // SPI.h interface.
thedo 166:240bc5a0f42a 144
thedo 166:240bc5a0f42a 145 ------------------------
thedo 166:240bc5a0f42a 146 | |
thedo 166:240bc5a0f42a 147 | SPI | // SPI subsystem (C++ classes and C-HAL implementation).
thedo 166:240bc5a0f42a 148 | |
thedo 166:240bc5a0f42a 149 ------------------------
thedo 166:240bc5a0f42a 150
thedo 166:240bc5a0f42a 151 Figure 1. mbedOS generic architecture of filesystem software stack.
thedo 166:240bc5a0f42a 152
thedo 166:240bc5a0f42a 153 The figure above shows the mbed OS software component stack used for data
thedo 166:240bc5a0f42a 154 storage on SDCard:
thedo 166:240bc5a0f42a 155
thedo 166:240bc5a0f42a 156 - At the top level is the application component which uses the standard POSIX File API
thedo 166:240bc5a0f42a 157 to read and write application data to persistent storage.
thedo 166:240bc5a0f42a 158 - The newlib standard library (libc) stdio.h interface (POSIX File API)
thedo 166:240bc5a0f42a 159 implementation is used as it's optimised for resource limited embedded systems.
thedo 166:240bc5a0f42a 160 - mbed_retarget.cpp implements the libc back-end file OS handlers and maps them
thedo 166:240bc5a0f42a 161 to the FileSystem.
thedo 166:240bc5a0f42a 162 - The File System code (hosted in mbed-os) is composed of 2 parts:
thedo 166:240bc5a0f42a 163 - The mbed OS file system wrapper classes (e.g. FileSystem, File, FileBase classes)
thedo 166:240bc5a0f42a 164 which are used to present a consistent API to the retarget module for different
thedo 166:240bc5a0f42a 165 (third-party) file system implementations.
thedo 166:240bc5a0f42a 166 - The FAT filesystem implementation code.
thedo 166:240bc5a0f42a 167 The [FATFS: Generic FAT File System Module](http://elm-chan.org/fsw/ff/00index_e.html)
thedo 166:240bc5a0f42a 168 (ChanFS) has been integrated within mbed-os.
thedo 166:240bc5a0f42a 169 - The Block API Device Driver. The SDCard driver is an example of a persistent storage driver.
thedo 166:240bc5a0f42a 170 It's maintained as a separate component from the mbed OS repository (in this repository).
thedo 166:240bc5a0f42a 171 - The SPI module provides the mbed OS generic SPI API. This functionality is maintained in
thedo 166:240bc5a0f42a 172 mbed OS.
thedo 166:240bc5a0f42a 173
thedo 166:240bc5a0f42a 174
thedo 166:240bc5a0f42a 175 # SDCard POSIX File API Example App for Reading/Writing Data
thedo 166:240bc5a0f42a 176
thedo 166:240bc5a0f42a 177 ### Overview
thedo 166:240bc5a0f42a 178
thedo 166:240bc5a0f42a 179 This section describes how to build and run an example application that
thedo 166:240bc5a0f42a 180 uses the POSIX File API to read and write data to SDCard. The discussion begins by
thedo 166:240bc5a0f42a 181 descibing how to run the example on the FRDM K64F target, but this is later
thedo 166:240bc5a0f42a 182 generalised to all target platforms that have the standard
thedo 166:240bc5a0f42a 183 Arduino form factor headers. Tthe Continuous Integration (CI) Test Shield
thedo 166:240bc5a0f42a 184 can be inserted into the headers to add a SDCard slot to the target.
thedo 166:240bc5a0f42a 185
thedo 166:240bc5a0f42a 186 The example code is a modified version of the
thedo 166:240bc5a0f42a 187 [mbed-os-example-fat-filesystem](https://github.com/ARMmbed/mbed-os-example-fat-filesystem) example
thedo 166:240bc5a0f42a 188 modified for use with the sd-driver.
thedo 166:240bc5a0f42a 189
thedo 166:240bc5a0f42a 190 The following sub-sections describe the steps for building and running the example:
thedo 166:240bc5a0f42a 191
thedo 166:240bc5a0f42a 192 - The [Pre-Requisites](#pre-requisites) section describes the development environment used for this example.
thedo 166:240bc5a0f42a 193 Other similar development environments can be used.
thedo 166:240bc5a0f42a 194 - The [Create the Example Project](#create-the-example-project) section describes how the application project is created
thedo 166:240bc5a0f42a 195 by including the mbed-os and sd-driver code.
thedo 166:240bc5a0f42a 196 - The [Build the Example Project](#build-the-example-project) section describes how to build the example application.
thedo 166:240bc5a0f42a 197 - The [Insert SDCard into K64F](#insert-sdcard-into-k64f) section describes how to select a card and insert it into the
thedo 166:240bc5a0f42a 198 SDCard slot on the K64F.
thedo 166:240bc5a0f42a 199 - The [Run the Example Binary on the K64F](#run-the-example-binary-on-the-k64f) section describes how to run the
thedo 166:240bc5a0f42a 200 example binary on the target and verify the example has run correctly.
thedo 166:240bc5a0f42a 201 - The [Testing with an SDCard on Target XYZ](#testing-with-an-sdcard-on-target-xyx) section describes the use
thedo 166:240bc5a0f42a 202 of Continuous Integration Test Shield, which hosts an SDCard slot. By inserting the CI test shield into the
thedo 166:240bc5a0f42a 203 Arduino headers of an mbed target platform, the SDCard/FAT Filesystem components can be used to store data
thedo 166:240bc5a0f42a 204 persistently on any standard mbed target development board.
thedo 166:240bc5a0f42a 205
thedo 166:240bc5a0f42a 206
thedo 166:240bc5a0f42a 207 ### <a name="pre-requisites"></a> Pre-Requisites
thedo 166:240bc5a0f42a 208
thedo 166:240bc5a0f42a 209 To work through this example, you should have a working development environment on your machine. For example,
thedo 166:240bc5a0f42a 210 the following tools should be installed:
thedo 166:240bc5a0f42a 211
thedo 166:240bc5a0f42a 212 - A compiler e.g. arm-none-eabi-gcc.
thedo 166:240bc5a0f42a 213 - Python 2.7.9 or later.
thedo 166:240bc5a0f42a 214 - [mbed Greentea](https://github.com/armmbed/greentea), the mbed OS test tool.
thedo 166:240bc5a0f42a 215 - Git Bash or a similar git command line tool to interact with the ARM mbed GitHub repositories.
thedo 166:240bc5a0f42a 216 - [mbed-cli](https://github.com/armmbed/mbed-cli), the tool used to make mbed OS application and test builds.
thedo 166:240bc5a0f42a 217
thedo 166:240bc5a0f42a 218 For more information on how to setup a development environment, please review the documentation on the
thedo 166:240bc5a0f42a 219 [mbed documentation site](https://docs.mbed.com).
thedo 166:240bc5a0f42a 220
thedo 166:240bc5a0f42a 221
thedo 166:240bc5a0f42a 222 ### <a name="create-the-example-project"></a> Create the Example Project
thedo 166:240bc5a0f42a 223
thedo 166:240bc5a0f42a 224 First create the top level application directory sd_ex1 and move into it:
thedo 166:240bc5a0f42a 225
thedo 166:240bc5a0f42a 226 simhug01@E107851:/d/demo_area$ mkdir sd_ex1
thedo 166:240bc5a0f42a 227 simhug01@E107851:/d/demo_area$ cd sd_ex1
thedo 166:240bc5a0f42a 228 simhug01@E107851:/d/demo_area/sd_ex1$
thedo 166:240bc5a0f42a 229
thedo 166:240bc5a0f42a 230 Next, perform the "mbed new" operation to download the mbed-os repository into this directory:
thedo 166:240bc5a0f42a 231
thedo 166:240bc5a0f42a 232 simhug01@E107851:/d/demo_area/sd_ex1$ mbed new .
thedo 166:240bc5a0f42a 233 [mbed] Creating new program "ex_sdcard" (git)
thedo 166:240bc5a0f42a 234 [mbed] Adding library "mbed-os" from "https://github.com/ARMmbed/mbed-os" at branch latest
thedo 166:240bc5a0f42a 235 [mbed] Updating reference "mbed-os" -> "https://github.com/ARMmbed/mbed-os/#5faf4b26c5954d15c7c1cccac6498e0c690ad101"
thedo 166:240bc5a0f42a 236 warning: LF will be replaced by CRLF in mbed-os.lib.
thedo 166:240bc5a0f42a 237 The file will have its original line endings in your working directory.
thedo 166:240bc5a0f42a 238 (mx1_venv1) simhug01@E107851:/d/demo_area/sd_ex1$ ls -1
thedo 166:240bc5a0f42a 239 mbed-os
thedo 166:240bc5a0f42a 240 mbed-os.lib
thedo 166:240bc5a0f42a 241 mbed_settings.py
thedo 166:240bc5a0f42a 242 (mx1_venv1) simhug01@E107851:/d/demo_area/sd_ex1$
thedo 166:240bc5a0f42a 243
thedo 166:240bc5a0f42a 244 Next, get add the sd-driver component to the application project:
thedo 166:240bc5a0f42a 245
thedo 166:240bc5a0f42a 246 simhug01@E107851:/d/demo_area/sd_ex1$ mbed add sd-driver
thedo 166:240bc5a0f42a 247 <trace removed>
thedo 166:240bc5a0f42a 248 simhug01@E107851:/d/demo_area/sd_ex1$
thedo 166:240bc5a0f42a 249
thedo 166:240bc5a0f42a 250 Next, copy the example1.cpp file and `mbed_app.json` files from inside the sd-driver directory to the top level sd_ex1 directory:
thedo 166:240bc5a0f42a 251
thedo 166:240bc5a0f42a 252 simhug01@E107851:/d/demo_area/sd_ex1$ cp sd-driver/features/TESTS/examples/example1.cpp .
thedo 166:240bc5a0f42a 253 simhug01@E107851:/d/demo_area/sd_ex1$ cp sd-driver/config/mbed_app.json .
thedo 166:240bc5a0f42a 254 simhug01@E107851:/d/demo_area/sd_ex1$
thedo 166:240bc5a0f42a 255
thedo 166:240bc5a0f42a 256 The `mbed_app.json` file specifies the SPI bus pin configuration for different targets.
thedo 166:240bc5a0f42a 257 The file includes a specific configuration of the K64F which is used
thedo 166:240bc5a0f42a 258 because the mbed compile command specifies the K64F build target. The `mbed_app.json` file
thedo 166:240bc5a0f42a 259 is described in more detail in the [Testing with an SDCard on Target XYZ](#testing-with-an-sdcard-on-target-xyx) section.
thedo 166:240bc5a0f42a 260
thedo 166:240bc5a0f42a 261 ### <a name="build-the-example-project"></a> Build the Example Project
thedo 166:240bc5a0f42a 262
thedo 166:240bc5a0f42a 263 Next, build the example application:
thedo 166:240bc5a0f42a 264
thedo 166:240bc5a0f42a 265 simhug01@E107851:/d/demo_area/sd_ex1$ mbed compile -m K64F -t GCC_ARM 2>&1 | tee build_log.txt
thedo 166:240bc5a0f42a 266
thedo 166:240bc5a0f42a 267
thedo 166:240bc5a0f42a 268 #### WARNING: "mbed new ." command and possible mbed-os sd-driver versioning incompatibilities
thedo 166:240bc5a0f42a 269
thedo 166:240bc5a0f42a 270 If you experience problems building the example then it may mean the version
thedo 166:240bc5a0f42a 271 of the mbed-os repository created with the "mbed new ." command is not compatible with
thedo 166:240bc5a0f42a 272 the sd-driver repository version created with "mbed add sd-driver" command. This is because:
thedo 166:240bc5a0f42a 273
thedo 166:240bc5a0f42a 274 - The "mbed new ." creates the mbed-os repository at the latest "Release" e.g. `mbed-os-5.4.0`.
thedo 166:240bc5a0f42a 275 - The "mbed add sd-driver" command creates the sd-driver repository at the latest version of
thedo 166:240bc5a0f42a 276 master i.e. the tip of master. Changes may be present that are not compatible with
thedo 166:240bc5a0f42a 277 the latest mbed-os release e.g. in preparation for the next release.
thedo 166:240bc5a0f42a 278
thedo 166:240bc5a0f42a 279 This situation can be resolved by checking out compatible versions of the repositories as
thedo 166:240bc5a0f42a 280 described in the section [Setting mbed-os/sd-driver Repositories To Compatible Versions](#settting-repos-to-compatible-versions)
thedo 166:240bc5a0f42a 281
thedo 166:240bc5a0f42a 282 ### <a name="insert-sdcard-into-k64f"></a> Insert SDCard into K64F
thedo 166:240bc5a0f42a 283
thedo 166:240bc5a0f42a 284 The examples and test cases have been run on a K64F with the following pre-formatted microSDHC cards:
thedo 166:240bc5a0f42a 285
thedo 166:240bc5a0f42a 286 - Kingston 2GB mircoSDHC card.
thedo 166:240bc5a0f42a 287 - Kingston 8GB mircoSDHC card.
thedo 166:240bc5a0f42a 288 - SanDisk 16GB mircoSDHC ultra card.
thedo 166:240bc5a0f42a 289
thedo 166:240bc5a0f42a 290 If the card requires formatting then the following procedure is known to work:
thedo 166:240bc5a0f42a 291
thedo 166:240bc5a0f42a 292 - Insert microSD card into SD adapter in USB stick (or similar) so the microSD card can be insert into windows PC.
thedo 166:240bc5a0f42a 293 - Within file explorer, right click/Format on the USB drive.
thedo 166:240bc5a0f42a 294 - Select FAT32, 4096 cluster size, Quick Format.
thedo 166:240bc5a0f42a 295 - Format the drive.
thedo 166:240bc5a0f42a 296
thedo 166:240bc5a0f42a 297 The microSD card should then be ready for use in the K64F. Insert the formatted card
thedo 166:240bc5a0f42a 298 into the SDCard slot on the K64F PCB.
thedo 166:240bc5a0f42a 299
thedo 166:240bc5a0f42a 300
thedo 166:240bc5a0f42a 301 ### <a name="run-the-example-binary-on-the-k64f"></a> Run the Example Binary on the K64F
thedo 166:240bc5a0f42a 302
thedo 166:240bc5a0f42a 303 Once the binary is built, copy the binary from `/d/demo_area/sd_ex1/BUILD/K64F/GCC_ARM/example1.bin` to the K64F.
thedo 166:240bc5a0f42a 304 After connecting a serial console and resetting the target, the following trace should be seen:
thedo 166:240bc5a0f42a 305
thedo 166:240bc5a0f42a 306 Welcome to the filesystem example.
thedo 166:240bc5a0f42a 307 Opening a new file, numbers.txt. done.
thedo 166:240bc5a0f42a 308 Writing decimal numbers to a file (20/20) done.
thedo 166:240bc5a0f42a 309 Closing file. done.
thedo 166:240bc5a0f42a 310 Re-opening file read-only. done.
thedo 166:240bc5a0f42a 311 Dumping file to screen.
thedo 166:240bc5a0f42a 312 0
thedo 166:240bc5a0f42a 313 1
thedo 166:240bc5a0f42a 314 2
thedo 166:240bc5a0f42a 315 3
thedo 166:240bc5a0f42a 316 4
thedo 166:240bc5a0f42a 317 5
thedo 166:240bc5a0f42a 318 6
thedo 166:240bc5a0f42a 319 7
thedo 166:240bc5a0f42a 320 8
thedo 166:240bc5a0f42a 321 9
thedo 166:240bc5a0f42a 322 10
thedo 166:240bc5a0f42a 323 11
thedo 166:240bc5a0f42a 324 12
thedo 166:240bc5a0f42a 325 13
thedo 166:240bc5a0f42a 326 14
thedo 166:240bc5a0f42a 327 15
thedo 166:240bc5a0f42a 328 16
thedo 166:240bc5a0f42a 329 17
thedo 166:240bc5a0f42a 330 18
thedo 166:240bc5a0f42a 331 19
thedo 166:240bc5a0f42a 332 EOF.
thedo 166:240bc5a0f42a 333 Closing file. done.
thedo 166:240bc5a0f42a 334 Opening root directory. done.
thedo 166:240bc5a0f42a 335 Printing all filenames:
thedo 166:240bc5a0f42a 336 numbers.txt
thedo 166:240bc5a0f42a 337 Closeing root directory. done.
thedo 166:240bc5a0f42a 338 Filesystem Demo complete.
thedo 166:240bc5a0f42a 339
thedo 166:240bc5a0f42a 340
thedo 166:240bc5a0f42a 341 ### <a name="testing-with-an-sdcard-on-target-xyx"></a> Testing with an SDCard on Target XYZ
thedo 166:240bc5a0f42a 342
thedo 166:240bc5a0f42a 343 The standard way to test is with the mbed CI Test Shield plugged into the
thedo 166:240bc5a0f42a 344 target board. This pin mapping for this configuration is parameterised in
thedo 166:240bc5a0f42a 345 the `mbed_app.json` file.
thedo 166:240bc5a0f42a 346
thedo 166:240bc5a0f42a 347 The following is an example of the `mbed_app.json` file available in the repository:
thedo 166:240bc5a0f42a 348
thedo 166:240bc5a0f42a 349 {
thedo 166:240bc5a0f42a 350 "config": {
thedo 166:240bc5a0f42a 351 "UART_RX": "D0",
thedo 166:240bc5a0f42a 352 "UART_TX": "D1",
thedo 166:240bc5a0f42a 353 "DIO_0": "D0",
thedo 166:240bc5a0f42a 354 "DIO_1": "D1",
thedo 166:240bc5a0f42a 355 "DIO_2": "D2",
thedo 166:240bc5a0f42a 356 "DIO_3": "D3",
thedo 166:240bc5a0f42a 357 "DIO_4": "D4",
thedo 166:240bc5a0f42a 358 "DIO_5": "D5",
thedo 166:240bc5a0f42a 359 "DIO_6": "D6",
thedo 166:240bc5a0f42a 360 "DIO_7": "D7",
thedo 166:240bc5a0f42a 361 "DIO_8": "D8",
thedo 166:240bc5a0f42a 362 "DIO_9": "D9",
thedo 166:240bc5a0f42a 363 "SPI_CS": "D10",
thedo 166:240bc5a0f42a 364 "SPI_MOSI": "D11",
thedo 166:240bc5a0f42a 365 "SPI_MISO": "D12",
thedo 166:240bc5a0f42a 366 "SPI_CLK": "D13",
thedo 166:240bc5a0f42a 367 "I2C_SDA": "D14",
thedo 166:240bc5a0f42a 368 "I2C_SCL": "D15",
thedo 166:240bc5a0f42a 369 "I2C_TEMP_ADDR":"0x90",
thedo 166:240bc5a0f42a 370 "I2C_EEPROM_ADDR":"0xA0",
thedo 166:240bc5a0f42a 371 "AIN_0": "A0",
thedo 166:240bc5a0f42a 372 "AIN_1": "A1",
thedo 166:240bc5a0f42a 373 "AIN_2": "A2",
thedo 166:240bc5a0f42a 374 "AIN_3": "A3",
thedo 166:240bc5a0f42a 375 "AIN_4": "A4",
thedo 166:240bc5a0f42a 376 "AIN_5": "A5",
thedo 166:240bc5a0f42a 377 "AOUT" : "A5",
thedo 166:240bc5a0f42a 378 "PWM_0": "D3",
thedo 166:240bc5a0f42a 379 "PWM_1": "D5",
thedo 166:240bc5a0f42a 380 "PWM_2": "D6",
thedo 166:240bc5a0f42a 381 "PWM_3": "D9",
thedo 166:240bc5a0f42a 382 "DEBUG_MSG": 0,
thedo 166:240bc5a0f42a 383 "DEVICE_SPI": 1,
thedo 166:240bc5a0f42a 384 "FSFAT_SDCARD_INSTALLED": 1
thedo 166:240bc5a0f42a 385 },
thedo 166:240bc5a0f42a 386 "target_overrides": {
thedo 166:240bc5a0f42a 387 "DISCO_F051R8": {
thedo 166:240bc5a0f42a 388 "SPI_MOSI": "SPI_MOSI",
thedo 166:240bc5a0f42a 389 "SPI_MISO": "SPI_MISO",
thedo 166:240bc5a0f42a 390 "SPI_CLK": "SPI_SCK",
thedo 166:240bc5a0f42a 391 "SPI_CS": "SPI_CS"
thedo 166:240bc5a0f42a 392 },
thedo 166:240bc5a0f42a 393 "K20D50M": {
thedo 166:240bc5a0f42a 394 "SPI_MOSI": "PTD2",
thedo 166:240bc5a0f42a 395 "SPI_MISO": "PTD3",
thedo 166:240bc5a0f42a 396 "SPI_CLK": "PTD1",
thedo 166:240bc5a0f42a 397 "SPI_CS": "PTC2"
thedo 166:240bc5a0f42a 398 },
thedo 166:240bc5a0f42a 399 "KL22F": {
thedo 166:240bc5a0f42a 400 "SPI_MOSI": "PTD6",
thedo 166:240bc5a0f42a 401 "SPI_MISO": "PTD7",
thedo 166:240bc5a0f42a 402 "SPI_CLK": "PTD5",
thedo 166:240bc5a0f42a 403 "SPI_CS": "PTD4"
thedo 166:240bc5a0f42a 404 },
thedo 166:240bc5a0f42a 405 "KL25Z": {
thedo 166:240bc5a0f42a 406 "SPI_MOSI": "PTD2",
thedo 166:240bc5a0f42a 407 "SPI_MISO": "PTD3",
thedo 166:240bc5a0f42a 408 "SPI_CLK": "PTD1",
thedo 166:240bc5a0f42a 409 "SPI_CS": "PTD0"
thedo 166:240bc5a0f42a 410 },
thedo 166:240bc5a0f42a 411 "KL43Z": {
thedo 166:240bc5a0f42a 412 "SPI_MOSI": "PTD6",
thedo 166:240bc5a0f42a 413 "SPI_MISO": "PTD7",
thedo 166:240bc5a0f42a 414 "SPI_CLK": "PTD5",
thedo 166:240bc5a0f42a 415 "SPI_CS": "PTD4"
thedo 166:240bc5a0f42a 416 },
thedo 166:240bc5a0f42a 417 "KL46Z": {
thedo 166:240bc5a0f42a 418 "SPI_MOSI": "PTD6",
thedo 166:240bc5a0f42a 419 "SPI_MISO": "PTD7",
thedo 166:240bc5a0f42a 420 "SPI_CLK": "PTD5",
thedo 166:240bc5a0f42a 421 "SPI_CS": "PTD4"
thedo 166:240bc5a0f42a 422 },
thedo 166:240bc5a0f42a 423 "K64F": {
thedo 166:240bc5a0f42a 424 "SPI_MOSI": "PTE3",
thedo 166:240bc5a0f42a 425 "SPI_MISO": "PTE1",
thedo 166:240bc5a0f42a 426 "SPI_CLK": "PTE2",
thedo 166:240bc5a0f42a 427 "SPI_CS": "PTE4"
thedo 166:240bc5a0f42a 428 },
thedo 166:240bc5a0f42a 429 "K66F": {
thedo 166:240bc5a0f42a 430 "SPI_MOSI": "PTE3",
thedo 166:240bc5a0f42a 431 "SPI_MISO": "PTE1",
thedo 166:240bc5a0f42a 432 "SPI_CLK": "PTE2",
thedo 166:240bc5a0f42a 433 "SPI_CS": "PTE4"
thedo 166:240bc5a0f42a 434 },
thedo 166:240bc5a0f42a 435 "LPC11U37H_401": {
thedo 166:240bc5a0f42a 436 "SPI_MOSI": "SDMOSI",
thedo 166:240bc5a0f42a 437 "SPI_MISO": "SDMISO",
thedo 166:240bc5a0f42a 438 "SPI_CLK": "SDSCLK",
thedo 166:240bc5a0f42a 439 "SPI_CS": "SDSSEL"
thedo 166:240bc5a0f42a 440 },
thedo 166:240bc5a0f42a 441 "LPC2368": {
thedo 166:240bc5a0f42a 442 "SPI_MOSI": "p11",
thedo 166:240bc5a0f42a 443 "SPI_MISO": "p12",
thedo 166:240bc5a0f42a 444 "SPI_CLK": "p13",
thedo 166:240bc5a0f42a 445 "SPI_CS": "p14"
thedo 166:240bc5a0f42a 446 },
thedo 166:240bc5a0f42a 447 "NUCLEO_L031K6": {
thedo 166:240bc5a0f42a 448 "SPI_MOSI": "SPI_MOSI",
thedo 166:240bc5a0f42a 449 "SPI_MISO": "SPI_MISO",
thedo 166:240bc5a0f42a 450 "SPI_CLK": "SPI_SCK",
thedo 166:240bc5a0f42a 451 "SPI_CS": "SPI_CS"
thedo 166:240bc5a0f42a 452 },
thedo 166:240bc5a0f42a 453 "nRF51822": {
thedo 166:240bc5a0f42a 454 "SPI_MOSI": "p12",
thedo 166:240bc5a0f42a 455 "SPI_MISO": "p13",
thedo 166:240bc5a0f42a 456 "SPI_CLK": "p15",
thedo 166:240bc5a0f42a 457 "SPI_CS": "p14"
thedo 166:240bc5a0f42a 458 },
thedo 166:240bc5a0f42a 459 "RZ_A1H": {
thedo 166:240bc5a0f42a 460 "SPI_MOSI": "P8_5",
thedo 166:240bc5a0f42a 461 "SPI_MISO": "P8_6",
thedo 166:240bc5a0f42a 462 "SPI_CLK": "P8_3",
thedo 166:240bc5a0f42a 463 "SPI_CS": "P8_4"
thedo 166:240bc5a0f42a 464 }
thedo 166:240bc5a0f42a 465 }
thedo 166:240bc5a0f42a 466 }
thedo 166:240bc5a0f42a 467
thedo 166:240bc5a0f42a 468 Note the following things about the `mbed_app.json` file:
thedo 166:240bc5a0f42a 469
thedo 166:240bc5a0f42a 470 - The `mbed_app.json` file is used to define target specific symbols for the SPI pins connecting the SDCard slot to the target MCU:
thedo 166:240bc5a0f42a 471 - "SPI\_CS". This is the Chip Select line.
thedo 166:240bc5a0f42a 472 - "SPI\_MOSI". This is the Master Out Slave In data line.
thedo 166:240bc5a0f42a 473 - "SPI\_MISO". This is the Master In Slave Out data line.
thedo 166:240bc5a0f42a 474 - "SPI\_CLK". This is the serial Clock line.
thedo 166:240bc5a0f42a 475 - The default configuration defined in the "config" section is for the standard Arduino header pin mappings for the SPI bus.
thedo 166:240bc5a0f42a 476 The "config" section defines a dictionary mapping functional names to target board Arduino header pins:
thedo 166:240bc5a0f42a 477 - "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.
thedo 166:240bc5a0f42a 478 D10 is defined in the target specific PinNames.h file.
thedo 166:240bc5a0f42a 479 - "SPI\_MOSI": "D11". This causes the MBED\_CONF\_APP\_SPI\_MOSI symbol to be defined in mbed\_config.h.
thedo 166:240bc5a0f42a 480 - "SPI\_MISO": "D12". This causes the MBED\_CONF\_APP\_SPI\_MISO symbol to be defined in mbed\_config.h.
thedo 166:240bc5a0f42a 481 - "SPI\_CLK": "D13". This causes the MBED\_CONF\_APP\_SPI\_CLK symbol to be defined in mbed\_config.h.
thedo 166:240bc5a0f42a 482 - The `"target_overrides"` section is used to override the "SPI\_xxx" symbols for specific target boards, which may have an SDCard slot, for example.
thedo 166:240bc5a0f42a 483 This is the case for the K64F, where the "SPI\_xxx" are mapped to the pin names for the on-board SDCard.
thedo 166:240bc5a0f42a 484
thedo 166:240bc5a0f42a 485 ```
thedo 166:240bc5a0f42a 486 "K64F": {
thedo 166:240bc5a0f42a 487 "SPI_MOSI": "PTE3",
thedo 166:240bc5a0f42a 488 "SPI_MISO": "PTE1",
thedo 166:240bc5a0f42a 489 "SPI_CLK": "PTE2",
thedo 166:240bc5a0f42a 490 "SPI_CS": "PTE4"
thedo 166:240bc5a0f42a 491 }
thedo 166:240bc5a0f42a 492 ```
thedo 166:240bc5a0f42a 493 - Thus, in the absence of any target specific definitions in the `"target_overrides"` section, all boards will default to
thedo 166:240bc5a0f42a 494 using the Arduino header configuration. For those platforms with a `"target_overrides"` section then this configuration
thedo 166:240bc5a0f42a 495 will be used in preference.
thedo 166:240bc5a0f42a 496 - Hence in the case that you want to test a platform with an SDCard inserted into a
thedo 166:240bc5a0f42a 497 fitted CI test shield (rather than the on-board SDCard slot)
thedo 166:240bc5a0f42a 498 and there is a `"target_overrides"` section present in the `mbed_app.json` file, you must then delete the `"target_overrides"`
thedo 166:240bc5a0f42a 499 section before building. This will result in the default configuration being used (suitable for the CI
thedo 166:240bc5a0f42a 500 Test Shield).
thedo 166:240bc5a0f42a 501 - Note when inserting the v1.0.0 CI Test Shield into the Arduino header of the target platform, the shield pins D0 and
thedo 166:240bc5a0f42a 502 D1 should be bent to be parallel to the shield PCB so they are not inserted into the Arduino header. This is because
thedo 166:240bc5a0f42a 503 some boards use the same UART on DAPLINK and D0/D1, which means the serial debug channel breaks and hence the mbed greentea
thedo 166:240bc5a0f42a 504 test suite will not work correctly. This is mainly on older ST boards and should not be a problem on
thedo 166:240bc5a0f42a 505 `K64F`, `NUCLEO_F429ZI` and `UBLOX_EVK_ODIN_W2`. Note also that the v2.0.0 CI Test Shield doesn't suffer from this
thedo 166:240bc5a0f42a 506 problem and the pins don't need to be bent.
thedo 166:240bc5a0f42a 507 - When inserting the SDCard into the card slot on the CI test shield, make sure the card is fully inserted.
thedo 166:240bc5a0f42a 508 On insertion, there should be a small clicking sound when the card registers, and the back edge of the card
thedo 166:240bc5a0f42a 509 should protrude no more than ~1mm over the edge of the CI test shield PCB. If the SDCard fails to register,
thedo 166:240bc5a0f42a 510 try gently pushing the metal flexible strip in the shape of a spade at the top edge of the SDCard metal slot
thedo 166:240bc5a0f42a 511 casing with a pair of tweezers, bending it a little to lower it into the slot casing. This helps with the
thedo 166:240bc5a0f42a 512 insertion mechanism.
thedo 166:240bc5a0f42a 513
thedo 166:240bc5a0f42a 514
thedo 166:240bc5a0f42a 515 ### Target K64F with CI Test Shield fitted
thedo 166:240bc5a0f42a 516
thedo 166:240bc5a0f42a 517 ![alt text](docs/pics/sd_driver_k64_with_ci_test_shield.jpg "unseen title text")
thedo 166:240bc5a0f42a 518
thedo 166:240bc5a0f42a 519 **Figure 2. The figure shows the K64F platform with the CI shield fitted.**
thedo 166:240bc5a0f42a 520
thedo 166:240bc5a0f42a 521 The above figure shows the K64F with the v1.0.0 CI test shield fitted. Note:
thedo 166:240bc5a0f42a 522
thedo 166:240bc5a0f42a 523 - The pins D0/D1 (top right of CI test shield) are bent sideways so as not to insert into the header.
thedo 166:240bc5a0f42a 524 - The SDCard is fully inserted into the slot and overhangs the PCB by ~1mm.
thedo 166:240bc5a0f42a 525
thedo 166:240bc5a0f42a 526
thedo 166:240bc5a0f42a 527 # SDBlockDevice Example Application
thedo 166:240bc5a0f42a 528
thedo 166:240bc5a0f42a 529 The following sample code illustrates how to use the sd-driver Block Device API:
thedo 166:240bc5a0f42a 530
thedo 166:240bc5a0f42a 531
thedo 166:240bc5a0f42a 532 #include "mbed.h"
thedo 166:240bc5a0f42a 533 #include "SDBlockDevice.h"
thedo 166:240bc5a0f42a 534
thedo 166:240bc5a0f42a 535 // Instantiate the SDBlockDevice by specifying the SPI pins connected to the SDCard
thedo 166:240bc5a0f42a 536 // socket. The PINS are:
thedo 166:240bc5a0f42a 537 // MOSI (Master Out Slave In)
thedo 166:240bc5a0f42a 538 // MISO (Master In Slave Out)
thedo 166:240bc5a0f42a 539 // SCLK (Serial Clock)
thedo 166:240bc5a0f42a 540 // CS (Chip Select)
thedo 166:240bc5a0f42a 541 SDBlockDevice sd(p5, p6, p7, p12); // mosi, miso, sclk, cs
thedo 166:240bc5a0f42a 542 uint8_t block[512] = "Hello World!\n";
thedo 166:240bc5a0f42a 543
thedo 166:240bc5a0f42a 544 int main()
thedo 166:240bc5a0f42a 545 {
thedo 166:240bc5a0f42a 546 // call the SDBlockDevice instance initialisation method.
thedo 166:240bc5a0f42a 547 sd.init();
thedo 166:240bc5a0f42a 548
thedo 166:240bc5a0f42a 549 // Write some the data block to the device
thedo 166:240bc5a0f42a 550 sd.program(block, 0, 512);
thedo 166:240bc5a0f42a 551
thedo 166:240bc5a0f42a 552 // read the data block from the device
thedo 166:240bc5a0f42a 553 sd.read(block, 0, 512);
thedo 166:240bc5a0f42a 554
thedo 166:240bc5a0f42a 555 // print the contents of the block
thedo 166:240bc5a0f42a 556 printf("%s", block);
thedo 166:240bc5a0f42a 557
thedo 166:240bc5a0f42a 558 // call the SDBlockDevice instance de-initialisation method.
thedo 166:240bc5a0f42a 559 sd.deinit();
thedo 166:240bc5a0f42a 560 }
thedo 166:240bc5a0f42a 561
thedo 166:240bc5a0f42a 562
thedo 166:240bc5a0f42a 563 # SDCard POSIX File API mbed Greentea Test Cases
thedo 166:240bc5a0f42a 564
thedo 166:240bc5a0f42a 565 This section describes how to build and run the POSIX file API test cases.
thedo 166:240bc5a0f42a 566 The following steps are covered:
thedo 166:240bc5a0f42a 567
thedo 166:240bc5a0f42a 568 - [Create the FAT/SDCard Application Project](#create-fat-sdcard-application-project).
thedo 166:240bc5a0f42a 569 This section describes how to git clone the mbed OS and sd-driver repositories containing the
thedo 166:240bc5a0f42a 570 code and test cases of interest.
thedo 166:240bc5a0f42a 571 - [Build the mbed OS Test Cases](#build-the-mbedos-test-cases). This section
thedo 166:240bc5a0f42a 572 describes how to build the mbed OS test cases.
thedo 166:240bc5a0f42a 573 - [Insert a microSD Card Into the K64F for Greentea Testing](#greentea-insert-sdcard-into-k64f).This section
thedo 166:240bc5a0f42a 574 describes how to format (if required) a microSD card prior to running the tests.
thedo 166:240bc5a0f42a 575 - [Run the POSIX File Test Case](#run-the-posix-file-test-cases).This section
thedo 166:240bc5a0f42a 576 describes how to run the POSIX file test cases.
thedo 166:240bc5a0f42a 577
thedo 166:240bc5a0f42a 578
thedo 166:240bc5a0f42a 579 ### <a name="create-fat-sdcard-application-project"></a> Create the FAT/SDCard Application Project
thedo 166:240bc5a0f42a 580
thedo 166:240bc5a0f42a 581 This section describes how to create an application project combining the
thedo 166:240bc5a0f42a 582 mbed-os and sd-driver repositories into a single project.
thedo 166:240bc5a0f42a 583 In summary the following steps will be covered in this section:
thedo 166:240bc5a0f42a 584
thedo 166:240bc5a0f42a 585 - A top level application project directory is created. The directory name is ex_app1.
thedo 166:240bc5a0f42a 586 - In the ex_app1 directory, the mbed-os repository is cloned.
thedo 166:240bc5a0f42a 587 - In the ex_app1 directory at the same level as the mbed-os directory, the sd-driver repository is cloned.
thedo 166:240bc5a0f42a 588 - The `mbed_app.json` file is copied from the `sd-driver/config/mbed_app.json` to the ex_app1 directory.
thedo 166:240bc5a0f42a 589
thedo 166:240bc5a0f42a 590 First create the top level application directory ex_app1 and move into it:
thedo 166:240bc5a0f42a 591
thedo 166:240bc5a0f42a 592 simhug01@E107851:/d/demo_area$ mkdir ex_app1
thedo 166:240bc5a0f42a 593 simhug01@E107851:/d/demo_area$ pushd ex_app1
thedo 166:240bc5a0f42a 594
thedo 166:240bc5a0f42a 595 Next, get a clone of public mbed OS repository in the following way:
thedo 166:240bc5a0f42a 596
thedo 166:240bc5a0f42a 597 simhug01@E107851:/d/demo_area/ex_app1$ git clone git@github.com:/armmbed/mbed-os
thedo 166:240bc5a0f42a 598 <trace removed>
thedo 166:240bc5a0f42a 599 simhug01@E107851:/d/demo_area/ex_app1$
thedo 166:240bc5a0f42a 600
thedo 166:240bc5a0f42a 601 Next, get a clone of the sd-driver repository:
thedo 166:240bc5a0f42a 602
thedo 166:240bc5a0f42a 603 simhug01@E107851:/d/demo_area/ex_app1$ git clone git@github.com:/armmbed/sd-driver
thedo 166:240bc5a0f42a 604 <trace removed>
thedo 166:240bc5a0f42a 605 simhug01@E107851:/d/demo_area/ex_app1$
thedo 166:240bc5a0f42a 606
thedo 166:240bc5a0f42a 607 Finally, copy the `mbed_app.json` application configuration file from `sd-driver/config/mbed_app.json` to the ex_app1 directory:
thedo 166:240bc5a0f42a 608
thedo 166:240bc5a0f42a 609 simhug01@E107851:/d/demo_area/ex_app1$ cp sd-driver/config/mbed_app.json .
thedo 166:240bc5a0f42a 610 simhug01@E107851:/d/demo_area/ex_app1$
thedo 166:240bc5a0f42a 611
thedo 166:240bc5a0f42a 612 The `mbed_app.json` file specifies the SPI bus pin configuration for different targets,
thedo 166:240bc5a0f42a 613 and is discussed in the [Testing with an SDCard on Target XYZ](#testing-with-an-sdcard-on-target-xyx) section.
thedo 166:240bc5a0f42a 614
thedo 166:240bc5a0f42a 615
thedo 166:240bc5a0f42a 616 ### <a name="build-the-mbedos-test-cases"></a> Build the mbed OS Test Cases
thedo 166:240bc5a0f42a 617
thedo 166:240bc5a0f42a 618 Build the test cases for the K64F target using the following command:
thedo 166:240bc5a0f42a 619
thedo 166:240bc5a0f42a 620 simhug01@E107851:/d/demo_area/ex_app1$ mbed -v test --compile -t GCC_ARM -m K64F --app-config mbed_app.json 2>&1 | tee build_tests_gcc_20161219_1007.txt
thedo 166:240bc5a0f42a 621 <trace removed>
thedo 166:240bc5a0f42a 622 simhug01@E107851:/d/demo_area/ex_app1$
thedo 166:240bc5a0f42a 623
thedo 166:240bc5a0f42a 624 The build trace is quite extensive but on a successful build you should see the following output at the end of the log:
thedo 166:240bc5a0f42a 625
thedo 166:240bc5a0f42a 626 Build successes:
thedo 166:240bc5a0f42a 627 * K64F::GCC_ARM::MBED-BUILD
thedo 166:240bc5a0f42a 628 * K64F::GCC_ARM::MBED-OS-FEATURES-FEATURE_LWIP-TESTS-MBEDMICRO-NET-CONNECTIVITY
thedo 166:240bc5a0f42a 629 <trace removed>
thedo 166:240bc5a0f42a 630 * K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-FAT_FILE_SYSTEM
thedo 166:240bc5a0f42a 631 * K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-HEAP_BLOCK_DEVICE
thedo 166:240bc5a0f42a 632 * K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-UTIL_BLOCK_DEVICE
thedo 166:240bc5a0f42a 633 <trace removed>
thedo 166:240bc5a0f42a 634 * K64F::GCC_ARM::SD-DRIVER-FEATURES-TESTS-FILESYSTEM-BASIC
thedo 166:240bc5a0f42a 635 * K64F::GCC_ARM::SD-DRIVER-FEATURES-TESTS-FILESYSTEM-FOPEN
thedo 166:240bc5a0f42a 636
thedo 166:240bc5a0f42a 637 Build skips:
thedo 166:240bc5a0f42a 638 * K64F::GCC_ARM::MBED-OS-FEATURES-FEATURE_LWIP-TESTS-MBEDMICRO-NET-TCP_PACKET_PRESSURE
thedo 166:240bc5a0f42a 639 <trace removed>
thedo 166:240bc5a0f42a 640
thedo 166:240bc5a0f42a 641
thedo 166:240bc5a0f42a 642 Notice the following tests in the sd-driver tree are listed above:
thedo 166:240bc5a0f42a 643
thedo 166:240bc5a0f42a 644 - `K64F::GCC_ARM::SD-DRIVER-FEATURES-TESTS-FILESYSTEM-BASIC`
thedo 166:240bc5a0f42a 645 - `K64F::GCC_ARM::SD-DRIVER-FEATURES-TESTS-FILESYSTEM-FOPEN`
thedo 166:240bc5a0f42a 646
thedo 166:240bc5a0f42a 647
thedo 166:240bc5a0f42a 648 The FAT32/SDCard test cases are at following locations in the source code tree:
thedo 166:240bc5a0f42a 649
thedo 166:240bc5a0f42a 650 /d/demo_area/ex_app1/sd-driver/features/TESTS/filesystem/basic/basic.cpp
thedo 166:240bc5a0f42a 651 /d/demo_area/ex_app1/sd-driver/features/TESTS/filesystem/fopen/fopen.cpp
thedo 166:240bc5a0f42a 652
thedo 166:240bc5a0f42a 653
thedo 166:240bc5a0f42a 654 #### <a name="settting-repos-to-compatible-versions"></a> Setting mbed-os/sd-driver Repositories To Compatible Versions
thedo 166:240bc5a0f42a 655
thedo 166:240bc5a0f42a 656 The sd-driver master HEAD and the mbed-os master HEAD should be compatible
thedo 166:240bc5a0f42a 657 with one another and therefore no specific tagged versions need to be checked out.
thedo 166:240bc5a0f42a 658 However, in the case that you experience problems building, checkout out the compatible
thedo 166:240bc5a0f42a 659 tagged version of each repository, as shown below:
thedo 166:240bc5a0f42a 660
thedo 166:240bc5a0f42a 661 simhug01@E107851:/d/demo_area/ex_app1$ pushd mbed-os
thedo 166:240bc5a0f42a 662 simhug01@E107851:/d/demo_area/ex_app1$ git checkout tags/mbed-os-5.4.0
thedo 166:240bc5a0f42a 663 simhug01@E107851:/d/demo_area/ex_app1$ popd
thedo 166:240bc5a0f42a 664 simhug01@E107851:/d/demo_area/ex_app1$ pushd sd-driver
thedo 166:240bc5a0f42a 665 simhug01@E107851:/d/demo_area/ex_app1$ git checkout tags/sd-driver-0.0.2-mbed-os-5.4.0
thedo 166:240bc5a0f42a 666 simhug01@E107851:/d/demo_area/ex_app1$ popd
thedo 166:240bc5a0f42a 667
thedo 166:240bc5a0f42a 668 In the above:
thedo 166:240bc5a0f42a 669
thedo 166:240bc5a0f42a 670 - `mbed-os-5.4.0` should be replaced with the latest mbed-os release tag.
thedo 166:240bc5a0f42a 671 - 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`
thedo 166:240bc5a0f42a 672 where `a.b.c` is the latest version code for the `mbed-os-x.y.z` tag.
thedo 166:240bc5a0f42a 673
thedo 166:240bc5a0f42a 674 ### <a name="greentea-insert-sdcard-into-k64f"></a> Insert SDCard into K64F for Greentea Testing
thedo 166:240bc5a0f42a 675
thedo 166:240bc5a0f42a 676 See the previous section for [Insert SDCard into K64F](#insert-sdcard-into-k64f) for details.
thedo 166:240bc5a0f42a 677
thedo 166:240bc5a0f42a 678
thedo 166:240bc5a0f42a 679 ### <a name="run-the-posix-file-test-cases"></a> Run the POSIX File Test Case
thedo 166:240bc5a0f42a 680
thedo 166:240bc5a0f42a 681 To setup for running the test cases, connect the K64F development board to your
thedo 166:240bc5a0f42a 682 PC using a suitable USB cable.
thedo 166:240bc5a0f42a 683
thedo 166:240bc5a0f42a 684 All tests can be run using the following command:
thedo 166:240bc5a0f42a 685
thedo 166:240bc5a0f42a 686 simhug01@E107851:/d/demo_area/ex_app1$ mbedgt -VS
thedo 166:240bc5a0f42a 687 <trace removed>
thedo 166:240bc5a0f42a 688
thedo 166:240bc5a0f42a 689 However, it's possible to run a particular test case using the following form of the mbedgt command:
thedo 166:240bc5a0f42a 690
thedo 166:240bc5a0f42a 691 simhug01@E107851:/d/demo_area/ex_app1$ mbedgt -VS --test-by-names=<test-name>
thedo 166:240bc5a0f42a 692
thedo 166:240bc5a0f42a 693 The names of the tests can be listed using:
thedo 166:240bc5a0f42a 694
thedo 166:240bc5a0f42a 695 simhug01@E107851:/d/demo_area/ex_app1$ mbedgt -VS --list
thedo 166:240bc5a0f42a 696
thedo 166:240bc5a0f42a 697 For example, to run the basic test use:
thedo 166:240bc5a0f42a 698
thedo 166:240bc5a0f42a 699 simhug01@E107851:/d/demo_area/ex_app1$ mbedgt -VS --test-by-names=sd-driver-features-tests-filesystem-basic 2>&1 | tee run_tests_basic.txt
thedo 166:240bc5a0f42a 700
thedo 166:240bc5a0f42a 701 To run the fopen test use:
thedo 166:240bc5a0f42a 702
thedo 166:240bc5a0f42a 703 simhug01@E107851:/d/demo_area/ex_app1$ mbedgt -VS --test-by-names=sd-driver-features-tests-filesystem-fopen 2>&1 | tee run_tests_fopen.txt
thedo 166:240bc5a0f42a 704
thedo 166:240bc5a0f42a 705 On a successful run, results similar to the following will be shown:
thedo 166:240bc5a0f42a 706
thedo 166:240bc5a0f42a 707 mbedgt: test suite report:
thedo 166:240bc5a0f42a 708 +--------------+---------------+-------------------------------------------+--------+--------------------+-------------+
thedo 166:240bc5a0f42a 709 | target | platform_name | test suite | result | elapsed_time (sec) | copy_method |
thedo 166:240bc5a0f42a 710 +--------------+---------------+-------------------------------------------+--------+--------------------+-------------+
thedo 166:240bc5a0f42a 711 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | OK | 151.46 | shell |
thedo 166:240bc5a0f42a 712 +--------------+---------------+-------------------------------------------+--------+--------------------+-------------+
thedo 166:240bc5a0f42a 713 mbedgt: test suite results: 1 OK
thedo 166:240bc5a0f42a 714 mbedgt: test case report:
thedo 166:240bc5a0f42a 715 +--------------+---------------+-------------------------------------------+----------------------------------------------------------------------------------------+--------+--------+--------+--------------------+
thedo 166:240bc5a0f42a 716 | target | platform_name | test suite | test case | passed | failed | result | elapsed_time (sec) |
thedo 166:240bc5a0f42a 717 +--------------+---------------+-------------------------------------------+----------------------------------------------------------------------------------------+--------+--------+--------+--------------------+
thedo 166:240bc5a0f42a 718 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_01: fopen()/fwrite()/fclose() directories/file in multi-dir filepath. | 1 | 0 | OK | 7.57 |
thedo 166:240bc5a0f42a 719 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_02: fopen(r) pre-existing file try to write it. | 1 | 0 | OK | 0.2 |
thedo 166:240bc5a0f42a 720 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_03: fopen(w+) pre-existing file try to write it. | 1 | 0 | OK | 0.41 |
thedo 166:240bc5a0f42a 721 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_04: fopen() with a filename exceeding the maximum length. | 1 | 0 | OK | 0.11 |
thedo 166:240bc5a0f42a 722 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_06: fopen() with bad filenames (minimal). | 1 | 0 | OK | 0.1 |
thedo 166:240bc5a0f42a 723 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_07: fopen()/errno handling. | 1 | 0 | OK | 0.07 |
thedo 166:240bc5a0f42a 724 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_08: ferror()/clearerr()/errno handling. | 1 | 0 | OK | 0.1 |
thedo 166:240bc5a0f42a 725 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_09: ftell() handling. | 1 | 0 | OK | 0.17 |
thedo 166:240bc5a0f42a 726 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_10: remove() test. | 1 | 0 | OK | 1.28 |
thedo 166:240bc5a0f42a 727 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_11: rename(). | 1 | 0 | OK | 2.3 |
thedo 166:240bc5a0f42a 728 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_12: opendir(), readdir(), closedir() test. | 1 | 0 | OK | 3.57 |
thedo 166:240bc5a0f42a 729 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_13: mkdir() test. | 1 | 0 | OK | 1.21 |
thedo 166:240bc5a0f42a 730 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_14: stat() test. | 1 | 0 | OK | 1.47 |
thedo 166:240bc5a0f42a 731 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_15: format() test. | 1 | 0 | OK | 26.12 |
thedo 166:240bc5a0f42a 732 | K64F-GCC_ARM | K64F | sd-driver-features-tests-filesystem-fopen | FSFAT_FOPEN_TEST_16: write/check n x 25kB data files. | 1 | 0 | OK | 87.11 |
thedo 166:240bc5a0f42a 733 +--------------+---------------+-------------------------------------------+----------------------------------------------------------------------------------------+--------+--------+--------+--------------------+
thedo 166:240bc5a0f42a 734 mbedgt: test case results: 15 OK
thedo 166:240bc5a0f42a 735 mbedgt: completed in 152.35 sec
thedo 166:240bc5a0f42a 736
thedo 166:240bc5a0f42a 737
thedo 166:240bc5a0f42a 738 # <a name="summary-posix-api-documentation"></a> Summary of POSIX File API Documentation
thedo 166:240bc5a0f42a 739
thedo 166:240bc5a0f42a 740 ### POSIX File API
thedo 166:240bc5a0f42a 741
thedo 166:240bc5a0f42a 742 mbed OS supports a subset of the POSIX File API, as outlined below:
thedo 166:240bc5a0f42a 743
thedo 166:240bc5a0f42a 744 - [clearerr()](https://linux.die.net/man/3/clearerr).
thedo 166:240bc5a0f42a 745 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 746 - [fclose()](https://linux.die.net/man/3/fclose).
thedo 166:240bc5a0f42a 747 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 748 - [ferror()](https://linux.die.net/man/3/clearerr).
thedo 166:240bc5a0f42a 749 - STATUS: Basic testing implemented.
thedo 166:240bc5a0f42a 750 - STATUS: GCC_ARM: Working.
thedo 166:240bc5a0f42a 751 - STATUS: ARMCC: ARMCC has problem with ferror(filep) where filep is NULL. Appears to work for non-NULL pointer.
thedo 166:240bc5a0f42a 752 - [fgetc()](https://linux.die.net/man/3/fgets).
thedo 166:240bc5a0f42a 753 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 754 - [fgets()](https://linux.die.net/man/3/fgets).
thedo 166:240bc5a0f42a 755 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 756 - [fputc()](https://linux.die.net/man/3/fputs).
thedo 166:240bc5a0f42a 757 - STATUS: Unknown.
thedo 166:240bc5a0f42a 758 - [fputs()](https://linux.die.net/man/3/fputs).
thedo 166:240bc5a0f42a 759 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 760 - [fprintf()](https://linux.die.net/man/3/fprintf).
thedo 166:240bc5a0f42a 761 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 762 - [fopen()](https://linux.die.net/man/3/fopen).
thedo 166:240bc5a0f42a 763 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 764 - [freopen()](https://linux.die.net/man/3/fopen).
thedo 166:240bc5a0f42a 765 - STATUS: This is not tested.
thedo 166:240bc5a0f42a 766 - [fread()](https://linux.die.net/man/3/fread).
thedo 166:240bc5a0f42a 767 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 768 - STATUS: n x 25kB stress test working.
thedo 166:240bc5a0f42a 769 - [ftell()](https://linux.die.net/man/3/ftell).
thedo 166:240bc5a0f42a 770 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 771 - [fwrite()](https://linux.die.net/man/3/fwrite).
thedo 166:240bc5a0f42a 772 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 773 - STATUS: n x 25kB stress test working.
thedo 166:240bc5a0f42a 774 - [fseek()](https://linux.die.net/man/3/fseek)
thedo 166:240bc5a0f42a 775 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 776 - [getc()](https://linux.die.net/man/3/fgets).
thedo 166:240bc5a0f42a 777 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 778 - [gets()](https://linux.die.net/man/3/fgets).
thedo 166:240bc5a0f42a 779 - STATUS: Unknown.
thedo 166:240bc5a0f42a 780 - [putc()](https://linux.die.net/man/3/fputs).
thedo 166:240bc5a0f42a 781 - STATUS: Unknown.
thedo 166:240bc5a0f42a 782 - [puts()](https://linux.die.net/man/3/fputs).
thedo 166:240bc5a0f42a 783 - STATUS: Unknown.
thedo 166:240bc5a0f42a 784 - [remove()](https://linux.die.net/man/3/remove)
thedo 166:240bc5a0f42a 785 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 786 - [rewind()](https://linux.die.net/man/3/rewind).
thedo 166:240bc5a0f42a 787 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 788 - [stat()](https://linux.die.net/man/2/stat)
thedo 166:240bc5a0f42a 789 - STATUS: Implemented. Working.
thedo 166:240bc5a0f42a 790 - STATUS: Not supported by ARMCC/IAR libc.
thedo 166:240bc5a0f42a 791 - [tmpfile()](https://linux.die.net/man/3/tmpfile).
thedo 166:240bc5a0f42a 792 - STATUS: Not implemented.
thedo 166:240bc5a0f42a 793 - [tmpnam()](https://linux.die.net/man/3/tmpnam).
thedo 166:240bc5a0f42a 794 - STATUS: Not implemented.
thedo 166:240bc5a0f42a 795
thedo 166:240bc5a0f42a 796 Supported directory related operations are as follows:
thedo 166:240bc5a0f42a 797
thedo 166:240bc5a0f42a 798 - [closedir()](https://linux.die.net/man/3/closedir).
thedo 166:240bc5a0f42a 799 - STATUS: Implemented. Working.
thedo 166:240bc5a0f42a 800 - [mkdir()](https://linux.die.net/man/3/mkdir).
thedo 166:240bc5a0f42a 801 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 802 - [opendir()](https://linux.die.net/man/3/opendir).
thedo 166:240bc5a0f42a 803 - STATUS: Implemented. Working.
thedo 166:240bc5a0f42a 804 - [readdir()](https://linux.die.net/man/3/readdir).
thedo 166:240bc5a0f42a 805 - STATUS: Implemented. Working.
thedo 166:240bc5a0f42a 806 - [remove()](https://linux.die.net/man/3/remove).
thedo 166:240bc5a0f42a 807 - STATUS: Basic testing implemented. Working.
thedo 166:240bc5a0f42a 808 - [rename()](https://linux.die.net/man/3/rename).
thedo 166:240bc5a0f42a 809 - STATUS: Implemented. Not tested.
thedo 166:240bc5a0f42a 810 - [rewinddir()](https://linux.die.net/man/3/rewinddir).
thedo 166:240bc5a0f42a 811 - STATUS: Implemented. Found not to work. Test case not present in repo.
thedo 166:240bc5a0f42a 812 - [seekdir()](https://linux.die.net/man/3/seekdir).
thedo 166:240bc5a0f42a 813 - STATUS: Implemented. Found not to work. Test case not present in repo.
thedo 166:240bc5a0f42a 814 - [telldir()](https://linux.die.net/man/3/telldir).
thedo 166:240bc5a0f42a 815 - STATUS: Implemented. Found not to work. Test case not present in repo.
thedo 166:240bc5a0f42a 816
thedo 166:240bc5a0f42a 817 ### errno
thedo 166:240bc5a0f42a 818
thedo 166:240bc5a0f42a 819 Basic errno reporting is supported, tested and known to be working.
thedo 166:240bc5a0f42a 820
thedo 166:240bc5a0f42a 821
thedo 166:240bc5a0f42a 822 # Related Projects Resources
thedo 166:240bc5a0f42a 823
thedo 166:240bc5a0f42a 824 The following are related mbed storage projects and useful resources:
thedo 166:240bc5a0f42a 825
thedo 166:240bc5a0f42a 826 - The [mbed-os repository](https://github.com/ARMmbed/mbed-os). This is the main mbed OS repository.
thedo 166:240bc5a0f42a 827 - The [mbed-os-example-fat-filesystem repository](https://github.com/ARMmbed/mbed-os-example-fat-filesystem).
thedo 166:240bc5a0f42a 828 This is an example project for the mbed OS FAT filesystem.
thedo 166:240bc5a0f42a 829 - The [spiflash-driver repository](https://github.com/armmbed/spiflash-driver)
thedo 166:240bc5a0f42a 830 - The [i2ceeprom-driver repository](https://github.com/ARMmbed/i2ceeprom-driver.git)
thedo 166:240bc5a0f42a 831 - The [ci-test-shield repository](https://github.com/ARMmbed/ci-test-shield). This is the project describing
thedo 166:240bc5a0f42a 832 the mbed-os Continuous Integration test shield, together with standard tests.
thedo 166:240bc5a0f42a 833 - [POSIX File Interface ISO/IEC 9899:TC2 Documentation](http://www.eng.utah.edu/~cs5785/slides-f10/n1124.pdf).
thedo 166:240bc5a0f42a 834 - [FATFS: Generic FAT File System Module used in mbed OS](http://elm-chan.org/fsw/ff/00index_e.html)
thedo 166:240bc5a0f42a 835
thedo 166:240bc5a0f42a 836
thedo 166:240bc5a0f42a 837 # Appendix 1: Getting Started with SPIFlash-Driver Example
thedo 166:240bc5a0f42a 838
thedo 166:240bc5a0f42a 839 ## Overview
thedo 166:240bc5a0f42a 840
thedo 166:240bc5a0f42a 841 This example describes how to build and run the spiflash-driver SPIFBlockDevice examples to
thedo 166:240bc5a0f42a 842 read and write data to a SPI NOR flash part connected to a K64F.
thedo 166:240bc5a0f42a 843
thedo 166:240bc5a0f42a 844 Hardware required:
thedo 166:240bc5a0f42a 845
thedo 166:240bc5a0f42a 846 - K64F.
thedo 166:240bc5a0f42a 847 - CI test shield.
thedo 166:240bc5a0f42a 848 - SPI NOR Flash Device wired to Arduino header pins e.g. the Macronix MX25R2035F. The datasheet is available
thedo 166:240bc5a0f42a 849 from the [Macronix website](http://www.macronix.com/).
thedo 166:240bc5a0f42a 850 - Micro USB cable.
thedo 166:240bc5a0f42a 851
thedo 166:240bc5a0f42a 852 Software required:
thedo 166:240bc5a0f42a 853
thedo 166:240bc5a0f42a 854 - mbed CLI (with all other dependencies installed).
thedo 166:240bc5a0f42a 855 - ARMCC / GCC_ARM / IAR compiler.
thedo 166:240bc5a0f42a 856 - mbed greentea.
thedo 166:240bc5a0f42a 857 - git account.
thedo 166:240bc5a0f42a 858
thedo 166:240bc5a0f42a 859 Github repos to use:
thedo 166:240bc5a0f42a 860
thedo 166:240bc5a0f42a 861 - The [mbed OS repository](https://github.com/armmbed/mbed-os)
thedo 166:240bc5a0f42a 862 - The [SPI Flash Driver repository](https://github.com/armmbed/spiflash-driver)
thedo 166:240bc5a0f42a 863
thedo 166:240bc5a0f42a 864 ## Simple SPIFBlockDevice Example
thedo 166:240bc5a0f42a 865
thedo 166:240bc5a0f42a 866 This section describes how to create an application project combining the
thedo 166:240bc5a0f42a 867 mbed-os and spiflash-driver repositories into a single project.
thedo 166:240bc5a0f42a 868 In summary the following steps will be covered in this section:
thedo 166:240bc5a0f42a 869
thedo 166:240bc5a0f42a 870 - A top level application project directory is created. The directory name is ex_app2.
thedo 166:240bc5a0f42a 871 - In the ex_app2 directory, the mbed-os repository is cloned.
thedo 166:240bc5a0f42a 872 - In the ex_app2 directory at the same level as the mbed-os directory, the spiflash-driver repository is cloned.
thedo 166:240bc5a0f42a 873
thedo 166:240bc5a0f42a 874 First create the top level application directory ex_app2 and move into it:
thedo 166:240bc5a0f42a 875
thedo 166:240bc5a0f42a 876 simhug01@E107851:/d/demo_area$ mkdir ex_app2
thedo 166:240bc5a0f42a 877 simhug01@E107851:/d/demo_area$ pushd ex_app2
thedo 166:240bc5a0f42a 878
thedo 166:240bc5a0f42a 879 Next, get a clone of public mbed OS repository in the following way:
thedo 166:240bc5a0f42a 880
thedo 166:240bc5a0f42a 881 simhug01@E107851:/d/demo_area/ex_app2$ git clone git@github.com:/armmbed/mbed-os
thedo 166:240bc5a0f42a 882 <trace removed>
thedo 166:240bc5a0f42a 883 simhug01@E107851:/d/demo_area/ex_app2$
thedo 166:240bc5a0f42a 884
thedo 166:240bc5a0f42a 885 Next, get a clone of the spiflash-driver repository:
thedo 166:240bc5a0f42a 886
thedo 166:240bc5a0f42a 887 simhug01@E107851:/d/demo_area/ex_app2$ git clone git@github.com:/armmbed/spiflash-driver
thedo 166:240bc5a0f42a 888 <trace removed>
thedo 166:240bc5a0f42a 889 simhug01@E107851:/d/demo_area/ex_app2$
thedo 166:240bc5a0f42a 890
thedo 166:240bc5a0f42a 891 In the top level directory create the example2.cpp:
thedo 166:240bc5a0f42a 892
thedo 166:240bc5a0f42a 893 simhug01@E107851:/d/demo_area/ex_app2$ touch example2.cpp
thedo 166:240bc5a0f42a 894
thedo 166:240bc5a0f42a 895 Copy the [spiflash-driver example code](https://github.com/armmbed/spiflash-driver)
thedo 166:240bc5a0f42a 896 and paste into example2.cpp (reproduced here for convenience and corrected to build for
thedo 166:240bc5a0f42a 897 GCC_ARM):
thedo 166:240bc5a0f42a 898
thedo 166:240bc5a0f42a 899 // Here's an example using the MX25R SPI flash device on the K82F
thedo 166:240bc5a0f42a 900 #include "mbed.h"
thedo 166:240bc5a0f42a 901 #include "SPIFBlockDevice.h"
thedo 166:240bc5a0f42a 902
thedo 166:240bc5a0f42a 903 /* This is the original configuration of the SPI Flash Driver
thedo 166:240bc5a0f42a 904 * pins for Freescale K82F development board. We're not using
thedo 166:240bc5a0f42a 905 * this as we're using the CI Test Shield
thedo 166:240bc5a0f42a 906 */
thedo 166:240bc5a0f42a 907 // Create flash device on SPI bus with PTE5 as chip select
thedo 166:240bc5a0f42a 908 //SPIFBlockDevice spif(PTE2, PTE4, PTE1, PTE5);
thedo 166:240bc5a0f42a 909
thedo 166:240bc5a0f42a 910 /* This configuration of the SPI Flash Driver pins is for
thedo 166:240bc5a0f42a 911 * the Freescale K64F connecting the SPI pins on the
thedo 166:240bc5a0f42a 912 * Arduino header to the SPI NOR part.
thedo 166:240bc5a0f42a 913 */
thedo 166:240bc5a0f42a 914 SPIFBlockDevice spif(D11, D12, D13, D10);
thedo 166:240bc5a0f42a 915
thedo 166:240bc5a0f42a 916
thedo 166:240bc5a0f42a 917 int main() {
thedo 166:240bc5a0f42a 918 printf("spif test\n");
thedo 166:240bc5a0f42a 919
thedo 166:240bc5a0f42a 920 // Initialize the SPI flash device and print the memory layout
thedo 166:240bc5a0f42a 921 spif.init();
thedo 166:240bc5a0f42a 922 printf("spif size: %llu\n", spif.size());
thedo 166:240bc5a0f42a 923 printf("spif read size: %llu\n", spif.get_read_size());
thedo 166:240bc5a0f42a 924 printf("spif program size: %llu\n", spif.get_program_size());
thedo 166:240bc5a0f42a 925 printf("spif erase size: %llu\n", spif.get_erase_size());
thedo 166:240bc5a0f42a 926
thedo 166:240bc5a0f42a 927 // Write "Hello World!" to the first block
thedo 166:240bc5a0f42a 928 char *buffer = (char*) malloc(spif.get_erase_size());
thedo 166:240bc5a0f42a 929 sprintf(buffer, "Hello World!\n");
thedo 166:240bc5a0f42a 930 spif.erase(0, spif.get_erase_size());
thedo 166:240bc5a0f42a 931 spif.program(buffer, 0, spif.get_erase_size());
thedo 166:240bc5a0f42a 932
thedo 166:240bc5a0f42a 933 // Read back what was stored
thedo 166:240bc5a0f42a 934 spif.read(buffer, 0, spif.get_erase_size());
thedo 166:240bc5a0f42a 935 printf("%s", buffer);
thedo 166:240bc5a0f42a 936
thedo 166:240bc5a0f42a 937 // Deinitialize the device
thedo 166:240bc5a0f42a 938 spif.deinit();
thedo 166:240bc5a0f42a 939 }
thedo 166:240bc5a0f42a 940
thedo 166:240bc5a0f42a 941 Note the following modifications to the original code sample:
thedo 166:240bc5a0f42a 942
thedo 166:240bc5a0f42a 943 - The SPI Flash Driver instance `spif` is given the pin configuration
thedo 166:240bc5a0f42a 944 for the SPI bus from the Arduino header pins D11, D12, D13 and D10,
thedo 166:240bc5a0f42a 945 as noted in the comments.
thedo 166:240bc5a0f42a 946 - The buffer type has been modified to char* to (see line with malloc() above).
thedo 166:240bc5a0f42a 947
thedo 166:240bc5a0f42a 948 The application can be built with the following command:
thedo 166:240bc5a0f42a 949
thedo 166:240bc5a0f42a 950 simhug01@E107851:/d/demo_area/ex_app2$ mbed compile -m K64F -t GCC_ARM 2>&1 | tee build_app_ex_app2_log.txt
thedo 166:240bc5a0f42a 951
thedo 166:240bc5a0f42a 952 Once the binary is built, copy the binary from `/d/demo_area/ex_app2/BUILD/K64F/GCC_ARM/example2.bin` to the K64F.
thedo 166:240bc5a0f42a 953 After connecting a serial console and resetting the target, the following trace should be seen:
thedo 166:240bc5a0f42a 954
thedo 166:240bc5a0f42a 955 spif test
thedo 166:240bc5a0f42a 956 spif size: 2097152
thedo 166:240bc5a0f42a 957 spif read size: 1
thedo 166:240bc5a0f42a 958 spif program size: 1
thedo 166:240bc5a0f42a 959 spif erase size: 4096
thedo 166:240bc5a0f42a 960 Hello World!
thedo 166:240bc5a0f42a 961
thedo 166:240bc5a0f42a 962
thedo 166:240bc5a0f42a 963 ## Build the mbed OS Test Cases
thedo 166:240bc5a0f42a 964
thedo 166:240bc5a0f42a 965 If you have completed the previous section "Simple SPIFBlockDevice Example" then first prepare the environment by removing the BUILD
thedo 166:240bc5a0f42a 966 directory and hiding or removing the example2.cpp:
thedo 166:240bc5a0f42a 967
thedo 166:240bc5a0f42a 968 simhug01@E107851:/d/demo_area/ex_app2$ rm -fR BUILD
thedo 166:240bc5a0f42a 969 simhug01@E107851:/d/demo_area/ex_app2$ cp example2.cpp example2_cpp
thedo 166:240bc5a0f42a 970
thedo 166:240bc5a0f42a 971 Build the test cases for the K64F target using the following command:
thedo 166:240bc5a0f42a 972
thedo 166:240bc5a0f42a 973 simhug01@E107851:/d/demo_area/ex_app2$ mbed -v test --compile -t GCC_ARM -m K64F 2>&1 | tee build_tests_gcc_20170322_1007.txt
thedo 166:240bc5a0f42a 974 <trace removed>
thedo 166:240bc5a0f42a 975 simhug01@E107851:/d/demo_area/ex_app2$
thedo 166:240bc5a0f42a 976
thedo 166:240bc5a0f42a 977 The build trace is quite extensive but on a successful build you should see the following output at the end of the log:
thedo 166:240bc5a0f42a 978
thedo 166:240bc5a0f42a 979 Build successes:
thedo 166:240bc5a0f42a 980 * K64F::GCC_ARM::MBED-BUILD
thedo 166:240bc5a0f42a 981 * K64F::GCC_ARM::MBED-OS-FEATURES-FEATURE_LWIP-TESTS-MBEDMICRO-NET-CONNECTIVITY
thedo 166:240bc5a0f42a 982 <trace removed>
thedo 166:240bc5a0f42a 983 * K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-FAT_FILE_SYSTEM
thedo 166:240bc5a0f42a 984 * K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-HEAP_BLOCK_DEVICE
thedo 166:240bc5a0f42a 985 * K64F::GCC_ARM::MBED-OS-FEATURES-TESTS-FILESYSTEM-UTIL_BLOCK_DEVICE
thedo 166:240bc5a0f42a 986 <trace removed>
thedo 166:240bc5a0f42a 987 * K64F::GCC_ARM::MBED-OS-TESTS-STORAGE_ABSTRACTION-BASICAPI
thedo 166:240bc5a0f42a 988 * K64F::GCC_ARM::SPIFLASH-DRIVER-TESTS-BLOCK_DEVICE-SPIF
thedo 166:240bc5a0f42a 989
thedo 166:240bc5a0f42a 990
thedo 166:240bc5a0f42a 991 Build skips:
thedo 166:240bc5a0f42a 992 * K64F::GCC_ARM::MBED-OS-FEATURES-FEATURE_LWIP-TESTS-MBEDMICRO-NET-TCP_PACKET_PRESSURE
thedo 166:240bc5a0f42a 993 <trace removed>
thedo 166:240bc5a0f42a 994
thedo 166:240bc5a0f42a 995 Notice the following test in the spiflash-driver tree listed above:
thedo 166:240bc5a0f42a 996
thedo 166:240bc5a0f42a 997 - `K64F::GCC_ARM::SPIFLASH-DRIVER-TESTS-BLOCK_DEVICE-SPIF`
thedo 166:240bc5a0f42a 998
thedo 166:240bc5a0f42a 999
thedo 166:240bc5a0f42a 1000 The SPIFBlockDevice test case is at following locations in the source code tree:
thedo 166:240bc5a0f42a 1001
thedo 166:240bc5a0f42a 1002 /d/demo_area/ex_app2/spiflash-driver/TESTS/block_device/spif/main.cpp
thedo 166:240bc5a0f42a 1003
thedo 166:240bc5a0f42a 1004 This provides an example of reading and writing data blocks to the block device interface for the SPI NOR part.
thedo 166:240bc5a0f42a 1005
thedo 166:240bc5a0f42a 1006 Run the test using the following command:
thedo 166:240bc5a0f42a 1007
thedo 166:240bc5a0f42a 1008 simhug01@E107851:/d/demo_area/ex_app2$ mbedgt -VS --test-by-names=spiflash-driver-tests-block_device-spif 2>&1 | tee run_test_gcc_20170322_1007.txt
thedo 166:240bc5a0f42a 1009
thedo 166:240bc5a0f42a 1010 The test output should look similar to the following trace:
thedo 166:240bc5a0f42a 1011
thedo 166:240bc5a0f42a 1012 (mx_env1) simhug01@E107851:/d/datastore/public/jobs/yr2017/2278/sdh_dev_mx1/ex_app5$ mbedgt -VS --test-by-names=spiflash-driver-tests-block_device-sp
thedo 166:240bc5a0f42a 1013 if 2>&1 | tee 2278_run_test_ex_app5_br_master_time_20170322_1207_spif.txt
thedo 166:240bc5a0f42a 1014 mbedgt: greentea test automation tool ver. 1.2.5
thedo 166:240bc5a0f42a 1015 mbedgt: using multiple test specifications from current directory!
thedo 166:240bc5a0f42a 1016 using 'BUILD\tests\K64F\GCC_ARM\test_spec.json'
thedo 166:240bc5a0f42a 1017 mbedgt: detecting connected mbed-enabled devices...
thedo 166:240bc5a0f42a 1018 mbedgt: detected 1 device
thedo 166:240bc5a0f42a 1019 +---------------+----------------------+-------------+-------------+--------------------------------------------------+
thedo 166:240bc5a0f42a 1020 | platform_name | platform_name_unique | serial_port | mount_point | target_id |
thedo 166:240bc5a0f42a 1021 +---------------+----------------------+-------------+-------------+--------------------------------------------------+
thedo 166:240bc5a0f42a 1022 | K64F | K64F[0] | COM46 | E: | 0240000029304e450023500878a3001df131000097969900 |
thedo 166:240bc5a0f42a 1023 +---------------+----------------------+-------------+-------------+--------------------------------------------------+
thedo 166:240bc5a0f42a 1024 mbedgt: processing target 'K64F' toolchain 'GCC_ARM' compatible platforms... (note: switch set to --parallel 1)
thedo 166:240bc5a0f42a 1025 +---------------+----------------------+-------------+-------------+--------------------------------------------------+
thedo 166:240bc5a0f42a 1026 | platform_name | platform_name_unique | serial_port | mount_point | target_id |
thedo 166:240bc5a0f42a 1027 +---------------+----------------------+-------------+-------------+--------------------------------------------------+
thedo 166:240bc5a0f42a 1028 | K64F | K64F[0] | COM46:9600 | E: | 0240000029304e450023500878a3001df131000097969900 |
thedo 166:240bc5a0f42a 1029 +---------------+----------------------+-------------+-------------+--------------------------------------------------+
thedo 166:240bc5a0f42a 1030 mbedgt: test case filter (specified with -n option)
thedo 166:240bc5a0f42a 1031 test filtered in 'spiflash-driver-tests-block_device-spif'
thedo 166:240bc5a0f42a 1032 mbedgt: running 1 test for platform 'K64F' and toolchain 'GCC_ARM'
thedo 166:240bc5a0f42a 1033 use 1 instance of execution threads for testing
thedo 166:240bc5a0f42a 1034 mbedgt: checking for 'host_tests' directory above image directory structure
thedo 166:240bc5a0f42a 1035 'host_tests' directory not found: two directory levels above image path checked
thedo 166:240bc5a0f42a 1036 mbedgt: selecting test case observer...
thedo 166:240bc5a0f42a 1037 calling mbedhtrun: mbedhtrun -m K64F -p COM46:9600 -f "BUILD/tests/K64F/GCC_ARM/spiflash-driver/TESTS/block_device/spif/spif.bin" -d E: -C 4 -
thedo 166:240bc5a0f42a 1038 c shell -t 0240000029304e450023500878a3001df131000097969900
thedo 166:240bc5a0f42a 1039 mbedgt: mbed-host-test-runner: started
thedo 166:240bc5a0f42a 1040 [1490184626.50][HTST][INF] host test executor ver. 1.1.6
thedo 166:240bc5a0f42a 1041 [1490184626.50][HTST][INF] copy image onto target...
thedo 166:240bc5a0f42a 1042 [1490184626.50][COPY][INF] Waiting up to 60 sec for '0240000029304e450023500878a3001df131000097969900' mount point (current is 'E:')...
thedo 166:240bc5a0f42a 1043 1 file(s) copied.
thedo 166:240bc5a0f42a 1044 [1490184635.79][HTST][INF] starting host test process...
thedo 166:240bc5a0f42a 1045 [1490184636.10][CONN][INF] starting connection process...
thedo 166:240bc5a0f42a 1046 [1490184636.10][CONN][INF] notify event queue about extra 60 sec timeout for serial port pooling
thedo 166:240bc5a0f42a 1047 [1490184636.10][CONN][INF] initializing serial port listener...
thedo 166:240bc5a0f42a 1048 [1490184636.10][PLGN][INF] Waiting up to 60 sec for '0240000029304e450023500878a3001df131000097969900' serial port (current is 'COM46')...
thedo 166:240bc5a0f42a 1049 [1490184636.12][HTST][INF] setting timeout to: 60 sec
thedo 166:240bc5a0f42a 1050 [1490184636.24][SERI][INF] serial(port=COM46, baudrate=9600, timeout=0.01)
thedo 166:240bc5a0f42a 1051 <lines deleted to save space>
thedo 166:240bc5a0f42a 1052 [1490184649.90][CONN][INF] found KV pair in stream: {{__testcase_name;Testing read write random blocks}}, queued...
thedo 166:240bc5a0f42a 1053 [1490184649.97][CONN][RXD] >>> Running case #1: 'Testing read write random blocks'...
thedo 166:240bc5a0f42a 1054 [1490184650.02][CONN][INF] found KV pair in stream: {{__testcase_start;Testing read write random blocks}}, queued...
thedo 166:240bc5a0f42a 1055 [1490184650.05][CONN][RXD] read size: 1bytes (1bytes)
thedo 166:240bc5a0f42a 1056 [1490184650.08][CONN][RXD] program size: 1bytes (1bytes)
thedo 166:240bc5a0f42a 1057 [1490184650.12][CONN][RXD] erase size: 4kbytes (4096bytes)
thedo 166:240bc5a0f42a 1058 [1490184650.13][CONN][RXD] total size: 2Mbytes (2097152bytes)
thedo 166:240bc5a0f42a 1059 [1490184650.17][CONN][RXD] test 002d000:4096...
thedo 166:240bc5a0f42a 1060 [1490184650.36][CONN][RXD] write 002d000:4096 aad8573abd84e79e5e3684fa5519aabb...
thedo 166:240bc5a0f42a 1061 [1490184650.50][CONN][RXD] read 002d000:4096 aad8573abd84e79e5e3684fa5519aabb...
thedo 166:240bc5a0f42a 1062 [1490184650.56][CONN][RXD] error 002d000:4096 00000000000000000000000000000000
thedo 166:240bc5a0f42a 1063 [1490184650.58][CONN][RXD] test 0036000:4096...
thedo 166:240bc5a0f42a 1064 [1490184650.77][CONN][RXD] write 0036000:4096 92fc08f5b4113047225a8d3b855e5460...
thedo 166:240bc5a0f42a 1065 [1490184650.91][CONN][RXD] read 0036000:4096 92fc08f5b4113047225a8d3b855e5460...
thedo 166:240bc5a0f42a 1066 [1490184650.97][CONN][RXD] error 0036000:4096 00000000000000000000000000000000
thedo 166:240bc5a0f42a 1067 [1490184650.99][CONN][RXD] test 00c6000:4096...
thedo 166:240bc5a0f42a 1068 [1490184651.16][CONN][RXD] write 00c6000:4096 89a030a34b17ca3545c7b007001ef74f...
thedo 166:240bc5a0f42a 1069 [1490184651.32][CONN][RXD] read 00c6000:4096 89a030a34b17ca3545c7b007001ef74f...
thedo 166:240bc5a0f42a 1070 [1490184651.38][CONN][RXD] error 00c6000:4096 00000000000000000000000000000000
thedo 166:240bc5a0f42a 1071 [1490184651.40][CONN][RXD] test 00da000:4096...
thedo 166:240bc5a0f42a 1072 [1490184651.60][CONN][RXD] write 00da000:4096 446fd0232a3d053af820b69c614b3662...
thedo 166:240bc5a0f42a 1073 [1490184651.73][CONN][RXD] read 00da000:4096 446fd0232a3d053af820b69c614b3662...
thedo 166:240bc5a0f42a 1074 [1490184651.79][CONN][RXD] error 00da000:4096 00000000000000000000000000000000
thedo 166:240bc5a0f42a 1075 [1490184651.81][CONN][RXD] test 0188000:4096...
thedo 166:240bc5a0f42a 1076 [1490184652.00][CONN][RXD] write 0188000:4096 9a36d3c6d4034958cade542a9f1e22c2...
thedo 166:240bc5a0f42a 1077 [1490184652.14][CONN][RXD] read 0188000:4096 9a36d3c6d4034958cade542a9f1e22c2...
thedo 166:240bc5a0f42a 1078 [1490184652.20][CONN][RXD] error 0188000:4096 00000000000000000000000000000000
thedo 166:240bc5a0f42a 1079 [1490184652.21][CONN][RXD] test 015f000:4096...
thedo 166:240bc5a0f42a 1080 [1490184652.42][CONN][RXD] write 015f000:4096 70f83b9cc6713736c60089a0fa55f12d...
thedo 166:240bc5a0f42a 1081 [1490184652.55][CONN][RXD] read 015f000:4096 70f83b9cc6713736c60089a0fa55f12d...
thedo 166:240bc5a0f42a 1082 [1490184652.61][CONN][RXD] error 015f000:4096 00000000000000000000000000000000
thedo 166:240bc5a0f42a 1083 [1490184652.63][CONN][RXD] test 005c000:4096...
thedo 166:240bc5a0f42a 1084 [1490184652.82][CONN][RXD] write 005c000:4096 47a0f043fda26135877bb11c7b7016dc...
thedo 166:240bc5a0f42a 1085 [1490184652.96][CONN][RXD] read 005c000:4096 47a0f043fda26135877bb11c7b7016dc...
thedo 166:240bc5a0f42a 1086 [1490184653.02][CONN][RXD] error 005c000:4096 00000000000000000000000000000000
thedo 166:240bc5a0f42a 1087 [1490184653.04][CONN][RXD] test 0177000:4096...
thedo 166:240bc5a0f42a 1088 [1490184653.24][CONN][RXD] write 0177000:4096 174f13941b6385d4a829f2d066a1e375...
thedo 166:240bc5a0f42a 1089 [1490184653.37][CONN][RXD] read 0177000:4096 174f13941b6385d4a829f2d066a1e375...
thedo 166:240bc5a0f42a 1090 [1490184653.42][CONN][RXD] error 0177000:4096 00000000000000000000000000000000
thedo 166:240bc5a0f42a 1091 [1490184653.45][CONN][RXD] test 0173000:4096...
thedo 166:240bc5a0f42a 1092 [1490184653.65][CONN][RXD] write 0173000:4096 383f0ca8cc86e3225362805329e0d659...
thedo 166:240bc5a0f42a 1093 [1490184653.78][CONN][RXD] read 0173000:4096 383f0ca8cc86e3225362805329e0d659...
thedo 166:240bc5a0f42a 1094 [1490184653.84][CONN][RXD] error 0173000:4096 00000000000000000000000000000000
thedo 166:240bc5a0f42a 1095 [1490184653.86][CONN][RXD] test 01d9000:4096...
thedo 166:240bc5a0f42a 1096 [1490184654.05][CONN][RXD] write 01d9000:4096 73f32decf08112f271131f9837b76f28...
thedo 166:240bc5a0f42a 1097 [1490184654.19][CONN][RXD] read 01d9000:4096 73f32decf08112f271131f9837b76f28...
thedo 166:240bc5a0f42a 1098 [1490184654.24][CONN][RXD] error 01d9000:4096 00000000000000000000000000000000
thedo 166:240bc5a0f42a 1099 [1490184654.31][CONN][INF] found KV pair in stream: {{__testcase_finish;Testing read write random blocks;1;0}}, queued...
thedo 166:240bc5a0f42a 1100 [1490184654.38][CONN][RXD] >>> 'Testing read write random blocks': 1 passed, 0 failed
thedo 166:240bc5a0f42a 1101 [1490184654.38][CONN][RXD]
thedo 166:240bc5a0f42a 1102 [1490184654.41][CONN][RXD] >>> Test cases: 1 passed, 0 failed
thedo 166:240bc5a0f42a 1103 [1490184654.44][CONN][INF] found KV pair in stream: {{__testcase_summary;1;0}}, queued...
thedo 166:240bc5a0f42a 1104 [1490184654.47][CONN][INF] found KV pair in stream: {{max_heap_usage;0}}, queued...
thedo 166:240bc5a0f42a 1105 [1490184654.48][CONN][INF] found KV pair in stream: {{end;success}}, queued...
thedo 166:240bc5a0f42a 1106 [1490184654.48][HTST][ERR] orphan event in main phase: {{max_heap_usage;0}}, timestamp=1490184654.467000
thedo 166:240bc5a0f42a 1107 [1490184654.48][HTST][INF] __notify_complete(True)
thedo 166:240bc5a0f42a 1108 [1490184654.50][CONN][INF] found KV pair in stream: {{__exit;0}}, queued...
thedo 166:240bc5a0f42a 1109 [1490184654.51][HTST][INF] __exit(0)
thedo 166:240bc5a0f42a 1110 [1490184654.52][HTST][INF] __exit_event_queue received
thedo 166:240bc5a0f42a 1111 [1490184654.52][HTST][INF] test suite run finished after 4.75 sec...
thedo 166:240bc5a0f42a 1112 [1490184654.53][CONN][INF] received special even '__host_test_finished' value='True', finishing
thedo 166:240bc5a0f42a 1113 [1490184654.53][HTST][INF] CONN exited with code: 0
thedo 166:240bc5a0f42a 1114 [1490184654.53][HTST][INF] No events in queue
thedo 166:240bc5a0f42a 1115 [1490184654.53][HTST][INF] stopped consuming events
thedo 166:240bc5a0f42a 1116 [1490184654.53][HTST][INF] host test result() call skipped, received: True
thedo 166:240bc5a0f42a 1117 [1490184654.53][HTST][INF] calling blocking teardown()
thedo 166:240bc5a0f42a 1118 [1490184654.53][HTST][INF] teardown() finished
thedo 166:240bc5a0f42a 1119 [1490184654.53][HTST][INF] {{result;success}}
thedo 166:240bc5a0f42a 1120 mbedgt: checking for GCOV data...
thedo 166:240bc5a0f42a 1121 mbedgt: mbed-host-test-runner: stopped and returned 'OK'
thedo 166:240bc5a0f42a 1122 mbedgt: test on hardware with target id: 0240000029304e450023500878a3001df131000097969900
thedo 166:240bc5a0f42a 1123 mbedgt: test suite 'spiflash-driver-tests-block_device-spif' ......................................... OK in 28.42 sec
thedo 166:240bc5a0f42a 1124 test case: 'Testing read write random blocks' ................................................ OK in 4.29 sec
thedo 166:240bc5a0f42a 1125 mbedgt: test case summary: 1 pass, 0 failures
thedo 166:240bc5a0f42a 1126 mbedgt: all tests finished!
thedo 166:240bc5a0f42a 1127 mbedgt: shuffle seed: 0.0217829158
thedo 166:240bc5a0f42a 1128 mbedgt: test suite report:
thedo 166:240bc5a0f42a 1129 +--------------+---------------+-----------------------------------------+--------+--------------------+-------------+
thedo 166:240bc5a0f42a 1130 | target | platform_name | test suite | result | elapsed_time (sec) | copy_method |
thedo 166:240bc5a0f42a 1131 +--------------+---------------+-----------------------------------------+--------+--------------------+-------------+
thedo 166:240bc5a0f42a 1132 | K64F-GCC_ARM | K64F | spiflash-driver-tests-block_device-spif | OK | 28.42 | shell |
thedo 166:240bc5a0f42a 1133 +--------------+---------------+-----------------------------------------+--------+--------------------+-------------+
thedo 166:240bc5a0f42a 1134 mbedgt: test suite results: 1 OK
thedo 166:240bc5a0f42a 1135 mbedgt: test case report:
thedo 166:240bc5a0f42a 1136 +--------------+---------------+-----------------------------------------+----------------------------------+--------+--------+--------+--------------------+
thedo 166:240bc5a0f42a 1137 | target | platform_name | test suite | test case | passed | failed | result | elapsed_time (sec) |
thedo 166:240bc5a0f42a 1138 +--------------+---------------+-----------------------------------------+----------------------------------+--------+--------+--------+--------------------+
thedo 166:240bc5a0f42a 1139 | K64F-GCC_ARM | K64F | spiflash-driver-tests-block_device-spif | Testing read write random blocks | 1 | 0 | OK | 4.29 |
thedo 166:240bc5a0f42a 1140 +--------------+---------------+-----------------------------------------+----------------------------------+--------+--------+--------+--------------------+
thedo 166:240bc5a0f42a 1141 mbedgt: test case results: 1 OK
thedo 166:240bc5a0f42a 1142 mbedgt: completed in 35.04 sec
thedo 166:240bc5a0f42a 1143 (mx_env1) simhug01@E107851:/d/datastore/public/jobs/yr2017/2278/sdh_dev_mx1/ex_app5$
thedo 166:240bc5a0f42a 1144
thedo 166:240bc5a0f42a 1145
thedo 166:240bc5a0f42a 1146
thedo 166:240bc5a0f42a 1147 # Appendix 2: Getting Started With The I2C EEPROM Driver
thedo 166:240bc5a0f42a 1148
thedo 166:240bc5a0f42a 1149 Hardware required:
thedo 166:240bc5a0f42a 1150
thedo 166:240bc5a0f42a 1151 - K64F.
thedo 166:240bc5a0f42a 1152 - CI test shield.
thedo 166:240bc5a0f42a 1153 - Micro USB cable.
thedo 166:240bc5a0f42a 1154
thedo 166:240bc5a0f42a 1155 Software required:
thedo 166:240bc5a0f42a 1156
thedo 166:240bc5a0f42a 1157 - mbed CLI (with all other dependencies installed).
thedo 166:240bc5a0f42a 1158 - ARMCC / GCC / IAR compiler.
thedo 166:240bc5a0f42a 1159 - mbed greentea.
thedo 166:240bc5a0f42a 1160 - git account.
thedo 166:240bc5a0f42a 1161
thedo 166:240bc5a0f42a 1162 Github repos to use:
thedo 166:240bc5a0f42a 1163
thedo 166:240bc5a0f42a 1164 - The [mbed OS repository](https://github.com/armmbed/mbed-os)
thedo 166:240bc5a0f42a 1165 - The [I2C EEPROM driver repository](https://github.com/ARMmbed/i2ceeprom-driver.git)
thedo 166:240bc5a0f42a 1166 - The [CI test shield repository](https://github.com/ARMmbed/ci-test-shield.git) for `mbed_app.json` application configuration file.
thedo 166:240bc5a0f42a 1167
thedo 166:240bc5a0f42a 1168 Steps to follow:
thedo 166:240bc5a0f42a 1169
thedo 166:240bc5a0f42a 1170 - Create an empty example project in a suitable directory. Move into it.
thedo 166:240bc5a0f42a 1171 - Download mbed OS into the example directory via `mbed new .`
thedo 166:240bc5a0f42a 1172 - Add the I2C EEPROM driver via `mbed add i2ceeprom-driver`
thedo 166:240bc5a0f42a 1173 - Clone the CI test shield repository to another suitable directory. Copy the mbed_app.json
thedo 166:240bc5a0f42a 1174 from the CI test shield directory to the top level of the newly created example directory.
thedo 166:240bc5a0f42a 1175 - Make sure the I2C pins are SDA on D14 and SCL on D15 and the I2C EEPROM slave address is
thedo 166:240bc5a0f42a 1176 0xA0 in the mbed_app.json that you just copied.
thedo 166:240bc5a0f42a 1177 - Connect the target to the host machine. Run `mbed detect` to make sure the target is detected.
thedo 166:240bc5a0f42a 1178 - Now we are ready to run the greentea tests on this target with
thedo 166:240bc5a0f42a 1179 `mbed test -t ARM -m K64F -n i2ceeprom-driver-tests-block_device-i2cee -v`
thedo 166:240bc5a0f42a 1180 - Note that the greentea test above makes use of the main.cpp supplied in the
thedo 166:240bc5a0f42a 1181 `TESTS\block_device\i2cee` directory. You can customize this if required or use your own test
thedo 166:240bc5a0f42a 1182 application via main.cpp. Be sure to have only 1 main(). If using a custom main() then you
thedo 166:240bc5a0f42a 1183 can either have this in the TESTS directory or at the top level example directory.
thedo 166:240bc5a0f42a 1184 - The tests should pass. If not, time to debug!!
thedo 166:240bc5a0f42a 1185 - For other targets, please change the target ID string in the test command above to the
thedo 166:240bc5a0f42a 1186 appropriate one. You can check the supported targets from mbed CLI using `mbed target --supported`.
thedo 166:240bc5a0f42a 1187
thedo 166:240bc5a0f42a 1188 The output should be like this:
thedo 166:240bc5a0f42a 1189
thedo 166:240bc5a0f42a 1190
thedo 166:240bc5a0f42a 1191 Building library mbed-build (K64F, ARM)
thedo 166:240bc5a0f42a 1192 Scan: i2c_ex1
thedo 166:240bc5a0f42a 1193 Scan: FEATURE_BLE
thedo 166:240bc5a0f42a 1194 Scan: FEATURE_COMMON_PAL
thedo 166:240bc5a0f42a 1195 Scan: FEATURE_LWIP
thedo 166:240bc5a0f42a 1196 Scan: FEATURE_UVISOR
thedo 166:240bc5a0f42a 1197 Scan: FEATURE_ETHERNET_HOST
thedo 166:240bc5a0f42a 1198 Scan: FEATURE_LOWPAN_BORDER_ROUTER
thedo 166:240bc5a0f42a 1199 Scan: FEATURE_LOWPAN_HOST
thedo 166:240bc5a0f42a 1200 Scan: FEATURE_LOWPAN_ROUTER
thedo 166:240bc5a0f42a 1201 Scan: FEATURE_NANOSTACK
thedo 166:240bc5a0f42a 1202 Scan: FEATURE_NANOSTACK_FULL
thedo 166:240bc5a0f42a 1203 Scan: FEATURE_THREAD_BORDER_ROUTER
thedo 166:240bc5a0f42a 1204 Scan: FEATURE_THREAD_END_DEVICE
thedo 166:240bc5a0f42a 1205 Scan: FEATURE_THREAD_ROUTER
thedo 166:240bc5a0f42a 1206 Scan: FEATURE_STORAGE
thedo 166:240bc5a0f42a 1207 Scan: ARM
thedo 166:240bc5a0f42a 1208 Scan: FEATURE_LWIP
thedo 166:240bc5a0f42a 1209 Scan: FEATURE_STORAGE
thedo 166:240bc5a0f42a 1210 Building project i2cee (K64F, ARM)
thedo 166:240bc5a0f42a 1211 Scan: ARM
thedo 166:240bc5a0f42a 1212 Scan: FEATURE_LWIP
thedo 166:240bc5a0f42a 1213 Scan: FEATURE_STORAGE
thedo 166:240bc5a0f42a 1214 Scan: i2cee
thedo 166:240bc5a0f42a 1215 +-----------+-------+-------+-------+
thedo 166:240bc5a0f42a 1216 | Module | .text | .data | .bss |
thedo 166:240bc5a0f42a 1217 +-----------+-------+-------+-------+
thedo 166:240bc5a0f42a 1218 | Misc | 49473 | 420 | 11628 |
thedo 166:240bc5a0f42a 1219 | Subtotals | 49473 | 420 | 11628 |
thedo 166:240bc5a0f42a 1220 +-----------+-------+-------+-------+
thedo 166:240bc5a0f42a 1221 Allocated Heap: unknown
thedo 166:240bc5a0f42a 1222 Allocated Stack: unknown
thedo 166:240bc5a0f42a 1223 Total Static RAM memory (data + bss): 12048 bytes
thedo 166:240bc5a0f42a 1224 Total RAM memory (data + bss + heap + stack): 12048 bytes
thedo 166:240bc5a0f42a 1225 Total Flash memory (text + data + misc): 49893 bytes
thedo 166:240bc5a0f42a 1226 Image: BUILD/tests/K64F/ARM/i2ceeprom-driver/TESTS/block_device/i2cee/i2cee.bin
thedo 166:240bc5a0f42a 1227
thedo 166:240bc5a0f42a 1228
thedo 166:240bc5a0f42a 1229 Memory map breakdown for built projects (values in Bytes):
thedo 166:240bc5a0f42a 1230 +-------+--------+-----------+------------+-------+------+-----------+-------------+
thedo 166:240bc5a0f42a 1231 | name | target | toolchain | static_ram | stack | heap | total_ram | total_flash |
thedo 166:240bc5a0f42a 1232 +-------+--------+-----------+------------+-------+------+-----------+-------------+
thedo 166:240bc5a0f42a 1233 | i2cee | K64F | ARM | 12048 | 0 | 0 | 12048 | 49893 |
thedo 166:240bc5a0f42a 1234 +-------+--------+-----------+------------+-------+------+-----------+-------------+
thedo 166:240bc5a0f42a 1235
thedo 166:240bc5a0f42a 1236
thedo 166:240bc5a0f42a 1237 Build successes:
thedo 166:240bc5a0f42a 1238 * K64F::ARM::I2CEEPROM-DRIVER-TESTS-BLOCK_DEVICE-I2CEE
thedo 166:240bc5a0f42a 1239 * K64F::ARM::MBED-BUILD
thedo 166:240bc5a0f42a 1240 mbedgt: greentea test automation tool ver. 1.2.5
thedo 166:240bc5a0f42a 1241 mbedgt: test specification file 'C:\Ashok\SiPWorkshop\Filesystem\i2c_ex1\BUILD\tests\K64F\ARM\test_spec.json' (specified with --test-spec option)
thedo 166:240bc5a0f42a 1242 mbedgt: using 'C:\Ashok\SiPWorkshop\Filesystem\i2c_ex1\BUILD\tests\K64F\ARM\test_spec.json' from current directory!
thedo 166:240bc5a0f42a 1243 mbedgt: detecting connected mbed-enabled devices...
thedo 166:240bc5a0f42a 1244 mbedgt: detected 1 device
thedo 166:240bc5a0f42a 1245 mbedgt: processing target 'K64F' toolchain 'ARM' compatible platforms... (note: switch set to --parallel 1)
thedo 166:240bc5a0f42a 1246 mbedgt: test case filter (specified with -n option)
thedo 166:240bc5a0f42a 1247 test filtered in 'i2ceeprom-driver-tests-block_device-i2cee'
thedo 166:240bc5a0f42a 1248 mbedgt: running 1 test for platform 'K64F' and toolchain 'ARM'
thedo 166:240bc5a0f42a 1249 mbedgt: mbed-host-test-runner: started
thedo 166:240bc5a0f42a 1250 mbedgt: checking for GCOV data...
thedo 166:240bc5a0f42a 1251 mbedgt: test on hardware with target id: 0240000034544e45002600048e3800285a91000097969900
thedo 166:240bc5a0f42a 1252 mbedgt: test suite 'i2ceeprom-driver-tests-block_device-i2cee' ....................................... OK in 11.79 sec
thedo 166:240bc5a0f42a 1253 test case: 'Testing read write random blocks' ................................................ OK in 1.23 sec
thedo 166:240bc5a0f42a 1254 mbedgt: test case summary: 1 pass, 0 failures
thedo 166:240bc5a0f42a 1255 mbedgt: all tests finished!
thedo 166:240bc5a0f42a 1256 mbedgt: shuffle seed: 0.1529521449
thedo 166:240bc5a0f42a 1257 mbedgt: test suite report:
thedo 166:240bc5a0f42a 1258 +----------+---------------+-------------------------------------------+--------+--------------------+-------------+
thedo 166:240bc5a0f42a 1259 | target | platform_name | test suite | result | elapsed_time (sec) | copy_method |
thedo 166:240bc5a0f42a 1260 +----------+---------------+-------------------------------------------+--------+--------------------+-------------+
thedo 166:240bc5a0f42a 1261 | K64F-ARM | K64F | i2ceeprom-driver-tests-block_device-i2cee | OK | 11.79 | shell |
thedo 166:240bc5a0f42a 1262 +----------+---------------+-------------------------------------------+--------+--------------------+-------------+
thedo 166:240bc5a0f42a 1263 mbedgt: test suite results: 1 OK
thedo 166:240bc5a0f42a 1264 mbedgt: test case report:
thedo 166:240bc5a0f42a 1265 +----------+---------------+-------------------------------------------+----------------------------------+--------+--------+--------+--------------------+
thedo 166:240bc5a0f42a 1266 | target | platform_name | test suite | test case | passed | failed | result | elapsed_time (sec) |
thedo 166:240bc5a0f42a 1267 +----------+---------------+-------------------------------------------+----------------------------------+--------+--------+--------+--------------------+
thedo 166:240bc5a0f42a 1268 | K64F-ARM | K64F | i2ceeprom-driver-tests-block_device-i2cee | Testing read write random blocks | 1 | 0 | OK | 1.23 |
thedo 166:240bc5a0f42a 1269 +----------+---------------+-------------------------------------------+----------------------------------+--------+--------+--------+--------------------+
thedo 166:240bc5a0f42a 1270 mbedgt: test case results: 1 OK
thedo 166:240bc5a0f42a 1271 mbedgt: completed in 13.30 sec