From 272a45df12d77fa9a9dff6eb382e40b8d78c9e83 Mon Sep 17 00:00:00 2001 From: Noah Pendleton <2538614+noahp@users.noreply.github.com> Date: Sat, 12 Dec 2020 12:43:02 -0500 Subject: [PATCH 01/22] add src/artifacts to .gitignore This folder is generated when running `make -C src all_platforms`. Add it to ignored files. Ignore .gdb_history too. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 322deda3..1e555038 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ blackmagic_upgrade *.exe *.elf .vscode +.gdb_history +src/artifacts/ From 98c92a6d18d943acdebeb42bac24845f925fe4f2 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sun, 13 Dec 2020 13:21:23 +0100 Subject: [PATCH 02/22] hosted: Really fix the case of no serial number (#807) --- src/platforms/hosted/bmp_libusb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platforms/hosted/bmp_libusb.c b/src/platforms/hosted/bmp_libusb.c index e29344b8..06134a36 100644 --- a/src/platforms/hosted/bmp_libusb.c +++ b/src/platforms/hosted/bmp_libusb.c @@ -36,13 +36,15 @@ #define VENDOR_ID_SEGGER 0x1366 +#define NO_SERIAL_NUMBER "" + void bmp_ident(bmp_info_t *info) { DEBUG_INFO("BMP hosted %s\n for ST-Link V2/3, CMSIS_DAP, JLINK and " "LIBFTDI/MPSSE\n", FIRMWARE_VERSION); if (info && info->vid && info->pid) DEBUG_INFO("Using %04x:%04x %s %s\n %s\n", info->vid, info->pid, - info->serial, + (info->serial[0]) ? info->serial : NO_SERIAL_NUMBER, info->manufacturer, info->product); } @@ -233,11 +235,9 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) if (!cable->name) continue; } - if (!serial[0]) - strcpy(serial, ""); if (report) { DEBUG_WARN("%2d: %s, %s, %s\n", found_debuggers + 1, - serial, + (serial[0]) ? serial : NO_SERIAL_NUMBER, manufacturer,product); } info->vid = desc.idVendor; From 5f76169b959cbd48d8f99fb9b27f769dceadbb13 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 14 Dec 2020 21:10:03 +0800 Subject: [PATCH 03/22] hosted: remove ftdi include when built with BMP_ONLY #811 Signed-off-by: Sean Cross --- src/platforms/hosted/ftdi_bmp.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/platforms/hosted/ftdi_bmp.h b/src/platforms/hosted/ftdi_bmp.h index ffb9e866..51368194 100644 --- a/src/platforms/hosted/ftdi_bmp.h +++ b/src/platforms/hosted/ftdi_bmp.h @@ -27,7 +27,6 @@ #include "jtagtap.h" #include "bmp_hosted.h" -#include typedef struct data_desc_s { int16_t data_low; @@ -101,11 +100,6 @@ typedef struct cable_desc_s { char * name; }cable_desc_t; -extern cable_desc_t cable_desc[]; -extern cable_desc_t *active_cable; -extern struct ftdi_context *ftdic; -extern data_desc_t active_state; - #if HOSTED_BMP_ONLY == 1 # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunused-parameter" @@ -123,6 +117,12 @@ void libftdi_max_frequency_set(uint32_t freq) {}; uint32_t libftdi_max_frequency_get(void) {return 0;}; # pragma GCC diagnostic pop #else +#include +extern cable_desc_t cable_desc[]; +extern cable_desc_t *active_cable; +extern struct ftdi_context *ftdic; +extern data_desc_t active_state; + int ftdi_bmp_init(BMP_CL_OPTIONS_t *cl_opts, bmp_info_t *info); int libftdi_swdptap_init(swd_proc_t *swd_proc); int libftdi_jtagtap_init(jtag_proc_t *jtag_proc); From 2b06f045c442c676ecd8bac515b54f4d7321c89f Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 14 Dec 2020 10:22:56 +0800 Subject: [PATCH 04/22] target: kinetis: add S32K148 This adds support for the NXP S32K148. This is an automotive-grade part that is derived from the Kinetis line, so it has a very similar interface to other parts in the family. Signed-off-by: Sean Cross --- src/target/kinetis.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/target/kinetis.c b/src/target/kinetis.c index 442eac8b..98f9f764 100644 --- a/src/target/kinetis.c +++ b/src/target/kinetis.c @@ -326,6 +326,13 @@ bool kinetis_probe(target *t) kl_gen_add_flash(t, 0x00000000, 0x00040000, 0x800, K64_WRITE_LEN); /* P-Flash, 256 KB, 2 KB Sectors */ kl_gen_add_flash(t, 0x10000000, 0x00008000, 0x800, K64_WRITE_LEN); /* FlexNVM, 32 KB, 2 KB Sectors */ break; + case 0x148: /* S32K148 */ + t->driver = "S32K148"; + target_add_ram(t, 0x1FFE0000, 0x20000); /* SRAM_L, 128 KB */ + target_add_ram(t, 0x20000000, 0x1f000); /* SRAM_H, 124 KB */ + kl_gen_add_flash(t, 0x00000000, 0x00180000, 0x1000, K64_WRITE_LEN); /* P-Flash, 1536 KB, 4 KB Sectors */ + kl_gen_add_flash(t, 0x10000000, 0x80000, 0x1000, K64_WRITE_LEN); /* FlexNVM, 512 KB, 4 KB Sectors */ + break; default: return false; } From c49c895f398cd05df7acc16413ec42196c61f616 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Wed, 16 Dec 2020 14:30:37 +0800 Subject: [PATCH 05/22] gitattributes: add attributes file On different platforms, line endings can differ. Git tries to intelligently convert source code to match native line endings when doing a checkout, unless a particular configuration flag is set. An alternate approach is to create a `.gitattributes` file and manually specify various types of files. This ensures files are properly handled. It also prevents git from creating patches that consist of nothing more than replacing line endings. Signed-off-by: Sean Cross --- .gitattributes | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..cc80d9c8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,40 @@ +# Text for humans +LICENSE text eol=lf +HACKING text eol=lf +COPYING text eol=lf +UsingSWO text eol=lf +README.* text eol=lf + +# Source code +Makefile text eol=lf +*.mk text eol=lf +*.mak text eol=lf +*.inc text eol=lf +*.py text eol=lf +*.sh text eol=lf +*.c text eol=lf +*.S text eol=lf +*.s text eol=lf +*.h text eol=lf +*.ld text eol=lf +*.yml text eol=lf +*.rules text eol=lf + +# Git control files +.gitattributes eol=lf +.gitignore eol=lf +.gitmodules eol=lf + +# Windows source code uses CRLF +*.vcxproj text eol=crlf +*.props text eol=crlf +*.bat text eol=crlf +*.ps1 text eol=crlf +*.inf text eol=crlf + +# Other binary files +*.png binary +*.jpg binary +*.bin binary +*.elf binary +*.bin binary From 09c000eca8341b1b5ee4706befc2af02591323be Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 19 Dec 2020 16:25:03 +0100 Subject: [PATCH 06/22] hosted: Really handle setting tpwr on remote on the command line #817 Expect the command to fail, due to old firmware or remote not implementing the power switch. --- src/platforms/hosted/bmp_remote.c | 5 +++-- src/platforms/hosted/bmp_remote.h | 2 +- src/platforms/hosted/platform.c | 14 ++++++++++++++ src/platforms/pc/cl_utils.c | 3 --- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/platforms/hosted/bmp_remote.c b/src/platforms/hosted/bmp_remote.c index 66d1b92a..b8dc1d2e 100644 --- a/src/platforms/hosted/bmp_remote.c +++ b/src/platforms/hosted/bmp_remote.c @@ -73,7 +73,7 @@ bool remote_target_get_power(void) return (construct[1] == '1'); } -void remote_target_set_power(bool power) +bool remote_target_set_power(bool power) { uint8_t construct[REMOTE_MAX_MSG_SIZE]; int s; @@ -87,8 +87,9 @@ void remote_target_set_power(bool power) if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { DEBUG_WARN("platform_target_set_power failed, error %s\n", s ? (char *)&(construct[1]) : "unknown"); - exit(-1); + return false; } + return true; } void remote_srst_set_val(bool assert) diff --git a/src/platforms/hosted/bmp_remote.h b/src/platforms/hosted/bmp_remote.h index c61cb026..cff7563f 100644 --- a/src/platforms/hosted/bmp_remote.h +++ b/src/platforms/hosted/bmp_remote.h @@ -34,7 +34,7 @@ int remote_swdptap_init(swd_proc_t *swd_proc); int remote_jtagtap_init(jtag_proc_t *jtag_proc); bool remote_target_get_power(void); const char *remote_target_voltage(void); -void remote_target_set_power(bool power); +bool remote_target_set_power(bool power); void remote_srst_set_val(bool assert); bool remote_srst_get_val(void); void remote_max_frequency_set(uint32_t freq); diff --git a/src/platforms/hosted/platform.c b/src/platforms/hosted/platform.c index 5e55603d..7b95c8db 100644 --- a/src/platforms/hosted/platform.c +++ b/src/platforms/hosted/platform.c @@ -377,6 +377,20 @@ uint32_t platform_max_frequency_get(void) return false; } +void platform_target_set_power(bool power) +{ + switch (info.bmp_type) { + case BMP_TYPE_BMP: + if (remote_target_set_power(power)) + DEBUG_INFO("Powering up device!\n"); + else + DEBUG_WARN("Powering up device unimplemented or failed\n"); + break; + default: + break; + } +} + void platform_buffer_flush(void) { switch (info.bmp_type) { diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 78ba5b52..686828fa 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -313,13 +313,10 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) { int res = -1; int num_targets; -#if defined(PLATFORM_HAS_POWER_SWITCH) if (opt->opt_tpwr) { - DEBUG_INFO("Powering up device"); platform_target_set_power(true); platform_delay(500); } -#endif if (opt->opt_connect_under_reset) DEBUG_INFO("Connecting under reset\n"); connect_assert_srst = opt->opt_connect_under_reset; From 42f590ce0b018a4c7a1acff66da051ed826854ac Mon Sep 17 00:00:00 2001 From: Alex Norman Date: Tue, 22 Dec 2020 18:11:12 -0800 Subject: [PATCH 07/22] fixing some memory map errors for stm32h7, PR #821 --- src/target/stm32h7.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/target/stm32h7.c b/src/target/stm32h7.c index a867ed48..16e9bad1 100644 --- a/src/target/stm32h7.c +++ b/src/target/stm32h7.c @@ -25,6 +25,13 @@ * Reference manual - STM32H7x3 advanced ARMĀ®-based 32-bit MCUs Rev.3 */ +/* + * While the ST document (RM 0433) claims that the stm32h750 only has 1 bank + * with 1 sector (128k) of user main memory flash (pages 151-152), we were able + * to write and successfully verify into other regions in bank 1 and also into + * bank 2 (0x0810 0000 as indicated for the other chips). + */ + #include "general.h" #include "target.h" #include "target_internal.h" @@ -199,13 +206,14 @@ static bool stm32h7_attach(target *t) target_mem_map_free(t); /* Add RAM to memory map */ + /* Table 7. Memory map and default device memory area attributes RM 0433, pg 130 */ target_add_ram(t, 0x00000000, 0x10000); /* ITCM Ram, 64 k */ target_add_ram(t, 0x20000000, 0x20000); /* DTCM Ram, 128 k */ target_add_ram(t, 0x24000000, 0x80000); /* AXI Ram, 512 k */ target_add_ram(t, 0x30000000, 0x20000); /* AHB SRAM1, 128 k */ - target_add_ram(t, 0x32000000, 0x20000); /* AHB SRAM2, 128 k */ - target_add_ram(t, 0x34000000, 0x08000); /* AHB SRAM3, 32 k */ - target_add_ram(t, 0x38000000, 0x01000); /* AHB SRAM4, 32 k */ + target_add_ram(t, 0x30020000, 0x20000); /* AHB SRAM2, 128 k */ + target_add_ram(t, 0x30040000, 0x08000); /* AHB SRAM3, 32 k */ + target_add_ram(t, 0x38000000, 0x10000); /* AHB SRAM4, 64 k */ /* Add the flash to memory map. */ stm32h7_add_flash(t, 0x8000000, 0x100000, FLASH_SECTOR_SIZE); From d4dc3b2717a550e181d3021278e42e090b5dad20 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 29 Jan 2021 11:54:46 +0100 Subject: [PATCH 08/22] The USB CDC is no modem and does not use the AT protocol Signed-off-by: Martin --- src/platforms/common/cdcacm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platforms/common/cdcacm.c b/src/platforms/common/cdcacm.c index 91136134..2ad61191 100644 --- a/src/platforms/common/cdcacm.c +++ b/src/platforms/common/cdcacm.c @@ -144,7 +144,7 @@ static const struct usb_interface_descriptor gdb_comm_iface[] = {{ .bNumEndpoints = 1, .bInterfaceClass = USB_CLASS_CDC, .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, - .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, + .bInterfaceProtocol = USB_CDC_PROTOCOL_NONE, .iInterface = 4, .endpoint = gdb_comm_endp, @@ -174,7 +174,7 @@ static const struct usb_iface_assoc_descriptor gdb_assoc = { .bInterfaceCount = 2, .bFunctionClass = USB_CLASS_CDC, .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, - .bFunctionProtocol = USB_CDC_PROTOCOL_AT, + .bFunctionProtocol = USB_CDC_PROTOCOL_NONE, .iFunction = 0, }; @@ -247,7 +247,7 @@ static const struct usb_interface_descriptor uart_comm_iface[] = {{ .bNumEndpoints = 1, .bInterfaceClass = USB_CLASS_CDC, .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, - .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, + .bInterfaceProtocol = USB_CDC_PROTOCOL_NONE, .iInterface = 5, .endpoint = uart_comm_endp, @@ -277,7 +277,7 @@ static const struct usb_iface_assoc_descriptor uart_assoc = { .bInterfaceCount = 2, .bFunctionClass = USB_CLASS_CDC, .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, - .bFunctionProtocol = USB_CDC_PROTOCOL_AT, + .bFunctionProtocol = USB_CDC_PROTOCOL_NONE, .iFunction = 0, }; From 3b8502c2e554627e63452181451ff67d26dabb40 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 29 Jan 2021 12:09:32 +0100 Subject: [PATCH 09/22] add space in USB product string (be consistent with ../stm32/dfucore.c) This changes the USB identification from "Black Magic Probe(STLINK/V2) v..." to "Black Magic Probe (STLINK/V2) v..." Signed-off-by: Martin --- src/platforms/common/cdcacm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platforms/common/cdcacm.c b/src/platforms/common/cdcacm.c index 2ad61191..848391de 100644 --- a/src/platforms/common/cdcacm.c +++ b/src/platforms/common/cdcacm.c @@ -401,8 +401,8 @@ char serial_no[13]; static char serial_no[9]; #endif -#define BOARD_IDENT "Black Magic Probe" PLATFORM_IDENT FIRMWARE_VERSION -#define DFU_IDENT "Black Magic Firmware Upgrade" PLATFORM_IDENT FIRMWARE_VERSION +#define BOARD_IDENT "Black Magic Probe " PLATFORM_IDENT FIRMWARE_VERSION +#define DFU_IDENT "Black Magic Firmware Upgrade " PLATFORM_IDENT FIRMWARE_VERSION static const char *usb_strings[] = { "Black Sphere Technologies", From 4eb336277c68c8826ab73f6f2ee7f34455b43b21 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 16 Dec 2020 17:02:22 +0100 Subject: [PATCH 10/22] native: Remove high current draw (#814) Special iRST_SENSE handling does not apply at least for BMP 2.1c. On V2.1c, iRST_SENSE was set as output high and xRST high shorted iRST_SENSE to ground via Q2 FIXME: Check for older versions! --- src/platforms/native/platform.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 2f6e87f4..798a7f0d 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -131,10 +131,6 @@ void platform_init(void) GPIO_CNF_OUTPUT_PUSHPULL, LED_UART | LED_IDLE_RUN | LED_ERROR); - /* FIXME: This pin in intended to be input, but the TXS0108 fails - * to release the device from reset if this floats. */ - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO7); /* Enable SRST output. Original uses a NPN to pull down, so setting the * output HIGH asserts. Mini is directly connected so use open drain output * and set LOW to assert. @@ -146,7 +142,17 @@ void platform_init(void) ? GPIO_CNF_OUTPUT_PUSHPULL : GPIO_CNF_OUTPUT_OPENDRAIN), SRST_PIN); - + /* FIXME: Gareth, Esden, what versions need this fix? */ + if (platform_hwversion() < 3) { + /* FIXME: This pin in intended to be input, but the TXS0108 fails + * to release the device from reset if this floats. */ + gpio_set_mode(SRST_SENSE_PORT, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, SRST_SENSE_PIN); + } else { + gpio_set(SRST_SENSE_PORT, SRST_SENSE_PIN); + gpio_set_mode(SRST_SENSE_PORT, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_PULL_UPDOWN, SRST_SENSE_PIN); + } /* Enable internal pull-up on PWR_BR so that we don't drive TPWR locally or inadvertently supply power to the target. */ if (platform_hwversion () == 1) { From 165560edd8d93f89c342931e64442b7f7d03d48a Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 10 Feb 2021 21:43:44 +0100 Subject: [PATCH 11/22] cl_utils: target selection '-n' argument needs optarg. foreach now returns the number of targets. --- src/include/target.h | 2 +- src/platforms/pc/cl_utils.c | 10 +++++----- src/target/target.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/include/target.h b/src/include/target.h index 7c71340f..b7808d72 100644 --- a/src/include/target.h +++ b/src/include/target.h @@ -41,7 +41,7 @@ int platform_jtag_scan(const uint8_t *lrlens); int adiv5_swdp_scan(void); int jtag_scan(const uint8_t *lrlens); -bool target_foreach(void (*cb)(int i, target *t, void *context), void *context); +int target_foreach(void (*cb)(int i, target *t, void *context), void *context); void target_list_free(void); /* Attach/detach functions */ diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 686828fa..3d4a3fd2 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -1,7 +1,7 @@ /* * This file is part of the Black Magic Debug project. * - * Copyright (C) 2019 - 2020 Uwe Bonnes + * Copyright (C) 2019 - 2021 Uwe Bonnes * (bon@elektron.ikp.physik.tu-darmstadt.de) * * This program is free software: you can redistribute it and/or modify @@ -168,7 +168,7 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) opt->opt_flash_size = 16 * 1024 *1024; opt->opt_flash_start = 0xffffffff; opt->opt_max_swj_frequency = 4000000; - while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:CnltVtTa:S:jpP:rR")) != -1) { + while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:tVtTa:S:jpP:rR")) != -1) { switch(c) { case 'c': if (optarg) @@ -333,11 +333,11 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) DEBUG_WARN("No target found\n"); return res; } else { - target_foreach(display_target, NULL); + num_targets = target_foreach(display_target, &num_targets); } if (opt->opt_target_dev > num_targets) { - DEBUG_WARN("Given target nummer %d not available\n", - opt->opt_target_dev); + DEBUG_WARN("Given target nummer %d not available max %d\n", + opt->opt_target_dev, num_targets); return res; } target *t = target_attach_n(opt->opt_target_dev, NULL); diff --git a/src/target/target.c b/src/target/target.c index 5a5ec388..3004c975 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -69,13 +69,13 @@ target *target_new(void) return t; } -bool target_foreach(void (*cb)(int, target *t, void *context), void *context) +int target_foreach(void (*cb)(int, target *t, void *context), void *context) { int i = 1; target *t = target_list; for (; t; t = t->next, i++) cb(i, t, context); - return target_list != NULL; + return i; } void target_mem_map_free(target *t) From 8e2f6937d5942cb69434c634f66980d6e2d9de1a Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 30 Dec 2020 11:56:24 +0100 Subject: [PATCH 12/22] hosted: Run target specific monitor commands with -M "command" . Lists available commands: "blackmagic -M help" Quote multi argument monitor commands, e.g. STM32F1: blackmagic -M "option help" --- src/command.c | 19 ++++++++----------- src/platforms/hosted/Readme.md | 14 +++++++++++++- src/platforms/pc/cl_utils.c | 34 ++++++++++++++++++++++++++++++---- src/platforms/pc/cl_utils.h | 2 ++ src/target/target.c | 2 +- 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/src/command.c b/src/command.c index 9f15c211..c84237b0 100644 --- a/src/command.c +++ b/src/command.c @@ -3,6 +3,8 @@ * * Copyright (C) 2011 Black Sphere Technologies Ltd. * Written by Gareth McMullin + * Copyright (C) 2021 Uwe Bonnes + * (bon@elektron.ikp.physik.tu-darmstadt.de) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +29,7 @@ #include "command.h" #include "gdb_packet.h" #include "target.h" +#include "target_internal.h" #include "morse.h" #include "version.h" #include "serialno.h" @@ -37,13 +40,6 @@ typedef bool (*cmd_handler)(target *t, int argc, const char **argv); -struct command_s { - const char *cmd; - cmd_handler handler; - - const char *help; -}; - static bool cmd_version(target *t, int argc, char **argv); static bool cmd_help(target *t, int argc, char **argv); @@ -161,10 +157,11 @@ bool cmd_help(target *t, int argc, char **argv) (void)argv; const struct command_s *c; - gdb_out("General commands:\n"); - for(c = cmd_list; c->cmd; c++) - gdb_outf("\t%s -- %s\n", c->cmd, c->help); - + if (!t || t->tc->destroy_callback) { + gdb_out("General commands:\n"); + for(c = cmd_list; c->cmd; c++) + gdb_outf("\t%s -- %s\n", c->cmd, c->help); + } if (!t) return -1; diff --git a/src/platforms/hosted/Readme.md b/src/platforms/hosted/Readme.md index 13477ddd..5f3e24d1 100644 --- a/src/platforms/hosted/Readme.md +++ b/src/platforms/hosted/Readme.md @@ -36,7 +36,19 @@ blackmagic -V .bin ``` ### Show more options ``` -blackmagic -h" +blackmagic -h +``` +### Show available monitor commands +``` +blackmagic -M help +``` +### Show available monitor commands on second target +``` +blackmagic -n 2 -M help +``` +### Monitor commands with multiple arguments, e.g.Stm32F1: +``` +blackmagic -M "option help" ``` ## Used shared libraries: ### libusb diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 3d4a3fd2..a675657e 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -32,6 +32,7 @@ #include "target.h" #include "target_internal.h" #include "cortexm.h" +#include "command.h" #include "cl_utils.h" #include "bmp_hosted.h" @@ -45,6 +46,18 @@ # include #endif +static void cl_target_printf(struct target_controller *tc, + const char *fmt, va_list ap) +{ + (void)tc; + + vprintf(fmt, ap); +} + +static struct target_controller cl_controller = { + .printf = cl_target_printf, +}; + struct mmap_data { void *data; size_t size; @@ -152,6 +165,8 @@ static void cl_help(char **argv) DEBUG_WARN("\t-p\t\t: Supplies power to the target (where applicable)\n"); DEBUG_WARN("\t-R\t\t: Reset device\n"); DEBUG_WARN("\t-H\t\t: Do not use high level commands (BMP-Remote)\n"); + DEBUG_WARN("\t-M \t: Run target specific monitor commands. Quote multi\n"); + DEBUG_WARN("\t\t\t word strings. Run \"-M help\" for help.\n"); DEBUG_WARN("Flash operation modifiers options:\n"); DEBUG_WARN("\tDefault action with given file is to write to flash\n"); DEBUG_WARN("\t-a \t: Start flash operation at flash address \n" @@ -168,7 +183,7 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) opt->opt_flash_size = 16 * 1024 *1024; opt->opt_flash_start = 0xffffffff; opt->opt_max_swj_frequency = 4000000; - while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:tVtTa:S:jpP:rR")) != -1) { + while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:M:tVtTa:S:jpP:rR")) != -1) { switch(c) { case 'c': if (optarg) @@ -255,6 +270,11 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) if (optarg) opt->opt_target_dev = strtol(optarg, NULL, 0); break; + case 'M': + opt->opt_mode = BMP_MODE_MONITOR; + if (optarg) + opt->opt_monitor = optarg; + break; case 'P': if (optarg) opt->opt_position = atoi(optarg); @@ -340,7 +360,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) opt->opt_target_dev, num_targets); return res; } - target *t = target_attach_n(opt->opt_target_dev, NULL); + target *t = target_attach_n(opt->opt_target_dev, &cl_controller); + if (!t) { DEBUG_WARN("Can not attach to target %d\n", opt->opt_target_dev); goto target_detach; @@ -403,6 +424,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) default: DEBUG_WARN("No test for this core type yet\n"); } + } else if (opt->opt_mode == BMP_MODE_MONITOR) { + command_process(t, opt->opt_monitor); } if ((opt->opt_mode == BMP_MODE_TEST) || (opt->opt_mode == BMP_MODE_SWJ_TEST)) @@ -525,8 +548,11 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) uint32_t end_time = platform_time_ms(); if (read_file != -1) close(read_file); - DEBUG_WARN("Read/Verify succeeded for %d bytes, %8.3f kiB/s\n", - bytes_read, (((bytes_read * 1.0)/(end_time - start_time)))); + if ((opt->opt_mode == BMP_MODE_FLASH_VERIFY) || + (opt->opt_mode == BMP_MODE_FLASH_READ)) + DEBUG_WARN("Read/Verify succeeded for %d bytes, %8.3f kiB/s\n", + bytes_read, + (((bytes_read * 1.0)/(end_time - start_time)))); } free_map: if (map.size) diff --git a/src/platforms/pc/cl_utils.h b/src/platforms/pc/cl_utils.h index 81aedc66..4e6c8516 100644 --- a/src/platforms/pc/cl_utils.h +++ b/src/platforms/pc/cl_utils.h @@ -35,6 +35,7 @@ enum bmp_cl_mode { BMP_MODE_FLASH_READ, BMP_MODE_FLASH_VERIFY, BMP_MODE_SWJ_TEST, + BMP_MODE_MONITOR, }; typedef struct BMP_CL_OPTIONS_s { @@ -51,6 +52,7 @@ typedef struct BMP_CL_OPTIONS_s { char *opt_ident_string; int opt_position; char *opt_cable; + char *opt_monitor; int opt_debuglevel; int opt_target_dev; uint32_t opt_flash_start; diff --git a/src/target/target.c b/src/target/target.c index 3004c975..ea07c237 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -100,7 +100,7 @@ void target_list_free(void) while(target_list) { target *t = target_list->next; - if (target_list->tc) + if (target_list->tc && target_list->tc->destroy_callback) target_list->tc->destroy_callback(target_list->tc, target_list); if (target_list->priv) target_list->priv_free(target_list->priv); From c776e7a9a6309fb8172dd62c169d7e217ce94088 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 10 Feb 2021 10:18:31 +0100 Subject: [PATCH 13/22] swd_scan: Add '-m' as targetid argument to swd_scan to prepare multi-drop. In a real multi-drop setup, the device to use must be specified. --- src/command.c | 9 +++++---- src/include/target.h | 4 ++-- src/platforms/hosted/platform.c | 8 +++++--- src/platforms/pc/cl_utils.c | 9 +++++++-- src/platforms/pc/cl_utils.h | 3 ++- src/target/adiv5_swdp.c | 5 +++-- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/command.c b/src/command.c index c84237b0..859496af 100644 --- a/src/command.c +++ b/src/command.c @@ -219,8 +219,9 @@ static bool cmd_jtag_scan(target *t, int argc, char **argv) bool cmd_swdp_scan(target *t, int argc, char **argv) { (void)t; - (void)argc; - (void)argv; + volatile uint32_t targetid = 0; + if (argc > 1) + targetid = strtol(argv[1], NULL, 0); if (platform_target_voltage()) gdb_outf("Target voltage: %s\n", platform_target_voltage()); @@ -231,9 +232,9 @@ bool cmd_swdp_scan(target *t, int argc, char **argv) volatile struct exception e; TRY_CATCH (e, EXCEPTION_ALL) { #if PC_HOSTED == 1 - devs = platform_adiv5_swdp_scan(); + devs = platform_adiv5_swdp_scan(targetid); #else - devs = adiv5_swdp_scan(); + devs = adiv5_swdp_scan(targetid); #endif } switch (e.type) { diff --git a/src/include/target.h b/src/include/target.h index b7808d72..5cf04ac5 100644 --- a/src/include/target.h +++ b/src/include/target.h @@ -35,10 +35,10 @@ typedef uint32_t target_addr; struct target_controller; #if PC_HOSTED == 1 -int platform_adiv5_swdp_scan(void); +int platform_adiv5_swdp_scan(uint32_t targetid); int platform_jtag_scan(const uint8_t *lrlens); #endif -int adiv5_swdp_scan(void); +int adiv5_swdp_scan(uint32_t targetid); int jtag_scan(const uint8_t *lrlens); int target_foreach(void (*cb)(int i, target *t, void *context), void *context); diff --git a/src/platforms/hosted/platform.c b/src/platforms/hosted/platform.c index 7b95c8db..fc4d1011 100644 --- a/src/platforms/hosted/platform.c +++ b/src/platforms/hosted/platform.c @@ -1,7 +1,7 @@ /* * This file is part of the Black Magic Debug project. * - * Copyright (C) 2020 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de) + * Copyright (C) 2020- 2021 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -119,14 +119,16 @@ void platform_init(int argc, char **argv) exit(ret); } -int platform_adiv5_swdp_scan(void) +int platform_adiv5_swdp_scan(uint32_t targetid) { info.is_jtag = false; platform_max_frequency_set(cl_opts.opt_max_swj_frequency); + if (targetid && (info.bmp_type != BMP_TYPE_BMP)) + DEBUG_WARN("Ignoring TARGETID for now!\n"); switch (info.bmp_type) { case BMP_TYPE_BMP: case BMP_TYPE_LIBFTDI: - return adiv5_swdp_scan(); + return adiv5_swdp_scan(targetid); break; case BMP_TYPE_STLINKV2: { diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index a675657e..92cf29af 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -165,6 +165,7 @@ static void cl_help(char **argv) DEBUG_WARN("\t-p\t\t: Supplies power to the target (where applicable)\n"); DEBUG_WARN("\t-R\t\t: Reset device\n"); DEBUG_WARN("\t-H\t\t: Do not use high level commands (BMP-Remote)\n"); + DEBUG_WARN("\t-m \t: Use (target)id for SWD multi-drop.\n"); DEBUG_WARN("\t-M \t: Run target specific monitor commands. Quote multi\n"); DEBUG_WARN("\t\t\t word strings. Run \"-M help\" for help.\n"); DEBUG_WARN("Flash operation modifiers options:\n"); @@ -183,7 +184,7 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) opt->opt_flash_size = 16 * 1024 *1024; opt->opt_flash_start = 0xffffffff; opt->opt_max_swj_frequency = 4000000; - while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:M:tVtTa:S:jpP:rR")) != -1) { + while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:m:M:tVtTa:S:jpP:rR")) != -1) { switch(c) { case 'c': if (optarg) @@ -270,6 +271,10 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) if (optarg) opt->opt_target_dev = strtol(optarg, NULL, 0); break; + case 'm': + if (optarg) + opt->opt_targetid = strtol(optarg, NULL, 0); + break; case 'M': opt->opt_mode = BMP_MODE_MONITOR; if (optarg) @@ -347,7 +352,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) if (opt->opt_usejtag) { num_targets = platform_jtag_scan(NULL); } else { - num_targets = platform_adiv5_swdp_scan(); + num_targets = platform_adiv5_swdp_scan(opt->opt_targetid); } if (!num_targets) { DEBUG_WARN("No target found\n"); diff --git a/src/platforms/pc/cl_utils.h b/src/platforms/pc/cl_utils.h index 4e6c8516..e002cda9 100644 --- a/src/platforms/pc/cl_utils.h +++ b/src/platforms/pc/cl_utils.h @@ -1,7 +1,7 @@ /* * This file is part of the Black Magic Debug project. * - * Copyright (C) 2019 - 2020 Uwe Bonnes + * Copyright (C) 2019 - 2021 Uwe Bonnes * Written by Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de) * * This program is free software: you can redistribute it and/or modify @@ -49,6 +49,7 @@ typedef struct BMP_CL_OPTIONS_s { char *opt_flash_file; char *opt_device; char *opt_serial; + uint32_t opt_targetid; char *opt_ident_string; int opt_position; char *opt_cable; diff --git a/src/target/adiv5_swdp.c b/src/target/adiv5_swdp.c index 0678064b..68c36023 100644 --- a/src/target/adiv5_swdp.c +++ b/src/target/adiv5_swdp.c @@ -3,6 +3,7 @@ * * Copyright (C) 2011 Black Sphere Technologies Ltd. * Written by Gareth McMullin + * Copyright (C) 2020- 2021 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,10 +34,10 @@ #define SWDP_ACK_WAIT 0x02 #define SWDP_ACK_FAULT 0x04 -int adiv5_swdp_scan(void) +int adiv5_swdp_scan(uint32_t targetid) { uint32_t ack; - + (void) targetid; target_list_free(); #if PC_HOSTED == 1 if (platform_swdptap_init()) { From d70fa8c7f6b11ee22f6511d062c96a6a00a2c3bc Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Fri, 12 Feb 2021 00:01:05 +0100 Subject: [PATCH 14/22] hosted: Remove restrictions when gathering information on the debugger That way, we find RPI Pico pico-debug. --- src/platforms/hosted/bmp_libusb.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/platforms/hosted/bmp_libusb.c b/src/platforms/hosted/bmp_libusb.c index 06134a36..0264f25b 100644 --- a/src/platforms/hosted/bmp_libusb.c +++ b/src/platforms/hosted/bmp_libusb.c @@ -1,7 +1,7 @@ /* * This file is part of the Black Magic Debug project. * - * Copyright (C) 2020 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de) + * Copyright(C) 2020 - 2021 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -149,22 +149,9 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) res = libusb_get_string_descriptor_ascii( handle, desc.iManufacturer, (uint8_t*)manufacturer, sizeof(manufacturer)); - if (res > 0) { - res = libusb_get_string_descriptor_ascii( - handle, desc.iProduct, (uint8_t*)product, - sizeof(product)); - if (res <= 0) { - DEBUG_WARN( "WARN:" - "libusb_get_string_descriptor_ascii " - "for ident_string failed: %s\n", - libusb_strerror(res)); - libusb_close(handle); - continue; - } - } else { - libusb_close(handle); - continue; - } + res = libusb_get_string_descriptor_ascii( + handle, desc.iProduct, (uint8_t*)product, + sizeof(product)); libusb_close(handle); if (cl_opts->opt_ident_string) { char *match_manu = NULL; From 0df44e205ba5c4e82ad47f2b9b7442fa5fd98ed9 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Tue, 16 Feb 2021 20:17:07 +0100 Subject: [PATCH 15/22] ADIv5: Abort Romtable scan also if CIDR0 is invalid after halting #832 STM32WLE5 has the same dual core chip as STM32WL5. For the second core, the additional AP can be see, but access to e.g. CIDR0 for that Romtable fails. Aborting the scan too if again the second read of CIDR0 fails makes sense anyways! --- src/target/adiv5.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/target/adiv5.c b/src/target/adiv5.c index a45bb1d8..7a6f28d7 100644 --- a/src/target/adiv5.c +++ b/src/target/adiv5.c @@ -416,6 +416,8 @@ static void adiv5_component_probe(ADIv5_AP_t *ap, uint32_t addr, int recursion, return; /* Halting failed! */ /* CPU now halted, read cidr again. */ cidr = adiv5_ap_read_id(ap, addr + CIDR0_OFFSET); + if ((cidr & ~CID_CLASS_MASK) != CID_PREAMBLE) + return; } } #if defined(ENABLE_DEBUG) From aeae9f7cde568e0c49a5355aff4d170bdae0f0e7 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Tue, 16 Feb 2021 22:23:19 +0100 Subject: [PATCH 16/22] UsingSWO: Revisit Baudrate calculation and limits. There are more SWO frequency options than the old documents indicated --- UsingSWO | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/UsingSWO b/UsingSWO index a9d8ee16..d8ad984b 100644 --- a/UsingSWO +++ b/UsingSWO @@ -14,24 +14,28 @@ monitor traceswo 115200 We are constrained on maximum input speed by both the capabilities of the BMP STM32F103 USART and the ability to get the packets back out over the USB -link. The UART baudrate is set by b=(72x10^6)/(16*d)...so for d=1 that means -a maximum speed of 4.5Mbps. For continious streaming that turns out to be -_too_ fast for the USB link, so the next available option is the 2.25Mbps -that we use. ....you can safely use the 4.5Mbps setting if your debug data +link. The UART baudrate is set by b=(72x10^6)/d...with d >= 16 or +a maximum speed of 4.5Mbps UART1 and 2.25 Mbps on UART2. +For continious streaming that turns out to be_too_ fast for the USB +link, so the next available option is the 2.25Mbps that we use. .... +You can safely use the 4.5Mbps setting if your debug data is bursty, or if you're using a different CPU to the STM32F103 as your BMP host, but you potentially run the risk of losing packets if you have long runs of sending which the usb cannot flush in time (there's a 12K buffer, so the it is a pretty long run before it becomes a problem). Note that the baudrate equation means there are only certain speeds -available. The highest half dozen are; -SWO uses USART1(stlink) USART2(swlink) -1 4.50 Mbps 2.25 Mbps -2 2.25 Mbps 1.125 Mbps -3 1.50 Mbps 0.75 Mbps -4 1.125 Mbps 0.5635 Mbps -5 0.900 Mbps 0.45 Mbps -6 0.750 Mbps 0.375 Mbps +available. The highest: +BRR USART1(stlink) USART2(swlink) +16 4.50 Mbps 2.25 Mbps +17 4.235 Mbps 2.118 Mbps +18 4.000 Mbps 2.0 Mbps +19 3.789 Mbps 1.895 Mbps +20 3.600 Mbps 1.8 Mbps +... +24 3.0 Mbps 1.5 Mbps +... +36 2.0 Mbps 1.0 Mbps ...the USART will cope with some timing slip, but it's advisible to stay as close to these values as you can. As the speed comes down the spread between From 560a046a22d54d0dc58a44337f8b3fe6ecb0800d Mon Sep 17 00:00:00 2001 From: Thiadmer Riemersma Date: Sat, 20 Feb 2021 21:07:08 +0100 Subject: [PATCH 17/22] Add support for NXP LPC802, LPC804, LPC832 and LPC834 --- src/target/cortexm.c | 2 ++ src/target/lpc11xx.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/target/cortexm.c b/src/target/cortexm.c index 78f5330e..99ae41f1 100644 --- a/src/target/cortexm.c +++ b/src/target/cortexm.c @@ -458,6 +458,8 @@ bool cortexm_probe(ADIv5_AP_t *ap) PROBE(kinetis_probe); /* Older K-series */ } else if (ap->ap_partno == 0x4cb) { /* Cortex-M23 ROM */ PROBE(gd32f1_probe); /* GD32E23x uses GD32F1 peripherals */ + } else if (ap->ap_partno == 0x4c0) { /* Cortex-M0+ ROM */ + PROBE(lpc11xx_probe); /* some of the LPC8xx series, like LPC802 */ } /* Info on PIDR of these parts wanted! */ PROBE(sam3x_probe); diff --git a/src/target/lpc11xx.c b/src/target/lpc11xx.c index 2b6d28b5..d487f337 100644 --- a/src/target/lpc11xx.c +++ b/src/target/lpc11xx.c @@ -29,8 +29,8 @@ #define MIN_RAM_SIZE 1024 #define RAM_USAGE_FOR_IAP_ROUTINES 32 /* IAP routines use 32 bytes at top of ram */ -#define IAP_ENTRY_MOST 0x1fff1ff1 /* all except LPC84x */ -#define IAP_ENTRY_84x 0x0f001ff1 +#define IAP_ENTRY_MOST 0x1fff1ff1 /* all except LPC802, LPC804 & LPC84x */ +#define IAP_ENTRY_84x 0x0f001ff1 /* LPC802, LPC804 & LPC84x */ #define IAP_RAM_BASE 0x10000000 #define LPC11XX_DEVICE_ID 0x400483F4 @@ -142,6 +142,25 @@ lpc11xx_probe(target *t) } idcode = target_mem_read32(t, LPC8XX_DEVICE_ID); switch (idcode) { + case 0x00008021: /* 802M001JDH20 */ + case 0x00008022: /* 802M011JDH20 */ + case 0x00008023: /* 802M001JDH16 */ + case 0x00008024: /* 802M001JHI33 */ + t->driver = "LPC802"; + target_add_ram(t, 0x10000000, 0x800); + lpc11xx_add_flash(t, 0x00000000, 0x4000, 0x400, IAP_ENTRY_84x); + target_add_commands(t, lpc11xx_cmd_list, "LPC802"); + return true; + case 0x00008040: /* 804M101JBD64 */ + case 0x00008041: /* 804M101JDH20 */ + case 0x00008042: /* 804M101JDH24 */ + case 0x00008043: /* 804M111JDH24 */ + case 0x00008044: /* 804M101JHI33 */ + t->driver = "LPC804"; + target_add_ram(t, 0x10000000, 0x1000); + lpc11xx_add_flash(t, 0x00000000, 0x8000, 0x400, IAP_ENTRY_84x); + target_add_commands(t, lpc11xx_cmd_list, "LPC804"); + return true; case 0x00008100: /* LPC810M021FN8 */ case 0x00008110: /* LPC811M001JDH16 */ case 0x00008120: /* LPC812M101JDH16 */ @@ -161,6 +180,18 @@ lpc11xx_probe(target *t) lpc11xx_add_flash(t, 0x00000000, 0x8000, 0x400, IAP_ENTRY_MOST); target_add_commands(t, lpc11xx_cmd_list, "LPC82x"); return true; + case 0x00008322: /* LPC832M101FDH20 */ + t->driver = "LPC832"; + target_add_ram(t, 0x10000000, 0x1000); + lpc11xx_add_flash(t, 0x00000000, 0x4000, 0x400, IAP_ENTRY_MOST); + target_add_commands(t, lpc11xx_cmd_list, "LPC832"); + return true; + case 0x00008341: /* LPC8341201FHI33 */ + t->driver = "LPC834"; + target_add_ram(t, 0x10000000, 0x1000); + lpc11xx_add_flash(t, 0x00000000, 0x8000, 0x400, IAP_ENTRY_MOST); + target_add_commands(t, lpc11xx_cmd_list, "LPC834"); + return true; case 0x00008441: case 0x00008442: case 0x00008443: /* UM11029 Rev.1.4 list 8442 */ From 43770736f139f6e2a291d981b04ecd43724bc313 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sun, 28 Feb 2021 13:54:00 +0100 Subject: [PATCH 18/22] cl_utils: Rework Flash/Ram printout --- src/platforms/pc/cl_utils.c | 63 ++++++++++++++----------------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 92cf29af..df13c123 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -371,48 +371,33 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) DEBUG_WARN("Can not attach to target %d\n", opt->opt_target_dev); goto target_detach; } + /* List each defined RAM */ + int n_ram = 0; + for (struct target_ram *r = t->ram; r; r = r->next) + n_ram++; + for (int n = n_ram; n >= 0; n --) { + struct target_ram *r = t->ram; + for (int i = 1; r; r = r->next, i++) + if (i == n) + DEBUG_INFO("RAM Start: 0x%08" PRIx32 " length = 0x%" PRIx32 "\n", + r->start, (uint32_t)r->length); + } /* Always scan memory map to find lowest flash */ - char memory_map [1024], *p = memory_map; + /* List each defined Flash */ uint32_t flash_start = 0xffffffff; - if (target_mem_map(t, memory_map, sizeof(memory_map))) { - while (*p && (*p == '<')) { - unsigned int start, size; - char *res; - int match; - match = strncmp(p, "", strlen("")); - if (!match) { - p += strlen(""); - continue; + int n_flash = 0; + for (struct target_flash *f = t->flash; f; f = f->next) + n_flash++; + for (int n = n_flash; n >= 0; n --) { + struct target_flash *f = t->flash; + for (int i = 1; f; f = f->next, i++) + if (i == n) { + DEBUG_INFO("Flash Start: 0x%08" PRIx32 " length = 0x%" PRIx32 + " blocksize 0x%" PRIx32 "\n", + f->start, (uint32_t)f->length, (uint32_t)f->blocksize); + if (f->start < flash_start) + flash_start = f->start; } - match = strncmp(p, "" - "%x", - &start, &size, &blocksize)) { - if (opt->opt_mode == BMP_MODE_TEST) - DEBUG_INFO("Flash Start: 0x%08x, length %#9x, " - "blocksize %#8x\n", start, size, blocksize); - if (start < flash_start) - flash_start = start; - } - res = strstr(p, ""); - p = res + strlen(""); - continue; - } - match = strncmp(p, "opt_mode == BMP_MODE_TEST) - DEBUG_INFO("Ram Start: 0x%08x, length %#9x\n", - start, size); - res = strstr(p, "/>"); - p = res + strlen("/>"); - continue; - } - break; - } } if (opt->opt_flash_start == 0xffffffff) opt->opt_flash_start = flash_start; From 3aa6f169642a7b6808c13cfcbd3d5fbe28508a76 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 3 Mar 2021 12:08:39 +0100 Subject: [PATCH 19/22] serial_unix: Split timeout in seconds and microseconds Macos exposed errors when tv_usec was > 1000000. --- src/platforms/pc/serial_unix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platforms/pc/serial_unix.c b/src/platforms/pc/serial_unix.c index 11000351..96e2da92 100644 --- a/src/platforms/pc/serial_unix.c +++ b/src/platforms/pc/serial_unix.c @@ -190,7 +190,8 @@ int platform_buffer_read(uint8_t *data, int maxsize) c = data; tv.tv_sec = 0; - tv.tv_usec = 1000 * cortexm_wait_timeout; + tv.tv_sec = cortexm_wait_timeout / 1000 ; + tv.tv_usec = 1000 * (cortexm_wait_timeout % 1000); /* Look for start of response */ do { From cfb784d428780166ad41842f7bf2ed31d696f2d0 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 27 Feb 2021 14:39:17 +0100 Subject: [PATCH 20/22] adiv5: Fix comments and debug output --- src/target/adiv5.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/target/adiv5.c b/src/target/adiv5.c index 7a6f28d7..28267740 100644 --- a/src/target/adiv5.c +++ b/src/target/adiv5.c @@ -322,7 +322,7 @@ uint64_t adiv5_ap_read_pidr(ADIv5_AP_t *ap, uint32_t addr) * DBGMCU_CR not set. * * Keep a copy of DEMCR at startup to restore with exit, to - * not interrupt tracing initialed by the CPU. + * not interrupt tracing initiated by the CPU. */ static bool cortexm_prepare(ADIv5_AP_t *ap) { @@ -339,6 +339,8 @@ static bool cortexm_prepare(ADIv5_AP_t *ap) while (true) { adiv5_mem_write(ap, CORTEXM_DHCSR, &dhcsr_ctl, sizeof(dhcsr_ctl)); dhcsr = adiv5_mem_read32(ap, CORTEXM_DHCSR); + /* ADIV5_DP_CTRLSTAT_READOK is always set e.g. on STM32F7 even so + CORTEXM_DHCS reads nonsense*/ /* On a sleeping STM32F7, invalid DHCSR reads with e.g. 0xffffffff and * 0x0xA05F0000 may happen. * M23/33 will have S_SDE set when debug is allowed @@ -606,9 +608,9 @@ ADIv5_AP_t *adiv5_new_ap(ADIv5_DP_t *dp, uint8_t apsel) #if defined(ENABLE_DEBUG) uint32_t cfg = adiv5_ap_read(ap, ADIV5_AP_CFG); DEBUG_INFO("AP %3d: IDR=%08"PRIx32" CFG=%08"PRIx32" BASE=%08" PRIx32 - " CSW=%08"PRIx32"\n", apsel, ap->idr, cfg, ap->base, ap->csw); - DEBUG_INFO("AP#0 IDR = 0x%08" PRIx32 " (AHB-AP var%x rev%x)\n", - ap->idr, (ap->idr >> 4) & 0xf, ap->idr >> 28); + " CSW=%08"PRIx32, apsel, ap->idr, cfg, ap->base, ap->csw); + DEBUG_INFO(" (AHB-AP var%x rev%x)\n", + (ap->idr >> 4) & 0xf, ap->idr >> 28); #endif adiv5_ap_ref(ap); return ap; From 7859a2aabd40e09d54a6fc00847726e3233c0a5c Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 10 Feb 2021 12:52:09 +0100 Subject: [PATCH 21/22] adiv5_swd: Factor out creation of packet request. --- src/target/adiv5_swdp.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/target/adiv5_swdp.c b/src/target/adiv5_swdp.c index 68c36023..24af6c49 100644 --- a/src/target/adiv5_swdp.c +++ b/src/target/adiv5_swdp.c @@ -34,6 +34,21 @@ #define SWDP_ACK_WAIT 0x02 #define SWDP_ACK_FAULT 0x04 +static unsigned int make_packet_request(uint8_t RnW, uint16_t addr) +{ + bool APnDP = addr & ADIV5_APnDP; + addr &= 0xff; + unsigned int request = 0x81; /* Park and Startbit */ + if(APnDP) request ^= 0x22; + if(RnW) request ^= 0x24; + + addr &= 0xC; + request |= (addr << 1) & 0x18; + if((addr == 4) || (addr == 8)) + request ^= 0x20; + return request; +} + int adiv5_swdp_scan(uint32_t targetid) { uint32_t ack; @@ -61,7 +76,8 @@ int adiv5_swdp_scan(uint32_t targetid) /* Read the SW-DP IDCODE register to syncronise */ /* This could be done with adiv_swdp_low_access(), but this doesn't * allow the ack to be checked here. */ - swd_proc.swdptap_seq_out(0xA5, 8); + uint32_t request = make_packet_request(ADIV5_LOW_READ, ADIV5_DP_IDCODE); + swd_proc.swdptap_seq_out(request, 8); ack = swd_proc.swdptap_seq_in(3); uint32_t idcode; if((ack != SWDP_ACK_OK) || swd_proc.swdptap_seq_in_parity(&idcode, 32)) { @@ -123,22 +139,12 @@ uint32_t firmware_swdp_read(ADIv5_DP_t *dp, uint16_t addr) uint32_t firmware_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, uint16_t addr, uint32_t value) { - bool APnDP = addr & ADIV5_APnDP; - addr &= 0xff; - uint32_t request = 0x81; + uint32_t request = make_packet_request(RnW, addr); uint32_t response = 0; uint32_t ack; platform_timeout timeout; - if(APnDP && dp->fault) return 0; - - if(APnDP) request ^= 0x22; - if(RnW) request ^= 0x24; - - addr &= 0xC; - request |= (addr << 1) & 0x18; - if((addr == 4) || (addr == 8)) - request ^= 0x20; + if((addr & ADIV5_APnDP) && dp->fault) return 0; platform_timeout_set(&timeout, 2000); do { From e6a9a1a3665e83e25d5d4077a33aa5b0110646b8 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Fri, 12 Feb 2021 17:31:29 +0100 Subject: [PATCH 22/22] cmsis-dap: Get the firmware version. --- src/platforms/hosted/cmsis_dap.c | 34 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/platforms/hosted/cmsis_dap.c b/src/platforms/hosted/cmsis_dap.c index 06894174..a4056eb0 100644 --- a/src/platforms/hosted/cmsis_dap.c +++ b/src/platforms/hosted/cmsis_dap.c @@ -1,7 +1,7 @@ /* * This file is part of the Black Magic Debug project. * - * Copyright (C) 2019-20 Uwe Bonnes + * Copyright (C) 2019-2021 Uwe Bonnes * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,10 +49,11 @@ uint8_t mode; static hid_device *handle = NULL; static uint8_t hid_buffer[1024 + 1]; static int report_size = 64 + 1; // TODO: read actual report size +static bool has_swd_sequence = false; + /* LPC845 Breakout Board Rev. 0 report invalid response with > 65 bytes */ int dap_init(bmp_info_t *info) { - DEBUG_INFO("dap_init\n"); if (hid_init()) return -1; int size = strlen(info->serial); @@ -71,17 +72,32 @@ int dap_init(bmp_info_t *info) if (!handle) return -1; dap_disconnect(); + size = dap_info(DAP_INFO_FW_VER, hid_buffer, sizeof(hid_buffer)); + if (size) { + DEBUG_INFO("Ver %s, ", hid_buffer); + int major = -1, minor = -1, sub = -1; + if (sscanf((const char *)hid_buffer, "%d.%d.%d", + &major, &minor, &sub)) { + if (sub == -1) { + if (minor > 10) { + minor /= 10; + sub = 0; + } + } + has_swd_sequence = ((major > 0 ) && (minor > 1)); + } + } size = dap_info(DAP_INFO_CAPABILITIES, hid_buffer, sizeof(hid_buffer)); dap_caps = hid_buffer[0]; - DEBUG_INFO(" Cap (0x%2x): %s%s%s", hid_buffer[0], - (hid_buffer[0] & 1)? "SWD" : "", - ((hid_buffer[0] & 3) == 3) ? "/" : "", - (hid_buffer[0] & 2)? "JTAG" : ""); - if (hid_buffer[0] & 4) + DEBUG_INFO("Cap (0x%2x): %s%s%s", dap_caps, + (dap_caps & 1)? "SWD" : "", + ((dap_caps & 3) == 3) ? "/" : "", + (dap_caps & 2)? "JTAG" : ""); + if (dap_caps & 4) DEBUG_INFO(", SWO_UART"); - if (hid_buffer[0] & 8) + if (dap_caps & 8) DEBUG_INFO(", SWO_MANCHESTER"); - if (hid_buffer[0] & 0x10) + if (dap_caps & 0x10) DEBUG_INFO(", Atomic Cmds"); DEBUG_INFO("\n"); return 0;