Example #1
0
        private void addWriteFuses()
        {
            MCU mcu = mainForm.mcu;

            if (mcu != null)
            {
                if (mcu.memoryTypes.Contains("lfuse"))
                {
                    makeWriteFuseLock(Avrdude.FuseLockType.Lfuse, mainForm.lowFuse);
                }
                if (mcu.memoryTypes.Contains("hfuse"))
                {
                    makeWriteFuseLock(Avrdude.FuseLockType.Hfuse, mainForm.highFuse);
                }
                if (mcu.memoryTypes.Contains("efuse"))
                {
                    makeWriteFuseLock(Avrdude.FuseLockType.Efuse, mainForm.exFuse);
                }
                if (mcu.memoryTypes.Contains("fuse"))
                {
                    makeWriteFuseLock(Avrdude.FuseLockType.Fuse, mainForm.lowFuse);
                }
            }

            // TODO what if MCU doesnt have any of these fuses?
        }
Example #2
0
        private void savePart(bool isProgrammer, string parentId, string id, string desc, string signature, int flash, int eeprom)
        {
            if (id != null)
            {
                if (isProgrammer)
                {
                    // Find parent
                    Programmer parent = null;
                    if (parentId != null)
                    {
                        parent = _programmers.Find(m => m.id == parentId);
                    }

                    _programmers.Add(new Programmer(id, desc, parent));
                }
                else
                {
                    if (!id.StartsWith(".") && !desc.StartsWith("deprecated")) // Part is a common value thing or deprecated
                    {
                        // Some formatting
                        desc = desc.ToUpper().Replace("XMEGA", "xmega").Replace("MEGA", "mega").Replace("TINY", "tiny");

                        // Find parent
                        MCU parent = null;
                        if (parentId != null)
                        {
                            parent = _mcus.Find(m => m.id == parentId);
                        }

                        // Add to MCUs
                        _mcus.Add(new MCU(id, desc, signature, flash, eeprom, parent));
                    }
                }
            }
        }
Example #3
0
        private void savePart(bool isProgrammer, string parentId, string id, string desc, string signature, int flash, int eeprom, List <string> memoryTypes)
        {
            if (id != null)
            {
                if (isProgrammer)
                {
                    // Find parent
                    Programmer parent = null;
                    if (parentId != null)
                    {
                        parent = _programmers.Find(m => m.id == parentId);
                    }

                    _programmers.Add(new Programmer(id, desc, parent));
                }
                else
                {
                    // Some formatting
                    desc = desc.ToUpper().Replace("XMEGA", "xmega").Replace("MEGA", "mega").Replace("TINY", "tiny");

                    // Find parent
                    MCU parent = null;
                    if (parentId != null)
                    {
                        parent = _mcus.Find(m => m.id == parentId);
                    }

                    // Add to MCUs
                    _mcus.Add(new MCU(id, desc, signature, flash, eeprom, parent, memoryTypes));
                }
            }
        }
Example #4
0
 public MCU(string name, string fullName = "", string signature = "", int flash = 0, int eeprom = 0, MCU parent = null)
     : base(name, fullName)
 {
     this.signature = signature.ToLower();
     this.flash     = flash;
     this.eeprom    = eeprom;
     this.parent    = parent;
 }
Example #5
0
 public MCU(string name, string fullName = "", string signature = "", int flash = 0, int eeprom = 0, MCU parent = null)
     : base(name, fullName)
 {
     this.signature = signature.ToLower();
     this.flash = flash;
     this.eeprom = eeprom;
     this.parent = parent;
 }
Example #6
0
        // Got MCU info
        private void detectComplete(object param)
        {
            string log = outputLog.ToLower();

            // Look for string
            int pos = log.IndexOf("device signature");

            if (pos > -1)
            {
                // Cut out line
                log = log.Substring(pos);
                log = log.Substring(0, log.IndexOf(Environment.NewLine));

                // Split by =
                string[] signature = log.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);

                // Check split result
                if (signature.Length == 2 && signature[0].Trim() == "device signature")
                {
                    // Remove 0x and spaces from signature
                    string detectedSignature = signature[1].Trim(new char[] { ' ', '"', ';' }).Replace("0x", "").Replace(" ", "");

                    // Found something
                    if (detectedSignature != "")
                    {
                        // Look for MCU with same signature
                        MCU m = mcus.Find(s => s.signature == detectedSignature);

                        if (m != null) // Found
                        {
                            if (OnDetectedMCU != null)
                            {
                                OnDetectedMCU(this, new DetectedMCUEventArgs(m));
                            }
                        }
                        else // Not found
                        {
                            // TODO: dont write to console here
                            //m = new MCU(null, null, detectedSignature);
                            Util.consoleWrite("Unknown signature " + detectedSignature + Environment.NewLine);
                        }

                        return;
                    }
                }
            }

            if (OnDetectedMCU != null)
            {
                OnDetectedMCU(this, new DetectedMCUEventArgs(null));
            }
        }
Example #7
0
        //Load 3devo Default settings
        public void LoadFilamentMakerDefaults()
        {
            prog               = new Programmer("arduino");
            mcu                = new MCU("m2560");
            port               = "";
            baudRate           = "115200";
            flashFileFormat    = "i";
            flashFileOperation = "w";

            force               = false;
            disableVerify       = true;
            disableFlashErase   = false;
            eraseFlashAndEEPROM = false;
            doNotWrite          = false;
            verbosity           = 1;
        }
Example #8
0
        // Got MCU info
        private void detectComplete(object param)
        {
            string log = outputLog.ToLower();

            // Look for string
            int pos = log.IndexOf("device signature");

            if (pos > -1)
            {
                // Remove upto "device signature" line
                log = log.Substring(pos);

                int sigStart = log.IndexOf("0x"); // Look for signature hex value
                if (sigStart > -1)
                {
                    // Get the 6 hex digits
                    string detectedSignature = log.Substring(sigStart + 2, 6);

                    // Look for MCU with same signature
                    MCU m = mcus.Find(s => s.signature == detectedSignature);

                    if (m != null) // Found
                    {
                        if (OnDetectedMCU != null)
                        {
                            OnDetectedMCU(this, new DetectedMCUEventArgs(m));
                        }
                    }
                    else // Not found
                    {
                        // TODO: dont write to console here
                        //m = new MCU(null, null, detectedSignature);
                        Util.consoleError("_UNKNOWNSIG", detectedSignature);
                    }

                    return;
                }
            }

            if (OnDetectedMCU != null)
            {
                OnDetectedMCU(this, new DetectedMCUEventArgs(null));
            }
        }
Example #9
0
        public string[] editFuseAndLocks(MCU mcu, string[] fuses)
        {
            Text = string.Format(Language.Translation.get("_TITLE_FUSEANDLOCKBITS"), mcu.desc, mcu.signature.ToUpper());

            lblCarefulNow.Visible = !FusesList.fl.isSupported(mcu.signature);

            string[] lfd = FusesList.fl.getLfuse(mcu.signature).Split(',');
            string[] hfd = FusesList.fl.getHfuse(mcu.signature).Split(',');
            string[] efd = FusesList.fl.getEfuse(mcu.signature).Split(',');
            string[] lbd = FusesList.fl.getLockBits(mcu.signature).Split(',');

            string lf = hex2binary(fuses[0]);
            string hf = hex2binary(fuses[1]);
            string ef = hex2binary(fuses[2]);
            string lb = hex2binary(fuses[3]);

            for (int i = 7; i >= 0; i--)
            {
                btnLFuse[i].Text   = lf.Substring(7 - i, 1);
                btnHFuse[i].Text   = hf.Substring(7 - i, 1);
                btnEFuse[i].Text   = ef.Substring(7 - i, 1);
                cbLBits[i].Checked = (lb.Substring(7 - i, 1) == "0");

                lbLB[i].Text = lbd[i];
                lbLF[i].Text = lfd[i];
                lbHF[i].Text = hfd[i];
                lbEF[i].Text = efd[i];

                btnLFuse[i].Enabled = (lfd[i] != "");
                btnHFuse[i].Enabled = (hfd[i] != "");
                btnEFuse[i].Enabled = (efd[i] != "");
                cbLBits[i].Enabled  = (lbd[i] != "");
            }

            generateFusesAndLocks();

            if (ShowDialog() == DialogResult.OK)
            {
                return(newFuses);
            }

            return(null);
        }
Example #10
0
        public string[] editFuseAndLocks(MCU mcu, string[] fuses)
        {
            Text = "Fuse & lock bits: " + mcu.fullName + " (" + mcu.signature.ToUpper() + ")";

            lblCarefulNow.Visible = !FusesList.fl.isSupported(mcu.signature);

            string[] lfd = FusesList.fl.getLfuse(mcu.signature).Split(',');
            string[] hfd = FusesList.fl.getHfuse(mcu.signature).Split(',');
            string[] efd = FusesList.fl.getEfuse(mcu.signature).Split(',');
            string[] lbd = FusesList.fl.getLockBits(mcu.signature).Split(',');

            string lf = hex2binary(fuses[0]);
            string hf = hex2binary(fuses[1]);
            string ef = hex2binary(fuses[2]);
            string lb = hex2binary(fuses[3]);

            for (int i = 7; i >= 0; i--)
            {
                btnLFuse[i].Text   = lf.Substring(7 - i, 1);
                btnHFuse[i].Text   = hf.Substring(7 - i, 1);
                btnEFuse[i].Text   = ef.Substring(7 - i, 1);
                cbLBits[i].Checked = (lb.Substring(7 - i, 1) == "0");

                lbLB[i].Text = lbd[i];
                lbLF[i].Text = lfd[i];
                lbHF[i].Text = hfd[i];
                lbEF[i].Text = efd[i];

                btnLFuse[i].Enabled = (lfd[i] != "");
                btnHFuse[i].Enabled = (hfd[i] != "");
                btnEFuse[i].Enabled = (efd[i] != "");
                cbLBits[i].Enabled  = (lbd[i] != "");
            }

            generateFusesAndLocks();

            if (ShowDialog() == DialogResult.OK)
            {
                return(newFuses);
            }

            return(null);
        }
Example #11
0
        public string[] editFuseAndLocks(MCU mcu, string[] fuses)
        {
            Text = "Fuse & lock bits: " + mcu.fullName + " (" + mcu.signature.ToUpper() + ")";

            lblCarefulNow.Visible = !FusesList.fl.isSupported(mcu.signature);

            string[] lfd = FusesList.fl.getLfuse(mcu.signature).Split(',');
            string[] hfd = FusesList.fl.getHfuse(mcu.signature).Split(',');
            string[] efd = FusesList.fl.getEfuse(mcu.signature).Split(',');
            string[] lbd = FusesList.fl.getLockBits(mcu.signature).Split(',');

            string lf = hex2binary(fuses[0]);
            string hf = hex2binary(fuses[1]);
            string ef = hex2binary(fuses[2]);
            string lb = hex2binary(fuses[3]);

            for (int i = 7; i >= 0; i--)
            {
                btnLFuse[i].Text = lf.Substring(7 - i, 1);
                btnHFuse[i].Text = hf.Substring(7 - i, 1);
                btnEFuse[i].Text = ef.Substring(7 - i, 1);
                cbLBits[i].Checked = (lb.Substring(7 - i, 1) == "0");

                lbLB[i].Text = lbd[i];
                lbLF[i].Text = lfd[i];
                lbHF[i].Text = hfd[i];
                lbEF[i].Text = efd[i];

                btnLFuse[i].Enabled = (lfd[i] != "");
                btnHFuse[i].Enabled = (hfd[i] != "");
                btnEFuse[i].Enabled = (efd[i] != "");
                cbLBits[i].Enabled = (lbd[i] != "");
            }

            generateFusesAndLocks();

            if(ShowDialog() == DialogResult.OK)
                return newFuses;

            return null;
        }
Example #12
0
 public DetectedMCUEventArgs(MCU m)
 {
     mcu = m;
 }
Example #13
0
 public DetectedMCUEventArgs(MCU m)
 {
     mcu = m;
 }
Example #14
0
        // Basic parsing of avrdude.conf to get programmers & MCUs
        private void LoadConfig(string confLoc)
        {
            string conf_loc = null;

            if (!String.IsNullOrEmpty(confLoc))
            {
                conf_loc = Path.Combine(confLoc, FILE_AVRDUDECONF);
            }
            else
            {
                // If on Unix check /etc/ and /usr/local/etc/ first
                if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    conf_loc = "/etc/" + FILE_AVRDUDECONF;
                    if (!File.Exists(conf_loc))
                    {
                        conf_loc = "/usr/local/etc/" + FILE_AVRDUDECONF;
                        if (!File.Exists(conf_loc))
                        {
                            conf_loc = null;
                        }
                    }
                }

                if (conf_loc == null)
                {
                    conf_loc = Path.Combine(AssemblyData.directory, FILE_AVRDUDECONF);
                    if (!File.Exists(conf_loc))
                    {
                        conf_loc = Path.Combine(Directory.GetCurrentDirectory(), FILE_AVRDUDECONF);
                    }
                }
            }

            // Config file not found
            if (String.IsNullOrEmpty(conf_loc) || !File.Exists(conf_loc))
            {
                throw new System.IO.FileNotFoundException(FILE_AVRDUDECONF + " is not found in the application folder.");
                return;
            }

            // Load config
            string[] lines;
            try {
                lines = File.ReadAllLines(conf_loc);
            }
            catch (Exception ex) {
                MsgBox.error("Error reading " + FILE_AVRDUDECONF, ex);
                return;
            }

            char[] trimChars = new char[3] {
                ' ', '"', ';'
            };

            for (int i = 0; i < lines.Length - 3; i++)
            {
                string s = lines[i].Trim();

                bool isProgrammer = s.StartsWith("programmer");
                bool isPart       = s.StartsWith("part");
                if (!isPart && !isProgrammer)
                {
                    continue;
                }

                // Get parent ID
                string partentId = null;
                if (isPart && s.Contains("parent"))
                {
                    string[] parts = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length > 2)
                    {
                        partentId = parts[2].Trim(trimChars);
                    }
                }

                i++; // next line
                     // Does line have id key?
                int pos = lines[i].IndexOf('=');
                if (pos < 0 || lines[i].Substring(1, pos - 1).Trim() != "id")
                {
                    continue;
                }

                // Get ID value
                string id = lines[i].Substring(pos + 1).Trim(trimChars);

                i++; // next line
                     // Does line have desc key?
                pos = lines[i].IndexOf('=');
                if (pos < 0 || lines[i].Substring(1, pos - 1).Trim() != "desc")
                {
                    continue;
                }

                // Get description value
                string desc = lines[i].Substring(pos + 1).Trim(trimChars);

                // If its a programmer then add to programmers and go back to the top
                if (isProgrammer)
                {
                    _programmers.Add(new Programmer(id, desc));
                    continue;
                }

                // Otherwise its an MCU

                // Part is a common value thing or deprecated
                if (id.StartsWith(".") || desc.StartsWith("deprecated"))
                {
                    continue;
                }

                // Here we get the MCU signature, flash and EEPROM sizes

                string       signature = "";
                int          flash     = -1;
                int          eeprom    = -1;
                ParseMemType memType   = ParseMemType.None;

                // Loop through lines looking for "signature" and "memory"
                // Abort if "part" or "programmer" is found
                for ( ; i < lines.Length; i++)
                {
                    s = lines[i].Trim();

                    // Too far
                    if (s.StartsWith("part") || s.StartsWith("programmer"))
                    {
                        i--;
                        break;
                    }

                    // Found memory section
                    if (s.StartsWith("memory"))
                    {
                        pos = lines[i].IndexOf('"');
                        if (pos > -1)
                        {
                            // What type of memory is this?
                            string mem = lines[i].Substring(pos - 1).Trim(trimChars).ToLower();
                            if (mem == "flash")
                            {
                                memType = ParseMemType.Flash;
                            }
                            else if (mem == "eeprom")
                            {
                                memType = ParseMemType.Eeprom;
                            }
                        }
                    }
                    else if (memType != ParseMemType.None)
                    {
                        // See if this line defines the memory size
                        pos = lines[i].IndexOf('=');
                        if (pos > -1 && lines[i].Substring(1, pos - 1).Trim() == "size")
                        {
                            // Get size value
                            string memStr = lines[i].Substring(pos + 1).Trim(trimChars);

                            // Parse to int
                            int memTmp = 0;
                            if (!int.TryParse(memStr, out memTmp))
                            {
                                // Probably hex
                                if (memStr.StartsWith("0x"))
                                {
                                    memStr = memStr.Substring(2); // Remove 0x
                                }
                                int.TryParse(memStr, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out memTmp);
                            }

                            if (memType == ParseMemType.Flash)
                            {
                                flash = memTmp;
                            }
                            else if (memType == ParseMemType.Eeprom)
                            {
                                eeprom = memTmp;
                            }

                            memType = ParseMemType.None;
                        }
                    }

                    // Does line have signature key?
                    pos = lines[i].IndexOf('=');
                    if (pos > -1 && lines[i].Substring(1, pos - 1).Trim() == "signature")
                    {
                        // Get signature value
                        signature = lines[i].Substring(pos + 1).Trim(trimChars);

                        // Remove 0x and spaces from signature (0xAA 0xAA 0xAA -> AAAAAA)
                        signature = signature.Replace("0x", "").Replace(" ", "");
                    }
                }

                // Some formatting
                desc = desc.ToUpper().Replace("XMEGA", "xmega").Replace("MEGA", "mega").Replace("TINY", "tiny");

                // Find parent
                MCU parent = null;
                if (partentId != null)
                {
                    parent = _mcus.Find(m => m.name == partentId);
                }

                // Add to MCUs
                _mcus.Add(new MCU(id, desc, signature, flash, eeprom, parent));
            }
        }
Example #15
0
 public MCU(string id, string desc = null, string signature = null, int flash = 0, int eeprom = 0, MCU parent = null, List <string> memoryTypes = null)
     : base(id, desc, parent)
 {
     if (signature != null)
     {
         this.signature = signature.ToLower();
     }
     this.flash   = flash;
     this.eeprom  = eeprom;
     _memoryTypes = (memoryTypes != null) ? memoryTypes : new List <string>();
 }