Skip to content

Commit 80a74c6

Browse files
authored
Merge pull request #3468 from simonqhughes/feature-storage
STORAGE: FAT32/SDCARD Filesystem support with basic test (basic.cpp)
2 parents eb3dc2d + d8bf533 commit 80a74c6

23 files changed

+2413
-3
lines changed

features/TESTS/filesystem/basic/basic.cpp

Lines changed: 429 additions & 0 deletions
Large diffs are not rendered by default.

features/TESTS/filesystem/fopen/fopen.cpp

Lines changed: 852 additions & 0 deletions
Large diffs are not rendered by default.

features/filesystem/README.md

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
# FAT32 Filesystem Support README #
2+
3+
Simon Hughes
4+
5+
20161219
6+
7+
Version 0.02
8+
9+
10+
# Executive Summary
11+
12+
These notes are intended to help the mbed client team adopt the mbedOS POSIX File API support. The notes cover:
13+
14+
- Brief notes on how to setup the mbedOS development environment, including links to other resources.
15+
- How to build the mbedOS test cases.
16+
- How to run the POSIX File API test case.
17+
18+
Note the following:
19+
20+
- The mbedOS FAT32/SDCard support implements a POSIX File API for off-chip, persistent file storage.
21+
- The FAT32/SDCard support was present in mbedOS 2, but was moved to the "unsupported" area of the source tree in mbedOS 5.
22+
This is because there are currently no FAT32/SDCard POSIX API test cases in the public repository, software quality is hence unknown, and the features are therefore unsupported.
23+
- The implementation of new test cases is an active development activity. So far, one test binary (basic.cpp) has been implemented and is available on the mbed-os branch called 'feature-storage'. The test case support
24+
is being enhanced as a matter of urgency.
25+
- The work described here is intended to make the POSIX File API available to the mbed client team before the Christmas holidays.
26+
Further test cases will be implemented and when completed, the work will be merged into the public repository master branch. In the meantime,
27+
the work is available from feature-storage branch.
28+
29+
# Getting Started
30+
31+
This section describes how to build and run the POSIX file API test case. The following steps are covered:
32+
33+
- [Installing the Tools](#installing-the-tools). This section briefly describes how to setup the mbedos development environment.
34+
- [Git Clone the Public mbedOS Repo](#git-clone-the-mbedos-repo). This section describes how to git clone the mbedOS repository containing the FAT32/SDCard and POSIX File API test case of interest.
35+
- [Build the mbedOS Test Cases](#build-the-mbedos-test-cases). This section describes how to build the mbedOS test cases.
36+
- [Run the POSIX File Test Case](#run-the-posix-file-test-cases).This section describes how to run the POSIX file test case basic.cpp.
37+
38+
### <a name="installing-the-tools"></a> Installing the Tools
39+
40+
The following tools should be installed:
41+
42+
- arm-none-eabi-gcc. See [mbedOS Development Environment Setup Howto Notes][MBED_DEVENV_NOTES] for guidance.
43+
- Python 2.7.9 or later. See [mbedOS Development Environment Setup Howto Notes][MBED_DEVENV_NOTES] for guidance.
44+
- mbed Greentea. This is the mbedOS test tool.
45+
- Git Bash. See [mbedOS Development Environment Setup Howto Notes][MBED_DEVENV_NOTES] for guidance.
46+
- mbed-cli. This is the tool used to make mbedOS application and test builds.
47+
48+
Using a Git Bash terminal, setup mbed-cli in the following way:
49+
50+
simhug01@E107851:/d/demo_area$ git clone [email protected]:/armmbed/mbed-cli
51+
<trace removed>
52+
simhug01@E107851:/d/demo_area$ pushd mbed-cli
53+
simhug01@E107851:/d/demo_area/mbed-cli/$ python.exe setup.py install
54+
simhug01@E107851:/d/demo_area/mbed-cli/$ popd
55+
56+
57+
Using a Git Bash terminal, setup Greentea in the following way:
58+
59+
simhug01@E107851:/d/demo_area$ git clone [email protected]:/armmbed/greentea
60+
<trace removed>
61+
simhug01@E107851:/d/demo_area$ pushd greentea
62+
simhug01@E107851:/d/demo_area/greentea/$ python.exe setup.py install
63+
simhug01@E107851:/d/demo_area/greentea/$ popd
64+
simhug01@E107851:/d/demo_area/$
65+
66+
67+
### <a name="git-clone-the-mbedos-repo"></a> Git Clone the Public mbedOS Repo
68+
69+
Get a clone of public mbedOS repository in the following way
70+
71+
simhug01@E107851:/d/demo_area$ mkdir ex_app1
72+
simhug01@E107851:/d/demo_area$ pushd ex_app1
73+
simhug01@E107851:/d/demo_area/ex_app1$ git clone [email protected]:/armmbed/mbed-os
74+
<trace removed>
75+
simhug01@E107851:/d/demo_area/ex_app1$
76+
77+
78+
### <a name="build-the-mbedos-test-cases"></a> Build the mbedOS Test Cases
79+
80+
Switch to the `feature-storage` branch using the following commands:
81+
82+
simhug01@E107851:/d/demo_area/ex_app1$ pushd mbed-os
83+
simhug01@E107851:/d/demo_area/ex_app1$ git branch
84+
* master
85+
feature-storage
86+
<other branches deleted>
87+
simhug01@E107851:/d/demo_area/ex_app1$ git checkout feature-storage
88+
Switched to branch 'feature-storage'
89+
simhug01@E107851:/d/demo_area/ex_app1$ git branch
90+
master
91+
* feature-storage
92+
<other branches deleted>
93+
simhug01@E107851:/d/demo_area/ex_app1$
94+
95+
Build the test cases for the K64F target using the following commands:
96+
97+
simhug01@E107851:/d/demo_area/ex_app1$ mbed -v test --compile -t GCC_ARM -m K64F -DFSFAT_SDCARD_INSTALLED 2>&1 | tee build_tests_gcc_20161219_1007.txt
98+
<trace removed>
99+
simhug01@E107851:/d/demo_area/ex_app1$
100+
101+
The complete [build log][BUILD-TESTS-GCC-20161219-1007] is available for reference.
102+
103+
104+
### <a name="run-the-posix-file-test-cases"></a> Run the POSIX File Test Case
105+
106+
To setup for running the test cases, complete the following steps:
107+
108+
- Insert a micro SDCard into K64F SDCard socket.
109+
- Connect the K64F development board to your PC using a suitable USB cable.
110+
111+
All tests can be run using the following command:
112+
113+
simhug01@E107851:/d/demo_area/ex_app1$ mbedgt -VS
114+
<trace removed>
115+
116+
However, it's possible to run a particular test case using the following .json file:
117+
118+
{
119+
"builds": {
120+
"K64F-GCC_ARM": {
121+
"binary_type": "bootable",
122+
"tests": {
123+
"mbed-os-features-storage-feature_storage-tests-fs-fat-basic": {
124+
"binaries": [
125+
{
126+
"path": "BUILD/tests/K64F/GCC_ARM/mbed-os/features/storage/FEATURE_STORAGE/TESTS/fs-fat/basic/basic.bin"
127+
}
128+
]
129+
}
130+
},
131+
"toolchain": "GCC_ARM",
132+
"base_path": "BUILD/tests/K64F/GCC_ARM",
133+
"baud_rate": 9600,
134+
"platform": "K64F"
135+
}
136+
}
137+
}
138+
139+
Store the above text in a file called `ex_app1_fat_basic_spec.json` in the ex_app1 directory. The test can be run using the following command:
140+
141+
simhug01@E107851:/d/demo_area/ex_app1$ mbedgt -VS --test-spec=ex_app1_fat_basic_spec.json 2>&1 | tee run_tests_master_gcc_ex_app2_fat_basic_20161219_1011.txt
142+
<trace removed>
143+
144+
On a successful run, the following table will be shown at the end of the log:
145+
146+
mbedgt: test suite 'mbed-os-features-storage-feature_storage-tests-fs-fat-basic' ..................... OK in 15.86 sec
147+
test case: 'FSFAT_test_00: fopen()/fgetc()/fprintf()/fclose() test.' ......................... OK in 0.90 sec
148+
test case: 'FSFAT_test_01: fopen()/fseek()/fclose() test.' ................................... OK in 0.32 sec
149+
mbedgt: test case summary: 2 passes, 0 failures
150+
mbedgt: all tests finished!
151+
mbedgt: shuffle seed: 0.7720862854
152+
mbedgt: test suite report:
153+
+--------------+---------------+-------------------------------------------------------------+--------+--------------------+-------------+
154+
| target | platform_name | test suite | result | elapsed_time (sec) | copy_method |
155+
+--------------+---------------+-------------------------------------------------------------+--------+--------------------+-------------+
156+
| K64F-GCC_ARM | K64F | mbed-os-features-storage-feature_storage-tests-fs-fat-basic | OK | 15.86 | shell |
157+
+--------------+---------------+-------------------------------------------------------------+--------+--------------------+-------------+
158+
mbedgt: test suite results: 1 OK
159+
mbedgt: test case report:
160+
+--------------+---------------+-------------------------------------------------------------+---------------------------------------------------------+--------+--------+--------+--------------------+
161+
| target | platform_name | test suite | test case | passed | failed | result | elapsed_time (sec) |
162+
+--------------+---------------+-------------------------------------------------------------+---------------------------------------------------------+--------+--------+--------+--------------------+
163+
| K64F-GCC_ARM | K64F | mbed-os-features-storage-feature_storage-tests-fs-fat-basic | FSFAT_test_00: fopen()/fgetc()/fprintf()/fclose() test. | 1 | 0 | OK | 0.9 |
164+
| K64F-GCC_ARM | K64F | mbed-os-features-storage-feature_storage-tests-fs-fat-basic | FSFAT_test_01: fopen()/fseek()/fclose() test. | 1 | 0 | OK | 0.32 |
165+
+--------------+---------------+-------------------------------------------------------------+---------------------------------------------------------+--------+--------+--------+--------------------+
166+
mbedgt: test case results: 2 OK
167+
mbedgt: completed in 16.53 sec
168+
169+
170+
The full [test output log][RUN-TESTS-GCC-20161219-1011] is available for reference.
171+
172+
173+
# POSIX File API
174+
175+
mbedOS supports a subset of the POSIX File API, as outlined below:
176+
177+
- [fclose()][MAN_FCLOSE].
178+
- [fgetc(), fgets(), getc(), gets()][MAN_FGETS].
179+
- [fputc(), fputs(), putc(), puts()][MAN_FPUTS].
180+
- fprintf()
181+
- fopen()
182+
- freopen()
183+
- [fread()][MAN_FREAD]
184+
- [fwrite()][MAN_FWRITE]
185+
- [fseek()][MAN_FSEEK]
186+
- [remove()][MAN_REMOVE]
187+
- [rewind()][MAN_REWIND].
188+
189+
The FAT32/SDCard support is at the following location in the source code tree:
190+
191+
<mbed-os_src_root>\features\storage\FEATURE_STORAGE\fs
192+
193+
The FAT32/SDCard test cases are at following locations in the source code tree:
194+
195+
<mbed-os_src_root>\features\storage\FEATURE_STORAGE\TESTS\fs-fat\basic\basic.cpp
196+
197+
198+
199+
200+
201+
# Further Reading
202+
203+
* The [mbedOS Development Environment Setup Notes][MBED_DEVENV_NOTES].
204+
* The example mbedOS build log [BUILD-TESTS-GCC-20161219-1007][BUILD-TESTS-GCC-20161219-1007] for reference.
205+
* The example mbedOS test run log [RUN-TESTS-GCC-20161219-1011][RUN-TESTS-GCC-20161219-1011] for reference.
206+
207+
208+
[MBED_DEVENV_NOTES]: https://github.com/ARMmbed/meVo/blob/master/docs/ARM_MBED/TN/ARM_MBED_TN_0017/12-mbed_devenv_setup_how_to_notes.docx
209+
[BUILD-TESTS-GCC-20161219-1007]: https://github.com/ARMmbed/meVo/blob/master/docs/ARM_MBED/TN/ARM_MBED_TN_0017/build_tests_gcc_20161219_1007.txt
210+
[RUN-TESTS-GCC-20161219-1011]: https://github.com/ARMmbed/meVo/blob/master/docs/ARM_MBED/TN/ARM_MBED_TN_0017/run_tests_master_gcc_ex_app2_fat_basic_20161219_1011.txt
211+
212+
[MAN_FCLOSE]: https://linux.die.net/man/3/fclose
213+
[MAN_FGETS]: https://linux.die.net/man/3/fgets
214+
[MAN_FPUTS]: https://linux.die.net/man/3/fputs
215+
[MAN_FREAD]: https://linux.die.net/man/3/fread
216+
[MAN_FSEEK]: https://linux.die.net/man/3/fseek
217+
[MAN_FWRITE]: https://linux.die.net/man/3/fwrite
218+
[MAN_REMOVE]: https://linux.die.net/man/3/remove
219+
[MAN_REWIND]: https://linux.die.net/man/3/rewind

features/unsupported/fs/sd/SDFileSystem.cpp renamed to features/filesystem/sd/SDFileSystem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
* | 0xFE | data[0] | data[1] | | data[n] | crc[15:8] | crc[7:0] |
113113
* +------+---------+---------+- - - -+---------+-----------+----------+
114114
*/
115+
116+
/* If the target has no SPI support then SDCard is not supported */
117+
#ifdef DEVICE_SPI
118+
115119
#include "SDFileSystem.h"
116120
#include "mbed_debug.h"
117121

@@ -537,3 +541,5 @@ uint32_t SDFileSystem::_sd_sectors() {
537541
};
538542
return blocks;
539543
}
544+
545+
#endif /* DEVICE_SPI */

features/unsupported/fs/sd/SDFileSystem.h renamed to features/filesystem/sd/SDFileSystem.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@
2222
#ifndef MBED_SDFILESYSTEM_H
2323
#define MBED_SDFILESYSTEM_H
2424

25+
/* If the target has no SPI support then SDCard is not supported */
26+
#ifdef DEVICE_SPI
27+
2528
#include "mbed.h"
2629
#include "FATFileSystem.h"
2730
#include <stdint.h>
2831

32+
33+
2934
/** Access the filesystem on an SD Card using SPI
3035
*
3136
* @code
@@ -88,4 +93,6 @@ class SDFileSystem : public FATFileSystem {
8893
bool _dbg;
8994
};
9095

91-
#endif
96+
#endif /* DEVICE_SPI */
97+
98+
#endif /* MBED_SDFILESYSTEM_H */
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/** @file fsfat_debug.h
2+
*
3+
* component debug header file.
4+
*/
5+
6+
7+
#ifndef __FSFAT_DEBUG
8+
#define __FSFAT_DEBUG
9+
10+
#include <stdint.h>
11+
#include <assert.h>
12+
#include <stdio.h>
13+
14+
15+
/* Debug Support */
16+
17+
#define FSFAT_LOG_NONE 0
18+
#define FSFAT_LOG_ERR 1
19+
#define FSFAT_LOG_WARN 2
20+
#define FSFAT_LOG_NOTICE 3
21+
#define FSFAT_LOG_INFO 4
22+
#define FSFAT_LOG_DEBUG 5
23+
#define FSFAT_LOG_FENTRY 6
24+
25+
#define FSFAT_LOG(_fmt, ...) \
26+
do \
27+
{ \
28+
printf(_fmt, __VA_ARGS__); \
29+
}while(0);
30+
31+
#define noFSFAT_DEBUG
32+
33+
#ifdef FSFAT_DEBUG
34+
35+
extern uint32_t fsfat_optDebug_g;
36+
extern uint32_t fsfat_optLogLevel_g;
37+
38+
39+
/* uncomment for asserts to work */
40+
/* #undef NDEBUG */
41+
// todo: port to mbedOSV3++ #include <core-util/assert.h>
42+
43+
#define FSFAT_INLINE
44+
// todo: port to mbedOSV3++ #define FSFAT_ASSERT CORE_UTIL_ASSERT
45+
#define FSFAT_ASSERT(...)
46+
47+
#define FSFAT_DBGLOG(_fmt, ...) \
48+
do \
49+
{ \
50+
if(fsfat_optDebug_g && (fsfat_optLogLevel_g >= FSFAT_LOG_DEBUG)) \
51+
{ \
52+
printf(_fmt, __VA_ARGS__); \
53+
} \
54+
}while(0);
55+
56+
57+
#define FSFAT_ERRLOG(_fmt, ...) \
58+
do \
59+
{ \
60+
if(fsfat_optDebug_g && (fsfat_optLogLevel_g >= FSFAT_LOG_ERR)) \
61+
{ \
62+
printf(_fmt, __VA_ARGS__); \
63+
} \
64+
}while(0);
65+
66+
67+
#define FSFAT_FENTRYLOG(_fmt, ...) \
68+
do \
69+
{ \
70+
if(fsfat_optDebug_g && (fsfat_optLogLevel_g >= FSFAT_LOG_FENTRY)) \
71+
{ \
72+
printf(_fmt, __VA_ARGS__); \
73+
} \
74+
}while(0);
75+
76+
77+
78+
79+
80+
#else
81+
#define FSFAT_ASSERT(_x) do { } while(0)
82+
#define FSFAT_INLINE inline
83+
#define FSFAT_DBGLOG(_fmt, ...) do { } while(0)
84+
#define FSFAT_ERRLOG(_fmt, ...) do { } while(0)
85+
#define FSFAT_FENTRYLOG(_fmt, ...) do { } while(0)
86+
#endif /* FSFAT_DEBUG */
87+
88+
89+
#endif /*__FSFAT_DEBUG*/

0 commit comments

Comments
 (0)