@@ -36,107 +36,88 @@ public class AvrdudeUploader extends Uploader {
36
36
public AvrdudeUploader () {
37
37
}
38
38
39
+ // XXX: add support for uploading sketches using a programmer
39
40
public boolean uploadUsingPreferences (String buildPath , String className )
40
- throws RunnerException {
41
+ throws RunnerException {
41
42
List commandDownloader = new ArrayList ();
42
-
43
- // avrdude doesn't want to read device signatures (it always gets
44
- // 0x000000); force it to continue uploading anyway
45
- //commandDownloader.add("-F");
46
-
47
43
String protocol = Preferences .get ("boards." + Preferences .get ("board" ) + ".upload.protocol" );
48
44
49
45
// avrdude wants "stk500v1" to distinguish it from stk500v2
50
46
if (protocol .equals ("stk500" ))
51
47
protocol = "stk500v1" ;
52
48
commandDownloader .add ("-c" + protocol );
53
- if (protocol .equals ("dapa" )) {
54
- // avrdude doesn't need to be told the address of the parallel port
55
- //commandDownloader.add("-dlpt=" + Preferences.get("parallel.port"));
56
- } else {
57
- commandDownloader .add ("-P" + (Base .isWindows () ? "\\ \\ .\\ " : "" ) + Preferences .get ("serial.port" ));
58
- commandDownloader .add (
59
- "-b" + Preferences .getInteger ("boards." + Preferences .get ("board" ) + ".upload.speed" ));
60
- }
61
- if (Preferences .getBoolean ("upload.erase" ))
62
- commandDownloader .add ("-e" );
63
- else
64
- commandDownloader .add ("-D" );
65
- if (!Preferences .getBoolean ("upload.verify" ))
66
- commandDownloader .add ("-V" );
49
+ commandDownloader .add ("-P" + (Base .isWindows () ? "\\ \\ .\\ " : "" ) + Preferences .get ("serial.port" ));
50
+ commandDownloader .add (
51
+ "-b" + Preferences .getInteger ("boards." + Preferences .get ("board" ) + ".upload.speed" ));
52
+ commandDownloader .add ("-D" ); // don't erase
67
53
commandDownloader .add ("-Uflash:w:" + buildPath + File .separator + className + ".hex:i" );
68
54
69
55
flushSerialBuffer ();
70
56
71
- return uisp (commandDownloader );
72
- }
73
-
74
- public boolean burnBootloaderAVRISP (String target ) throws RunnerException {
75
- List commandDownloader = new ArrayList ();
76
- commandDownloader .add ("-c" +
77
- Preferences .get ("bootloader." + target + ".programmer" ));
78
-
79
- if (Preferences .get ("bootloader." + target + ".communication" ).equals ("usb" )) {
80
- commandDownloader .add ("-Pusb" );
81
- } else {
82
- commandDownloader .add (
83
- "-P" + (Base .isWindows () ?
84
- "/dev/" + Preferences .get ("serial.port" ).toLowerCase () :
85
- Preferences .get ("serial.port" )));
86
- }
87
- commandDownloader .add ("-b" + Preferences .get ("serial.burn_rate" ));
88
- return burnBootloader (target , commandDownloader );
57
+ return avrdude (commandDownloader );
89
58
}
90
59
91
- public boolean burnBootloaderParallel (String target ) throws RunnerException {
92
- List commandDownloader = new ArrayList ();
93
- commandDownloader .add ("-dprog=dapa" );
94
- commandDownloader .add ("-dlpt=" + Preferences .get ("parallel.port" ));
95
- return burnBootloader (target , commandDownloader );
60
+ public boolean burnBootloader (String programmer ) throws RunnerException {
61
+ List params = new ArrayList ();
62
+ params .add ("-c" + Preferences .get ("programmers." + programmer + ".protocol" ));
63
+
64
+ if ("usb" .equals (Preferences .get ("programmers." + programmer + ".communication" ))) {
65
+ params .add ("-Pusb" );
66
+ } else if ("serial" .equals (Preferences .get ("programmers." + programmer + ".communication" ))) {
67
+ params .add ("-P" + (Base .isWindows () ? "\\ \\ .\\ " : "" ) + Preferences .get ("serial.port" ));
68
+ // XXX: add support for specifying the baud rate for serial programmers.
69
+ }
70
+ // XXX: add support for specifying the port address for parallel
71
+ // programmers, although avrdude has a default that works in most cases.
72
+
73
+ if (Preferences .get ("programmers." + programmer + ".delay" ) != null )
74
+ params .add ("-i" + Preferences .get ("programmers." + programmer + ".delay" ));
75
+
76
+ return burnBootloader (params );
96
77
}
97
78
98
- protected boolean burnBootloader (String target , Collection params )
99
- throws RunnerException
100
- {
101
- return
102
- // unlock bootloader segment of flash memory and write fuses
103
- uisp (params , Arrays .asList (new String [] {
104
- "-e" ,
105
- "-Ulock:w:" + Preferences .get ("bootloader." + target + ".unlock_bits" ) + ":m" ,
106
- "-Uefuse:w:" + Preferences .get ("bootloader." + target + ".extended_fuses" ) + ":m" ,
107
- "-Uhfuse:w:" + Preferences .get ("bootloader." + target + ".high_fuses" ) + ":m" ,
108
- "-Ulfuse:w:" + Preferences .get ("bootloader." + target + ".low_fuses" ) + ":m" ,
109
- })) &&
110
- // upload bootloader and lock bootloader segment
111
- uisp (params , Arrays .asList (new String [] {
112
- "-Uflash:w:" + Preferences .get ("bootloader." + target + ".path" ) +
113
- File .separator + Preferences .get ("bootloader." + target + ".file" ) + ":i" ,
114
- "-Ulock:w:" + Preferences .get ("bootloader." + target + ".lock_bits" ) + ":m"
115
- }));
79
+ protected boolean burnBootloader (Collection params )
80
+ throws RunnerException {
81
+ List fuses = new ArrayList ();
82
+ fuses .add ("-e" ); // erase the chip
83
+ fuses .add ("-Ulock:w:" + Preferences .get ("boards." + Preferences .get ("board" ) + ".bootloader.unlock_bits" ) + ":m" );
84
+ if (Preferences .get ("boards." + Preferences .get ("board" ) + ".bootloader.extended_fuses" ) != null )
85
+ fuses .add ("-Uefuse:w:" + Preferences .get ("boards." + Preferences .get ("board" ) + ".bootloader.extended_fuses" ) + ":m" );
86
+ fuses .add ("-Uhfuse:w:" + Preferences .get ("boards." + Preferences .get ("board" ) + ".bootloader.high_fuses" ) + ":m" );
87
+ fuses .add ("-Ulfuse:w:" + Preferences .get ("boards." + Preferences .get ("board" ) + ".bootloader.low_fuses" ) + ":m" );
88
+
89
+ if (!avrdude (params , fuses ))
90
+ return false ;
91
+
92
+ List bootloader = new ArrayList ();
93
+ bootloader .add ("-Uflash:w:" + "hardware" + File .separator + "bootloaders" + File .separator +
94
+ Preferences .get ("boards." + Preferences .get ("board" ) + ".bootloader.path" ) +
95
+ File .separator + Preferences .get ("boards." + Preferences .get ("board" ) + ".bootloader.file" ) + ":i" );
96
+ bootloader .add ("-Ulock:w:" + Preferences .get ("boards." + Preferences .get ("board" ) + ".bootloader.lock_bits" ) + ":m" );
97
+
98
+ return avrdude (params , bootloader );
116
99
}
117
100
118
- public boolean uisp (Collection p1 , Collection p2 ) throws RunnerException {
101
+ public boolean avrdude (Collection p1 , Collection p2 ) throws RunnerException {
119
102
ArrayList p = new ArrayList (p1 );
120
103
p .addAll (p2 );
121
- return uisp (p );
104
+ return avrdude (p );
122
105
}
123
106
124
- public boolean uisp (Collection params ) throws RunnerException {
107
+ public boolean avrdude (Collection params ) throws RunnerException {
125
108
List commandDownloader = new ArrayList ();
126
109
commandDownloader .add ("avrdude" );
127
110
128
- // On Windows and the Mac, we need to point avrdude at its config file
129
- // since it's getting installed in an unexpected location (i.e. a
130
- // sub-directory of wherever the user happens to stick Arduino). On Linux,
131
- // avrdude will have been properly installed by the distribution's package
132
- // manager and should be able to find its config file.
111
+ // Point avrdude at its config file since it's in a non-standard location.
133
112
if (Base .isMacOS ()) {
134
113
commandDownloader .add ("-C" + "hardware/tools/avr/etc/avrdude.conf" );
135
114
}
136
115
else if (Base .isWindows ()) {
137
116
String userdir = System .getProperty ("user.dir" ) + File .separator ;
138
117
commandDownloader .add ("-C" + userdir + "hardware/tools/avr/etc/avrdude.conf" );
139
118
} else {
119
+ // ???: is it better to have Linux users install avrdude themselves, in
120
+ // a way that it can find its own configuration file?
140
121
commandDownloader .add ("-C" + "hardware/tools/avrdude.conf" );
141
122
}
142
123
0 commit comments