Skip to content

Commit 684fcc1

Browse files
authored
Merge pull request #3864 from geky/fix-size_t-mbed-2
Fix mbed 2 builds
2 parents 88a4baa + a937ee0 commit 684fcc1

File tree

4 files changed

+83
-3
lines changed

4 files changed

+83
-3
lines changed

drivers/FileSystemLike.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class FileSystemLike : public FileBase {
114114
* 0 on success or un-needed,
115115
* -1 on error
116116
*/
117-
virtual int stat(const char *name, struct stat *st) = 0;
117+
virtual int stat(const char *name, struct stat *st) { return -1; };
118118
};
119119

120120
} // namespace mbed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include "test_env.h"
2+
#include "mbed_semihost_api.h"
3+
4+
Serial pc(USBTX, USBRX);
5+
6+
#define FILENAME "/local/out.txt"
7+
#define TEST_STRING "Hello World!"
8+
9+
FILE *test_open(const char *mode) {
10+
FILE *f = fopen(FILENAME, mode);
11+
if (f == NULL) {
12+
printf("Error opening file"NL);
13+
notify_completion(false);
14+
}
15+
return f;
16+
}
17+
18+
void test_write(FILE *f, char *str, int str_len) {
19+
int n = fprintf(f, str);
20+
21+
if (n != str_len) {
22+
printf("Error writing file"NL);
23+
notify_completion(false);
24+
}
25+
}
26+
27+
void test_read(FILE *f, char *str, int str_len) {
28+
int n = fread(str, sizeof(unsigned char), str_len, f);
29+
30+
if (n != str_len) {
31+
printf("Error reading file"NL);
32+
notify_completion(false);
33+
}
34+
}
35+
36+
void test_close(FILE *f) {
37+
int rc = fclose(f);
38+
39+
if (rc != 0) {
40+
printf("Error closing file"NL);
41+
notify_completion(false);
42+
}
43+
}
44+
45+
int main() {
46+
MBED_HOSTTEST_TIMEOUT(20);
47+
MBED_HOSTTEST_SELECT(default_auto);
48+
MBED_HOSTTEST_DESCRIPTION(Semihost file system);
49+
MBED_HOSTTEST_START("MBED_A2");
50+
51+
pc.printf("Test the Stream class\n");
52+
53+
printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No"));
54+
55+
char mac[16];
56+
mbed_mac_address(mac);
57+
printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
58+
59+
LocalFileSystem local("local");
60+
61+
FILE *f;
62+
char *str = TEST_STRING;
63+
char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING));
64+
int str_len = strlen(TEST_STRING);
65+
66+
// Write
67+
f = test_open("w");
68+
test_write(f, str, str_len);
69+
test_close(f);
70+
71+
// Read
72+
f = test_open("r");
73+
test_read(f, buffer, str_len);
74+
test_close(f);
75+
76+
// Check the two strings are equal
77+
MBED_HOSTTEST_RESULT((strncmp(buffer, str, str_len) == 0));
78+
}

platform/mbed_retarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define RETARGET_H
2121

2222
#include <stdint.h>
23+
#include <stddef.h>
2324

2425
/* We can get the following standard types from sys/types for gcc, but we
2526
* need to define the types ourselves for the other compilers that normally

tools/build_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ def build_library(src_paths, build_path, target, toolchain_name,
732732
######################
733733

734734
def mbed2_obj_path(target_name, toolchain_name):
735-
return join("TARGET_" + target_name, "TOOLCHAIN_" + toolchain_name)
735+
real_tc_name = TOOLCHAIN_CLASSES[toolchain_name].__name__
736+
return join("TARGET_" + target_name, "TOOLCHAIN_" + real_tc_name)
736737

737738
def build_lib(lib_id, target, toolchain_name, verbose=False,
738739
clean=False, macros=None, notify=None, jobs=1, silent=False,
@@ -955,7 +956,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
955956
try:
956957
# Source and Build Paths
957958
build_target = join(MBED_LIBRARIES, "TARGET_" + target.name)
958-
build_toolchain = join(build_target, "TOOLCHAIN_" + toolchain_name)
959+
build_toolchain = join(MBED_LIBRARIES, mbed2_obj_path(target.name, toolchain_name))
959960
mkdir(build_toolchain)
960961

961962
# Toolchain

0 commit comments

Comments
 (0)