Skip to content

Add support for avrdude -Pavrdoper #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion app/src/processing/app/Sketch.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
package processing.app;

import processing.app.debug.AvrdudeUploader;
import processing.app.debug.BasicUploader;
import processing.app.debug.Compiler;
import processing.app.debug.RunnerException;
import processing.app.debug.Sizer;
import processing.app.debug.Target;
import processing.app.debug.Uploader;
import processing.app.preproc.*;
import processing.core.*;
Expand Down Expand Up @@ -1694,6 +1696,39 @@ protected void size(String buildPath, String suggestedClassName)
_("Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it."));
}

/**
* Get the appropriate Uploader class to use.
*
* Currently this defaults to AvrdudeUploader.
* If you are using a programmer which has "programmer.uploader=basic", use BasicUploader
*/
private Uploader getUploader(boolean usingProgrammer) {

// if no protocol is specified for this board, assume it lacks a
// bootloader and upload using the selected programmer.
//
Map<String, String> boardPreferences = Base.getBoardPreferences();
if (usingProgrammer || boardPreferences.get("upload.protocol") == null) {
String programmer = Preferences.get("programmer");
Target target = Base.getTarget();

if (programmer.indexOf(":") != -1) {
target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":")));
programmer = programmer.substring(programmer.indexOf(":") + 1);
}
Map<String, String> programmerPreferences = target.getProgrammers().get(programmer);

// If the programmer has "programmer.uploader=basic" specified, use the BasicUploader
//
if ("basic".equals(programmerPreferences.get("uploader"))) {
return new BasicUploader();
}
}

// Use AvrdudeUploader by default.
//
return new AvrdudeUploader();
}

protected String upload(String buildPath, String suggestedClassName, boolean usingProgrammer)
throws RunnerException, SerialException {
Expand All @@ -1702,7 +1737,7 @@ protected String upload(String buildPath, String suggestedClassName, boolean usi

// download the program
//
uploader = new AvrdudeUploader();
uploader = getUploader(usingProgrammer);
boolean success = uploader.uploadUsingPreferences(buildPath,
suggestedClassName,
usingProgrammer);
Expand Down
2 changes: 2 additions & 0 deletions app/src/processing/app/debug/AvrdudeUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ private Collection getProgrammerCommands(Target target, String programmer) {
if (programmerPreferences.get("speed") != null) {
params.add("-b" + Integer.parseInt(programmerPreferences.get("speed")));
}
} else if ("avrdoper".equals(programmerPreferences.get("communication"))) {
params.add("-Pavrdoper");
}
// XXX: add support for specifying the port address for parallel
// programmers, although avrdude has a default that works in most cases.
Expand Down
120 changes: 120 additions & 0 deletions app/src/processing/app/debug/BasicUploader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */

/*
BasicUploader - basic uploader implementation
Part of the Arduino project - http://www.arduino.cc/

Copyright (c) 2012
Andrew Dalgleish

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.debug;

import processing.app.Base;
import processing.app.Preferences;
import processing.app.Serial;
import processing.app.SerialException;

import java.io.*;
import java.util.*;
import java.util.zip.*;
import javax.swing.*;
import gnu.io.*;


public class BasicUploader extends Uploader {
public BasicUploader() {
}

public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer)
throws RunnerException, SerialException {
this.verbose = verbose;


// if no protocol is specified for this board, assume it lacks a
// bootloader and upload using the selected programmer.
Map<String, String> boardPreferences = Base.getBoardPreferences();
if (!usingProgrammer && boardPreferences.get("upload.protocol") != null) {
// We should never get here - BasicUploader is only for using a programmer
return false;
}

String programmer = Preferences.get("programmer");
Target target = Base.getTarget();

if (programmer.indexOf(":") != -1) {
target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":")));
programmer = programmer.substring(programmer.indexOf(":") + 1);
}
Map<String, String> programmerPreferences = target.getProgrammers().get(programmer);

String command = programmerPreferences.get("uploader.basic.command");
String parameters = programmerPreferences.get("uploader.basic.parameters");

List commandList = new ArrayList();

// Try our tools directories first, else assume the command includes the full path
//
if ((new File(Base.getHardwarePath() + "/tools/" + command)).exists()) {
commandList.add(Base.getHardwarePath() + "/tools/" + command);
} else if ((new File(Base.getHardwarePath() + "/tools/avr/bin/" + command)).exists()) {
commandList.add(Base.getHardwarePath() + "/tools/avr/bin/" + command);
} else {
commandList.add(command);
}

// If we have any parameters, split them using the first character
// This lets us define any character for the separator, but you always need at least one.
// For example:
// |param1
// /param1/param2
//
if (parameters != null) {

// Get the first character to use as a separator, and remove it
//
String separator = parameters.substring(0, 1);
parameters = parameters.substring(1);

// While we have another separator, split the first part off and remember the rest
//
while (parameters.indexOf(separator) != -1) {
commandList.add(parameters.substring(0, parameters.indexOf(separator)));
parameters = parameters.substring(parameters.indexOf(separator)+1);
}

// If we have any left, use it
//
if (parameters != null) {
commandList.add(parameters);
}
}

// Add our hex file as the last parameter
commandList.add(buildPath + File.separator + className + ".hex");

return executeUploadCommand(commandList);
}

public boolean burnBootloader() throws RunnerException {
// BasicUploader does not handle burning a bootloader
return false;
}

}
11 changes: 11 additions & 0 deletions hardware/arduino/programmers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ arduinoisp.name=Arduino as ISP
arduinoisp.communication=serial
arduinoisp.protocol=stk500v1
arduinoisp.speed=19200

# AVR-Doper using HID
avrdoper.name=AVR-Doper
avrdoper.communication=avrdoper
avrdoper.protocol=stk500v2

# bootloadHID
bootloadhid.name=bootloadHID
bootloadhid.uploader=basic
bootloadhid.uploader.basic.command=bootloadHID.exe
bootloadhid.uploader.basic.parameters=|-r