From 90fbdd314ac0debe3630aee47973999387a1edee Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Tue, 17 May 2016 12:57:16 -0400 Subject: [PATCH] configtool: Add avrdude flags option to settings Some target devices need extra avrdude command line switches to get them to upload successfully. There are dozens of options which may be useful to different people. Instead of breaking all the possible options out into separate fields, provide a generic "Program Flags" text field which the user can fill in similar to the CFLAGS and LDFLAGS settings. The Arduino Mega2560 bootloader was changed[1] to report an error when asked to erase flash because it has never actually implemented erasing flash. To program this bootloader with avrdude requires the -D switch to avoid flash erase. But it seems that every arduino will work fine with -D, as evidenced by the fact that the Arduino IDE always [2] includes -D in the avrdude commandline. Presumably the flash is erased during/before programming anyway and the separate erase step is unneeded. Perhaps the -D should be always added to avrdude command line in configtool and in Makefile-AVR. But I haven't tested any other boards yet, and I'm being more cautious even though the Arduino IDE does otherwise. [1] arduino/Arduino#543 [2] https://github.com/arduino/Arduino/blob/d8e5997328b76c570c1803baef4c5399783fded0/app/src/processing/app/debug/AvrdudeUploader.java#L168 --- configtool/build.py | 6 +++--- configtool/settings.py | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/configtool/build.py b/configtool/build.py index b6ca8da..74d023c 100644 --- a/configtool/build.py +++ b/configtool/build.py @@ -419,9 +419,9 @@ class Upload(wx.Dialog): cmdpath = ScriptTools(self.settings).figureCommandPath("avrdude") hexpath = "\"" + join(self.root, "teacup.hex") + "\"" - cmd = cmdpath + " -c %s -b %s -p %s -P %s -U flash:w:%s:i" % \ - (self.settings.programmer, self.baud, self.cpu, self.settings.port, - hexpath) + cmd = cmdpath + " -c %s %s -b %s -p %s -P %s -U flash:w:%s:i" % \ + (self.settings.programmer, self.settings.programflags, self.baud, + self.cpu, self.settings.port, hexpath) self.script.append(cmd) def uploadUpdate(self, evt): diff --git a/configtool/settings.py b/configtool/settings.py index 8753413..d62caa6 100644 --- a/configtool/settings.py +++ b/configtool/settings.py @@ -12,13 +12,14 @@ CFLAGS = 1 LDFLAGS = 2 OBJCOPYFLAGS= 3 PROGRAMMER = 4 -PORT = 5 -UPLOADSPEED = 6 -NUMTEMPS = 7 -MINADC = 8 -MAXADC = 9 -T0 = 10 -R1 = 11 +PROGRAMFLAGS = 5 +PORT = 6 +UPLOADSPEED = 7 +NUMTEMPS = 8 +MINADC = 9 +MAXADC = 10 +T0 = 11 +R1 = 12 class Settings: @@ -33,6 +34,7 @@ class Settings: self.ldflags = "" self.objcopyflags = "" self.programmer = "wiring" + self.programflags = "" self.port = "/dev/ttyACM0" self.uploadspeed = 38400 @@ -66,6 +68,8 @@ class Settings: self.port = value elif opt == "objcopyflags": self.objcopyflags = value + elif opt == "programflags": + self.programflags = value elif opt == "t0": self.t0 = value elif opt == "r1": @@ -95,6 +99,7 @@ class Settings: self.cfg.set(self.section, "ldflags", str(self.ldflags)) self.cfg.set(self.section, "objcopyflags", str(self.objcopyflags)) self.cfg.set(self.section, "programmer", str(self.programmer)) + self.cfg.set(self.section, "programflags", str(self.programflags)) self.cfg.set(self.section, "port", str(self.port)) self.cfg.set(self.section, "t0", str(self.t0)) self.cfg.set(self.section, "r1", str(self.r1)) @@ -139,6 +144,7 @@ class SettingsDlg(wx.Dialog): htLDFlags = "Flags passed to avr-gcc to be passed on to the linker." htObjCopy = "Flags passed to avr-objcopy." htProgrammer = "The programmer type - passed to avrdude." + htProgramFlags = "Extra flags passed to avrdude." htPort = "The port to which the controller is connected. Typically a " \ "path starting with /dev/... on Linux or Mac OS X, or some " \ "COM... on Windows." @@ -159,6 +165,7 @@ class SettingsDlg(wx.Dialog): ["LD Flags", settings.ldflags, htLDFlags], ["Object Copy Flags", settings.objcopyflags, htObjCopy], ["AVR Programmer", settings.programmer, htProgrammer], + ["AVR Upload Flags", settings.programflags, htProgramFlags], ["Port", settings.port, htPort], ["Upload Speed", settings.uploadspeed, htSpeed], ["Number of Temps", settings.numTemps, htNumTemps], @@ -244,6 +251,7 @@ class SettingsDlg(wx.Dialog): self.settings.ldflags = self.teList[LDFLAGS].GetValue() self.settings.objcopyflags = self.teList[OBJCOPYFLAGS].GetValue() self.settings.programmer = self.teList[PROGRAMMER].GetValue() + self.settings.programflags = self.teList[PROGRAMFLAGS].GetValue() self.settings.port = self.teList[PORT].GetValue() self.settings.uploadspeed = self.teList[UPLOADSPEED].GetValue() self.settings.numTemps = self.teList[NUMTEMPS].GetValue()