Пример #1
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                foreach (var kv in _SpecialMemoryLayouts)
                {
                    if (kv.Key.IsMatch(mcu.Name))
                    {
                        return(kv.Value);
                    }
                }

                MemoryLayout layout = new MemoryLayout {
                    DeviceName = mcu.Name, Memories = new List <Memory>()
                };

                layout.Memories.Add(new Memory
                {
                    Name   = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.FLASH,
                    Start  = FLASHBase,
                    Size   = (uint)mcu.FlashSize,
                });

                layout.Memories.Add(new Memory
                {
                    Name   = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.RAM,
                    Start  = SRAMBase,
                    Size   = (uint)mcu.RAMSize,
                });


                return(layout);
            }
Пример #2
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                var layout = new MemoryLayout {
                    DeviceName = mcu.Name, Memories = new List <Memory>()
                };

                layout.Memories.Add(new Memory
                {
                    Name   = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.FLASH,
                    Start  = FLASHBase,
                    Size   = (uint)mcu.FlashSize
                });

                layout.Memories.Add(new Memory
                {
                    Name   = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.RAM,
                    Start  = SRAMBase,
                    Size   = (uint)mcu.RAMSize
                });

                return(layout);
            }
Пример #3
0
            public override MemoryLayoutAndSubstitutionRules GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                if (mcu is DeviceListProviders.CubeProvider.STM32MCUBuilder stMCU)
                {
                    return(stMCU.ToMemoryLayout(family.BSP.Report));
                }

                throw new Exception($"{mcu.Name} is not provided by the STM32CubeMX-based MCU locator. Please ensure we get the actual memory map for this device, as guessing it from totals often yields wrong results.");


                MemoryLayout layout = new MemoryLayout {
                    DeviceName = mcu.Name, Memories = new List <Memory>()
                };

                layout.Memories.Add(new Memory
                {
                    Name   = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.FLASH,
                    Start  = FLASHBase,
                    Size   = (uint)mcu.FlashSize,
                });

                layout.Memories.Add(new Memory
                {
                    Name   = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.RAM,
                    Start  = SRAMBase,
                    Size   = (uint)mcu.RAMSize,
                });


                return(new MemoryLayoutAndSubstitutionRules(layout));
            }
Пример #4
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes.
                MemoryLayout layout = new MemoryLayout {
                    DeviceName = mcu.Name, Memories = new List <Memory>()
                };

                layout.Memories.Add(new Memory
                {
                    Name   = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.FLASH,
                    Start  = FLASHBase,
                    Size   = (uint)mcu.FlashSize,
                });

                layout.Memories.Add(new Memory
                {
                    Name   = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.RAM,
                    Start  = SRAMBase,
                    Size   = (uint)mcu.RAMSize,
                });

                return(layout);
            }
Пример #5
0
            protected override LinkerScriptTemplate GetTemplateForMCU(MCUBuilder mcu)
            {
                var template = base.GetTemplateForMCU(mcu).ShallowCopy();

                template.SymbolAliases = new[] { new SymbolAlias {
                                                     Name = "__Vectors", Target = "g_pfnVectors"
                                                 } };
                return(template);
            }
Пример #6
0
        static List <MCUBuilder> RemoveDuplicateMCU(ref List <MCUBuilder> rawmcu_list)
        {
            //---------------------------------
            // Remove duplicate MCU
            //  List<MCUBuilder> rawmcu_list = pListMCU;
            rawmcu_list.Sort((a, b) => a.Name.CompareTo(b.Name));
            for (int ic = 0; ic < rawmcu_list.Count; ic++)
            {
                int        DelCount  = 0;
                MCUBuilder mcu       = rawmcu_list[ic];
                Regex      rg        = new Regex(@"^LPC...[\d]*[L]?[V]?");
                string     shortName = "";
                var        m         = rg.Match(mcu.Name);
                if (m.Success)
                {
                    shortName = m.Groups[0].ToString();
                }
                Boolean flModif = true;
                for (int il = ic + 1; il < rawmcu_list.Count; il++)
                {
                    MCUBuilder mcuNext = rawmcu_list[il];
                    m = rg.Match(mcuNext.Name);
                    string shortNameNext = "";
                    if (m.Success)
                    {
                        shortNameNext = m.Groups[0].ToString();
                    }

                    if (shortName != shortNameNext)
                    {
                        break;
                    }

                    if (mcu.FlashSize != mcuNext.FlashSize || mcu.RAMSize != mcuNext.RAMSize)
                    {
                        flModif = false;
                    }

                    DelCount++;
                }

                if (flModif)
                {
                    rawmcu_list[ic].Name = shortName;
                    rawmcu_list.RemoveRange(ic + 1, DelCount); //Delete duplicate
                }
                else
                {
                    ic += DelCount;
                }
            }

            return(rawmcu_list);
        }
Пример #7
0
 protected override LinkerScriptTemplate GetTemplateForMCU(MCUBuilder mcu)
 {
     if (mcu.Name.StartsWith("XMC1", StringComparison.InvariantCultureIgnoreCase))
     {
         return(LDSTemplateX1);
     }
     else
     {
         return(LDSTemplate);
     }
 }
Пример #8
0
 static bool IsMcuFull(MCUBuilder mcu)
 {
     if (mcu.RAMSize != 0 && mcu.FlashSize != 0 && mcu.Core != CortexCore.Invalid)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #9
0
        public static MCUBuilder GetMcuFromFile(string fileinc)
        {
            var mcu = new MCUBuilder();

            foreach (var lnstr in File.ReadAllLines(fileinc))
            {
                Match m = Regex.Match(lnstr, @"[/* ]+Flash and SRAM limits for ([\w\d]+) [.]*");
                if (m.Success)
                {
                    mcu.Name = m.Groups[1].Value;
                }

                if (mcu.Name == null)
                {
                    continue;
                }

                GetPropertyMCU(lnstr, "FLASH_SIZE", ref mcu.FlashSize);
                GetPropertyMCU(lnstr, "SRAM_SIZE", ref mcu.RAMSize);
                if (mcu.Core != CortexCore.Invalid)
                {
                    continue;
                }
                m = Regex.Match(lnstr, @"#define __CM([\d\w]+)_REV[0-9xU /*<]+(Cortex-M[0-7+]+).*");
                if (m.Success)
                {
                    mcu.Core = BSPGeneratorTools.ParseCoreName(m.Groups[2].Value);
                }

                if (IsMcuFull(mcu))
                {
                    break;
                }
            }

            if (mcu.Name == null)
            {
                return(null);
            }
            if (mcu.Core == CortexCore.Invalid || mcu.Name.StartsWith("EFR32BG21"))
            {
                mcu.Core = CortexCore.M4;
            }
            if (mcu.Core == CortexCore.Invalid || mcu.FlashSize == 0 || mcu.RAMSize == 0)
            {
                throw new Exception($"mcu '{mcu.Name}' have not size of memory , file {fileinc}");
            }

            mcu.FPU = BSPGeneratorTools.GetDefaultFPU(mcu.Core);

            return(mcu);
        }
Пример #10
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                MemoryLayout compatLayout = _SpecialMemoryLayouts.FirstOrDefault(m => m.Key.IsMatch(mcu.Name)).Value;

                if (mcu is DeviceListProviders.CubeProvider.STM32MCUBuilder stMCU)
                {
                    var newLayout = stMCU.ToMemoryLayout();

                    if (newLayout.Memories.FirstOrDefault(m => m.Name == "SRAM") == null)
                    {
                        var ram1 = newLayout.Memories.First(m => m.Name == "RAM_D1");
                        ram1.Name = "SRAM";
                    }

                    if (compatLayout != null)
                    {
                        VerifyMemories(mcu.Name, newLayout, compatLayout, "FLASH");
                        VerifyMemories(mcu.Name, newLayout, compatLayout, "SRAM");
                    }
                    return(newLayout);
                }

                throw new Exception($"{mcu.Name} is not provided by the STM32CubeMX-based MCU locator. Please ensure we get the actual memory map for this device, as guessing it from totals often yields wrong results.");


                MemoryLayout layout = new MemoryLayout {
                    DeviceName = mcu.Name, Memories = new List <Memory>()
                };

                layout.Memories.Add(new Memory
                {
                    Name   = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.FLASH,
                    Start  = FLASHBase,
                    Size   = (uint)mcu.FlashSize,
                });

                layout.Memories.Add(new Memory
                {
                    Name   = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.RAM,
                    Start  = SRAMBase,
                    Size   = (uint)mcu.RAMSize,
                });


                return(layout);
            }
Пример #11
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes.
                MemoryLayout layout = new MemoryLayout();

                layout.Memories   = new List <Memory>();
                layout.DeviceName = mcu.Name;
                string aFileName = family.BSP.Directories.InputDir + "\\platform\\Device\\SiliconLabs\\" + family.FamilyFilePrefix.Substring(0, family.FamilyFilePrefix.Length - 1) + "\\Include\\" + mcu + ".h";
                Match  m;
                Regex  rg       = new Regex(@"(#define RAM_MEM_BASE[ \t]*.*0x)([0-9][U][L])+.*");
                var    RAMStart = 0;

                foreach (var ln in File.ReadAllLines(aFileName))
                {
                    m        = Regex.Match(ln, @"#define RAM_MEM_BASE[ \t]+.*0x([\d]+)UL.*");
                    RAMStart = 0;
                    if (m.Success)
                    {
                        RAMStart = Convert.ToInt32(m.Groups[1].Value, 16);
                        break;
                    }
                }
                if (RAMStart == 0)
                {
                    throw new Exception("no RAM Start");
                }
                layout.Memories.Insert(0, new Memory
                {
                    Name   = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.FLASH,
                    Start  = FLASHBase,
                    Size   = (uint)mcu.FlashSize
                });
                layout.Memories.Insert(0, new Memory
                {
                    Name   = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.RAM,
                    Start  = (uint)RAMStart,
                    Size   = (uint)mcu.RAMSize
                });

                return(layout);
            }
Пример #12
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes.
                MemoryLayout layout = new MemoryLayout {
                    DeviceName = mcu.Name, Memories = FindMemories(mcu.Name)
                };

                layout.Memories.Insert(0, new Memory
                {
                    Name   = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.FLASH,
                    Start  = FLASHBase,
                    Size   = (uint)mcu.FlashSize
                });

                if (mcu.Name.StartsWith("LPC4", StringComparison.CurrentCultureIgnoreCase))
                {
                    int sram = mcu.RAMSize / 1024;
                    if ((sram == 24) || (sram == 40) || (sram == 80) || (sram == 96) || (sram == 104) || (sram == 136) || (sram == 168) || (sram == 200) || (sram == 264) || (sram == 282) || (sram == 154))
                    {
                        if ((layout.Memories[0].Size / 1024) == 0)
                        {
                            layout.Memories[0].Size = 64 * 1024;
                        }
                    }
                    else
                    {
                        throw new Exception("Unknown LPC43xx memory configuration");
                    }
                }

                if (mcu.FlashSize == 0)
                {
                    layout.Memories[0].Size = 65536;
                }

                return(layout);
            }
Пример #13
0
 internal bool Match(MCUBuilder builder) => builder.Name == _Mcu.ID;
Пример #14
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                var layout = new MemoryLayout { DeviceName = mcu.Name, Memories = new List<Memory>() };

                layout.Memories.Add(new Memory
                {
                    Name = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.FLASH,
                    Start = FLASHBase,
                    Size = (uint)mcu.FlashSize
                });

                layout.Memories.Add(new Memory
                {
                    Name = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.RAM,
                    Start = SRAMBase,
                    Size = (uint)mcu.RAMSize
                });

                return layout;
            }
Пример #15
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes.
                MemoryLayout layout = new MemoryLayout { DeviceName = mcu.Name, Memories = new List<Memory>() };

                layout.Memories.Add(new Memory
                {
                    Name = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.RAM,
                    Start = SRAMBase,
                    Size = (uint)mcu.RAMSize,
                });

                return layout;
            }
Пример #16
0
 protected override LinkerScriptTemplate GetTemplateForMCU(MCUBuilder mcu)
 {
     if (mcu.Name.StartsWith("XMC1", StringComparison.InvariantCultureIgnoreCase))
         return LDSTemplateX1;
     else
         return LDSTemplate;
 }
Пример #17
0
 public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
 {
     throw new NotImplementedException();
 }
Пример #18
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes.
                MemoryLayout layout = new MemoryLayout();
                layout.Memories = new List<Memory>();
                layout.DeviceName = mcu.Name;
                string aFileName = family.BSP.Directories.InputDir + "\\Device\\SiliconLabs\\" + family.FamilyFilePrefix.Substring(0, family.FamilyFilePrefix.Length - 1) + "\\Include\\" + mcu + ".h";
                Match m;
                Regex rg = new Regex(@"(#define RAM_MEM_BASE[ \t]*.*0x)([0-9][U][L])+.*");
                int RAMStart = 0;
                foreach (var ln in File.ReadAllLines(aFileName))
                {
                    m = Regex.Match(ln, @"#define RAM_MEM_BASE[ \t]+.*0x([\d]+)UL.*");
                    RAMStart = 0;
                    if (m.Success)
                    {
                        RAMStart = Convert.ToInt32(m.Groups[1].Value, 16);
                        break;
                    }
                }
                if (RAMStart == 0)
                    throw new Exception("no RAM Start");
                layout.Memories.Insert(0, new Memory
                {
                    Name = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.FLASH,
                    Start = FLASHBase,
                    Size = (uint)mcu.FlashSize
                });
                layout.Memories.Insert(0, new Memory
                {
                    Name = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.RAM,
                    Start = (uint)RAMStart,
                    Size = (uint)mcu.RAMSize
                });

                return layout;
            }
Пример #19
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                foreach (var kv in _SpecialMemoryLayouts)
                    if (kv.Key.IsMatch(mcu.Name))
                        return kv.Value;

                MemoryLayout layout = new MemoryLayout { DeviceName = mcu.Name, Memories = new List<Memory>() };

                    layout.Memories.Add(new Memory
                    {
                        Name = "FLASH",
                        Access = MemoryAccess.Undefined,
                        Type = MemoryType.FLASH,
                        Start = FLASHBase,
                        Size = (uint)mcu.FlashSize,
                    });

                    layout.Memories.Add(new Memory
                    {
                        Name = "SRAM",
                        Access = MemoryAccess.Undefined,
                        Type = MemoryType.RAM,
                        Start = SRAMBase,
                        Size = (uint)mcu.RAMSize,
                    });

                return layout;
            }
Пример #20
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes.
                MemoryLayout layout = new MemoryLayout();

                layout.Memories   = new List <Memory>();
                layout.DeviceName = mcu.Name;
                string shName = mcu.Name;
                string aDirSam;

                if (mcu.Name.StartsWith("AT"))
                {
                    shName = mcu.Name.Substring(2, mcu.Name.Length - 2);
                }
                if (shName.StartsWith("SAMC") || shName.StartsWith("SAMD") || shName.StartsWith("SAMR") || shName.StartsWith("SAMB") || shName.StartsWith("SAML"))
                {
                    aDirSam = "\\Sam0";
                }
                else
                {
                    aDirSam = "\\Sam";
                }
                //  EAK                if (shName == "SAMD10D13A" || shName == "SAMD10D14A" || shName == "SAMD10D12A"|| shName == "SAMD11D14A")
                //  EAK                    shName = shName + "S";//Different Device ID (DID)
                string aFileName = family.BSP.Directories.InputDir + aDirSam + "\\Utils\\Cmsis\\" + family.FamilyFilePrefix + "\\Include\\" + shName;

                if (family.FamilyFilePrefix.ToUpper().StartsWith("SAMG"))
                {
                    aFileName = family.BSP.Directories.InputDir + "\\Sam\\Utils\\Cmsis\\samg\\" + family.FamilyFilePrefix + "\\Include\\" + shName;
                }

                if (family.Definition.Name.ToUpper() == "SAM4C" || family.Definition.Name.ToUpper() == "SAM4CM" || family.Definition.Name.ToUpper() == "SAM4CP" || family.Definition.Name.ToUpper() == "SAM4CM32")
                {
                    aFileName = aFileName + "_0.h";
                }
                else
                {
                    aFileName = aFileName + ".h";
                }

                int RAMStart   = -1;
                int FLASHStart = -1;

                if (Regex.IsMatch(mcu.Name, "SAML21...B"))
                {
                    aFileName = aFileName.Replace("\\Include\\S", "\\Include_b\\S");
                }

                foreach (var ln in File.ReadAllLines(aFileName))
                {
                    //                    var m = Regex.Match(ln, @"(#define [IH]?[HS]?[HMC]*RAM[C]?[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^uU]+)+.*");
                    var m = Regex.Match(ln, @"(#define [ID]*[IH]?[HS]?[HMC]*RAM[C]?[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^uU]+[L]?)+.*");

                    if (m.Success)
                    {
                        RAMStart = Convert.ToInt32(m.Groups[2].Value, 16);
                    }

                    m = Regex.Match(ln, @"(#define [I]?FLASH[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");
                    if (!m.Success)
                    {
                        m = Regex.Match(ln, @"(#define [I]?FLASH[0]?_CNC_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");
                    }
                    if (!m.Success)
                    {
                        m = Regex.Match(ln, @"(#define BOOTROM_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");//samb11
                    }
                    if (m.Success)
                    {
                        FLASHStart = Convert.ToInt32(m.Groups[2].Value, 16);
                    }
                    if (FLASHStart > -1 && RAMStart > -1)
                    {
                        break;
                    }
                }
                if (RAMStart == -1)
                {
                    throw new Exception("no RAM Start");
                }
                //    Console.WriteLine("RAMBase mcu {0} NO file :{1} ", mcu.Name, aFileName);
                if (FLASHStart == -1)
                {
                    throw new Exception("no FLASH Start");
                }
                //   Console.WriteLine("FLASHBase mcu {0} NO file :{1} ",mcu.Name , aFileName);
                layout.Memories.Insert(0, new Memory
                {
                    Name   = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.FLASH,
                    Start  = (uint)FLASHStart,
                    Size   = (uint)mcu.FlashSize
                });
                layout.Memories.Insert(0, new Memory
                {
                    Name   = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.RAM,
                    Start  = (uint)RAMStart,
                    Size   = (uint)mcu.RAMSize
                });

                return(layout);
            }
Пример #21
0
 public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
 {
     return _mcuMemoryLayouts[mcu.Name];
 }
Пример #22
0
 private uint GetSramStart(MCUBuilder mcu)
 {
     return _mcuMemoryLayouts[mcu.Name].Memories.Where(mem => mem.Name == "SRAM").First().Start;
 }
Пример #23
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes.
                MemoryLayout layout = new MemoryLayout();
                layout.Memories = new List<Memory>();
                layout.DeviceName = mcu.Name;
                string shName = mcu.Name;
                string aDirSam;
                if (mcu.Name.StartsWith("AT"))
                    shName = mcu.Name.Substring(2, mcu.Name.Length - 2);
                if (shName.StartsWith("SAMC") || shName.StartsWith("SAMD") || shName.StartsWith("SAMR") || shName.StartsWith("SAMB") || shName.StartsWith("SAML"))
                    aDirSam = "\\Sam0";
                else
                    aDirSam = "\\Sam";
                //  EAK                if (shName == "SAMD10D13A" || shName == "SAMD10D14A" || shName == "SAMD10D12A"|| shName == "SAMD11D14A")
                //  EAK                    shName = shName + "S";//Different Device ID (DID)
                string aFileName = family.BSP.Directories.InputDir + aDirSam +"\\Utils\\Cmsis\\" + family.FamilyFilePrefix + "\\Include\\" + shName;

                if (family.FamilyFilePrefix.ToUpper().StartsWith("SAMG"))
                    aFileName = family.BSP.Directories.InputDir + "\\Sam\\Utils\\Cmsis\\samg\\" + family.FamilyFilePrefix + "\\Include\\" + shName;

                if (family.Definition.Name.ToUpper() == "SAM4C" || family.Definition.Name.ToUpper() == "SAM4CM" || family.Definition.Name.ToUpper() == "SAM4CP" || family.Definition.Name.ToUpper() == "SAM4CM32")
                    aFileName = aFileName + "_0.h";
                else
                    aFileName = aFileName + ".h";

                int RAMStart = -1;
                int FLASHStart = -1;

                if (Regex.IsMatch(mcu.Name, "SAML21...B"))
                    aFileName = aFileName.Replace("\\Include\\S", "\\Include_b\\S");

                foreach (var ln in File.ReadAllLines(aFileName))
                {
                //                    var m = Regex.Match(ln, @"(#define [IH]?[HS]?[HMC]*RAM[C]?[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^uU]+)+.*");
                    var m = Regex.Match(ln, @"(#define [ID]*[IH]?[HS]?[HMC]*RAM[C]?[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^uU]+[L]?)+.*");

                    if (m.Success)
                    {
                        RAMStart = Convert.ToInt32(m.Groups[2].Value, 16);
                    }

                    m = Regex.Match(ln, @"(#define [I]?FLASH[0]?_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");
                    if (!m.Success)
                        m = Regex.Match(ln, @"(#define [I]?FLASH[0]?_CNC_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");
                    if (!m.Success)
                        m = Regex.Match(ln, @"(#define BOOTROM_ADDR[ \t]*.*0x)([0-9A-Fa-f]+[^u|U]+)+.*");//samb11
                    if (m.Success)
                    {
                        FLASHStart = Convert.ToInt32(m.Groups[2].Value, 16);
                    }
                    if (FLASHStart > -1 && RAMStart > -1)
                        break;
                }
                if (RAMStart == -1)
                    throw new Exception("no RAM Start");
                //    Console.WriteLine("RAMBase mcu {0} NO file :{1} ", mcu.Name, aFileName);
                if (FLASHStart == -1)
                    throw new Exception("no FLASH Start");
                 //   Console.WriteLine("FLASHBase mcu {0} NO file :{1} ",mcu.Name , aFileName);
                layout.Memories.Insert(0, new Memory
                {
                    Name = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.FLASH,
                    Start = (uint)FLASHStart,
                    Size = (uint)mcu.FlashSize
                });
                layout.Memories.Insert(0, new Memory
                {
                    Name = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.RAM,
                    Start = (uint)RAMStart,
                    Size = (uint)mcu.RAMSize
                });

                return layout;
            }
Пример #24
0
 public override string GetMCUTypeMacro(MCUBuilder mcu)
 {
     return $"__{mcu.Name.Substring(2)}__";
 }
Пример #25
0
 public override string GetMCUTypeMacro(MCUBuilder mcu)
 {
     return($"__{mcu.Name.Substring(2)}__");
 }
Пример #26
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                //No additional memory information available for this MCU. Build a basic memory layout from known RAM/FLASH sizes.
                MemoryLayout layout = new MemoryLayout { DeviceName = mcu.Name, Memories = FindMemories(mcu.Name) };

                layout.Memories.Insert(0, new Memory
                {
                    Name = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.FLASH,
                    Start = FLASHBase,
                    Size = (uint)mcu.FlashSize
                });

                if (mcu.Name.StartsWith("LPC4", StringComparison.CurrentCultureIgnoreCase))
                {
                    int sram = mcu.RAMSize / 1024;
                    if ((sram == 24) || (sram == 40) || (sram == 80) || (sram == 96) || (sram == 104) || (sram == 136) || (sram == 168) || (sram == 200) || (sram == 264) || (sram == 282))
                    {
                        if ((layout.Memories[0].Size / 1024) == 0)
                            layout.Memories[0].Size = 64 * 1024;
                    }
                    else
                        throw new Exception("Unknown LPC43xx memory configuration");
                }

                if (mcu.FlashSize == 0)
                    layout.Memories[0].Size = 65536;

                return layout;
            }
Пример #27
0
            void DoGenerateLinkerScriptsAndUpdateMCU(string ldsDirectory, string familyFilePrefix, MCUBuilder mcu, MemoryLayout layout, string generalizedName, string ldsSuffix)
            {
                foreach (var sd in SoftDevices)
                {
                    if (!sd.IsCompatible(mcu.Name))
                    {
                        continue;
                    }
                    if (sd.LinkerScriptWithMaximumReservedRAM == null)
                    {
                        using (var gen = new LdsFileGenerator(LDSTemplate, layout))
                        {
                            using (var sw = new StreamWriter(Path.Combine(ldsDirectory, generalizedName + "_nosoftdev" + ldsSuffix + ".lds")))
                                gen.GenerateLdsFile(sw);
                        }

                        //IoT
                        var softdevTemplate = LDSTemplate.ShallowCopy();
                        softdevTemplate.Sections = new List <Section>(softdevTemplate.Sections);
                        softdevTemplate.Sections.Insert(0, new Section {
                            Name = ".softdevice", TargetMemory = "FLASH_SOFTDEVICE", Inputs = new List <SectionReference> {
                                new SectionReference {
                                    NamePattern = ".softdevice", Flags = SectionReferenceFlags.Keep
                                }
                            }, Fill = new FillInfo {
                                Pattern = uint.MaxValue, TotalSize = (int)sd.FLASHSize
                            }, Flags = SectionFlags.Unaligned
                        });
                        softdevTemplate.Sections.Insert(1, new Section {
                            Name = ".softdevice_sram", TargetMemory = "SRAM_SOFTDEVICE", Inputs = new List <SectionReference>(), Fill = new FillInfo {
                                Pattern = 0, TotalSize = (int)sd.SRAMSize
                            }, Flags = SectionFlags.Unaligned
                        });

                        var layoutCopy = layout.Clone();
                        var flash      = layoutCopy.Memories.First(m => m.Name == "FLASH");
                        var ram        = layoutCopy.Memories.First(m => m.Name == "SRAM");

                        if (flash.Size < sd.FLASHSize || ram.Size < sd.SRAMSize)
                        {
                            throw new Exception("Device too small for " + sd.Name);
                        }

                        layoutCopy.Memories.Insert(layoutCopy.Memories.IndexOf(flash), new Memory {
                            Name = "FLASH_SOFTDEVICE", Access = MemoryAccess.Readable | MemoryAccess.Executable, Start = flash.Start, Size = sd.FLASHSize
                        });
                        layoutCopy.Memories.Insert(layoutCopy.Memories.IndexOf(ram), new Memory {
                            Name = "SRAM_SOFTDEVICE", Access = MemoryAccess.Readable | MemoryAccess.Writable | MemoryAccess.Executable, Start = ram.Start, Size = sd.SRAMSize
                        });

                        flash.Size  -= sd.FLASHSize;
                        flash.Start += sd.FLASHSize;

                        ram.Size  -= sd.SRAMSize;
                        ram.Start += sd.SRAMSize;

                        using (var gen = new LdsFileGenerator(softdevTemplate, layoutCopy))
                        {
                            using (var sw = new StreamWriter(Path.Combine(ldsDirectory, generalizedName + "_" + sd.Name.ToLower() + ldsSuffix + ".lds")))
                                gen.GenerateLdsFile(sw, new string[] { "", "GROUP(" + sd.Name + "_softdevice.o)", "" });
                        }
                    }
                    else
                    {
                        BuildLinkerScriptBasedOnOriginalNordicScripts(ldsDirectory, generalizedName, ldsSuffix, sd);
                    }
                }
                mcu.LinkerScriptPath = $"$$SYS:BSP_ROOT$$/{familyFilePrefix}LinkerScripts/{generalizedName}_$${SoftdevicePropertyID}$$.lds";
            }
Пример #28
0
 public override void GenerateLinkerScriptsAndUpdateMCU(string ldsDirectory, string familyFilePrefix, MCUBuilder mcu, MemoryLayout layout, string generalizedName)
 {
     foreach (var sd in SoftDevices)
     {
         if (!sd.IsCompatible(mcu.Name))
         {
             continue;
         }
         if (sd.LinkerScriptWithMaximumReservedRAM == null)
         {
             //Due to the complexity of the Nordic SDK, we need to reuse the original linker scripts instead of generating them from scratch.
             throw new Exception("Could not locate the original linker script for this device.");
         }
         else
         {
             BuildLinkerScriptBasedOnOriginalNordicScripts(ldsDirectory, generalizedName, sd);
         }
     }
     mcu.LinkerScriptPath = $"$$SYS:BSP_ROOT$$/{familyFilePrefix}LinkerScripts/{generalizedName}_$${SoftdevicePropertyID}$$.lds";
 }
Пример #29
0
 public override MemoryLayoutAndSubstitutionRules GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
 {
     throw new NotSupportedException("RS14100 BSP should reuse existing linker scripts instead of generating new ones");
 }
Пример #30
0
 public override void GenerateLinkerScriptsAndUpdateMCU(string ldsDirectory, string familyFilePrefix, MCUBuilder mcu, MemoryLayout layout, string generalizedName)
 {
     base.GenerateLinkerScriptsAndUpdateMCU(ldsDirectory, familyFilePrefix, mcu, layout, generalizedName);
 }
Пример #31
0
 public override void GenerateLinkerScriptsAndUpdateMCU(string ldsDirectory, string familyFilePrefix, MCUBuilder mcu, MemoryLayout layout, string generalizedName)
 {
     base.GenerateLinkerScriptsAndUpdateMCU(ldsDirectory, familyFilePrefix, mcu, layout, generalizedName);
 }
Пример #32
0
 public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
 {
     throw new NotImplementedException();
 }
Пример #33
0
            public override string GetMCUTypeMacro(MCUBuilder mcu)
            {
                var macro = base.GetMCUTypeMacro(mcu);

                return(macro.Replace('-', '_'));
            }
Пример #34
0
 static string GetSubfamilyDefine(MCUBuilder builder)
 {
     return((builder as DeviceListProviders.CubeProvider.STM32MCUBuilder)?.MCU.Define ?? throw new Exception("Unknown primary macro for " + builder.Name));
 }
Пример #35
0
 public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
 {
     return(_mcuMemoryLayouts[mcu.Name]);
 }
Пример #36
0
 private uint GetSramStart(MCUBuilder mcu)
 {
     return(_mcuMemoryLayouts[mcu.Name].Memories.Where(mem => mem.Name == "SRAM").First().Start);
 }
Пример #37
0
            public override MemoryLayoutAndSubstitutionRules GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                MemoryLayout layout = new MemoryLayout {
                    DeviceName = mcu.Name, Memories = new List <Memory>()
                };
                string aDir        = Directories.InputDir + @"\CMSIS\Infineon\" + family.Definition.Name + @"_series\Source\GCC";
                Regex  aRgFl1      = new Regex(@"((FLASH)[ \(]+RX[\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)");
                Regex  aRgFl2      = new Regex(@"((FLASH_1_uncached)[ \(]+RX[\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)");
                Regex  aRgRam1     = new Regex(@"((SRAM)[ \(!RWX\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)");
                Regex  aRgRam3     = new Regex(@"((PSRAM_1)[ \(!RWX\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)");
                Regex  aRgRam2     = new Regex(@"((SRAM_combined)[ \(!RWX\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)");
                string aStartFlash = "";
                string aLenFlash   = "";
                string aStartRam   = "";
                string aLenRam     = "";
                int    idX         = mcu.Name.IndexOf("x");
                string longMCUName = mcu.Name.Replace("_", "-");

                string expectedScriptPath = string.Format(@"{0}\{1}x{2:d4}.ld", aDir, family.Definition.Name, mcu.Name.Substring(idX + 1));

                if (!File.Exists(expectedScriptPath))
                {
                    expectedScriptPath = string.Format(@"{0}\{1}x{2:d4}.ld", aDir, longMCUName.Substring(0, longMCUName.IndexOf('-')), mcu.Name.Substring(idX + 1));
                    if (!File.Exists(expectedScriptPath))
                    {
                        throw new Exception("Failed to find linker script for " + mcu.Name);
                    }
                }

                Regex[] sramRegexes = new Regex[] { aRgRam1, aRgRam2, aRgRam3 };
                Match[] sramMatches = new Match[sramRegexes.Length];

                foreach (var line in File.ReadAllLines(expectedScriptPath))
                {
                    // Search Flash notes
                    var m = aRgFl1.Match(line);
                    if (!m.Success)
                    {
                        m = aRgFl2.Match(line);
                    }

                    if (m.Success)
                    {
                        aStartFlash = m.Groups[3].Value;
                        aLenFlash   = m.Groups[4].Value;
                    }

                    for (int i = 0; i < sramRegexes.Length; i++)
                    {
                        if (sramMatches[i] == null)
                        {
                            m = sramRegexes[i].Match(line);
                            if (m.Success)
                            {
                                sramMatches[i] = m;
                            }
                        }
                    }

                    continue;
                }

                foreach (var m in sramMatches)
                {
                    if (m != null)
                    {
                        aStartRam = m.Groups[3].Value;
                        aLenRam   = m.Groups[4].Value;
                        break;
                    }
                }

                if (string.IsNullOrEmpty(aStartFlash) || string.IsNullOrEmpty(aLenFlash) || string.IsNullOrEmpty(aStartRam) || string.IsNullOrEmpty(aLenRam))
                {
                    throw new Exception("Failed to find FLASH/RAM parameters");
                }

                layout.Memories.Add(new Memory
                {
                    Name   = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.FLASH,
                    Start  = Convert.ToUInt32(aStartFlash, 16),
                    Size   = Convert.ToUInt32(aLenFlash, 16),
                });

                layout.Memories.Add(new Memory
                {
                    Name   = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type   = MemoryType.RAM,
                    Start  = Convert.ToUInt32(aStartRam, 16),
                    Size   = Convert.ToUInt32(aLenRam, 16),
                });

                return(new MemoryLayoutAndSubstitutionRules(layout));
            }
Пример #38
0
            public override MemoryLayout GetMemoryLayout(MCUBuilder mcu, MCUFamilyBuilder family)
            {
                MemoryLayout layout = new MemoryLayout { DeviceName = mcu.Name, Memories = new List<Memory>() };
                string aDir = Directories.InputDir + @"\CMSIS\Infineon\" + family.Definition.Name + @"_series\Source\GCC";
                Regex aRgFl1 = new Regex(@"((FLASH)[ \(]+RX[\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)");
                Regex aRgFl2 = new Regex(@"((FLASH_1_uncached)[ \(]+RX[\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)");
                Regex aRgRam1 = new Regex(@"((SRAM)[ \(!RWX\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)");
                Regex aRgRam3 = new Regex(@"((PSRAM_1)[ \(!RWX\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)");
                Regex aRgRam2 = new Regex(@"((SRAM_combined)[ \(!RWX\) :]+ORIGIN[ =]+)(0x[A-F\d]*)[ ,\t\w]+[ =]+(0x[A-F\d]*)");
                string aStartFlash = "";
                string aLenFlash = "";
                string aStartRam = "";
                string aLenRam = "";
                int idX = mcu.Name.IndexOf("x");
                string longMCUName = mcu.Name.Replace("_", "-");

                string expectedScriptPath = string.Format(@"{0}\{1}x{2:d4}.ld", aDir, family.Definition.Name, mcu.Name.Substring(idX + 1));
                if (!File.Exists(expectedScriptPath))
                {
                    expectedScriptPath = string.Format(@"{0}\{1}x{2:d4}.ld", aDir, longMCUName.Substring(0, longMCUName.IndexOf('-')), mcu.Name.Substring(idX + 1));
                    if (!File.Exists(expectedScriptPath))
                    {
                        throw new Exception("Failed to find linker script for " + mcu.Name);
                    }
                }

                Regex[] sramRegexes = new Regex[] { aRgRam1, aRgRam2, aRgRam3 };
                Match[] sramMatches = new Match[sramRegexes.Length];

                foreach (var line in File.ReadAllLines(expectedScriptPath))
                {
                    // Search Flash notes
                    var m = aRgFl1.Match(line);
                    if (!m.Success)
                        m = aRgFl2.Match(line);

                    if (m.Success)
                    {
                        aStartFlash = m.Groups[3].Value;
                        aLenFlash = m.Groups[4].Value;
                    }

                    for (int i = 0; i < sramRegexes.Length; i++)
                        if (sramMatches[i] == null)
                        {
                            m = sramRegexes[i].Match(line);
                            if (m.Success)
                                sramMatches[i] = m;
                        }

                    continue;
                }

                foreach(var m in sramMatches)
                {
                    if (m != null)
                    {
                        aStartRam = m.Groups[3].Value;
                        aLenRam = m.Groups[4].Value;
                        break;
                    }
                }

                if (string.IsNullOrEmpty(aStartFlash) || string.IsNullOrEmpty(aLenFlash) || string.IsNullOrEmpty(aStartRam) || string.IsNullOrEmpty(aLenRam))
                {
                    throw new Exception("Failed to find FLASH/RAM parameters");
                }

                layout.Memories.Add(new Memory
                {
                    Name = "FLASH",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.FLASH,
                    Start = Convert.ToUInt32(aStartFlash, 16),
                    Size = Convert.ToUInt32(aLenFlash, 16),
                });

                layout.Memories.Add(new Memory
                {
                    Name = "SRAM",
                    Access = MemoryAccess.Undefined,
                    Type = MemoryType.RAM,
                    Start = Convert.ToUInt32(aStartRam, 16),
                    Size = Convert.ToUInt32(aLenRam, 16),
                });

                return layout;
            }