libftdi/jtagtap: Try harder to initialize Ftdi MPSSE jtag mode.

After "mon s" at least the second "mon j" now succeeds again.
This commit is contained in:
Uwe Bonnes 2018-05-07 17:56:51 +02:00
parent c548e307fe
commit aa938c6dae
3 changed files with 35 additions and 25 deletions

View File

@ -38,6 +38,34 @@
int jtagtap_init(void)
{
assert(ftdic != NULL);
int err = ftdi_usb_purge_buffers(ftdic);
if (err != 0) {
fprintf(stderr, "ftdi_usb_purge_buffer: %d: %s\n",
err, ftdi_get_error_string(ftdic));
abort();
}
/* Reset MPSSE controller. */
err = ftdi_set_bitmode(ftdic, 0, BITMODE_RESET);
if (err != 0) {
fprintf(stderr, "ftdi_set_bitmode: %d: %s\n",
err, ftdi_get_error_string(ftdic));
return -1;;
}
/* Enable MPSSE controller. Pin directions are set later.*/
err = ftdi_set_bitmode(ftdic, 0, BITMODE_MPSSE);
if (err != 0) {
fprintf(stderr, "ftdi_set_bitmode: %d: %s\n",
err, ftdi_get_error_string(ftdic));
return -1;;
}
uint8_t ftdi_init[9] = {TCK_DIVISOR, 0x00, 0x00, SET_BITS_LOW, 0,0,
SET_BITS_HIGH, 0,0};
ftdi_init[4]= active_cable->dbus_data;
ftdi_init[5]= active_cable->dbus_ddr;
ftdi_init[7]= active_cable->cbus_data;
ftdi_init[8]= active_cable->cbus_ddr;
platform_buffer_write(ftdi_init, 9);
platform_buffer_flush();
/* Go to JTAG mode for SWJ-DP */
for (int i = 0; i <= 50; i++)

View File

@ -150,9 +150,6 @@ void platform_init(int argc, char **argv)
unsigned index = 0;
char *serial = NULL;
char * cablename = "ftdi";
uint8_t ftdi_init[9] = {TCK_DIVISOR, 0x01, 0x00, SET_BITS_LOW, 0,0,
SET_BITS_HIGH, 0,0};
while((c = getopt(argc, argv, "c:s:")) != -1) {
switch(c) {
case 'c':
@ -176,15 +173,6 @@ void platform_init(int argc, char **argv)
active_cable = &cable_desc[index];
if (active_cable->dbus_data)
ftdi_init[4]= active_cable->dbus_data;
if (active_cable->dbus_ddr)
ftdi_init[5]= active_cable->dbus_ddr;
if (active_cable->cbus_data)
ftdi_init[7]= active_cable->cbus_data;
if(active_cable->cbus_ddr)
ftdi_init[8]= active_cable->cbus_ddr;
printf("\nBlack Magic Probe (" FIRMWARE_VERSION ")\n");
printf("Copyright (C) 2015 Black Sphere Technologies Ltd.\n");
printf("License GPLv3+: GNU GPL version 3 or later "
@ -223,24 +211,11 @@ void platform_init(int argc, char **argv)
err, ftdi_get_error_string(ftdic));
abort();
}
if((err = ftdi_usb_purge_buffers(ftdic)) != 0) {
fprintf(stderr, "ftdi_set_baudrate: %d: %s\n",
err, ftdi_get_error_string(ftdic));
abort();
}
if((err = ftdi_write_data_set_chunksize(ftdic, BUF_SIZE)) != 0) {
fprintf(stderr, "ftdi_write_data_set_chunksize: %d: %s\n",
err, ftdi_get_error_string(ftdic));
abort();
}
if((err = ftdi_set_bitmode(ftdic, 0, BITMODE_MPSSE)) != 0) {
fprintf(stderr, "ftdi_set_bitmode: %d: %s\n",
err, ftdi_get_error_string(ftdic));
abort();
}
assert(ftdi_write_data(ftdic, ftdi_init, 9) == 9);
assert(gdb_if_init() == 0);
}

View File

@ -37,6 +37,13 @@ int swdptap_init(void)
assert(ftdic != NULL);
/* Reset MPSSE controller. */
if((err = ftdi_set_bitmode(ftdic, 0, BITMODE_RESET)) != 0) {
fprintf(stderr, "ftdi_set_bitmode: %d: %s\n",
err, ftdi_get_error_string(ftdic));
abort();
}
if((err = ftdi_set_bitmode(ftdic, 0xAB, BITMODE_BITBANG)) != 0) {
fprintf(stderr, "ftdi_set_bitmode: %d: %s\n",
err, ftdi_get_error_string(ftdic));