From 5360fa729d7cd6425e11b1b2283c034beeaa47b3 Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Thu, 21 Jun 2007 23:00:31 +0000 Subject: [PATCH] Initial version of the avrdude uploader (only supports uploading, not burning the bootloader). --- app/AvrdudeUploader.java | 141 ++++++++++++++++++ app/Sketch.java | 2 +- .../macosx/Arduino.xcodeproj/project.pbxproj | 8 + todo.txt | 2 +- 4 files changed, 151 insertions(+), 2 deletions(-) create mode 100755 app/AvrdudeUploader.java diff --git a/app/AvrdudeUploader.java b/app/AvrdudeUploader.java new file mode 100755 index 000000000..6d8537b6e --- /dev/null +++ b/app/AvrdudeUploader.java @@ -0,0 +1,141 @@ +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + AvrdudeUploader - uploader implementation using avrdude + Part of the Arduino project - http://www.arduino.cc/ + + Copyright (c) 2004-05 + Hernando Barragan + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + $Id$ +*/ + +package processing.app; +import java.io.*; +import java.util.*; +import java.util.zip.*; +import javax.swing.*; +import gnu.io.*; + + +public class AvrdudeUploader extends Uploader { + public AvrdudeUploader() { + } + + public boolean uploadUsingPreferences(String buildPath, String className) + throws RunnerException { + List commandDownloader = new ArrayList(); + String programmer = Preferences.get("upload.programmer"); + + // avrdude wants "stk500v1" to distinguish it from stk500v2 + if (programmer.equals("stk500")) + programmer = "stk500v1"; + + // avrdude doesn't want to read device signatures (it always gets + // 0x000000); force it to continue uploading anyway + commandDownloader.add("-F"); + commandDownloader.add("-c" + programmer); + if (Preferences.get("upload.programmer").equals("dapa")) { + // avrdude doesn't need to be told the address of the parallel port + //commandDownloader.add("-dlpt=" + Preferences.get("parallel.port")); + } else { + commandDownloader.add( + "-P" + (Base.isWindows() ? + "/dev/" + Preferences.get("serial.port").toLowerCase() : + Preferences.get("serial.port"))); + commandDownloader.add( + "-b" + Preferences.getInteger("serial.download_rate")); + } + if (Preferences.getBoolean("upload.erase")) + commandDownloader.add("-e"); + else + commandDownloader.add("-D"); + if (!Preferences.getBoolean("upload.verify")) + commandDownloader.add("-V"); + commandDownloader.add("-Uflash:w:" + buildPath + File.separator + className + ".hex"); + return uisp(commandDownloader); + } + + public boolean burnBootloaderAVRISP() throws RunnerException { + List commandDownloader = new ArrayList(); + commandDownloader.add("-dprog=" + Preferences.get("bootloader.programmer")); + commandDownloader.add( + "-dserial=" + (Base.isWindows() ? + "/dev/" + Preferences.get("serial.port").toLowerCase() : + Preferences.get("serial.port"))); + commandDownloader.add("-dspeed=" + Preferences.get("serial.burn_rate")); + return burnBootloader(commandDownloader); + } + + public boolean burnBootloaderParallel() throws RunnerException { + List commandDownloader = new ArrayList(); + commandDownloader.add("-dprog=dapa"); + commandDownloader.add("-dlpt=" + Preferences.get("parallel.port")); + return burnBootloader(commandDownloader); + } + + protected boolean burnBootloader(Collection params) throws RunnerException { + // I know this is ugly; apologies - that's what happens when you try to + // write Lisp-style code in Java. + return + // unlock bootloader segment of flash memory + uisp(params, Arrays.asList(new String[] { + "--wr_lock=" + Preferences.get("bootloader.unlock_bits") })) && + // write fuses: + // bootloader size of 512 words; from 0xE00-0xFFF + // clock speed of 16 MHz, external quartz + uisp(params, Arrays.asList(new String[] { + "--wr_fuse_l=" + Preferences.get("bootloader.low_fuses"), + "--wr_fuse_h=" + Preferences.get("bootloader.high_fuses") })) && + // upload bootloader + uisp(params, Arrays.asList(new String[] { + "--erase", "--upload", "--verify", + "if=" + Preferences.get("bootloader.path") + File.separator + + Preferences.get("bootloader.file") })) && + // lock bootloader segment + uisp(params, Arrays.asList(new String[] { + "--wr_lock=" + Preferences.get("bootloader.lock_bits") })); + } + + public boolean uisp(Collection p1, Collection p2) throws RunnerException { + ArrayList p = new ArrayList(p1); + p.addAll(p2); + return uisp(p); + } + + public boolean uisp(Collection params) throws RunnerException { + flushSerialBuffer(); + + List commandDownloader = new ArrayList(); + commandDownloader.add("avrdude"); + if (Preferences.getBoolean("upload.verbose")) { + commandDownloader.add("-v"); + commandDownloader.add("-v"); + commandDownloader.add("-v"); + commandDownloader.add("-v"); + } else { + commandDownloader.add("-q"); + commandDownloader.add("-q"); + } + // XXX: quick hack to chop the "atmega" off of "atmega8" and "atmega168", + // then shove an "m" at the beginning. won't work for attiny's, etc. + commandDownloader.add("-pm" + Preferences.get("build.mcu").substring(6)); + commandDownloader.addAll(params); + + return executeUploadCommand(commandDownloader); + } +} diff --git a/app/Sketch.java b/app/Sketch.java index ba52b0b2a..4613bfc53 100644 --- a/app/Sketch.java +++ b/app/Sketch.java @@ -1675,7 +1675,7 @@ public class Sketch { // download the program // - Uploader uploader = new UispUploader(); + Uploader uploader = new AvrdudeUploader(); // macos9 now officially broken.. see PdeCompilerJavac //PdeCompiler compiler = // ((PdeBase.platform == PdeBase.MACOS9) ? diff --git a/build/macosx/Arduino.xcodeproj/project.pbxproj b/build/macosx/Arduino.xcodeproj/project.pbxproj index 8a3e0d319..6cb5b20bc 100644 --- a/build/macosx/Arduino.xcodeproj/project.pbxproj +++ b/build/macosx/Arduino.xcodeproj/project.pbxproj @@ -247,6 +247,8 @@ 33CF03CE09662DC000F2C9A9 /* antlr.jar in CopyFiles */ = {isa = PBXBuildFile; fileRef = 33AF620A0965D67800B514A9 /* antlr.jar */; settings = {JAVA_ARCHIVE_SUBDIR = ../shared/lib; }; }; 33CF03CF09662DC000F2C9A9 /* registry.jar in CopyFiles */ = {isa = PBXBuildFile; fileRef = 33AF620E0965D67A00B514A9 /* registry.jar */; settings = {JAVA_ARCHIVE_SUBDIR = ../shared/lib; }; }; 33CF03D009662DC000F2C9A9 /* oro.jar in CopyFiles */ = {isa = PBXBuildFile; fileRef = 33AF620D0965D67900B514A9 /* oro.jar */; settings = {JAVA_ARCHIVE_SUBDIR = ../shared/lib; }; }; + 33F9446D0C2B2F6F0093EB9C /* UispUploader.java in Sources */ = {isa = PBXBuildFile; fileRef = 33F9446B0C2B2F6F0093EB9C /* UispUploader.java */; }; + 33F944E10C2B33560093EB9C /* AvrdudeUploader.java in Sources */ = {isa = PBXBuildFile; fileRef = 33F944E00C2B33560093EB9C /* AvrdudeUploader.java */; }; 33FF07100965BF8A0016AC38 /* burn.command in CopyFiles */ = {isa = PBXBuildFile; fileRef = 33FFFEAF0965BD110016AC38 /* burn.command */; }; 33FF071F0965C1E30016AC38 /* about.jpg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 33FF01DE0965BD160016AC38 /* about.jpg */; }; 33FF07220965C1E30016AC38 /* buttons.gif in CopyFiles */ = {isa = PBXBuildFile; fileRef = 33FF02770965BD160016AC38 /* buttons.gif */; }; @@ -429,6 +431,8 @@ 33BEE0CD09D7446100430D5B /* Library.java */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.java; path = Library.java; sourceTree = ""; }; 33CF03B009662CA800F2C9A9 /* arduino.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = arduino.icns; path = dist/arduino.icns; sourceTree = ""; }; 33DD8FB6096AC8DA0013AF8F /* Arduino.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Arduino.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 33F9446B0C2B2F6F0093EB9C /* UispUploader.java */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.java; path = UispUploader.java; sourceTree = ""; }; + 33F944E00C2B33560093EB9C /* AvrdudeUploader.java */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.java; path = AvrdudeUploader.java; sourceTree = ""; }; 33FF01DE0965BD160016AC38 /* about.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = about.jpg; sourceTree = ""; }; 33FF02770965BD160016AC38 /* buttons.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = buttons.gif; sourceTree = ""; }; 33FF02780965BD160016AC38 /* icon.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = icon.gif; sourceTree = ""; }; @@ -637,6 +641,8 @@ 33FFFE220965BD100016AC38 /* app */ = { isa = PBXGroup; children = ( + 33F944E00C2B33560093EB9C /* AvrdudeUploader.java */, + 33F9446B0C2B2F6F0093EB9C /* UispUploader.java */, 33BEE0CD09D7446100430D5B /* Library.java */, 33BEDDB009D6DC1300430D5B /* LibraryManager.java */, 33FFFE240965BD100016AC38 /* Base.java */, @@ -1022,6 +1028,8 @@ 33BEDDD509D6E8D800430D5B /* Archiver.java in Sources */, 33BEDDD609D6E8D800430D5B /* ExportFolder.java in Sources */, 33BEE0CE09D7446100430D5B /* Library.java in Sources */, + 33F9446D0C2B2F6F0093EB9C /* UispUploader.java in Sources */, + 33F944E10C2B33560093EB9C /* AvrdudeUploader.java in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/todo.txt b/todo.txt index 88faade4c..05e7f8e56 100644 --- a/todo.txt +++ b/todo.txt @@ -1 +1 @@ -0008 arduino +0009 arduino