static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: risc-v.exe <freedom-e-sdk directory>"); } var bspBuilder = new RISCVBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); PathTools.CopyDirectoryRecursive(@"..\..\bsp-template", bspBuilder.Directories.OutputDir); var bsp = XmlTools.LoadObject <BoardSupportPackage>(Path.Combine(bspBuilder.BSPRoot, "bsp.xml")); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); List <string> projectFiles = new List <string>(); PropertyList unused = null; if (commonPseudofamily.Definition.CoreFramework != null) { foreach (var job in commonPseudofamily.Definition.CoreFramework.CopyJobs) { job.CopyAndBuildFlags(bspBuilder, projectFiles, null, ref unused); } } List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(bsp.Frameworks); frameworks.AddRange(commonPseudofamily.GenerateFrameworkDefinitions()); bsp.Frameworks = frameworks.ToArray(); var samples = commonPseudofamily.CopySamples(frameworks).ToArray(); bsp.Examples = samples.Select(s => s.RelativePath).ToArray(); var mainFamily = bsp.MCUFamilies.First(); if (mainFamily.AdditionalSourceFiles != null || mainFamily.AdditionalHeaderFiles != null || bsp.FileConditions != null) { throw new Exception("TODO: merge lists"); } mainFamily.AdditionalSourceFiles = projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray(); mainFamily.AdditionalHeaderFiles = projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray(); bsp.FileConditions = bspBuilder.MatchedFileConditions.ToArray(); XmlTools.SaveObject(bsp, Path.Combine(bspBuilder.BSPRoot, "BSP.XML")); }
//=========================================================== static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: InfineonXMC.exe <InfineonXMC SW package directory>"); } using (var bspBuilder = new InfineonXMCBSPBuilder(BSPDirectories.MakeDefault(args))) { var devices = BSPGeneratorTools.ReadMCUDevicesFromCommaDelimitedCSVFile(bspBuilder.Directories.RulesDir + @"\McuInfineonDevices.csv", "Product", "Program Memory(KB) ", "SRAM (KB) ", "CORE", true); devices = UpdateListMCU(devices); List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) { allFamilies.Add(new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(fn))); } var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allFamilies); if (rejects.Count > 0) { throw new Exception($"Found {rejects.Count} MCUs not assigned to any family"); } List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <string> exampleDirs = new List <string>(); bool noPeripheralRegisters = args.Contains("/noperiph"); List <KeyValuePair <string, string> > macroToHeaderMap = new List <KeyValuePair <string, string> >(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); foreach (var sample in commonPseudofamily.CopySamples()) { exampleDirs.Add(sample.RelativePath); } foreach (var fam in allFamilies) { var rejectedMCUs = fam.RemoveUnsupportedMCUs(); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } fam.AttachStartupFiles(ParseStartupFiles(fam.Definition.StartupFileDir)); if (!noPeripheralRegisters) { fam.AttachPeripheralRegisters(new MCUDefinitionWithPredicate[] { SVDParser.ParseSVDFile(Path.Combine(fam.Definition.PrimaryHeaderDir, @"CMSIS\Infineon\SVD\" + fam.Definition.Name + ".svd"), fam.Definition.Name) }); } var famObj = fam.GenerateFamilyObject(true); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); famObj.CompilationFlags.PreprocessorMacros = LoadedBSP.Combine(famObj.CompilationFlags.PreprocessorMacros, new string[] { "$$com.sysprogs.bspoptions.primary_memory$$_layout" }); familyDefinitions.Add(famObj); fam.GenerateLinkerScripts(false); foreach (var mcu in fam.MCUs) { mcuDefinitions.Add(mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters)); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in fam.CopySamples()) { exampleDirs.Add(sample.RelativePath); } } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = "com.sysprogs.arm.infineon.xmc", PackageDescription = "Infineon XMC Devices", GNUTargetID = "arm-eabi", GeneratedMakFileName = "infineon_xmc.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.ToArray(), FileConditions = bspBuilder.MatchedFileConditions.Values.ToArray(), PackageVersion = "2.1.24R2" }; bspBuilder.Save(bsp, true); } }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: msp432_bsp_generator.exe <MSP432 SW package directory>"); } var bspBuilder = new Msp432Builder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); var devices = BSPGeneratorTools.ReadMCUDevicesFromCommaDelimitedCSVFile( bspBuilder.Directories.RulesDir + @"\msp432devices.csv", "Part Number", "Non-volatile Memory (KB)", "RAM(KB)", "CPU", true); var allMCUFamilyBuilders = new List <MCUFamilyBuilder>(); foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) { allMCUFamilyBuilders.Add(new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(fn))); } var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allMCUFamilyBuilders); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); var flags = new ToolFlags(); var projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); var exampleDirs = new List <string>(); foreach (var sample in commonPseudofamily.CopySamples()) { exampleDirs.Add(sample); } bool noPeripheralRegisters = args.Contains("/noperiph"); var familyDefinitions = new List <MCUFamily>(); var mcuDefinitions = new List <MCU>(); var frameworks = new List <EmbeddedFramework>(); foreach (var mcuFamilyBuilder in allMCUFamilyBuilders) { var rejectedMCUs = mcuFamilyBuilder.RemoveUnsupportedMCUs(true); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", mcuFamilyBuilder.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } mcuFamilyBuilder.AttachStartupFiles(new[] { StartupFilesParser.Parse( mcuFamilyBuilder.Definition.Name, mcuFamilyBuilder.Definition.PrimaryHeaderDir, mcuFamilyBuilder.Definition.Name + "_startup_gcc.c") }); if (!noPeripheralRegisters) { var headerFiles = Directory.GetFiles(mcuFamilyBuilder.Definition.PrimaryHeaderDir + "\\inc", "*.h"); var headerFileRegex = new Regex(mcuFamilyBuilder.Definition.DeviceRegex, RegexOptions.IgnoreCase); var familyHeaderFiles = headerFiles.Where(headerFile => headerFileRegex.Match(headerFile.Substring(headerFile.LastIndexOf("\\") + 1)).Success).ToArray(); if (familyHeaderFiles.Length == 0) { throw new Exception("No header file found for MCU family"); } else if (familyHeaderFiles.Length > 1) { throw new Exception("Only one header file expected for MCU family"); } var registersParser = new RegistersParser(familyHeaderFiles[0]); mcuFamilyBuilder.AttachPeripheralRegisters(new[] { new MCUDefinitionWithPredicate { MCUName = mcuFamilyBuilder.Definition.Name, RegisterSets = registersParser.Parse(), MatchPredicate = m => true } }); } var familyObject = mcuFamilyBuilder.GenerateFamilyObject(true); familyObject.AdditionalSourceFiles = LoadedBSP.Combine(familyObject.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); familyObject.AdditionalHeaderFiles = LoadedBSP.Combine(familyObject.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); familyObject.AdditionalSystemVars = LoadedBSP.Combine(familyObject.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); familyObject.CompilationFlags = familyObject.CompilationFlags.Merge(flags); familyDefinitions.Add(familyObject); mcuFamilyBuilder.GenerateLinkerScripts(false); foreach (var mcu in mcuFamilyBuilder.MCUs) { mcuDefinitions.Add(mcu.GenerateDefinition(mcuFamilyBuilder, bspBuilder, !noPeripheralRegisters)); } foreach (var fw in mcuFamilyBuilder.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in mcuFamilyBuilder.CopySamples()) { exampleDirs.Add(sample); } } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = "com.sysprogs.arm.ti.msp432", PackageDescription = "TI MSP432 Devices", GNUTargetID = "arm-eabi", GeneratedMakFileName = "msp432.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.ToArray(), PackageVersion = "1.0" }; bspBuilder.Save(bsp, true); }
static void Main(string[] args) { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; if (args.Length < 2) { throw new Exception("Usage: TestFrameworkGenerator <Rules subdir> <Source directory>"); } var dummyBSPBuilder = new DummyBSPBuilder(new BSPDirectories(args[1], @"..\..\Output\" + args[0], @"..\..\rules\" + args[0])); if (Directory.Exists(dummyBSPBuilder.Directories.OutputDir)) { Directory.Delete(dummyBSPBuilder.Directories.OutputDir, true); } Directory.CreateDirectory(dummyBSPBuilder.Directories.OutputDir); var fwObj = XmlTools.LoadObject <TestFrameworkDefinition>(Path.Combine(dummyBSPBuilder.Directories.RulesDir, "TestFramework.xml")); dummyBSPBuilder.FrameworkID = fwObj.ID; var rules = XmlTools.LoadObject <TestFrameworkRules>(Path.Combine(dummyBSPBuilder.Directories.RulesDir, "rules.xml")); List <string> projectFiles = new List <string>(); ToolFlags flags = new ToolFlags(); if (fwObj.Common == null) { fwObj.Common = new TestFrameworkDefinition.TestPlatformBuild(); } foreach (var job in rules.CopyJobs) { flags = flags.Merge(job.CopyAndBuildFlags(dummyBSPBuilder, projectFiles, null, ref fwObj.Common.ConfigurableProperties, null)); } Dictionary <string, FileCondition> matchedConditions = new Dictionary <string, FileCondition>(StringComparer.InvariantCultureIgnoreCase); foreach (var cond in dummyBSPBuilder.MatchedFileConditions) { matchedConditions[cond.FilePath] = cond; } var platformIndepenentFiles = projectFiles.Where(f => !matchedConditions.ContainsKey(f)).ToList(); List <string> embeddedFiles = new List <string>(); List <string> linuxFiles = new List <string>(); foreach (var f in projectFiles) { FileCondition cond; if (matchedConditions.TryGetValue(f, out cond)) { var eq = (cond.ConditionToInclude as Condition.Equals); if (eq?.Expression == "$$platform$$") { dummyBSPBuilder.MatchedFileConditions.Remove(cond); switch (eq.ExpectedValue) { case "embedded": embeddedFiles.Add(f); break; case "linux": linuxFiles.Add(f); break; default: throw new Exception("Invalid platform condition"); } } else if (!platformIndepenentFiles.Contains(f)) { platformIndepenentFiles.Add(f); } } } fwObj.Common.AdditionalSourceFiles = platformIndepenentFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).Select(f => dummyBSPBuilder.MakeRelativePath(f)).ToArray(); fwObj.Common.AdditionalHeaderFiles = platformIndepenentFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).Select(f => dummyBSPBuilder.MakeRelativePath(f)).ToArray(); fwObj.Common.AdditionalIncludeDirs = flags.IncludeDirectories?.Select(f => dummyBSPBuilder.MakeRelativePath(f))?.ToArray(); fwObj.Common.AdditionalPreprocessorMacros = flags.PreprocessorMacros?.Select(f => dummyBSPBuilder.MakeRelativePath(f))?.ToArray(); if (fwObj.Embedded != null) { fwObj.Embedded.AdditionalSourceFiles = embeddedFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).Select(f => dummyBSPBuilder.MakeRelativePath(f)).ToArray(); fwObj.Embedded.AdditionalHeaderFiles = embeddedFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).Select(f => dummyBSPBuilder.MakeRelativePath(f)).ToArray(); fwObj.Embedded.AdditionalIncludeDirs = fwObj.Embedded.AdditionalIncludeDirs?.Select(f => dummyBSPBuilder.MakeRelativePath(f))?.ToArray(); } if (fwObj.Linux != null) { fwObj.Linux.AdditionalSourceFiles = linuxFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).Select(f => dummyBSPBuilder.MakeRelativePath(f)).ToArray(); fwObj.Linux.AdditionalHeaderFiles = linuxFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).Select(f => dummyBSPBuilder.MakeRelativePath(f)).ToArray(); fwObj.Linux.AdditionalIncludeDirs = fwObj.Linux.AdditionalIncludeDirs?.Select(f => dummyBSPBuilder.MakeRelativePath(f))?.ToArray(); } foreach (var cond in dummyBSPBuilder.MatchedFileConditions) { cond.FilePath = dummyBSPBuilder.MakeRelativePath(cond.FilePath); //Substitute $$SYS:BSP_ROOT$$ with $$SYS:TESTFW_BASE$$/... } fwObj.FileConditions = dummyBSPBuilder.MatchedFileConditions.ToArray(); CopyAndAdjustSamples(dummyBSPBuilder, fwObj.Embedded.Samples); CopyAndAdjustSamples(dummyBSPBuilder, fwObj.Common.Samples); XmlTools.SaveObject(fwObj, Path.Combine(dummyBSPBuilder.Directories.OutputDir, "TestFramework.xml")); string outDir = dummyBSPBuilder.Directories.OutputDir; string archiveName = $"{fwObj.ID.Split('.').Last()}-{fwObj.Version}.vgdbxtfp"; Console.WriteLine("Building archive..."); string archiveFile = Path.Combine(dummyBSPBuilder.Directories.OutputDir, archiveName); TarPacker.PackDirectoryToTGZ(outDir, archiveFile, fn => Path.GetExtension(fn).ToLower() != ".vgdbxtfp"); }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: nrf5x.exe <Nordic SW package directory>"); } bool usingIoTSDK = false; /* if (Directory.Exists(Path.Combine(args[0], @"components\iot\ble_6lowpan"))) * { * usingIoTSDK = true; * Console.WriteLine("Detected IoT SDK"); * }*/ if (usingIoTSDK) { bspBuilder = new NordicBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules_iot")); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("s1xx_iot", 0x1f000, 0x2800, "nrf52", "IoT", bspBuilder.Directories.InputDir)); } else { bspBuilder = new NordicBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S132", "nrf52832.*", null, bspBuilder.Directories.InputDir)); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S140", "nrf52840.*", null, bspBuilder.Directories.InputDir)); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S112", "nrf52810.*", null, bspBuilder.Directories.InputDir)); } List <MCUBuilder> devices = new List <MCUBuilder>(); #if NRF51_SUPPORT if (!usingIoTSDK) { foreach (string part in new string[] { "nRF51822", "nRF51422" }) { devices.Add(new MCUBuilder { Name = part + "_XXAA", FlashSize = 256 * 1024, RAMSize = 16 * 1024, Core = CortexCore.M0 }); devices.Add(new MCUBuilder { Name = part + "_XXAB", FlashSize = 128 * 1024, RAMSize = 16 * 1024, Core = CortexCore.M0 }); devices.Add(new MCUBuilder { Name = part + "_XXAC", FlashSize = 256 * 1024, RAMSize = 32 * 1024, Core = CortexCore.M0 }); } } #endif devices.Add(new MCUBuilder { Name = "nRF52832_XXAA", FlashSize = 512 * 1024, RAMSize = 64 * 1024, Core = CortexCore.M4, StartupFile = "$$SYS:BSP_ROOT$$/nRF5x/components/toolchain/gcc/gcc_startup_nrf52.S" }); devices.Add(new MCUBuilder { Name = "nRF52840_XXAA", FlashSize = 1024 * 1024, RAMSize = 256 * 1024, Core = CortexCore.M4, StartupFile = "$$SYS:BSP_ROOT$$/nRF5x/components/toolchain/gcc/gcc_startup_nrf52840.S" }); devices.Add(new MCUBuilder { Name = "nRF52810_XXAA", FlashSize = 192 * 1024, RAMSize = 24 * 1024, Core = CortexCore.M4_NOFPU, StartupFile = "$$SYS:BSP_ROOT$$/nRF5x/components/toolchain/gcc/gcc_startup_nrf52810.S" }); List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) { allFamilies.Add(new NordicFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(fn))); } var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allFamilies); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <MCUFamilyBuilder.CopiedSample> exampleDirs = new List <MCUFamilyBuilder.CopiedSample>(); bool noPeripheralRegisters = true; List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); flags = flags.Merge(commonPseudofamily.Definition.CompilationFlags); List <ConditionalToolFlags> condFlags = new List <ConditionalToolFlags>(); foreach (var fam in allFamilies) { fam.GenerateLinkerScripts(false); Console.WriteLine("Processing " + fam.Definition.Name + " family..."); string famBase = fam.Definition.Name.Substring(0, 5).ToLower(); var rejectedMCUs = fam.RemoveUnsupportedMCUs(true); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } List <Framework> bleFrameworks = new List <Framework>(); foreach (var line in File.ReadAllLines(bspBuilder.Directories.RulesDir + @"\BLEFrameworks.txt")) { int idx = line.IndexOf('|'); string dir = line.Substring(0, idx); string desc = line.Substring(idx + 1); string id = Path.GetFileName(dir); if (!id.StartsWith("ble_")) { id = "ble_" + id; } if (dir.StartsWith("services\\", StringComparison.CurrentCultureIgnoreCase)) { id = "ble_svc_" + id.Substring(4); } bleFrameworks.Add(new Framework { Name = string.Format("Bluetooth LE - {0} ({1})", desc, Path.GetFileName(dir)), ID = "com.sysprogs.arm.nordic." + famBase + "." + id, ClassID = "com.sysprogs.arm.nordic.nrfx." + id, ProjectFolderName = "BLE " + desc, DefaultEnabled = false, CopyJobs = new CopyJob[] { new CopyJob { SourceFolder = allFamilies[0].Definition.PrimaryHeaderDir + @"\..\components\ble\" + dir, TargetFolder = dir, FilesToCopy = "*.c;*.h", } } }); } fam.Definition.AdditionalFrameworks = fam.Definition.AdditionalFrameworks.Concat(bleFrameworks).ToArray(); // Starting from SDK 14.0 we use the original Nordic startup files & linker scripts as they contain various non-trivial logic #if GENERATE_STARTUP_FILES StartupFileGenerator.InterruptVectorTable[] aStartupVectors; if (usingIoTSDK) { aStartupVectors = new StartupFileGenerator.InterruptVectorTable[] { GenerateStartupFile(fam.Definition.StartupFileDir, "nRF52") } } ; else { aStartupVectors = new StartupFileGenerator.InterruptVectorTable[] { GenerateStartupFile(fam.Definition.StartupFileDir, "nRF51"), GenerateStartupFile(fam.Definition.StartupFileDir, "nRF52") } }; fam.AttachStartupFiles(aStartupVectors); #endif // SVD Files var aMcuDef1 = (new MCUDefinitionWithPredicate[] { SVDParser.ParseSVDFile(Path.Combine(fam.Definition.PrimaryHeaderDir, "nRF51.svd"), "nRF51") }); aMcuDef1[0].MatchPredicate = m => m.Name.StartsWith("nRF51"); var aMcuDef2 = (new MCUDefinitionWithPredicate[] { SVDParser.ParseSVDFile(Path.Combine(fam.Definition.PrimaryHeaderDir, "nRF52.svd"), "nRF52") }); aMcuDef2[0].MatchPredicate = m => m.Name.StartsWith("nRF52"); fam.AttachPeripheralRegisters(aMcuDef1.Concat(aMcuDef2)); var famObj = fam.GenerateFamilyObject(true); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); familyDefinitions.Add(famObj); fam.GenerateLinkerScripts(false); SysVarEntry suffixEntry = null; foreach (var mcu in fam.MCUs) { var mcuDef = mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters, false, MCUFamilyBuilder.CoreSpecificFlags.All & ~MCUFamilyBuilder.CoreSpecificFlags.PrimaryMemory); if (mcu.Name.StartsWith("nRF52832")) { //Although documented as a legacy definition, skipping this breaks fds_internal_defs.h mcuDef.CompilationFlags.PreprocessorMacros = mcuDef.CompilationFlags.PreprocessorMacros.Concat(new[] { "NRF52" }).ToArray(); } var compatibleSoftdevs = new[] { new PropertyEntry.Enumerated.Suggestion { InternalValue = "nosoftdev", UserFriendlyName = "None" } } .Concat(bspBuilder.SoftDevices.Where(sd => sd.IsCompatible(mcu.Name)) .SelectMany(s => new[] { new PropertyEntry.Enumerated.Suggestion { InternalValue = s.Name, UserFriendlyName = s.UserFriendlyName }, new PropertyEntry.Enumerated.Suggestion { InternalValue = s.Name + "_reserve", UserFriendlyName = $"{s.UserFriendlyName} (programmed separately)" } })) .ToArray(); if (mcuDef.ConfigurableProperties == null) { mcuDef.ConfigurableProperties = new PropertyList { PropertyGroups = new List <PropertyGroup>() } } ; mcuDef.ConfigurableProperties.PropertyGroups.Add(new PropertyGroup { Properties = new List <PropertyEntry> { new PropertyEntry.Enumerated { UniqueID = NordicBSPBuilder.SoftdevicePropertyID, Name = "Softdevice", DefaultEntryIndex = 1, SuggestionList = compatibleSoftdevs, } } }); if (mcu.Name.StartsWith("nRF52") && !mcu.Name.StartsWith("nRF52810")) { var prop = mcuDef.ConfigurableProperties.PropertyGroups[0].Properties.Find(p => p.UniqueID == "com.sysprogs.bspoptions.arm.floatmode") as PropertyEntry.Enumerated; var idx = Array.FindIndex(prop.SuggestionList, p => p.UserFriendlyName == "Hardware"); prop.DefaultEntryIndex = idx; prop.SuggestionList[idx].UserFriendlyName = "Hardware (required when using a softdevice)"; //Otherwise the system_nrf52.c file won't initialize the FPU and the internal initialization of the softdevice will later fail. } string defaultConfig; if (mcu.Name.StartsWith("nRF52840")) { defaultConfig = "pca10056/s140"; } else if (mcu.Name.StartsWith("nRF52810")) { defaultConfig = "pca10040e/s112"; } else { defaultConfig = "pca10040/s132"; } suffixEntry = new SysVarEntry { Key = "com.sysprogs.nordic.default_config_suffix", Value = defaultConfig }; mcuDef.AdditionalSystemVars = LoadedBSP.Combine(mcuDef.AdditionalSystemVars, new SysVarEntry[] { suffixEntry }); mcuDefinitions.Add(mcuDef); } if (fam.Definition.ConditionalFlags != null) { condFlags.AddRange(fam.Definition.ConditionalFlags); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in fam.CopySamples(null, new SysVarEntry[] { new SysVarEntry { Key = "com.sysprogs.nordic.default_config_suffix", Value = "pca10040e/s112" } })) { exampleDirs.Add(sample); } } const string softdevExpression = "$$com.sysprogs.bspoptions.nrf5x.softdevice$$"; foreach (var softdev in bspBuilder.SoftDevices) { condFlags.Add(new ConditionalToolFlags { FlagCondition = new Condition.Equals { Expression = softdevExpression, ExpectedValue = softdev.Name + "_reserve" }, Flags = new ToolFlags { PreprocessorMacros = familyDefinitions.First().CompilationFlags.PreprocessorMacros.Where(f => f.Contains(softdevExpression)).Select(f => f.Replace(softdevExpression, softdev.Name)).ToArray(), IncludeDirectories = familyDefinitions.First().CompilationFlags.IncludeDirectories.Where(f => f.Contains(softdevExpression)).Select(f => f.Replace(softdevExpression, softdev.Name)).ToArray() } }); } bspBuilder.GenerateSoftdeviceLibraries(); Console.WriteLine("Building BSP archive..."); string strPackageID, strPackageDesc, strPAckVersion; if (usingIoTSDK) { strPackageID = "com.sysprogs.arm.nordic.nrf5x-iot"; strPackageDesc = "Nordic NRF52 IoT"; strPAckVersion = "0.9"; foreach (var mcu in mcuDefinitions) { mcu.UserFriendlyName = mcu.ID + " (IoT)"; } } else { strPackageID = "com.sysprogs.arm.nordic.nrf5x"; strPackageDesc = "Nordic NRF52x Devices"; strPAckVersion = "14.2R2"; } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = strPackageID, PackageDescription = strPackageDesc, GNUTargetID = "arm-eabi", GeneratedMakFileName = "nrf5x.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.Where(s => !s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), TestExamples = exampleDirs.Where(s => s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), PackageVersion = strPAckVersion, FileConditions = bspBuilder.MatchedFileConditions.ToArray(), MinimumEngineVersion = "5.0", ConditionalFlags = condFlags.ToArray(), InitializationCodeInsertionPoints = commonPseudofamily.Definition.InitializationCodeInsertionPoints, }; bspBuilder.Save(bsp, true, false); } }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: tiva.exe <Tiva SW package directory>"); } var bspBuilder = new TivaBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); var devices = BSPGeneratorTools.ReadMCUDevicesFromCommaDelimitedCSVFile(bspBuilder.Directories.RulesDir + @"\Tivadevices.csv", "Part Number", "Flash (KB)", "SRAM(kB)", "CPU", true); List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) { allFamilies.Add(new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(fn))); } var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allFamilies); List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <MCUFamilyBuilder.CopiedSample> exampleDirs = new List <MCUFamilyBuilder.CopiedSample>(); bool noPeripheralRegisters = args.Contains("/noperiph"); List <KeyValuePair <string, string> > macroToHeaderMap = new List <KeyValuePair <string, string> >(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); foreach (var sample in commonPseudofamily.CopySamples()) { exampleDirs.Add(sample); } foreach (var fam in allFamilies) { var rejectedMCUs = fam.RemoveUnsupportedMCUs(true); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } foreach (var mcu in fam.MCUs) { string fn = string.Format("{0}\\inc\\{1}.h", fam.Definition.PrimaryHeaderDir, mcu.Name); if (!File.Exists(fn)) { throw new Exception("Missing device header file"); } macroToHeaderMap.Add(new KeyValuePair <string, string>(mcu.Name, mcu.Name.ToLower() + ".h")); } fam.AttachStartupFiles(ParseStartupFiles(fam.Definition.PrimaryHeaderDir, "startup_gcc.c", fam)); if (!noPeripheralRegisters) { fam.AttachPeripheralRegisters(ParsePeripheralRegisters(fam.Definition.PrimaryHeaderDir)); } var famObj = fam.GenerateFamilyObject(true); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); familyDefinitions.Add(famObj); fam.GenerateLinkerScripts(false); foreach (var mcu in fam.MCUs) { mcuDefinitions.Add(mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters)); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in fam.CopySamples()) { exampleDirs.Add(sample); } } using (var sw = File.CreateText(Path.Combine(bspBuilder.BSPRoot, "SDK", "inc", "tiva_device.h"))) { sw.WriteLine("#pragma once"); sw.WriteLine(); bool first = true; foreach (var kv in macroToHeaderMap) { sw.WriteLine("#{0}if defined({1})", first ? "" : "el", kv.Key); sw.WriteLine("\t#include \"{0}\"", kv.Value); first = false; } sw.WriteLine("#else"); sw.WriteLine("#error Device type not specified"); sw.WriteLine("#endif"); } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = "com.sysprogs.arm.ti.tiva", PackageDescription = "TI Tiva Devices", GNUTargetID = "arm-eabi", GeneratedMakFileName = "tiva.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.Where(s => !s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), TestExamples = exampleDirs.Where(s => s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), PackageVersion = "2.1.4.178" }; bspBuilder.Save(bsp, true); }
//---------------------------------------------- static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: EFM32.exe <Atmel SW package directory>"); } var bspBuilder = new AtmelBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); var devices = BSPGeneratorTools.ReadMCUDevicesFromCommaDelimitedCSVFile(bspBuilder.Directories.RulesDir + @"\McuAtmel.csv", "Device Name", "Flash (kBytes)", "SRAM (kBytes)", "CPU", true); RemoveDuplicateMCU(ref devices); List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) { allFamilies.Add(new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(fn))); } var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allFamilies); List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <MCUFamilyBuilder.CopiedSample> exampleDirs = new List <MCUFamilyBuilder.CopiedSample>(); CopyAddSourceFiles(bspBuilder.Directories.InputDir); bool noPeripheralRegisters = args.Contains("/noperiph"); List <KeyValuePair <string, string> > macroToHeaderMap = new List <KeyValuePair <string, string> >(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); //Embedded Frameworks var AddFrW = GenereteAddFrameWorks(bspBuilder.Directories, "ServicesFrimwork.txt"); commonPseudofamily.Definition.AdditionalFrameworks = commonPseudofamily.Definition.AdditionalFrameworks.Concat(AddFrW).ToArray(); AddFrW = GenereteAddFrameWorksDir(bspBuilder.Directories, "sam"); commonPseudofamily.Definition.AdditionalFrameworks = commonPseudofamily.Definition.AdditionalFrameworks.Concat(AddFrW).ToArray(); AddFrW = GenereteAddFrameWorksDir(bspBuilder.Directories, "sam0"); commonPseudofamily.Definition.AdditionalFrameworks = commonPseudofamily.Definition.AdditionalFrameworks.Concat(AddFrW).ToArray(); foreach (var fw in commonPseudofamily.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); foreach (var sample in commonPseudofamily.CopySamples()) { exampleDirs.Add(sample); } foreach (var fam in allFamilies) { var rejectedMCUs = fam.RemoveUnsupportedMCUs(true); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } fam.AttachStartupFiles(ParseStartupFiles(fam.Definition.StartupFileDir, fam)); var famObj = fam.GenerateFamilyObject(true); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); famObj.CompilationFlags.PreprocessorMacros = LoadedBSP.Combine(famObj.CompilationFlags.PreprocessorMacros, new string[] { "$$com.sysprogs.bspoptions.primary_memory$$_layout" }); familyDefinitions.Add(famObj); var memoryLayouts = fam.GenerateLinkerScripts(false); if (!noPeripheralRegisters) { fam.AttachPeripheralRegisters(ParsePeripheralRegisters(bspBuilder.Directories.OutputDir, fam)); } foreach (var mcu in fam.MCUs) { var mcuDef = mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters); var layout = memoryLayouts[mcu.Name]; var ram = layout.Memories.First(m => m.Type == MemoryType.RAM); var flash = layout.Memories.First(m => m.Type == MemoryType.FLASH); mcuDef.RAMBase = ram.Start; mcuDef.RAMSize = (int)ram.Size; mcuDef.FLASHBase = flash.Start; mcuDef.FLASHSize = (int)flash.Size; mcuDefinitions.Add(mcuDef); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in fam.CopySamples()) { exampleDirs.Add(sample); } } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = "com.sysprogs.arm.atmel.sam-cortex", PackageDescription = "Atmel ARM Cortex Devices", GNUTargetID = "arm-eabi", GeneratedMakFileName = "atmel.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.Where(s => !s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), TestExamples = exampleDirs.Where(s => s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), FileConditions = bspBuilder.MatchedFileConditions.ToArray(), PackageVersion = "3.35.2" }; bspBuilder.Save(bsp, true); }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: EFM32.exe <SLab SW package directory>"); } var bspBuilder = new SLabBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); var devices = BSPGeneratorTools.ReadMCUDevicesFromCommaDelimitedCSVFile(bspBuilder.Directories.RulesDir + @"\McuSiliconLabs.csv", "Part No.", "Flash (kB)", "Ram (kB)", "MCU Core", true); RemoveDuplicateMCU(ref devices); var devicesOld = BSPGeneratorTools.ReadMCUDevicesFromCommaDelimitedCSVFile(bspBuilder.Directories.RulesDir + @"\McuSiliconLabsOld.csv", "Part No.", "Flash (kB)", "Ram (kB)", "MCU Core", true); RemoveDuplicateMCU(ref devicesOld); foreach (var d in devicesOld) { if (!devices.Contains(d)) { devices.Add(d); } } if (devices.Where(d => d.RAMSize == 0 || d.FlashSize == 0).Count() > 0) { throw new Exception($"Some devices are RAM Size ({devices.Where(d => d.RAMSize == 0).Count()}) = 0 or FLASH Size({devices.Where(d => d.FlashSize == 0).Count()}) = 0 "); } List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) { allFamilies.Add(new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(fn))); } var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allFamilies); List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <MCUFamilyBuilder.CopiedSample> exampleDirs = new List <MCUFamilyBuilder.CopiedSample>(); bool noPeripheralRegisters = args.Contains("/noperiph"); List <KeyValuePair <string, string> > macroToHeaderMap = new List <KeyValuePair <string, string> >(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); foreach (var fw in commonPseudofamily.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); foreach (var sample in commonPseudofamily.CopySamples()) { exampleDirs.Add(sample); } foreach (var fam in allFamilies) { var rejectedMCUs = fam.RemoveUnsupportedMCUs(true); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } fam.AttachStartupFiles(ParseStartupFiles(fam.Definition.StartupFileDir, fam)); var famObj = fam.GenerateFamilyObject(true); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); famObj.CompilationFlags.PreprocessorMacros = LoadedBSP.Combine(famObj.CompilationFlags.PreprocessorMacros, new string[] { "$$com.sysprogs.bspoptions.primary_memory$$_layout" }); familyDefinitions.Add(famObj); fam.GenerateLinkerScripts(false); if (!noPeripheralRegisters) { fam.AttachPeripheralRegisters(ParsePeripheralRegisters(bspBuilder.Directories.OutputDir + "\\" + fam.Definition.FamilySubdirectory + "\\Devices", fam)); } foreach (var mcu in fam.MCUs) { mcuDefinitions.Add(mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters)); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in fam.CopySamples()) { exampleDirs.Add(sample); } } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = "com.sysprogs.arm.silabs.efm32", PackageDescription = "Silabs EFM32 Devices", GNUTargetID = "arm-eabi", GeneratedMakFileName = "efm32.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.Where(s => !s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), TestExamples = exampleDirs.Where(s => s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), FileConditions = bspBuilder.MatchedFileConditions.ToArray(), PackageVersion = "5.1.2" }; bspBuilder.Save(bsp, true); }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: esp32.exe <esp-idf directory>"); } var bspBuilder = new ESP32BSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); PathTools.CopyDirectoryRecursive(@"..\..\bsp-template", bspBuilder.Directories.OutputDir); string registerSetFile = Path.Combine(bspBuilder.Directories.OutputDir, "registers.xml"); var registers = PeripheralRegisterParser.ParsePeripheralRegisters(Path.Combine(bspBuilder.Directories.InputDir, "esp-idf")); XmlTools.SaveObject(new MCUDefinition { MCUName = "ESP32", RegisterSets = registers }, registerSetFile); var bsp = XmlTools.LoadObject <BoardSupportPackage>(Path.Combine(bspBuilder.BSPRoot, "bsp.xml")); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(bsp.Frameworks); frameworks.AddRange(commonPseudofamily.GenerateFrameworkDefinitions()); bsp.Frameworks = frameworks.ToArray(); List <string> projectFiles = new List <string>(); if (commonPseudofamily.Definition.CoreFramework != null) { foreach (var job in commonPseudofamily.Definition.CoreFramework.CopyJobs) { job.CopyAndBuildFlags(bspBuilder, projectFiles, null); } } var mainFamily = bsp.MCUFamilies.First(); if (mainFamily.AdditionalSourceFiles != null || mainFamily.AdditionalHeaderFiles != null || bsp.FileConditions != null) { throw new Exception("TODO: merge lists"); } mainFamily.AdditionalSourceFiles = projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray(); mainFamily.AdditionalHeaderFiles = projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray(); bsp.FileConditions = bspBuilder.MatchedFileConditions.ToArray(); foreach (var fn in Directory.GetFiles(Path.Combine(bspBuilder.Directories.OutputDir, @"esp-idf\components\nghttp"), "*.?", SearchOption.AllDirectories)) { string ext = Path.GetExtension(fn).ToLower(); if (ext != ".c" && ext != ".h") { continue; } var lines = File.ReadAllLines(fn); bool changed = false; for (int i = 0; i < lines.Length; i++) { if (lines[i].Contains("<config.h>")) { lines[i] = lines[i].Replace("<config.h>", "<nghttp-config.h>"); changed = true; } } if (changed) { File.WriteAllLines(fn, lines); } } foreach (var mcu in bsp.SupportedMCUs) { mcu.MCUDefinitionFile = Path.GetFileName(registerSetFile); } File.WriteAllText(Path.Combine(bspBuilder.Directories.OutputDir, @"esp-idf\components\nghttp\port\include\nghttp-config.h"), "#include \"config.h\"\n"); string linkerScript = Path.Combine(bspBuilder.Directories.OutputDir, @"esp-idf\components\esp32\ld\esp32.common.ld"); var lines2 = File.ReadAllLines(linkerScript).ToList(); Regex rgLibrary = new Regex(@"(.*)\*lib([0-9a-zA-Z_]+).a:\(([^()]+)\)"); Regex rgFileInLibrary = new Regex(@"(.*)\*lib([0-9a-zA-Z_]+).a:([0-9a-zA-Z]+\.o)\(([^()]+)\)"); for (int i = 0; i < lines2.Count; i++) { var m = rgLibrary.Match(lines2[i]); if (m.Success) { string dir = Path.Combine(bspBuilder.Directories.OutputDir, @"esp-idf\components\" + m.Groups[2].Value); if (Directory.Exists(dir)) { string[] fns = Directory.GetFiles(dir) .Select(f => Path.GetFileName(f)) .Where(f => f.EndsWith(".S", StringComparison.InvariantCultureIgnoreCase) || f.EndsWith(".c", StringComparison.InvariantCultureIgnoreCase)) .Select(f => Path.ChangeExtension(f, ".o")) .OrderBy(f => f) .ToArray(); int j = 0; foreach (var fn in fns) { lines2.Insert(i + ++j, $"{m.Groups[1].Value}*{fn}({m.Groups[3].Value})"); } lines2.RemoveAt(i--); continue; } } m = rgFileInLibrary.Match(lines2[i]); if (m.Success) { lines2[i] = $"{m.Groups[1].Value}*{m.Groups[3].Value}({m.Groups[4].Value})"; } } File.WriteAllLines(linkerScript, lines2); XmlTools.SaveObject(bsp, Path.Combine(bspBuilder.BSPRoot, "BSP.XML")); }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: risc-v.exe <freedom-e-sdk directory with build logs>"); } const string TargetVariable = "com.sysprogs.riscv.target"; const string LinkerScriptVariant = "com.sysprogs.riscv.linkerscript"; string linkerScriptTemplate = $"$$SYS:BSP_ROOT$$/bsp/$${TargetVariable}$$/metal.$${LinkerScriptVariant}$$.lds"; const string FamilyName = "SIFIVE"; using (var bspBuilder = new RISCVBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules", @"..\..\logs"))) { BoardSupportPackage bsp = new BoardSupportPackage { PackageID = "com.sysprogs.arm.riscv.sifive", PackageDescription = "SiFive Freedom E Devices", GNUTargetID = "riscv64-unknown-elf", RequiredToolchainID = "com.visualgdb.risc-v", GeneratedMakFileName = "sifive.mak", PackageVersion = "1.0", MinimumEngineVersion = "5.4", MCUFamilies = new[] { new MCUFamily { ID = FamilyName, CompilationFlags = new ToolFlags { IncludeDirectories = new[] { $"$$SYS:BSP_ROOT$$/bsp/$${TargetVariable}$$/install/include" }, LinkerScript = linkerScriptTemplate, AdditionalLibraries = new[] { "c", "gcc", "m" }, }, ConfigurableProperties = new PropertyList { PropertyGroups = new List <PropertyGroup> { new PropertyGroup { Properties = new List <PropertyEntry> { new PropertyEntry.Enumerated { UniqueID = LinkerScriptVariant, Name = "Default Linker Script", SuggestionList = new [] { "default", "freertos", "ramrodata", "scratchpad" }.Select(s => new PropertyEntry.Enumerated.Suggestion { InternalValue = s }).ToArray(), } } } } } } } }; List <MCU> mcus = new List <MCU>(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); List <MCUDefinitionWithPredicate> registers = new List <MCUDefinitionWithPredicate>(); foreach (var bspDir in Directory.GetDirectories(Path.Combine(bspBuilder.Directories.InputDir, "bsp"))) { var target = Path.GetFileName(bspDir); var logFile = Path.Combine(bspBuilder.Directories.InputDir, target + ".log"); if (!File.Exists(logFile)) { throw new Exception($"Missing {logFile}. Please run _buildall.sh in the SDK directory using WSL."); } var parsedLog = BuildLogFileParser.ParseRISCVBuildLog(logFile); if (parsedLog.LinkerScript == null) { throw new Exception("Unknown linker script"); } var script = bspBuilder.WSLPathToBSPPath(parsedLog.LinkerScript).Replace('/', '\\'); if (StringComparer.InvariantCultureIgnoreCase.Compare(script, linkerScriptTemplate.Replace($"$${TargetVariable}$$", target).Replace($"$${LinkerScriptVariant}$$", "default").Replace('/', '\\')) != 0) { throw new Exception("Unexpected linker script: " + script); } var memories = LinkerScriptTools.ScanLinkerScriptForMemories(script.Replace("$$SYS:BSP_ROOT$$", bspBuilder.Directories.InputDir)); var mcu = new MCU { ID = target.ToUpper(), UserFriendlyName = target.ToUpper(), FamilyID = FamilyName, MemoryMap = new AdvancedMemoryMap { Memories = memories, }, CompilationFlags = new ToolFlags { IncludeDirectories = parsedLog.allIncludes.Where(inc => inc != ".").Select(bspBuilder.WSLPathToBSPPath).ToArray(), PreprocessorMacros = parsedLog.allDefines.Where(kv => !kv.Key.StartsWith("PACKAGE")).Select(kv => $"{kv.Key}={kv.Value}").ToArray(), COMMONFLAGS = string.Join(" ", parsedLog.allFlags), LDFLAGS = string.Join(" ", parsedLog.AllLDFlags), }, AdditionalSystemVars = new[] { new SysVarEntry { Key = TargetVariable, Value = target, } }, RAMSize = (int)(memories.FirstOrDefault(m => m.Name == "ram")?.Size ?? 0), FLASHSize = (int)(memories.FirstOrDefault(m => m.Name == "rom")?.Size ?? 0), MCUDefinitionFile = $"DeviceDefinitions/{target.ToUpper()}.xml", }; if (mcu.RAMSize < 0) { mcu.RAMSize = 0; } var parsedSVD = SVDParser.ParseSVDFile(Path.Combine(bspDir, "design.svd"), target.ToUpper()); parsedSVD.MatchPredicate = new MCUPredicateImpl(mcu).Match; registers.Add(parsedSVD); commonPseudofamily.MCUs.Add(new MCUBuilder { Name = mcu.ID }); mcus.Add(mcu); } commonPseudofamily.AttachPeripheralRegisters(registers); bsp.SupportedMCUs = mcus.ToArray(); List <string> projectFiles = new List <string>(); PropertyList unused = null; if (commonPseudofamily.Definition.CoreFramework != null) { foreach (var job in commonPseudofamily.Definition.CoreFramework.CopyJobs) { job.CopyAndBuildFlags(bspBuilder, projectFiles, null, ref unused, null); } } bsp.Frameworks = commonPseudofamily.GenerateFrameworkDefinitions().ToArray(); var samples = commonPseudofamily.CopySamples(bsp.Frameworks).ToArray(); bsp.Examples = samples.Select(s => s.RelativePath).ToArray(); var mainFamily = bsp.MCUFamilies.First(); if (mainFamily.AdditionalSourceFiles != null || mainFamily.AdditionalHeaderFiles != null || bsp.FileConditions != null) { throw new Exception("TODO: merge lists"); } mainFamily.AdditionalSourceFiles = projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray(); mainFamily.AdditionalHeaderFiles = projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray(); bsp.FileConditions = bspBuilder.MatchedFileConditions.Values.ToArray(); XmlTools.SaveObject(bsp, Path.Combine(bspBuilder.BSPRoot, "BSP.XML")); } }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: nrf5x.exe <Nordic SW package directory>"); } bool usingIoTSDK = false; if (Directory.Exists(Path.Combine(args[0], @"components\iot\ble_6lowpan"))) { usingIoTSDK = true; Console.WriteLine("Detected IoT SDK"); } NordicBSPBuilder bspBuilder; if (usingIoTSDK) { bspBuilder = new NordicBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules_iot")); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("s1xx_iot", 0x1f000, 0x2800, "nrf52", "IoT")); } else { bspBuilder = new NordicBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S130", 0x1b000, 0x13c8, "nrf51", "Bluetooth LE Universal")); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S132", 0x20000, 0x2168, "nrf52832", "Bluetooth LE")); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S140", 0x21000, 0x2780, "nrf52840", "Bluetooth LE")); } List <MCUBuilder> devices = new List <MCUBuilder>(); if (!usingIoTSDK) { foreach (string part in new string[] { "nRF51822", "nRF51422" }) { devices.Add(new MCUBuilder { Name = part + "_XXAA", FlashSize = 256 * 1024, RAMSize = 16 * 1024, Core = CortexCore.M0 }); devices.Add(new MCUBuilder { Name = part + "_XXAB", FlashSize = 128 * 1024, RAMSize = 16 * 1024, Core = CortexCore.M0 }); devices.Add(new MCUBuilder { Name = part + "_XXAC", FlashSize = 256 * 1024, RAMSize = 32 * 1024, Core = CortexCore.M0 }); } } devices.Add(new MCUBuilder { Name = "nRF52832_XXAA", FlashSize = 512 * 1024, RAMSize = 64 * 1024, Core = CortexCore.M4 }); devices.Add(new MCUBuilder { Name = "nRF52840_XXAA", FlashSize = 1024 * 1024, RAMSize = 256 * 1024, Core = CortexCore.M4 }); List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) { allFamilies.Add(new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(fn))); } var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allFamilies); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <MCUFamilyBuilder.CopiedSample> exampleDirs = new List <MCUFamilyBuilder.CopiedSample>(); bool noPeripheralRegisters = true; List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); flags = flags.Merge(commonPseudofamily.Definition.CompilationFlags); List <ConditionalToolFlags> condFlags = new List <ConditionalToolFlags>(); foreach (var fam in allFamilies) { Console.WriteLine("Processing " + fam.Definition.Name + " family..."); string famBase = fam.Definition.Name.Substring(0, 5).ToLower(); var rejectedMCUs = fam.RemoveUnsupportedMCUs(true); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } List <Framework> bleFrameworks = new List <Framework>(); foreach (var line in File.ReadAllLines(bspBuilder.Directories.RulesDir + @"\BLEFrameworks.txt")) { int idx = line.IndexOf('|'); string dir = line.Substring(0, idx); string desc = line.Substring(idx + 1); string id = Path.GetFileName(dir); if (!id.StartsWith("ble_")) { id = "ble_" + id; } if (dir.StartsWith("services\\", StringComparison.CurrentCultureIgnoreCase)) { id = "ble_svc_" + id.Substring(4); } bleFrameworks.Add(new Framework { Name = string.Format("Bluetooth LE - {0} ({1})", desc, Path.GetFileName(dir)), ID = "com.sysprogs.arm.nordic." + famBase + "." + id, ClassID = "com.sysprogs.arm.nordic.nrfx." + id, ProjectFolderName = "BLE " + desc, DefaultEnabled = false, CopyJobs = new CopyJob[] { new CopyJob { SourceFolder = allFamilies[0].Definition.PrimaryHeaderDir + @"\..\components\ble\" + dir, TargetFolder = dir, FilesToCopy = "*.c;*.h", } } }); } fam.Definition.AdditionalFrameworks = fam.Definition.AdditionalFrameworks.Concat(bleFrameworks).ToArray(); // Startup Files StartupFileGenerator.InterruptVectorTable[] aStartupVectors; if (usingIoTSDK) { aStartupVectors = new StartupFileGenerator.InterruptVectorTable[] { GenerateStartupFile(fam.Definition.StartupFileDir, "nRF52") } } ; else { aStartupVectors = new StartupFileGenerator.InterruptVectorTable[] { GenerateStartupFile(fam.Definition.StartupFileDir, "nRF51"), GenerateStartupFile(fam.Definition.StartupFileDir, "nRF52") } }; fam.AttachStartupFiles(aStartupVectors); // SVD Files var aMcuDef1 = (new MCUDefinitionWithPredicate[] { SVDParser.ParseSVDFile(Path.Combine(fam.Definition.PrimaryHeaderDir, "nRF51.svd"), "nRF51") }); aMcuDef1[0].MatchPredicate = m => m.Name.StartsWith("nRF51"); var aMcuDef2 = (new MCUDefinitionWithPredicate[] { SVDParser.ParseSVDFile(Path.Combine(fam.Definition.PrimaryHeaderDir, "nRF52.svd"), "nRF52") }); aMcuDef2[0].MatchPredicate = m => m.Name.StartsWith("nRF52"); fam.AttachPeripheralRegisters(aMcuDef1.Concat(aMcuDef2)); var famObj = fam.GenerateFamilyObject(true); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); familyDefinitions.Add(famObj); fam.GenerateLinkerScripts(false); SysVarEntry defaultConfigFolder51 = new SysVarEntry { Key = "com.sysprogs.nordic.default_config_suffix", Value = "pca10040/s132" }; // s132_pca10036" }; SysVarEntry defaultConfigFolder52 = new SysVarEntry { Key = "com.sysprogs.nordic.default_config_suffix", Value = "pca10028/s130" }; // s130_pca10028" }; foreach (var mcu in fam.MCUs) { var mcuDef = mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters); var compatibleSoftdevs = new PropertyEntry.Enumerated.Suggestion[] { new PropertyEntry.Enumerated.Suggestion { InternalValue = "nosoftdev", UserFriendlyName = "None" } }.Concat(bspBuilder.SoftDevices.Where(sd => sd.IsCompatible(mcu.Name)).Select(s => new PropertyEntry.Enumerated.Suggestion { InternalValue = s.Name, UserFriendlyName = s.UserFriendlyName })).ToArray(); if (mcuDef.ConfigurableProperties == null) { mcuDef.ConfigurableProperties = new PropertyList { PropertyGroups = new List <PropertyGroup>() } } ; mcuDef.ConfigurableProperties.PropertyGroups.Add(new PropertyGroup { Properties = new List <PropertyEntry> { new PropertyEntry.Enumerated { UniqueID = NordicBSPBuilder.SoftdevicePropertyID, Name = "Softdevice", DefaultEntryIndex = 1, SuggestionList = compatibleSoftdevs, } } }); if (mcu.Name.StartsWith("nRF52")) { var prop = mcuDef.ConfigurableProperties.PropertyGroups[0].Properties.Find(p => p.UniqueID == "com.sysprogs.bspoptions.arm.floatmode") as PropertyEntry.Enumerated; var idx = Array.FindIndex(prop.SuggestionList, p => p.UserFriendlyName == "Hardware"); prop.DefaultEntryIndex = idx; prop.SuggestionList[idx].UserFriendlyName = "Hardware (required when using a softdevice)"; //Otherwise the system_nrf52.c file won't initialize the FPU and the internal initialization of the softdevice will later fail. mcuDef.AdditionalSystemVars = LoadedBSP.Combine(mcuDef.AdditionalSystemVars, new SysVarEntry[] { defaultConfigFolder51 }); } else { mcuDef.AdditionalSystemVars = LoadedBSP.Combine(mcuDef.AdditionalSystemVars, new SysVarEntry[] { defaultConfigFolder52 }); } mcuDefinitions.Add(mcuDef); } if (fam.Definition.ConditionalFlags != null) { condFlags.AddRange(fam.Definition.ConditionalFlags); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in fam.CopySamples(null, new SysVarEntry[] { defaultConfigFolder51 })) { exampleDirs.Add(sample); } // var prioritizer = new SamplePrioritizer(Path.Combine(bspBuilder.Directories.RulesDir, "SamplePriorities.txt")); // exampleDirs.Sort((a, b) => prioritizer.Prioritize(a.RelativePath, b.RelativePath)); } bspBuilder.GenerateSoftdeviceLibraries(); Console.WriteLine("Building BSP archive..."); string strPackageID, strPackageDesc, strPAckVersion; if (usingIoTSDK) { strPackageID = "com.sysprogs.arm.nordic.nrf5x-iot"; strPackageDesc = "Nordic NRF52 IoT"; strPAckVersion = "0.9"; foreach (var mcu in mcuDefinitions) { mcu.UserFriendlyName = mcu.ID + " (IoT)"; } } else { strPackageID = "com.sysprogs.arm.nordic.nrf5x"; strPackageDesc = "Nordic NRF5x Devices"; strPAckVersion = "13.0-alpha"; } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = strPackageID, PackageDescription = strPackageDesc, GNUTargetID = "arm-eabi", GeneratedMakFileName = "nrf5x.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.Where(s => !s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), TestExamples = exampleDirs.Where(s => s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), PackageVersion = strPAckVersion, FileConditions = bspBuilder.MatchedFileConditions.ToArray(), MinimumEngineVersion = "5.0", ConditionalFlags = condFlags.ToArray(), }; bspBuilder.Save(bsp, true); } } }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: EFM32.exe <SLab SW package directory>"); } var bspBuilder = new SLabBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); var ignoredFamilyNames = File.ReadAllLines(Path.Combine(bspBuilder.Directories.RulesDir, "rulesfamaly.txt")); string DirDevices = Path.Combine(bspBuilder.Directories.InputDir, @"platform\Device\SiliconLabs"); string[] allFamilySubdirectories = Directory.GetDirectories(DirDevices); Console.WriteLine("Enumerating devices..."); foreach (var dir in allFamilySubdirectories) { string familyName = Path.GetFileNameWithoutExtension(dir); if (ignoredFamilyNames.FirstOrDefault(n => dir.Contains(n)) != null) { continue; } var devices = GetMCUsForFamily(dir); Console.WriteLine($" {familyName}: {devices.Count} devices"); ValidateMCUNames(devices); if (devices.Where(d => d.RAMSize == 0 || d.FlashSize == 0).Count() > 0) { throw new Exception($"Some devices are RAM Size ({devices.Where(d => d.RAMSize == 0).Count()}) = 0 or FLASH Size({devices.Where(d => d.FlashSize == 0).Count()}) = 0 "); } if (devices.Count == 0) { throw new Exception("No devices for " + familyName); } string StartupFile = Directory.GetFiles(Path.Combine(DirDevices, familyName, @"Source\GCC"), "startup_*.c")[0].Replace(bspBuilder.Directories.InputDir, @"$$BSPGEN:INPUT_DIR$$"); var copyJob = new CopyJob() { FilesToCopy = "-*startup_*;*.h;*.c", TargetFolder = "Devices", ProjectInclusionMask = "*.c", AutoIncludeMask = "*.h", SourceFolder = DirDevices + "\\" + familyName }; var fam = new MCUFamilyBuilder(bspBuilder, new FamilyDefinition() { Name = familyName, FamilySubdirectory = familyName, PrimaryHeaderDir = "$$BSPGEN:INPUT_DIR$$", StartupFileDir = StartupFile, CoreFramework = new Framework() { CopyJobs = new[] { copyJob } }, Subfamilies = new MCUClassifier[] { }.ToArray() }); fam.MCUs.AddRange(devices); allFamilies.Add(fam); } List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <MCUFamilyBuilder.CopiedSample> exampleDirs = new List <MCUFamilyBuilder.CopiedSample>(); bool noPeripheralRegisters = args.Contains("/noperiph"); List <KeyValuePair <string, string> > macroToHeaderMap = new List <KeyValuePair <string, string> >(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); foreach (var fw in commonPseudofamily.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); foreach (var sample in commonPseudofamily.CopySamples()) { exampleDirs.Add(sample); } Console.WriteLine("Processing families..."); int cnt = 0; foreach (var fam in allFamilies) { Console.WriteLine($" {fam.Definition.Name} ({++cnt}/{allFamilies.Count})..."); var rejectedMCUs = fam.RemoveUnsupportedMCUs(true); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } fam.AttachStartupFiles(ParseStartupFiles(fam.Definition.StartupFileDir, fam)); var famObj = fam.GenerateFamilyObject(true); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); famObj.CompilationFlags.PreprocessorMacros = LoadedBSP.Combine(famObj.CompilationFlags.PreprocessorMacros, new string[] { "$$com.sysprogs.bspoptions.primary_memory$$_layout" }); familyDefinitions.Add(famObj); fam.GenerateLinkerScripts(false); if (!noPeripheralRegisters) { fam.AttachPeripheralRegisters(ParsePeripheralRegisters(bspBuilder.Directories.OutputDir + "\\" + fam.Definition.FamilySubdirectory + "\\Devices", fam)); } foreach (var mcu in fam.MCUs) { mcuDefinitions.Add(mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters)); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in fam.CopySamples()) { exampleDirs.Add(sample); } } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = "com.sysprogs.arm.silabs.efm32", PackageDescription = "Silabs EFM32 Devices", GNUTargetID = "arm-eabi", GeneratedMakFileName = "efm32.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.Where(s => !s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), TestExamples = exampleDirs.Where(s => s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), FileConditions = bspBuilder.MatchedFileConditions.ToArray(), PackageVersion = "5.8.3" }; Console.WriteLine("Saving BSP..."); bspBuilder.Save(bsp, true); }
private void GenerateMCUsAndMCUFamilies() { foreach (var mcuFamilyBuilder in _mcuFamilyBuilders) { var vectorTables = new List <StartupFileGenerator.InterruptVector[]>(); var vectorTableFiles = Directory.GetFiles( mcuFamilyBuilder.Definition.PrimaryHeaderDir + VECTOR_TABLE_RELATIVE_PATH, VECTOR_TABLE_FILE_PATTERN); foreach (var vectorTableFile in vectorTableFiles) { StartupFileGenerator.InterruptVector[] vectorTable = null; vectorTable = StartupFileGenerator.ParseInterruptVectors( vectorTableFile, @"^[ \t]*__isr_vector[ \t]*:", @"^[ \t]*.size[ \t]+__isr_vector", @"^[ \t]*.long[ \t]+(\w+)[ \t]*(\/\*[\s]*[\w \t\(,';\-\/\)]*[\s]*\*\/)", null, @"^[ \t\r\n]+(\/\*[ \w]+\*\/)?$", null, 1, 2); if (vectorTable.Length > 0) { var defaultISRNumber = 0; foreach (var vector in vectorTable) { if (vector == null) { continue; } if (vector.Name == DEFAULT_ISR_NAME) { vector.Name = DEFAULT_ISR_NAME + defaultISRNumber++; } else if (vector.Name == TRIM_VALUE) { vector.SpecialVectorValue = TRIM_VALUE; vector.Name = TRIM_VALUE_NAME; } } vectorTables.Add(vectorTable); } } if (vectorTables.Count == 0) { throw new Exception("Didn't find any vector table"); } CheckVectorTables(vectorTables); Directory.CreateDirectory(Path.Combine(Directories.OutputDir, mcuFamilyBuilder.FamilyFilePrefix)); GenerateStartupFiles(mcuFamilyBuilder, vectorTables[0]); if (_parsePeripheralRegisters) { var headerFiles = Directory.GetFiles(mcuFamilyBuilder.Definition.PrimaryHeaderDir + "/include", "*.h"); var familyHeaderFiles = headerFiles .Where(file => file.Substring(file.LastIndexOf(Path.DirectorySeparatorChar) + 1) == "M" + mcuFamilyBuilder.Definition.Name + ".h").ToArray(); if (familyHeaderFiles.Length == 0) { throw new Exception("No header file found for MCU family"); } else if (familyHeaderFiles.Length > 1) { throw new Exception("Only one header file expected for MCU family"); } mcuFamilyBuilder.AttachPeripheralRegisters(new[] { new MCUDefinitionWithPredicate { MCUName = mcuFamilyBuilder.Definition.Name, RegisterSets = PeripheralRegisterGenerator.GenerateFamilyPeripheralRegisters(familyHeaderFiles[0]), MatchPredicate = m => true } }); } var famObj = mcuFamilyBuilder.GenerateFamilyObject(true); famObj.ConfigurableProperties.PropertyGroups[0].Properties.Add( new PropertyEntry.Boolean { Name = "Disable Watchdog", UniqueID = "com.sysprogs.bspoptions.wdog", ValueForTrue = "DISABLE_WDOG", DefaultValue = true } ); famObj.AdditionalSourceFiles = new string[] { "$$SYS:BSP_ROOT$$/" + mcuFamilyBuilder.FamilyFilePrefix + STARTUP_FILES_FOLDER + "/startup.c", "$$SYS:BSP_ROOT$$/" + mcuFamilyBuilder.FamilyFilePrefix + STARTUP_FILES_FOLDER + "/vectors_" + mcuFamilyBuilder.Definition.Name + ".c" }; var deviceSpecificFiles = _projectFiles.Where(file => file.Contains("devices") || file.Contains("CMSIS")); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, deviceSpecificFiles.Where(f => f.Contains(famObj.ID) && !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, deviceSpecificFiles. Where(f => (f.Contains(famObj.ID) || f.Contains("CMSIS") || f.Contains("fsl_device_registers.h")) && MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, _commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(_flags); famObj.CompilationFlags.IncludeDirectories = new HashSet <string>(famObj.AdditionalSourceFiles.Concat(famObj.AdditionalHeaderFiles).Select(f => f.Substring(0, f.LastIndexOf("/")))).ToArray(); _mcuFamilies.Add(famObj); GenerateLinkerScripts(mcuFamilyBuilder); foreach (var mcuBuilder in mcuFamilyBuilder.MCUs) { mcuBuilder.StartupFile = "$$SYS:BSP_ROOT$$/" + mcuFamilyBuilder.FamilyFilePrefix + STARTUP_FILES_FOLDER + "/startup.c"; var mcu = mcuBuilder.GenerateDefinition(mcuFamilyBuilder, mcuFamilyBuilder.BSP, _parsePeripheralRegisters); mcu.FLASHBase = _mcuMemoryLayouts[mcu.ID].Memories.First(m => m.Name == FLASH_MEMORY).Start; mcu.RAMBase = _mcuMemoryLayouts[mcu.ID].Memories.First(m => m.Name == SRAM_MEMORY).Start; var preprocessorMacroses = mcu.CompilationFlags.PreprocessorMacros.ToList(); preprocessorMacroses.Add("CPU_" + mcu.ID); mcu.CompilationFlags.PreprocessorMacros = preprocessorMacroses.ToArray(); _mcus.Add(mcu); } foreach (var fw in mcuFamilyBuilder.GenerateFrameworkDefinitions()) { _frameworks.Add(fw); } foreach (var sample in mcuFamilyBuilder.CopySamples(_frameworks)) { _exampleDirs.Add(sample); } } }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: EFM32.exe <SLab SW package directory>"); } var bspBuilder = new SLabBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); /* * var devices = BSPGeneratorTools.ReadMCUDevicesFromCommaDelimitedCSVFile(bspBuilder.Directories.RulesDir + @"\McuSiliconLabs.csv", * "Part No.", "Flash (kB)", "Ram (kB)", "MCU Core", true); * RemoveDuplicateMCU(ref devices); * var devicesOld = BSPGeneratorTools.ReadMCUDevicesFromCommaDelimitedCSVFile(bspBuilder.Directories.RulesDir + @"\McuSiliconLabsOld.csv", * "Part No.", "Flash (kB)", "Ram (kB)", "MCU Core", true); * RemoveDuplicateMCU(ref devicesOld); * * * foreach (var d in devicesOld) * if (!devices.Contains(d)) * devices.Add(d); */ var devices = GetMcuFromSDK(bspBuilder.Directories.InputDir); RemoveDuplicateMCU(ref devices); if (devices.Where(d => d.RAMSize == 0 || d.FlashSize == 0).Count() > 0) { throw new Exception($"Some devices are RAM Size ({devices.Where(d => d.RAMSize == 0).Count()}) = 0 or FLASH Size({devices.Where(d => d.FlashSize == 0).Count()}) = 0 "); } List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); // foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) // allFamilies.Add(new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject<FamilyDefinition>(fn))); // foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) // allFamilies.Add(new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject<FamilyDefinition>(fn))); //------------ var ignoreFams = File.ReadAllLines(Path.Combine(bspBuilder.Directories.RulesDir, "rulesfamaly.txt")); string DirDevices = Path.Combine(bspBuilder.Directories.InputDir, @"platform\Device\SiliconLabs"); string[] lstSubDir = Directory.GetDirectories(DirDevices); foreach (var fl in lstSubDir) { string vNameSubDir = Path.GetFileNameWithoutExtension(fl); string StartupFile = Directory.GetFiles(Path.Combine(DirDevices, vNameSubDir, @"Source\GCC"), "startup_*.c")[0].Replace(bspBuilder.Directories.InputDir, @"$$BSPGEN:INPUT_DIR$$"); CopyJob[] CopyJobs = { new CopyJob() { FilesToCopy = "-*startup_*;*.h;*.c", TargetFolder = "Devices", ProjectInclusionMask = "*.c", AutoIncludeMask = "*.h", SourceFolder = DirDevices + "\\" + vNameSubDir } }; //MCUClassifier[] ddd = { new MCUClassifier() }; //if (!fl.EndsWith("BGM13")) //continue; bool flignore = false; foreach (var igf in ignoreFams) { if (fl.Contains(igf)) { flignore = true; } } if (flignore) { continue; } //if (!fl.Contains("EFR32BG21")) // continue; allFamilies.Add(new MCUFamilyBuilder(bspBuilder, new FamilyDefinition() { Name = vNameSubDir, DeviceRegex = SetDeviceRegex(vNameSubDir.ToUpper(), lstSubDir), FamilySubdirectory = vNameSubDir, PrimaryHeaderDir = "$$BSPGEN:INPUT_DIR$$", StartupFileDir = StartupFile, CoreFramework = new Framework() { CopyJobs = CopyJobs.ToArray() }, Subfamilies = new MCUClassifier[] { }.ToArray() })); } //------------ var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allFamilies); List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <MCUFamilyBuilder.CopiedSample> exampleDirs = new List <MCUFamilyBuilder.CopiedSample>(); bool noPeripheralRegisters = args.Contains("/noperiph"); List <KeyValuePair <string, string> > macroToHeaderMap = new List <KeyValuePair <string, string> >(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); foreach (var fw in commonPseudofamily.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); foreach (var sample in commonPseudofamily.CopySamples()) { exampleDirs.Add(sample); } foreach (var fam in allFamilies) { var rejectedMCUs = fam.RemoveUnsupportedMCUs(true); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } fam.AttachStartupFiles(ParseStartupFiles(fam.Definition.StartupFileDir, fam)); var famObj = fam.GenerateFamilyObject(true); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); famObj.CompilationFlags.PreprocessorMacros = LoadedBSP.Combine(famObj.CompilationFlags.PreprocessorMacros, new string[] { "$$com.sysprogs.bspoptions.primary_memory$$_layout" }); familyDefinitions.Add(famObj); fam.GenerateLinkerScripts(false); if (!noPeripheralRegisters) { fam.AttachPeripheralRegisters(ParsePeripheralRegisters(bspBuilder.Directories.OutputDir + "\\" + fam.Definition.FamilySubdirectory + "\\Devices", fam)); } foreach (var mcu in fam.MCUs) { mcuDefinitions.Add(mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters)); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in fam.CopySamples()) { exampleDirs.Add(sample); } } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = "com.sysprogs.arm.silabs.efm32", PackageDescription = "Silabs EFM32 Devices", GNUTargetID = "arm-eabi", GeneratedMakFileName = "efm32.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.Where(s => !s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), TestExamples = exampleDirs.Where(s => s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), FileConditions = bspBuilder.MatchedFileConditions.ToArray(), PackageVersion = "5.6.0" }; bspBuilder.Save(bsp, true); }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: nxp.exe <NXP SW package directory>"); } var bspBuilder = new NxpBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules")); var devices = BSPGeneratorTools.ReadMCUDevicesFromCommaDelimitedCSVFile(bspBuilder.Directories.RulesDir + @"\McuNXPLpcDevices.csv", "Part Number", "Flash (KB)", "SRAM(kB)", "CPU", true); RemoveDuplicateMCU(ref devices); List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) { allFamilies.Add(new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(fn))); } var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allFamilies); List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <MCUFamilyBuilder.CopiedSample> examples = new List <MCUFamilyBuilder.CopiedSample>(); bool noPeripheralRegisters = args.Contains("/noperiph"); List <KeyValuePair <string, string> > macroToHeaderMap = new List <KeyValuePair <string, string> >(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); foreach (var sample in commonPseudofamily.CopySamples()) { examples.Add(sample); } foreach (var fam in allFamilies) { var rejectedMCUs = fam.RemoveUnsupportedMCUs(true); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } fam.AttachStartupFiles(ParseStartupFiles(fam.Definition.StartupFileDir, "cr_startup_lpc8xx.c", fam)); if (!noPeripheralRegisters) { fam.AttachPeripheralRegisters(ParsePeripheralRegisters(fam.Definition.PrimaryHeaderDir + "\\" + fam.Definition.FamilySubdirectory, fam)); } var famObj = fam.GenerateFamilyObject(true); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); famObj.CompilationFlags.PreprocessorMacros = LoadedBSP.Combine(famObj.CompilationFlags.PreprocessorMacros, new string[] { "$$com.sysprogs.bspoptions.primary_memory$$_layout" }); familyDefinitions.Add(famObj); fam.GenerateLinkerScripts(false); foreach (var mcu in fam.MCUs) { mcuDefinitions.Add(mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters)); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } foreach (var sample in fam.CopySamples()) { examples.Add(sample); } } BoardSupportPackage bsp = new BoardSupportPackage { PackageID = "com.sysprogs.arm.nxp_lpc", PackageDescription = "NXP LPC Devices", GNUTargetID = "arm-eabi", GeneratedMakFileName = "nxp_lpc.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = examples.Select(s => s.RelativePath).ToArray(), FileConditions = bspBuilder.MatchedFileConditions.ToArray(), PackageVersion = "2.1" }; bspBuilder.Save(bsp, true); }
static void Main(string[] args) { if (args.Length < 1) { throw new Exception("Usage: nrf5x.exe <Nordic SW package directory>"); } using (var bspBuilder = new NordicBSPBuilder(new BSPDirectories(args[0], @"..\..\Output", @"..\..\rules", @"..\..\logs"))) { bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S132", "nrf52832.*", true, null, bspBuilder.Directories.InputDir)); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S140", "nrf52840.*", true, null, bspBuilder.Directories.InputDir)); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S112", "nrf5281.*", false, null, bspBuilder.Directories.InputDir)); bspBuilder.SoftDevices.Add(new NordicBSPBuilder.SoftDevice("S113", "nrf528.*", true, null, bspBuilder.Directories.InputDir)); List <MCUBuilder> devices = new List <MCUBuilder> { new NordicMCUBuilder("nRF52832_XXAA", 512, 64, CortexCore.M4, true, "S132", "PCA10040"), new NordicMCUBuilder("nRF52810_XXAA", 192, 24, CortexCore.M4, false, "S112", "PCA10040"), new NordicMCUBuilder("nRF52811_XXAA", 192, 24, CortexCore.M4, false, "S112", "PCA10056"), new NordicMCUBuilder("nRF52833_XXAA", 512, 128, CortexCore.M4, true, "S140", "PCA10100"), new NordicMCUBuilder("nRF52840_XXAA", 1024, 256, CortexCore.M4, true, "S140", "PCA10056"), }; List <MCUFamilyBuilder> allFamilies = new List <MCUFamilyBuilder>(); foreach (var fn in Directory.GetFiles(bspBuilder.Directories.RulesDir + @"\Families", "*.xml")) { allFamilies.Add(new NordicFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(fn))); } var rejects = BSPGeneratorTools.AssignMCUsToFamilies(devices, allFamilies); List <EmbeddedFramework> frameworks = new List <EmbeddedFramework>(); List <MCUFamilyBuilder.CopiedSample> exampleDirs = new List <MCUFamilyBuilder.CopiedSample>(); bool noPeripheralRegisters = args.Contains("/noperiph"); List <MCUFamily> familyDefinitions = new List <MCUFamily>(); List <MCU> mcuDefinitions = new List <MCU>(); var commonPseudofamily = new MCUFamilyBuilder(bspBuilder, XmlTools.LoadObject <FamilyDefinition>(bspBuilder.Directories.RulesDir + @"\CommonFiles.xml")); var flags = new ToolFlags(); List <string> projectFiles = new List <string>(); commonPseudofamily.CopyFamilyFiles(ref flags, projectFiles); flags = flags.Merge(commonPseudofamily.Definition.CompilationFlags); List <ConditionalToolFlags> condFlags = new List <ConditionalToolFlags>(); foreach (var fam in allFamilies) { fam.GenerateLinkerScripts(false); Console.WriteLine("Processing " + fam.Definition.Name + " family..."); var rejectedMCUs = fam.RemoveUnsupportedMCUs(); if (rejectedMCUs.Length != 0) { Console.WriteLine("Unsupported {0} MCUs:", fam.Definition.Name); foreach (var mcu in rejectedMCUs) { Console.WriteLine("\t{0}", mcu.Name); } } bspBuilder.RuleGenerator.GenerateRulesForFamily(fam.Definition); List <MCUDefinitionWithPredicate> hardwareRegisterFiles = new List <MCUDefinitionWithPredicate>(); foreach (var svd in Directory.GetFiles(fam.Definition.PrimaryHeaderDir, "*.svd")) { var name = Path.GetFileNameWithoutExtension(svd).ToUpper(); if (name == "NRF52") { name = "NRF52832"; } if (!name.StartsWith("NRF52")) { continue; } var registers = SVDParser.ParseSVDFile(svd, name); hardwareRegisterFiles.Add(new MCUDefinitionWithPredicate { MCUName = name, RegisterSets = registers.RegisterSets, MatchPredicate = m => m.Name.StartsWith(registers.MCUName, StringComparison.InvariantCultureIgnoreCase) }); } fam.AttachPeripheralRegisters(hardwareRegisterFiles); var famObj = fam.GenerateFamilyObject(MCUFamilyBuilder.CoreSpecificFlags.All); famObj.AdditionalSourceFiles = LoadedBSP.Combine(famObj.AdditionalSourceFiles, projectFiles.Where(f => !MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalHeaderFiles = LoadedBSP.Combine(famObj.AdditionalHeaderFiles, projectFiles.Where(f => MCUFamilyBuilder.IsHeaderFile(f)).ToArray()); famObj.AdditionalSystemVars = LoadedBSP.Combine(famObj.AdditionalSystemVars, commonPseudofamily.Definition.AdditionalSystemVars); famObj.CompilationFlags = famObj.CompilationFlags.Merge(flags); familyDefinitions.Add(famObj); fam.GenerateLinkerScripts(false); foreach (var mcu in fam.MCUs) { var mcuDef = mcu.GenerateDefinition(fam, bspBuilder, !noPeripheralRegisters, false, MCUFamilyBuilder.CoreSpecificFlags.All & ~MCUFamilyBuilder.CoreSpecificFlags.PrimaryMemory); if (mcu.Name.StartsWith("nRF52832")) { //Although documented as a legacy definition, skipping this breaks fds_internal_defs.h mcuDef.CompilationFlags.PreprocessorMacros = mcuDef.CompilationFlags.PreprocessorMacros.Concat(new[] { "NRF52" }).ToArray(); } var nosoftdev = new[] { new PropertyEntry.Enumerated.Suggestion { InternalValue = "nosoftdev", UserFriendlyName = "None" } }; var compatibleSoftdevs = bspBuilder.SoftDevices.Where(sd => sd.IsCompatible(mcu.Name)).SelectMany( s => new[] { new PropertyEntry.Enumerated.Suggestion { InternalValue = s.Name, UserFriendlyName = s.UserFriendlyName }, new PropertyEntry.Enumerated.Suggestion { InternalValue = s.Name + "_reserve", UserFriendlyName = $"{s.UserFriendlyName} (programmed separately)" } }); if (mcuDef.ConfigurableProperties == null) { mcuDef.ConfigurableProperties = new PropertyList { PropertyGroups = new List <PropertyGroup>() } } ; mcuDef.ConfigurableProperties.PropertyGroups.Add(new PropertyGroup { Properties = new List <PropertyEntry> { new PropertyEntry.Enumerated { UniqueID = NordicBSPBuilder.SoftdevicePropertyID, Name = "Softdevice", DefaultEntryIndex = 1, SuggestionList = nosoftdev.Concat(compatibleSoftdevs).ToArray(), } } }); if (mcu.Name.StartsWith("nRF52") && !mcu.Name.StartsWith("nRF5281")) { var prop = mcuDef.ConfigurableProperties.PropertyGroups[0].Properties.Find(p => p.UniqueID == "com.sysprogs.bspoptions.arm.floatmode") as PropertyEntry.Enumerated; var idx = Array.FindIndex(prop.SuggestionList, p => p.UserFriendlyName == "Hardware"); prop.DefaultEntryIndex = idx; prop.SuggestionList[idx].UserFriendlyName = "Hardware (required when using a softdevice)"; //Otherwise the system_nrf52.c file won't initialize the FPU and the internal initialization of the softdevice will later fail. } string defaultConfig; if (mcu.Name.StartsWith("nRF52840")) { defaultConfig = "pca10056/s140"; } else if (mcu.Name.StartsWith("nRF52810")) { defaultConfig = "pca10040e/s112"; } else if (mcu.Name.StartsWith("nRF52811")) { defaultConfig = "pca10056e/s112"; } else { defaultConfig = "pca10040/s132"; } var extraEntries = new[] { new SysVarEntry { Key = "com.sysprogs.nordic.default_config_suffix", Value = defaultConfig }, new SysVarEntry { Key = "com.sysprogs.nordic.default_config_suffix_blank", Value = "pca10040" } }; mcuDef.AdditionalSystemVars = LoadedBSP.Combine(mcuDef.AdditionalSystemVars, extraEntries); mcuDefinitions.Add(mcuDef); } if (fam.Definition.ConditionalFlags != null) { condFlags.AddRange(fam.Definition.ConditionalFlags); } foreach (var fw in fam.GenerateFrameworkDefinitions()) { frameworks.Add(fw); } string dirpca = "pca10040e/s112"; foreach (var sample in fam.CopySamples(null, new SysVarEntry[] { new SysVarEntry { Key = "com.sysprogs.nordic.default_config_suffix", Value = dirpca }, new SysVarEntry { Key = "com.sysprogs.nordic.default_config_suffix_blank", Value = "pca10040" } })) { exampleDirs.Add(sample); } } const string softdevExpression = "$$com.sysprogs.bspoptions.nrf5x.softdevice$$"; foreach (var softdev in bspBuilder.SoftDevices) { condFlags.Add(new ConditionalToolFlags { FlagCondition = new Condition.Equals { Expression = softdevExpression, ExpectedValue = softdev.Name + "_reserve" }, Flags = new ToolFlags { PreprocessorMacros = familyDefinitions.First().CompilationFlags.PreprocessorMacros.Where(f => f.Contains(softdevExpression)).Select(f => f.Replace(softdevExpression, softdev.Name)).ToArray(), IncludeDirectories = familyDefinitions.First().CompilationFlags.IncludeDirectories.Where(f => f.Contains(softdevExpression)).Select(f => f.Replace(softdevExpression, softdev.Name)).ToArray() } }); } bspBuilder.GenerateSoftdeviceLibraries(); bspBuilder.RuleGenerator.PatchGeneratedFrameworks(frameworks, condFlags); // CheckEntriesSample(Path.Combine(bspBuilder.Directories.OutputDir, @"nRF5x\components\libraries"), // Path.Combine(bspBuilder.Directories.OutputDir, "Samples")); Console.WriteLine("Building BSP archive..."); BoardSupportPackage bsp = new BoardSupportPackage { PackageID = "com.sysprogs.arm.nordic.nrf5x", PackageDescription = "Nordic NRF52x Devices", GNUTargetID = "arm-eabi", GeneratedMakFileName = "nrf5x.mak", MCUFamilies = familyDefinitions.ToArray(), SupportedMCUs = mcuDefinitions.ToArray(), Frameworks = frameworks.ToArray(), Examples = exampleDirs.Where(s => !s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), TestExamples = exampleDirs.Where(s => s.IsTestProjectSample).Select(s => s.RelativePath).ToArray(), PackageVersion = "16.0", FirstCompatibleVersion = "16.0", FileConditions = bspBuilder.MatchedFileConditions.Values.ToArray(), MinimumEngineVersion = "5.0", ConditionalFlags = condFlags.ToArray(), InitializationCodeInsertionPoints = commonPseudofamily.Definition.InitializationCodeInsertionPoints, }; bspBuilder.ValidateBSP(bsp); List <ConfigurationFixSampleReference> samplesForComputingSymbolLists = new List <ConfigurationFixSampleReference>(); foreach (var sampleName in new[] { "BLEMouse", "IoT/Icmp", "BLEMultilinkCentral", "LEDBlink_FreeRTOS" }) { samplesForComputingSymbolLists.Add(new ConfigurationFixSampleReference { MCUID = "nRF52840_XXAA", SamplePath = "$$SYS:BSP_ROOT$$/samples/" + sampleName }); } bspBuilder.ReverseFileConditions.SaveIfConsistent(bspBuilder.Directories.OutputDir, bspBuilder.ExportRenamedFileTable(), true, samplesForComputingSymbolLists.ToArray()); bspBuilder.Save(bsp, false, false); } } }