the do / gr-peach-opencv-project

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

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

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