Increase PIC/FT232 UART speed to 2 Mbaud (instead of 115200 baud) in
firmware 5.5 and newer. Given that UART speed is the biggest bottleneck
for Bus Pirate communication (right now 90% of the read time is caused
by slow BP<->host communication), this patch is absolutely needed to get
any decent speed out of the Bus Pirate.
WARNING: This patch may hang flashrom or corrupt data for any non-v3 Bus
Pirate model. I haven't tested such models, and it might work without
problems. Who knows. We would have to find someone with a v2 (or
earlier) Bus Pirate and a firmware version >=v5.5 to test this. For Bus
Pirate model v4 this patch may be completely superfluous. Anyway,
activating fast UART only for some models is probably the way to go. We
already have code to determine the hardware model in the init function,
this just needs to be stored in some variable.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006(a)gmx.net>
Signed-off-by: Stefan Tauner <stefan.tauner(a)student.tuwien.ac.at>
---
buspirate_spi.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/buspirate_spi.c b/buspirate_spi.c
index d2ebc75..57da63a 100644
--- a/buspirate_spi.c
+++ b/buspirate_spi.c
@@ -178,7 +178,10 @@ static int buspirate_spi_shutdown(void *data)
}
/* Reset Bus Pirate (return to user terminal) */
bp_commbuf[0] = 0x0f;
- ret = buspirate_sendrecv(bp_commbuf, 1, 0);
+ if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0)))
+ goto out_shutdown;
+ if ((ret = serialport_config(sp_fd, 115200)))
+ goto out_shutdown;
out_shutdown:
/* Shut down serial port communication */
@@ -365,6 +368,45 @@ int buspirate_spi_init(void)
spi_programmer_buspirate.command = buspirate_spi_send_command_v1;
}
+ /* Increase PIC/FT232 UART speed to 2 Mbaud (instead of 115200 baud) in firmware 5.5 and newer.
+ * Although this is already possible in firmware 5.2, fast UART in combination with the old SPI
+ * command set causes hangs for bigger transactions. This is caused by a UART buffer overrun
+ * in the PIC, and all firmware versions up to (hopefully not including) 6.2 are affected.
+ */
+ if (BP_FWVERSION(fw_version_major, fw_version_minor) >= BP_FWVERSION(5, 5)) {
+ // FIXME: Do this only for USB-based Bus Pirates... unless you're sure the UART can handle more.
+ int cmdlen;
+ /* Request setting the UART baud rate. */
+ cmdlen = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "b\n");
+ if ((ret = buspirate_sendrecv(bp_commbuf, cmdlen, 0)))
+ return ret;
+ if ((ret = buspirate_wait_for_string(bp_commbuf, ">")))
+ return ret;
+ /* Request setting the UART clock divisor manually. */
+ cmdlen = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "10\n");
+ if ((ret = buspirate_sendrecv(bp_commbuf, cmdlen, 0)))
+ return ret;
+ if ((ret = buspirate_wait_for_string(bp_commbuf, ">")))
+ return ret;
+ /* Set the UART clock divisor. New clock is 4000000/(divisor+1). */
+ cmdlen = snprintf((char *)bp_commbuf, DEFAULT_BUFSIZE, "%i\n", 1);
+ if ((ret = buspirate_sendrecv(bp_commbuf, cmdlen, 0)))
+ return ret;
+ sleep(1);
+ if (serialport_config(sp_fd, 115200) != 0)
+ return 1;
+ bp_commbuf[0] = ' ';
+ if ((ret = buspirate_sendrecv(bp_commbuf, 1, 0)))
+ return ret;
+ if ((ret = buspirate_wait_for_string(bp_commbuf, "HiZ>")))
+ return ret;
+ msg_pdbg("Using fast 2 Mbaud for Bus Pirate <-> host communication.\n");
+ } else {
+ msg_pinfo("Bus Pirate firmware 5.4 and older does not support fast Bus Pirate <-> host "
+ "communication. Limiting UART speed to 115200 Baud.\n");
+ msg_pinfo("It is recommended to upgrade to firmware 6.2 or newer.\n");
+ }
+
/* Workaround for broken speed settings in firmware 6.1 and older. */
if (BP_FWVERSION(fw_version_major, fw_version_minor) < BP_FWVERSION(6, 2))
if (spispeed > 0x4) {
--
Kind regards, Stefan Tauner