Esempio n. 1
0
        public MCU GenerateDefinition(MCUFamilyBuilder fam, BSPBuilder bspBuilder, bool requirePeripheralRegisters, bool allowIncompleteDefinition = false, MCUFamilyBuilder.CoreSpecificFlags flagsToAdd = MCUFamilyBuilder.CoreSpecificFlags.All)
        {
            if (!allowIncompleteDefinition && string.IsNullOrEmpty(LinkerScriptPath))
            {
                throw new Exception("Linker script not defined for " + Name);
            }
            if (!allowIncompleteDefinition && string.IsNullOrEmpty(StartupFile))
            {
                throw new Exception("Startup file not defined for " + Name);
            }
            if (string.IsNullOrEmpty(MCUDefinitionFile) && requirePeripheralRegisters)
            {
                throw new Exception("Peripheral register definition not found for " + Name);
            }

            var mcu = new MCU
            {
                ID               = Name,
                FamilyID         = fam.Definition.Name,
                FLASHSize        = FlashSize,
                RAMSize          = RAMSize,
                HierarchicalPath = $@"{bspBuilder.ShortName}\{fam.Definition.Name}",
                CompilationFlags = new ToolFlags
                {
                    PreprocessorMacros = new string[] { bspBuilder.GetMCUTypeMacro(this) },
                    LinkerScript       = LinkerScriptPath,
                },
                AdditionalSourceFiles = new string[] { StartupFile }.Where(s => !string.IsNullOrEmpty(s)).ToArray(),
                MCUDefinitionFile     = MCUDefinitionFile
            };

            if (fam.Definition.HasMixedCores)
            {
                MCUFamilyBuilder.AddCoreSpecificFlags(flagsToAdd, mcu, Core);
            }

            List <SysVarEntry> sysVars = new List <SysVarEntry>();

            foreach (var classifier in fam.Definition.Subfamilies)
            {
                string category = classifier.TryMatchMCUName(Name);
                if (category == null)
                {
                    if (classifier.Required)
                    {
                        throw new Exception("Cannot detect subfamily for " + Name);
                    }
                }

                sysVars.Add(new SysVarEntry {
                    Key = classifier.VariableName, Value = category
                });
            }

            if (sysVars.Count > 0)
            {
                mcu.AdditionalSystemVars = sysVars.ToArray();
            }

            bspBuilder.GetMemoryBases(out mcu.FLASHBase, out mcu.RAMBase);
            return(mcu);
        }
Esempio n. 2
0
                public override MCU GenerateDefinition(MCUFamilyBuilder fam, BSPBuilder bspBuilder, bool requirePeripheralRegisters, bool allowIncompleteDefinition = false, MCUFamilyBuilder.CoreSpecificFlags flagsToAdd = MCUFamilyBuilder.CoreSpecificFlags.All)
                {
                    var mcu = base.GenerateDefinition(fam, bspBuilder, requirePeripheralRegisters, allowIncompleteDefinition, flagsToAdd);

                    var layout = ToMemoryLayout(true);
                    var sram   = layout.Memories.First(m => m.Name == "SRAM");

                    mcu.RAMBase = sram.Start;
                    mcu.RAMSize = (int)sram.Size;

                    mcu.MemoryMap = new AdvancedMemoryMap
                    {
                        Memories = layout.Memories.Select(MakeMCUMemory).ToArray()
                    };

                    return(mcu);
                }
Esempio n. 3
0
                public override MCU GenerateDefinition(MCUFamilyBuilder fam, BSPBuilder bspBuilder, bool requirePeripheralRegisters, bool allowIncompleteDefinition = false, MCUFamilyBuilder.CoreSpecificFlags flagsToAdd = MCUFamilyBuilder.CoreSpecificFlags.All)
                {
                    var mcu = base.GenerateDefinition(fam, bspBuilder, requirePeripheralRegisters, allowIncompleteDefinition, flagsToAdd);

                    var layout = ToMemoryLayout(fam.BSP.Report);
                    var sram   = layout.Layout.Memories.FirstOrDefault(m => m.Type == MemoryType.RAM && m.IsPrimary);

                    if (sram != null)
                    {
                        mcu.RAMBase = sram.Start;
                        mcu.RAMSize = (int)sram.Size;
                    }

                    mcu.MemoryMap            = layout.Layout.ToMemoryMap();
                    mcu.AdditionalSystemVars = LoadedBSP.Combine(new[] { new SysVarEntry {
                                                                             Key = "com.sysprogs.stm32.hal_device_family", Value = MCU.Define
                                                                         } }, mcu.AdditionalSystemVars);

                    return(mcu);
                }