Index: avrdude.1
===================================================================
--- avrdude.1	(revision 1018)
+++ avrdude.1	(working copy)
@@ -972,7 +972,7 @@
 good candidates with the latches driven by the appropriate reset pin (cs, 
 aux or aux2). Otherwise the SPI traffic in one active circuit may interfere
 with programming the AVR in the other design.
-.It Ar speed=<0..7>
+.It Ar spifreq=<0..7>
 BusPirate to AVR SPI speed:
 .Bd -literal
 0 ..  30 kHz   (default)
@@ -991,8 +991,23 @@
 the above
 .Ar reset=
 and 
-.Ar speed=
+.Ar spifreq=
 parameters unavailable. 
+.It Ar cpufreq=<125..4000>
+This sets the AUX pin to output a frequency of 
+.Ar n
+kHz. Connecting
+the AUX pin to the XTAL1 pin of your MCU, you can provide it a clock, 
+for example when it needs an external clock because of wrong fuses settings.
+This setting is only available in ASCII mode. (The lower limit was chosen so
+the CPU frequency is at least for four times the SPI frequency which is in 
+ASCII mode 30kHz.)  
+.It Ar serial_recv_timeout=<1...>
+This sets the serial receive timeout to the given value. 
+The timeout happens every time avrdude waits for the BusPirate prompt. 
+Especially in ascii mode this happens very often, so setting a smaller value 
+can speed up programming a lot. 
+The default value is 100ms. Using 10ms might work in most cases. 
 .El
 .It Ar Wiring
 When using the Wiring programmer type, the
Index: buspirate.c
===================================================================
--- buspirate.c	(revision 1018)
+++ buspirate.c	(working copy)
@@ -29,6 +29,7 @@
  *      MOSI  <->  MOSI
  *      MISO  <->  MISO
  *   SCL/CLK  <->  SCK
+ *     ( AUX  <->  XTAL1 )
  *
  * Tested with BusPirate PTH, firmware version 2.1 programming ATmega328P
  */
@@ -61,6 +62,7 @@
 #define BP_FLAG_XPARM_FORCE_ASCII   (1<<1)
 #define BP_FLAG_XPARM_RESET         (1<<2)
 #define BP_FLAG_XPARM_SPIFREQ       (1<<3)
+#define BP_FLAG_XPARM_CPUFREQ       (1<<4)
 
 struct pdata
 {
@@ -70,6 +72,8 @@
 	int	bin_spi_version;
 	int	current_peripherals_config;
 	int	spifreq;		/* 0..7 - see buspirate manual for what freq each value means */
+	int	cpufreq;		/* (125)..4000 kHz - see buspirate manual */
+	int	serial_recv_timeout; /* timeout in ms, default 100 */
 	int	reset;			/* See BP_RESET_* above */
 };
 #define PDATA(pgm) ((struct pdata *)(pgm->cookie))
@@ -206,7 +210,7 @@
 			break;
 		}
 		buf_p++;
-		serial_recv_timeout = 100;
+		serial_recv_timeout = PDATA(pgm)->serial_recv_timeout;
 	}
 	serial_recv_timeout = orig_serial_recv_timeout;
 	if (verbose)
@@ -296,6 +300,8 @@
 	char reset[10];
 	char *preset = reset;	/* for strtok() */
 	int spifreq;
+	int cpufreq;
+	int serial_recv_timeout;
 
 	for (ln = lfirst(extparms); ln; ln = lnext(ln)) {
     	extended_param = ldata(ln);
@@ -314,6 +320,18 @@
 			continue;
 		}
 
+		if (sscanf(extended_param, "cpufreq=%d", &cpufreq) == 1) {
+			/* lower limit comes from 'cpufreq > 4 * spifreq', spifreq in ascii mode is 30kHz. */
+			if (cpufreq < 125 || cpufreq > 4000) {
+				fprintf(stderr, "BusPirate: cpufreq must be between 125 and 4000 kHz.\n");
+				fprintf(stderr, "BusPirate: see BusPirate manual for details.\n");
+				return -1;
+			}
+			PDATA(pgm)->cpufreq = cpufreq;
+			pgm->flag |= BP_FLAG_XPARM_CPUFREQ;
+			continue;
+		}
+
 		if (sscanf(extended_param, "reset=%s", reset) == 1) {
 			char *resetpin;
 			while ((resetpin = strtok(preset, ","))) {
@@ -332,6 +350,15 @@
 			pgm->flag |= BP_FLAG_XPARM_RESET;
 			continue;
 		}
+
+		if (sscanf(extended_param, "serial_recv_timeout=%d", &serial_recv_timeout) == 1) {
+			if (serial_recv_timeout < 1) {
+				fprintf(stderr, "BusPirate: serial_recv_timeout must be greater 0.\n");
+				return -1;
+			}
+			PDATA(pgm)->serial_recv_timeout = serial_recv_timeout;
+			continue;
+		}
 	}
 
 	return 0;
@@ -363,6 +390,11 @@
 		return -1;
 	}
 
+	if ((pgm->flag & BP_FLAG_XPARM_CPUFREQ) && !buspirate_uses_ascii(pgm)) {
+		fprintf(stderr, "BusPirate: Setting cpufreq is only supported in ASCII mode\n");
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -490,7 +522,7 @@
 	int cmd;
 	char *rcvd, mode[11], buf[5];
 
-	buspirate_send(pgm, "M\n");
+	buspirate_send(pgm, "m\n");
 	while(1) {
 		rcvd = buspirate_readline(pgm, NULL, 0);
 		if (spi_cmd == -1 && sscanf(rcvd, "%d. %10s", &cmd, mode)) {
@@ -594,7 +626,7 @@
 		if (buspirate_start_spi_mode_bin(pgm) < 0)
 			fprintf(stderr, "%s: Failed to start binary SPI mode\n", progname);
 	}
-	if (!pgm->flag & BP_FLAG_IN_BINMODE) {
+	if (!(pgm->flag & BP_FLAG_IN_BINMODE)) {
 		fprintf(stderr, "BusPirate: using ASCII mode\n");
 		if (buspirate_start_spi_mode_ascii(pgm) < 0) {
 			fprintf(stderr, "%s: Failed to start ascii SPI mode\n", progname);
@@ -624,9 +656,26 @@
 	if (pgm->flag & BP_FLAG_IN_BINMODE) {
 		/* Powerup in BinMode is handled in SPI init */
 		return;
-	} else
-		if (buspirate_expect(pgm, "W\n", "POWER SUPPLIES ON", 1))
+	} else {
+		if (buspirate_expect(pgm, "W\n", "Power supplies ON", 1)) {
+			if (pgm->flag & BP_FLAG_XPARM_CPUFREQ) {
+				char buf[25];
+				int ok = 0;
+				snprintf(buf, sizeof(buf), "%d\n", PDATA(pgm)->cpufreq);
+				if (buspirate_expect(pgm, "g\n", "Frequency in KHz", 1)) {
+					if (buspirate_expect(pgm, buf, "Duty cycle in %", 1)) {
+						if (buspirate_expect(pgm, "50\n", "PWM active", 1)) {
+							ok = 1;
+						}
+					}
+				}
+				if(!ok) {
+					fprintf(stderr, "%s: warning: did not get a response to start PWM command.\n", progname);
+				}
+			}
 			return;
+		}
+	}
 
 	fprintf(stderr, "%s: warning: did not get a response to PowerUp command.\n", progname);
 	fprintf(stderr, "%s: warning: Trying to continue anyway...\n", progname);
@@ -639,9 +688,15 @@
 		 * we want everything off -- 0b01000000 = 0x40 */
 		if (buspirate_expect_bin_byte(pgm, 0x40, 0x01))
 			return;
-	} else
-		if (buspirate_expect(pgm, "w\n", "POWER SUPPLIES OFF", 1))
+	} else {
+		if (pgm->flag & BP_FLAG_XPARM_CPUFREQ) {
+			if (!buspirate_expect(pgm, "g\n", "PWM disabled", 1)) {
+				fprintf(stderr, "%s: warning: did not get a response to stop PWM command.\n", progname);
+			}
+		}
+		if (buspirate_expect(pgm, "w\n", "Power supplies OFF", 1))
 			return;
+	}
 
 	fprintf(stderr, "%s: warning: did not get a response to PowerDown command.\n", progname);
 }
@@ -791,5 +846,6 @@
 			progname);
 		exit(1);
 	}
+	PDATA(pgm)->serial_recv_timeout = 100;
 }
 
Index: doc/avrdude.texi
===================================================================
--- doc/avrdude.texi	(revision 1018)
+++ doc/avrdude.texi	(working copy)
@@ -1010,25 +1010,17 @@
 aux or aux2). Otherwise the SPI traffic in one active circuit may interfere
 with programming the AVR in the other design.
 
-@item @samp{speed=@var{0..7}}
-@table @code
-@item 0
-30 kHz (default)
-@item 1
-125 kHz
-@item 2
-250 kHz
-@item 3
-1 MHz
-@item 4
-2 MHz
-@item 5
-2.6 MHz
-@item 6
-4 MHz
-@item 7
-8 MHz
-@end table
+@item @samp{spifreq=@var{0..7}}
+@multitable @columnfractions .05 .3
+@item @code{0} @tab  30 kHz (default)
+@item @code{1} @tab 125 kHz
+@item @code{2} @tab 250 kHz
+@item @code{3} @tab   1 MHz
+@item @code{4} @tab   2 MHz
+@item @code{5} @tab   2.6 MHz
+@item @code{6} @tab   4 MHz
+@item @code{7} @tab   8 MHz
+@end multitable
 
 @item @samp{ascii}
 Use ASCII mode even when the firmware supports BinMode (binary mode).
@@ -1037,8 +1029,24 @@
 the above
 @samp{reset=}
 and
-@samp{speed=}
+@samp{spifreq=}
 parameters unavailable.
+
+@item @samp{cpufreq=@var{125..4000}}
+This sets the @emph{AUX}  pin to output a frequency of @var{n} kHz. Connecting
+the @emph{AUX} pin to the XTAL1 pin of your MCU, you can provide it a clock, 
+for example when it needs an external clock because of wrong fuses settings.
+This setting is only available in ASCII mode. (The lower limit was chosen so
+the CPU frequency is at least for four times the SPI frequency which is in 
+ASCII mode 30kHz.)  
+
+@item @samp{serial_recv_timeout=@var{1...}}
+This sets the serial receive timeout to the given value. 
+The timeout happens every time avrdude waits for the BusPirate prompt. 
+Especially in ascii mode this happens very often, so setting a smaller value 
+can speed up programming a lot. 
+The default value is 100ms. Using 10ms might work in most cases.  
+
 @end table
 
 @item Wiring
