From e0fc21a2a715893331f49d9d838bc0d4a69cf84c Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sun, 5 May 2013 00:46:47 +0400 Subject: adiv5_swdp: allow to connect to a sleeping target by pulling SRST This patch introduces a new command, "connect_srst [enable|disable]" which allows to enable special mode in which SRST would be pulled low before the SWD scan till attaching to a target. Since on Cortex-Mx the SRST signal doesn't gate JTAG and SWD, it's possible to connect to a target while holding reset, ask it to stop at reset vector and only then deassert reset, thus allowing to attach to the kind of firmware that goes immediately to sleep or disables debugging by other means early on start. Tested on an STM32VLDiscovery board with STM32F100 configured to go to STOP mode and executing WFI in the very beginning of main(). Signed-off-by: Paul Fertser --- src/adiv5_swdp.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/adiv5_swdp.c') diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 06d5446..669bf42 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -27,6 +27,7 @@ #include "adiv5.h" #include "swdptap.h" +#include "jtagtap.h" #include "command.h" @@ -53,6 +54,8 @@ int adiv5_swdp_scan(void) ADIv5_DP_t *dp = (void*)calloc(1, sizeof(*dp)); swdptap_init(); + if(connect_assert_srst) + jtagtap_srst(true); /* will be deasserted after attach */ /* 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. */ -- cgit v1.2.3 From 8c877d6dfa5aff2b70ce2c96ef6314bcae7a25c2 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Mon, 17 Jun 2013 15:53:32 +1200 Subject: Fix trailing whitespace everywhere. --- src/adiv5_jtagdp.c | 12 ++++++------ src/adiv5_swdp.c | 14 +++++++------- src/arm7tdmi.c | 6 +++--- src/command.c | 30 +++++++++++++++--------------- src/gdb_packet.c | 16 ++++++++-------- src/hex_utils.c | 6 +++--- src/include/adiv5.h | 4 ++-- src/include/jtagtap.h | 6 +++--- src/include/target.h | 12 ++++++------ src/jtagtap_generic.c | 8 ++++---- src/lmi.c | 6 +++--- src/main.c | 2 +- src/nxp_tgt.c | 12 ++++++------ src/platforms/libftdi/jtagtap.c | 12 ++++++------ src/platforms/libftdi/platform.c | 24 ++++++++++++------------ src/platforms/libftdi/swdptap.c | 10 +++++----- src/platforms/native/platform.c | 2 +- src/platforms/native/platform.h | 4 ++-- src/platforms/stlink/platform.c | 20 ++++++++++---------- src/platforms/stlink/platform.h | 2 +- src/platforms/stm32/swdptap.c | 8 ++++---- src/platforms/swlink/platform.c | 6 +++--- src/platforms/swlink/platform.h | 2 +- src/sam3x.c | 2 +- src/stm32f1.c | 14 +++++++------- src/stm32f4.c | 10 +++++----- src/stm32l1.c | 4 ++-- 27 files changed, 127 insertions(+), 127 deletions(-) (limited to 'src/adiv5_swdp.c') diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index 68bcddd..693b94e 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -/* This file implements the JTAG-DP specific functions of the +/* This file implements the JTAG-DP specific functions of the * ARM Debug Interface v5 Architecure Specification, ARM doc IHI0031A. */ @@ -43,7 +43,7 @@ static uint32_t adiv5_jtagdp_read(ADIv5_DP_t *dp, uint8_t addr); static uint32_t adiv5_jtagdp_error(ADIv5_DP_t *dp); -static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, +static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, uint8_t addr, uint32_t value); @@ -70,19 +70,19 @@ static void adiv5_jtagdp_write(ADIv5_DP_t *dp, uint8_t addr, uint32_t value) static uint32_t adiv5_jtagdp_read(ADIv5_DP_t *dp, uint8_t addr) { adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_READ, addr, 0); - return adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_READ, + return adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_READ, ADIV5_DP_RDBUFF, 0); } static uint32_t adiv5_jtagdp_error(ADIv5_DP_t *dp) { - adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_READ, + adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_READ, ADIV5_DP_CTRLSTAT, 0); - return adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_WRITE, + return adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_WRITE, ADIV5_DP_CTRLSTAT, 0xF0000032) & 0x32; } -static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, +static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, uint8_t addr, uint32_t value) { uint64_t request, response; diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 669bf42..8a38330 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -/* This file implements the SW-DP specific functions of the +/* This file implements the SW-DP specific functions of the * ARM Debug Interface v5 Architecure Specification, ARM doc IHI0031A. */ @@ -42,7 +42,7 @@ static uint32_t adiv5_swdp_read(ADIv5_DP_t *dp, uint8_t addr); static uint32_t adiv5_swdp_error(ADIv5_DP_t *dp); -static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, +static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, uint8_t addr, uint32_t value); @@ -95,15 +95,15 @@ static uint32_t adiv5_swdp_error(ADIv5_DP_t *dp) { uint32_t err, clr = 0; - err = adiv5_swdp_read(dp, ADIV5_DP_CTRLSTAT) & + err = adiv5_swdp_read(dp, ADIV5_DP_CTRLSTAT) & (ADIV5_DP_CTRLSTAT_STICKYORUN | ADIV5_DP_CTRLSTAT_STICKYCMP | ADIV5_DP_CTRLSTAT_STICKYERR); - if(err & ADIV5_DP_CTRLSTAT_STICKYORUN) + if(err & ADIV5_DP_CTRLSTAT_STICKYORUN) clr |= ADIV5_DP_ABORT_ORUNERRCLR; - if(err & ADIV5_DP_CTRLSTAT_STICKYCMP) + if(err & ADIV5_DP_CTRLSTAT_STICKYCMP) clr |= ADIV5_DP_ABORT_STKCMPCLR; - if(err & ADIV5_DP_CTRLSTAT_STICKYERR) + if(err & ADIV5_DP_CTRLSTAT_STICKYERR) clr |= ADIV5_DP_ABORT_STKERRCLR; adiv5_swdp_write(dp, ADIV5_DP_ABORT, clr); @@ -112,7 +112,7 @@ static uint32_t adiv5_swdp_error(ADIv5_DP_t *dp) return err; } -static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, +static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, uint8_t addr, uint32_t value) { uint8_t request = 0x81; diff --git a/src/arm7tdmi.c b/src/arm7tdmi.c index 805f995..ad38ab3 100644 --- a/src/arm7tdmi.c +++ b/src/arm7tdmi.c @@ -139,7 +139,7 @@ void arm7tdmi_jtag_handler(jtag_dev_t *dev) t->halt_request = arm7_halt_request; t->halt_wait = arm7_halt_wait; t->halt_resume = arm7_halt_resume; - + /* TODO: Breakpoint and watchpoint functions. */ /* TODO: Fault unwinder. */ /* TODO: Memory map / Flash programming. */ @@ -152,7 +152,7 @@ static void arm7_select_scanchain(struct target_arm7_s *target, uint8_t chain) jtag_dev_write_ir(target->jtag, ARM7_IR_INTEST); } -static void arm7_eice_write(struct target_arm7_s *target, +static void arm7_eice_write(struct target_arm7_s *target, uint8_t addr, uint32_t value) { uint64_t val = ((uint64_t)addr << 32) | value | ARM7_EICE_WRITE; @@ -256,7 +256,7 @@ static void arm7_halt_resume(struct target_s *target, bool step) /* Release DBGRQ */ arm7_eice_write(t, ARM7_EICE_DEBUG_CTRL, 0); - /* This sequence restores PC if no other instructions issued in + /* This sequence restores PC if no other instructions issued in * debug mode... * 0 E1A00000; MOV R0, R0 * 1 E1A00000; MOV R0, R0 diff --git a/src/command.c b/src/command.c index e9f7096..8378576 100644 --- a/src/command.c +++ b/src/command.c @@ -74,19 +74,19 @@ int command_process(target *t, char *cmd) const char **argv; /* Initial estimate for argc */ - for(char *s = cmd; *s; s++) + for(char *s = cmd; *s; s++) if((*s == ' ') || (*s == '\t')) argc++; argv = alloca(sizeof(const char *) * argc); /* Tokenize cmd to find argv */ - for(argc = 0, argv[argc] = strtok(cmd, " \t"); + for(argc = 0, argv[argc] = strtok(cmd, " \t"); argv[argc]; argv[++argc] = strtok(NULL, " \t")); /* Look for match and call handler */ for(c = cmd_list; c->cmd; c++) { /* Accept a partial match as GDB does. - * So 'mon ver' will match 'monitor version' + * So 'mon ver' will match 'monitor version' */ if(!strncmp(argv[0], c->cmd, strlen(argv[0]))) return !c->handler(t, argc, argv); @@ -96,7 +96,7 @@ int command_process(target *t, char *cmd) return -1; for (tc = t->commands; tc; tc = tc->next) - for(c = tc->cmds; c->cmd; c++) + for(c = tc->cmds; c->cmd; c++) if(!strncmp(argv[0], c->cmd, strlen(argv[0]))) return !c->handler(t, argc, argv); @@ -119,7 +119,7 @@ bool cmd_help(target *t) const struct command_s *c; gdb_out("General commands:\n"); - for(c = cmd_list; c->cmd; c++) + for(c = cmd_list; c->cmd; c++) gdb_outf("\t%s -- %s\n", c->cmd, c->help); if (!t) @@ -127,7 +127,7 @@ bool cmd_help(target *t) for (tc = t->commands; tc; tc = tc->next) { gdb_outf("%s specific commands:\n", tc->specific_name); - for(c = tc->cmds; c->cmd; c++) + for(c = tc->cmds; c->cmd; c++) gdb_outf("\t%s -- %s\n", c->cmd, c->help); } @@ -154,15 +154,15 @@ static bool cmd_jtag_scan(target *t, int argc, char **argv) if(devs < 0) { gdb_out("JTAG device scan failed!\n"); return false; - } + } if(devs == 0) { gdb_out("JTAG scan found no devices!\n"); return false; - } + } gdb_outf("Device IR Len IDCODE Description\n"); for(int i = 0; i < jtag_dev_count; i++) - gdb_outf("%d\t%d\t0x%08lX %s\n", i, - jtag_devs[i].ir_len, jtag_devs[i].idcode, + gdb_outf("%d\t%d\t0x%08lX %s\n", i, + jtag_devs[i].ir_len, jtag_devs[i].idcode, jtag_devs[i].descr); gdb_out("\n"); cmd_targets(NULL); @@ -176,13 +176,13 @@ bool cmd_swdp_scan(void) if(adiv5_swdp_scan() < 0) { gdb_out("SW-DP scan failed!\n"); return false; - } + } //gdb_outf("SW-DP detected IDCODE: 0x%08X\n", adiv5_dp_list->idcode); cmd_targets(NULL); return true; - + } bool cmd_targets(target *cur_target) @@ -194,11 +194,11 @@ bool cmd_targets(target *cur_target) gdb_out("No usable targets found.\n"); return false; } - + gdb_out("Available Targets:\n"); gdb_out("No. Att Driver\n"); for(t = target_list, i = 1; t; t = t->next, i++) - gdb_outf("%2d %c %s\n", i, t==cur_target?'*':' ', + gdb_outf("%2d %c %s\n", i, t==cur_target?'*':' ', t->driver); return true; @@ -206,7 +206,7 @@ bool cmd_targets(target *cur_target) bool cmd_morse(void) { - if(morse_msg) + if(morse_msg) gdb_outf("%s\n", morse_msg); return true; } diff --git a/src/gdb_packet.c b/src/gdb_packet.c index 958572c..d43be42 100644 --- a/src/gdb_packet.c +++ b/src/gdb_packet.c @@ -34,7 +34,7 @@ #include "gdb_packet.h" #include "hex_utils.h" -int +int gdb_getpacket(unsigned char *packet, int size) { unsigned char c; @@ -54,9 +54,9 @@ gdb_getpacket(unsigned char *packet, int size) if(i == size) break; /* Oh shit */ if(c == '$') { /* Restart capture */ - i = 0; - csum = 0; - continue; + i = 0; + csum = 0; + continue; } if(c == '}') { /* escaped char */ c = gdb_if_getchar(); @@ -70,7 +70,7 @@ gdb_getpacket(unsigned char *packet, int size) recv_csum[0] = gdb_if_getchar(); recv_csum[1] = gdb_if_getchar(); recv_csum[2] = 0; - + /* return packet if checksum matches */ if(csum == strtol(recv_csum, NULL, 16)) break; @@ -84,7 +84,7 @@ gdb_getpacket(unsigned char *packet, int size) DEBUG("%s : ", __func__); for(int j = 0; j < i; j++) { c = packet[j]; - if ((c >= 32) && (c < 127)) + if ((c >= 32) && (c < 127)) DEBUG("%c", c); else DEBUG("\\x%02X", c); @@ -101,7 +101,7 @@ void gdb_putpacket(unsigned char *packet, int size) unsigned char c; char xmit_csum[3]; int tries = 0; - + do { #ifdef DEBUG_GDBPACKET DEBUG("%s : ", __func__); @@ -111,7 +111,7 @@ void gdb_putpacket(unsigned char *packet, int size) for(i = 0; i < size; i++) { c = packet[i]; #ifdef DEBUG_GDBPACKET - if ((c >= 32) && (c < 127)) + if ((c >= 32) && (c < 127)) DEBUG("%c", c); else DEBUG("\\x%02X", c); diff --git a/src/hex_utils.c b/src/hex_utils.c index 6629f10..e477281 100644 --- a/src/hex_utils.c +++ b/src/hex_utils.c @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -/* Convenience function to convert to/from ascii strings of hex digits. +/* Convenience function to convert to/from ascii strings of hex digits. */ #include @@ -44,9 +44,9 @@ char * hexify(char *hex, const unsigned char *buf, int size) static uint8_t unhex_digit(char hex) { uint8_t tmp = hex - '0'; - if(tmp > 9) + if(tmp > 9) tmp -= 'A' - '0' - 10; - if(tmp > 16) + if(tmp > 16) tmp -= 'a' - 'A'; return tmp; } diff --git a/src/include/adiv5.h b/src/include/adiv5.h index d2d4be0..1bfb5a1 100644 --- a/src/include/adiv5.h +++ b/src/include/adiv5.h @@ -111,7 +111,7 @@ typedef struct ADIv5_DP_s { uint32_t (*error)(struct ADIv5_DP_s *dp); - uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t APnDP, uint8_t RnW, + uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t APnDP, uint8_t RnW, uint8_t addr, uint32_t value); union { @@ -135,7 +135,7 @@ static inline uint32_t adiv5_dp_error(ADIv5_DP_t *dp) return dp->error(dp); } -static inline uint32_t adiv5_dp_low_access(struct ADIv5_DP_s *dp, uint8_t APnDP, +static inline uint32_t adiv5_dp_low_access(struct ADIv5_DP_s *dp, uint8_t APnDP, uint8_t RnW, uint8_t addr, uint32_t value) { return dp->low_access(dp, APnDP, RnW, addr, value); diff --git a/src/include/jtagtap.h b/src/include/jtagtap.h index f0588a0..fd13f2b 100644 --- a/src/include/jtagtap.h +++ b/src/include/jtagtap.h @@ -44,9 +44,9 @@ void jtagtap_tms_seq(uint32_t MS, int ticks); void jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks); void jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks); /* Shift out a sequence on MS and DI, capture data to DO. - * - This is not endian safe: First byte will always be first shifted out. - * - DO may be NULL to ignore captured data. - * - DO may be point to the same address as DI. + * - This is not endian safe: First byte will always be first shifted out. + * - DO may be NULL to ignore captured data. + * - DO may be point to the same address as DI. */ /* generic soft reset: 1, 1, 1, 1, 1, 0 */ diff --git a/src/include/target.h b/src/include/target.h index b83a2e9..574a0eb 100644 --- a/src/include/target.h +++ b/src/include/target.h @@ -34,7 +34,7 @@ typedef struct target_s target; * targets, or because of a communication failure. The target data may * be assumed to be intact, but the communication medium may not be available, * so access methods shouldn't be called. - * + * * The callback is installed by target_attach() and only removed by attaching * with a different callback. It remains intact after target_detach(). */ @@ -131,14 +131,14 @@ struct target_s { int (*check_error)(struct target_s *target); /* Memory access functions */ - int (*mem_read_words)(struct target_s *target, uint32_t *dest, uint32_t src, + int (*mem_read_words)(struct target_s *target, uint32_t *dest, uint32_t src, int len); - int (*mem_write_words)(struct target_s *target, uint32_t dest, + int (*mem_write_words)(struct target_s *target, uint32_t dest, const uint32_t *src, int len); - int (*mem_read_bytes)(struct target_s *target, uint8_t *dest, uint32_t src, + int (*mem_read_bytes)(struct target_s *target, uint8_t *dest, uint32_t src, int len); - int (*mem_write_bytes)(struct target_s *target, uint32_t dest, + int (*mem_write_bytes)(struct target_s *target, uint32_t dest, const uint8_t *src, int len); /* Register access functions */ @@ -172,7 +172,7 @@ struct target_s { /* Flash memory access functions */ const char *xml_mem_map; int (*flash_erase)(struct target_s *target, uint32_t addr, int len); - int (*flash_write)(struct target_s *target, uint32_t dest, + int (*flash_write)(struct target_s *target, uint32_t dest, const uint8_t *src, int len); /* Host I/O support */ diff --git a/src/jtagtap_generic.c b/src/jtagtap_generic.c index a2e723b..63c8e44 100644 --- a/src/jtagtap_generic.c +++ b/src/jtagtap_generic.c @@ -28,14 +28,14 @@ jtagtap_tms_seq(uint32_t MS, int ticks) { while(ticks--) { jtagtap_next(MS & 1, 1); - MS >>= 1; + MS >>= 1; } } #endif #ifdef PROVIDE_GENERIC_JTAGTAP_TDI_TDO_SEQ -void +void jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks) { uint8_t index = 1; @@ -55,7 +55,7 @@ jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int #ifdef PROVIDE_GENERIC_JTAGTAP_TDI_SEQ -void +void jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks) { uint8_t index = 1; @@ -63,7 +63,7 @@ jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks) jtagtap_next(ticks?0:final_tms, *DI & index); if(!(index <<= 1)) { index = 1; - DI++; + DI++; } } } diff --git a/src/lmi.c b/src/lmi.c index 09a9dd5..cb620c0 100644 --- a/src/lmi.c +++ b/src/lmi.c @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -/* This file implements TI/LMI LM3S target specific functions providing +/* This file implements TI/LMI LM3S target specific functions providing * the XML memory map and Flash memory programming. * * Issues: @@ -35,7 +35,7 @@ #include "target.h" static int lmi_flash_erase(struct target_s *target, uint32_t addr, int len); -static int lmi_flash_write(struct target_s *target, uint32_t dest, +static int lmi_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len); static const char lmi_driver_str[] = "LuminaryMicro Stellaris"; @@ -135,7 +135,7 @@ int lmi_flash_erase(struct target_s *target, uint32_t addr, int len) return 0; } -int lmi_flash_write(struct target_s *target, uint32_t dest, +int lmi_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len) { uint32_t data[(len>>2)+2]; diff --git a/src/main.c b/src/main.c index 4921aed..809d4bf 100644 --- a/src/main.c +++ b/src/main.c @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -/* Provides main entry point. Initialise subsystems and enter GDB +/* Provides main entry point. Initialise subsystems and enter GDB * protocol loop. */ diff --git a/src/nxp_tgt.c b/src/nxp_tgt.c index ccb2cc6..83f37ba 100644 --- a/src/nxp_tgt.c +++ b/src/nxp_tgt.c @@ -51,10 +51,10 @@ static struct flash_program flash_pgm; static void lpc11x_iap_call(struct target_s *target, struct flash_param *param, unsigned param_len); static int lpc11xx_flash_prepare(struct target_s *target, uint32_t addr, int len); static int lpc11xx_flash_erase(struct target_s *target, uint32_t addr, int len); -static int lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, +static int lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len); -/* +/* * Note that this memory map is actually for the largest of the lpc11xx devices; * There seems to be no good way to decode the part number to determine the RAM * and flash sizes. @@ -143,7 +143,7 @@ lpc11x_iap_call(struct target_s *target, struct flash_param *param, unsigned par static int lpc11xx_flash_prepare(struct target_s *target, uint32_t addr, int len) -{ +{ /* prepare the sector(s) to be erased */ memset(&flash_pgm.p, 0, sizeof(flash_pgm.p)); flash_pgm.p.command[0] = IAP_CMD_PREPARE; @@ -196,15 +196,15 @@ lpc11xx_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, unsigned chunk; for (chunk = first_chunk; chunk <= last_chunk; chunk++) { - + DEBUG("chunk %u len %d\n", chunk, len); /* first and last chunk may require special handling */ if ((chunk == first_chunk) || (chunk == last_chunk)) { /* fill with all ff to avoid sector rewrite corrupting other writes */ memset(flash_pgm.data, 0xff, sizeof(flash_pgm.data)); - - /* copy as much as fits */ + + /* copy as much as fits */ int copylen = IAP_PGM_CHUNKSIZE - chunk_offset; if (copylen > len) copylen = len; diff --git a/src/platforms/libftdi/jtagtap.c b/src/platforms/libftdi/jtagtap.c index 77e1867..91f6ae2 100644 --- a/src/platforms/libftdi/jtagtap.c +++ b/src/platforms/libftdi/jtagtap.c @@ -84,7 +84,7 @@ jtagtap_tms_seq(uint32_t MS, int ticks) //jtagtap_next(MS & 1, 1); tmp[1] = ticks<7?ticks-1:6; tmp[2] = 0x80 | (MS & 0x7F); - + // assert(ftdi_write_data(ftdic, tmp, 3) == 3); platform_buffer_write(tmp, 3); MS >>= 7; ticks -= 7; @@ -93,7 +93,7 @@ jtagtap_tms_seq(uint32_t MS, int ticks) #endif #ifndef PROVIDE_GENERIC_TAP_TDI_SEQ -void +void jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks) { char *tmp; @@ -119,7 +119,7 @@ jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks) tmp[index++] = rticks - 1; tmp[index++] = *DI; } - + if(final_tms) { tmp[index++] = 0x4B; tmp[index++] = 0; @@ -131,7 +131,7 @@ jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks) #endif #ifndef PROVIDE_GENERIC_TAP_TDI_TDO_SEQ -void +void jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks) { uint8_t *tmp; @@ -159,7 +159,7 @@ jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int tmp[index++] = rticks - 1; tmp[index++] = *DI; } - + if(final_tms) { rsize++; tmp[index++] = 0x6B; @@ -176,7 +176,7 @@ jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int printf("\n");*/ index = 0; if(final_tms) rsize--; - + while(rsize--) { /*if(rsize) printf("%02X ", tmp[index]);*/ *DO++ = tmp[index++]; diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c index ec2a8f1..dc57a45 100644 --- a/src/platforms/libftdi/platform.c +++ b/src/platforms/libftdi/platform.c @@ -122,7 +122,7 @@ static struct cable_desc_s { }; int platform_init(int argc, char **argv) -{ +{ int err; int c; int index = 0; @@ -167,40 +167,40 @@ int platform_init(int argc, char **argv) ftdic = NULL; } if((ftdic = ftdi_new()) == NULL) { - fprintf(stderr, "ftdi_new: %s\n", + fprintf(stderr, "ftdi_new: %s\n", ftdi_get_error_string(ftdic)); abort(); } if((err = ftdi_set_interface(ftdic, cable_desc[index].interface)) != 0) { - fprintf(stderr, "ftdi_set_interface: %d: %s\n", + fprintf(stderr, "ftdi_set_interface: %d: %s\n", err, ftdi_get_error_string(ftdic)); abort(); } if((err = ftdi_usb_open_desc( ftdic, cable_desc[index].vendor, cable_desc[index].product, cable_desc[index].description, serial)) != 0) { - fprintf(stderr, "unable to open ftdi device: %d (%s)\n", + fprintf(stderr, "unable to open ftdi device: %d (%s)\n", err, ftdi_get_error_string(ftdic)); abort(); } if((err = ftdi_set_latency_timer(ftdic, 1)) != 0) { - fprintf(stderr, "ftdi_set_latency_timer: %d: %s\n", + fprintf(stderr, "ftdi_set_latency_timer: %d: %s\n", err, ftdi_get_error_string(ftdic)); abort(); } if((err = ftdi_set_baudrate(ftdic, 1000000)) != 0) { - fprintf(stderr, "ftdi_set_baudrate: %d: %s\n", + fprintf(stderr, "ftdi_set_baudrate: %d: %s\n", err, ftdi_get_error_string(ftdic)); abort(); } if((err = ftdi_usb_purge_buffers(ftdic)) != 0) { - fprintf(stderr, "ftdi_set_baudrate: %d: %s\n", + 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", + fprintf(stderr, "ftdi_write_data_set_chunksize: %d: %s\n", err, ftdi_get_error_string(ftdic)); abort(); } @@ -216,8 +216,8 @@ int platform_init(int argc, char **argv) assert(gdb_if_init() == 0); jtag_scan(NULL); - - return 0; + + return 0; } void platform_buffer_flush(void) @@ -250,9 +250,9 @@ int vasprintf(char **strp, const char *fmt, va_list ap) int size = 128, ret = 0; *strp = malloc(size); - while(*strp && ((ret = vsnprintf(*strp, size, fmt, ap)) == size)) + while(*strp && ((ret = vsnprintf(*strp, size, fmt, ap)) == size)) *strp = realloc(*strp, size <<= 1); - + return ret; } #endif diff --git a/src/platforms/libftdi/swdptap.c b/src/platforms/libftdi/swdptap.c index be329d8..cd3582b 100644 --- a/src/platforms/libftdi/swdptap.c +++ b/src/platforms/libftdi/swdptap.c @@ -40,7 +40,7 @@ int swdptap_init(void) assert(ftdic != NULL); if((err = ftdi_set_bitmode(ftdic, 0xAB, BITMODE_BITBANG)) != 0) { - fprintf(stderr, "ftdi_set_bitmode: %d: %s\n", + fprintf(stderr, "ftdi_set_bitmode: %d: %s\n", err, ftdi_get_error_string(ftdic)); abort(); } @@ -49,11 +49,11 @@ int swdptap_init(void) /* This must be investigated in more detail. * As described in STM32 Reference Manual... */ - swdptap_seq_out(0xFFFF, 16); + swdptap_seq_out(0xFFFF, 16); swdptap_reset(); - swdptap_seq_out(0xE79E, 16); /* 0b0111100111100111 */ + swdptap_seq_out(0xE79E, 16); /* 0b0111100111100111 */ swdptap_reset(); - swdptap_seq_out(0, 16); + swdptap_seq_out(0, 16); return 0; } @@ -85,7 +85,7 @@ static void swdptap_turnaround(uint8_t dir) assert(ftdi_set_bitmode(ftdic, 0xAB, BITMODE_BITBANG) == 0); } -static uint8_t swdptap_bit_in(void) +static uint8_t swdptap_bit_in(void) { uint8_t ret; diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 24eb79b..d6eb50c 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -123,7 +123,7 @@ int platform_init(void) cdcacm_init(); jtag_scan(NULL); - + return 0; } diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index a1471dc..fa9fc79 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -60,7 +60,7 @@ extern usbd_device *usbdev; * nSRST = PA7 (input) * * USB cable pull-up: PA8 - * USB VBUS detect: PB13 -- New on mini design. + * USB VBUS detect: PB13 -- New on mini design. * Enable pull up for compatibility. * Force DFU mode button: PB12 */ @@ -118,7 +118,7 @@ extern usbd_device *usbdev; #define USB_ISR usb_lp_can_rx0_isr /* Interrupt priorities. Low numbers are high priority. * For now USART1 preempts USB which may spin while buffer is drained. - * TIM3 is used for traceswo capture and must be highest priority. + * TIM3 is used for traceswo capture and must be highest priority. */ #define IRQ_PRI_USB (2 << 4) #define IRQ_PRI_USBUSART (1 << 4) diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index 08fcd32..03509ea 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -92,23 +92,23 @@ int platform_init(void) GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO8); } /* Setup GPIO ports */ - gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, + gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); - gpio_set_mode(TCK_PORT, GPIO_MODE_OUTPUT_50_MHZ, + gpio_set_mode(TCK_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TCK_PIN); - gpio_set_mode(TDI_PORT, GPIO_MODE_OUTPUT_50_MHZ, + gpio_set_mode(TDI_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TDI_PIN); uint16_t srst_pin = platform_hwversion() == 0 ? SRST_PIN_V1 : SRST_PIN_V2; gpio_set(SRST_PORT, srst_pin); - gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ, + gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, srst_pin); - - gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, + + gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run); /* Setup heartbeat timer */ - systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); + systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); systick_set_reload(900000); /* Interrupt us at 10 Hz */ SCB_SHPR(11) &= ~((15 << 4) & 0xff); SCB_SHPR(11) |= ((14 << 4) & 0xff); @@ -122,7 +122,7 @@ int platform_init(void) cdcacm_init(); jtag_scan(NULL); - + return 0; } @@ -144,10 +144,10 @@ void platform_srst_set_val(bool assert) void sys_tick_handler(void) { - if(running_status) + if(running_status) gpio_toggle(LED_PORT, led_idle_run); - if(timeout_counter) + if(timeout_counter) timeout_counter--; } diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index 1ee944c..029eb0a 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -59,7 +59,7 @@ extern usbd_device *usbdev; * nSRST = PA7 (input) * * USB cable pull-up: PA8 - * USB VBUS detect: PB13 -- New on mini design. + * USB VBUS detect: PB13 -- New on mini design. * Enable pull up for compatibility. * Force DFU mode button: PB12 */ diff --git a/src/platforms/stm32/swdptap.c b/src/platforms/stm32/swdptap.c index 72fb0f9..e7049d3 100644 --- a/src/platforms/stm32/swdptap.c +++ b/src/platforms/stm32/swdptap.c @@ -73,9 +73,9 @@ int swdptap_init(void) /* This must be investigated in more detail. * As described in STM32 Reference Manual... */ swdptap_reset(); - swdptap_seq_out(0xE79E, 16); /* 0b0111100111100111 */ + swdptap_seq_out(0xE79E, 16); /* 0b0111100111100111 */ swdptap_reset(); - swdptap_seq_out(0, 16); + swdptap_seq_out(0, 16); return 0; } @@ -132,7 +132,7 @@ void swdptap_seq_out(uint32_t MS, int ticks) while(ticks--) { swdptap_bit_out(MS & 1); - MS >>= 1; + MS >>= 1; } } @@ -146,7 +146,7 @@ void swdptap_seq_out_parity(uint32_t MS, int ticks) while(ticks--) { swdptap_bit_out(MS & 1); parity ^= MS; - MS >>= 1; + MS >>= 1; } swdptap_bit_out(parity & 1); } diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 1aa45b1..1b45cfb 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -86,7 +86,7 @@ int platform_init(void) AFIO_MAPR = data; /* Setup heartbeat timer */ - systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); + systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); systick_set_reload(900000); /* Interrupt us at 10 Hz */ SCB_SHPR(11) &= ~((15 << 4) & 0xff); SCB_SHPR(11) |= ((14 << 4) & 0xff); @@ -112,10 +112,10 @@ void platform_delay(uint32_t delay) void sys_tick_handler(void) { - if(running_status) + if(running_status) gpio_toggle(LED_PORT, led_idle_run); - if(timeout_counter) + if(timeout_counter) timeout_counter--; } diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 469499f..7d36326 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -53,7 +53,7 @@ extern usbd_device *usbdev; * nSRST = PA7 (input) * * USB cable pull-up: PA8 - * USB VBUS detect: PB13 -- New on mini design. + * USB VBUS detect: PB13 -- New on mini design. * Enable pull up for compatibility. * Force DFU mode button: PB9 Low */ diff --git a/src/sam3x.c b/src/sam3x.c index 3c5cc2e..79dca3d 100644 --- a/src/sam3x.c +++ b/src/sam3x.c @@ -32,7 +32,7 @@ #include "gdb_packet.h" static int sam3x_flash_erase(struct target_s *target, uint32_t addr, int len); -static int sam3x_flash_write(struct target_s *target, uint32_t dest, +static int sam3x_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len); static bool sam3x_cmd_gpnvm_get(target *t); diff --git a/src/stm32f1.c b/src/stm32f1.c index 4cc7b2a..03dcc43 100644 --- a/src/stm32f1.c +++ b/src/stm32f1.c @@ -50,9 +50,9 @@ const struct command_s stm32f1_cmd_list[] = { static int stm32md_flash_erase(struct target_s *target, uint32_t addr, int len); static int stm32hd_flash_erase(struct target_s *target, uint32_t addr, int len); -static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, int len, +static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, int len, uint32_t pagesize); -static int stm32f1_flash_write(struct target_s *target, uint32_t dest, +static int stm32f1_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len); static const char stm32f1_driver_str[] = "STM32, Medium density."; @@ -103,7 +103,7 @@ static const char stm32hd_xml_memory_map[] = "" #define FLASH_SR_BSY (1 << 0) -#define FLASH_OBP_RDP 0x1FFFF800 +#define FLASH_OBP_RDP 0x1FFFF800 #define FLASH_OBP_RDP_KEY 0x5aa5 #define FLASH_OBP_RDP_KEY_F3 0x55AA @@ -220,7 +220,7 @@ static int stm32f1_flash_erase(struct target_s *target, uint32_t addr, int len, /* Flash page erase instruction */ adiv5_ap_mem_write(ap, FLASH_CR, FLASH_CR_PER); /* write address to FMA */ - adiv5_ap_mem_write(ap, FLASH_AR, addr); + adiv5_ap_mem_write(ap, FLASH_AR, addr); /* Flash page erase start instruction */ adiv5_ap_mem_write(ap, FLASH_CR, FLASH_CR_STRT | FLASH_CR_PER); @@ -251,7 +251,7 @@ static int stm32md_flash_erase(struct target_s *target, uint32_t addr, int len) return stm32f1_flash_erase(target, addr, len, 0x400); } -static int stm32f1_flash_write(struct target_s *target, uint32_t dest, +static int stm32f1_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len) { ADIv5_AP_t *ap = adiv5_target_ap(target); @@ -287,7 +287,7 @@ static int stm32f1_flash_write(struct target_s *target, uint32_t dest, static bool stm32f1_cmd_erase_mass(target *t) { ADIv5_AP_t *ap = adiv5_target_ap(t); - + stm32f1_flash_unlock(ap); /* Flash mass erase start instruction */ @@ -313,7 +313,7 @@ static bool stm32f1_option_erase(target *t) /* Erase option bytes instruction */ adiv5_ap_mem_write(ap, FLASH_CR, FLASH_CR_OPTER | FLASH_CR_OPTWRE); - adiv5_ap_mem_write(ap, FLASH_CR, + adiv5_ap_mem_write(ap, FLASH_CR, FLASH_CR_STRT | FLASH_CR_OPTER | FLASH_CR_OPTWRE); /* Read FLASH_SR to poll for BSY bit */ while(adiv5_ap_mem_read(ap, FLASH_SR) & FLASH_SR_BSY) diff --git a/src/stm32f4.c b/src/stm32f4.c index b9764cc..471f167 100644 --- a/src/stm32f4.c +++ b/src/stm32f4.c @@ -50,7 +50,7 @@ const struct command_s stm32f4_cmd_list[] = { static int stm32f4_flash_erase(struct target_s *target, uint32_t addr, int len); -static int stm32f4_flash_write(struct target_s *target, uint32_t dest, +static int stm32f4_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len); static const char stm32f4_driver_str[] = "STM32F4xx"; @@ -218,11 +218,11 @@ static int stm32f4_flash_erase(struct target_s *target, uint32_t addr, int len) /* Flash page erase instruction */ adiv5_ap_mem_write(ap, FLASH_CR, cr); /* write address to FMA */ - adiv5_ap_mem_write(ap, FLASH_CR, cr | FLASH_CR_STRT); + adiv5_ap_mem_write(ap, FLASH_CR, cr | FLASH_CR_STRT); /* Read FLASH_SR to poll for BSY bit */ while(adiv5_ap_mem_read(ap, FLASH_SR) & FLASH_SR_BSY) - if(target_check_error(target)) + if(target_check_error(target)) return -1; len -= pagesize; @@ -237,7 +237,7 @@ static int stm32f4_flash_erase(struct target_s *target, uint32_t addr, int len) return 0; } -static int stm32f4_flash_write(struct target_s *target, uint32_t dest, +static int stm32f4_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len) { ADIv5_AP_t *ap = adiv5_target_ap(target); @@ -257,7 +257,7 @@ static int stm32f4_flash_write(struct target_s *target, uint32_t dest, target_mem_write_words(target, 0x20000000, (void*)stm32f4_flash_write_stub, 0x30); target_mem_write_words(target, 0x20000030, data, sizeof(data)); target_pc_write(target, 0x20000000); - if(target_check_error(target)) + if(target_check_error(target)) return -1; /* Execute the stub */ diff --git a/src/stm32l1.c b/src/stm32l1.c index 8fd25f7..325b415 100644 --- a/src/stm32l1.c +++ b/src/stm32l1.c @@ -39,7 +39,7 @@ #include "gdb_packet.h" static int stm32l1_flash_erase(struct target_s *target, uint32_t addr, int len); -static int stm32l1_flash_write(struct target_s *target, uint32_t dest, +static int stm32l1_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len); static const char stm32l1_driver_str[] = "STM32L1xx"; @@ -148,7 +148,7 @@ static int stm32l1_flash_erase(struct target_s *target, uint32_t addr, int len) return 0; } -static int stm32l1_flash_write(struct target_s *target, uint32_t dest, +static int stm32l1_flash_write(struct target_s *target, uint32_t dest, const uint8_t *src, int len) { ADIv5_AP_t *ap = adiv5_target_ap(target); -- cgit v1.2.3 From d90e10cdbaa05509d1ee78f982d3aa0a2c94e972 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sun, 5 May 2013 00:46:49 +0400 Subject: adiv5_swdp: avoid dead-loop with a sleeping target A sleeping target continues to communicate over SWD properly but consistently returns SWDP_ACK_WAIT. It might be nice to be able to wait for the target to wake up on its own but if it's not going to wake up, BMP becomes absolutely unresponsive. Probably the timeout should be made configurable or some other workaround invented. Signed-off-by: Paul Fertser --- src/adiv5_swdp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/adiv5_swdp.c') diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 8a38330..839127d 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -129,10 +129,14 @@ static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW if((addr == 4) || (addr == 8)) request ^= 0x20; + size_t tries = 1000; do { swdptap_seq_out(request, 8); ack = swdptap_seq_in(3); - } while(ack == SWDP_ACK_WAIT); + } while(--tries && ack == SWDP_ACK_WAIT); + + if(!tries) + PLATFORM_FATAL_ERROR(1); if(ack == SWDP_ACK_FAULT) { dp->fault = 1; -- cgit v1.2.3 From d8f737fc53fa27bb13a934f94e39157748401ce4 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Wed, 19 Jun 2013 21:05:53 +1200 Subject: Disable ADIv5 timeout while target is running. --- src/adiv5_jtagdp.c | 6 +++++- src/adiv5_swdp.c | 4 ++-- src/cortexm.c | 4 ++++ src/include/adiv5.h | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/adiv5_swdp.c') diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index 693b94e..4306101 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -92,10 +92,14 @@ static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t R jtag_dev_write_ir(dp->dev, APnDP?IR_APACC:IR_DPACC); + int tries = 1000; do { jtag_dev_shift_dr(dp->dev, (uint8_t*)&response, (uint8_t*)&request, 35); ack = response & 0x07; - } while(ack == JTAGDP_ACK_WAIT); + } while(--tries && (ack == JTAGDP_ACK_WAIT)); + + if (dp->allow_timeout && (ack == JTAGDP_ACK_WAIT)) + return 0; if((ack != JTAGDP_ACK_OK)) { /* Fatal error if invalid ACK response */ diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 839127d..c021190 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -135,8 +135,8 @@ static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW ack = swdptap_seq_in(3); } while(--tries && ack == SWDP_ACK_WAIT); - if(!tries) - PLATFORM_FATAL_ERROR(1); + if (dp->allow_timeout && (ack == SWDP_ACK_WAIT)) + return 0; if(ack == SWDP_ACK_FAULT) { dp->fault = 1; diff --git a/src/cortexm.c b/src/cortexm.c index 7819598..a8bb34b 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -584,6 +584,7 @@ cortexm_halt_request(struct target_s *target) { ADIv5_AP_t *ap = adiv5_target_ap(target); + ap->dp->allow_timeout = false; adiv5_ap_mem_write(ap, CORTEXM_DHCSR, CORTEXM_DHCSR_DBGKEY | CORTEXM_DHCSR_C_HALT | CORTEXM_DHCSR_C_DEBUGEN); } @@ -596,6 +597,8 @@ cortexm_halt_wait(struct target_s *target) if (!(adiv5_ap_mem_read(ap, CORTEXM_DHCSR) & CORTEXM_DHCSR_S_HALT)) return 0; + ap->dp->allow_timeout = false; + /* We've halted. Let's find out why. */ uint32_t dfsr = adiv5_ap_mem_read(ap, CORTEXM_DFSR); adiv5_ap_mem_write(ap, CORTEXM_DFSR, dfsr); /* write back to reset */ @@ -654,6 +657,7 @@ cortexm_halt_resume(struct target_s *target, bool step) } adiv5_ap_mem_write(ap, CORTEXM_DHCSR, dhcsr); + ap->dp->allow_timeout = true; } static int cortexm_fault_unwind(struct target_s *target) diff --git a/src/include/adiv5.h b/src/include/adiv5.h index 1bfb5a1..64b6a28 100644 --- a/src/include/adiv5.h +++ b/src/include/adiv5.h @@ -106,6 +106,8 @@ typedef struct ADIv5_DP_s { uint32_t idcode; + bool allow_timeout; + void (*dp_write)(struct ADIv5_DP_s *dp, uint8_t addr, uint32_t value); uint32_t (*dp_read)(struct ADIv5_DP_s *dp, uint8_t addr); -- cgit v1.2.3 From a30ef31018c6e4ea4cba69755f2fcdd0dbc17baa Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Wed, 19 Jun 2013 21:06:59 +1200 Subject: Handle SW-DP fault on WDATAERR. --- src/adiv5_swdp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/adiv5_swdp.c') diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index c021190..7896d8b 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -73,6 +73,7 @@ int adiv5_swdp_scan(void) dp->error = adiv5_swdp_error; dp->low_access = adiv5_swdp_low_access; + adiv5_swdp_error(dp); adiv5_dp_init(dp); if(!target_list) morse("NO TARGETS.", 1); @@ -97,7 +98,7 @@ static uint32_t adiv5_swdp_error(ADIv5_DP_t *dp) err = adiv5_swdp_read(dp, ADIV5_DP_CTRLSTAT) & (ADIV5_DP_CTRLSTAT_STICKYORUN | ADIV5_DP_CTRLSTAT_STICKYCMP | - ADIV5_DP_CTRLSTAT_STICKYERR); + ADIV5_DP_CTRLSTAT_STICKYERR | ADIV5_DP_CTRLSTAT_WDATAERR); if(err & ADIV5_DP_CTRLSTAT_STICKYORUN) clr |= ADIV5_DP_ABORT_ORUNERRCLR; @@ -105,6 +106,8 @@ static uint32_t adiv5_swdp_error(ADIv5_DP_t *dp) clr |= ADIV5_DP_ABORT_STKCMPCLR; if(err & ADIV5_DP_CTRLSTAT_STICKYERR) clr |= ADIV5_DP_ABORT_STKERRCLR; + if(err & ADIV5_DP_CTRLSTAT_WDATAERR) + clr |= ADIV5_DP_ABORT_WDERRCLR; adiv5_swdp_write(dp, ADIV5_DP_ABORT, clr); dp->fault = 0; -- cgit v1.2.3 From 75001a442126e3b42f6f95f1917a7cb33b92d063 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 28 Feb 2015 22:05:10 -0800 Subject: Factor Morse code functions out of platform code. --- src/Makefile | 1 + src/adiv5_jtagdp.c | 1 + src/adiv5_swdp.c | 1 + src/command.c | 1 + src/include/morse.h | 32 ++++++++++ src/jtag_scan.c | 1 + src/morse.c | 100 ++++++++++++++++++++++++++++++++ src/platforms/f4discovery/platform.c | 85 +-------------------------- src/platforms/f4discovery/platform.h | 4 +- src/platforms/launchpad-icdi/platform.c | 8 --- src/platforms/launchpad-icdi/platform.h | 2 - src/platforms/libftdi/platform.c | 8 --- src/platforms/libftdi/platform.h | 3 - src/platforms/native/platform.c | 86 ++------------------------- src/platforms/native/platform.h | 3 +- src/platforms/stlink/platform.c | 8 --- src/platforms/stlink/platform.h | 3 - src/platforms/swlink/platform.c | 8 --- src/platforms/swlink/platform.h | 2 - 19 files changed, 146 insertions(+), 211 deletions(-) create mode 100644 src/include/morse.h create mode 100644 src/morse.c (limited to 'src/adiv5_swdp.c') diff --git a/src/Makefile b/src/Makefile index fcf5d1f..25cf715 100644 --- a/src/Makefile +++ b/src/Makefile @@ -29,6 +29,7 @@ SRC = \ lpc43xx.c \ kinetis.c \ main.c \ + morse.c \ nrf51.c \ platform.c \ sam3x.c \ diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index 4306101..fd77a04 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -27,6 +27,7 @@ #include "adiv5.h" #include "jtag_scan.h" #include "jtagtap.h" +#include "morse.h" #include diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 7896d8b..6bafc91 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -30,6 +30,7 @@ #include "jtagtap.h" #include "command.h" +#include "morse.h" #include diff --git a/src/command.c b/src/command.c index c13fa9f..7c17864 100644 --- a/src/command.c +++ b/src/command.c @@ -32,6 +32,7 @@ #include "jtag_scan.h" #include "target.h" +#include "morse.h" #include "adiv5.h" diff --git a/src/include/morse.h b/src/include/morse.h new file mode 100644 index 0000000..ac53893 --- /dev/null +++ b/src/include/morse.h @@ -0,0 +1,32 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2015 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __MORSE_H +#define __MORSE_H + +#include + +extern const char *morse_msg; + +void morse(const char *msg, char repeat); +bool morse_update(void); + +#endif + diff --git a/src/jtag_scan.c b/src/jtag_scan.c index 6ca4603..257e6c4 100644 --- a/src/jtag_scan.c +++ b/src/jtag_scan.c @@ -30,6 +30,7 @@ #include "general.h" #include "jtagtap.h" +#include "morse.h" #include "jtag_scan.h" #include "gdb_packet.h" diff --git a/src/morse.c b/src/morse.c new file mode 100644 index 0000000..6b17c16 --- /dev/null +++ b/src/morse.c @@ -0,0 +1,100 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2015 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "general.h" +#include "morse.h" + +/* Morse code patterns and lengths */ +static const struct { + uint16_t code; + uint8_t bits; +} morse_letter[] = { + { 0b00011101, 8}, // 'A' .- + { 0b000101010111, 12}, // 'B' -... + { 0b00010111010111, 14}, // 'C' -.-. + { 0b0001010111, 10}, // 'D' -.. + { 0b0001, 4}, // 'E' . + { 0b000101110101, 12}, // 'F' ..-. + { 0b000101110111, 12}, // 'G' --. + { 0b0001010101, 10}, // 'H' .... + { 0b000101, 6}, // 'I' .. + {0b0001110111011101, 16}, // 'J' .--- + { 0b000111010111, 12}, // 'K' -.- + { 0b000101011101, 12}, // 'L' .-.. + { 0b0001110111, 10}, // 'M' -- + { 0b00010111, 8}, // 'N' -. + { 0b00011101110111, 14}, // 'O' --- + { 0b00010111011101, 14}, // 'P' .--. + {0b0001110101110111, 16}, // 'Q' --.- + { 0b0001011101, 10}, // 'R' .-. + { 0b00010101, 8}, // 'S' ... + { 0b000111, 6}, // 'T' - + { 0b0001110101, 10}, // 'U' ..- + { 0b000111010101, 12}, // 'V' ...- + { 0b000111011101, 12}, // 'W' .-- + { 0b00011101010111, 14}, // 'X' -..- + {0b0001110111010111, 16}, // 'Y' -.-- + { 0b00010101110111, 14}, // 'Z' --.. +}; + +const char *morse_msg; +static const char * volatile morse_ptr; +static char morse_repeat; + +void morse(const char *msg, char repeat) +{ + morse_msg = morse_ptr = msg; + morse_repeat = repeat; +} + +bool morse_update(void) +{ + static uint16_t code; + static uint8_t bits; + + if (!morse_ptr) + return false; + + if (!bits) { + char c = *morse_ptr++; + if (!c) { + if(morse_repeat) { + morse_ptr = morse_msg; + c = *morse_ptr++; + } else { + morse_ptr = 0; + return false; + } + } + if ((c >= 'A') && (c <= 'Z')) { + c -= 'A'; + code = morse_letter[c].code; + bits = morse_letter[c].bits; + } else { + code = 0; bits = 4; + } + } + + bool ret = code & 1; + code >>= 1; + bits--; + + return ret; +} + diff --git a/src/platforms/f4discovery/platform.c b/src/platforms/f4discovery/platform.c index efe8050..e051564 100644 --- a/src/platforms/f4discovery/platform.c +++ b/src/platforms/f4discovery/platform.c @@ -33,17 +33,14 @@ #include #include "jtag_scan.h" -#include - -#include +#include "usbuart.h" +#include "morse.h" uint8_t running_status; volatile uint32_t timeout_counter; jmp_buf fatal_error_jmpbuf; -static void morse_update(void); - int platform_init(void) { /* Check the USER button*/ @@ -116,83 +113,7 @@ void sys_tick_handler(void) if(timeout_counter) timeout_counter--; - morse_update(); -} - - -/* Morse code patterns and lengths */ -static const struct { - uint16_t code; - uint8_t bits; -} morse_letter[] = { - { 0b00011101, 8}, // 'A' .- - { 0b000101010111, 12}, // 'B' -... - { 0b00010111010111, 14}, // 'C' -.-. - { 0b0001010111, 10}, // 'D' -.. - { 0b0001, 4}, // 'E' . - { 0b000101110101, 12}, // 'F' ..-. - { 0b000101110111, 12}, // 'G' --. - { 0b0001010101, 10}, // 'H' .... - { 0b000101, 6}, // 'I' .. - {0b0001110111011101, 16}, // 'J' .--- - { 0b000111010111, 12}, // 'K' -.- - { 0b000101011101, 12}, // 'L' .-.. - { 0b0001110111, 10}, // 'M' -- - { 0b00010111, 8}, // 'N' -. - { 0b00011101110111, 14}, // 'O' --- - { 0b00010111011101, 14}, // 'P' .--. - {0b0001110101110111, 16}, // 'Q' --.- - { 0b0001011101, 10}, // 'R' .-. - { 0b00010101, 8}, // 'S' ... - { 0b000111, 6}, // 'T' - - { 0b0001110101, 10}, // 'U' ..- - { 0b000111010101, 12}, // 'V' ...- - { 0b000111011101, 12}, // 'W' .-- - { 0b00011101010111, 14}, // 'X' -..- - {0b0001110111010111, 16}, // 'Y' -.-- - { 0b00010101110111, 14}, // 'Z' --.. -}; - - -const char *morse_msg; -static const char * volatile morse_ptr; -static char morse_repeat; - -void morse(const char *msg, char repeat) -{ - morse_msg = morse_ptr = msg; - morse_repeat = repeat; - SET_ERROR_STATE(0); -} - -static void morse_update(void) -{ - static uint16_t code; - static uint8_t bits; - - if(!morse_ptr) return; - - if(!bits) { - char c = *morse_ptr++; - if(!c) { - if(morse_repeat) { - morse_ptr = morse_msg; - c = *morse_ptr++; - } else { - morse_ptr = 0; - return; - } - } - if((c >= 'A') && (c <= 'Z')) { - c -= 'A'; - code = morse_letter[c].code; - bits = morse_letter[c].bits; - } else { - code = 0; bits = 4; - } - } - SET_ERROR_STATE(code & 1); - code >>= 1; bits--; + SET_ERROR_STATE(morse_update()); } const char *platform_target_voltage(void) diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 7d6e92e..90b2a11 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -34,6 +34,7 @@ #include #include "gdb_packet.h" +#include "morse.h" #define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 @@ -156,8 +157,6 @@ extern volatile uint32_t timeout_counter; extern jmp_buf fatal_error_jmpbuf; -extern const char *morse_msg; - #define gpio_set_val(port, pin, val) do { \ if(val) \ gpio_set((port), (pin)); \ @@ -180,7 +179,6 @@ extern const char *morse_msg; } int platform_init(void); -void morse(const char *msg, char repeat); const char *platform_target_voltage(void); void platform_delay(uint32_t delay); static inline int platform_hwversion(void) diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index 848271e..1e66e12 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -19,14 +19,6 @@ jmp_buf fatal_error_jmpbuf; uint8_t running_status; volatile uint32_t timeout_counter; -const char *morse_msg; - -void morse(const char *msg, char repeat) -{ - (void) msg; - (void) repeat; -} - void sys_tick_handler(void) { if(timeout_counter) diff --git a/src/platforms/launchpad-icdi/platform.h b/src/platforms/launchpad-icdi/platform.h index 7f5d55f..8c343a8 100644 --- a/src/platforms/launchpad-icdi/platform.h +++ b/src/platforms/launchpad-icdi/platform.h @@ -23,7 +23,6 @@ extern usbd_device *usbdev; extern jmp_buf fatal_error_jmpbuf; extern uint8_t running_status; -extern const char *morse_msg; extern volatile uint32_t timeout_counter; #define TMS_PORT GPIOA_BASE @@ -112,7 +111,6 @@ extern usbd_driver lm4f_usb_driver; #define PLATFORM_HAS_TRACESWO int platform_init(void); -void morse(const char *msg, char repeat); inline static void gpio_set_val(uint32_t port, uint8_t pin, uint8_t val) { gpio_write(port, pin, val == 0 ? 0 : 0xff); diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c index dc57a45..723efa3 100644 --- a/src/platforms/libftdi/platform.c +++ b/src/platforms/libftdi/platform.c @@ -267,11 +267,3 @@ void platform_delay(uint32_t delay) usleep(delay * 100000); } -void morse(const char *msg, char repeat) -{ - (void)repeat; - - if (msg != NULL) - fprintf(stderr,"%s\n", msg); -} - diff --git a/src/platforms/libftdi/platform.h b/src/platforms/libftdi/platform.h index 5ce45fd..a95a3f4 100644 --- a/src/platforms/libftdi/platform.h +++ b/src/platforms/libftdi/platform.h @@ -40,12 +40,9 @@ #define PLATFORM_FATAL_ERROR(error) abort() #define PLATFORM_SET_FATAL_ERROR_RECOVERY() -#define morse_msg 0 - extern struct ftdi_context *ftdic; int platform_init(int argc, char **argv); -void morse(const char *msg, char repeat); const char *platform_target_voltage(void); void platform_delay(uint32_t delay); diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 5e5c78c..3e269d9 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -34,17 +34,14 @@ #include #include "jtag_scan.h" -#include - -#include +#include "usbuart.h" +#include "morse.h" uint8_t running_status; volatile uint32_t timeout_counter; jmp_buf fatal_error_jmpbuf; -static void morse_update(void); - static void adc_init(void); /* Pins PB[7:5] are used to detect hardware revision. @@ -187,83 +184,7 @@ void sys_tick_handler(void) if(timeout_counter) timeout_counter--; - morse_update(); -} - - -/* Morse code patterns and lengths */ -static const struct { - uint16_t code; - uint8_t bits; -} morse_letter[] = { - { 0b00011101, 8}, // 'A' .- - { 0b000101010111, 12}, // 'B' -... - { 0b00010111010111, 14}, // 'C' -.-. - { 0b0001010111, 10}, // 'D' -.. - { 0b0001, 4}, // 'E' . - { 0b000101110101, 12}, // 'F' ..-. - { 0b000101110111, 12}, // 'G' --. - { 0b0001010101, 10}, // 'H' .... - { 0b000101, 6}, // 'I' .. - {0b0001110111011101, 16}, // 'J' .--- - { 0b000111010111, 12}, // 'K' -.- - { 0b000101011101, 12}, // 'L' .-.. - { 0b0001110111, 10}, // 'M' -- - { 0b00010111, 8}, // 'N' -. - { 0b00011101110111, 14}, // 'O' --- - { 0b00010111011101, 14}, // 'P' .--. - {0b0001110101110111, 16}, // 'Q' --.- - { 0b0001011101, 10}, // 'R' .-. - { 0b00010101, 8}, // 'S' ... - { 0b000111, 6}, // 'T' - - { 0b0001110101, 10}, // 'U' ..- - { 0b000111010101, 12}, // 'V' ...- - { 0b000111011101, 12}, // 'W' .-- - { 0b00011101010111, 14}, // 'X' -..- - {0b0001110111010111, 16}, // 'Y' -.-- - { 0b00010101110111, 14}, // 'Z' --.. -}; - - -const char *morse_msg; -static const char * volatile morse_ptr; -static char morse_repeat; - -void morse(const char *msg, char repeat) -{ - morse_msg = morse_ptr = msg; - morse_repeat = repeat; - SET_ERROR_STATE(0); -} - -static void morse_update(void) -{ - static uint16_t code; - static uint8_t bits; - - if(!morse_ptr) return; - - if(!bits) { - char c = *morse_ptr++; - if(!c) { - if(morse_repeat) { - morse_ptr = morse_msg; - c = *morse_ptr++; - } else { - morse_ptr = 0; - return; - } - } - if((c >= 'A') && (c <= 'Z')) { - c -= 'A'; - code = morse_letter[c].code; - bits = morse_letter[c].bits; - } else { - code = 0; bits = 4; - } - } - SET_ERROR_STATE(code & 1); - code >>= 1; bits--; + SET_ERROR_STATE(morse_update()); } static void adc_init(void) @@ -351,3 +272,4 @@ void setup_vbus_irq(void) exti15_10_isr(); } + diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 81a2a4b..73b6c59 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -35,6 +35,7 @@ #include #include "gdb_packet.h" +#include "morse.h" #define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 @@ -163,7 +164,6 @@ extern volatile uint32_t timeout_counter; extern jmp_buf fatal_error_jmpbuf; -extern const char *morse_msg; #define gpio_set_val(port, pin, val) do { \ if(val) \ @@ -187,7 +187,6 @@ extern const char *morse_msg; } while (0) int platform_init(void); -void morse(const char *msg, char repeat); const char *platform_target_voltage(void); int platform_hwversion(void); void platform_delay(uint32_t delay); diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index 494499c..6ef8c77 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -156,14 +156,6 @@ void sys_tick_handler(void) timeout_counter--; } -const char *morse_msg; - -void morse(const char *msg, char repeat) -{ - (void)repeat; - morse_msg = msg; -} - const char *platform_target_voltage(void) { return "unknown"; diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index e56abd9..ee08875 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -143,8 +143,6 @@ extern volatile uint32_t timeout_counter; extern jmp_buf fatal_error_jmpbuf; -extern const char *morse_msg; - #define gpio_set_val(port, pin, val) do { \ if(val) \ gpio_set((port), (pin)); \ @@ -166,7 +164,6 @@ extern uint16_t led_idle_run; } while (0) int platform_init(void); -void morse(const char *msg, char repeat); const char *platform_target_voltage(void); void platform_delay(uint32_t delay); void platform_srst_set_val(bool assert); diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 7b7446a..853cbc9 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -124,14 +124,6 @@ void sys_tick_handler(void) timeout_counter--; } -const char *morse_msg; - -void morse(const char *msg, char repeat) -{ - (void)repeat; - morse_msg = msg; -} - const char *platform_target_voltage(void) { return "unknown"; diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 6683421..99c8fa3 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -141,7 +141,6 @@ extern volatile uint32_t timeout_counter; extern jmp_buf fatal_error_jmpbuf; -extern const char *morse_msg; #define gpio_set_val(port, pin, val) do { \ if(val) \ @@ -164,7 +163,6 @@ extern const char *morse_msg; } int platform_init(void); -void morse(const char *msg, char repeat); const char *platform_target_voltage(void); void platform_delay(uint32_t delay); -- cgit v1.2.3 From 4d4813de87721528fc9a06174dd1da5c245ae2f3 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 1 Mar 2015 22:16:04 -0800 Subject: Clean up includes everywhere. All source files include general.h first and before anything else. This inlcludes platform.h and platform_support.h No header file needs to include to include any of these, but should include any others needed for it's own declarations.--- src/adiv5.c | 5 ---- src/adiv5_jtagdp.c | 3 --- src/adiv5_swdp.c | 5 ---- src/arm7tdmi.c | 4 ---- src/command.c | 6 ----- src/cortexm.c | 7 ++---- src/crc32.c | 2 +- src/gdb_main.c | 11 --------- src/gdb_packet.c | 9 ++------ src/hex_utils.c | 4 +--- src/include/adiv5.h | 1 - src/include/arm7tdmi.h | 1 - src/include/command.h | 1 - src/include/cortexm.h | 20 ++++++++++++++++ src/include/crc32.h | 2 -- src/include/gdb_packet.h | 2 -- src/include/general.h | 12 +++++++--- src/include/jtag_scan.h | 2 -- src/include/jtagtap.h | 2 -- src/include/morse.h | 2 -- src/include/platform_support.h | 41 +++++++++++++++++++++++++++++++++ src/include/swdptap.h | 2 -- src/include/target.h | 2 -- src/jtag_scan.c | 7 ------ src/kinetis.c | 3 --- src/lmi.c | 3 --- src/lpc11xx.c | 21 +++++++++++++---- src/lpc43xx.c | 5 +--- src/main.c | 10 +++----- src/nrf51.c | 3 --- src/platforms/common/usbuart.h | 1 - src/platforms/f4discovery/platform.c | 22 +++++------------- src/platforms/f4discovery/platform.h | 14 ++--------- src/platforms/f4discovery/usbdfu.c | 6 ++--- src/platforms/launchpad-icdi/platform.c | 11 ++++----- src/platforms/launchpad-icdi/platform.h | 16 +------------ src/platforms/libftdi/jtagtap.c | 1 + src/platforms/libftdi/platform.c | 15 +++--------- src/platforms/libftdi/platform.h | 5 ---- src/platforms/libftdi/swdptap.c | 2 +- src/platforms/native/platform.c | 22 ++++-------------- src/platforms/native/platform.h | 22 ++---------------- src/platforms/stlink/platform.c | 22 ++++-------------- src/platforms/stlink/platform.h | 16 ++++--------- src/platforms/stm32/cdcacm.c | 2 +- src/platforms/stm32/dfu_f1.c | 5 ++-- src/platforms/stm32/dfu_f4.c | 6 ++--- src/platforms/stm32/dfucore.c | 2 +- src/platforms/stm32/gdb_if.c | 2 +- src/platforms/stm32/gpio.h | 10 ++++++++ src/platforms/stm32/jtagtap.c | 2 -- src/platforms/stm32/traceswo.c | 5 +--- src/platforms/stm32/usbuart.c | 2 +- src/platforms/swlink/platform.c | 21 ++++------------- src/platforms/swlink/platform.h | 16 ++----------- src/platforms/tm4c/cdcacm.c | 2 +- src/platforms/tm4c/gdb_if.c | 6 +++-- src/platforms/tm4c/jtagtap.c | 1 + src/platforms/tm4c/swdptap.c | 1 - src/platforms/tm4c/traceswo.c | 5 ---- src/platforms/tm4c/usbuart.c | 4 ++-- src/sam3x.c | 3 --- src/samd.c | 4 ---- src/stm32f1.c | 3 --- src/stm32f4.c | 3 --- src/stm32l1.c | 3 --- src/target.c | 2 -- 67 files changed, 167 insertions(+), 316 deletions(-) create mode 100644 src/include/platform_support.h (limited to 'src/adiv5_swdp.c') diff --git a/src/adiv5.c b/src/adiv5.c index 6dcc919..361cd75 100644 --- a/src/adiv5.c +++ b/src/adiv5.c @@ -25,15 +25,10 @@ * Currently doesn't use ROM table for introspection, just assumes * the device is Cortex-M3. */ - -#include -#include - #include "general.h" #include "jtag_scan.h" #include "gdb_packet.h" #include "adiv5.h" - #include "target.h" #ifndef DO_RESET_SEQ diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index fd77a04..8f62a11 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -23,14 +23,11 @@ */ #include "general.h" -#include "platform.h" #include "adiv5.h" #include "jtag_scan.h" #include "jtagtap.h" #include "morse.h" -#include - #define JTAGDP_ACK_OK 0x02 #define JTAGDP_ACK_WAIT 0x01 diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 6bafc91..9df362f 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -23,17 +23,12 @@ */ #include "general.h" -#include "platform.h" #include "adiv5.h" - #include "swdptap.h" #include "jtagtap.h" - #include "command.h" #include "morse.h" -#include - #define SWDP_ACK_OK 0x01 #define SWDP_ACK_WAIT 0x02 #define SWDP_ACK_FAULT 0x04 diff --git a/src/arm7tdmi.c b/src/arm7tdmi.c index 1c7b443..1721787 100644 --- a/src/arm7tdmi.c +++ b/src/arm7tdmi.c @@ -24,14 +24,10 @@ */ #include "general.h" -#include "platform.h" #include "target.h" #include "jtag_scan.h" #include "jtagtap.h" -#include -#include - /* TODO: * Skeleton target. * EmbeddedICE registers, halt/resume target. diff --git a/src/command.c b/src/command.c index 7c17864..f271085 100644 --- a/src/command.c +++ b/src/command.c @@ -22,18 +22,12 @@ * commands. */ -#include -#include - #include "general.h" - #include "command.h" #include "gdb_packet.h" - #include "jtag_scan.h" #include "target.h" #include "morse.h" - #include "adiv5.h" #ifdef PLATFORM_HAS_TRACESWO diff --git a/src/cortexm.c b/src/cortexm.c index 12914d3..a016342 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -28,11 +28,6 @@ * Issues: * There are way too many magic numbers used here. */ -#include -#include -#include -#include - #include "general.h" #include "jtagtap.h" #include "jtag_scan.h" @@ -42,6 +37,8 @@ #include "gdb_packet.h" #include "cortexm.h" +#include + static char cortexm_driver_str[] = "ARM Cortex-M"; static bool cortexm_vector_catch(target *t, int argc, char *argv[]); diff --git a/src/crc32.c b/src/crc32.c index 810a9dd..42d1d48 100644 --- a/src/crc32.c +++ b/src/crc32.c @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -#include "platform.h" +#include "general.h" #include "target.h" #if !defined(STM32F1) && !defined(STM32F4) diff --git a/src/gdb_main.c b/src/gdb_main.c index 41ab84a..17ad9a5 100644 --- a/src/gdb_main.c +++ b/src/gdb_main.c @@ -24,26 +24,15 @@ * Originally written for GDB 6.8, updated and tested with GDB 7.2. */ -#include -#include -#include - -#include - -#include "platform.h" - #include "general.h" #include "hex_utils.h" #include "gdb_if.h" #include "gdb_packet.h" #include "gdb_main.h" - #include "jtagtap.h" #include "jtag_scan.h" #include "adiv5.h" - #include "target.h" - #include "command.h" #include "crc32.h" diff --git a/src/gdb_packet.c b/src/gdb_packet.c index d43be42..4dc934f 100644 --- a/src/gdb_packet.c +++ b/src/gdb_packet.c @@ -22,18 +22,13 @@ * reception and transmission as well as some convenience functions. */ -#define _GNU_SOURCE -#include -#include -#include - -#include - #include "general.h" #include "gdb_if.h" #include "gdb_packet.h" #include "hex_utils.h" +#include + int gdb_getpacket(unsigned char *packet, int size) { diff --git a/src/hex_utils.c b/src/hex_utils.c index e477281..45382ff 100644 --- a/src/hex_utils.c +++ b/src/hex_utils.c @@ -21,9 +21,7 @@ /* Convenience function to convert to/from ascii strings of hex digits. */ -#include -#include - +#include "general.h" #include "hex_utils.h" static char hexdigits[] = "0123456789abcdef"; diff --git a/src/include/adiv5.h b/src/include/adiv5.h index 0f17119..e0ce9cf 100644 --- a/src/include/adiv5.h +++ b/src/include/adiv5.h @@ -21,7 +21,6 @@ #ifndef __ADIV5_H #define __ADIV5_H -#include "general.h" #include "jtag_scan.h" #include "target.h" diff --git a/src/include/arm7tdmi.h b/src/include/arm7tdmi.h index ffcd6e9..fa7d586 100644 --- a/src/include/arm7tdmi.h +++ b/src/include/arm7tdmi.h @@ -21,7 +21,6 @@ #ifndef __ARM7TDMI_H #define __ARM7TDMI_H -#include "general.h" #include "jtag_scan.h" void arm7tdmi_jtag_handler(jtag_dev_t *dev); diff --git a/src/include/command.h b/src/include/command.h index 32b0d7b..3910bbb 100644 --- a/src/include/command.h +++ b/src/include/command.h @@ -21,7 +21,6 @@ #ifndef __COMMAND_H #define __COMMAND_H -#include "general.h" #include "target.h" int command_process(target *t, char *cmd); diff --git a/src/include/cortexm.h b/src/include/cortexm.h index f1fc07a..1fd77e6 100644 --- a/src/include/cortexm.h +++ b/src/include/cortexm.h @@ -1,6 +1,26 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2015 Gareth McMullin + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #ifndef __CORTEXM_H #define __CORTEXM_H +#include "target.h" + /* Private peripheral bus base address */ #define CORTEXM_PPB_BASE 0xE0000000 diff --git a/src/include/crc32.h b/src/include/crc32.h index 6cc00ea..9966d8d 100644 --- a/src/include/crc32.h +++ b/src/include/crc32.h @@ -21,8 +21,6 @@ #ifndef __CRC32_H #define __CRC32_H -#include "platform.h" - uint32_t crc32_calc(uint32_t crc, uint8_t data); uint32_t generic_crc32(struct target_s *target, uint32_t base, int len); diff --git a/src/include/gdb_packet.h b/src/include/gdb_packet.h index 9f5430f..222b86d 100644 --- a/src/include/gdb_packet.h +++ b/src/include/gdb_packet.h @@ -21,8 +21,6 @@ #ifndef __GDB_PACKET_H #define __GDB_PACKET_H -#include - int gdb_getpacket(unsigned char *packet, int size); void gdb_putpacket(unsigned char *packet, int size); #define gdb_putpacketz(packet) gdb_putpacket((packet), strlen(packet)) diff --git a/src/include/general.h b/src/include/general.h index b0721ac..b4e9aeb 100644 --- a/src/include/general.h +++ b/src/include/general.h @@ -21,15 +21,21 @@ #ifndef __GENERAL_H #define __GENERAL_H +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + #include "platform.h" +#include "platform_support.h" #ifndef DEBUG #include #define DEBUG printf #endif -#include -#include - #endif diff --git a/src/include/jtag_scan.h b/src/include/jtag_scan.h index b425b95..aa006e7 100644 --- a/src/include/jtag_scan.h +++ b/src/include/jtag_scan.h @@ -21,8 +21,6 @@ #ifndef __JTAG_SCAN_H #define __JTAG_SCAN_H -#include "general.h" - #define JTAG_MAX_DEVS 5 #define JTAG_MAX_IR_LEN 16 diff --git a/src/include/jtagtap.h b/src/include/jtagtap.h index fd13f2b..0072594 100644 --- a/src/include/jtagtap.h +++ b/src/include/jtagtap.h @@ -21,8 +21,6 @@ #ifndef __JTAGTAP_H #define __JTAGTAP_H -#include "general.h" - /* Note: Signal names are as for the device under test. */ int jtagtap_init(void); diff --git a/src/include/morse.h b/src/include/morse.h index ac53893..5ba39b1 100644 --- a/src/include/morse.h +++ b/src/include/morse.h @@ -21,8 +21,6 @@ #ifndef __MORSE_H #define __MORSE_H -#include - extern const char *morse_msg; void morse(const char *msg, char repeat); diff --git a/src/include/platform_support.h b/src/include/platform_support.h new file mode 100644 index 0000000..cc88ab6 --- /dev/null +++ b/src/include/platform_support.h @@ -0,0 +1,41 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2015 Gareth McMullin + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __PLATFORM_SUPPORT_H +#define __PLATFORM_SUPPORT_H + +#ifndef __GENERAL_H +# error "Include 'general.h' instead" +#endif + +#if defined(LIBFTDI) +void platform_init(int argc, char **argv); +#else +void platform_init(void); +#endif + +const char *platform_target_voltage(void); +int platform_hwversion(void); +void platform_delay(uint32_t delay); +void platform_srst_set_val(bool assert); +bool platform_target_get_power(void); +void platform_target_set_power(bool power); + +#endif + diff --git a/src/include/swdptap.h b/src/include/swdptap.h index 5bb0545..3263a1d 100644 --- a/src/include/swdptap.h +++ b/src/include/swdptap.h @@ -21,8 +21,6 @@ #ifndef __SWDPTAP_H #define __SWDPTAP_H -#include "general.h" - int swdptap_init(void); void swdptap_reset(void); diff --git a/src/include/target.h b/src/include/target.h index 50f1ebe..0e6d9c2 100644 --- a/src/include/target.h +++ b/src/include/target.h @@ -25,8 +25,6 @@ #ifndef __TARGET_H #define __TARGET_H -#include "general.h" - typedef struct target_s target; /* The destroy callback function will be called by target_list_free() just diff --git a/src/jtag_scan.c b/src/jtag_scan.c index 257e6c4..208a1db 100644 --- a/src/jtag_scan.c +++ b/src/jtag_scan.c @@ -22,19 +22,12 @@ * to detect devices on the scan chain and read their IDCODEs. * It depends on the low-level function provided by the platform's jtagtap.c. */ -#include -#include -#include - -#include #include "general.h" #include "jtagtap.h" #include "morse.h" #include "jtag_scan.h" - #include "gdb_packet.h" - #include "adiv5.h" #include "arm7tdmi.h" diff --git a/src/kinetis.c b/src/kinetis.c index 393bb18..4b7cf31 100644 --- a/src/kinetis.c +++ b/src/kinetis.c @@ -22,9 +22,6 @@ * the XML memory map and Flash memory programming. */ -#include -#include - #include "general.h" #include "adiv5.h" #include "target.h" diff --git a/src/lmi.c b/src/lmi.c index a251242..8d409d0 100644 --- a/src/lmi.c +++ b/src/lmi.c @@ -27,9 +27,6 @@ * Flash erase is very slow. */ -#include -#include - #include "general.h" #include "adiv5.h" #include "target.h" diff --git a/src/lpc11xx.c b/src/lpc11xx.c index ef26e78..d9e918e 100644 --- a/src/lpc11xx.c +++ b/src/lpc11xx.c @@ -1,8 +1,19 @@ - -#include -#include -#include - +/* + * This file is part of the Black Magic Debug project. + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "general.h" #include "adiv5.h" #include "target.h" diff --git a/src/lpc43xx.c b/src/lpc43xx.c index bfb96f7..3940fed 100644 --- a/src/lpc43xx.c +++ b/src/lpc43xx.c @@ -17,11 +17,8 @@ * along with this program. If not, see . */ -#include -#include -#include -#include "command.h" #include "general.h" +#include "command.h" #include "adiv5.h" #include "target.h" #include "gdb_packet.h" diff --git a/src/main.c b/src/main.c index 809d4bf..60db15c 100644 --- a/src/main.c +++ b/src/main.c @@ -22,26 +22,22 @@ * protocol loop. */ -#include -#include -#include - +#include "general.h" #include "gdb_if.h" #include "gdb_main.h" #include "jtagtap.h" #include "jtag_scan.h" - #include "target.h" int main(int argc, char **argv) { #if defined(LIBFTDI) - assert(platform_init(argc, argv) == 0); + platform_init(argc, argv); #else (void) argc; (void) argv; - assert(platform_init() == 0); + platform_init(); #endif PLATFORM_SET_FATAL_ERROR_RECOVERY(); diff --git a/src/nrf51.c b/src/nrf51.c index 7305d29..6c1a8b9 100644 --- a/src/nrf51.c +++ b/src/nrf51.c @@ -21,9 +21,6 @@ * the device, providing the XML memory map and Flash memory programming. */ -#include -#include - #include "general.h" #include "adiv5.h" #include "target.h" diff --git a/src/platforms/common/usbuart.h b/src/platforms/common/usbuart.h index 39f7dcd..51f5702 100644 --- a/src/platforms/common/usbuart.h +++ b/src/platforms/common/usbuart.h @@ -22,7 +22,6 @@ #include #include -#include "general.h" void usbuart_init(void); diff --git a/src/platforms/f4discovery/platform.c b/src/platforms/f4discovery/platform.c index e051564..cf6cdf3 100644 --- a/src/platforms/f4discovery/platform.c +++ b/src/platforms/f4discovery/platform.c @@ -22,7 +22,11 @@ * implementation. */ -#include "platform.h" +#include "general.h" +#include "cdcacm.h" +#include "usbuart.h" +#include "morse.h" + #include #include #include @@ -32,16 +36,12 @@ #include #include -#include "jtag_scan.h" -#include "usbuart.h" -#include "morse.h" - uint8_t running_status; volatile uint32_t timeout_counter; jmp_buf fatal_error_jmpbuf; -int platform_init(void) +void platform_init(void) { /* Check the USER button*/ rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); @@ -86,17 +86,7 @@ int platform_init(void) systick_counter_enable(); usbuart_init(); - cdcacm_init(); - - // Set recovery point - if (setjmp(fatal_error_jmpbuf)) { - return 0; // Do nothing on failure - } - - jtag_scan(NULL); - - return 0; } void platform_delay(uint32_t delay) diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 140e8d1..f58205d 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -24,19 +24,12 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include -#include -#include -#include -#include - -#include -#include - #include "gdb_packet.h" #include "gpio.h" #include "morse.h" +#include + #define PLATFORM_HAS_TRACESWO #define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade) for F4Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -173,9 +166,6 @@ extern jmp_buf fatal_error_jmpbuf; longjmp(fatal_error_jmpbuf, (error)); \ } -int platform_init(void); -const char *platform_target_voltage(void); -void platform_delay(uint32_t delay); static inline int platform_hwversion(void) { return 0; diff --git a/src/platforms/f4discovery/usbdfu.c b/src/platforms/f4discovery/usbdfu.c index 7070ade..6a40295 100644 --- a/src/platforms/f4discovery/usbdfu.c +++ b/src/platforms/f4discovery/usbdfu.c @@ -17,14 +17,14 @@ * along with this program. If not, see . */ -#include +#include "general.h" +#include "usbdfu.h" + #include #include #include #include -#include "usbdfu.h" - void dfu_detach(void) { /* USB device must detach, we just reset... */ diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index 1e66e12..0e3fb85 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -1,5 +1,6 @@ -#include "platform.h" +#include "general.h" #include "gdb_if.h" +#include "cdcacm.h" #include "usbuart.h" #include @@ -26,14 +27,14 @@ void sys_tick_handler(void) trace_tick(); } -int +void platform_init(void) { int i; for(i=0; i<1000000; i++); rcc_sysclk_config(OSCSRC_MOSC, XTAL_16M, PLL_DIV_80MHZ); - + // Enable all JTAG ports and set pins to output periph_clock_enable(RCC_GPIOA); periph_clock_enable(RCC_GPIOB); @@ -59,10 +60,6 @@ platform_init(void) usbuart_init(); cdcacm_init(); - - //jtag_scan(NULL); - - return 0; } void platform_delay(uint32_t delay) diff --git a/src/platforms/launchpad-icdi/platform.h b/src/platforms/launchpad-icdi/platform.h index 8c343a8..5f686f4 100644 --- a/src/platforms/launchpad-icdi/platform.h +++ b/src/platforms/launchpad-icdi/platform.h @@ -1,16 +1,13 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include +#include "gdb_packet.h" #include -#include #include #include -#include "gdb_packet.h" - #define CDCACM_PACKET_SIZE 64 #define BOARD_IDENT "Black Magic Probe (Launchpad ICDI), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade) for Launchpad, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -110,8 +107,6 @@ extern usbd_driver lm4f_usb_driver; #define PLATFORM_HAS_TRACESWO -int platform_init(void); - inline static void gpio_set_val(uint32_t port, uint8_t pin, uint8_t val) { gpio_write(port, pin, val == 0 ? 0 : 0xff); } @@ -120,15 +115,6 @@ inline static uint8_t gpio_get(uint32_t port, uint8_t pin) { return !(gpio_read(port, pin) == 0); } -void platform_delay(uint32_t delay); -const char *platform_target_voltage(void); - -/* */ -void cdcacm_init(void); -/* Returns current usb configuration, or 0 if not configured. */ -int cdcacm_get_config(void); -int cdcacm_get_dtr(void); - #define disconnect_usb() do { usbd_disconnect(usbdev,1); nvic_disable_irq(USB_IRQ);} while(0) #define setup_vbus_irq() diff --git a/src/platforms/libftdi/jtagtap.c b/src/platforms/libftdi/jtagtap.c index 91f6ae2..c9bc876 100644 --- a/src/platforms/libftdi/jtagtap.c +++ b/src/platforms/libftdi/jtagtap.c @@ -69,6 +69,7 @@ void jtagtap_reset(void) void jtagtap_srst(bool assert) { + (void)assert; platform_buffer_flush(); //ftdi_write_data(ftdic, "\x80\x88\xAB", 3); //usleep(1000); diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c index 723efa3..e53f011 100644 --- a/src/platforms/libftdi/platform.c +++ b/src/platforms/libftdi/platform.c @@ -17,14 +17,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#include "platform.h" +#include "general.h" #include "gdb_if.h" -#include "jtag_scan.h" -#include -#include #include -#include struct ftdi_context *ftdic; @@ -121,7 +117,7 @@ static struct cable_desc_s { }, }; -int platform_init(int argc, char **argv) +void platform_init(int argc, char **argv) { int err; int c; @@ -149,7 +145,7 @@ int platform_init(int argc, char **argv) if (index == sizeof(cable_desc)/sizeof(cable_desc[0])){ fprintf(stderr, "No cable matching %s found\n",cablename); - return -1; + exit(-1); } if (cable_desc[index].dbus_data) @@ -212,12 +208,7 @@ int platform_init(int argc, char **argv) } assert(ftdi_write_data(ftdic, ftdi_init, 9) == 9); - assert(gdb_if_init() == 0); - - jtag_scan(NULL); - - return 0; } void platform_buffer_flush(void) diff --git a/src/platforms/libftdi/platform.h b/src/platforms/libftdi/platform.h index a95a3f4..135b2e3 100644 --- a/src/platforms/libftdi/platform.h +++ b/src/platforms/libftdi/platform.h @@ -21,7 +21,6 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include #include #ifndef WIN32 @@ -42,10 +41,6 @@ extern struct ftdi_context *ftdic; -int platform_init(int argc, char **argv); -const char *platform_target_voltage(void); -void platform_delay(uint32_t delay); - void platform_buffer_flush(void); int platform_buffer_write(const uint8_t *data, int size); int platform_buffer_read(uint8_t *data, int size); diff --git a/src/platforms/libftdi/swdptap.c b/src/platforms/libftdi/swdptap.c index ef350de..eb6e65e 100644 --- a/src/platforms/libftdi/swdptap.c +++ b/src/platforms/libftdi/swdptap.c @@ -26,7 +26,7 @@ #include #include -#include "platform.h" +#include "general.h" #include "swdptap.h" static void swdptap_turnaround(uint8_t dir); diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 3f61f5f..9b39238 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -22,7 +22,10 @@ * implementation. */ -#include "platform.h" +#include "general.h" +#include "cdcacm.h" +#include "usbuart.h" +#include "morse.h" #include #include @@ -33,11 +36,6 @@ #include #include -#include "jtag_scan.h" -#include "cdcacm.h" -#include "usbuart.h" -#include "morse.h" - uint8_t running_status; volatile uint32_t timeout_counter; @@ -62,7 +60,7 @@ int platform_hwversion(void) return hwversion; } -int platform_init(void) +void platform_init(void) { rcc_clock_setup_in_hse_8mhz_out_72mhz(); @@ -136,16 +134,6 @@ int platform_init(void) cdcacm_init(); usbuart_init(); - - /* Set recovery point */ - if (setjmp(fatal_error_jmpbuf)) { - /* Do nothing on failure */ - return 0; - } - - jtag_scan(NULL); - - return 0; } void platform_srst_set_val(bool assert) diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 321c3f3..5688e60 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -24,20 +24,12 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include -#include -#include - -#include -#include - -#include -#include - #include "gdb_packet.h" #include "gpio.h" #include "morse.h" +#include + #define PLATFORM_HAS_TRACESWO #define PLATFORM_HAS_POWER_SWITCH #define BOARD_IDENT "Black Magic Probe" @@ -173,13 +165,6 @@ extern jmp_buf fatal_error_jmpbuf; longjmp(fatal_error_jmpbuf, (error)); \ } while (0) -int platform_init(void); -const char *platform_target_voltage(void); -int platform_hwversion(void); -void platform_set_timeout(uint32_t ms); -bool platform_timeout_expired(void); -void platform_delay(uint32_t delay); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf @@ -188,9 +173,6 @@ void platform_delay(uint32_t delay); #define disconnect_usb() gpio_set_mode(USB_PU_PORT, GPIO_MODE_INPUT, 0, USB_PU_PIN); void assert_boot_pin(void); void setup_vbus_irq(void); -void platform_srst_set_val(bool assert); -bool platform_target_get_power(void); -void platform_target_set_power(bool power); #endif diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index 6ef8c77..6194d92 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -22,7 +22,10 @@ * implementation. */ -#include "platform.h" +#include "general.h" +#include "cdcacm.h" +#include "usbuart.h" + #include #include #include @@ -31,11 +34,6 @@ #include #include -#include "jtag_scan.h" -#include - -#include - uint8_t running_status; volatile uint32_t timeout_counter; @@ -68,7 +66,7 @@ int platform_hwversion(void) return hwversion; } -int platform_init(void) +void platform_init(void) { rcc_clock_setup_in_hse_8mhz_out_72mhz(); @@ -119,16 +117,6 @@ int platform_init(void) SCB_VTOR = 0x2000; /* Relocate interrupt vector table here */ cdcacm_init(); - - /* Set recovery point */ - if (setjmp(fatal_error_jmpbuf)) { - /* Do nothing on failure */ - return 0; - } - - jtag_scan(NULL); - - return 0; } void platform_delay(uint32_t delay) diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index a33ca06..5768817 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -24,18 +24,14 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include +#include "gdb_packet.h" +#include "gpio.h" + #include #include - -#include #include #include -#include - -#include "gdb_packet.h" -#include "gpio.h" #define BOARD_IDENT "Black Magic Probe (STLINK), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -151,11 +147,6 @@ extern uint16_t led_idle_run; longjmp(fatal_error_jmpbuf, (error)); \ } while (0) -int platform_init(void); -const char *platform_target_voltage(void); -void platform_delay(uint32_t delay); -void platform_srst_set_val(bool assert); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf @@ -163,6 +154,7 @@ void platform_srst_set_val(bool assert); void disconnect_usb(void); void assert_boot_pin(void); +void setup_vbus_irq(void); #endif diff --git a/src/platforms/stm32/cdcacm.c b/src/platforms/stm32/cdcacm.c index 074b534..577925a 100644 --- a/src/platforms/stm32/cdcacm.c +++ b/src/platforms/stm32/cdcacm.c @@ -33,7 +33,7 @@ #include #include -#include "platform.h" +#include "general.h" #include "gdb_if.h" #include "cdcacm.h" #if defined(PLATFORM_HAS_TRACESWO) diff --git a/src/platforms/stm32/dfu_f1.c b/src/platforms/stm32/dfu_f1.c index bb1e274..abbdbe6 100644 --- a/src/platforms/stm32/dfu_f1.c +++ b/src/platforms/stm32/dfu_f1.c @@ -16,12 +16,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -#include "platform.h" +#include "general.h" +#include "usbdfu.h" #include #include -#include "usbdfu.h" #define FLASH_OBP_RDP 0x1FFFF800 #define FLASH_OBP_WRP10 0x1FFFF808 diff --git a/src/platforms/stm32/dfu_f4.c b/src/platforms/stm32/dfu_f4.c index 1065938..2ececa0 100644 --- a/src/platforms/stm32/dfu_f4.c +++ b/src/platforms/stm32/dfu_f4.c @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -#include "platform.h" +#include "general.h" +#include "usbdfu.h" #if defined(STM32F2) # include @@ -26,8 +26,6 @@ #endif #include -#include "usbdfu.h" - static uint32_t sector_addr[] = { 0x8000000, 0x8004000, 0x8008000, 0x800c000, 0x8010000, 0x8020000, 0x8040000, 0x8060000, diff --git a/src/platforms/stm32/dfucore.c b/src/platforms/stm32/dfucore.c index 77cef4e..7b733d7 100644 --- a/src/platforms/stm32/dfucore.c +++ b/src/platforms/stm32/dfucore.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "platform.h" +#include "general.h" #include #if defined(STM32F1) diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c index 6cc9084..286c66b 100644 --- a/src/platforms/stm32/gdb_if.c +++ b/src/platforms/stm32/gdb_if.c @@ -22,7 +22,7 @@ * Serial Debugging protocol is implemented. This implementation for STM32 * uses the USB CDC-ACM device bulk endpoints to implement the channel. */ -#include "platform.h" +#include "general.h" #include "cdcacm.h" #include "gdb_if.h" diff --git a/src/platforms/stm32/gpio.h b/src/platforms/stm32/gpio.h index 035f3c9..ee8275e 100644 --- a/src/platforms/stm32/gpio.h +++ b/src/platforms/stm32/gpio.h @@ -20,6 +20,16 @@ #ifndef __GPIO_H #define __GPIO_H +#include + +#ifndef STM32F4 +# include +# include +#else +# include +# include +#endif + #define INLINE_GPIO #define gpio_set_val(port, pin, val) do { \ diff --git a/src/platforms/stm32/jtagtap.c b/src/platforms/stm32/jtagtap.c index 2d09b84..3c45a81 100644 --- a/src/platforms/stm32/jtagtap.c +++ b/src/platforms/stm32/jtagtap.c @@ -23,9 +23,7 @@ #include #include "general.h" - #include "jtagtap.h" -#include "platform.h" int jtagtap_init(void) { diff --git a/src/platforms/stm32/traceswo.c b/src/platforms/stm32/traceswo.c index 29bae8f..a2e704d 100644 --- a/src/platforms/stm32/traceswo.c +++ b/src/platforms/stm32/traceswo.c @@ -32,15 +32,12 @@ * The core can then process the buffer to extract the frame. */ #include "general.h" +#include "cdcacm.h" #include #include #include -#include -#include "platform.h" -#include "cdcacm.h" - void traceswo_init(void) { TRACE_TIM_CLK_EN(); diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index 970a609..cce2904 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -27,7 +27,7 @@ #include #include -#include "platform.h" +#include "general.h" #include "cdcacm.h" #define USBUART_TIMER_FREQ_HZ 1000000U /* 1us per tick */ diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 853cbc9..168ba2a 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -22,7 +22,10 @@ * implementation. */ -#include "platform.h" +#include "general.h" +#include "cdcacm.h" +#include "usbuart.h" + #include #include #include @@ -31,17 +34,12 @@ #include #include -#include "jtag_scan.h" -#include - -#include - uint8_t running_status; volatile uint32_t timeout_counter; jmp_buf fatal_error_jmpbuf; -int platform_init(void) +void platform_init(void) { uint32_t data; rcc_clock_setup_in_hse_8mhz_out_72mhz(); @@ -98,15 +96,6 @@ int platform_init(void) SCB_VTOR = 0x2000; // Relocate interrupt vector table here cdcacm_init(); - - // Set recovery point - if (setjmp(fatal_error_jmpbuf)) { - return 0; // Do nothing on failure - } - - jtag_scan(NULL); - - return 0; } void platform_delay(uint32_t delay) diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 26cb7a6..dec5548 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -24,19 +24,11 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include -#include -#include - -#include -#include - -#include -#include - #include "gdb_packet.h" #include "gpio.h" +#include + #define BOARD_IDENT "Black Magic Probe (SWLINK), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade), STM8S Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_UPD "Black Magic (DFU Upgrade), STM8S Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -149,10 +141,6 @@ extern jmp_buf fatal_error_jmpbuf; longjmp(fatal_error_jmpbuf, (error)); \ } -int platform_init(void); -const char *platform_target_voltage(void); -void platform_delay(uint32_t delay); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/tm4c/cdcacm.c b/src/platforms/tm4c/cdcacm.c index 041d85b..2677ad5 100644 --- a/src/platforms/tm4c/cdcacm.c +++ b/src/platforms/tm4c/cdcacm.c @@ -35,7 +35,7 @@ #include #include -#include "platform.h" +#include "general.h" #include "gdb_if.h" #if defined(PLATFORM_HAS_TRACESWO) #include diff --git a/src/platforms/tm4c/gdb_if.c b/src/platforms/tm4c/gdb_if.c index b14bbd3..7119638 100644 --- a/src/platforms/tm4c/gdb_if.c +++ b/src/platforms/tm4c/gdb_if.c @@ -22,10 +22,12 @@ * Serial Debugging protocol is implemented. This implementation for STM32 * uses the USB CDC-ACM device bulk endpoints to implement the channel. */ -#include "platform.h" -#include +#include "general.h" #include "gdb_if.h" +#include "cdcacm.h" + +#include static volatile uint32_t head_out, tail_out; static volatile uint32_t count_in; diff --git a/src/platforms/tm4c/jtagtap.c b/src/platforms/tm4c/jtagtap.c index f340b1e..e0bdd68 100644 --- a/src/platforms/tm4c/jtagtap.c +++ b/src/platforms/tm4c/jtagtap.c @@ -1,3 +1,4 @@ +#include "general.h" #include "jtagtap.h" int diff --git a/src/platforms/tm4c/swdptap.c b/src/platforms/tm4c/swdptap.c index 7004598..058f6ba 100644 --- a/src/platforms/tm4c/swdptap.c +++ b/src/platforms/tm4c/swdptap.c @@ -1,5 +1,4 @@ #include "general.h" -#include "platform.h" #include "swdptap.h" static void swdptap_turnaround(uint8_t dir) diff --git a/src/platforms/tm4c/traceswo.c b/src/platforms/tm4c/traceswo.c index eb63139..03c6d66 100644 --- a/src/platforms/tm4c/traceswo.c +++ b/src/platforms/tm4c/traceswo.c @@ -32,14 +32,9 @@ #include #include #include - #include - #include -#include -#include "platform.h" - void traceswo_init(void) { periph_clock_enable(RCC_GPIOD); diff --git a/src/platforms/tm4c/usbuart.c b/src/platforms/tm4c/usbuart.c index bb769f0..da82198 100644 --- a/src/platforms/tm4c/usbuart.c +++ b/src/platforms/tm4c/usbuart.c @@ -19,6 +19,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include "general.h" +#include "cdcacm.h" #include #include @@ -27,8 +29,6 @@ #include #include -#include - #define FIFO_SIZE 128 /* RX Fifo buffer */ diff --git a/src/sam3x.c b/src/sam3x.c index e6b8f2e..ef99290 100644 --- a/src/sam3x.c +++ b/src/sam3x.c @@ -22,9 +22,6 @@ * the device, providing the XML memory map and Flash memory programming. */ -#include -#include - #include "general.h" #include "adiv5.h" #include "target.h" diff --git a/src/samd.c b/src/samd.c index b043c50..1a7a553 100644 --- a/src/samd.c +++ b/src/samd.c @@ -32,10 +32,6 @@ * particularly Sections 12. DSU and 20. NVMCTRL */ -#include -#include -#include - #include "general.h" #include "jtagtap.h" #include "adiv5.h" diff --git a/src/stm32f1.c b/src/stm32f1.c index bce00d3..017196a 100644 --- a/src/stm32f1.c +++ b/src/stm32f1.c @@ -29,9 +29,6 @@ * Programming manual - STM32F10xxx Flash memory microcontrollers */ -#include -#include - #include "general.h" #include "adiv5.h" #include "target.h" diff --git a/src/stm32f4.c b/src/stm32f4.c index 148c31b..bc3572f 100644 --- a/src/stm32f4.c +++ b/src/stm32f4.c @@ -30,9 +30,6 @@ * manual */ -#include -#include - #include "general.h" #include "adiv5.h" #include "target.h" diff --git a/src/stm32l1.c b/src/stm32l1.c index 0472885..227f67c 100644 --- a/src/stm32l1.c +++ b/src/stm32l1.c @@ -29,9 +29,6 @@ * Flash and EEPROM programming */ -#include -#include - #include "general.h" #include "adiv5.h" #include "target.h" diff --git a/src/target.c b/src/target.c index 2a68f23..4299a45 100644 --- a/src/target.c +++ b/src/target.c @@ -21,8 +21,6 @@ #include "general.h" #include "target.h" -#include - target *target_list = NULL; bool connect_assert_srst; -- cgit v1.2.3 From 2e785e56fa4e77549878eac88f2c4891af043e64 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 14 Mar 2015 18:03:04 -0700 Subject: adiv5: Encode APnDP into register definition. Clean up magic numbers in adiv5 calls. Removed old adiv5_dp_write_ap and adiv5_dp_read_ap.--- src/adiv5.c | 90 +++++++++++++++++++---------------------------------- src/adiv5_jtagdp.c | 31 +++++++++--------- src/adiv5_swdp.c | 28 +++++++++++------ src/cortexm.c | 35 ++++++++++++--------- src/include/adiv5.h | 57 +++++++++++++++++---------------- src/lmi.c | 11 ++++--- src/samd.c | 4 +-- 7 files changed, 123 insertions(+), 133 deletions(-) (limited to 'src/adiv5_swdp.c') diff --git a/src/adiv5.c b/src/adiv5.c index 361cd75..aee8471 100644 --- a/src/adiv5.c +++ b/src/adiv5.c @@ -160,23 +160,6 @@ void adiv5_dp_init(ADIv5_DP_t *dp) adiv5_dp_unref(dp); } -void adiv5_dp_write_ap(ADIv5_DP_t *dp, uint8_t addr, uint32_t value) -{ - adiv5_dp_low_access(dp, ADIV5_LOW_AP, ADIV5_LOW_WRITE, addr, value); -} - -uint32_t adiv5_dp_read_ap(ADIv5_DP_t *dp, uint8_t addr) -{ - uint32_t ret; - - adiv5_dp_low_access(dp, ADIV5_LOW_AP, ADIV5_LOW_READ, addr, 0); - ret = adiv5_dp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_READ, - ADIV5_DP_RDBUFF, 0); - - return ret; -} - - static int ap_check_error(struct target_s *target) { @@ -194,26 +177,24 @@ ap_mem_read_words(struct target_s *target, uint32_t *dest, uint32_t src, int len adiv5_ap_write(ap, ADIV5_AP_CSW, ap->csw | ADIV5_AP_CSW_SIZE_WORD | ADIV5_AP_CSW_ADDRINC_SINGLE); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_WRITE, - ADIV5_AP_TAR, src); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_READ, - ADIV5_AP_DRW, 0); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, src); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_AP_DRW, 0); while(--len) { - *dest++ = adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, + *dest++ = adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_AP_DRW, 0); src += 4; /* Check for 10 bit address overflow */ if ((src ^ osrc) & 0xfffffc00) { osrc = src; - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, src); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_AP_DRW, 0); } } - *dest++ = adiv5_dp_low_access(ap->dp, ADIV5_LOW_DP, ADIV5_LOW_READ, - ADIV5_DP_RDBUFF, 0); + *dest++ = adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, + ADIV5_DP_RDBUFF, 0); return 0; } @@ -229,12 +210,10 @@ ap_mem_read_halfwords(struct target_s *target, uint16_t *dest, uint32_t src, int adiv5_ap_write(ap, ADIV5_AP_CSW, ap->csw | ADIV5_AP_CSW_SIZE_HALFWORD | ADIV5_AP_CSW_ADDRINC_SINGLE); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_WRITE, - ADIV5_AP_TAR, src); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_READ, - ADIV5_AP_DRW, 0); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, src); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_AP_DRW, 0); while(--len) { - tmp = adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_READ, + tmp = adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_AP_DRW, 0); *dest++ = (tmp >> ((src & 0x2) << 3) & 0xFFFF); @@ -242,13 +221,13 @@ ap_mem_read_halfwords(struct target_s *target, uint16_t *dest, uint32_t src, int /* Check for 10 bit address overflow */ if ((src ^ osrc) & 0xfffffc00) { osrc = src; - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, src); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_AP_DRW, 0); } } - tmp = adiv5_dp_low_access(ap->dp, 0, 1, ADIV5_DP_RDBUFF, 0); + tmp = adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_DP_RDBUFF, 0); *dest++ = (tmp >> ((src & 0x2) << 3) & 0xFFFF); return 0; @@ -263,25 +242,23 @@ ap_mem_read_bytes(struct target_s *target, uint8_t *dest, uint32_t src, int len) adiv5_ap_write(ap, ADIV5_AP_CSW, ap->csw | ADIV5_AP_CSW_SIZE_BYTE | ADIV5_AP_CSW_ADDRINC_SINGLE); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_WRITE, - ADIV5_AP_TAR, src); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_READ, - ADIV5_AP_DRW, 0); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, src); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_AP_DRW, 0); while(--len) { - tmp = adiv5_dp_low_access(ap->dp, 1, 1, ADIV5_AP_DRW, 0); + tmp = adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_AP_DRW, 0); *dest++ = (tmp >> ((src & 0x3) << 3) & 0xFF); src++; /* Check for 10 bit address overflow */ if ((src ^ osrc) & 0xfffffc00) { osrc = src; - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, src); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_AP_DRW, 0); } } - tmp = adiv5_dp_low_access(ap->dp, 0, 1, ADIV5_DP_RDBUFF, 0); + tmp = adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_DP_RDBUFF, 0); *dest++ = (tmp >> ((src++ & 0x3) << 3) & 0xFF); return 0; @@ -298,16 +275,15 @@ ap_mem_write_words(struct target_s *target, uint32_t dest, const uint32_t *src, adiv5_ap_write(ap, ADIV5_AP_CSW, ap->csw | ADIV5_AP_CSW_SIZE_WORD | ADIV5_AP_CSW_ADDRINC_SINGLE); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_WRITE, - ADIV5_AP_TAR, dest); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, dest); while(len--) { - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_WRITE, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_DRW, *src++); dest += 4; /* Check for 10 bit address overflow */ if ((dest ^ odest) & 0xfffffc00) { odest = dest; - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, dest); } } @@ -325,17 +301,16 @@ ap_mem_write_halfwords(struct target_s *target, uint32_t dest, const uint16_t *s adiv5_ap_write(ap, ADIV5_AP_CSW, ap->csw | ADIV5_AP_CSW_SIZE_HALFWORD | ADIV5_AP_CSW_ADDRINC_SINGLE); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_WRITE, - ADIV5_AP_TAR, dest); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, dest); while(len--) { uint32_t tmp = (uint32_t)*src++ << ((dest & 2) << 3); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_WRITE, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_DRW, tmp); dest += 2; /* Check for 10 bit address overflow */ if ((dest ^ odest) & 0xfffffc00) { odest = dest; - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, dest); } } @@ -350,17 +325,16 @@ ap_mem_write_bytes(struct target_s *target, uint32_t dest, const uint8_t *src, i adiv5_ap_write(ap, ADIV5_AP_CSW, ap->csw | ADIV5_AP_CSW_SIZE_BYTE | ADIV5_AP_CSW_ADDRINC_SINGLE); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_WRITE, - ADIV5_AP_TAR, dest); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, dest); while(len--) { uint32_t tmp = (uint32_t)*src++ << ((dest++ & 3) << 3); - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, ADIV5_LOW_WRITE, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_DRW, tmp); /* Check for 10 bit address overflow */ if ((dest ^ odest) & 0xfffffc00) { odest = dest; - adiv5_dp_low_access(ap->dp, ADIV5_LOW_AP, + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, dest); } } @@ -429,19 +403,19 @@ void adiv5_ap_mem_write_byte(ADIv5_AP_t *ap, uint32_t addr, uint8_t value) adiv5_ap_write(ap, ADIV5_AP_DRW, v); } -void adiv5_ap_write(ADIv5_AP_t *ap, uint8_t addr, uint32_t value) +void adiv5_ap_write(ADIv5_AP_t *ap, uint16_t addr, uint32_t value) { adiv5_dp_write(ap->dp, ADIV5_DP_SELECT, ((uint32_t)ap->apsel << 24)|(addr & 0xF0)); - adiv5_dp_write_ap(ap->dp, addr, value); + adiv5_dp_write(ap->dp, addr, value); } -uint32_t adiv5_ap_read(ADIv5_AP_t *ap, uint8_t addr) +uint32_t adiv5_ap_read(ADIv5_AP_t *ap, uint16_t addr) { uint32_t ret; adiv5_dp_write(ap->dp, ADIV5_DP_SELECT, ((uint32_t)ap->apsel << 24)|(addr & 0xF0)); - ret = adiv5_dp_read_ap(ap->dp, addr); + ret = adiv5_dp_read(ap->dp, addr); return ret; } diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index 8f62a11..eb60caa 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -36,13 +36,13 @@ #define IR_DPACC 0xA #define IR_APACC 0xB -static void adiv5_jtagdp_write(ADIv5_DP_t *dp, uint8_t addr, uint32_t value); -static uint32_t adiv5_jtagdp_read(ADIv5_DP_t *dp, uint8_t addr); +static void adiv5_jtagdp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value); +static uint32_t adiv5_jtagdp_read(ADIv5_DP_t *dp, uint16_t addr); static uint32_t adiv5_jtagdp_error(ADIv5_DP_t *dp); -static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, - uint8_t addr, uint32_t value); +static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, + uint16_t addr, uint32_t value); void adiv5_jtag_dp_handler(jtag_dev_t *dev) @@ -60,35 +60,36 @@ void adiv5_jtag_dp_handler(jtag_dev_t *dev) adiv5_dp_init(dp); } -static void adiv5_jtagdp_write(ADIv5_DP_t *dp, uint8_t addr, uint32_t value) +static void adiv5_jtagdp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value) { - adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_WRITE, addr, value); + adiv5_jtagdp_low_access(dp, ADIV5_LOW_WRITE, addr, value); } -static uint32_t adiv5_jtagdp_read(ADIv5_DP_t *dp, uint8_t addr) +static uint32_t adiv5_jtagdp_read(ADIv5_DP_t *dp, uint16_t addr) { - adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_READ, addr, 0); - return adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_READ, + adiv5_jtagdp_low_access(dp, ADIV5_LOW_READ, addr, 0); + return adiv5_jtagdp_low_access(dp, ADIV5_LOW_READ, ADIV5_DP_RDBUFF, 0); } static uint32_t adiv5_jtagdp_error(ADIv5_DP_t *dp) { - adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_READ, - ADIV5_DP_CTRLSTAT, 0); - return adiv5_jtagdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_WRITE, + adiv5_jtagdp_low_access(dp, ADIV5_LOW_READ, ADIV5_DP_CTRLSTAT, 0); + return adiv5_jtagdp_low_access(dp, ADIV5_LOW_WRITE, ADIV5_DP_CTRLSTAT, 0xF0000032) & 0x32; } -static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, - uint8_t addr, uint32_t value) +static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, + uint16_t addr, uint32_t value) { + bool APnDP = addr & ADIV5_APnDP; + addr &= 0xff; uint64_t request, response; uint8_t ack; request = ((uint64_t)value << 3) | ((addr >> 1) & 0x06) | (RnW?1:0); - jtag_dev_write_ir(dp->dev, APnDP?IR_APACC:IR_DPACC); + jtag_dev_write_ir(dp->dev, APnDP ? IR_APACC : IR_DPACC); int tries = 1000; do { diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 9df362f..3e775cc 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -33,13 +33,13 @@ #define SWDP_ACK_WAIT 0x02 #define SWDP_ACK_FAULT 0x04 -static void adiv5_swdp_write(ADIv5_DP_t *dp, uint8_t addr, uint32_t value); -static uint32_t adiv5_swdp_read(ADIv5_DP_t *dp, uint8_t addr); +static void adiv5_swdp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value); +static uint32_t adiv5_swdp_read(ADIv5_DP_t *dp, uint16_t addr); static uint32_t adiv5_swdp_error(ADIv5_DP_t *dp); -static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, - uint8_t addr, uint32_t value); +static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, + uint16_t addr, uint32_t value); int adiv5_swdp_scan(void) @@ -78,14 +78,20 @@ int adiv5_swdp_scan(void) return target_list?1:0; } -static void adiv5_swdp_write(ADIv5_DP_t *dp, uint8_t addr, uint32_t value) +static void adiv5_swdp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value) { - adiv5_swdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_WRITE, addr, value); + adiv5_swdp_low_access(dp, ADIV5_LOW_WRITE, addr, value); } -static uint32_t adiv5_swdp_read(ADIv5_DP_t *dp, uint8_t addr) +static uint32_t adiv5_swdp_read(ADIv5_DP_t *dp, uint16_t addr) { - return adiv5_swdp_low_access(dp, ADIV5_LOW_DP, ADIV5_LOW_READ, addr, 0); + if (addr & ADIV5_APnDP) { + adiv5_dp_low_access(dp, ADIV5_LOW_READ, addr, 0); + return adiv5_dp_low_access(dp, ADIV5_LOW_READ, + ADIV5_DP_RDBUFF, 0); + } else { + return adiv5_swdp_low_access(dp, ADIV5_LOW_READ, addr, 0); + } } static uint32_t adiv5_swdp_error(ADIv5_DP_t *dp) @@ -111,9 +117,11 @@ static uint32_t adiv5_swdp_error(ADIv5_DP_t *dp) return err; } -static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t APnDP, uint8_t RnW, - uint8_t addr, uint32_t value) +static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, + uint16_t addr, uint32_t value) { + bool APnDP = addr & ADIV5_APnDP; + addr &= 0xff; uint8_t request = 0x81; uint32_t response; uint8_t ack; diff --git a/src/cortexm.c b/src/cortexm.c index b1d3569..da48f8e 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -359,20 +359,23 @@ cortexm_regs_read(struct target_s *target, void *data) /* Map the banked data registers (0x10-0x1c) to the * debug registers DHCSR, DCRSR, DCRDR and DEMCR respectively */ - adiv5_dp_low_access(ap->dp, 1, 0, ADIV5_AP_TAR, CORTEXM_DHCSR); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, CORTEXM_DHCSR); /* Walk the regnum_cortex_m array, reading the registers it * calls out. */ adiv5_ap_write(ap, ADIV5_AP_DB(1), regnum_cortex_m[0]); /* Required to switch banks */ - *regs++ = adiv5_dp_read_ap(ap->dp, ADIV5_AP_DB(2)); + *regs++ = adiv5_dp_read(ap->dp, ADIV5_AP_DB(2)); for(i = 1; i < sizeof(regnum_cortex_m) / 4; i++) { - adiv5_dp_low_access(ap->dp, 1, 0, ADIV5_AP_DB(1), regnum_cortex_m[i]); - *regs++ = adiv5_dp_read_ap(ap->dp, ADIV5_AP_DB(2)); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_DB(1), + regnum_cortex_m[i]); + *regs++ = adiv5_dp_read(ap->dp, ADIV5_AP_DB(2)); } if (target->target_options & TOPT_FLAVOUR_V7MF) for(i = 0; i < sizeof(regnum_cortex_mf) / 4; i++) { - adiv5_dp_low_access(ap->dp, 1, 0, ADIV5_AP_DB(1), regnum_cortex_mf[i]); - *regs++ = adiv5_dp_read_ap(ap->dp, ADIV5_AP_DB(2)); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, + ADIV5_AP_DB(1), + regnum_cortex_mf[i]); + *regs++ = adiv5_dp_read(ap->dp, ADIV5_AP_DB(2)); } return 0; @@ -391,22 +394,26 @@ cortexm_regs_write(struct target_s *target, const void *data) /* Map the banked data registers (0x10-0x1c) to the * debug registers DHCSR, DCRSR, DCRDR and DEMCR respectively */ - adiv5_dp_low_access(ap->dp, 1, 0, ADIV5_AP_TAR, CORTEXM_DHCSR); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_TAR, CORTEXM_DHCSR); /* Walk the regnum_cortex_m array, writing the registers it * calls out. */ adiv5_ap_write(ap, ADIV5_AP_DB(2), *regs++); /* Required to switch banks */ - adiv5_dp_low_access(ap->dp, 1, 0, ADIV5_AP_DB(1), 0x10000 | regnum_cortex_m[0]); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_DB(1), + 0x10000 | regnum_cortex_m[0]); for(i = 1; i < sizeof(regnum_cortex_m) / 4; i++) { - adiv5_dp_low_access(ap->dp, 1, 0, ADIV5_AP_DB(2), *regs++); - adiv5_dp_low_access(ap->dp, 1, 0, ADIV5_AP_DB(1), - 0x10000 | regnum_cortex_m[i]); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, + ADIV5_AP_DB(2), *regs++); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_DB(1), + 0x10000 | regnum_cortex_m[i]); } if (target->target_options & TOPT_FLAVOUR_V7MF) for(i = 0; i < sizeof(regnum_cortex_mf) / 4; i++) { - adiv5_dp_low_access(ap->dp, 1, 0, ADIV5_AP_DB(2), *regs++); - adiv5_dp_low_access(ap->dp, 1, 0, ADIV5_AP_DB(1), - 0x10000 | regnum_cortex_mf[i]); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, + ADIV5_AP_DB(2), *regs++); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, + ADIV5_AP_DB(1), + 0x10000 | regnum_cortex_mf[i]); } return 0; diff --git a/src/include/adiv5.h b/src/include/adiv5.h index e0ce9cf..cfdb4e5 100644 --- a/src/include/adiv5.h +++ b/src/include/adiv5.h @@ -24,12 +24,16 @@ #include "jtag_scan.h" #include "target.h" +#define ADIV5_APnDP 0x100 +#define ADIV5_DP_REG(x) (x) +#define ADIV5_AP_REG(x) (ADIV5_APnDP | (x)) + /* ADIv5 DP Register addresses */ -#define ADIV5_DP_IDCODE 0x0 -#define ADIV5_DP_ABORT 0x0 -#define ADIV5_DP_CTRLSTAT 0x4 -#define ADIV5_DP_SELECT 0x8 -#define ADIV5_DP_RDBUFF 0xC +#define ADIV5_DP_IDCODE ADIV5_DP_REG(0x0) +#define ADIV5_DP_ABORT ADIV5_DP_REG(0x0) +#define ADIV5_DP_CTRLSTAT ADIV5_DP_REG(0x4) +#define ADIV5_DP_SELECT ADIV5_DP_REG(0x8) +#define ADIV5_DP_RDBUFF ADIV5_DP_REG(0xC) /* AP Abort Register (ABORT) */ /* Bits 31:5 - Reserved */ @@ -63,15 +67,15 @@ /* ADIv5 MEM-AP Registers */ -#define ADIV5_AP_CSW 0x00 -#define ADIV5_AP_TAR 0x04 +#define ADIV5_AP_CSW ADIV5_AP_REG(0x00) +#define ADIV5_AP_TAR ADIV5_AP_REG(0x04) /* 0x08 - Reserved */ -#define ADIV5_AP_DRW 0x0C -#define ADIV5_AP_DB(x) (0x10 + (4*(x))) +#define ADIV5_AP_DRW ADIV5_AP_REG(0x0C) +#define ADIV5_AP_DB(x) ADIV5_AP_REG(0x10 + (4*(x))) /* 0x20:0xF0 - Reserved */ -#define ADIV5_AP_CFG 0xF4 -#define ADIV5_AP_BASE 0xF8 -#define ADIV5_AP_IDR 0xFC +#define ADIV5_AP_CFG ADIV5_AP_REG(0xF4) +#define ADIV5_AP_BASE ADIV5_AP_REG(0xF8) +#define ADIV5_AP_IDR ADIV5_AP_REG(0xFC) /* AP Control and Status Word (CSW) */ #define ADIV5_AP_CSW_DBGSWENABLE (1u << 31) @@ -93,11 +97,9 @@ #define ADIV5_AP_CSW_SIZE_WORD (2u << 0) #define ADIV5_AP_CSW_SIZE_MASK (7u << 0) -/* Constants to make RnW and APnDP parameters more clear in code */ +/* Constants to make RnW parameters more clear in code */ #define ADIV5_LOW_WRITE 0 #define ADIV5_LOW_READ 1 -#define ADIV5_LOW_DP 0 -#define ADIV5_LOW_AP 1 /* Try to keep this somewhat absract for later adding SW-DP */ typedef struct ADIv5_DP_s { @@ -107,13 +109,13 @@ typedef struct ADIv5_DP_s { bool allow_timeout; - void (*dp_write)(struct ADIv5_DP_s *dp, uint8_t addr, uint32_t value); - uint32_t (*dp_read)(struct ADIv5_DP_s *dp, uint8_t addr); + void (*dp_write)(struct ADIv5_DP_s *dp, uint16_t addr, uint32_t value); + uint32_t (*dp_read)(struct ADIv5_DP_s *dp, uint16_t addr); uint32_t (*error)(struct ADIv5_DP_s *dp); - uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t APnDP, uint8_t RnW, - uint8_t addr, uint32_t value); + uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t RnW, + uint16_t addr, uint32_t value); union { jtag_dev_t *dev; @@ -121,12 +123,12 @@ typedef struct ADIv5_DP_s { }; } ADIv5_DP_t; -static inline void adiv5_dp_write(ADIv5_DP_t *dp, uint8_t addr, uint32_t value) +static inline void adiv5_dp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value) { dp->dp_write(dp, addr, value); } -static inline uint32_t adiv5_dp_read(ADIv5_DP_t *dp, uint8_t addr) +static inline uint32_t adiv5_dp_read(ADIv5_DP_t *dp, uint16_t addr) { return dp->dp_read(dp, addr); } @@ -136,10 +138,10 @@ static inline uint32_t adiv5_dp_error(ADIv5_DP_t *dp) return dp->error(dp); } -static inline uint32_t adiv5_dp_low_access(struct ADIv5_DP_s *dp, uint8_t APnDP, - uint8_t RnW, uint8_t addr, uint32_t value) +static inline uint32_t adiv5_dp_low_access(struct ADIv5_DP_s *dp, uint8_t RnW, + uint16_t addr, uint32_t value) { - return dp->low_access(dp, APnDP, RnW, addr, value); + return dp->low_access(dp, RnW, addr, value); } typedef struct ADIv5_AP_s { @@ -164,9 +166,6 @@ void adiv5_ap_ref(ADIv5_AP_t *ap); void adiv5_dp_unref(ADIv5_DP_t *dp); void adiv5_ap_unref(ADIv5_AP_t *ap); -void adiv5_dp_write_ap(ADIv5_DP_t *dp, uint8_t addr, uint32_t value); -uint32_t adiv5_dp_read_ap(ADIv5_DP_t *dp, uint8_t addr); - uint32_t adiv5_ap_mem_read(ADIv5_AP_t *ap, uint32_t addr); void adiv5_ap_mem_write(ADIv5_AP_t *ap, uint32_t addr, uint32_t value); uint16_t adiv5_ap_mem_read_halfword(ADIv5_AP_t *ap, uint32_t addr); @@ -174,8 +173,8 @@ void adiv5_ap_mem_write_halfword(ADIv5_AP_t *ap, uint32_t addr, uint16_t value); uint8_t adiv5_ap_mem_read_byte(ADIv5_AP_t *ap, uint32_t addr); void adiv5_ap_mem_write_byte(ADIv5_AP_t *ap, uint32_t addr, uint8_t value); -void adiv5_ap_write(ADIv5_AP_t *ap, uint8_t addr, uint32_t value); -uint32_t adiv5_ap_read(ADIv5_AP_t *ap, uint8_t addr); +void adiv5_ap_write(ADIv5_AP_t *ap, uint16_t addr, uint32_t value); +uint32_t adiv5_ap_read(ADIv5_AP_t *ap, uint16_t addr); void adiv5_jtag_dp_handler(jtag_dev_t *dev); int adiv5_swdp_scan(void); diff --git a/src/lmi.c b/src/lmi.c index 0f16db4..9359458 100644 --- a/src/lmi.c +++ b/src/lmi.c @@ -131,17 +131,18 @@ int lmi_flash_erase(struct target_s *target, uint32_t addr, size_t len) adiv5_ap_write(ap, 0x00, 0xA2000052); /* select Flash Control */ - adiv5_dp_low_access(ap->dp, 1, 0, 0x04, 0x400FD000); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, 0x04, 0x400FD000); while(len) { /* write address to FMA */ - adiv5_ap_write(ap, 0x10, addr); /* Required to switch banks */ + adiv5_ap_write(ap, ADIV5_AP_DB(0), addr); /* Required to switch banks */ /* set ERASE bit in FMC */ - adiv5_dp_low_access(ap->dp, 1, 0, 0x08, 0xA4420002); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_WRITE, ADIV5_AP_DB(2), 0xA4420002); /* Read FMC to poll for ERASE bit */ - adiv5_dp_low_access(ap->dp, 1, 1, 0x08, 0); + adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, ADIV5_AP_DB(2), 0); do { - tmp = adiv5_dp_low_access(ap->dp, 1, 1, 0x08, 0); + tmp = adiv5_dp_low_access(ap->dp, ADIV5_LOW_READ, + ADIV5_AP_DB(2), 0); } while (tmp & 2); len -= 0x400; diff --git a/src/samd.c b/src/samd.c index 6f73956..2719763 100644 --- a/src/samd.c +++ b/src/samd.c @@ -553,7 +553,7 @@ static int samd_flash_write(struct target_s *target, uint32_t dest, /* Partial, manual page write */ for (; addr <= MINIMUM(end, end_of_this_page); addr += 4, i++) { - adiv5_dp_write_ap(ap->dp, ADIV5_AP_DRW, data[i]); + adiv5_dp_write(ap->dp, ADIV5_AP_DRW, data[i]); } /* Unlock */ @@ -578,7 +578,7 @@ static int samd_flash_write(struct target_s *target, uint32_t dest, /* Full, automatic page write */ for (; addr < page + SAMD_PAGE_SIZE; addr += 4, i++) { - adiv5_dp_write_ap(ap->dp, ADIV5_AP_DRW, data[i]); + adiv5_dp_write(ap->dp, ADIV5_AP_DRW, data[i]); } } -- cgit v1.2.3 From c3f798438a65b284adec281e7ddb4e8268ff4f4b Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 15 Mar 2015 17:12:31 -0700 Subject: Remove abstraction of adiv5_dp_write. Both implementations were identical. --- src/adiv5.c | 5 +++++ src/adiv5_jtagdp.c | 7 ------- src/adiv5_swdp.c | 9 +-------- src/include/adiv5.h | 7 +------ 4 files changed, 7 insertions(+), 21 deletions(-) (limited to 'src/adiv5_swdp.c') diff --git a/src/adiv5.c b/src/adiv5.c index 2179ca6..f2421ce 100644 --- a/src/adiv5.c +++ b/src/adiv5.c @@ -70,6 +70,11 @@ void adiv5_ap_unref(ADIv5_AP_t *ap) } } +void adiv5_dp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value) +{ + dp->low_access(dp, ADIV5_LOW_WRITE, addr, value); +} + void adiv5_dp_init(ADIv5_DP_t *dp) { uint32_t ctrlstat; diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index eb60caa..5049e3c 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -36,7 +36,6 @@ #define IR_DPACC 0xA #define IR_APACC 0xB -static void adiv5_jtagdp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value); static uint32_t adiv5_jtagdp_read(ADIv5_DP_t *dp, uint16_t addr); static uint32_t adiv5_jtagdp_error(ADIv5_DP_t *dp); @@ -52,7 +51,6 @@ void adiv5_jtag_dp_handler(jtag_dev_t *dev) dp->dev = dev; dp->idcode = dev->idcode; - dp->dp_write = adiv5_jtagdp_write; dp->dp_read = adiv5_jtagdp_read; dp->error = adiv5_jtagdp_error; dp->low_access = adiv5_jtagdp_low_access; @@ -60,11 +58,6 @@ void adiv5_jtag_dp_handler(jtag_dev_t *dev) adiv5_dp_init(dp); } -static void adiv5_jtagdp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value) -{ - adiv5_jtagdp_low_access(dp, ADIV5_LOW_WRITE, addr, value); -} - static uint32_t adiv5_jtagdp_read(ADIv5_DP_t *dp, uint16_t addr) { adiv5_jtagdp_low_access(dp, ADIV5_LOW_READ, addr, 0); diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 3e775cc..9ac791a 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -33,7 +33,6 @@ #define SWDP_ACK_WAIT 0x02 #define SWDP_ACK_FAULT 0x04 -static void adiv5_swdp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value); static uint32_t adiv5_swdp_read(ADIv5_DP_t *dp, uint16_t addr); static uint32_t adiv5_swdp_error(ADIv5_DP_t *dp); @@ -64,7 +63,6 @@ int adiv5_swdp_scan(void) return -1; } - dp->dp_write = adiv5_swdp_write; dp->dp_read = adiv5_swdp_read; dp->error = adiv5_swdp_error; dp->low_access = adiv5_swdp_low_access; @@ -78,11 +76,6 @@ int adiv5_swdp_scan(void) return target_list?1:0; } -static void adiv5_swdp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value) -{ - adiv5_swdp_low_access(dp, ADIV5_LOW_WRITE, addr, value); -} - static uint32_t adiv5_swdp_read(ADIv5_DP_t *dp, uint16_t addr) { if (addr & ADIV5_APnDP) { @@ -111,7 +104,7 @@ static uint32_t adiv5_swdp_error(ADIv5_DP_t *dp) if(err & ADIV5_DP_CTRLSTAT_WDATAERR) clr |= ADIV5_DP_ABORT_WDERRCLR; - adiv5_swdp_write(dp, ADIV5_DP_ABORT, clr); + adiv5_dp_write(dp, ADIV5_DP_ABORT, clr); dp->fault = 0; return err; diff --git a/src/include/adiv5.h b/src/include/adiv5.h index 4bc3905..6896f6d 100644 --- a/src/include/adiv5.h +++ b/src/include/adiv5.h @@ -109,7 +109,6 @@ typedef struct ADIv5_DP_s { bool allow_timeout; - void (*dp_write)(struct ADIv5_DP_s *dp, uint16_t addr, uint32_t value); uint32_t (*dp_read)(struct ADIv5_DP_s *dp, uint16_t addr); uint32_t (*error)(struct ADIv5_DP_s *dp); @@ -123,11 +122,6 @@ typedef struct ADIv5_DP_s { }; } ADIv5_DP_t; -static inline void adiv5_dp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value) -{ - dp->dp_write(dp, addr, value); -} - static inline uint32_t adiv5_dp_read(ADIv5_DP_t *dp, uint16_t addr) { return dp->dp_read(dp, addr); @@ -160,6 +154,7 @@ typedef struct ADIv5_AP_s { } ADIv5_AP_t; void adiv5_dp_init(ADIv5_DP_t *dp); +void adiv5_dp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value); void adiv5_dp_ref(ADIv5_DP_t *dp); void adiv5_ap_ref(ADIv5_AP_t *ap); -- cgit v1.2.3 From fa046601a54ddf2137048f11594ed7d72ede995a Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 28 Feb 2015 20:50:10 -0800 Subject: Add exception handling mechanism and raise exception on low-level comms failure. --- src/Makefile | 1 + src/adiv5_jtagdp.c | 7 ++-- src/adiv5_swdp.c | 9 +++-- src/exception.c | 39 ++++++++++++++++++++++ src/include/exception.h | 74 +++++++++++++++++++++++++++++++++++++++++ src/platforms/native/platform.h | 1 + 6 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 src/exception.c create mode 100644 src/include/exception.h (limited to 'src/adiv5_swdp.c') diff --git a/src/Makefile b/src/Makefile index 02b5690..73fb8e9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -24,6 +24,7 @@ SRC = \ command.c \ cortexm.c \ crc32.c \ + exception.c \ gdb_if.c \ gdb_main.c \ gdb_packet.c \ diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index 5049e3c..bb478d1 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -23,6 +23,7 @@ */ #include "general.h" +#include "exception.h" #include "adiv5.h" #include "jtag_scan.h" #include "jtagtap.h" @@ -93,10 +94,8 @@ static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, if (dp->allow_timeout && (ack == JTAGDP_ACK_WAIT)) return 0; - if((ack != JTAGDP_ACK_OK)) { - /* Fatal error if invalid ACK response */ - PLATFORM_FATAL_ERROR(1); - } + if((ack != JTAGDP_ACK_OK)) + raise_exception(EXCEPTION_ERROR, "JTAG-DP invalid ACK"); return (uint32_t)(response >> 3); } diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 9ac791a..d5193ac 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -23,6 +23,7 @@ */ #include "general.h" +#include "exception.h" #include "adiv5.h" #include "swdptap.h" #include "jtagtap.h" @@ -143,14 +144,12 @@ static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, return 0; } - if(ack != SWDP_ACK_OK) { - /* Fatal error if invalid ACK response */ - PLATFORM_FATAL_ERROR(1); - } + if(ack != SWDP_ACK_OK) + raise_exception(EXCEPTION_ERROR, "SWDP invalid ACK"); if(RnW) { if(swdptap_seq_in_parity(&response, 32)) /* Give up on parity error */ - PLATFORM_FATAL_ERROR(1); + raise_exception(EXCEPTION_ERROR, "SWDP Parity error"); } else { swdptap_seq_out_parity(value, 32); } diff --git a/src/exception.c b/src/exception.c new file mode 100644 index 0000000..33e3869 --- /dev/null +++ b/src/exception.c @@ -0,0 +1,39 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2015 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "general.h" +#include "exception.h" + +struct exception *innermost_exception; + +void raise_exception(uint32_t type, const char *msg) +{ + struct exception *e; + for (e = innermost_exception; e; e = e->outer) { + if (e->mask & type) { + e->type = type; + e->msg = msg; + innermost_exception = e->outer; + longjmp(e->jmpbuf, type); + } + } + PLATFORM_FATAL_ERROR(type); +} + diff --git a/src/include/exception.h b/src/include/exception.h new file mode 100644 index 0000000..180398d --- /dev/null +++ b/src/include/exception.h @@ -0,0 +1,74 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2015 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* Exception handling to escape deep nesting. + * Used for the case of communicaiton failure and timeouts. + */ + +/* Example usage: + * + * volatile struct exception e; + * TRY_CATCH (e, EXCEPTION_TIMEOUT) { + * ... + * raise_exception(EXCEPTION_TIMEOUT, "Timeout occurred"); + * ... + * } + * if (e.type == EXCEPTION_TIMEOUT) { + * printf("timeout: %s\n", e.msg); + * } + */ + +/* Limitations: + * Can't use break, return, goto, etc from inside the TRY_CATCH block. + */ + +#ifndef __EXCEPTION_H +#define __EXCEPTION_H + +#include +#include + +#define EXCEPTION_ERROR 0x01 +#define EXCEPTION_TIMEOUT 0x02 +#define EXCEPTION_ALL -1 + +struct exception { + uint32_t type; + const char *msg; + /* private */ + uint32_t mask; + jmp_buf jmpbuf; + struct exception *outer; +}; + +extern struct exception *innermost_exception; + +#define TRY_CATCH(e, type_mask) \ + (e).type = 0; \ + (e).mask = (type_mask); \ + (e).outer = innermost_exception; \ + innermost_exception = (void*)&(e); \ + if (setjmp(innermost_exception->jmpbuf) == 0) \ + for (;innermost_exception == &(e); innermost_exception = (e).outer) + +void raise_exception(uint32_t type, const char *msg); + +#endif + diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index ae9bcef..3b1769b 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -153,6 +153,7 @@ extern jmp_buf fatal_error_jmpbuf; #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);} #define SET_ERROR_STATE(state) {gpio_set_val(LED_PORT, LED_ERROR, state);} +#include "target.h" #define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} #define PLATFORM_FATAL_ERROR(error) do { \ if(running_status) gdb_putpacketz("X1D"); \ -- cgit v1.2.3 From d6225eec763bd49ef3cb8edac5138df9e524a073 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 28 Feb 2015 20:53:25 -0800 Subject: Raise timeout exception when target is in WFI. Ignore the exception when polling for halt, and report the exception to the user if halting the target fails. Remove old allow_timeout flag in DP struct that's no longer needed.--- src/adiv5_jtagdp.c | 4 ++-- src/adiv5_swdp.c | 4 ++-- src/cortexm.c | 29 +++++++++++++++++++---------- src/include/adiv5.h | 4 ---- 4 files changed, 23 insertions(+), 18 deletions(-) (limited to 'src/adiv5_swdp.c') diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index bb478d1..a460113 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -91,8 +91,8 @@ static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, ack = response & 0x07; } while(--tries && (ack == JTAGDP_ACK_WAIT)); - if (dp->allow_timeout && (ack == JTAGDP_ACK_WAIT)) - return 0; + if (ack == JTAGDP_ACK_WAIT) + raise_exception(EXCEPTION_TIMEOUT, "JTAG-DP ACK timeout"); if((ack != JTAGDP_ACK_OK)) raise_exception(EXCEPTION_ERROR, "JTAG-DP invalid ACK"); diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index d5193ac..1a6b158 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -136,8 +136,8 @@ static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, ack = swdptap_seq_in(3); } while(--tries && ack == SWDP_ACK_WAIT); - if (dp->allow_timeout && (ack == SWDP_ACK_WAIT)) - return 0; + if (ack == SWDP_ACK_WAIT) + raise_exception(EXCEPTION_TIMEOUT, "SWDP ACK timeout"); if(ack == SWDP_ACK_FAULT) { dp->fault = 1; diff --git a/src/cortexm.c b/src/cortexm.c index a129a3c..f20f282 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -29,6 +29,7 @@ * There are way too many magic numbers used here. */ #include "general.h" +#include "exception.h" #include "jtagtap.h" #include "jtag_scan.h" #include "adiv5.h" @@ -467,12 +468,15 @@ cortexm_reset(struct target_s *target) static void cortexm_halt_request(struct target_s *target) { - ADIv5_AP_t *ap = adiv5_target_ap(target); - - ap->dp->allow_timeout = false; - target_mem_write32(target, CORTEXM_DHCSR, - CORTEXM_DHCSR_DBGKEY | CORTEXM_DHCSR_C_HALT | - CORTEXM_DHCSR_C_DEBUGEN); + volatile struct exception e; + TRY_CATCH (e, EXCEPTION_TIMEOUT) { + target_mem_write32(target, CORTEXM_DHCSR, CORTEXM_DHCSR_DBGKEY | + CORTEXM_DHCSR_C_HALT | + CORTEXM_DHCSR_C_DEBUGEN); + } + if (e.type) { + gdb_out("Timeout sending interrupt, is target in WFI?\n"); + } } static int @@ -480,10 +484,16 @@ cortexm_halt_wait(struct target_s *target) { ADIv5_AP_t *ap = adiv5_target_ap(target); struct cortexm_priv *priv = ap->priv; - if (!(target_mem_read32(target, CORTEXM_DHCSR) & CORTEXM_DHCSR_S_HALT)) - return 0; - ap->dp->allow_timeout = false; + uint32_t dhcsr = 0; + volatile struct exception e; + TRY_CATCH (e, EXCEPTION_TIMEOUT) { + /* If this times out because the target is in WFI then + * the target is still running. */ + dhcsr = target_mem_read32(target, CORTEXM_DHCSR); + } + if (e.type || !(dhcsr & CORTEXM_DHCSR_S_HALT)) + return 0; /* We've halted. Let's find out why. */ uint32_t dfsr = target_mem_read32(target, CORTEXM_DFSR); @@ -543,7 +553,6 @@ void cortexm_halt_resume(struct target_s *target, bool step) } target_mem_write32(target, CORTEXM_DHCSR, dhcsr); - ap->dp->allow_timeout = true; } static int cortexm_fault_unwind(struct target_s *target) diff --git a/src/include/adiv5.h b/src/include/adiv5.h index 6896f6d..12d3bf4 100644 --- a/src/include/adiv5.h +++ b/src/include/adiv5.h @@ -107,12 +107,8 @@ typedef struct ADIv5_DP_s { uint32_t idcode; - bool allow_timeout; - uint32_t (*dp_read)(struct ADIv5_DP_s *dp, uint16_t addr); - uint32_t (*error)(struct ADIv5_DP_s *dp); - uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t RnW, uint16_t addr, uint32_t value); -- cgit v1.2.3 From 83b83ca48f71639d14673d1deb544bf39a7332be Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Mon, 2 Mar 2015 23:10:15 -0800 Subject: Use controlled timeout on SW/JTAG DP transactions. --- src/adiv5_jtagdp.c | 4 ++-- src/adiv5_swdp.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/adiv5_swdp.c') diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index a460113..d97bc99 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -85,11 +85,11 @@ static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, jtag_dev_write_ir(dp->dev, APnDP ? IR_APACC : IR_DPACC); - int tries = 1000; + platform_timeout_set(2000); do { jtag_dev_shift_dr(dp->dev, (uint8_t*)&response, (uint8_t*)&request, 35); ack = response & 0x07; - } while(--tries && (ack == JTAGDP_ACK_WAIT)); + } while(!platform_timeout_is_expired() && (ack == JTAGDP_ACK_WAIT)); if (ack == JTAGDP_ACK_WAIT) raise_exception(EXCEPTION_TIMEOUT, "JTAG-DP ACK timeout"); diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 1a6b158..b53fcb5 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -130,11 +130,11 @@ static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, if((addr == 4) || (addr == 8)) request ^= 0x20; - size_t tries = 1000; + platform_timeout_set(2000); do { swdptap_seq_out(request, 8); ack = swdptap_seq_in(3); - } while(--tries && ack == SWDP_ACK_WAIT); + } while (!platform_timeout_is_expired() && ack == SWDP_ACK_WAIT); if (ack == SWDP_ACK_WAIT) raise_exception(EXCEPTION_TIMEOUT, "SWDP ACK timeout"); -- cgit v1.2.3