Skip to content

Commit 091fe5c

Browse files
committed
synch targets, exporters and tests
1 parent f9a1972 commit 091fe5c

File tree

7 files changed

+194
-46
lines changed

7 files changed

+194
-46
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include "test_env.h"
2+
3+
/******************************************************************************
4+
This will test an I2C EEPROM connected to mbed by writing a predefined byte at
5+
address 0 and then reading it back and comparing it with the known byte value a
6+
number of times. This test was written specifically for reproducing the bug
7+
reported here:
8+
9+
https://mbed.org/forum/bugs-suggestions/topic/4128/
10+
11+
Test configuration:
12+
13+
* set 'ntests' to the number of iterations
14+
* set 'i2c_speed_hz' to the desired speed of the I2C interface
15+
* set 'i2c_delay_us' to the delay that will be inserted between 'write' and
16+
'read' I2C operations (https://mbed.org/users/mbed_official/code/mbed/issues/1
17+
for more details). '0' disables the delay.
18+
* define I2C_EEPROM_VERBOSE to get verbose output
19+
20+
The test ran with a 24LC256 external EEPROM memory, but any I2C EEPROM memory
21+
that uses two byte addresses should work.
22+
******************************************************************************/
23+
24+
// Test configuration block
25+
static const int ntests = 10000;
26+
static const int i2c_freq_hz = 400000;
27+
static const int i2c_delay_us = 0;
28+
//#define I2C_EEPROM_VERBOSE
29+
// End of test configuration block
30+
31+
#if defined(TARGET_KL25Z)
32+
I2C i2c(PTE0, PTE1);
33+
#else
34+
I2C i2c(p28, p27);
35+
#endif
36+
37+
#ifdef I2C_EEPROM_VERBOSE
38+
#define dprintf printf
39+
#else
40+
int dprintf(const char* args, ...) {
41+
return 0;
42+
}
43+
#endif
44+
45+
class TestHelper {
46+
public:
47+
// Defaults to 'passed'
48+
TestHelper() {
49+
passed();
50+
}
51+
52+
void passed() {
53+
m_result = true;
54+
}
55+
56+
void failed() {
57+
m_result = false;
58+
}
59+
60+
~TestHelper() {
61+
notify_completion(m_result);
62+
}
63+
private:
64+
bool m_result;
65+
};
66+
67+
int main() {
68+
const int addr = 0xA0;
69+
const char mark = 0x66;
70+
char data[3];
71+
int fw = 0, fr = 0, fc = 0;
72+
int i2c_stat;
73+
TestHelper helper;
74+
75+
i2c.frequency(i2c_freq_hz);
76+
77+
// Data write
78+
data[0] = data[1] = 0;
79+
data[2] = mark;
80+
if((i2c_stat = i2c.write(addr, data, 3)) != 0) {
81+
dprintf("Unable to write data to EEPROM (i2c_stat = 0x%02X), aborting\r\n", i2c_stat);
82+
helper.failed();
83+
return 1;
84+
}
85+
// ACK polling (assumes write will be successful eventually)
86+
while(i2c.write(addr, data, 0) != 0);
87+
88+
// Data read (actual test)
89+
for(int i = 0; i < ntests; i ++)
90+
{
91+
data[0] = data[1] = 0;
92+
if((i2c_stat = i2c.write(addr, data, 2, true)) != 0)
93+
{
94+
dprintf("Test %d failed at write, i2c_stat is 0x%02X\r\n", i, i2c_stat);
95+
fw ++;
96+
continue;
97+
}
98+
if(i2c_delay_us != 0)
99+
wait_us(i2c_delay_us);
100+
if((i2c_stat = i2c.read(addr, data, 1)) != 0)
101+
{
102+
dprintf("Test %d failed at read, i2c_stat is 0x%02X\r\n", i, i2c_stat);
103+
fr ++;
104+
continue;
105+
}
106+
if(data[0] != mark)
107+
{
108+
dprintf("Test %d failed at data match\r\n", i);
109+
fc ++;
110+
}
111+
}
112+
dprintf("Test finished.\r\n");
113+
if(fw + fr + fc == 0)
114+
dprintf("No failures in %d tests.\r\n", ntests);
115+
else
116+
{
117+
dprintf("Statistics:\r\n");
118+
dprintf(" Total tests: %d\r\n", ntests);
119+
dprintf(" Failed at write: %d\r\n", fw);
120+
dprintf(" Failed at read: %d\r\n", fr);
121+
dprintf(" Data mismatch: %d\r\n", fc);
122+
dprintf(" Total failures: %d\r\n", fw + fr + fc);
123+
helper.failed();
124+
}
125+
}

workspace_tools/export/uvision4.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class Uvision4(Exporter):
66
NAME = 'uVision4'
77
TOOLCHAIN = 'ARM'
8-
TARGETS = ['LPC1768', 'LPC11U24', 'KL25Z']
8+
TARGETS = ['LPC1768', 'LPC11U24', 'KL25Z', 'LPC1347']
99
FILE_TYPES = {
1010
'c_sources':'1',
1111
'cpp_sources':'8',
@@ -21,7 +21,6 @@ def generate(self):
2121
source_files.append({
2222
'name': basename(file), 'type': n, 'path': file
2323
})
24-
2524
ctx = {
2625
'name': self.program_name,
2726
'include_paths': self.resources.inc_dirs,
@@ -33,7 +32,4 @@ def generate(self):
3332

3433
# Project file
3534
self.gen_file('uvision4_%s.uvproj.tmpl' % target, ctx, '%s.uvproj' % self.program_name)
36-
37-
if (target == 'lpc1768' or target == 'lpc11u24' or target == 'kl25z'):
38-
# Add debug option to target the MCB1700
39-
self.gen_file('uvision4_%s.uvopt.tmpl' % target, ctx, '%s.uvopt' % self.program_name)
35+
self.gen_file('uvision4_%s.uvopt.tmpl' % target, ctx, '%s.uvopt' % self.program_name)

workspace_tools/export/uvision4_lpc11u24.uvproj.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@
344344
<uThumb>0</uThumb>
345345
<VariousControls>
346346
<MiscControls>--gnu</MiscControls>
347-
<Define>TARGET_LPC11U24</Define>
347+
<Define>TARGET_LPC11U24, NDEBUG, TOOLCHAIN_ARM, __CMSIS_RTOS, __CORTEX_M0</Define>
348348
<Undefine></Undefine>
349349
<IncludePath> {% for path in include_paths %} {{path}}; {% endfor %} </IncludePath>
350350
</VariousControls>
@@ -358,7 +358,7 @@
358358
<SwStkChk>0</SwStkChk>
359359
<NoWarn>0</NoWarn>
360360
<VariousControls>
361-
<MiscControls>--gnu</MiscControls>
361+
<MiscControls></MiscControls>
362362
<Define></Define>
363363
<Undefine></Undefine>
364364
<IncludePath></IncludePath>

workspace_tools/export_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_export(toolchain, target, expected_error=None):
7272
setup_test_user_prj()
7373

7474
for toolchain, target in [
75-
('uvision', 'LPC1768'), ('uvision', 'LPC11U24'), ('uvision', 'KL25Z'),
75+
('uvision', 'LPC1768'), ('uvision', 'LPC11U24'), ('uvision', 'KL25Z'), ('uvision', 'LPC1347'),
7676

7777
('codered', 'LPC1768'),
7878

workspace_tools/synch.py

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212
ROOT = abspath(join(dirname(__file__), ".."))
1313
sys.path.append(ROOT)
1414

15-
from workspace_tools.settings import MBED_ORG_PATH, MBED_ORG_USER
15+
from workspace_tools.settings import MBED_ORG_PATH, MBED_ORG_USER, BUILD_DIR
1616
from workspace_tools.paths import LIB_DIR
1717
from workspace_tools.utils import cmd, run_cmd
1818

1919

20+
MBED_URL = "mbed.org"
21+
# MBED_URL = "world2.dev.mbed.org"
22+
2023
MBED_REPO_EXT = (".lib", ".bld")
2124

2225
# mbed_official code that does have a mirror in the mbed SDK
2326
OFFICIAL_CODE = (
24-
("mbed-src" , "mbed"),
25-
27+
("mbed-src" , "mbed"),
2628
("mbed-rtos", "rtos"),
2729
("mbed-dsp" , "dsp"),
2830
("mbed-rpc" , "rpc"),
@@ -35,7 +37,7 @@
3537
("EthernetInterface", "net/eth/EthernetInterface"),
3638

3739
("USBDevice", "USBDevice"),
38-
("USBHost", "USBHost"),
40+
("USBHost" , "USBHost"),
3941
)
4042

4143

@@ -71,7 +73,7 @@
7173

7274

7375
class MbedOfficialRepository:
74-
URL = "http://mbed.org/users/mbed_official/code/%s/"
76+
URL = "http://" + MBED_URL + "/users/mbed_official/code/%s/"
7577

7678
def __init__(self, name):
7779
self.name = name
@@ -123,32 +125,35 @@ def visit_files(path, visit, ignore=None, select=None):
123125
visit(join(root, file))
124126

125127

128+
def update_repo(repo_name, sdk_path):
129+
repo = MbedOfficialRepository(repo_name)
130+
# copy files from mbed SDK to mbed_official repository
131+
def visit_mbed_sdk(sdk_file):
132+
repo_file = join(repo.path, relpath(sdk_file, sdk_path))
133+
134+
repo_dir = dirname(repo_file)
135+
if not exists(repo_dir):
136+
makedirs(repo_dir)
137+
138+
copyfile(sdk_file, repo_file)
139+
visit_files(sdk_path, visit_mbed_sdk, ['.json'])
140+
141+
# remove repository files that do not exist in the mbed SDK
142+
def visit_repo(repo_file):
143+
sdk_file = join(sdk_path, relpath(repo_file, repo.path))
144+
if not exists(sdk_file):
145+
remove(repo_file)
146+
print "remove: %s" % repo_file
147+
visit_files(repo.path, visit_repo, MBED_REPO_EXT)
148+
149+
repo.publish()
150+
151+
126152
def update_code(repositories):
127153
for repo_name, sdk_dir in repositories:
128154
print '\n=== Updating "%s" ===' % repo_name
129-
repo = MbedOfficialRepository(repo_name)
130155
sdk_path = join(LIB_DIR, sdk_dir)
131-
132-
# copy files from mbed SDK to mbed_official repository
133-
def visit_mbed_sdk(sdk_file):
134-
repo_file = join(repo.path, relpath(sdk_file, sdk_path))
135-
136-
repo_dir = dirname(repo_file)
137-
if not exists(repo_dir):
138-
makedirs(repo_dir)
139-
140-
copyfile(sdk_file, repo_file)
141-
visit_files(sdk_path, visit_mbed_sdk, ['.json'])
142-
143-
# remove repository files that do not exist in the mbed SDK
144-
def visit_repo(repo_file):
145-
sdk_file = join(sdk_path, relpath(repo_file, repo.path))
146-
if not exists(sdk_file):
147-
remove(repo_file)
148-
print "remove: %s" % repo_file
149-
visit_files(repo.path, visit_repo, MBED_REPO_EXT)
150-
151-
repo.publish()
156+
update_repo(repo_name, sdk_path)
152157

153158

154159
def update_dependencies(repositories):
@@ -167,21 +172,33 @@ def visit_repo(repo_file):
167172
repo.publish()
168173

169174

175+
def update_mbed():
176+
update_repo("mbed", join(BUILD_DIR, "mbed"))
177+
178+
170179
if __name__ == '__main__':
171180
parser = OptionParser()
172181

173-
parser.add_option("-c", "--code", dest="code",
182+
parser.add_option("-c", "--code",
174183
action="store_true", default=False,
175184
help="Update the mbed_official code")
176185

177-
parser.add_option("-d", "--dependencies", dest="dependencies",
186+
parser.add_option("-d", "--dependencies",
178187
action="store_true", default=False,
179188
help="Update the mbed_official code dependencies")
180189

190+
parser.add_option("-m", "--mbed",
191+
action="store_true", default=False,
192+
help="Release a build of the mbed library")
193+
181194
(options, args) = parser.parse_args()
182195

183196
if options.code:
184197
update_code(OFFICIAL_CODE)
185198

186199
if options.dependencies:
187200
update_dependencies(CODE_WITH_DEPENDENCIES)
201+
202+
if options.mbed:
203+
update_mbed()
204+

workspace_tools/targets.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ def __init__(self):
163163

164164
self.supported_toolchains = ["ARM"]
165165

166+
class LPC1347(Target):
167+
def __init__(self):
168+
Target.__init__(self)
169+
170+
self.core = "Cortex-M3"
171+
172+
self.extra_labels = ['NXP', 'LPC13XX']
173+
174+
self.supported_toolchains = ["ARM", "GCC_ARM"]
166175

167176
# Get a single instance for each target
168177
TARGETS = [
@@ -175,7 +184,8 @@ def __init__(self):
175184
LPC4088(),
176185
LPC4330_M4(),
177186
STM32F407(),
178-
MBED_MCU()
187+
MBED_MCU(),
188+
LPC1347()
179189
]
180190

181191
# Map each target name to its unique instance

0 commit comments

Comments
 (0)