diff --git a/src/platforms/hosted/Readme.md b/src/platforms/hosted/Readme.md index bfbfaf6d..13324182 100644 --- a/src/platforms/hosted/Readme.md +++ b/src/platforms/hosted/Readme.md @@ -13,19 +13,51 @@ connect to the BMP with the CDCACM GDB serial server. GDB functionality is the same, monitor option may vary. More arguments allow to -### print information on the connected target "blackmagiv -t" -### directly flash a binary file at 0x0800000 "blackmagic " +### Print information on the connected target +``` +blackmagic -t +``` +### Directly flash a binary file at lowest flash address +``` +blackmagic +``` or with the -S argument at some other address -### read flash to binary file "blackmagic -r .bin -### verify flash against binary file "blackmagic -V .bin - -Use "blackmagic -h" to see all options. +``` +blackmagic -S 0x08002000 +``` +### Read flash to binary file +``` +blackmagic -r .bin +``` +### Verify flash against binary file +``` +blackmagic -V .bin +``` +### Show more options +``` +blackmagic -h" +``` ## Used libraries: ### libusb ### libftdi, for FTDI support ### hidapi-libusb, for CMSIS-DAP support +## Compiling on windows + +You can crosscompile blackmagic for windows with mingw or on windows +with cygwin. For compilation, headers for libftdi1 and libusb-1.0 are +needed. For running, libftdi1.dll and libusb-1.0.dll are needed and +the executable must be able to find them. Mingw on cygwin does not provide +a libftdi package yet. + +To prepare libusb access to the ftdi device, run zadig https://zadig.akeo.ie/. +Choose WinUSB(libusb-1.0) for the BMP Ftdi device. + +Running cygwin/blackmagic in a cygwin console, the program does not react +on ^C. In another console, run "ps ax" to find the WINPID of the process +and then "taskkill /F ?PID (WINPID)". + ## Supported debuggers REMOTE_BMP is a "normal" BMP usb connected @@ -39,6 +71,69 @@ REMOTE_BMP is a "normal" BMP usb connected | FTDI MPSSE | ++ | Requires a device descrition | JLINK | - | Usefull to add BMP support for MCUs with built-in JLINK +## Device matching +As other USB dongles already connected to the host PC may use FTDI chips, +cable descriptions are provided to match with the dongle. +To match the dongle, at least USB VID/PID that must match. +If a description is given, the USB device must provide that string. If a +serial number string is given on the command line, that number must match +with serial number in the USB descriptor of the device. + +## FTDI connection possibilities: + +| Direct Connection | +| ----------------------| +| MPSSE_SK --> JTAG_TCK | +| MPSSE_DO --> JTAG_TDI | +| MPSSE_DI <-- JTAG_TDO | +| MPSSE_CS <-> JTAG_TMS | + +\+ JTAG and bitbanging SWD is possible
+\- No level translation, no buffering, no isolation
+Example: [Flossjtag](https://randomprojects.org/wiki/Floss-JTAG). + +| Resistor SWD | +|------------------------| +| MPSSE_SK ---> JTAG_TCK | +| MPSSE_DO -R-> JTAG_TMS | +| MPSSE_DI <--- JTAG_TMS | + +BMP would allow direct MPSSE_DO ->JTAG_TMS connections as BMP tristates DO +when reading. Resistor defeats contentions anyways. R is typical choosen +in the range of 470R + +\+ MPSSE SWD possible
+\- No Jtag, no level translation, no buffering, no isolation
+ +|Direct buffered Connection| +|--------------------------| +| MPSSE_SK -B-> JTAG_TCK | +| MPSSE_DO -B-> JTAG_TDI | +| MPSSE_DI <-B- JTAG_TDO | +| MPSSE_CS -B-> JTAG_TMS | + +\+ Only Jtag, buffered, possible level translation and isolation
+\- No SWD
+Example: [Turtelizer]http://www.ethernut.de/en/hardware/turtelizer/index.html) +[schematics](http://www.ethernut.de/pdf/turtelizer20c-schematic.pdf) + +The 'r' command line arguments allows to specify an external SWD +resistor connection added to some existing cable. Jtag is not possible +together with the 'r' argument. + +### Many variants possible +As the FTDI has more pins, these pins may be used to control +enables of buffers and multiplexer selection in many variants. + +### Reset, Target voltage readback etc +The additional pins may also control Reset functionality, provide +information if target voltage is applied. etc. + +### Cable descriptions +Please help to verify the cable description and give feedback on the +cables already listed and propose other cable. A link to the schematics +is welcome. + ## Feedback ### Issues and Pull request on https://github.com/blacksphere/blackmagic/ ### Discussions on Discord. diff --git a/src/platforms/hosted/ftdi_bmp.c b/src/platforms/hosted/ftdi_bmp.c index f4189967..6f4ce740 100644 --- a/src/platforms/hosted/ftdi_bmp.c +++ b/src/platforms/hosted/ftdi_bmp.c @@ -238,6 +238,22 @@ int ftdi_bmp_init(BMP_CL_OPTIONS_t *cl_opts, bmp_info_t *info) active_cable = &cable_desc[index]; memcpy(&active_state, &active_cable->init, sizeof(data_desc_t)); + /* If swd_(read|write) is not given for the selected cable and + the 'r' command line argument is give, assume resistor SWD + connection.*/ + if (cl_opts->external_resistor_swd && + (active_cable->mpsse_swd_read.set_data_low == 0) && + (active_cable->mpsse_swd_read.clr_data_low == 0) && + (active_cable->mpsse_swd_read.set_data_high == 0) && + (active_cable->mpsse_swd_read.clr_data_high == 0) && + (active_cable->mpsse_swd_write.set_data_low == 0) && + (active_cable->mpsse_swd_write.clr_data_low == 0) && + (active_cable->mpsse_swd_write.set_data_high == 0) && + (active_cable->mpsse_swd_write.clr_data_high == 0)) { + DEBUG_INFO("Using external resistor SWD\n"); + active_cable->mpsse_swd_read.set_data_low = MPSSE_DO; + active_cable->mpsse_swd_write.set_data_low = MPSSE_DO; + } DEBUG_WARN("Black Magic Probe for FTDI/MPSSE\n"); if(ftdic) { diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 38d3c729..146510af 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -135,6 +135,8 @@ static void cl_help(char **argv, BMP_CL_OPTIONS_t *opt) DEBUG_WARN("\t-C\t\t: Connect under reset\n"); DEBUG_WARN("\t-t\t\t: Scan SWD or JTAG and display information about \n" "\t\t\t connected devices\n"); + DEBUG_WARN("\t-e\t\t: Assume \"resistor SWD connection\" on FTDI: TDI\n" + "\t\t\t connected to TMS, TDO to TDI with eventual resistor\n"); DEBUG_WARN("\t-E\t\t: Erase flash until flash end or for given size\n"); DEBUG_WARN("\t-V\t\t: Verify flash against binary file\n"); DEBUG_WARN("\t-r\t\t: Read flash and write to binary file\n"); @@ -154,7 +156,7 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) int c; opt->opt_target_dev = 1; opt->opt_flash_size = 16 * 1024 *1024; - while((c = getopt(argc, argv, "Ehv:d:s:I:c:CnltVta:S:jpP:rR")) != -1) { + while((c = getopt(argc, argv, "eEhv:d:s:I:c:CnltVta:S:jpP:rR")) != -1) { switch(c) { case 'c': if (optarg) @@ -177,6 +179,9 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) case 'C': opt->opt_connect_under_reset = true; break; + case 'e': + opt->external_resistor_swd = true; + break; case 'd': if (optarg) opt->opt_device = optarg; diff --git a/src/platforms/pc/cl_utils.h b/src/platforms/pc/cl_utils.h index 3fedb7ec..e2bd4356 100644 --- a/src/platforms/pc/cl_utils.h +++ b/src/platforms/pc/cl_utils.h @@ -42,6 +42,7 @@ typedef struct BMP_CL_OPTIONS_s { bool opt_tpwr; bool opt_list_only; bool opt_connect_under_reset; + bool external_resistor_swd; char *opt_flash_file; char *opt_device; char *opt_serial;