Skip to content

Commit c4ebe63

Browse files
committed
Updated to mbed 5.9
1 parent 3d17ced commit c4ebe63

File tree

7 files changed

+88
-34
lines changed

7 files changed

+88
-34
lines changed

generators/mbed/MbedBSPGenerator.cs

+21-6
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private void LoadMCUDefinitionsFromOtherBSPs()
6565
}
6666
}
6767

68-
public void UpdateGitAndRescanTargets()
68+
public void UpdateGitAndRescanTargets(bool skipRescan = false)
6969
{
7070
string gitExe = (Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\BSPGenerators")?.GetValue("git") as string) ?? "git.exe";
7171
string pythonExe = (Registry.CurrentUser.OpenSubKey(@"Software\Sysprogs\BSPGenerators")?.GetValue("python") as string) ?? "python.exe";
@@ -127,6 +127,17 @@ public void UpdateGitAndRescanTargets()
127127
File.WriteAllLines(patchedFile, lines);
128128
}
129129

130+
patchedFile = Path.Combine(mbedRoot, @"tools\config\__init__.py");
131+
lines = File.ReadAllLines(patchedFile).ToList();
132+
str = "raise NotSupportedException(\"Target does not support mbed OS 5\")";
133+
idx2 = Enumerable.Range(0, lines.Count).FirstOrDefault(i => lines[i].Contains(str));
134+
if (idx2 > 0)
135+
{
136+
int subIdx = lines[idx2].IndexOf(str);
137+
lines[idx2] = lines[idx2].Substring(0, subIdx) + "print(\"library does not support mbed OS 5\")";
138+
File.WriteAllLines(patchedFile, lines);
139+
}
140+
130141
string sampleDir = Path.Combine(mbedRoot, "samples");
131142
if (Directory.Exists(sampleDir))
132143
Directory.Delete(sampleDir, true);
@@ -136,11 +147,15 @@ public void UpdateGitAndRescanTargets()
136147
bspGenInfo.UseShellExecute = false;
137148
bspGenInfo.EnvironmentVariables["PYTHONPATH"] = mbedRoot;
138149
bspGenInfo.EnvironmentVariables["PATH"] += $@";{toolchainDir}\bin";
139-
proc = Process.Start(bspGenInfo);
140-
proc.WaitForExit();
141150

142-
if (proc.ExitCode != 0)
143-
throw new Exception("BSP generator exited with code " + proc.ExitCode);
151+
if (!skipRescan)
152+
{
153+
proc = Process.Start(bspGenInfo);
154+
proc.WaitForExit();
155+
156+
if (proc.ExitCode != 0)
157+
throw new Exception("BSP generator exited with code " + proc.ExitCode);
158+
}
144159
}
145160

146161
public void PatchBuggyFiles()
@@ -352,7 +367,7 @@ public void DetectAndApplyMemorySizes(MCU mcu, string linkerScript)
352367

353368
mcu.MemoryMap = new AdvancedMemoryMap { Memories = memories };
354369
var flash = memories.FirstOrDefault(m => m.Name.ToUpper() == "FLASH" || m.Name == "m_text" || m.Name == "ROM" || m.Name == "rom" || m.Name == "MFlash256");
355-
var ram = memories.First(m => m.Name.ToUpper() == "RAM" || m.Name == "m_data" || m.Name == "RAM_INTERN" || m.Name == "SRAM1" || m.Name == "RAM0" || m.Name.StartsWith("Ram0_"));
370+
var ram = memories.First(m => m.Name.ToUpper() == "RAM" || m.Name == "m_data" || m.Name == "RAM_INTERN" || m.Name == "SRAM1" || m.Name == "RAM0" || m.Name.StartsWith("Ram0_") || m.Name.StartsWith("DSRAM_"));
356371

357372
if (flash == null)
358373
{

generators/mbed/ParsedTargetList.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ public struct RawConfigurationVariable
2020

2121
public bool IsFixed => string.IsNullOrEmpty(Description);
2222

23+
public bool IsUnsupported
24+
{
25+
get
26+
{
27+
if (IsBool != "True" && DefaultValue == "None")
28+
return true; //In mbed, setting the variable to 'none' completely removes the corresponding macro. VisualGDB can only replicate this for variables with a fixed list of options, that isn't the case for mbed.
29+
return false;
30+
}
31+
}
32+
2333
public override string ToString()
2434
{
2535
return ID;
@@ -60,14 +70,14 @@ public PropertyEntry ToPropertyEntry()
6070
int defaultIdx = Array.IndexOf(options, DefaultValue);
6171
if (defaultIdx < 0)
6272
throw new Exception("Default value is not a part of suggestion list");
63-
if (options.FirstOrDefault(s=>!IsValidIdentifier(s)) == null)
73+
if (options.FirstOrDefault(s => !IsValidIdentifier(s)) == null)
6474
{
6575
//All options are valid identifiers
6676
return new PropertyEntry.Enumerated
6777
{
6878
UniqueID = ID,
6979
Name = ID,
70-
SuggestionList = options.Select(s=>new PropertyEntry.Enumerated.Suggestion { InternalValue = s}).ToArray(),
80+
SuggestionList = options.Select(s => new PropertyEntry.Enumerated.Suggestion { InternalValue = s }).ToArray(),
7181
DefaultEntryIndex = defaultIdx
7282
};
7383
}
@@ -94,12 +104,13 @@ public string[] EffectivePreprocessorMacros
94104
{
95105
return NormalPreprocessorMacros
96106
.Concat(ConfigurationVariables.Where(c => c.IsFixed).Select(c => $"{c.MacroName}={c.DefaultValue}"))
97-
.Concat(ConfigurationVariables.Where(c => !c.IsFixed).Select(c => $"{c.MacroName}=$$com.sysprogs.mbed.{c.ID}$$"))
107+
.Concat(ConfigurationVariables.Where(c => !c.IsFixed && !c.IsUnsupported).Select(c => $"{c.MacroName}=$$com.sysprogs.mbed.{c.ID}$$"))
98108
.ToArray();
99109
}
100110
}
101111

102-
public PropertyEntry[] EffectiveConfigurableProperties => ConfigurationVariables.Where(c => !c.IsFixed).Select(c => c.ToPropertyEntry()).ToArray();
112+
113+
public PropertyEntry[] EffectiveConfigurableProperties => ConfigurationVariables.Where(c => !c.IsFixed && !c.IsUnsupported).Select(c => c.ToPropertyEntry()).ToArray();
103114

104115
static string[] SubtractOrThrow(string[] left, string[] right, bool throwIfBaseValuesAreNotPresent, string hint)
105116
{
@@ -150,6 +161,11 @@ public class DerivedConfiguration
150161

151162
public string CanonicalKey => Library != null ? "L:" + Library : "F:" + Feature;
152163

164+
public override string ToString()
165+
{
166+
return CanonicalKey;
167+
}
168+
153169
public BuildConfiguration Configuration;
154170

155171
public BuildConfiguration[] ConfigurationsToMerge;

generators/mbed/Program.cs

+16-7
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ public ConditionalConfigAggregator(ParsedTargetList.DerivedConfiguration cfg)
177177
}
178178

179179
public readonly string ID, Name;
180+
181+
public override string ToString()
182+
{
183+
return ID;
184+
}
180185
}
181186

182187
class PropertyComparerByID : IEqualityComparer<PropertyEntry>
@@ -194,10 +199,12 @@ public int GetHashCode(PropertyEntry obj)
194199

195200
static void Main(string[] args)
196201
{
197-
var generator = new MbedBSPGenerator("5.7.7");
202+
var generator = new MbedBSPGenerator("5.9");
203+
204+
bool skipRescan = args.Contains("/norescan");
198205

199206
string suffix = "";
200-
generator.UpdateGitAndRescanTargets();
207+
generator.UpdateGitAndRescanTargets(skipRescan);
201208

202209
ParsedTargetList parsedTargets = XmlTools.LoadObject<ParsedTargetList>(Path.Combine(generator.outputDir, "mbed", "ParsedTargets.xml"));
203210
generator.PatchBuggyFiles();
@@ -212,16 +219,18 @@ static void Main(string[] args)
212219
BSPSourceFolderName = "mbed Files"
213220
};
214221

222+
var validTargets = parsedTargets.Targets.Where(t => t.BaseConfiguration != null).ToArray();
223+
215224
MCUFamily commonFamily = new MCUFamily
216225
{
217226
ID = "MBED_CORE",
218-
AdditionalSourceFiles = generator.ConvertPaths(Intersect(parsedTargets.Targets.Select(t => t.BaseConfiguration.SourceFiles))),
219-
AdditionalHeaderFiles = generator.ConvertPaths(Intersect(parsedTargets.Targets.Select(t => t.BaseConfiguration.HeaderFiles))),
227+
AdditionalSourceFiles = generator.ConvertPaths(Intersect(validTargets.Select(t => t.BaseConfiguration.SourceFiles))),
228+
AdditionalHeaderFiles = generator.ConvertPaths(Intersect(validTargets.Select(t => t.BaseConfiguration.HeaderFiles))),
220229
SymbolsRequiredByLinkerScript = new[] { "__Vectors", "Stack_Size" },
221230
CompilationFlags = new ToolFlags
222231
{
223-
IncludeDirectories = generator.ConvertPaths(Intersect(parsedTargets.Targets.Select(t => t.BaseConfiguration.IncludeDirectories))),
224-
PreprocessorMacros = Intersect(parsedTargets.Targets.Select(t => t.BaseConfiguration.EffectivePreprocessorMacros))
232+
IncludeDirectories = generator.ConvertPaths(Intersect(validTargets.Select(t => t.BaseConfiguration.IncludeDirectories))),
233+
PreprocessorMacros = Intersect(validTargets.Select(t => t.BaseConfiguration.EffectivePreprocessorMacros))
225234
}
226235
};
227236

@@ -232,7 +241,7 @@ static void Main(string[] args)
232241

233242
Console.WriteLine("Generating target definitions...");
234243

235-
foreach (var target in parsedTargets.Targets)
244+
foreach (var target in validTargets)
236245
{
237246
if (string.IsNullOrEmpty(target.BaseConfiguration.LinkerScript))
238247
{

generators/mbed/data/BuildConfigExtractor.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from tools.settings import ROOT
2525
import bootloader_scanner
2626
from tools.targets import TARGET_NAMES, TARGET_MAP
27+
from tools.utils import NotSupportedException
2728
import re;
2829

2930

@@ -114,7 +115,8 @@ def main():
114115
'fat': "FAT File System support",
115116
'eth': "Ethernet support",
116117
'rtx': "Keil RTX RTOS",
117-
'features': 'Device features'
118+
'features': 'Device features',
119+
'mbedtls' : 'TLS Support (mbedtls)'
118120
}
119121

120122
print("Parsing targets...")
@@ -123,7 +125,7 @@ def main():
123125
copy._deepcopy_dispatch[type(re.compile('x'))] = copy_regex
124126

125127
#IPV6 is configured, but not listed as supported.Ignore it.
126-
supported_targets = [t for t in supported_targets if "Super_Target" not in t]
128+
supported_targets = [t for t in supported_targets if t not in ("Super_Target", "VBLUNO51_OTA", "VBLUNO51_BOOT", "VBLUNO51_LEGACY", "VBLUNO51")]
127129

128130
rootNode = ElementTree.Element('ParsedTargetList')
129131
targetListNode = append_node(rootNode, 'Targets')
@@ -135,7 +137,11 @@ def main():
135137
targetNode = append_node(targetListNode, 'Target')
136138
targetNode.append(make_node('ID', target))
137139

138-
toolchain = ba.prepare_toolchain([ROOT], "", target, 'GCC_ARM', silent=True)
140+
try:
141+
toolchain = ba.prepare_toolchain([ROOT], "", target, 'GCC_ARM')
142+
except NotSupportedException:
143+
print(t + " is not supported!")
144+
continue
139145

140146
fullRes = toolchain.scan_resources(ROOT)
141147
fullRes.toolchain = toolchain
@@ -171,7 +177,7 @@ def main():
171177
libCfg = BuildConfiguration(libToolchain, libRes)
172178
libNode.append(libCfg.ToXML('Configuration'))
173179

174-
for feature in copy.copy(fullRes.features):
180+
for feature in list(fullRes.features):
175181
featureNode = append_node(derivedCfgListNode, 'DerivedConfiguration')
176182
featureNode.append(make_node('Feature', feature))
177183

@@ -181,9 +187,10 @@ def main():
181187
featureCfg = BuildConfiguration(featureToolchain, featureRes)
182188
featureNode.append(featureCfg.ToXML('Configuration'))
183189

184-
for lib in LIBRARIES:
190+
for lib in LIBRARIES + [{"id" : "mbedtls", "source_dir" : ROOT + "/features/mbedtls"}]:
185191
if lib['id'] in ['rtos' ,'rtx']:
186192
continue #Already handled via mbed_library_dirs
193+
187194
sourceDirs = lib['source_dir']
188195
if isinstance(sourceDirs, str):
189196
sourceDirs = [sourceDirs]

generators/mbed/data/samples/04_BLE_UART/USB_CDC.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
#define DEBUG(...) /* nothing */
3636
#endif /* #if NEED_CONSOLE_OUTPUT */
3737

38-
BLEDevice ble;
38+
BLEDevice g_BLE;
3939
DigitalOut led1(LED1);
4040
UARTService *uart;
4141

4242
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
4343
{
4444
DEBUG("Disconnected!\n\r");
4545
DEBUG("Restarting the advertising process\n\r");
46-
ble.startAdvertising();
46+
g_BLE.startAdvertising();
4747
}
4848

4949
void periodicCallback(void)
@@ -59,26 +59,26 @@ int main(void)
5959
ticker.attach(periodicCallback, 1);
6060

6161
DEBUG("Initialising the nRF51822\n\r");
62-
ble.init();
63-
ble.onDisconnection(disconnectionCallback);
62+
g_BLE.init();
63+
g_BLE.onDisconnection(disconnectionCallback);
6464

65-
uart = new UARTService(ble);
65+
uart = new UARTService(g_BLE);
6666

6767
/* setup advertising */
68-
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
69-
ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
70-
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
68+
g_BLE.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
69+
g_BLE.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
70+
g_BLE.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
7171
(const uint8_t *)"BLE UART",
7272
sizeof("BLE UART") - 1);
73-
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
73+
g_BLE.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
7474
(const uint8_t *)UARTServiceUUID_reversed,
7575
sizeof(UARTServiceUUID_reversed));
7676

77-
ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
78-
ble.startAdvertising();
77+
g_BLE.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
78+
g_BLE.startAdvertising();
7979

8080
while (true) {
81-
ble.waitForEvent();
81+
g_BLE.waitForEvent();
8282
}
8383
}
8484

generators/mbed/data/samples/04_BLE_UART/sample.xml

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<RequiredFrameworks>
99
<string>com.sysprogs.arm.mbed.drivers</string>
1010
<string>com.sysprogs.arm.mbed.feature.BLE</string>
11+
<string>com.sysprogs.arm.mbed.mbedtls</string>
1112
</RequiredFrameworks>
1213
</EmbeddedProjectSample>

generators/mbed/data/stubs.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ extern "C"
1414
{
1515
return 0;
1616
}
17+
18+
//Only needed for nRF5x-based targets. Will get overridden once the BLE-related frameworks are added.
19+
void __attribute__((weak)) assert_nrf_callback(unsigned short line_num, const unsigned char *p_file_name)
20+
{
21+
asm("bkpt 255");
22+
}
1723
}

0 commit comments

Comments
 (0)