BrainBooster
The way i usually do this type of stuff is like this:
I rename avrdude.exe to avrdude.exe.exe.
I write a small C/C++ program called avrdude.exe that calls avrdude.exe.exe and this program adds the wished parameters.
The code below compiles fine in visual studio C++ express as a console project
Best regards
Jantje
#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
string sarg;
string sCommand;
sCommand.assign(argv[0]);
sCommand +=".exe ";
sCommand +=" My extra command"; //add your command here
for(int i = 1 ; i < argc; i++)
{
sarg.assign(argv[i]);
sCommand += " ";
sCommand += sarg;
}
return system(sCommand.c_str());
}
maybe i've been unclear (sorry for my english in that case )
i have recompiled myself avrdude starting from the available source code in MingW and i've added the requested flag (-R = resurrect mode), so now i can also program the microcontrollers with the signature damaged.
My problem now is to make it work in the arduino ide, i would like to recall the flag optionally from a file like preferences or options, but i don't know how to pass the instrucion to avrdude.
Rob
Specific -> easy
Generic-> difficult.
So I try to keep it specific.
Note that you also need to specify the special file somewhere. So the systems has limitations.
I attached the code that reads the first line from a file and uses that as application to call and starting arguments.
Note that if you do not specify a full path in the code you need to be sure in which folder you start the program.
Best regards
Jantje
// capture.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
string sarg;
ifstream myfile;
char buffer[2048];
myfile.open ("c:\\input.txt",ios::app);
myfile.getline (buffer,2048);
myfile.close();
string sCommand(buffer);
for(int i = 1 ; i < argc; i++)
{
sarg.assign(argv[i]);
sCommand += " ";
sCommand += sarg;
}
return system(sCommand.c_str());
}
Brainbooster
No I don't understand why this trick would not be able to add parameters to avrdude started from Arduino IDE.
No I don't know a setting in Arduino IDE to pass extra parameters to Arduino.
But my question is: If you can recompile avrdude and make a special version; why do you need arduino to pass parameters? Can't you hard code them in a modded avrdude?
Best regards
Jantje
FYI: You can easily do this with my Arduino eclipse plugin.
hei guys,i want to modify the arduino code ,avrdude is readymade and working accepting the new option. @Jantje yes i could do it, but i prefer to recall the flag optionally because it is dangerous as it skips the signature check and goes on programming and could even program a wrong mcu by mistake (more powerfull than -F) option and it could mess with the fuses and brick the chip.
update: digging in the arduino source code i found the file: AvrdudeUploader.java, do you think i can modify it to make it parse a new option? something like "upload.zoombie"
This is what i've done, but it doesn't work, pasing the option in the preferences file.
/* -*- 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.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 AvrdudeUploader extends Uploader {
public AvrdudeUploader() {
}
public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer)
throws RunnerException, SerialException {
this.verbose = verbose;
Map<String, String> boardPreferences = Base.getBoardPreferences();
// if no protocol is specified for this board, assume it lacks a
// bootloader and upload using the selected programmer.
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);
}
Collection params = getProgrammerCommands(target, programmer);
params.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i");
return avrdude(params);
}
return uploadViaBootloader(buildPath, className);
}
private boolean uploadViaBootloader(String buildPath, String className)
throws RunnerException, SerialException {
Map<String, String> boardPreferences = Base.getBoardPreferences();
List commandDownloader = new ArrayList();
String protocol = boardPreferences.get("upload.protocol");
// avrdude wants "stk500v1" to distinguish it from stk500v2
if (protocol.equals("stk500"))
protocol = "stk500v1";
commandDownloader.add("-c" + protocol);
commandDownloader.add(
"-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port"));
commandDownloader.add(
"-b" + Integer.parseInt(boardPreferences.get("upload.speed")));
commandDownloader.add("-D"); // don't erase
if (!Preferences.getBoolean("upload.verify")) commandDownloader.add("-V"); // disable verify
if (Preferences.getBoolean("upload.zoombie")) commandDownloader.add("-R"); // enable resurrect mode
commandDownloader.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i");
if (boardPreferences.get("upload.disable_flushing") == null ||
boardPreferences.get("upload.disable_flushing").toLowerCase().equals("false")) {
flushSerialBuffer();
}
return avrdude(commandDownloader);
}
public boolean burnBootloader() throws RunnerException {
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);
}
return burnBootloader(getProgrammerCommands(target, programmer));
}
private Collection getProgrammerCommands(Target target, String programmer) {
Map<String, String> programmerPreferences = target.getProgrammers().get(programmer);
List params = new ArrayList();
params.add("-c" + programmerPreferences.get("protocol"));
if ("usb".equals(programmerPreferences.get("communication"))) {
params.add("-Pusb");
} else if ("serial".equals(programmerPreferences.get("communication"))) {
params.add("-P" + (Base.isWindows() ? "\\\\.\\" : "") + Preferences.get("serial.port"));
if (programmerPreferences.get("speed") != null) {
params.add("-b" + Integer.parseInt(programmerPreferences.get("speed")));
}
}
// XXX: add support for specifying the port address for parallel
// programmers, although avrdude has a default that works in most cases.
if (programmerPreferences.get("force") != null &&
programmerPreferences.get("force").toLowerCase().equals("true"))
params.add("-F");
if (programmerPreferences.get("delay") != null)
params.add("-i" + programmerPreferences.get("delay"));
return params;
}
protected boolean burnBootloader(Collection params)
throws RunnerException {
Map<String, String> boardPreferences = Base.getBoardPreferences();
List fuses = new ArrayList();
fuses.add("-e"); // erase the chip
if (boardPreferences.get("bootloader.unlock_bits") != null)
fuses.add("-Ulock:w:" + boardPreferences.get("bootloader.unlock_bits") + ":m");
if (boardPreferences.get("bootloader.extended_fuses") != null)
fuses.add("-Uefuse:w:" + boardPreferences.get("bootloader.extended_fuses") + ":m");
fuses.add("-Uhfuse:w:" + boardPreferences.get("bootloader.high_fuses") + ":m");
fuses.add("-Ulfuse:w:" + boardPreferences.get("bootloader.low_fuses") + ":m");
if (!avrdude(params, fuses))
return false;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
Target t;
List bootloader = new ArrayList();
String bootloaderPath = boardPreferences.get("bootloader.path");
if (bootloaderPath != null) {
if (bootloaderPath.indexOf(':') == -1) {
t = Base.getTarget(); // the current target (associated with the board)
} else {
String targetName = bootloaderPath.substring(0, bootloaderPath.indexOf(':'));
t = Base.targetsTable.get(targetName);
bootloaderPath = bootloaderPath.substring(bootloaderPath.indexOf(':') + 1);
}
File bootloadersFile = new File(t.getFolder(), "bootloaders");
File bootloaderFile = new File(bootloadersFile, bootloaderPath);
bootloaderPath = bootloaderFile.getAbsolutePath();
bootloader.add("-Uflash:w:" + bootloaderPath + File.separator +
boardPreferences.get("bootloader.file") + ":i");
}
if (boardPreferences.get("bootloader.lock_bits") != null)
bootloader.add("-Ulock:w:" + boardPreferences.get("bootloader.lock_bits") + ":m");
if (bootloader.size() > 0)
return avrdude(params, bootloader);
return true;
}
public boolean avrdude(Collection p1, Collection p2) throws RunnerException {
ArrayList p = new ArrayList(p1);
p.addAll(p2);
return avrdude(p);
}
public boolean avrdude(Collection params) throws RunnerException {
List commandDownloader = new ArrayList();
if(Base.isLinux()) {
if ((new File(Base.getHardwarePath() + "/tools/" + "avrdude")).exists()) {
commandDownloader.add(Base.getHardwarePath() + "/tools/" + "avrdude");
commandDownloader.add("-C" + Base.getHardwarePath() + "/tools/avrdude.conf");
} else {
commandDownloader.add("avrdude");
}
}
else {
commandDownloader.add(Base.getHardwarePath() + "/tools/avr/bin/" + "avrdude");
commandDownloader.add("-C" + Base.getHardwarePath() + "/tools/avr/etc/avrdude.conf");
}
if (verbose || Preferences.getBoolean("upload.verbose")) {
commandDownloader.add("-v");
commandDownloader.add("-v");
commandDownloader.add("-v");
commandDownloader.add("-v");
} else {
commandDownloader.add("-q");
commandDownloader.add("-q");
}
commandDownloader.add("-p" + Base.getBoardPreferences().get("build.mcu"));
commandDownloader.addAll(params);
return executeUploadCommand(commandDownloader);
}
}
in the preferences file, it doesn't work , and when i reopen the preferences file, the line is disappeared!
why?
You cannot edit the preferences file while the IDE is open as the IDE seems to write the file when closing.
I might not know your flag so it is not written...
Can you edit the boards file and copy the appropriate board and change the name and the necessary info and the save the boards file and restart everything?
Can you edit the boards file and copy the appropriate board and change the name and the necessary info and the save the boards file and restart everything?
all the changes as been made with the ide closed. @kf2qd , so do you think i have to change the file board.txt and not preference.txt?
edit:
tested changing the boards.txt file by adding the line :
upload.zoombie=true
but it doesn't get passed to avrdude
i don't wanna program a specific mcu, i only want to find the way to pass extra options to avrdude within the arduino ide.
I changed avrdude adding to it a new option, but usually, Arduino does not provide access to an option destinated to avrdude he doesn't know , so you have to make arduino ide able to understand the new option and if required in the configuration file, to communicate it to avrdude.
i changed the file AvrdudeUploader.java the way to make arduino able to parse the new option , reading it from the preferences.txt file.
and then i also changed the preference gui to add the small addon box.
that's it