From d4411fc51f15125cb35bda4d163673177ae0a3d2 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 31 Mar 2013 12:18:11 -0700 Subject: Removed verison info from USB strings on native platform. --- src/platforms/native/platform.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index fbd048a..a1471dc 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -35,8 +35,8 @@ #define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 #define PLATFORM_HAS_TRACESWO -#define BOARD_IDENT "Black Magic Probe, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" -#define BOARD_IDENT_DFU "Black Magic Probe (Upgrade), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" +#define BOARD_IDENT "Black Magic Probe" +#define BOARD_IDENT_DFU "Black Magic Probe (Upgrade)" #define DFU_IDENT "Black Magic Firmware Upgrade" #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,120*001Kg" -- cgit v1.2.3 From 43f7e7a3cf384e880bfefa6257f15c8915b02e3b Mon Sep 17 00:00:00 2001 From: Allen Ibara Date: Wed, 27 Mar 2013 12:09:49 -0700 Subject: Changes to the USBUART to make it less likely to drop characters at higher baud rates. USB UART seems to work fine at 115.2Kbps or 230.4Kbps, but starts to drop characters as the data rate goes higher. This commit changes the usbuart ISR to fill a software FIFO, and adds a low priority timer interrupt to run deferred processing to drain a FIFO and send USB CDCACM packets, rather than calling the usb send within the UART ISR. Tested on native platform, up to 1.5MBps. --- src/platforms/f4discovery/platform.h | 5 ++ src/platforms/native/platform.c | 3 +- src/platforms/native/platform.h | 5 ++ src/platforms/stlink/platform.h | 5 ++ src/platforms/stm32/usbuart.c | 126 ++++++++++++++++++++++++++++------- src/platforms/swlink/platform.h | 5 ++ 6 files changed, 123 insertions(+), 26 deletions(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 0010ec4..c1423b6 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -112,6 +112,7 @@ extern usbd_device *usbdev; */ #define IRQ_PRI_USB (2 << 4) #define IRQ_PRI_USBUSART (1 << 4) +#define IRQ_PRI_USBUSART_TIM (3 << 4) #define IRQ_PRI_TRACE (0 << 4) #define USBUSART USART3 @@ -124,6 +125,10 @@ extern usbd_device *usbdev; #define USBUSART_RX_PORT GPIOD #define USBUSART_RX_PIN GPIO9 #define USBUSART_ISR usart3_isr +#define USBUSART_TIM TIM4 +#define USBUSART_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM4EN) +#define USBUSART_TIM_IRQ NVIC_TIM4_IRQ +#define USBUSART_TIM_ISR tim4_isr #define UART_PIN_SETUP() do { \ gpio_mode_setup(USBUSART_TX_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, \ diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 24eb79b..3bd0816 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -108,8 +108,6 @@ int platform_init(void) systick_interrupt_enable(); systick_counter_enable(); - usbuart_init(); - if (platform_hwversion() > 0) { adc_init(); } else { @@ -121,6 +119,7 @@ int platform_init(void) SCB_VTOR = 0x2000; // Relocate interrupt vector table here cdcacm_init(); + usbuart_init(); jtag_scan(NULL); diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index a1471dc..eb91f8b 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -122,6 +122,7 @@ extern usbd_device *usbdev; */ #define IRQ_PRI_USB (2 << 4) #define IRQ_PRI_USBUSART (1 << 4) +#define IRQ_PRI_USBUSART_TIM (3 << 4) #define IRQ_PRI_USB_VBUS (14 << 4) #define IRQ_PRI_TRACE (0 << 4) @@ -133,6 +134,10 @@ extern usbd_device *usbdev; #define USBUSART_PORT GPIOA #define USBUSART_TX_PIN GPIO9 #define USBUSART_ISR usart1_isr +#define USBUSART_TIM TIM4 +#define USBUSART_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM4EN) +#define USBUSART_TIM_IRQ NVIC_TIM4_IRQ +#define USBUSART_TIM_ISR tim4_isr #define TRACE_TIM TIM3 #define TRACE_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM3EN) diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index cbfc0ba..09fab96 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -107,6 +107,7 @@ extern usbd_device *usbdev; */ #define IRQ_PRI_USB (2 << 4) #define IRQ_PRI_USBUSART (1 << 4) +#define IRQ_PRI_USBUSART_TIM (3 << 4) #define IRQ_PRI_USB_VBUS (14 << 4) #define IRQ_PRI_TIM3 (0 << 4) @@ -118,6 +119,10 @@ extern usbd_device *usbdev; #define USBUSART_PORT GPIOA #define USBUSART_TX_PIN GPIO2 #define USBUSART_ISR usart2_isr +#define USBUSART_TIM TIM4 +#define USBUSART_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM4EN) +#define USBUSART_TIM_IRQ NVIC_TIM4_IRQ +#define USBUSART_TIM_ISR tim4_isr #define DEBUG(...) diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index 1c71105..6694d90 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,20 @@ #include +#define USBUART_TIMER_FREQ_HZ 1000000U /* 1us per tick */ +#define USBUART_RUN_FREQ_HZ 5000U /* 200us (or 100 characters at 2Mbps) */ + +#define FIFO_SIZE 128 + +/* RX Fifo buffer */ +static uint8_t buf_rx[FIFO_SIZE]; +/* Fifo in pointer, writes assumed to be atomic, should be only incremented within RX ISR */ +static uint8_t buf_rx_in; +/* Fifo out pointer, writes assumed to be atomic, should be only incremented outside RX ISR */ +static uint8_t buf_rx_out; + +static void usbuart_run(void); + void usbuart_init(void) { #if defined(BLACKMAGIC) @@ -56,6 +71,62 @@ void usbuart_init(void) USBUSART_CR1 |= USART_CR1_RXNEIE; nvic_set_priority(USBUSART_IRQ, IRQ_PRI_USBUSART); nvic_enable_irq(USBUSART_IRQ); + + /* Setup timer for running deferred FIFO processing */ + USBUSART_TIM_CLK_EN(); + timer_reset(USBUSART_TIM); + timer_set_mode(USBUSART_TIM, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); + timer_set_prescaler(USBUSART_TIM, rcc_ppre2_frequency/TIMER_FREQ_HZ*2 - 1); + timer_set_period(USBUSART_TIM, TIMER_FREQ_HZ/USBUART_RUN_FREQ_HZ - 1); + + /* Setup update interrupt in NVIC */ + nvic_set_priority(USBUSART_TIM_IRQ, IRQ_PRI_USBUSART_TIM); + nvic_enable_irq(USBUSART_TIM_IRQ); + + /* turn the timer on */ + timer_enable_counter(USBUSART_TIM); +} + +/* + * Runs deferred processing for usb uart rx, draining RX FIFO by sending characters to host PC via CDCACM. + * Allowed to read from FIFO in pointer, but not write to it. Allowed to write to FIFO out pointer. + */ +static void usbuart_run(void) +{ + /* forcibly empty fifo if no USB endpoint */ + if (cdcacm_get_config() != 1) + { + buf_rx_out = buf_rx_in; + } + + /* if fifo empty, nothing further to do */ + if (buf_rx_in == buf_rx_out) { + /* turn off LED, disable IRQ */ + timer_disable_irq(USBUSART_TIM, TIM_DIER_UIE); + gpio_clear(LED_PORT_UART, LED_UART); + } + else + { + uint8_t packet_buf[CDCACM_PACKET_SIZE]; + uint8_t packet_size = 0; + uint8_t buf_out = buf_rx_out; + + /* copy from uart FIFO into local usb packet buffer */ + while (buf_rx_in != buf_out && packet_size < CDCACM_PACKET_SIZE) + { + packet_buf[packet_size++] = buf_rx[buf_out++]; + + /* wrap out pointer */ + if (buf_out >= FIFO_SIZE) + { + buf_out = 0; + } + + } + + /* advance fifo out pointer by amount written */ + buf_rx_out = (buf_rx_out + usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, packet_buf, packet_size)) % FIFO_SIZE; + } } void usbuart_set_line_coding(struct usb_cdc_line_coding *coding) @@ -108,41 +179,48 @@ void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep) gpio_clear(LED_PORT_UART, LED_UART); } -static uint8_t uart_usb_buf[CDCACM_PACKET_SIZE]; -static uint8_t uart_usb_buf_size; void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep) { - if (!uart_usb_buf_size) { - gpio_clear(LED_PORT_UART, LED_UART); - return; - } - - usbd_ep_write_packet(dev, ep, uart_usb_buf, uart_usb_buf_size); - uart_usb_buf_size = 0; + (void) dev; + (void) ep; } +/* + * Read a character from the UART RX and stuff it in a software FIFO. + * Allowed to read from FIFO out pointer, but not write to it. Allowed to write to FIFO in pointer. + */ void USBUSART_ISR(void) { char c = usart_recv(USBUSART); - /* Don't try to write until we are configured. - * Otherwise enumeration hanged in some cases. - */ - if (cdcacm_get_config() != 1) - return; - + /* Turn on LED */ gpio_set(LED_PORT_UART, LED_UART); - /* Try to send now */ - if (usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, &c, 1) == 1) - return; - - /* We failed, so queue for later */ - if (uart_usb_buf_size == CDCACM_PACKET_SIZE) { - /* Drop if the buffer's full: we have no flow control */ - return; + /* If the next increment of rx_in would put it at the same point + * as rx_out, the FIFO is considered full. + */ + if (((buf_rx_in + 1) % FIFO_SIZE) != buf_rx_out) + { + /* insert into FIFO */ + buf_rx[buf_rx_in++] = c; + + /* wrap out pointer */ + if (buf_rx_in >= FIFO_SIZE) + { + buf_rx_in = 0; + } + + /* enable deferred processing if we put data in the FIFO */ + timer_enable_irq(USBUSART_TIM, TIM_DIER_UIE); } +} + +void USBUSART_TIM_ISR(void) +{ + /* need to clear timer update event */ + timer_clear_flag(USBUSART_TIM, TIM_SR_UIF); - uart_usb_buf[uart_usb_buf_size++] = c; + /* process FIFO */ + usbuart_run(); } diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 469499f..c7eaca5 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -106,6 +106,7 @@ extern usbd_device *usbdev; */ #define IRQ_PRI_USB (2 << 4) #define IRQ_PRI_USBUSART (1 << 4) +#define IRQ_PRI_USBUSART_TIM (3 << 4) #define IRQ_PRI_USB_VBUS (14 << 4) #define IRQ_PRI_TRACE (0 << 4) @@ -117,6 +118,10 @@ extern usbd_device *usbdev; #define USBUSART_PORT GPIOB #define USBUSART_TX_PIN GPIO6 #define USBUSART_ISR usart1_isr +#define USBUSART_TIM TIM4 +#define USBUSART_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM4EN) +#define USBUSART_TIM_IRQ NVIC_TIM4_IRQ +#define USBUSART_TIM_ISR tim4_isr #define TRACE_TIM TIM2 #define TRACE_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM2EN) -- 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/platforms/native/platform.h') 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 27a86e244f6dd913b58fd18d40e470ef20810881 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Wed, 19 Jun 2013 19:21:49 +1200 Subject: native: Enable hard SRST signal. --- src/platforms/native/platform.c | 15 ++++++++++++++- src/platforms/native/platform.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index d6eb50c..f5b9135 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -82,7 +82,6 @@ int platform_init(void) gpio_set_mode(JTAG_PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN | TCK_PIN | TDI_PIN); - /* This needs some fixing... */ /* Toggle required to sort out line drivers... */ gpio_port_write(GPIOA, 0x8100); @@ -99,6 +98,11 @@ int platform_init(void) * to release the device from reset if this floats. */ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO7); + /* Enable SRST output */ + gpio_set_val(SRST_PORT, SRST_PIN, platform_hwversion() > 0); + gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, + SRST_PIN); /* Setup heartbeat timer */ systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); @@ -127,6 +131,15 @@ int platform_init(void) return 0; } +void platform_srst_set_val(bool assert) +{ + if (platform_hwversion() == 0) { + gpio_set_val(SRST_PORT, SRST_PIN, assert); + } else { + gpio_set_val(SRST_PORT, SRST_PIN, !assert); + } +} + void platform_delay(uint32_t delay) { timeout_counter = delay; diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index fa9fc79..fd456d8 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -113,6 +113,9 @@ extern usbd_device *usbdev; gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); +#define SRST_SET_VAL(x) \ + platform_srst_set_val(x) + #define USB_DRIVER stm32f103_usb_driver #define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ #define USB_ISR usb_lp_can_rx0_isr -- cgit v1.2.3 From 700833f38f72137bee78a51608ecbd2a9bb5cbd2 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Mon, 19 Aug 2013 12:27:36 +1200 Subject: Use do {...} while(0) for PLATFORM_FATAL_ERROR() macro. --- src/platforms/native/platform.h | 4 ++-- src/platforms/stlink/platform.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index fd456d8..37104d6 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -163,14 +163,14 @@ extern const char *morse_msg; #define SET_ERROR_STATE(state) {gpio_set_val(LED_PORT, LED_ERROR, state);} #define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) { \ +#define PLATFORM_FATAL_ERROR(error) do { \ if(running_status) gdb_putpacketz("X1D"); \ else gdb_putpacketz("EFF"); \ running_status = 0; \ target_list_free(); \ morse("TARGET LOST.", 1); \ longjmp(fatal_error_jmpbuf, (error)); \ -} +} while (0) int platform_init(void); void morse(const char *msg, char repeat); diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index 029eb0a..bee8879 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -147,13 +147,13 @@ extern uint16_t led_idle_run; #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, led_idle_run, state);} #define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) { \ +#define PLATFORM_FATAL_ERROR(error) do { \ if(running_status) gdb_putpacketz("X1D"); \ else gdb_putpacketz("EFF"); \ running_status = 0; \ target_list_free(); \ longjmp(fatal_error_jmpbuf, (error)); \ -} +} while (0) int platform_init(void); void morse(const char *msg, char repeat); -- cgit v1.2.3 From c28350f24234cdfe4aefdc14c77004919e7c2e3d Mon Sep 17 00:00:00 2001 From: BuFran Date: Mon, 29 Jul 2013 21:12:19 +0200 Subject: FIX: u{8,16,32} -> uint{8,16,32}_t to be compatible with new library The use of u8, u16, u32 has been deprecated in libopencm3. Update it with standard uint8_t, uint16_t, uint32_t types --- src/platforms/f4discovery/platform.h | 8 ++++---- src/platforms/native/platform.c | 6 +++--- src/platforms/native/platform.h | 8 ++++---- src/platforms/stlink/platform.h | 8 ++++---- src/platforms/stm32/cdcacm.c | 2 +- src/platforms/stm32/dfu_f1.c | 6 +++--- src/platforms/stm32/dfu_f4.c | 14 +++++++------- src/platforms/stm32/dfucore.c | 30 +++++++++++++++--------------- src/platforms/swlink/platform.h | 8 ++++---- 9 files changed, 45 insertions(+), 45 deletions(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 0010ec4..e50b6c7 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -190,23 +190,23 @@ void uart_usb_buf_drain(uint8_t ep); #define vasprintf vasiprintf #ifdef INLINE_GPIO -static inline void _gpio_set(u32 gpioport, u16 gpios) +static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) { GPIO_BSRR(gpioport) = gpios; GPIO_BSRR(gpioport) = gpios; } #define gpio_set _gpio_set -static inline void _gpio_clear(u32 gpioport, u16 gpios) +static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios) { GPIO_BSRR(gpioport) = gpios<<16; GPIO_BSRR(gpioport) = gpios<<16; } #define gpio_clear _gpio_clear -static inline u16 _gpio_get(u32 gpioport, u16 gpios) +static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) { - return (u16)GPIO_IDR(gpioport) & gpios; + return (uint16_t)GPIO_IDR(gpioport) & gpios; } #define gpio_get _gpio_get #endif diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index f5b9135..3228fff 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -263,15 +263,15 @@ const char *platform_target_voltage(void) return gpio_get(GPIOB, GPIO0) ? "OK" : "ABSENT!"; static char ret[] = "0.0V"; - const u8 channel = 8; - adc_set_regular_sequence(ADC1, 1, (u8*)&channel); + const uint8_t channel = 8; + adc_set_regular_sequence(ADC1, 1, (uint8_t*)&channel); adc_start_conversion_direct(ADC1); /* Wait for end of conversion. */ while (!adc_eoc(ADC1)); - u32 val = adc_read_regular(ADC1) * 99; /* 0-4095 */ + uint32_t val = adc_read_regular(ADC1) * 99; /* 0-4095 */ ret[0] = '0' + val / 81910; ret[2] = '0' + (val / 8191) % 10; diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 37104d6..77382dc 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -193,21 +193,21 @@ void uart_usb_buf_drain(uint8_t ep); #define vasprintf vasiprintf #ifdef INLINE_GPIO -static inline void _gpio_set(u32 gpioport, u16 gpios) +static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) { GPIO_BSRR(gpioport) = gpios; } #define gpio_set _gpio_set -static inline void _gpio_clear(u32 gpioport, u16 gpios) +static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios) { GPIO_BRR(gpioport) = gpios; } #define gpio_clear _gpio_clear -static inline u16 _gpio_get(u32 gpioport, u16 gpios) +static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) { - return (u16)GPIO_IDR(gpioport) & gpios; + return (uint16_t)GPIO_IDR(gpioport) & gpios; } #define gpio_get _gpio_get #endif diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index bee8879..c79ea13 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -176,21 +176,21 @@ void uart_usb_buf_drain(uint8_t ep); #define vasprintf vasiprintf #ifdef INLINE_GPIO -static inline void _gpio_set(u32 gpioport, u16 gpios) +static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) { GPIO_BSRR(gpioport) = gpios; } #define gpio_set _gpio_set -static inline void _gpio_clear(u32 gpioport, u16 gpios) +static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios) { GPIO_BRR(gpioport) = gpios; } #define gpio_clear _gpio_clear -static inline u16 _gpio_get(u32 gpioport, u16 gpios) +static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) { - return (u16)GPIO_IDR(gpioport) & gpios; + return (uint16_t)GPIO_IDR(gpioport) & gpios; } #define gpio_get _gpio_get #endif diff --git a/src/platforms/stm32/cdcacm.c b/src/platforms/stm32/cdcacm.c index 93b0f33..edd20d7 100644 --- a/src/platforms/stm32/cdcacm.c +++ b/src/platforms/stm32/cdcacm.c @@ -480,7 +480,7 @@ int cdcacm_get_dtr(void) return cdcacm_gdb_dtr; } -static void cdcacm_set_config(usbd_device *dev, u16 wValue) +static void cdcacm_set_config(usbd_device *dev, uint16_t wValue) { configured = wValue; diff --git a/src/platforms/stm32/dfu_f1.c b/src/platforms/stm32/dfu_f1.c index 827712d..08cbb02 100644 --- a/src/platforms/stm32/dfu_f1.c +++ b/src/platforms/stm32/dfu_f1.c @@ -48,7 +48,7 @@ void dfu_flash_program_buffer(uint32_t baseaddr, void *buf, int len) { for(int i = 0; i < len; i += 2) flash_program_half_word(baseaddr + i, - *(u16*)(buf+i)); + *(uint16_t*)(buf+i)); } uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum) @@ -77,12 +77,12 @@ void dfu_protect_enable(void) void dfu_jump_app_if_valid(void) { /* Boot the application if it's valid */ - if((*(volatile u32*)APP_ADDRESS & 0x2FFE0000) == 0x20000000) { + if((*(volatile uint32_t*)APP_ADDRESS & 0x2FFE0000) == 0x20000000) { /* Set vector table base address */ SCB_VTOR = APP_ADDRESS & 0x1FFFFF; /* Max 2 MByte Flash*/ /* Initialise master stack pointer */ asm volatile ("msr msp, %0"::"g" - (*(volatile u32*)APP_ADDRESS)); + (*(volatile uint32_t*)APP_ADDRESS)); /* Jump to application */ (*(void(**)())(APP_ADDRESS + 4))(); } diff --git a/src/platforms/stm32/dfu_f4.c b/src/platforms/stm32/dfu_f4.c index 960ec23..1421b19 100644 --- a/src/platforms/stm32/dfu_f4.c +++ b/src/platforms/stm32/dfu_f4.c @@ -26,17 +26,17 @@ #include "usbdfu.h" -static u32 sector_addr[] = {0x8000000, 0x8004000, 0x8008000, 0x800c000, +static uint32_t sector_addr[] = {0x8000000, 0x8004000, 0x8008000, 0x800c000, 0x8010000, 0x8020000, 0x8040000, 0x8060000, 0x8080000, 0x80a0000, 0x80c0000, 0x80e0000, 0x8100000, 0}; -static u16 sector_erase_time[12]= {500, 500, 500, 500, +static uint16_t sector_erase_time[12]= {500, 500, 500, 500, 1100, 2600, 2600, 2600, 2600, 2600, 2600, 2600}; -static u8 sector_num = 0xff; +static uint8_t sector_num = 0xff; /* Find the sector number for a given address*/ -static void get_sector_num(u32 addr) +static void get_sector_num(uint32_t addr) { int i = 0; while(sector_addr[i+1]) { @@ -60,7 +60,7 @@ void dfu_flash_program_buffer(uint32_t baseaddr, void *buf, int len) { for(int i = 0; i < len; i += 4) flash_program_word(baseaddr + i, - *(u32*)(buf+i), + *(uint32_t*)(buf+i), FLASH_PROGRAM_X32); } @@ -93,12 +93,12 @@ void dfu_jump_app_if_valid(void) /* Boot the application if it's valid */ /* Vector table may be anywhere in 128 kByte RAM CCM not handled*/ - if((*(volatile u32*)APP_ADDRESS & 0x2FFC0000) == 0x20000000) { + if((*(volatile uint32_t*)APP_ADDRESS & 0x2FFC0000) == 0x20000000) { /* Set vector table base address */ SCB_VTOR = APP_ADDRESS & 0x1FFFFF; /* Max 2 MByte Flash*/ /* Initialise master stack pointer */ asm volatile ("msr msp, %0"::"g" - (*(volatile u32*)APP_ADDRESS)); + (*(volatile uint32_t*)APP_ADDRESS)); /* Jump to application */ (*(void(**)())(APP_ADDRESS + 4))(); } diff --git a/src/platforms/stm32/dfucore.c b/src/platforms/stm32/dfucore.c index 2786e9a..834c0ad 100644 --- a/src/platforms/stm32/dfucore.c +++ b/src/platforms/stm32/dfucore.c @@ -34,19 +34,19 @@ usbd_device *usbdev; /* We need a special large control buffer for this device: */ -u8 usbd_control_buffer[1024]; +uint8_t usbd_control_buffer[1024]; -static u32 max_address; +static uint32_t max_address; static enum dfu_state usbdfu_state = STATE_DFU_IDLE; static char *get_dev_unique_id(char *serial_no); static struct { - u8 buf[sizeof(usbd_control_buffer)]; - u16 len; - u32 addr; - u16 blocknum; + uint8_t buf[sizeof(usbd_control_buffer)]; + uint16_t len; + uint32_t addr; + uint16_t blocknum; } prog; const struct usb_device_descriptor dev = { @@ -121,13 +121,13 @@ static const char *usb_strings[] = { DFU_IFACE_STRING, }; -static u32 get_le32(const void *vp) +static uint32_t get_le32(const void *vp) { - const u8 *p = vp; - return ((u32)p[3] << 24) + ((u32)p[2] << 16) + (p[1] << 8) + p[0]; + const uint8_t *p = vp; + return ((uint32_t)p[3] << 24) + ((uint32_t)p[2] << 16) + (p[1] << 8) + p[0]; } -static u8 usbdfu_getstatus(u32 *bwPollTimeout) +static uint8_t usbdfu_getstatus(uint32_t *bwPollTimeout) { switch(usbdfu_state) { case STATE_DFU_DNLOAD_SYNC: @@ -157,7 +157,7 @@ usbdfu_getstatus_complete(usbd_device *dev, struct usb_setup_data *req) flash_unlock(); if(prog.blocknum == 0) { - u32 addr = get_le32(prog.buf + 1); + uint32_t addr = get_le32(prog.buf + 1); if (addr < APP_ADDRESS || (addr >= max_address)) { flash_lock(); @@ -171,7 +171,7 @@ usbdfu_getstatus_complete(usbd_device *dev, struct usb_setup_data *req) prog.addr = addr; } } else { - u32 baseaddr = prog.addr + + uint32_t baseaddr = prog.addr + ((prog.blocknum - 2) * dfu_function.wTransferSize); dfu_flash_program_buffer(baseaddr, prog.buf, prog.len); @@ -193,7 +193,7 @@ usbdfu_getstatus_complete(usbd_device *dev, struct usb_setup_data *req) } static int usbdfu_control_request(usbd_device *dev, - struct usb_setup_data *req, u8 **buf, u16 *len, + struct usb_setup_data *req, uint8_t **buf, uint16_t *len, void (**complete)(usbd_device *dev, struct usb_setup_data *req)) { (void)dev; @@ -227,7 +227,7 @@ static int usbdfu_control_request(usbd_device *dev, /* Upload not supported for now */ return 0; case DFU_GETSTATUS: { - u32 bwPollTimeout = 0; /* 24-bit integer in DFU class spec */ + uint32_t bwPollTimeout = 0; /* 24-bit integer in DFU class spec */ (*buf)[0] = usbdfu_getstatus(&bwPollTimeout); (*buf)[1] = bwPollTimeout & 0xFF; @@ -292,7 +292,7 @@ static char *get_dev_unique_id(char *s) /* Calculated the upper flash limit from the exported data in theparameter block*/ - max_address = (*(u32 *) FLASH_SIZE_R) <<10; + max_address = (*(uint32_t *) FLASH_SIZE_R) <<10; /* Fetch serial number from chip's unique ID */ for(i = 0; i < 8; i++) { s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 7d36326..614a389 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -174,21 +174,21 @@ void uart_usb_buf_drain(uint8_t ep); #define vasprintf vasiprintf #ifdef INLINE_GPIO -static inline void _gpio_set(u32 gpioport, u16 gpios) +static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) { GPIO_BSRR(gpioport) = gpios; } #define gpio_set _gpio_set -static inline void _gpio_clear(u32 gpioport, u16 gpios) +static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios) { GPIO_BRR(gpioport) = gpios; } #define gpio_clear _gpio_clear -static inline u16 _gpio_get(u32 gpioport, u16 gpios) +static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) { - return (u16)GPIO_IDR(gpioport) & gpios; + return (uint16_t)GPIO_IDR(gpioport) & gpios; } #define gpio_get _gpio_get #endif -- cgit v1.2.3 From 40820a2354bd76b86e429dbd9f213375dfe05af4 Mon Sep 17 00:00:00 2001 From: Marc Singer Date: Fri, 6 Sep 2013 21:19:37 -0700 Subject: Added internal pull-up to PWR_BR. o Prevent probe from inadvertently powering target. If PWR_BR is allowed to float, the gate on Q1 (blackmagic_mini) will tend to be close enough to zero to turn the transistor on. We activate the internal pull-up on this IO pin to force the transistor off. --- src/platforms/native/platform.c | 9 +++++++++ src/platforms/native/platform.h | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 3228fff..44a5793 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -104,6 +104,15 @@ int platform_init(void) GPIO_CNF_OUTPUT_PUSHPULL, SRST_PIN); + /* Enable internal pull-up on PWR_BR so that we don't drive + TPWR locally or inadvertently supply power to the target. */ + if (platform_hwversion () > 0) { + gpio_set (PWR_BR_PORT, PWR_BR_PIN); + gpio_set_mode(PWR_BR_PORT, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_PULL_UPDOWN, + PWR_BR_PIN); + } + /* Setup heartbeat timer */ systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); systick_set_reload(900000); /* Interrupt us at 10 Hz */ diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 77382dc..40dd620 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -51,7 +51,8 @@ extern usbd_device *usbdev; * LED2 = PB11 (Red LED : Error) * * TPWR = RB0 (input) -- analogue on mini design ADC1, ch8 - * nTRST = PB1 + * nTRST = PB1 [blackmagic] + * PWR_BR = PB1 [blackmagic_mini] -- supply power to the target, active low * SRST_OUT = PA2 * TDI = PA3 * TMS = PA4 (input for SWDP) @@ -83,6 +84,8 @@ extern usbd_device *usbdev; #define TRST_PORT GPIOB #define TRST_PIN GPIO1 +#define PWR_BR_PORT GPIOB +#define PWR_BR_PIN GPIO1 #define SRST_PORT GPIOA #define SRST_PIN GPIO2 -- cgit v1.2.3 From c395c6f73a220cd6da26ff3b48afde8487b6199f Mon Sep 17 00:00:00 2001 From: Michael Tharp Date: Fri, 4 Oct 2013 21:24:53 -0400 Subject: Configure SRST output as open-drain for BMP Mini hardware --- src/platforms/native/platform.c | 11 ++++++++--- src/platforms/native/platform.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 44a5793..640ba58 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -98,10 +98,15 @@ int platform_init(void) * to release the device from reset if this floats. */ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO7); - /* Enable SRST output */ - gpio_set_val(SRST_PORT, SRST_PIN, platform_hwversion() > 0); + /* Enable SRST output. Original uses a NPN to pull down, so setting the + * output HIGH asserts. Mini is directly connected so use open drain output + * and set LOW to assert. + */ + platform_srst_set_val(false); gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, + (platform_hwversion() == 0 + ? GPIO_CNF_OUTPUT_PUSHPULL + : GPIO_CNF_OUTPUT_OPENDRAIN), SRST_PIN); /* Enable internal pull-up on PWR_BR so that we don't drive diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 40dd620..20d1510 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -220,3 +220,4 @@ static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) #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); -- cgit v1.2.3 From 0c9d5d816639c2b4ebce2b234be52e6aac4275a7 Mon Sep 17 00:00:00 2001 From: bon@elektron.ikp.physik.tu-darmstadt.de Date: Mon, 6 Jan 2014 12:51:09 +0100 Subject: Add dfu bootloader update application and use absolute delay for stlink Hello, appended 3 patches - adds a dfu-bootloader appliaction - uses absolute delays when waiting for pull-up delays on the STLINK (hopefully fixes issue #30) Updating the dfu-bootloader by additional application is helpfull for the STLINK, as for flashing the bootloader by SWDb otherwise jumpers need to be soldered or external SWD is not possible. Use like: - dfu-util -s 0x08002000:leave -D dfu_upgrade.bin - dfu-util -s 0x08000000:leave -D blackmagic_dfu.bin - Push reset buttom and reconnect to enter new dfu bootloader - dfu-util -s 0x08002000:leave -D blackmagic.bin -- Uwe Bonnes bon@elektron.ikp.physik.tu-darmstadt.de Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt --------- Tel. 06151 162516 -------- Fax. 06151 164321 ---------- >From fae5022c304a8866f056ea66660ac7ce3809dcf8 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sun, 20 Oct 2013 15:00:36 +0200 Subject: F1: Prepare to update dfu bootloader via DFU with additional application. --- .gitignore | 6 +- src/platforms/native/platform.h | 2 + src/platforms/native/usbdfu.c | 6 +- src/platforms/stlink/Makefile.inc | 13 +++- src/platforms/stlink/dfu_upgrade.c | 127 +++++++++++++++++++++++++++++++++++++ src/platforms/stlink/platform.h | 2 + src/platforms/stlink/usbdfu.c | 33 ++++++---- src/platforms/stm32/dfu_f1.c | 17 +++-- src/platforms/stm32/dfucore.c | 17 +++-- src/platforms/stm32/usbdfu.h | 16 ++--- src/platforms/swlink/platform.h | 2 + src/platforms/swlink/usbdfu.c | 6 +- 12 files changed, 209 insertions(+), 38 deletions(-) create mode 100644 src/platforms/stlink/dfu_upgrade.c (limited to 'src/platforms/native/platform.h') diff --git a/.gitignore b/.gitignore index 92e1e57..82a3e84 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ blackmagic -blackmagic.bin +*.bin +*.hex blackmagic_dfu -blackmagic_dfu.bin -blackmagic_dfu.hex +dfu_upgrade mapfile *.o *.d diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 62d565b..a1a28cf 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -37,8 +37,10 @@ #define PLATFORM_HAS_TRACESWO #define BOARD_IDENT "Black Magic Probe" #define BOARD_IDENT_DFU "Black Magic Probe (Upgrade)" +#define BOARD_IDENT_UPD "Black Magic Probe (DFU Upgrade)" #define DFU_IDENT "Black Magic Firmware Upgrade" #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,120*001Kg" +#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" extern usbd_device *usbdev; #define CDCACM_GDB_ENDPOINT 1 diff --git a/src/platforms/native/usbdfu.c b/src/platforms/native/usbdfu.c index 068138e..e9094a3 100644 --- a/src/platforms/native/usbdfu.c +++ b/src/platforms/native/usbdfu.c @@ -25,6 +25,8 @@ #include "usbdfu.h" +uint32_t app_address = 0x08002000; + void dfu_detach(void) { /* USB device must detach, we just reset... */ @@ -38,7 +40,7 @@ int main(void) if(gpio_get(GPIOB, GPIO12)) dfu_jump_app_if_valid(); - dfu_protect_enable(); + dfu_protect(DFU_MODE); rcc_clock_setup_in_hse_8mhz_out_72mhz(); systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); @@ -56,7 +58,7 @@ int main(void) gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO2 | GPIO10); - dfu_init(&stm32f103_usb_driver); + dfu_init(&stm32f103_usb_driver, DFU_MODE); gpio_set(GPIOA, GPIO8); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, diff --git a/src/platforms/stlink/Makefile.inc b/src/platforms/stlink/Makefile.inc index 1f46588..5cfe726 100644 --- a/src/platforms/stlink/Makefile.inc +++ b/src/platforms/stlink/Makefile.inc @@ -18,7 +18,7 @@ SRC += cdcacm.c \ platform.c \ usbuart.c \ -all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex +all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex dfu_upgrade.bin dfu_upgrade.hex blackmagic.bin: blackmagic $(OBJCOPY) -O binary $^ $@ @@ -32,6 +32,15 @@ blackmagic_dfu.bin: blackmagic_dfu blackmagic_dfu.hex: blackmagic_dfu $(OBJCOPY) -O ihex $^ $@ +dfu_upgrade: dfu_upgrade.o dfucore.o dfu_f1.o + $(CC) $^ -o $@ $(LDFLAGS) + +dfu_upgrade.bin: dfu_upgrade + $(OBJCOPY) -O binary $^ $@ + +dfu_upgrade.hex: dfu_upgrade + $(OBJCOPY) -O ihex $^ $@ + host_clean: - -rm blackmagic.bin blackmagic_dfu blackmagic_dfu.bin blackmagic_dfu.hex + -rm blackmagic.bin blackmagic_dfu blackmagic_dfu.bin blackmagic_dfu.hex dfu_upgrade dfu_upgrade.bin dfu_upgrade.hex diff --git a/src/platforms/stlink/dfu_upgrade.c b/src/platforms/stlink/dfu_upgrade.c new file mode 100644 index 0000000..2c7c1ad --- /dev/null +++ b/src/platforms/stlink/dfu_upgrade.c @@ -0,0 +1,127 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2013 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 +#include +#include +#include +#include + +#include "usbdfu.h" +uint32_t app_address = 0x08000000; + +static uint8_t rev; +static uint16_t led_idle_run; +static uint32_t led2_state = 0; + +void dfu_detach(void) +{ + /* Disconnect USB cable by resetting USB Device + and pulling USB_DP low*/ + rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); + rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); + rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + gpio_clear(GPIOA, GPIO12); + gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); + /* Pull PB0 (T_NRST) low + */ + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); + gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_OUTPUT_OPENDRAIN, GPIO0); + gpio_clear(GPIOB, GPIO0); + SCB_VTOR = 0; + scb_reset_core(); +} + +void stlink_set_rev(void) +{ + int i; + + /* First, get Board revision by pulling PC13/14 up. Read + * 11 for ST-Link V1, e.g. on VL Discovery, tag as rev 0 + * 10 for ST-Link V2, e.g. on F4 Discovery, tag as rev 1 + */ + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); + gpio_set_mode(GPIOC, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_PULL_UPDOWN, GPIO14 | GPIO13); + gpio_set(GPIOC, GPIO14 | GPIO13); + for (i = 0; i < 100; i++) + rev = (~(gpio_get(GPIOC, GPIO14 | GPIO13)) >> 13) & 3; + + switch (rev) { + case 0: + led_idle_run = GPIO8; + break; + default: + led_idle_run = GPIO9; + } + gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run); +} + +int main(void) +{ + + rcc_clock_setup_in_hse_8mhz_out_72mhz(); + + stlink_set_rev(); + + systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); + systick_set_reload(900000); + + dfu_protect(UPD_MODE); + + /* Handle USB disconnect/connect */ + /* Just in case: Disconnect USB cable by resetting USB Device + * and pulling USB_DP low + * Device will reconnect automatically as Pull-Up is hard wired*/ + rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); + rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); + rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + gpio_clear(GPIOA, GPIO12); + gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); + + systick_interrupt_enable(); + systick_counter_enable(); + + dfu_init(&stm32f103_usb_driver, UPD_MODE); + + dfu_main(); +} + +void sys_tick_handler(void) +{ + if (rev == 0) { + gpio_toggle(GPIOA, led_idle_run); + } else { + if (led2_state & 1) { + gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, + GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run); + gpio_set(GPIOA, led_idle_run); + } else { + gpio_set_mode(GPIOA, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_ANALOG, led_idle_run); + } + led2_state++; + } +} diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index a9e405b..ffe9fbf 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -36,8 +36,10 @@ #define CDCACM_PACKET_SIZE 64 #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 ")" +#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define DFU_IDENT "Black Magic Firmware Upgrade (STLINK)" #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" +#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" extern usbd_device *usbdev; #define CDCACM_GDB_ENDPOINT 1 diff --git a/src/platforms/stlink/usbdfu.c b/src/platforms/stlink/usbdfu.c index c14fd5a..1a40e64 100644 --- a/src/platforms/stlink/usbdfu.c +++ b/src/platforms/stlink/usbdfu.c @@ -29,24 +29,31 @@ static uint8_t rev; static uint16_t led_idle_run; static uint32_t led2_state = 0; +uint32_t app_address = 0x08002000; + static int stlink_test_nrst(void) { /* Test if JRST/NRST is pulled down*/ - int i; uint16_t nrst; uint16_t pin; + uint32_t systick_value; + + systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); + systick_set_reload(0xffffff); /* no underflow for about 16.7 seconds*/ + systick_counter_enable(); + /* systick ist now running with 1 MHz, systick counts down */ /* First, get Board revision by pulling PC13/14 up. Read * 11 for ST-Link V1, e.g. on VL Discovery, tag as rev 0 * 10 for ST-Link V2, e.g. on F4 Discovery, tag as rev 1 */ - for (i = 0; i < 0x200; i++) { - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); - gpio_set_mode(GPIOC, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_PULL_UPDOWN, GPIO14 | GPIO13); - gpio_set(GPIOC, GPIO14 | GPIO13); - rev = (~(gpio_get(GPIOC, GPIO14 | GPIO13)) >> 13) & 3; - } + rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); + gpio_set_mode(GPIOC, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_PULL_UPDOWN, GPIO14 | GPIO13); + gpio_set(GPIOC, GPIO14 | GPIO13); + systick_value = systick_get_value(); + while (systick_get_value() > (systick_value - 1000)); /* Wait 1 msec*/ + rev = (~(gpio_get(GPIOC, GPIO14 | GPIO13)) >> 13) & 3; switch (rev) { case 0: pin = GPIO1; @@ -62,8 +69,10 @@ static int stlink_test_nrst(void) gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, pin); gpio_set(GPIOB, pin); - for (i = 0; i < 100; i++) - nrst = gpio_get(GPIOB, pin); + systick_value = systick_get_value(); + while (systick_get_value() > (systick_value - 20000)); /* Wait 20 msec*/ + nrst = gpio_get(GPIOB, pin); + systick_counter_disable(); return (nrst) ? 1 : 0; } @@ -92,7 +101,7 @@ int main(void) if(((GPIOA_CRL & 0x40) == 0x40) && stlink_test_nrst()) dfu_jump_app_if_valid(); - dfu_protect_enable(); + dfu_protect(DFU_MODE); rcc_clock_setup_in_hse_8mhz_out_72mhz(); systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); @@ -113,7 +122,7 @@ int main(void) systick_interrupt_enable(); systick_counter_enable(); - dfu_init(&stm32f103_usb_driver); + dfu_init(&stm32f103_usb_driver, DFU_MODE); dfu_main(); } diff --git a/src/platforms/stm32/dfu_f1.c b/src/platforms/stm32/dfu_f1.c index 08cbb02..77b6f58 100644 --- a/src/platforms/stm32/dfu_f1.c +++ b/src/platforms/stm32/dfu_f1.c @@ -59,8 +59,9 @@ uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum) return 100; } -void dfu_protect_enable(void) +void dfu_protect(dfu_mode_t mode) { + if (mode == DFU_MODE) { #ifdef DFU_SELF_PROTECT if ((FLASH_WRPR & 0x03) != 0x00) { flash_unlock(); @@ -72,19 +73,25 @@ void dfu_protect_enable(void) flash_program_option_bytes(FLASH_OBP_WRP10, 0x03FC); } #endif + } + else if (mode == UPD_MODE) { + flash_unlock(); + FLASH_CR = 0; + flash_erase_option_bytes(); + } } void dfu_jump_app_if_valid(void) { /* Boot the application if it's valid */ - if((*(volatile uint32_t*)APP_ADDRESS & 0x2FFE0000) == 0x20000000) { + if((*(volatile uint32_t*)app_address & 0x2FFE0000) == 0x20000000) { /* Set vector table base address */ - SCB_VTOR = APP_ADDRESS & 0x1FFFFF; /* Max 2 MByte Flash*/ + SCB_VTOR = app_address & 0x1FFFFF; /* Max 2 MByte Flash*/ /* Initialise master stack pointer */ asm volatile ("msr msp, %0"::"g" - (*(volatile uint32_t*)APP_ADDRESS)); + (*(volatile uint32_t*)app_address)); /* Jump to application */ - (*(void(**)())(APP_ADDRESS + 4))(); + (*(void(**)())(app_address + 4))(); } } diff --git a/src/platforms/stm32/dfucore.c b/src/platforms/stm32/dfucore.c index a01616f..85e5e87 100644 --- a/src/platforms/stm32/dfucore.c +++ b/src/platforms/stm32/dfucore.c @@ -121,6 +121,14 @@ static const char *usb_strings[] = { DFU_IFACE_STRING, }; +static const char *usb_strings_upd[] = { + "Black Sphere Technologies", + BOARD_IDENT_UPD, + serial_no, + /* This string is used by ST Microelectronics' DfuSe utility */ + UPD_IFACE_STRING, +}; + static uint32_t get_le32(const void *vp) { const uint8_t *p = vp; @@ -158,8 +166,8 @@ usbdfu_getstatus_complete(usbd_device *dev, struct usb_setup_data *req) flash_unlock(); if(prog.blocknum == 0) { uint32_t addr = get_le32(prog.buf + 1); - if (addr < APP_ADDRESS || - (addr >= max_address)) { + if (addr < app_address || + (addr >= max_address)) { flash_lock(); usbd_ep_stall_set(dev, 0, 1); return; @@ -251,11 +259,12 @@ static int usbdfu_control_request(usbd_device *dev, return 0; } -void dfu_init(const usbd_driver *driver) +void dfu_init(const usbd_driver *driver, dfu_mode_t mode) { get_dev_unique_id(serial_no); - usbdev = usbd_init(driver, &dev, &config, usb_strings, 4, + usbdev = usbd_init(driver, &dev, &config, + (mode == DFU_MODE)?usb_strings:usb_strings_upd, 4, usbd_control_buffer, sizeof(usbd_control_buffer)); usbd_register_control_callback(usbdev, diff --git a/src/platforms/stm32/usbdfu.h b/src/platforms/stm32/usbdfu.h index d331ca4..e460082 100644 --- a/src/platforms/stm32/usbdfu.h +++ b/src/platforms/stm32/usbdfu.h @@ -19,25 +19,25 @@ #include -#ifdef STM32F4 -# define APP_ADDRESS 0x08010000 -#else -# define APP_ADDRESS 0x08002000 -#endif - /* Commands sent with wBlockNum == 0 as per ST implementation. */ #define CMD_SETADDR 0x21 #define CMD_ERASE 0x41 +extern uint32_t app_address; + +typedef enum { + DFU_MODE = 0, + UPD_MODE = 1 +} dfu_mode_t; /* dfucore.c - DFU core, common to libopencm3 platforms. */ -void dfu_init(const usbd_driver *driver); +void dfu_init(const usbd_driver *driver, dfu_mode_t mode); void dfu_main(void); /* Device specific functions */ void dfu_check_and_do_sector_erase(uint32_t sector); void dfu_flash_program_buffer(uint32_t baseaddr, void *buf, int len); uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum); -void dfu_protect_enable(void); +void dfu_protect(dfu_mode_t mode); void dfu_jump_app_if_valid(void); /* Platform specific function */ diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index d0c9618..90acfb3 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -36,8 +36,10 @@ #define CDCACM_PACKET_SIZE 64 #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 ")" #define DFU_IDENT "Black Magic Firmware Upgrade (SWLINK)" #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" +#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" extern usbd_device *usbdev; #define CDCACM_GDB_ENDPOINT 1 diff --git a/src/platforms/swlink/usbdfu.c b/src/platforms/swlink/usbdfu.c index 69cc1e2..de0b7ab 100644 --- a/src/platforms/swlink/usbdfu.c +++ b/src/platforms/swlink/usbdfu.c @@ -25,6 +25,8 @@ #include "usbdfu.h" +uint32_t app_address = 0x08002000; + void dfu_detach(void) { /* Disconnect USB cable by resetting USB Device @@ -58,7 +60,7 @@ int main(void) if(((GPIOA_CRL & 0x40) == 0x40) && pin_b) dfu_jump_app_if_valid(); - dfu_protect_enable(); + dfu_protect(DFU_MODE); rcc_clock_setup_in_hse_8mhz_out_72mhz(); systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); @@ -83,7 +85,7 @@ int main(void) systick_interrupt_enable(); systick_counter_enable(); - dfu_init(&stm32f103_usb_driver); + dfu_init(&stm32f103_usb_driver, DFU_MODE); dfu_main(); } -- cgit v1.2.3 From 12aeaad441a251e91ecb48528c6446a7461b435a Mon Sep 17 00:00:00 2001 From: Frantisek Burian Date: Thu, 13 Feb 2014 18:21:16 +0100 Subject: [locm3] Use the new clock-enabling mechanisms in locm3. --- src/platforms/f4discovery/platform.h | 7 +++---- src/platforms/native/platform.c | 12 ++++++------ src/platforms/native/platform.h | 7 +++---- src/platforms/native/usbdfu.c | 6 +++--- src/platforms/stlink/dfu_upgrade.c | 18 ++++++++---------- src/platforms/stlink/platform.c | 21 ++++++++++----------- src/platforms/stlink/platform.h | 5 ++--- src/platforms/stlink/usbdfu.c | 20 +++++++++----------- src/platforms/stm32/usbuart.c | 2 +- src/platforms/swlink/platform.c | 19 +++++++++---------- src/platforms/swlink/platform.h | 7 +++---- src/platforms/swlink/usbdfu.c | 18 ++++++++---------- 12 files changed, 65 insertions(+), 77 deletions(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 5523b9c..a777ed2 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -118,15 +118,14 @@ extern usbd_device *usbdev; #define USBUSART USART3 #define USBUSART_CR1 USART3_CR1 #define USBUSART_IRQ NVIC_USART3_IRQ -#define USBUSART_APB_ENR RCC_APB1ENR -#define USBUSART_CLK_ENABLE RCC_APB1ENR_USART3EN +#define USBUSART_CLK RCC_USART3 #define USBUSART_TX_PORT GPIOD #define USBUSART_TX_PIN GPIO8 #define USBUSART_RX_PORT GPIOD #define USBUSART_RX_PIN GPIO9 #define USBUSART_ISR usart3_isr #define USBUSART_TIM TIM4 -#define USBUSART_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM4EN) +#define USBUSART_TIM_CLK_EN() rcc_periph_clock_enable(RCC_TIM4) #define USBUSART_TIM_IRQ NVIC_TIM4_IRQ #define USBUSART_TIM_ISR tim4_isr @@ -140,7 +139,7 @@ extern usbd_device *usbdev; } while(0) #define TRACE_TIM TIM3 -#define TRACE_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM3EN) +#define TRACE_TIM_CLK_EN() rcc_periph_clock_enable(RCC_TIM3) #define TRACE_IRQ NVIC_TIM3_IRQ #define TRACE_ISR tim3_isr diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index c0ce658..d6ca992 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -68,11 +68,11 @@ int platform_init(void) rcc_clock_setup_in_hse_8mhz_out_72mhz(); /* Enable peripherals */ - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_CRCEN); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); + rcc_periph_clock_enable(RCC_GPIOB); + rcc_periph_clock_enable(RCC_AFIO); + rcc_periph_clock_enable(RCC_CRC); /* Setup GPIO ports */ gpio_clear(USB_PU_PORT, USB_PU_PIN); @@ -248,7 +248,7 @@ static void morse_update(void) static void adc_init(void) { - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN); + rcc_periph_clock_enable(RCC_ADC1); gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO0); diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index a1a28cf..2916e64 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -137,18 +137,17 @@ extern usbd_device *usbdev; #define USBUSART USART1 #define USBUSART_CR1 USART1_CR1 #define USBUSART_IRQ NVIC_USART1_IRQ -#define USBUSART_APB_ENR RCC_APB2ENR -#define USBUSART_CLK_ENABLE RCC_APB2ENR_USART1EN +#define USBUSART_CLK RCC_USART1 #define USBUSART_PORT GPIOA #define USBUSART_TX_PIN GPIO9 #define USBUSART_ISR usart1_isr #define USBUSART_TIM TIM4 -#define USBUSART_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM4EN) +#define USBUSART_TIM_CLK_EN() rcc_periph_clock_enable(RCC_TIM4) #define USBUSART_TIM_IRQ NVIC_TIM4_IRQ #define USBUSART_TIM_ISR tim4_isr #define TRACE_TIM TIM3 -#define TRACE_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM3EN) +#define TRACE_TIM_CLK_EN() rcc_periph_clock_enable(RCC_TIM3) #define TRACE_IRQ NVIC_TIM3_IRQ #define TRACE_ISR tim3_isr diff --git a/src/platforms/native/usbdfu.c b/src/platforms/native/usbdfu.c index e9094a3..3aac079 100644 --- a/src/platforms/native/usbdfu.c +++ b/src/platforms/native/usbdfu.c @@ -36,7 +36,7 @@ void dfu_detach(void) int main(void) { /* Check the force bootloader pin*/ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); + rcc_periph_clock_enable(RCC_GPIOB); if(gpio_get(GPIOB, GPIO12)) dfu_jump_app_if_valid(); @@ -46,8 +46,8 @@ int main(void) systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); systick_set_reload(900000); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); + rcc_periph_clock_enable(RCC_GPIOA); + rcc_periph_clock_enable(RCC_USB); gpio_set_mode(GPIOA, GPIO_MODE_INPUT, 0, GPIO8); systick_interrupt_enable(); diff --git a/src/platforms/stlink/dfu_upgrade.c b/src/platforms/stlink/dfu_upgrade.c index 8d954ca..b15117b 100644 --- a/src/platforms/stlink/dfu_upgrade.c +++ b/src/platforms/stlink/dfu_upgrade.c @@ -34,16 +34,15 @@ void dfu_detach(void) { /* Disconnect USB cable by resetting USB Device and pulling USB_DP low*/ - rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_reset_pulse(RST_USB); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); /* Pull PB0 (T_NRST) low */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); + rcc_periph_clock_enable(RCC_GPIOB); gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO0); gpio_clear(GPIOB, GPIO0); @@ -59,7 +58,7 @@ void stlink_set_rev(void) * 11 for ST-Link V1, e.g. on VL Discovery, tag as rev 0 * 10 for ST-Link V2, e.g. on F4 Discovery, tag as rev 1 */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); + rcc_periph_clock_enable(RCC_GPIOC); gpio_set_mode(GPIOC, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO14 | GPIO13); gpio_set(GPIOC, GPIO14 | GPIO13); @@ -93,10 +92,9 @@ int main(void) /* Just in case: Disconnect USB cable by resetting USB Device * and pulling USB_DP low * Device will reconnect automatically as Pull-Up is hard wired*/ - rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_reset_pulse(RST_USB); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index d7ae41d..ec8c000 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -74,12 +74,12 @@ int platform_init(void) rcc_clock_setup_in_hse_8mhz_out_72mhz(); /* Enable peripherals */ - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_CRCEN); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); + rcc_periph_clock_enable(RCC_GPIOB); + rcc_periph_clock_enable(RCC_GPIOC); + rcc_periph_clock_enable(RCC_AFIO); + rcc_periph_clock_enable(RCC_CRC); /* On Rev 1 unconditionally activate MCO on PORTA8 with HSE * platform_hwversion() also needed to initialize led_idle_run! @@ -167,10 +167,9 @@ const char *platform_target_voltage(void) void disconnect_usb(void) { /* Disconnect USB cable by resetting USB Device and pulling USB_DP low*/ - rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_reset_pulse(RST_USB); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); @@ -179,7 +178,7 @@ void disconnect_usb(void) void assert_boot_pin(void) { uint32_t crl = GPIOA_CRL; - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_clock_enable(RCC_GPIOA); /* Enable Pull on GPIOA1. We don't rely on the external pin * really pulled, but only on the value of the CNF register * changed from the reset value diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index ffe9fbf..6268a0e 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -123,13 +123,12 @@ extern usbd_device *usbdev; #define USBUSART USART2 #define USBUSART_CR1 USART2_CR1 #define USBUSART_IRQ NVIC_USART2_IRQ -#define USBUSART_APB_ENR RCC_APB1ENR -#define USBUSART_CLK_ENABLE RCC_APB1ENR_USART2EN +#define USBUSART_CLK RCC_USART2 #define USBUSART_PORT GPIOA #define USBUSART_TX_PIN GPIO2 #define USBUSART_ISR usart2_isr #define USBUSART_TIM TIM4 -#define USBUSART_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM4EN) +#define USBUSART_TIM_CLK_EN() rcc_periph_clock_enable(RCC_TIM4) #define USBUSART_TIM_IRQ NVIC_TIM4_IRQ #define USBUSART_TIM_ISR tim4_isr diff --git a/src/platforms/stlink/usbdfu.c b/src/platforms/stlink/usbdfu.c index 3c2b8be..843033b 100644 --- a/src/platforms/stlink/usbdfu.c +++ b/src/platforms/stlink/usbdfu.c @@ -47,7 +47,7 @@ static int stlink_test_nrst(void) * 11 for ST-Link V1, e.g. on VL Discovery, tag as rev 0 * 10 for ST-Link V2, e.g. on F4 Discovery, tag as rev 1 */ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN); + rcc_periph_clock_enable(RCC_GPIOC); gpio_set_mode(GPIOC, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO14 | GPIO13); gpio_set(GPIOC, GPIO14 | GPIO13); @@ -65,7 +65,7 @@ static int stlink_test_nrst(void) } gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); + rcc_periph_clock_enable(RCC_GPIOB); gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, pin); gpio_set(GPIOB, pin); @@ -80,10 +80,9 @@ void dfu_detach(void) { /* Disconnect USB cable by resetting USB Device and pulling USB_DP low*/ - rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_reset_pulse(RST_USB); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); @@ -93,7 +92,7 @@ void dfu_detach(void) int main(void) { /* Check the force bootloader pin*/ - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_clock_enable(RCC_GPIOA); /* Check value of GPIOA1 configuration. This pin is unconnected on * STLink V1 and V2. If we have a value other than the reset value (0x4), * we have a warm start and request Bootloader entry @@ -111,10 +110,9 @@ int main(void) /* Just in case: Disconnect USB cable by resetting USB Device * and pulling USB_DP low * Device will reconnect automatically as Pull-Up is hard wired*/ - rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_reset_pulse(RST_USB); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index 7f5ebde..95371dd 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -52,7 +52,7 @@ void usbuart_init(void) return; #endif - rcc_peripheral_enable_clock(&USBUSART_APB_ENR, USBUSART_CLK_ENABLE); + rcc_periph_clock_enable(USBUSART_CLK); UART_PIN_SETUP(); diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index ea88dcb..28db60f 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -47,11 +47,11 @@ int platform_init(void) rcc_clock_setup_in_hse_8mhz_out_72mhz(); /* Enable peripherals */ - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_AFIOEN); - rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_CRCEN); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); + rcc_periph_clock_enable(RCC_GPIOB); + rcc_periph_clock_enable(RCC_AFIO); + rcc_periph_clock_enable(RCC_CRC); /* Unmap JTAG Pins so we can reuse as GPIO */ data = AFIO_MAPR; @@ -135,10 +135,9 @@ const char *platform_target_voltage(void) void disconnect_usb(void) { /* Disconnect USB cable by resetting USB Device and pulling USB_DP low*/ - rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_reset_pulse(RST_USB); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); @@ -147,7 +146,7 @@ void disconnect_usb(void) void assert_boot_pin(void) { uint32_t crl = GPIOA_CRL; - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_clock_enable(RCC_GPIOA); /* Enable Pull on GPIOA1. We don't rely on the external pin * really pulled, but only on the value of the CNF register * changed from the reset value diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 90acfb3..dd2ac8a 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -115,18 +115,17 @@ extern usbd_device *usbdev; #define USBUSART USART1 #define USBUSART_CR1 USART1_CR1 #define USBUSART_IRQ NVIC_USART1_IRQ -#define USBUSART_APB_ENR RCC_APB2ENR -#define USBUSART_CLK_ENABLE RCC_APB2ENR_USART1EN +#define USBUSART_CLK RCC_USART1 #define USBUSART_PORT GPIOB #define USBUSART_TX_PIN GPIO6 #define USBUSART_ISR usart1_isr #define USBUSART_TIM TIM4 -#define USBUSART_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM4EN) +#define USBUSART_TIM_CLK_EN() rcc_periph_clock_enable(RCC_TIM4) #define USBUSART_TIM_IRQ NVIC_TIM4_IRQ #define USBUSART_TIM_ISR tim4_isr #define TRACE_TIM TIM2 -#define TRACE_TIM_CLK_EN() rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_TIM2EN) +#define TRACE_TIM_CLK_EN() rcc_periph_clock_enable(RCC_TIM2) #define TRACE_IRQ NVIC_TIM2_IRQ #define TRACE_ISR tim2_isr #define TRACE_IC_IN TIM_IC_IN_TI2 diff --git a/src/platforms/swlink/usbdfu.c b/src/platforms/swlink/usbdfu.c index de0b7ab..f87ccf4 100644 --- a/src/platforms/swlink/usbdfu.c +++ b/src/platforms/swlink/usbdfu.c @@ -31,10 +31,9 @@ void dfu_detach(void) { /* Disconnect USB cable by resetting USB Device and pulling USB_DP low*/ - rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_reset_pulse(RST_USB); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); @@ -45,8 +44,8 @@ int main(void) { /* Check the force bootloader pin*/ uint16_t pin_b; - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPBEN); + rcc_periph_clock_enable(RCC_GPIOA); + rcc_periph_clock_enable(RCC_GPIOB); /* Switch PB5 (SWIM_RST_IN) up */ gpio_set(GPIOB, GPIO5); gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, @@ -70,10 +69,9 @@ int main(void) /* Just in case: Disconnect USB cable by resetting USB Device * and pulling USB_DP low * Device will reconnect automatically as Pull-Up is hard wired*/ - rcc_peripheral_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_clear_reset(&RCC_APB1RSTR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB1ENR, RCC_APB1ENR_USBEN); - rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN); + rcc_periph_reset_pulse(RST_USB); + rcc_periph_clock_enable(RCC_USB); + rcc_periph_clock_enable(RCC_GPIOA); gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); -- cgit v1.2.3 From 72ae78a185d08d9979748dcef3d0cd29deddde9b Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Thu, 8 May 2014 11:02:35 -0700 Subject: Updated libopencm3. Fixes broken bootloader, issue #43. --- libopencm3 | 2 +- src/platforms/f4discovery/platform.c | 2 +- src/platforms/f4discovery/platform.h | 3 +++ src/platforms/native/platform.c | 3 ++- src/platforms/native/platform.h | 4 ++++ src/platforms/stlink/platform.c | 2 +- src/platforms/stlink/platform.h | 4 ++++ src/platforms/stm32/dfu_f1.c | 1 + src/platforms/stm32/dfu_f4.c | 2 ++ src/platforms/swlink/platform.c | 2 +- src/platforms/swlink/platform.h | 4 ++++ 11 files changed, 24 insertions(+), 5 deletions(-) (limited to 'src/platforms/native/platform.h') diff --git a/libopencm3 b/libopencm3 index a909b5c..67242de 160000 --- a/libopencm3 +++ b/libopencm3 @@ -1 +1 @@ -Subproject commit a909b5ca9e18f802e3caef19e63d38861662c128 +Subproject commit 67242de60dec0227739cd549e8a78e1a3c15dbf5 diff --git a/src/platforms/f4discovery/platform.c b/src/platforms/f4discovery/platform.c index 2786954..5b073e9 100644 --- a/src/platforms/f4discovery/platform.c +++ b/src/platforms/f4discovery/platform.c @@ -22,6 +22,7 @@ * implementation. */ +#include "platform.h" #include #include #include @@ -31,7 +32,6 @@ #include #include -#include "platform.h" #include "jtag_scan.h" #include diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index a777ed2..bbf01e1 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -24,6 +24,9 @@ #ifndef __PLATFORM_H #define __PLATFORM_H +#include +#include +#include #include #include diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index d6ca992..cb9e69e 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -22,6 +22,8 @@ * implementation. */ +#include "platform.h" + #include #include #include @@ -31,7 +33,6 @@ #include #include -#include "platform.h" #include "jtag_scan.h" #include diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 2916e64..082f6ef 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -24,6 +24,10 @@ #ifndef __PLATFORM_H #define __PLATFORM_H +#include +#include +#include + #include #include diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index ec8c000..1369c37 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -22,6 +22,7 @@ * implementation. */ +#include "platform.h" #include #include #include @@ -30,7 +31,6 @@ #include #include -#include "platform.h" #include "jtag_scan.h" #include diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index 6268a0e..0780706 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -24,6 +24,10 @@ #ifndef __PLATFORM_H #define __PLATFORM_H +#include +#include +#include + #include #include diff --git a/src/platforms/stm32/dfu_f1.c b/src/platforms/stm32/dfu_f1.c index 77b6f58..bb1e274 100644 --- a/src/platforms/stm32/dfu_f1.c +++ b/src/platforms/stm32/dfu_f1.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include "platform.h" #include #include diff --git a/src/platforms/stm32/dfu_f4.c b/src/platforms/stm32/dfu_f4.c index 1421b19..3d1e369 100644 --- a/src/platforms/stm32/dfu_f4.c +++ b/src/platforms/stm32/dfu_f4.c @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +#include "platform.h" + #if defined(STM32F2) # include #elif defined(STM32F4) diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 28db60f..0f5695d 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -22,6 +22,7 @@ * implementation. */ +#include "platform.h" #include #include #include @@ -30,7 +31,6 @@ #include #include -#include "platform.h" #include "jtag_scan.h" #include diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index dd2ac8a..fe3dc46 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -24,6 +24,10 @@ #ifndef __PLATFORM_H #define __PLATFORM_H +#include +#include +#include + #include #include -- cgit v1.2.3 From c9089f58514b59cfc43e27796eb258cbabb2112b Mon Sep 17 00:00:00 2001 From: Richard Eoin Meadows Date: Fri, 11 Apr 2014 18:35:55 +0100 Subject: Added monitor option to toggle target power --- src/command.c | 12 ++++++++++++ src/platforms/native/platform.c | 8 +++++++- src/platforms/native/platform.h | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/command.c b/src/command.c index 8378576..0c97949 100644 --- a/src/command.c +++ b/src/command.c @@ -47,6 +47,7 @@ static bool cmd_swdp_scan(void); static bool cmd_targets(target *t); static bool cmd_morse(void); static bool cmd_connect_srst(target *t, int argc, const char **argv); +static bool cmd_target_power(target *t, int argc, const char **argv); #ifdef PLATFORM_HAS_TRACESWO static bool cmd_traceswo(void); #endif @@ -59,6 +60,7 @@ const struct command_s cmd_list[] = { {"targets", (cmd_handler)cmd_targets, "Display list of available targets" }, {"morse", (cmd_handler)cmd_morse, "Display morse error message" }, {"connect_srst", (cmd_handler)cmd_connect_srst, "Configure connect under SRST: (enable|disable)" }, + {"tpwr", (cmd_handler)cmd_target_power, "Supplies power to the target: (enable|disable)"}, #ifdef PLATFORM_HAS_TRACESWO {"traceswo", (cmd_handler)cmd_traceswo, "Start trace capture" }, #endif @@ -221,6 +223,16 @@ static bool cmd_connect_srst(target *t, int argc, const char **argv) connect_assert_srst = !strcmp(argv[1], "enable"); return true; } +static bool cmd_target_power(target *t, int argc, const char **argv) +{ + (void)t; + if (argc == 1) + gdb_outf("Target Power: %s\n", + !platform_target_get_power() ? "enabled" : "disabled"); + else + platform_target_set_power(!strncmp(argv[1], "enable", strlen(argv[1]))); + return true; +} #ifdef PLATFORM_HAS_TRACESWO static bool cmd_traceswo(void) diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index cb9e69e..224daf8 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -153,7 +153,13 @@ void platform_srst_set_val(bool assert) gpio_set_val(SRST_PORT, SRST_PIN, !assert); } } - +bool platform_target_get_power(void) { + return gpio_get(PWR_BR_PORT, PWR_BR_PIN); +} +void platform_target_set_power(bool power) +{ + gpio_set_val(PWR_BR_PORT, PWR_BR_PIN, !power); +} void platform_delay(uint32_t delay) { timeout_counter = delay; diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 082f6ef..5ca0408 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -231,3 +231,5 @@ static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) 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); -- cgit v1.2.3 From 8a32b46f65ad8bc20107a26df9b7d3d9a356a5ee Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Fri, 8 Aug 2014 20:22:33 +1200 Subject: Fix build for non-native targets. --- src/command.c | 7 +++++++ src/platforms/native/platform.h | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/command.c b/src/command.c index 0c97949..e817197 100644 --- a/src/command.c +++ b/src/command.c @@ -47,7 +47,9 @@ static bool cmd_swdp_scan(void); static bool cmd_targets(target *t); static bool cmd_morse(void); static bool cmd_connect_srst(target *t, int argc, const char **argv); +#ifdef PLATFORM_HAS_POWER_SWITCH static bool cmd_target_power(target *t, int argc, const char **argv); +#endif #ifdef PLATFORM_HAS_TRACESWO static bool cmd_traceswo(void); #endif @@ -60,7 +62,9 @@ const struct command_s cmd_list[] = { {"targets", (cmd_handler)cmd_targets, "Display list of available targets" }, {"morse", (cmd_handler)cmd_morse, "Display morse error message" }, {"connect_srst", (cmd_handler)cmd_connect_srst, "Configure connect under SRST: (enable|disable)" }, +#ifdef PLATFORM_HAS_POWER_SWITCH {"tpwr", (cmd_handler)cmd_target_power, "Supplies power to the target: (enable|disable)"}, +#endif #ifdef PLATFORM_HAS_TRACESWO {"traceswo", (cmd_handler)cmd_traceswo, "Start trace capture" }, #endif @@ -223,6 +227,8 @@ static bool cmd_connect_srst(target *t, int argc, const char **argv) connect_assert_srst = !strcmp(argv[1], "enable"); return true; } + +#ifdef PLATFORM_HAS_POWER_SWITCH static bool cmd_target_power(target *t, int argc, const char **argv) { (void)t; @@ -233,6 +239,7 @@ static bool cmd_target_power(target *t, int argc, const char **argv) platform_target_set_power(!strncmp(argv[1], "enable", strlen(argv[1]))); return true; } +#endif #ifdef PLATFORM_HAS_TRACESWO static bool cmd_traceswo(void) diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 5ca0408..3bbcd17 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -39,6 +39,7 @@ #define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 #define PLATFORM_HAS_TRACESWO +#define PLATFORM_HAS_POWER_SWITCH #define BOARD_IDENT "Black Magic Probe" #define BOARD_IDENT_DFU "Black Magic Probe (Upgrade)" #define BOARD_IDENT_UPD "Black Magic Probe (DFU Upgrade)" @@ -225,7 +226,6 @@ static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) #define gpio_get _gpio_get #endif -#endif #define disconnect_usb() gpio_set_mode(USB_PU_PORT, GPIO_MODE_INPUT, 0, USB_PU_PIN); void assert_boot_pin(void); @@ -233,3 +233,6 @@ 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 + -- cgit v1.2.3 From a5549d630c3c261e7d52cb245d945e54f011a3e7 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Thu, 16 Oct 2014 13:19:34 -0700 Subject: Whitespace cleanup. --- src/cortexm.c | 2 +- src/gdb_main.c | 2 +- src/platforms/f4discovery/platform.h | 39 ++++++++++--------- src/platforms/f4discovery/usbdfu.c | 6 +-- src/platforms/libftdi/swdptap.c | 9 +++-- src/platforms/native/platform.c | 26 ++++++------- src/platforms/native/platform.h | 58 ++++++++++++++-------------- src/platforms/native/usbdfu.c | 2 +- src/platforms/stlink/dfu_upgrade.c | 10 ++--- src/platforms/stlink/platform.c | 72 ++++++++++++++++++----------------- src/platforms/stlink/platform.h | 45 +++++++++++----------- src/platforms/stlink/usbdfu.c | 6 +-- src/platforms/stm32/cdcacm.c | 52 ++++++++++++------------- src/platforms/stm32/dfu_f4.c | 27 +++++++------ src/platforms/stm32/dfucore.c | 73 ++++++++++++++++++------------------ src/platforms/stm32/gdb_if.c | 44 +++++++++++----------- src/platforms/swlink/platform.c | 26 ++++++------- src/platforms/swlink/platform.h | 45 +++++++++++----------- src/platforms/swlink/usbdfu.c | 20 +++++----- 19 files changed, 287 insertions(+), 277 deletions(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/cortexm.c b/src/cortexm.c index 8c2e54e..3ac960c 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -970,7 +970,7 @@ static int cortexm_hostio_request(target *t) case SYS_OPEN:{ /* open */ /* Translate stupid fopen modes to open flags. * See DUI0471C, Table 8-3 */ - const uint32_t flags[] = { + const uint32_t flags[] = { FILEIO_O_RDONLY, /* r, rb */ FILEIO_O_RDWR, /* r+, r+b */ FILEIO_O_WRONLY | FILEIO_O_CREAT | FILEIO_O_TRUNC,/*w*/ diff --git a/src/gdb_main.c b/src/gdb_main.c index bd27d48..c99ebac 100644 --- a/src/gdb_main.c +++ b/src/gdb_main.c @@ -217,7 +217,7 @@ gdb_main(void) break; case 0x04: - case 'D': /* GDB 'detach' command. */ + case 'D': /* GDB 'detach' command. */ if(cur_target) target_detach(cur_target); last_target = cur_target; diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index bbf01e1..210ba62 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -38,10 +38,10 @@ #define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 #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 ")" -#define DFU_IDENT "Black Magic Firmware Upgrade (F4Discovery" -#define DFU_IFACE_STRING "@Internal Flash /0x08000000/1*016Ka,3*016Kg,1*064Kg,7*128Kg" +#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 ")" +#define DFU_IDENT "Black Magic Firmware Upgrade (F4Discovery" +#define DFU_IFACE_STRING "@Internal Flash /0x08000000/1*016Ka,3*016Kg,1*064Kg,7*128Kg" extern usbd_device *usbdev; #define CDCACM_GDB_ENDPOINT 1 @@ -97,13 +97,16 @@ extern usbd_device *usbdev; #define LED_ERROR GPIO14 #define LED_BOOTLOADER GPIO15 -#define TMS_SET_MODE() gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, \ - GPIO_PUPD_NONE, TMS_PIN); -#define SWDIO_MODE_FLOAT() gpio_mode_setup(SWDIO_PORT, GPIO_MODE_INPUT, \ - GPIO_PUPD_NONE, SWDIO_PIN); +#define TMS_SET_MODE() \ + gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, \ + GPIO_PUPD_NONE, TMS_PIN); +#define SWDIO_MODE_FLOAT() \ + gpio_mode_setup(SWDIO_PORT, GPIO_MODE_INPUT, \ + GPIO_PUPD_NONE, SWDIO_PIN); -#define SWDIO_MODE_DRIVE() gpio_mode_setup(SWDIO_PORT, GPIO_MODE_OUTPUT, \ - GPIO_PUPD_NONE, SWDIO_PIN); +#define SWDIO_MODE_DRIVE() \ + gpio_mode_setup(SWDIO_PORT, GPIO_MODE_OUTPUT, \ + GPIO_PUPD_NONE, SWDIO_PIN); #define USB_DRIVER stm32f107_usb_driver @@ -121,7 +124,7 @@ extern usbd_device *usbdev; #define USBUSART USART3 #define USBUSART_CR1 USART3_CR1 #define USBUSART_IRQ NVIC_USART3_IRQ -#define USBUSART_CLK RCC_USART3 +#define USBUSART_CLK RCC_USART3 #define USBUSART_TX_PORT GPIOD #define USBUSART_TX_PIN GPIO8 #define USBUSART_RX_PORT GPIOD @@ -132,13 +135,13 @@ extern usbd_device *usbdev; #define USBUSART_TIM_IRQ NVIC_TIM4_IRQ #define USBUSART_TIM_ISR tim4_isr -#define UART_PIN_SETUP() do { \ - gpio_mode_setup(USBUSART_TX_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, \ - USBUSART_TX_PIN); \ - gpio_mode_setup(USBUSART_RX_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, \ - USBUSART_RX_PIN); \ - gpio_set_af(USBUSART_TX_PORT, GPIO_AF7, USBUSART_TX_PIN); \ - gpio_set_af(USBUSART_RX_PORT, GPIO_AF7, USBUSART_RX_PIN); \ +#define UART_PIN_SETUP() do { \ + gpio_mode_setup(USBUSART_TX_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, \ + USBUSART_TX_PIN); \ + gpio_mode_setup(USBUSART_RX_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, \ + USBUSART_RX_PIN); \ + gpio_set_af(USBUSART_TX_PORT, GPIO_AF7, USBUSART_TX_PIN); \ + gpio_set_af(USBUSART_RX_PORT, GPIO_AF7, USBUSART_RX_PIN); \ } while(0) #define TRACE_TIM TIM3 diff --git a/src/platforms/f4discovery/usbdfu.c b/src/platforms/f4discovery/usbdfu.c index b7af115..7070ade 100644 --- a/src/platforms/f4discovery/usbdfu.c +++ b/src/platforms/f4discovery/usbdfu.c @@ -27,7 +27,7 @@ void dfu_detach(void) { - /* USB device must detach, we just reset... */ + /* USB device must detach, we just reset... */ scb_reset_system(); } @@ -40,8 +40,8 @@ int main(void) dfu_protect_enable(); - /* Set up clock*/ - rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]); + /* Set up clock*/ + rcc_clock_setup_hse_3v3(&hse_8mhz_3v3[CLOCK_3V3_168MHZ]); systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); systick_set_reload(2100000); diff --git a/src/platforms/libftdi/swdptap.c b/src/platforms/libftdi/swdptap.c index cd3582b..ef350de 100644 --- a/src/platforms/libftdi/swdptap.c +++ b/src/platforms/libftdi/swdptap.c @@ -60,16 +60,17 @@ int swdptap_init(void) void swdptap_reset(void) { - swdptap_turnaround(0); - /* 50 clocks with TMS high */ - for(int i = 0; i < 50; i++) swdptap_bit_out(1); + swdptap_turnaround(0); + /* 50 clocks with TMS high */ + for(int i = 0; i < 50; i++) + swdptap_bit_out(1); } static void swdptap_turnaround(uint8_t dir) { static uint8_t olddir = 0; - //DEBUG("%s", dir ? "\n-> ":"\n<- "); + /*DEBUG("%s", dir ? "\n-> ":"\n<- ");*/ platform_buffer_flush(); if(dir == olddir) return; diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 66b84fa..2789d8c 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -110,14 +110,13 @@ int platform_init(void) : GPIO_CNF_OUTPUT_OPENDRAIN), SRST_PIN); - /* Enable internal pull-up on PWR_BR so that we don't drive - TPWR locally or inadvertently supply power to the target. */ - if (platform_hwversion () > 0) { - gpio_set (PWR_BR_PORT, PWR_BR_PIN); - gpio_set_mode(PWR_BR_PORT, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_PULL_UPDOWN, - PWR_BR_PIN); - } + /* Enable internal pull-up on PWR_BR so that we don't drive + TPWR locally or inadvertently supply power to the target. */ + if (platform_hwversion () > 0) { + gpio_set (PWR_BR_PORT, PWR_BR_PIN); + gpio_set_mode(PWR_BR_PORT, GPIO_MODE_INPUT, + GPIO_CNF_INPUT_PULL_UPDOWN, PWR_BR_PIN); + } /* Setup heartbeat timer */ systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); @@ -134,15 +133,16 @@ int platform_init(void) gpio_set_mode(GPIOB, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO0); } - - SCB_VTOR = 0x2000; // Relocate interrupt vector table here + /* Relocate interrupt vector table here */ + SCB_VTOR = 0x2000; cdcacm_init(); usbuart_init(); - // Set recovery point + /* Set recovery point */ if (setjmp(fatal_error_jmpbuf)) { - return 0; // Do nothing on failure + /* Do nothing on failure */ + return 0; } jtag_scan(NULL); @@ -162,7 +162,7 @@ bool platform_target_get_power(void) { if (platform_hwversion() > 0) { return gpio_get(PWR_BR_PORT, PWR_BR_PIN); } - return 1; // 1 = Unpowered + return 1; /* 1 = Unpowered */ } void platform_target_set_power(bool power) { diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 3bbcd17..81a2a4b 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -41,11 +41,11 @@ #define PLATFORM_HAS_TRACESWO #define PLATFORM_HAS_POWER_SWITCH #define BOARD_IDENT "Black Magic Probe" -#define BOARD_IDENT_DFU "Black Magic Probe (Upgrade)" -#define BOARD_IDENT_UPD "Black Magic Probe (DFU Upgrade)" +#define BOARD_IDENT_DFU "Black Magic Probe (Upgrade)" +#define BOARD_IDENT_UPD "Black Magic Probe (DFU Upgrade)" #define DFU_IDENT "Black Magic Firmware Upgrade" -#define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,120*001Kg" -#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" +#define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,120*001Kg" +#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" extern usbd_device *usbdev; #define CDCACM_GDB_ENDPOINT 1 @@ -109,35 +109,35 @@ extern usbd_device *usbdev; #define LED_IDLE_RUN GPIO10 #define LED_ERROR GPIO11 -#define TMS_SET_MODE() \ - gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ - GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); -#define SWDIO_MODE_FLOAT() \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, \ - GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); -#define SWDIO_MODE_DRIVE() \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ - GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN); - -#define UART_PIN_SETUP() \ - gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); - -#define SRST_SET_VAL(x) \ - platform_srst_set_val(x) - -#define USB_DRIVER stm32f103_usb_driver -#define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ -#define USB_ISR usb_lp_can_rx0_isr +#define TMS_SET_MODE() \ + gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ + GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); +#define SWDIO_MODE_FLOAT() \ + gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, \ + GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); +#define SWDIO_MODE_DRIVE() \ + gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ + GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN); + +#define UART_PIN_SETUP() \ + gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ + GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); + +#define SRST_SET_VAL(x) \ + platform_srst_set_val(x) + +#define USB_DRIVER stm32f103_usb_driver +#define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ +#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. */ -#define IRQ_PRI_USB (2 << 4) -#define IRQ_PRI_USBUSART (1 << 4) -#define IRQ_PRI_USBUSART_TIM (3 << 4) -#define IRQ_PRI_USB_VBUS (14 << 4) -#define IRQ_PRI_TRACE (0 << 4) +#define IRQ_PRI_USB (2 << 4) +#define IRQ_PRI_USBUSART (1 << 4) +#define IRQ_PRI_USBUSART_TIM (3 << 4) +#define IRQ_PRI_USB_VBUS (14 << 4) +#define IRQ_PRI_TRACE (0 << 4) #define USBUSART USART1 #define USBUSART_CR1 USART1_CR1 diff --git a/src/platforms/native/usbdfu.c b/src/platforms/native/usbdfu.c index 3aac079..39643da 100644 --- a/src/platforms/native/usbdfu.c +++ b/src/platforms/native/usbdfu.c @@ -29,7 +29,7 @@ uint32_t app_address = 0x08002000; void dfu_detach(void) { - /* USB device must detach, we just reset... */ + /* USB device must detach, we just reset... */ scb_reset_system(); } diff --git a/src/platforms/stlink/dfu_upgrade.c b/src/platforms/stlink/dfu_upgrade.c index b15117b..4a3648a 100644 --- a/src/platforms/stlink/dfu_upgrade.c +++ b/src/platforms/stlink/dfu_upgrade.c @@ -81,17 +81,17 @@ int main(void) rcc_clock_setup_in_hse_8mhz_out_72mhz(); - stlink_set_rev(); + stlink_set_rev(); systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); systick_set_reload(900000); - dfu_protect(UPD_MODE); + dfu_protect(UPD_MODE); - /* Handle USB disconnect/connect */ + /* Handle USB disconnect/connect */ /* Just in case: Disconnect USB cable by resetting USB Device - * and pulling USB_DP low - * Device will reconnect automatically as Pull-Up is hard wired*/ + * and pulling USB_DP low + * Device will reconnect automatically as Pull-Up is hard wired*/ rcc_periph_reset_pulse(RST_USB); rcc_periph_clock_enable(RCC_USB); rcc_periph_clock_enable(RCC_GPIOA); diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index cf2d954..494499c 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -49,22 +49,21 @@ uint16_t led_idle_run; int platform_hwversion(void) { static int hwversion = -1; - int i; + int i; if (hwversion == -1) { gpio_set_mode(GPIOC, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_PULL_UPDOWN, - GPIO14 | GPIO13); + GPIO_CNF_INPUT_PULL_UPDOWN, GPIO14 | GPIO13); gpio_set(GPIOC, GPIO14 | GPIO13); - for (i = 0; i<10; i++) - hwversion = ~(gpio_get(GPIOC, GPIO14 | GPIO13) >> 13) & 3; - switch (hwversion) - { - case 0: - led_idle_run = GPIO8; - break; - default: - led_idle_run = GPIO9; - } + for (i = 0; i<10; i++) + hwversion = ~(gpio_get(GPIOC, GPIO14 | GPIO13) >> 13) & 3; + switch (hwversion) + { + case 0: + led_idle_run = GPIO8; + break; + default: + led_idle_run = GPIO9; + } } return hwversion; } @@ -82,30 +81,30 @@ int platform_init(void) rcc_periph_clock_enable(RCC_CRC); /* On Rev 1 unconditionally activate MCO on PORTA8 with HSE - * platform_hwversion() also needed to initialize led_idle_run! - */ - if (platform_hwversion() == 1) - { - RCC_CFGR &= ~( 0xf<< 24); - RCC_CFGR |= (RCC_CFGR_MCO_HSECLK << 24); - gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO8); - } + * platform_hwversion() also needed to initialize led_idle_run! + */ + if (platform_hwversion() == 1) + { + RCC_CFGR &= ~(0xf << 24); + RCC_CFGR |= (RCC_CFGR_MCO_HSECLK << 24); + gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO8); + } /* Setup GPIO ports */ gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); + GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); gpio_set_mode(TCK_PORT, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, TCK_PIN); + GPIO_CNF_OUTPUT_PUSHPULL, TCK_PIN); gpio_set_mode(TDI_PORT, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, TDI_PIN); + GPIO_CNF_OUTPUT_PUSHPULL, TDI_PIN); uint16_t srst_pin = platform_hwversion() == 0 ? - SRST_PIN_V1 : SRST_PIN_V2; + SRST_PIN_V1 : SRST_PIN_V2; gpio_set(SRST_PORT, srst_pin); gpio_set_mode(SRST_PORT, GPIO_MODE_OUTPUT_50_MHZ, - GPIO_CNF_OUTPUT_OPENDRAIN, srst_pin); + GPIO_CNF_OUTPUT_OPENDRAIN, srst_pin); gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run); + GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run); /* Setup heartbeat timer */ systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); @@ -117,13 +116,14 @@ int platform_init(void) usbuart_init(); - SCB_VTOR = 0x2000; // Relocate interrupt vector table here + SCB_VTOR = 0x2000; /* Relocate interrupt vector table here */ cdcacm_init(); - // Set recovery point + /* Set recovery point */ if (setjmp(fatal_error_jmpbuf)) { - return 0; // Do nothing on failure + /* Do nothing on failure */ + return 0; } jtag_scan(NULL); @@ -134,7 +134,7 @@ int platform_init(void) void platform_delay(uint32_t delay) { timeout_counter = delay; - while(timeout_counter); + while (timeout_counter); } void platform_srst_set_val(bool assert) @@ -177,7 +177,7 @@ void disconnect_usb(void) rcc_periph_clock_enable(RCC_GPIOA); gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); + GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); } void assert_boot_pin(void) @@ -192,4 +192,8 @@ void assert_boot_pin(void) crl |= 0x80; GPIOA_CRL = crl; } -void setup_vbus_irq(void){}; + +void setup_vbus_irq(void) +{ +} + diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index 0780706..e56abd9 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -38,12 +38,12 @@ #define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 -#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 ")" -#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" -#define DFU_IDENT "Black Magic Firmware Upgrade (STLINK)" -#define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" -#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" +#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 ")" +#define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" +#define DFU_IDENT "Black Magic Firmware Upgrade (STLINK)" +#define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" +#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" extern usbd_device *usbdev; #define CDCACM_GDB_ENDPOINT 1 @@ -94,26 +94,26 @@ extern usbd_device *usbdev; #define LED_PORT_UART GPIOC #define LED_UART GPIO14 -#define TMS_SET_MODE() \ - gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ - GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); -#define SWDIO_MODE_FLOAT() \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, \ - GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); -#define SWDIO_MODE_DRIVE() \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ - GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN); +#define TMS_SET_MODE() \ + gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ + GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); +#define SWDIO_MODE_FLOAT() \ + gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, \ + GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); +#define SWDIO_MODE_DRIVE() \ + gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ + GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN); -#define UART_PIN_SETUP() \ - gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); +#define UART_PIN_SETUP() \ + gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ + GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); -#define SRST_SET_VAL(x) \ - platform_srst_set_val(x) +#define SRST_SET_VAL(x) \ + platform_srst_set_val(x) #define USB_DRIVER stm32f103_usb_driver -#define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ -#define USB_ISR usb_lp_can_rx0_isr +#define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ +#define USB_ISR usb_lp_can_rx0_isr /* Interrupt priorities. Low numbers are high priority. * For now USART2 preempts USB which may spin while buffer is drained. * TIM3 is used for traceswo capture and must be highest priority. @@ -209,3 +209,4 @@ static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) void disconnect_usb(void); void assert_boot_pin(void); + diff --git a/src/platforms/stlink/usbdfu.c b/src/platforms/stlink/usbdfu.c index 843033b..b42ec20 100644 --- a/src/platforms/stlink/usbdfu.c +++ b/src/platforms/stlink/usbdfu.c @@ -106,10 +106,10 @@ int main(void) systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); systick_set_reload(900000); - /* Handle USB disconnect/connect */ + /* Handle USB disconnect/connect */ /* Just in case: Disconnect USB cable by resetting USB Device - * and pulling USB_DP low - * Device will reconnect automatically as Pull-Up is hard wired*/ + * and pulling USB_DP low + * Device will reconnect automatically as Pull-Up is hard wired*/ rcc_periph_reset_pulse(RST_USB); rcc_periph_clock_enable(RCC_USB); rcc_periph_clock_enable(RCC_GPIOA); diff --git a/src/platforms/stm32/cdcacm.c b/src/platforms/stm32/cdcacm.c index 010117f..ef7ff3b 100644 --- a/src/platforms/stm32/cdcacm.c +++ b/src/platforms/stm32/cdcacm.c @@ -51,20 +51,20 @@ static int cdcacm_gdb_dtr = 1; static const struct usb_device_descriptor dev = { - .bLength = USB_DT_DEVICE_SIZE, - .bDescriptorType = USB_DT_DEVICE, - .bcdUSB = 0x0200, - .bDeviceClass = 0xEF, /* Miscellaneous Device */ - .bDeviceSubClass = 2, /* Common Class */ - .bDeviceProtocol = 1, /* Interface Association */ - .bMaxPacketSize0 = 64, - .idVendor = 0x1D50, - .idProduct = 0x6018, - .bcdDevice = 0x0100, - .iManufacturer = 1, - .iProduct = 2, - .iSerialNumber = 3, - .bNumConfigurations = 1, + .bLength = USB_DT_DEVICE_SIZE, + .bDescriptorType = USB_DT_DEVICE, + .bcdUSB = 0x0200, + .bDeviceClass = 0xEF, /* Miscellaneous Device */ + .bDeviceSubClass = 2, /* Common Class */ + .bDeviceProtocol = 1, /* Interface Association */ + .bMaxPacketSize0 = 64, + .idVendor = 0x1D50, + .idProduct = 0x6018, + .bcdDevice = 0x0100, + .iManufacturer = 1, + .iProduct = 2, + .iSerialNumber = 3, + .bNumConfigurations = 1, }; /* This notification endpoint isn't implemented. According to CDC spec its @@ -412,7 +412,7 @@ static void dfu_detach_complete(usbd_device *dev, struct usb_setup_data *req) disconnect_usb(); /* Assert boot-request pin */ - assert_boot_pin(); + assert_boot_pin(); /* Reset core to enter bootloader */ scb_reset_core(); @@ -555,22 +555,22 @@ void USB_ISR(void) static char *get_dev_unique_id(char *s) { #if defined(STM32F4) - volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFF7A10; + volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFF7A10; #else - volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8; + volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8; #endif uint32_t unique_id = *unique_id_p + *(unique_id_p + 1) + *(unique_id_p + 2); - int i; - - /* Fetch serial number from chip's unique ID */ - for(i = 0; i < 8; i++) { - s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; - } - for(i = 0; i < 8; i++) - if(s[i] > '9') - s[i] += 'A' - '9' - 1; + int i; + + /* Fetch serial number from chip's unique ID */ + for(i = 0; i < 8; i++) { + s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; + } + for(i = 0; i < 8; i++) + if(s[i] > '9') + s[i] += 'A' - '9' - 1; s[8] = 0; return s; diff --git a/src/platforms/stm32/dfu_f4.c b/src/platforms/stm32/dfu_f4.c index 3d1e369..1065938 100644 --- a/src/platforms/stm32/dfu_f4.c +++ b/src/platforms/stm32/dfu_f4.c @@ -28,13 +28,17 @@ #include "usbdfu.h" -static uint32_t sector_addr[] = {0x8000000, 0x8004000, 0x8008000, 0x800c000, - 0x8010000, 0x8020000, 0x8040000, 0x8060000, - 0x8080000, 0x80a0000, 0x80c0000, 0x80e0000, - 0x8100000, 0}; -static uint16_t sector_erase_time[12]= {500, 500, 500, 500, - 1100, - 2600, 2600, 2600, 2600, 2600, 2600, 2600}; +static uint32_t sector_addr[] = { + 0x8000000, 0x8004000, 0x8008000, 0x800c000, + 0x8010000, 0x8020000, 0x8040000, 0x8060000, + 0x8080000, 0x80a0000, 0x80c0000, 0x80e0000, + 0x8100000, 0 +}; +static uint16_t sector_erase_time[12]= { + 500, 500, 500, 500, + 1100, 2600, 2600, 2600, + 2600, 2600, 2600, 2600 +}; static uint8_t sector_num = 0xff; /* Find the sector number for a given address*/ @@ -45,7 +49,7 @@ static void get_sector_num(uint32_t addr) if (addr < sector_addr[i+1]) break; i++; - } + } if (!sector_addr[i]) return; sector_num = i; @@ -61,9 +65,8 @@ void dfu_check_and_do_sector_erase(uint32_t addr) void dfu_flash_program_buffer(uint32_t baseaddr, void *buf, int len) { for(int i = 0; i < len; i += 4) - flash_program_word(baseaddr + i, - *(uint32_t*)(buf+i), - FLASH_PROGRAM_X32); + flash_program_word(baseaddr + i, *(uint32_t*)(buf+i), + FLASH_PROGRAM_X32); } uint32_t dfu_poll_timeout(uint8_t cmd, uint32_t addr, uint16_t blocknum) @@ -100,7 +103,7 @@ void dfu_jump_app_if_valid(void) SCB_VTOR = APP_ADDRESS & 0x1FFFFF; /* Max 2 MByte Flash*/ /* Initialise master stack pointer */ asm volatile ("msr msp, %0"::"g" - (*(volatile uint32_t*)APP_ADDRESS)); + (*(volatile uint32_t*)APP_ADDRESS)); /* Jump to application */ (*(void(**)())(APP_ADDRESS + 4))(); } diff --git a/src/platforms/stm32/dfucore.c b/src/platforms/stm32/dfucore.c index 85e5e87..77cef4e 100644 --- a/src/platforms/stm32/dfucore.c +++ b/src/platforms/stm32/dfucore.c @@ -50,20 +50,20 @@ static struct { } prog; const struct usb_device_descriptor dev = { - .bLength = USB_DT_DEVICE_SIZE, - .bDescriptorType = USB_DT_DEVICE, - .bcdUSB = 0x0200, - .bDeviceClass = 0, - .bDeviceSubClass = 0, - .bDeviceProtocol = 0, - .bMaxPacketSize0 = 64, - .idVendor = 0x1D50, - .idProduct = 0x6017, - .bcdDevice = 0x0100, - .iManufacturer = 1, - .iProduct = 2, - .iSerialNumber = 3, - .bNumConfigurations = 1, + .bLength = USB_DT_DEVICE_SIZE, + .bDescriptorType = USB_DT_DEVICE, + .bcdUSB = 0x0200, + .bDeviceClass = 0, + .bDeviceSubClass = 0, + .bDeviceProtocol = 0, + .bMaxPacketSize0 = 64, + .idVendor = 0x1D50, + .idProduct = 0x6017, + .bcdDevice = 0x0100, + .iManufacturer = 1, + .iProduct = 2, + .iSerialNumber = 3, + .bNumConfigurations = 1, }; const struct usb_dfu_descriptor dfu_function = { @@ -166,8 +166,7 @@ usbdfu_getstatus_complete(usbd_device *dev, struct usb_setup_data *req) flash_unlock(); if(prog.blocknum == 0) { uint32_t addr = get_le32(prog.buf + 1); - if (addr < app_address || - (addr >= max_address)) { + if ((addr < app_address) || (addr >= max_address)) { flash_lock(); usbd_ep_stall_set(dev, 0, 1); return; @@ -282,34 +281,34 @@ void dfu_main(void) static char *get_dev_unique_id(char *s) { #if defined(STM32F4) || defined(STM32F2) -#define UNIQUE_SERIAL_R 0x1FFF7A10 -#define FLASH_SIZE_R 0x1fff7A22 +# define UNIQUE_SERIAL_R 0x1FFF7A10 +# define FLASH_SIZE_R 0x1fff7A22 #elif defined(STM32F3) -#define UNIQUE_SERIAL_R 0x1FFFF7AC -#define FLASH_SIZE_R 0x1fff77cc +# define UNIQUE_SERIAL_R 0x1FFFF7AC +# define FLASH_SIZE_R 0x1fff77cc #elif defined(STM32L1) -#define UNIQUE_SERIAL_R 0x1ff80050 -#define FLASH_SIZE_R 0x1FF8004C +# define UNIQUE_SERIAL_R 0x1ff80050 +# define FLASH_SIZE_R 0x1FF8004C #else -#define UNIQUE_SERIAL_R 0x1FFFF7E8; -#define FLASH_SIZE_R 0x1ffff7e0 +# define UNIQUE_SERIAL_R 0x1FFFF7E8; +# define FLASH_SIZE_R 0x1ffff7e0 #endif - volatile uint32_t *unique_id_p = (volatile uint32_t *)UNIQUE_SERIAL_R; + volatile uint32_t *unique_id_p = (volatile uint32_t *)UNIQUE_SERIAL_R; uint32_t unique_id = *unique_id_p + *(unique_id_p + 1) + *(unique_id_p + 2); - int i; - - /* Calculated the upper flash limit from the exported data - in theparameter block*/ - max_address = (*(uint32_t *) FLASH_SIZE_R) <<10; - /* Fetch serial number from chip's unique ID */ - for(i = 0; i < 8; i++) { - s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; - } - for(i = 0; i < 8; i++) - if(s[i] > '9') - s[i] += 'A' - '9' - 1; + int i; + + /* Calculated the upper flash limit from the exported data + in theparameter block*/ + max_address = (*(uint32_t *) FLASH_SIZE_R) <<10; + /* Fetch serial number from chip's unique ID */ + for(i = 0; i < 8; i++) { + s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; + } + for(i = 0; i < 8; i++) + if(s[i] > '9') + s[i] += 'A' - '9' - 1; s[8] = 0; return s; diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c index 28bc4c8..482effe 100644 --- a/src/platforms/stm32/gdb_if.c +++ b/src/platforms/stm32/gdb_if.c @@ -67,8 +67,8 @@ void gdb_usb_out_cb(usbd_device *dev, uint8_t ep) { (void)ep; usbd_ep_nak_set(dev, CDCACM_GDB_ENDPOINT, 1); - count_new = usbd_ep_read_packet(dev, CDCACM_GDB_ENDPOINT, - double_buffer_out, CDCACM_PACKET_SIZE); + count_new = usbd_ep_read_packet(dev, CDCACM_GDB_ENDPOINT, + double_buffer_out, CDCACM_PACKET_SIZE); if(!count_new) { usbd_ep_nak_set(dev, CDCACM_GDB_ENDPOINT, 0); } @@ -77,19 +77,19 @@ void gdb_usb_out_cb(usbd_device *dev, uint8_t ep) unsigned char gdb_if_getchar(void) { - while(!(out_ptr < count_out)) { + while (!(out_ptr < count_out)) { /* Detach if port closed */ - if(!cdcacm_get_dtr()) + if (!cdcacm_get_dtr()) return 0x04; - while(cdcacm_get_config() != 1); - if (count_new) { - memcpy(buffer_out, double_buffer_out,count_new); - count_out = count_new; - count_new = 0; - out_ptr = 0; - usbd_ep_nak_set(usbdev, CDCACM_GDB_ENDPOINT, 0); - } + while (cdcacm_get_config() != 1); + if (count_new) { + memcpy(buffer_out, double_buffer_out,count_new); + count_out = count_new; + count_new = 0; + out_ptr = 0; + usbd_ep_nak_set(usbdev, CDCACM_GDB_ENDPOINT, 0); + } } return buffer_out[out_ptr++]; @@ -99,19 +99,19 @@ unsigned char gdb_if_getchar_to(int timeout) { timeout_counter = timeout/100; - if(!(out_ptr < count_out)) do { + if (!(out_ptr < count_out)) do { /* Detach if port closed */ - if(!cdcacm_get_dtr()) + if (!cdcacm_get_dtr()) return 0x04; - while(cdcacm_get_config() != 1); - if (count_new) { - memcpy(buffer_out, double_buffer_out,count_new); - count_out = count_new; - count_new = 0; - out_ptr = 0; - usbd_ep_nak_set(usbdev, CDCACM_GDB_ENDPOINT, 0); - } + while (cdcacm_get_config() != 1); + if (count_new) { + memcpy(buffer_out, double_buffer_out,count_new); + count_out = count_new; + count_new = 0; + out_ptr = 0; + usbd_ep_nak_set(usbdev, CDCACM_GDB_ENDPOINT, 0); + } } while(timeout_counter && !(out_ptr < count_out)); if(out_ptr < count_out) diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 74f8691..7b7446a 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -54,10 +54,10 @@ int platform_init(void) rcc_periph_clock_enable(RCC_CRC); /* Unmap JTAG Pins so we can reuse as GPIO */ - data = AFIO_MAPR; - data &= ~AFIO_MAPR_SWJ_MASK; - data |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF; - AFIO_MAPR = data; + data = AFIO_MAPR; + data &= ~AFIO_MAPR_SWJ_MASK; + data |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_OFF; + AFIO_MAPR = data; /* Setup JTAG GPIO ports */ gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_10_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); @@ -69,21 +69,21 @@ int platform_init(void) gpio_set_mode(TDO_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, TDO_PIN); - gpio_set(NRST_PORT,NRST_PIN); + gpio_set(NRST_PORT,NRST_PIN); gpio_set_mode(NRST_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, NRST_PIN); gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run); - /* Remap TIM2 TIM2_REMAP[1] - * TIM2_CH1_ETR -> PA15 (TDI, set as output above) - * TIM2_CH2 -> PB3 (TDO) - */ - data = AFIO_MAPR; - data &= ~AFIO_MAPR_TIM2_REMAP_FULL_REMAP; - data |= AFIO_MAPR_TIM2_REMAP_PARTIAL_REMAP1; - AFIO_MAPR = data; + /* Remap TIM2 TIM2_REMAP[1] + * TIM2_CH1_ETR -> PA15 (TDI, set as output above) + * TIM2_CH2 -> PB3 (TDO) + */ + data = AFIO_MAPR; + data &= ~AFIO_MAPR_TIM2_REMAP_FULL_REMAP; + data |= AFIO_MAPR_TIM2_REMAP_PARTIAL_REMAP1; + AFIO_MAPR = data; /* Setup heartbeat timer */ systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index fe3dc46..6683421 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -38,12 +38,12 @@ #define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 -#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 ")" -#define DFU_IDENT "Black Magic Firmware Upgrade (SWLINK)" -#define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" -#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" +#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 ")" +#define DFU_IDENT "Black Magic Firmware Upgrade (SWLINK)" +#define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" +#define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" extern usbd_device *usbdev; #define CDCACM_GDB_ENDPOINT 1 @@ -86,26 +86,25 @@ extern usbd_device *usbdev; #define LED_PORT_UART GPIOC #define LED_UART GPIO14 -#define TMS_SET_MODE() \ - gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ - GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); -#define SWDIO_MODE_FLOAT() \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, \ - GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); -#define SWDIO_MODE_DRIVE() \ - gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ - GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN); - -#define UART_PIN_SETUP() do \ - { \ - AFIO_MAPR |= AFIO_MAPR_USART1_REMAP; \ - gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ - GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); \ - } while (0) +#define TMS_SET_MODE() \ + gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ + GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN); +#define SWDIO_MODE_FLOAT() \ + gpio_set_mode(SWDIO_PORT, GPIO_MODE_INPUT, \ + GPIO_CNF_INPUT_FLOAT, SWDIO_PIN); +#define SWDIO_MODE_DRIVE() \ + gpio_set_mode(SWDIO_PORT, GPIO_MODE_OUTPUT_50_MHZ, \ + GPIO_CNF_OUTPUT_PUSHPULL, SWDIO_PIN); + +#define UART_PIN_SETUP() do { \ + AFIO_MAPR |= AFIO_MAPR_USART1_REMAP; \ + gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_2_MHZ, \ + GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); \ +} while (0) #define USB_DRIVER stm32f103_usb_driver #define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ -#define USB_ISR usb_lp_can_rx0_isr +#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. * TIM2 is used for traceswo capture and must be highest priority. diff --git a/src/platforms/swlink/usbdfu.c b/src/platforms/swlink/usbdfu.c index f87ccf4..9360981 100644 --- a/src/platforms/swlink/usbdfu.c +++ b/src/platforms/swlink/usbdfu.c @@ -43,19 +43,19 @@ void dfu_detach(void) int main(void) { /* Check the force bootloader pin*/ - uint16_t pin_b; + uint16_t pin_b; rcc_periph_clock_enable(RCC_GPIOA); rcc_periph_clock_enable(RCC_GPIOB); /* Switch PB5 (SWIM_RST_IN) up */ gpio_set(GPIOB, GPIO5); gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, GPIO5); + GPIO_CNF_OUTPUT_PUSHPULL, GPIO5); gpio_set(GPIOB, GPIO5); - pin_b = gpio_get(GPIOB, GPIO6); + pin_b = gpio_get(GPIOB, GPIO6); /* Check state on PB6 ((SWIM_RST) and release PB5*/ - pin_b = gpio_get(GPIOB, GPIO6); + pin_b = gpio_get(GPIOB, GPIO6); gpio_set_mode(GPIOB, GPIO_MODE_INPUT, - GPIO_CNF_INPUT_FLOAT, GPIO5); + GPIO_CNF_INPUT_FLOAT, GPIO5); if(((GPIOA_CRL & 0x40) == 0x40) && pin_b) dfu_jump_app_if_valid(); @@ -65,10 +65,10 @@ int main(void) systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); systick_set_reload(900000); - /* Handle USB disconnect/connect */ + /* Handle USB disconnect/connect */ /* Just in case: Disconnect USB cable by resetting USB Device - * and pulling USB_DP low - * Device will reconnect automatically as Pull-Up is hard wired*/ + * and pulling USB_DP low + * Device will reconnect automatically as Pull-Up is hard wired*/ rcc_periph_reset_pulse(RST_USB); rcc_periph_clock_enable(RCC_USB); rcc_periph_clock_enable(RCC_GPIOA); @@ -76,7 +76,7 @@ int main(void) gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); - /* Handle LED*/ + /* Handle LED*/ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO8); @@ -90,5 +90,5 @@ int main(void) void sys_tick_handler(void) { - gpio_toggle(GPIOA, GPIO8); + gpio_toggle(GPIOA, GPIO8); } -- 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/platforms/native/platform.h') 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 5eff0ab5d648408cf4df528d2be3d29b04034083 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 28 Feb 2015 22:09:50 -0800 Subject: Factor out common GPIO code in STM32 platforms. --- src/platforms/f4discovery/platform.h | 28 ++--------------- src/platforms/native/platform.h | 33 ++----------------- src/platforms/stlink/platform.h | 33 ++----------------- src/platforms/stm32/gpio.h | 61 ++++++++++++++++++++++++++++++++++++ src/platforms/swlink/platform.h | 33 ++----------------- 5 files changed, 73 insertions(+), 115 deletions(-) create mode 100644 src/platforms/stm32/gpio.h (limited to 'src/platforms/native/platform.h') diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 90b2a11..dcad8a0 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -34,9 +34,9 @@ #include #include "gdb_packet.h" +#include "gpio.h" #include "morse.h" -#define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 #define PLATFORM_HAS_TRACESWO #define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -200,31 +200,9 @@ void uart_usb_buf_drain(uint8_t ep); #define sprintf siprintf #define vasprintf vasiprintf -#ifdef INLINE_GPIO -static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) -{ - GPIO_BSRR(gpioport) = gpios; - GPIO_BSRR(gpioport) = gpios; -} -#define gpio_set _gpio_set - -static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios) -{ - GPIO_BSRR(gpioport) = gpios<<16; - GPIO_BSRR(gpioport) = gpios<<16; -} -#define gpio_clear _gpio_clear - -static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) -{ - return (uint16_t)GPIO_IDR(gpioport) & gpios; -} -#define gpio_get _gpio_get -#endif - -#endif - #define disconnect_usb() do {usbd_disconnect(usbdev,1); nvic_disable_irq(USB_IRQ);} while(0) void assert_boot_pin(void); #define setup_vbus_irq() +#endif + diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 73b6c59..2fa1e84 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -35,9 +35,9 @@ #include #include "gdb_packet.h" +#include "gpio.h" #include "morse.h" -#define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 #define PLATFORM_HAS_TRACESWO #define PLATFORM_HAS_POWER_SWITCH @@ -164,14 +164,6 @@ extern volatile uint32_t timeout_counter; extern jmp_buf fatal_error_jmpbuf; - -#define gpio_set_val(port, pin, val) do { \ - if(val) \ - gpio_set((port), (pin)); \ - else \ - gpio_clear((port), (pin)); \ -} while(0) - #define SET_RUN_STATE(state) {running_status = (state);} #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);} @@ -189,6 +181,8 @@ extern jmp_buf fatal_error_jmpbuf; 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); /* */ @@ -205,27 +199,6 @@ void uart_usb_buf_drain(uint8_t ep); #define sprintf siprintf #define vasprintf vasiprintf -#ifdef INLINE_GPIO -static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) -{ - GPIO_BSRR(gpioport) = gpios; -} -#define gpio_set _gpio_set - -static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios) -{ - GPIO_BRR(gpioport) = gpios; -} -#define gpio_clear _gpio_clear - -static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) -{ - return (uint16_t)GPIO_IDR(gpioport) & gpios; -} -#define gpio_get _gpio_get -#endif - - #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); diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index ee08875..a49e73a 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -35,8 +35,8 @@ #include #include "gdb_packet.h" +#include "gpio.h" -#define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 #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 ")" @@ -143,13 +143,6 @@ extern volatile uint32_t timeout_counter; extern jmp_buf fatal_error_jmpbuf; -#define gpio_set_val(port, pin, val) do { \ - if(val) \ - gpio_set((port), (pin)); \ - else \ - gpio_clear((port), (pin)); \ -} while(0) - extern uint16_t led_idle_run; #define SET_RUN_STATE(state) {running_status = (state);} #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, led_idle_run, state);} @@ -182,28 +175,8 @@ void uart_usb_buf_drain(uint8_t ep); #define sprintf siprintf #define vasprintf vasiprintf -#ifdef INLINE_GPIO -static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) -{ - GPIO_BSRR(gpioport) = gpios; -} -#define gpio_set _gpio_set - -static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios) -{ - GPIO_BRR(gpioport) = gpios; -} -#define gpio_clear _gpio_clear - -static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) -{ - return (uint16_t)GPIO_IDR(gpioport) & gpios; -} -#define gpio_get _gpio_get -#endif - -#endif - void disconnect_usb(void); void assert_boot_pin(void); +#endif + diff --git a/src/platforms/stm32/gpio.h b/src/platforms/stm32/gpio.h new file mode 100644 index 0000000..035f3c9 --- /dev/null +++ b/src/platforms/stm32/gpio.h @@ -0,0 +1,61 @@ +/* + * 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 __GPIO_H +#define __GPIO_H + +#define INLINE_GPIO + +#define gpio_set_val(port, pin, val) do { \ + if(val) \ + gpio_set((port), (pin)); \ + else \ + gpio_clear((port), (pin)); \ +} while(0) + +#ifdef INLINE_GPIO +static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) +{ + GPIO_BSRR(gpioport) = gpios; +#ifdef F4DISCOVERY + GPIO_BSRR(gpioport) = gpios; +#endif +} +#define gpio_set _gpio_set + +static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios) +{ +#ifndef F4DISCOVERY + GPIO_BRR(gpioport) = gpios; +#else + GPIO_BSRR(gpioport) = gpios<<16; + GPIO_BSRR(gpioport) = gpios<<16; +#endif +} +#define gpio_clear _gpio_clear + +static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) +{ + return (uint16_t)GPIO_IDR(gpioport) & gpios; +} +#define gpio_get _gpio_get +#endif + +#endif + diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 99c8fa3..4b26466 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -35,8 +35,8 @@ #include #include "gdb_packet.h" +#include "gpio.h" -#define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 #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 ")" @@ -141,14 +141,6 @@ extern volatile uint32_t timeout_counter; extern jmp_buf fatal_error_jmpbuf; - -#define gpio_set_val(port, pin, val) do { \ - if(val) \ - gpio_set((port), (pin)); \ - else \ - gpio_clear((port), (pin)); \ -} while(0) - #define led_idle_run GPIO8 #define SET_RUN_STATE(state) {running_status = (state);} #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, led_idle_run, state);} @@ -180,27 +172,8 @@ void uart_usb_buf_drain(uint8_t ep); #define sprintf siprintf #define vasprintf vasiprintf -#ifdef INLINE_GPIO -static inline void _gpio_set(uint32_t gpioport, uint16_t gpios) -{ - GPIO_BSRR(gpioport) = gpios; -} -#define gpio_set _gpio_set - -static inline void _gpio_clear(uint32_t gpioport, uint16_t gpios) -{ - GPIO_BRR(gpioport) = gpios; -} -#define gpio_clear _gpio_clear - -static inline uint16_t _gpio_get(uint32_t gpioport, uint16_t gpios) -{ - return (uint16_t)GPIO_IDR(gpioport) & gpios; -} -#define gpio_get _gpio_get -#endif +void disconnect_usb(void); +void assert_boot_pin(void); #endif -void disconnect_usb(void); -void assert_boot_pin(void); -- cgit v1.2.3 From 476f83b69ad86c71ee57c8633f09667e9caa0a5f Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 28 Feb 2015 22:48:26 -0800 Subject: Move common USB stuff out of platform header files. --- src/include/traceswo.h | 28 ---------------------- src/include/usbuart.h | 33 -------------------------- src/platforms/f4discovery/platform.h | 14 ----------- src/platforms/native/platform.c | 1 + src/platforms/native/platform.h | 14 ----------- src/platforms/stlink/platform.h | 14 ----------- src/platforms/stm32/cdcacm.c | 5 ++-- src/platforms/stm32/cdcacm.h | 45 ++++++++++++++++++++++++++++++++++++ src/platforms/stm32/gdb_if.c | 3 +-- src/platforms/stm32/traceswo.c | 3 +-- src/platforms/stm32/traceswo.h | 28 ++++++++++++++++++++++ src/platforms/stm32/usbuart.c | 3 ++- src/platforms/stm32/usbuart.h | 33 ++++++++++++++++++++++++++ src/platforms/swlink/platform.h | 14 ----------- 14 files changed, 114 insertions(+), 124 deletions(-) delete mode 100644 src/include/traceswo.h delete mode 100644 src/include/usbuart.h create mode 100644 src/platforms/stm32/cdcacm.h create mode 100644 src/platforms/stm32/traceswo.h create mode 100644 src/platforms/stm32/usbuart.h (limited to 'src/platforms/native/platform.h') diff --git a/src/include/traceswo.h b/src/include/traceswo.h deleted file mode 100644 index 5566f94..0000000 --- a/src/include/traceswo.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of the Black Magic Debug project. - * - * Copyright (C) 2012 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 __TRACESWO_H -#define __TRACESWO_H - -#include - -void traceswo_init(void); -void trace_buf_drain(usbd_device *dev, uint8_t ep); - -#endif diff --git a/src/include/usbuart.h b/src/include/usbuart.h deleted file mode 100644 index 39f7dcd..0000000 --- a/src/include/usbuart.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the Black Magic Debug project. - * - * Copyright (C) 2012 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 __USBUART_H -#define __USBUART_H - -#include -#include -#include "general.h" - -void usbuart_init(void); - -void usbuart_set_line_coding(struct usb_cdc_line_coding *coding); -void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep); -void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep); - -#endif diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index dcad8a0..140e8d1 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -37,17 +37,12 @@ #include "gpio.h" #include "morse.h" -#define CDCACM_PACKET_SIZE 64 #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 ")" #define DFU_IDENT "Black Magic Firmware Upgrade (F4Discovery" #define DFU_IFACE_STRING "@Internal Flash /0x08000000/1*016Ka,3*016Kg,1*064Kg,7*128Kg" -extern usbd_device *usbdev; -#define CDCACM_GDB_ENDPOINT 1 -#define CDCACM_UART_ENDPOINT 3 - /* Important pin mappings for STM32 implementation: * * LED0 = PD12 (Green LED : Running) @@ -186,15 +181,6 @@ static inline int platform_hwversion(void) return 0; } -/* */ -void cdcacm_init(void); -/* Returns current usb configuration, or 0 if not configured. */ -int cdcacm_get_config(void); -int cdcacm_get_dtr(void); - -/* */ -void uart_usb_buf_drain(uint8_t ep); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 3e269d9..3f61f5f 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -34,6 +34,7 @@ #include #include "jtag_scan.h" +#include "cdcacm.h" #include "usbuart.h" #include "morse.h" diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 2fa1e84..321c3f3 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -38,7 +38,6 @@ #include "gpio.h" #include "morse.h" -#define CDCACM_PACKET_SIZE 64 #define PLATFORM_HAS_TRACESWO #define PLATFORM_HAS_POWER_SWITCH #define BOARD_IDENT "Black Magic Probe" @@ -48,10 +47,6 @@ #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,120*001Kg" #define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" -extern usbd_device *usbdev; -#define CDCACM_GDB_ENDPOINT 1 -#define CDCACM_UART_ENDPOINT 3 - /* Important pin mappings for STM32 implementation: * * LED0 = PB2 (Yellow LED : Running) @@ -185,15 +180,6 @@ void platform_set_timeout(uint32_t ms); bool platform_timeout_expired(void); void platform_delay(uint32_t delay); -/* */ -void cdcacm_init(void); -/* Returns current usb configuration, or 0 if not configured. */ -int cdcacm_get_config(void); -int cdcacm_get_dtr(void); - -/* */ -void uart_usb_buf_drain(uint8_t ep); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index a49e73a..a33ca06 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -37,7 +37,6 @@ #include "gdb_packet.h" #include "gpio.h" -#define CDCACM_PACKET_SIZE 64 #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 ")" #define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -45,10 +44,6 @@ #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" #define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" -extern usbd_device *usbdev; -#define CDCACM_GDB_ENDPOINT 1 -#define CDCACM_UART_ENDPOINT 3 - /* Important pin mappings for STM32 implementation: * * LED0 = PB2 (Yellow LED : Running) @@ -161,15 +156,6 @@ const char *platform_target_voltage(void); void platform_delay(uint32_t delay); void platform_srst_set_val(bool assert); -/* */ -void cdcacm_init(void); -/* Returns current usb configuration, or 0 if not configured. */ -int cdcacm_get_config(void); -int cdcacm_get_dtr(void); - -/* */ -void uart_usb_buf_drain(uint8_t ep); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/stm32/cdcacm.c b/src/platforms/stm32/cdcacm.c index 9694cf0..074b534 100644 --- a/src/platforms/stm32/cdcacm.c +++ b/src/platforms/stm32/cdcacm.c @@ -35,10 +35,11 @@ #include "platform.h" #include "gdb_if.h" +#include "cdcacm.h" #if defined(PLATFORM_HAS_TRACESWO) -#include +#include "traceswo.h" #endif -#include +#include "usbuart.h" #define DFU_IF_NO 4 diff --git a/src/platforms/stm32/cdcacm.h b/src/platforms/stm32/cdcacm.h new file mode 100644 index 0000000..f64399d --- /dev/null +++ b/src/platforms/stm32/cdcacm.h @@ -0,0 +1,45 @@ +/* + * 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 . + */ + +/* This file implements a the USB Communications Device Class - Abstract + * Control Model (CDC-ACM) as defined in CDC PSTN subclass 1.2. + * A Device Firmware Upgrade (DFU 1.1) class interface is provided for + * field firmware upgrade. + * + * The device's unique id is used as the USB serial number string. + */ +#ifndef __CDCACM_H +#define __CDCACM_H + +#include + +#define CDCACM_PACKET_SIZE 64 + +#define CDCACM_GDB_ENDPOINT 1 +#define CDCACM_UART_ENDPOINT 3 + +extern usbd_device *usbdev; + +void cdcacm_init(void); +/* Returns current usb configuration, or 0 if not configured. */ +int cdcacm_get_config(void); +int cdcacm_get_dtr(void); + +#endif diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c index c8208b3..6cc9084 100644 --- a/src/platforms/stm32/gdb_if.c +++ b/src/platforms/stm32/gdb_if.c @@ -23,8 +23,7 @@ * uses the USB CDC-ACM device bulk endpoints to implement the channel. */ #include "platform.h" -#include - +#include "cdcacm.h" #include "gdb_if.h" static uint32_t count_out; diff --git a/src/platforms/stm32/traceswo.c b/src/platforms/stm32/traceswo.c index 01ad728..29bae8f 100644 --- a/src/platforms/stm32/traceswo.c +++ b/src/platforms/stm32/traceswo.c @@ -37,10 +37,9 @@ #include #include -#include - #include #include "platform.h" +#include "cdcacm.h" void traceswo_init(void) { diff --git a/src/platforms/stm32/traceswo.h b/src/platforms/stm32/traceswo.h new file mode 100644 index 0000000..5566f94 --- /dev/null +++ b/src/platforms/stm32/traceswo.h @@ -0,0 +1,28 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2012 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 __TRACESWO_H +#define __TRACESWO_H + +#include + +void traceswo_init(void); +void trace_buf_drain(usbd_device *dev, uint8_t ep); + +#endif diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index f8f56bf..970a609 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -27,7 +27,8 @@ #include #include -#include +#include "platform.h" +#include "cdcacm.h" #define USBUART_TIMER_FREQ_HZ 1000000U /* 1us per tick */ #define USBUART_RUN_FREQ_HZ 5000U /* 200us (or 100 characters at 2Mbps) */ diff --git a/src/platforms/stm32/usbuart.h b/src/platforms/stm32/usbuart.h new file mode 100644 index 0000000..39f7dcd --- /dev/null +++ b/src/platforms/stm32/usbuart.h @@ -0,0 +1,33 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2012 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 __USBUART_H +#define __USBUART_H + +#include +#include +#include "general.h" + +void usbuart_init(void); + +void usbuart_set_line_coding(struct usb_cdc_line_coding *coding); +void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep); +void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep); + +#endif diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 4b26466..26cb7a6 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -37,7 +37,6 @@ #include "gdb_packet.h" #include "gpio.h" -#define CDCACM_PACKET_SIZE 64 #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 ")" @@ -45,10 +44,6 @@ #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" #define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" -extern usbd_device *usbdev; -#define CDCACM_GDB_ENDPOINT 1 -#define CDCACM_UART_ENDPOINT 3 - /* Pin mappings: * * nTRST = PB1 @@ -158,15 +153,6 @@ int platform_init(void); const char *platform_target_voltage(void); void platform_delay(uint32_t delay); -/* */ -void cdcacm_init(void); -/* Returns current usb configuration, or 0 if not configured. */ -int cdcacm_get_config(void); -int cdcacm_get_dtr(void); - -/* */ -void uart_usb_buf_drain(uint8_t ep); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf -- 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/platforms/native/platform.h') 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 b07ffffcee53e18051b324eb59a2794044ce6f95 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Mon, 2 Mar 2015 10:16:33 -0800 Subject: Factor out common cdcacm.c from stm32 and tm4c. Cleaned up interface to enter bootloader and read serial number.--- src/Makefile | 2 +- src/include/platform_support.h | 1 + src/platforms/common/cdcacm.c | 554 ++++++++++++++++++++++++++++++ src/platforms/common/serialno.h | 26 ++ src/platforms/f4discovery/Makefile.inc | 1 + src/platforms/f4discovery/platform.c | 8 +- src/platforms/f4discovery/platform.h | 4 - src/platforms/launchpad-icdi/platform.c | 46 +++ src/platforms/launchpad-icdi/platform.h | 22 +- src/platforms/native/Makefile.inc | 1 + src/platforms/native/platform.c | 10 +- src/platforms/native/platform.h | 4 - src/platforms/stlink/Makefile.inc | 3 +- src/platforms/stlink/platform.c | 10 +- src/platforms/stlink/platform.h | 4 - src/platforms/stm32/cdcacm.c | 583 -------------------------------- src/platforms/stm32/serialno.c | 45 +++ src/platforms/swlink/Makefile.inc | 3 +- src/platforms/swlink/platform.c | 8 +- src/platforms/swlink/platform.h | 3 - src/platforms/tm4c/cdcacm.c | 577 ------------------------------- src/platforms/tm4c/traceswo.c | 1 + 22 files changed, 715 insertions(+), 1201 deletions(-) create mode 100644 src/platforms/common/cdcacm.c create mode 100644 src/platforms/common/serialno.h delete mode 100644 src/platforms/stm32/cdcacm.c create mode 100644 src/platforms/stm32/serialno.c delete mode 100644 src/platforms/tm4c/cdcacm.c (limited to 'src/platforms/native/platform.h') diff --git a/src/Makefile b/src/Makefile index 8b01854..09e0bf0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ PROBE_HOST ?= native PLATFORM_DIR = platforms/$(PROBE_HOST) -VPATH += $(PLATFORM_DIR) +VPATH += platforms/common $(PLATFORM_DIR) BUILDDATE := `date +"%Y%m%d"` diff --git a/src/include/platform_support.h b/src/include/platform_support.h index cc88ab6..7d8443c 100644 --- a/src/include/platform_support.h +++ b/src/include/platform_support.h @@ -36,6 +36,7 @@ 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); +void platform_request_boot(void); #endif diff --git a/src/platforms/common/cdcacm.c b/src/platforms/common/cdcacm.c new file mode 100644 index 0000000..8e95a9a --- /dev/null +++ b/src/platforms/common/cdcacm.c @@ -0,0 +1,554 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2011 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 . + */ + +/* This file implements a the USB Communications Device Class - Abstract + * Control Model (CDC-ACM) as defined in CDC PSTN subclass 1.2. + * A Device Firmware Upgrade (DFU 1.1) class interface is provided for + * field firmware upgrade. + * + * The device's unique id is used as the USB serial number string. + */ + +#include "general.h" +#include "gdb_if.h" +#include "cdcacm.h" +#if defined(PLATFORM_HAS_TRACESWO) +# include "traceswo.h" +#endif +#include "usbuart.h" +#include "serialno.h" + +#include +#include +#include +#include +#include +#include + +#define DFU_IF_NO 4 + +usbd_device * usbdev; + +static int configured; +static int cdcacm_gdb_dtr = 1; + + +static const struct usb_device_descriptor dev = { + .bLength = USB_DT_DEVICE_SIZE, + .bDescriptorType = USB_DT_DEVICE, + .bcdUSB = 0x0200, + .bDeviceClass = 0xEF, /* Miscellaneous Device */ + .bDeviceSubClass = 2, /* Common Class */ + .bDeviceProtocol = 1, /* Interface Association */ + .bMaxPacketSize0 = 64, + .idVendor = 0x1D50, + .idProduct = 0x6018, + .bcdDevice = 0x0100, + .iManufacturer = 1, + .iProduct = 2, + .iSerialNumber = 3, + .bNumConfigurations = 1, +}; + +/* This notification endpoint isn't implemented. According to CDC spec its + * optional, but its absence causes a NULL pointer dereference in Linux cdc_acm + * driver. */ +static const struct usb_endpoint_descriptor gdb_comm_endp[] = {{ + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x82, + .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, + .wMaxPacketSize = 16, + .bInterval = 255, +}}; + +static const struct usb_endpoint_descriptor gdb_data_endp[] = {{ + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x01, + .bmAttributes = USB_ENDPOINT_ATTR_BULK, + .wMaxPacketSize = CDCACM_PACKET_SIZE, + .bInterval = 1, +}, { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x81, + .bmAttributes = USB_ENDPOINT_ATTR_BULK, + .wMaxPacketSize = CDCACM_PACKET_SIZE, + .bInterval = 1, +}}; + +static const struct { + struct usb_cdc_header_descriptor header; + struct usb_cdc_call_management_descriptor call_mgmt; + struct usb_cdc_acm_descriptor acm; + struct usb_cdc_union_descriptor cdc_union; +} __attribute__((packed)) gdb_cdcacm_functional_descriptors = { + .header = { + .bFunctionLength = sizeof(struct usb_cdc_header_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_HEADER, + .bcdCDC = 0x0110, + }, + .call_mgmt = { + .bFunctionLength = + sizeof(struct usb_cdc_call_management_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT, + .bmCapabilities = 0, + .bDataInterface = 1, + }, + .acm = { + .bFunctionLength = sizeof(struct usb_cdc_acm_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_ACM, + .bmCapabilities = 2, /* SET_LINE_CODING supported */ + }, + .cdc_union = { + .bFunctionLength = sizeof(struct usb_cdc_union_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_UNION, + .bControlInterface = 0, + .bSubordinateInterface0 = 1, + } +}; + +static const struct usb_interface_descriptor gdb_comm_iface[] = {{ + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 0, + .bAlternateSetting = 0, + .bNumEndpoints = 1, + .bInterfaceClass = USB_CLASS_CDC, + .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, + .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, + .iInterface = 4, + + .endpoint = gdb_comm_endp, + + .extra = &gdb_cdcacm_functional_descriptors, + .extralen = sizeof(gdb_cdcacm_functional_descriptors) +}}; + +static const struct usb_interface_descriptor gdb_data_iface[] = {{ + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 1, + .bAlternateSetting = 0, + .bNumEndpoints = 2, + .bInterfaceClass = USB_CLASS_DATA, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 0, + .iInterface = 0, + + .endpoint = gdb_data_endp, +}}; + +static const struct usb_iface_assoc_descriptor gdb_assoc = { + .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, + .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, + .bFirstInterface = 0, + .bInterfaceCount = 2, + .bFunctionClass = USB_CLASS_CDC, + .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, + .bFunctionProtocol = USB_CDC_PROTOCOL_AT, + .iFunction = 0, +}; + +/* Serial ACM interface */ +static const struct usb_endpoint_descriptor uart_comm_endp[] = {{ + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x84, + .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, + .wMaxPacketSize = 16, + .bInterval = 255, +}}; + +static const struct usb_endpoint_descriptor uart_data_endp[] = {{ + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x03, + .bmAttributes = USB_ENDPOINT_ATTR_BULK, + .wMaxPacketSize = CDCACM_PACKET_SIZE, + .bInterval = 1, +}, { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x83, + .bmAttributes = USB_ENDPOINT_ATTR_BULK, + .wMaxPacketSize = CDCACM_PACKET_SIZE, + .bInterval = 1, +}}; + +static const struct { + struct usb_cdc_header_descriptor header; + struct usb_cdc_call_management_descriptor call_mgmt; + struct usb_cdc_acm_descriptor acm; + struct usb_cdc_union_descriptor cdc_union; +} __attribute__((packed)) uart_cdcacm_functional_descriptors = { + .header = { + .bFunctionLength = sizeof(struct usb_cdc_header_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_HEADER, + .bcdCDC = 0x0110, + }, + .call_mgmt = { + .bFunctionLength = + sizeof(struct usb_cdc_call_management_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT, + .bmCapabilities = 0, + .bDataInterface = 3, + }, + .acm = { + .bFunctionLength = sizeof(struct usb_cdc_acm_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_ACM, + .bmCapabilities = 2, /* SET_LINE_CODING supported*/ + }, + .cdc_union = { + .bFunctionLength = sizeof(struct usb_cdc_union_descriptor), + .bDescriptorType = CS_INTERFACE, + .bDescriptorSubtype = USB_CDC_TYPE_UNION, + .bControlInterface = 2, + .bSubordinateInterface0 = 3, + } +}; + +static const struct usb_interface_descriptor uart_comm_iface[] = {{ + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 2, + .bAlternateSetting = 0, + .bNumEndpoints = 1, + .bInterfaceClass = USB_CLASS_CDC, + .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, + .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, + .iInterface = 5, + + .endpoint = uart_comm_endp, + + .extra = &uart_cdcacm_functional_descriptors, + .extralen = sizeof(uart_cdcacm_functional_descriptors) +}}; + +static const struct usb_interface_descriptor uart_data_iface[] = {{ + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 3, + .bAlternateSetting = 0, + .bNumEndpoints = 2, + .bInterfaceClass = USB_CLASS_DATA, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 0, + .iInterface = 0, + + .endpoint = uart_data_endp, +}}; + +static const struct usb_iface_assoc_descriptor uart_assoc = { + .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, + .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, + .bFirstInterface = 2, + .bInterfaceCount = 2, + .bFunctionClass = USB_CLASS_CDC, + .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, + .bFunctionProtocol = USB_CDC_PROTOCOL_AT, + .iFunction = 0, +}; + +const struct usb_dfu_descriptor dfu_function = { + .bLength = sizeof(struct usb_dfu_descriptor), + .bDescriptorType = DFU_FUNCTIONAL, + .bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH, + .wDetachTimeout = 255, + .wTransferSize = 1024, + .bcdDFUVersion = 0x011A, +}; + +const struct usb_interface_descriptor dfu_iface = { + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = DFU_IF_NO, + .bAlternateSetting = 0, + .bNumEndpoints = 0, + .bInterfaceClass = 0xFE, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 1, + .iInterface = 6, + + .extra = &dfu_function, + .extralen = sizeof(dfu_function), +}; + +static const struct usb_iface_assoc_descriptor dfu_assoc = { + .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, + .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, + .bFirstInterface = 4, + .bInterfaceCount = 1, + .bFunctionClass = 0xFE, + .bFunctionSubClass = 1, + .bFunctionProtocol = 1, + .iFunction = 6, +}; + +#if defined(PLATFORM_HAS_TRACESWO) +static const struct usb_endpoint_descriptor trace_endp[] = {{ + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bEndpointAddress = 0x85, + .bmAttributes = USB_ENDPOINT_ATTR_BULK, + .wMaxPacketSize = 64, + .bInterval = 0, +}}; + +const struct usb_interface_descriptor trace_iface = { + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bInterfaceNumber = 5, + .bAlternateSetting = 0, + .bNumEndpoints = 1, + .bInterfaceClass = 0xFF, + .bInterfaceSubClass = 0xFF, + .bInterfaceProtocol = 0xFF, + .iInterface = 7, + + .endpoint = trace_endp, +}; + +static const struct usb_iface_assoc_descriptor trace_assoc = { + .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, + .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, + .bFirstInterface = 5, + .bInterfaceCount = 1, + .bFunctionClass = 0xFF, + .bFunctionSubClass = 0xFF, + .bFunctionProtocol = 0xFF, + .iFunction = 7, +}; +#endif + +static const struct usb_interface ifaces[] = {{ + .num_altsetting = 1, + .iface_assoc = &gdb_assoc, + .altsetting = gdb_comm_iface, +}, { + .num_altsetting = 1, + .altsetting = gdb_data_iface, +}, { + .num_altsetting = 1, + .iface_assoc = &uart_assoc, + .altsetting = uart_comm_iface, +}, { + .num_altsetting = 1, + .altsetting = uart_data_iface, +}, { + .num_altsetting = 1, + .iface_assoc = &dfu_assoc, + .altsetting = &dfu_iface, +#if defined(PLATFORM_HAS_TRACESWO) +}, { + .num_altsetting = 1, + .iface_assoc = &trace_assoc, + .altsetting = &trace_iface, +#endif +}}; + +static const struct usb_config_descriptor config = { + .bLength = USB_DT_CONFIGURATION_SIZE, + .bDescriptorType = USB_DT_CONFIGURATION, + .wTotalLength = 0, +#if defined(PLATFORM_HAS_TRACESWO) + .bNumInterfaces = 6, +#else + .bNumInterfaces = 5, +#endif + .bConfigurationValue = 1, + .iConfiguration = 0, + .bmAttributes = 0x80, + .bMaxPower = 0x32, + + .interface = ifaces, +}; + +char serial_no[9]; + +static const char *usb_strings[] = { + "Black Sphere Technologies", + BOARD_IDENT, + serial_no, + "Black Magic GDB Server", + "Black Magic UART Port", + DFU_IDENT, +#if defined(PLATFORM_HAS_TRACESWO) + "Black Magic Trace Capture", +#endif +}; + +static void dfu_detach_complete(usbd_device *dev, struct usb_setup_data *req) +{ + (void)dev; + (void)req; + + platform_request_boot(); + + /* Reset core to enter bootloader */ + scb_reset_core(); +} + +static int cdcacm_control_request(usbd_device *dev, + struct usb_setup_data *req, uint8_t **buf, uint16_t *len, + void (**complete)(usbd_device *dev, struct usb_setup_data *req)) +{ + (void)dev; + (void)complete; + (void)buf; + (void)len; + + switch(req->bRequest) { + case USB_CDC_REQ_SET_CONTROL_LINE_STATE: + /* Ignore if not for GDB interface */ + if(req->wIndex != 0) + return 1; + + cdcacm_gdb_dtr = req->wValue & 1; + + return 1; + case USB_CDC_REQ_SET_LINE_CODING: + if(*len < sizeof(struct usb_cdc_line_coding)) + return 0; + + switch(req->wIndex) { + case 2: + usbuart_set_line_coding((struct usb_cdc_line_coding*)*buf); + case 0: + return 1; /* Ignore on GDB Port */ + default: + return 0; + } + case DFU_GETSTATUS: + if(req->wIndex == DFU_IF_NO) { + (*buf)[0] = DFU_STATUS_OK; + (*buf)[1] = 0; + (*buf)[2] = 0; + (*buf)[3] = 0; + (*buf)[4] = STATE_APP_IDLE; + (*buf)[5] = 0; /* iString not used here */ + *len = 6; + + return 1; + } + case DFU_DETACH: + if(req->wIndex == DFU_IF_NO) { + *complete = dfu_detach_complete; + return 1; + } + return 0; + } + return 0; +} + +int cdcacm_get_config(void) +{ + return configured; +} + +int cdcacm_get_dtr(void) +{ + return cdcacm_gdb_dtr; +} + +static void cdcacm_set_config(usbd_device *dev, uint16_t wValue) +{ + configured = wValue; + + /* GDB interface */ +#ifdef STM32F4 + usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, + CDCACM_PACKET_SIZE, gdb_usb_out_cb); +#else + usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, + CDCACM_PACKET_SIZE, NULL); +#endif + usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_BULK, + CDCACM_PACKET_SIZE, NULL); + usbd_ep_setup(dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); + + /* Serial interface */ + usbd_ep_setup(dev, 0x03, USB_ENDPOINT_ATTR_BULK, + CDCACM_PACKET_SIZE, usbuart_usb_out_cb); + usbd_ep_setup(dev, 0x83, USB_ENDPOINT_ATTR_BULK, + CDCACM_PACKET_SIZE, usbuart_usb_in_cb); + usbd_ep_setup(dev, 0x84, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); + +#if defined(PLATFORM_HAS_TRACESWO) + /* Trace interface */ + usbd_ep_setup(dev, 0x85, USB_ENDPOINT_ATTR_BULK, + 64, trace_buf_drain); +#endif + + usbd_register_control_callback(dev, + USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, + USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, + cdcacm_control_request); + + /* Notify the host that DCD is asserted. + * Allows the use of /dev/tty* devices on *BSD/MacOS + */ + char buf[10]; + struct usb_cdc_notification *notif = (void*)buf; + /* We echo signals back to host as notification */ + notif->bmRequestType = 0xA1; + notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE; + notif->wValue = 0; + notif->wIndex = 0; + notif->wLength = 2; + buf[8] = 3; /* DCD | DSR */ + buf[9] = 0; + usbd_ep_write_packet(dev, 0x82, buf, 10); + notif->wIndex = 2; + usbd_ep_write_packet(dev, 0x84, buf, 10); +} + +/* We need a special large control buffer for this device: */ +uint8_t usbd_control_buffer[256]; + +void cdcacm_init(void) +{ + void exti15_10_isr(void); + + serialno_read(serial_no); + + usbdev = usbd_init(&USB_DRIVER, &dev, &config, usb_strings, + sizeof(usb_strings)/sizeof(char *), + usbd_control_buffer, sizeof(usbd_control_buffer)); + + usbd_register_set_config_callback(usbdev, cdcacm_set_config); + + nvic_set_priority(USB_IRQ, IRQ_PRI_USB); + nvic_enable_irq(USB_IRQ); +} + +void USB_ISR(void) +{ + usbd_poll(usbdev); +} + diff --git a/src/platforms/common/serialno.h b/src/platforms/common/serialno.h new file mode 100644 index 0000000..946dc20 --- /dev/null +++ b/src/platforms/common/serialno.h @@ -0,0 +1,26 @@ +/* + * 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 __SERIALNO_H +#define __SERIALNO_H + +char *serialno_read(char *s); + +#endif + diff --git a/src/platforms/f4discovery/Makefile.inc b/src/platforms/f4discovery/Makefile.inc index 88575bb..21b4078 100644 --- a/src/platforms/f4discovery/Makefile.inc +++ b/src/platforms/f4discovery/Makefile.inc @@ -19,6 +19,7 @@ SRC += cdcacm.c \ platform.c \ traceswo.c \ usbuart.c \ + serialno.c \ all: blackmagic.bin diff --git a/src/platforms/f4discovery/platform.c b/src/platforms/f4discovery/platform.c index cf6cdf3..6e10ff4 100644 --- a/src/platforms/f4discovery/platform.c +++ b/src/platforms/f4discovery/platform.c @@ -46,7 +46,7 @@ void platform_init(void) /* Check the USER button*/ rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); if(gpio_get(GPIOA, GPIO0)) { - assert_boot_pin(); + platform_request_boot(); scb_reset_core(); } @@ -111,8 +111,12 @@ const char *platform_target_voltage(void) return "ABSENT!"; } -void assert_boot_pin(void) +void platform_request_boot(void) { + /* Disconnect USB cable */ + usbd_disconnect(usbdev, 1); + nvic_disable_irq(USB_IRQ); + /* Assert blue LED as indicator we are in the bootloader */ rcc_peripheral_enable_clock(&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN); gpio_mode_setup(LED_PORT, GPIO_MODE_OUTPUT, diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index f58205d..61753af 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -176,9 +176,5 @@ static inline int platform_hwversion(void) #define sprintf siprintf #define vasprintf vasiprintf -#define disconnect_usb() do {usbd_disconnect(usbdev,1); nvic_disable_irq(USB_IRQ);} while(0) -void assert_boot_pin(void); -#define setup_vbus_irq() - #endif diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index 0e3fb85..e689f0c 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -1,3 +1,19 @@ +/* + * 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 "gdb_if.h" #include "cdcacm.h" @@ -7,6 +23,7 @@ #include #include #include +#include #define SYSTICKHZ 100 #define SYSTICKMS (1000 / SYSTICKHZ) @@ -58,6 +75,13 @@ platform_init(void) nvic_enable_irq(NVIC_SYSTICK_IRQ); nvic_enable_irq(NVIC_UART0_IRQ); + periph_clock_enable(RCC_GPIOD); + __asm__("nop"); __asm__("nop"); __asm__("nop"); + gpio_mode_setup(GPIOD_BASE, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO4|GPIO5); + usb_enable_interrupts(USB_INT_RESET | USB_INT_DISCON | + USB_INT_RESUME | USB_INT_SUSPEND, + 0xff, 0xff); + usbuart_init(); cdcacm_init(); } @@ -73,3 +97,25 @@ const char *platform_target_voltage(void) return "not supported"; } +char *serialno_read(char *s) +{ + /* FIXME: Store a unique serial number somewhere and retreive here */ + uint32_t unique_id = 1; + int i; + + /* Fetch serial number from chip's unique ID */ + for(i = 0; i < 8; i++) { + s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; + } + for(i = 0; i < 8; i++) + if(s[i] > '9') + s[i] += 'A' - '9' - 1; + s[8] = 0; + + return s; +} + +void platform_request_boot(void) +{ +} + diff --git a/src/platforms/launchpad-icdi/platform.h b/src/platforms/launchpad-icdi/platform.h index 5f686f4..eb3ac6e 100644 --- a/src/platforms/launchpad-icdi/platform.h +++ b/src/platforms/launchpad-icdi/platform.h @@ -1,3 +1,19 @@ +/* + * 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 . + */ #ifndef __PLATFORM_H #define __PLATFORM_H @@ -8,16 +24,11 @@ #include #include -#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 ")" #define DFU_IDENT "Black Magic Firmware Upgrade (Launchpad)" #define DFU_IFACE_STRING "lolwut" -extern usbd_device *usbdev; -#define CDCACM_GDB_ENDPOINT 1 -#define CDCACM_UART_ENDPOINT 3 - extern jmp_buf fatal_error_jmpbuf; extern uint8_t running_status; extern volatile uint32_t timeout_counter; @@ -116,6 +127,5 @@ inline static uint8_t gpio_get(uint32_t port, uint8_t pin) { } #define disconnect_usb() do { usbd_disconnect(usbdev,1); nvic_disable_irq(USB_IRQ);} while(0) -#define setup_vbus_irq() #endif diff --git a/src/platforms/native/Makefile.inc b/src/platforms/native/Makefile.inc index cc4da0b..2270ff5 100644 --- a/src/platforms/native/Makefile.inc +++ b/src/platforms/native/Makefile.inc @@ -18,6 +18,7 @@ SRC += cdcacm.c \ platform.c \ traceswo.c \ usbuart.c \ + serialno.c \ all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 9b39238..5c28747 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -42,6 +42,7 @@ volatile uint32_t timeout_counter; jmp_buf fatal_error_jmpbuf; static void adc_init(void); +static void setup_vbus_irq(void); /* Pins PB[7:5] are used to detect hardware revision. * 000 - Original production build. @@ -134,6 +135,7 @@ void platform_init(void) cdcacm_init(); usbuart_init(); + setup_vbus_irq(); } void platform_srst_set_val(bool assert) @@ -221,8 +223,12 @@ const char *platform_target_voltage(void) return ret; } -void assert_boot_pin(void) +void platform_request_boot(void) { + /* Disconnect USB cable */ + gpio_set_mode(USB_PU_PORT, GPIO_MODE_INPUT, 0, USB_PU_PIN); + + /* Drive boot request pin */ gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12); gpio_clear(GPIOB, GPIO12); @@ -243,7 +249,7 @@ void exti15_10_isr(void) exti_reset_request(USB_VBUS_PIN); } -void setup_vbus_irq(void) +static void setup_vbus_irq(void) { nvic_set_priority(USB_VBUS_IRQ, IRQ_PRI_USB_VBUS); nvic_enable_irq(USB_VBUS_IRQ); diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 5688e60..c0b4dba 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -170,9 +170,5 @@ extern jmp_buf fatal_error_jmpbuf; #define sprintf siprintf #define vasprintf vasiprintf -#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); - #endif diff --git a/src/platforms/stlink/Makefile.inc b/src/platforms/stlink/Makefile.inc index 5cfe726..52ad33b 100644 --- a/src/platforms/stlink/Makefile.inc +++ b/src/platforms/stlink/Makefile.inc @@ -16,7 +16,8 @@ VPATH += platforms/stm32 SRC += cdcacm.c \ platform.c \ - usbuart.c \ + usbuart.c \ + serialno.c \ all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex dfu_upgrade.bin dfu_upgrade.hex diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index 6194d92..446fb47 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -149,7 +149,7 @@ const char *platform_target_voltage(void) return "unknown"; } -void disconnect_usb(void) +void platform_request_boot(void) { /* Disconnect USB cable by resetting USB Device and pulling USB_DP low*/ rcc_periph_reset_pulse(RST_USB); @@ -158,10 +158,8 @@ void disconnect_usb(void) gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); -} -void assert_boot_pin(void) -{ + /* Assert bootloader pin */ uint32_t crl = GPIOA_CRL; rcc_periph_clock_enable(RCC_GPIOA); /* Enable Pull on GPIOA1. We don't rely on the external pin @@ -173,7 +171,3 @@ void assert_boot_pin(void) GPIOA_CRL = crl; } -void setup_vbus_irq(void) -{ -} - diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index 5768817..fcbe259 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -152,9 +152,5 @@ extern uint16_t led_idle_run; #define sprintf siprintf #define vasprintf vasiprintf -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 deleted file mode 100644 index 577925a..0000000 --- a/src/platforms/stm32/cdcacm.c +++ /dev/null @@ -1,583 +0,0 @@ -/* - * This file is part of the Black Magic Debug project. - * - * Copyright (C) 2011 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 . - */ - -/* This file implements a the USB Communications Device Class - Abstract - * Control Model (CDC-ACM) as defined in CDC PSTN subclass 1.2. - * A Device Firmware Upgrade (DFU 1.1) class interface is provided for - * field firmware upgrade. - * - * The device's unique id is used as the USB serial number string. - */ - -#include -#include -#include -#include -#include -#include - -#include "general.h" -#include "gdb_if.h" -#include "cdcacm.h" -#if defined(PLATFORM_HAS_TRACESWO) -#include "traceswo.h" -#endif -#include "usbuart.h" - -#define DFU_IF_NO 4 - -usbd_device * usbdev; - -static char *get_dev_unique_id(char *serial_no); - -static int configured; -static int cdcacm_gdb_dtr = 1; - - -static const struct usb_device_descriptor dev = { - .bLength = USB_DT_DEVICE_SIZE, - .bDescriptorType = USB_DT_DEVICE, - .bcdUSB = 0x0200, - .bDeviceClass = 0xEF, /* Miscellaneous Device */ - .bDeviceSubClass = 2, /* Common Class */ - .bDeviceProtocol = 1, /* Interface Association */ - .bMaxPacketSize0 = 64, - .idVendor = 0x1D50, - .idProduct = 0x6018, - .bcdDevice = 0x0100, - .iManufacturer = 1, - .iProduct = 2, - .iSerialNumber = 3, - .bNumConfigurations = 1, -}; - -/* This notification endpoint isn't implemented. According to CDC spec its - * optional, but its absence causes a NULL pointer dereference in Linux cdc_acm - * driver. */ -static const struct usb_endpoint_descriptor gdb_comm_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x82, - .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, - .wMaxPacketSize = 16, - .bInterval = 255, -}}; - -static const struct usb_endpoint_descriptor gdb_data_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x01, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = CDCACM_PACKET_SIZE, - .bInterval = 1, -}, { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x81, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = CDCACM_PACKET_SIZE, - .bInterval = 1, -}}; - -static const struct { - struct usb_cdc_header_descriptor header; - struct usb_cdc_call_management_descriptor call_mgmt; - struct usb_cdc_acm_descriptor acm; - struct usb_cdc_union_descriptor cdc_union; -} __attribute__((packed)) gdb_cdcacm_functional_descriptors = { - .header = { - .bFunctionLength = sizeof(struct usb_cdc_header_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_HEADER, - .bcdCDC = 0x0110, - }, - .call_mgmt = { - .bFunctionLength = - sizeof(struct usb_cdc_call_management_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT, - .bmCapabilities = 0, - .bDataInterface = 1, - }, - .acm = { - .bFunctionLength = sizeof(struct usb_cdc_acm_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_ACM, - .bmCapabilities = 2, /* SET_LINE_CODING supported */ - }, - .cdc_union = { - .bFunctionLength = sizeof(struct usb_cdc_union_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_UNION, - .bControlInterface = 0, - .bSubordinateInterface0 = 1, - } -}; - -static const struct usb_interface_descriptor gdb_comm_iface[] = {{ - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 0, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_CLASS_CDC, - .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, - .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, - .iInterface = 4, - - .endpoint = gdb_comm_endp, - - .extra = &gdb_cdcacm_functional_descriptors, - .extralen = sizeof(gdb_cdcacm_functional_descriptors) -}}; - -static const struct usb_interface_descriptor gdb_data_iface[] = {{ - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 1, - .bAlternateSetting = 0, - .bNumEndpoints = 2, - .bInterfaceClass = USB_CLASS_DATA, - .bInterfaceSubClass = 0, - .bInterfaceProtocol = 0, - .iInterface = 0, - - .endpoint = gdb_data_endp, -}}; - -static const struct usb_iface_assoc_descriptor gdb_assoc = { - .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, - .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, - .bFirstInterface = 0, - .bInterfaceCount = 2, - .bFunctionClass = USB_CLASS_CDC, - .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, - .bFunctionProtocol = USB_CDC_PROTOCOL_AT, - .iFunction = 0, -}; - -/* Serial ACM interface */ -static const struct usb_endpoint_descriptor uart_comm_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x84, - .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, - .wMaxPacketSize = 16, - .bInterval = 255, -}}; - -static const struct usb_endpoint_descriptor uart_data_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x03, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = CDCACM_PACKET_SIZE, - .bInterval = 1, -}, { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x83, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = CDCACM_PACKET_SIZE, - .bInterval = 1, -}}; - -static const struct { - struct usb_cdc_header_descriptor header; - struct usb_cdc_call_management_descriptor call_mgmt; - struct usb_cdc_acm_descriptor acm; - struct usb_cdc_union_descriptor cdc_union; -} __attribute__((packed)) uart_cdcacm_functional_descriptors = { - .header = { - .bFunctionLength = sizeof(struct usb_cdc_header_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_HEADER, - .bcdCDC = 0x0110, - }, - .call_mgmt = { - .bFunctionLength = - sizeof(struct usb_cdc_call_management_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT, - .bmCapabilities = 0, - .bDataInterface = 3, - }, - .acm = { - .bFunctionLength = sizeof(struct usb_cdc_acm_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_ACM, - .bmCapabilities = 2, /* SET_LINE_CODING supported*/ - }, - .cdc_union = { - .bFunctionLength = sizeof(struct usb_cdc_union_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_UNION, - .bControlInterface = 2, - .bSubordinateInterface0 = 3, - } -}; - -static const struct usb_interface_descriptor uart_comm_iface[] = {{ - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 2, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_CLASS_CDC, - .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, - .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, - .iInterface = 5, - - .endpoint = uart_comm_endp, - - .extra = &uart_cdcacm_functional_descriptors, - .extralen = sizeof(uart_cdcacm_functional_descriptors) -}}; - -static const struct usb_interface_descriptor uart_data_iface[] = {{ - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 3, - .bAlternateSetting = 0, - .bNumEndpoints = 2, - .bInterfaceClass = USB_CLASS_DATA, - .bInterfaceSubClass = 0, - .bInterfaceProtocol = 0, - .iInterface = 0, - - .endpoint = uart_data_endp, -}}; - -static const struct usb_iface_assoc_descriptor uart_assoc = { - .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, - .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, - .bFirstInterface = 2, - .bInterfaceCount = 2, - .bFunctionClass = USB_CLASS_CDC, - .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, - .bFunctionProtocol = USB_CDC_PROTOCOL_AT, - .iFunction = 0, -}; - -const struct usb_dfu_descriptor dfu_function = { - .bLength = sizeof(struct usb_dfu_descriptor), - .bDescriptorType = DFU_FUNCTIONAL, - .bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH, - .wDetachTimeout = 255, - .wTransferSize = 1024, - .bcdDFUVersion = 0x011A, -}; - -const struct usb_interface_descriptor dfu_iface = { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = DFU_IF_NO, - .bAlternateSetting = 0, - .bNumEndpoints = 0, - .bInterfaceClass = 0xFE, - .bInterfaceSubClass = 1, - .bInterfaceProtocol = 1, - .iInterface = 6, - - .extra = &dfu_function, - .extralen = sizeof(dfu_function), -}; - -static const struct usb_iface_assoc_descriptor dfu_assoc = { - .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, - .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, - .bFirstInterface = 4, - .bInterfaceCount = 1, - .bFunctionClass = 0xFE, - .bFunctionSubClass = 1, - .bFunctionProtocol = 1, - .iFunction = 6, -}; - -#if defined(PLATFORM_HAS_TRACESWO) -static const struct usb_endpoint_descriptor trace_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x85, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = 64, - .bInterval = 0, -}}; - -const struct usb_interface_descriptor trace_iface = { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 5, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = 0xFF, - .bInterfaceSubClass = 0xFF, - .bInterfaceProtocol = 0xFF, - .iInterface = 7, - - .endpoint = trace_endp, -}; - -static const struct usb_iface_assoc_descriptor trace_assoc = { - .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, - .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, - .bFirstInterface = 5, - .bInterfaceCount = 1, - .bFunctionClass = 0xFF, - .bFunctionSubClass = 0xFF, - .bFunctionProtocol = 0xFF, - .iFunction = 7, -}; -#endif - -static const struct usb_interface ifaces[] = {{ - .num_altsetting = 1, - .iface_assoc = &gdb_assoc, - .altsetting = gdb_comm_iface, -}, { - .num_altsetting = 1, - .altsetting = gdb_data_iface, -}, { - .num_altsetting = 1, - .iface_assoc = &uart_assoc, - .altsetting = uart_comm_iface, -}, { - .num_altsetting = 1, - .altsetting = uart_data_iface, -}, { - .num_altsetting = 1, - .iface_assoc = &dfu_assoc, - .altsetting = &dfu_iface, -#if defined(PLATFORM_HAS_TRACESWO) -}, { - .num_altsetting = 1, - .iface_assoc = &trace_assoc, - .altsetting = &trace_iface, -#endif -}}; - -static const struct usb_config_descriptor config = { - .bLength = USB_DT_CONFIGURATION_SIZE, - .bDescriptorType = USB_DT_CONFIGURATION, - .wTotalLength = 0, -#if defined(PLATFORM_HAS_TRACESWO) - .bNumInterfaces = 6, -#else - .bNumInterfaces = 5, -#endif - .bConfigurationValue = 1, - .iConfiguration = 0, - .bmAttributes = 0x80, - .bMaxPower = 0x32, - - .interface = ifaces, -}; - -char serial_no[9]; - -static const char *usb_strings[] = { - "Black Sphere Technologies", - BOARD_IDENT, - serial_no, - "Black Magic GDB Server", - "Black Magic UART Port", - DFU_IDENT, -#if defined(PLATFORM_HAS_TRACESWO) - "Black Magic Trace Capture", -#endif -}; - -static void dfu_detach_complete(usbd_device *dev, struct usb_setup_data *req) -{ - (void)dev; - (void)req; - - /* Disconnect USB cable */ - disconnect_usb(); - - /* Assert boot-request pin */ - assert_boot_pin(); - - /* Reset core to enter bootloader */ - scb_reset_core(); -} - -static int cdcacm_control_request(usbd_device *dev, - struct usb_setup_data *req, uint8_t **buf, uint16_t *len, - void (**complete)(usbd_device *dev, struct usb_setup_data *req)) -{ - (void)dev; - (void)complete; - (void)buf; - (void)len; - - switch(req->bRequest) { - case USB_CDC_REQ_SET_CONTROL_LINE_STATE: - /* Ignore if not for GDB interface */ - if(req->wIndex != 0) - return 1; - - cdcacm_gdb_dtr = req->wValue & 1; - - return 1; - case USB_CDC_REQ_SET_LINE_CODING: - if(*len < sizeof(struct usb_cdc_line_coding)) - return 0; - - switch(req->wIndex) { - case 2: - usbuart_set_line_coding((struct usb_cdc_line_coding*)*buf); - case 0: - return 1; /* Ignore on GDB Port */ - default: - return 0; - } - case DFU_GETSTATUS: - if(req->wIndex == DFU_IF_NO) { - (*buf)[0] = DFU_STATUS_OK; - (*buf)[1] = 0; - (*buf)[2] = 0; - (*buf)[3] = 0; - (*buf)[4] = STATE_APP_IDLE; - (*buf)[5] = 0; /* iString not used here */ - *len = 6; - - return 1; - } - case DFU_DETACH: - if(req->wIndex == DFU_IF_NO) { - *complete = dfu_detach_complete; - return 1; - } - return 0; - } - return 0; -} - -int cdcacm_get_config(void) -{ - return configured; -} - -int cdcacm_get_dtr(void) -{ - return cdcacm_gdb_dtr; -} - -static void cdcacm_set_config(usbd_device *dev, uint16_t wValue) -{ - configured = wValue; - - /* GDB interface */ -#ifdef STM32F4 - usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, gdb_usb_out_cb); -#else - usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, NULL); -#endif - usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, NULL); - usbd_ep_setup(dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); - - /* Serial interface */ - usbd_ep_setup(dev, 0x03, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, usbuart_usb_out_cb); - usbd_ep_setup(dev, 0x83, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, usbuart_usb_in_cb); - usbd_ep_setup(dev, 0x84, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); - -#if defined(PLATFORM_HAS_TRACESWO) - /* Trace interface */ - usbd_ep_setup(dev, 0x85, USB_ENDPOINT_ATTR_BULK, - 64, trace_buf_drain); -#endif - - usbd_register_control_callback(dev, - USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, - USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, - cdcacm_control_request); - - /* Notify the host that DCD is asserted. - * Allows the use of /dev/tty* devices on *BSD/MacOS - */ - char buf[10]; - struct usb_cdc_notification *notif = (void*)buf; - /* We echo signals back to host as notification */ - notif->bmRequestType = 0xA1; - notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE; - notif->wValue = 0; - notif->wIndex = 0; - notif->wLength = 2; - buf[8] = 3; /* DCD | DSR */ - buf[9] = 0; - usbd_ep_write_packet(dev, 0x82, buf, 10); - notif->wIndex = 2; - usbd_ep_write_packet(dev, 0x84, buf, 10); -} - -/* We need a special large control buffer for this device: */ -uint8_t usbd_control_buffer[256]; - -void cdcacm_init(void) -{ - void exti15_10_isr(void); - - get_dev_unique_id(serial_no); - - usbdev = usbd_init(&USB_DRIVER, &dev, &config, usb_strings, - sizeof(usb_strings)/sizeof(char *), - usbd_control_buffer, sizeof(usbd_control_buffer)); - - usbd_register_set_config_callback(usbdev, cdcacm_set_config); - - nvic_set_priority(USB_IRQ, IRQ_PRI_USB); - nvic_enable_irq(USB_IRQ); - setup_vbus_irq(); -} - -void USB_ISR(void) -{ - usbd_poll(usbdev); -} - -static char *get_dev_unique_id(char *s) -{ -#if defined(STM32F4) - volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFF7A10; -#else - volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8; -#endif - uint32_t unique_id = *unique_id_p + - *(unique_id_p + 1) + - *(unique_id_p + 2); - int i; - - /* Fetch serial number from chip's unique ID */ - for(i = 0; i < 8; i++) { - s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; - } - for(i = 0; i < 8; i++) - if(s[i] > '9') - s[i] += 'A' - '9' - 1; - s[8] = 0; - - return s; -} diff --git a/src/platforms/stm32/serialno.c b/src/platforms/stm32/serialno.c new file mode 100644 index 0000000..ef28ed2 --- /dev/null +++ b/src/platforms/stm32/serialno.c @@ -0,0 +1,45 @@ +/* + * 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" + +char *serialno_read(char *s) +{ +#if defined(STM32F4) + volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFF7A10; +#else + volatile uint32_t *unique_id_p = (volatile uint32_t *)0x1FFFF7E8; +#endif + uint32_t unique_id = *unique_id_p + + *(unique_id_p + 1) + + *(unique_id_p + 2); + int i; + + /* Fetch serial number from chip's unique ID */ + for(i = 0; i < 8; i++) { + s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; + } + for(i = 0; i < 8; i++) + if(s[i] > '9') + s[i] += 'A' - '9' - 1; + s[8] = 0; + + return s; +} + diff --git a/src/platforms/swlink/Makefile.inc b/src/platforms/swlink/Makefile.inc index ff349db..b68b1ab 100644 --- a/src/platforms/swlink/Makefile.inc +++ b/src/platforms/swlink/Makefile.inc @@ -16,7 +16,8 @@ VPATH += platforms/stm32 SRC += cdcacm.c \ platform.c \ - usbuart.c \ + usbuart.c \ + serialno.c \ all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 168ba2a..1b9a76e 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -118,7 +118,7 @@ const char *platform_target_voltage(void) return "unknown"; } -void disconnect_usb(void) +void platform_request_boot(void) { /* Disconnect USB cable by resetting USB Device and pulling USB_DP low*/ rcc_periph_reset_pulse(RST_USB); @@ -127,10 +127,8 @@ void disconnect_usb(void) gpio_clear(GPIOA, GPIO12); gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12); -} -void assert_boot_pin(void) -{ + /* Assert bootloader pin */ uint32_t crl = GPIOA_CRL; rcc_periph_clock_enable(RCC_GPIOA); /* Enable Pull on GPIOA1. We don't rely on the external pin @@ -141,4 +139,4 @@ void assert_boot_pin(void) crl |= 0x80; GPIOA_CRL = crl; } -void setup_vbus_irq(void){}; + diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index dec5548..6ee4a9c 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -146,8 +146,5 @@ extern jmp_buf fatal_error_jmpbuf; #define sprintf siprintf #define vasprintf vasiprintf -void disconnect_usb(void); -void assert_boot_pin(void); - #endif diff --git a/src/platforms/tm4c/cdcacm.c b/src/platforms/tm4c/cdcacm.c deleted file mode 100644 index 2677ad5..0000000 --- a/src/platforms/tm4c/cdcacm.c +++ /dev/null @@ -1,577 +0,0 @@ -/* - * This file is part of the Black Magic Debug project. - * - * Copyright (C) 2011 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 . - */ - -/* This file implements a the USB Communications Device Class - Abstract - * Control Model (CDC-ACM) as defined in CDC PSTN subclass 1.2. - * A Device Firmware Upgrade (DFU 1.1) class interface is provided for - * field firmware upgrade. - * - * The device's unique id is used as the USB serial number string. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "general.h" -#include "gdb_if.h" -#if defined(PLATFORM_HAS_TRACESWO) -#include -#endif -#include - -#define DFU_IF_NO 4 - -usbd_device * usbdev; - -static char *get_dev_unique_id(char *serial_no); - -static int configured; -static int cdcacm_gdb_dtr = 1; - - -static const struct usb_device_descriptor dev = { - .bLength = USB_DT_DEVICE_SIZE, - .bDescriptorType = USB_DT_DEVICE, - .bcdUSB = 0x0200, - .bDeviceClass = 0xEF, /* Miscellaneous Device */ - .bDeviceSubClass = 2, /* Common Class */ - .bDeviceProtocol = 1, /* Interface Association */ - .bMaxPacketSize0 = 64, - .idVendor = 0x1D50, - .idProduct = 0x6018, - .bcdDevice = 0x0100, - .iManufacturer = 1, - .iProduct = 2, - .iSerialNumber = 3, - .bNumConfigurations = 1, -}; - -/* This notification endpoint isn't implemented. According to CDC spec its - * optional, but its absence causes a NULL pointer dereference in Linux cdc_acm - * driver. */ -static const struct usb_endpoint_descriptor gdb_comm_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x82, - .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, - .wMaxPacketSize = 16, - .bInterval = 255, -}}; - -static const struct usb_endpoint_descriptor gdb_data_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x01, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = CDCACM_PACKET_SIZE, - .bInterval = 1, -}, { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x81, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = CDCACM_PACKET_SIZE, - .bInterval = 1, -}}; - -static const struct { - struct usb_cdc_header_descriptor header; - struct usb_cdc_call_management_descriptor call_mgmt; - struct usb_cdc_acm_descriptor acm; - struct usb_cdc_union_descriptor cdc_union; -} __attribute__((packed)) gdb_cdcacm_functional_descriptors = { - .header = { - .bFunctionLength = sizeof(struct usb_cdc_header_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_HEADER, - .bcdCDC = 0x0110, - }, - .call_mgmt = { - .bFunctionLength = - sizeof(struct usb_cdc_call_management_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT, - .bmCapabilities = 0, - .bDataInterface = 1, - }, - .acm = { - .bFunctionLength = sizeof(struct usb_cdc_acm_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_ACM, - .bmCapabilities = 2, /* SET_LINE_CODING supported */ - }, - .cdc_union = { - .bFunctionLength = sizeof(struct usb_cdc_union_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_UNION, - .bControlInterface = 0, - .bSubordinateInterface0 = 1, - } -}; - -static const struct usb_interface_descriptor gdb_comm_iface[] = {{ - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 0, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_CLASS_CDC, - .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, - .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, - .iInterface = 4, - - .endpoint = gdb_comm_endp, - - .extra = &gdb_cdcacm_functional_descriptors, - .extralen = sizeof(gdb_cdcacm_functional_descriptors) -}}; - -static const struct usb_interface_descriptor gdb_data_iface[] = {{ - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 1, - .bAlternateSetting = 0, - .bNumEndpoints = 2, - .bInterfaceClass = USB_CLASS_DATA, - .bInterfaceSubClass = 0, - .bInterfaceProtocol = 0, - .iInterface = 0, - - .endpoint = gdb_data_endp, -}}; - -static const struct usb_iface_assoc_descriptor gdb_assoc = { - .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, - .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, - .bFirstInterface = 0, - .bInterfaceCount = 2, - .bFunctionClass = USB_CLASS_CDC, - .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, - .bFunctionProtocol = USB_CDC_PROTOCOL_AT, - .iFunction = 0, -}; - -/* Serial ACM interface */ -static const struct usb_endpoint_descriptor uart_comm_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x84, - .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT, - .wMaxPacketSize = 16, - .bInterval = 255, -}}; - -static const struct usb_endpoint_descriptor uart_data_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x03, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = CDCACM_PACKET_SIZE, - .bInterval = 1, -}, { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x83, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = CDCACM_PACKET_SIZE, - .bInterval = 1, -}}; - -static const struct { - struct usb_cdc_header_descriptor header; - struct usb_cdc_call_management_descriptor call_mgmt; - struct usb_cdc_acm_descriptor acm; - struct usb_cdc_union_descriptor cdc_union; -} __attribute__((packed)) uart_cdcacm_functional_descriptors = { - .header = { - .bFunctionLength = sizeof(struct usb_cdc_header_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_HEADER, - .bcdCDC = 0x0110, - }, - .call_mgmt = { - .bFunctionLength = - sizeof(struct usb_cdc_call_management_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT, - .bmCapabilities = 0, - .bDataInterface = 3, - }, - .acm = { - .bFunctionLength = sizeof(struct usb_cdc_acm_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_ACM, - .bmCapabilities = 2, /* SET_LINE_CODING supported*/ - }, - .cdc_union = { - .bFunctionLength = sizeof(struct usb_cdc_union_descriptor), - .bDescriptorType = CS_INTERFACE, - .bDescriptorSubtype = USB_CDC_TYPE_UNION, - .bControlInterface = 2, - .bSubordinateInterface0 = 3, - } -}; - -static const struct usb_interface_descriptor uart_comm_iface[] = {{ - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 2, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = USB_CLASS_CDC, - .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, - .bInterfaceProtocol = USB_CDC_PROTOCOL_AT, - .iInterface = 5, - - .endpoint = uart_comm_endp, - - .extra = &uart_cdcacm_functional_descriptors, - .extralen = sizeof(uart_cdcacm_functional_descriptors) -}}; - -static const struct usb_interface_descriptor uart_data_iface[] = {{ - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 3, - .bAlternateSetting = 0, - .bNumEndpoints = 2, - .bInterfaceClass = USB_CLASS_DATA, - .bInterfaceSubClass = 0, - .bInterfaceProtocol = 0, - .iInterface = 0, - - .endpoint = uart_data_endp, -}}; - -static const struct usb_iface_assoc_descriptor uart_assoc = { - .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, - .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, - .bFirstInterface = 2, - .bInterfaceCount = 2, - .bFunctionClass = USB_CLASS_CDC, - .bFunctionSubClass = USB_CDC_SUBCLASS_ACM, - .bFunctionProtocol = USB_CDC_PROTOCOL_AT, - .iFunction = 0, -}; - -const struct usb_dfu_descriptor dfu_function = { - .bLength = sizeof(struct usb_dfu_descriptor), - .bDescriptorType = DFU_FUNCTIONAL, - .bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH, - .wDetachTimeout = 255, - .wTransferSize = 1024, - .bcdDFUVersion = 0x011A, -}; - -const struct usb_interface_descriptor dfu_iface = { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = DFU_IF_NO, - .bAlternateSetting = 0, - .bNumEndpoints = 0, - .bInterfaceClass = 0xFE, - .bInterfaceSubClass = 1, - .bInterfaceProtocol = 1, - .iInterface = 6, - - .extra = &dfu_function, - .extralen = sizeof(dfu_function), -}; - -static const struct usb_iface_assoc_descriptor dfu_assoc = { - .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, - .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, - .bFirstInterface = 4, - .bInterfaceCount = 1, - .bFunctionClass = 0xFE, - .bFunctionSubClass = 1, - .bFunctionProtocol = 1, - .iFunction = 6, -}; - -#if defined(PLATFORM_HAS_TRACESWO) -static const struct usb_endpoint_descriptor trace_endp[] = {{ - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = 0x85, - .bmAttributes = USB_ENDPOINT_ATTR_BULK, - .wMaxPacketSize = 64, - .bInterval = 0, -}}; - -const struct usb_interface_descriptor trace_iface = { - .bLength = USB_DT_INTERFACE_SIZE, - .bDescriptorType = USB_DT_INTERFACE, - .bInterfaceNumber = 5, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = 0xFF, - .bInterfaceSubClass = 0xFF, - .bInterfaceProtocol = 0xFF, - .iInterface = 7, - - .endpoint = trace_endp, -}; - -static const struct usb_iface_assoc_descriptor trace_assoc = { - .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE, - .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION, - .bFirstInterface = 5, - .bInterfaceCount = 1, - .bFunctionClass = 0xFF, - .bFunctionSubClass = 0xFF, - .bFunctionProtocol = 0xFF, - .iFunction = 7, -}; -#endif - -static const struct usb_interface ifaces[] = {{ - .num_altsetting = 1, - .iface_assoc = &gdb_assoc, - .altsetting = gdb_comm_iface, -}, { - .num_altsetting = 1, - .altsetting = gdb_data_iface, -}, { - .num_altsetting = 1, - .iface_assoc = &uart_assoc, - .altsetting = uart_comm_iface, -}, { - .num_altsetting = 1, - .altsetting = uart_data_iface, -}, { - .num_altsetting = 1, - .iface_assoc = &dfu_assoc, - .altsetting = &dfu_iface, -#if defined(PLATFORM_HAS_TRACESWO) -}, { - .num_altsetting = 1, - .iface_assoc = &trace_assoc, - .altsetting = &trace_iface, -#endif -}}; - -static const struct usb_config_descriptor config = { - .bLength = USB_DT_CONFIGURATION_SIZE, - .bDescriptorType = USB_DT_CONFIGURATION, - .wTotalLength = 0, -#if defined(PLATFORM_HAS_TRACESWO) - .bNumInterfaces = 6, -#else - .bNumInterfaces = 5, -#endif - .bConfigurationValue = 1, - .iConfiguration = 0, - .bmAttributes = 0x80, - .bMaxPower = 0x32, - - .interface = ifaces, -}; - -char serial_no[9]; - -static const char *usb_strings[] = { - "Black Sphere Technologies", - BOARD_IDENT, - serial_no, - "Black Magic GDB Server", - "Black Magic UART Port", - DFU_IDENT, -#if defined(PLATFORM_HAS_TRACESWO) - "Black Magic Trace Capture", -#endif -}; - -static void dfu_detach_complete(usbd_device *dev, struct usb_setup_data *req) -{ - (void)dev; - (void)req; - - /* Disconnect USB cable */ - disconnect_usb(); - - /* Assert boot-request pin */ - //assert_boot_pin(); - - /* Reset core to enter bootloader */ - scb_reset_core(); -} - -static int cdcacm_control_request(usbd_device *dev, - struct usb_setup_data *req, uint8_t **buf, uint16_t *len, - void (**complete)(usbd_device *dev, struct usb_setup_data *req)) -{ - (void)dev; - (void)complete; - (void)buf; - (void)len; - - switch(req->bRequest) { - case USB_CDC_REQ_SET_CONTROL_LINE_STATE: - /* Ignore if not for GDB interface */ - if(req->wIndex != 0) - return 1; - - cdcacm_gdb_dtr = req->wValue & 1; - - return 1; - case USB_CDC_REQ_SET_LINE_CODING: - if(*len < sizeof(struct usb_cdc_line_coding)) - return 0; - - switch(req->wIndex) { - case 2: - usbuart_set_line_coding((struct usb_cdc_line_coding*)*buf); - case 0: - return 1; /* Ignore on GDB Port */ - default: - return 0; - } - case DFU_GETSTATUS: - if(req->wIndex == DFU_IF_NO) { - (*buf)[0] = DFU_STATUS_OK; - (*buf)[1] = 0; - (*buf)[2] = 0; - (*buf)[3] = 0; - (*buf)[4] = STATE_APP_IDLE; - (*buf)[5] = 0; /* iString not used here */ - *len = 6; - - return 1; - } - case DFU_DETACH: - if(req->wIndex == DFU_IF_NO) { - *complete = dfu_detach_complete; - return 1; - } - return 0; - } - return 0; -} - -int cdcacm_get_config(void) -{ - return configured; -} - -int cdcacm_get_dtr(void) -{ - return cdcacm_gdb_dtr; -} - -static void cdcacm_set_config(usbd_device *dev, uint16_t wValue) -{ - configured = wValue; - - /* GDB interface */ - usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, gdb_usb_out_cb); - usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, NULL); - usbd_ep_setup(dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); - - /* Serial interface */ - usbd_ep_setup(dev, 0x03, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, usbuart_usb_out_cb); - usbd_ep_setup(dev, 0x83, USB_ENDPOINT_ATTR_BULK, - CDCACM_PACKET_SIZE, usbuart_usb_in_cb); - usbd_ep_setup(dev, 0x84, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); - -#if defined(PLATFORM_HAS_TRACESWO) - /* Trace interface */ - usbd_ep_setup(dev, 0x85, USB_ENDPOINT_ATTR_BULK, - 64, trace_buf_drain); -#endif - - usbd_register_control_callback(dev, - USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, - USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, - cdcacm_control_request); - - /* Notify the host that DCD is asserted. - * Allows the use of /dev/tty* devices on *BSD/MacOS - */ - char buf[10]; - struct usb_cdc_notification *notif = (void*)buf; - /* We echo signals back to host as notification */ - notif->bmRequestType = 0xA1; - notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE; - notif->wValue = 0; - notif->wIndex = 0; - notif->wLength = 2; - buf[8] = 3; /* DCD | DSR */ - buf[9] = 0; - usbd_ep_write_packet(dev, 0x82, buf, 10); - notif->wIndex = 2; - usbd_ep_write_packet(dev, 0x84, buf, 10); -} - -/* We need a special large control buffer for this device: */ -uint8_t usbd_control_buffer[256]; - -void cdcacm_init(void) -{ - get_dev_unique_id(serial_no); - - periph_clock_enable(RCC_GPIOD); - __asm__("nop"); __asm__("nop"); __asm__("nop"); - gpio_mode_setup(GPIOD_BASE, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO4|GPIO5); - - usbdev = usbd_init(&USB_DRIVER, &dev, &config, usb_strings, - sizeof(usb_strings)/sizeof(char *), - usbd_control_buffer, sizeof(usbd_control_buffer)); - - usbd_register_set_config_callback(usbdev, cdcacm_set_config); - - usb_enable_interrupts(USB_INT_RESET|USB_INT_DISCON|USB_INT_RESUME|USB_INT_SUSPEND, - 0xff, 0xff); - nvic_set_priority(USB_IRQ, IRQ_PRI_USB); - nvic_enable_irq(USB_IRQ); - setup_vbus_irq(); -} - -void USB_ISR(void) -{ - usbd_poll(usbdev); -} - -static char *get_dev_unique_id(char *s) -{ - /* FIXME: Store a unique serial number somewhere and retreive here */ - uint32_t unique_id = 1; - int i; - - /* Fetch serial number from chip's unique ID */ - for(i = 0; i < 8; i++) { - s[7-i] = ((unique_id >> (4*i)) & 0xF) + '0'; - } - for(i = 0; i < 8; i++) - if(s[i] > '9') - s[i] += 'A' - '9' - 1; - s[8] = 0; - - return s; -} diff --git a/src/platforms/tm4c/traceswo.c b/src/platforms/tm4c/traceswo.c index 03c6d66..3e43a3b 100644 --- a/src/platforms/tm4c/traceswo.c +++ b/src/platforms/tm4c/traceswo.c @@ -28,6 +28,7 @@ */ #include "general.h" +#include "cdcacm.h" #include #include -- cgit v1.2.3 From 3e466f2d23401df610cb0f94a226317c2dc38751 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Mon, 2 Mar 2015 21:59:04 -0800 Subject: Factor out timing routines common to all STM32 targets. --- src/include/platform_support.h | 2 ++ src/platforms/f4discovery/Makefile.inc | 1 + src/platforms/f4discovery/platform.c | 30 +--------------- src/platforms/f4discovery/platform.h | 4 +-- src/platforms/native/Makefile.inc | 1 + src/platforms/native/platform.c | 29 +-------------- src/platforms/native/platform.h | 4 +-- src/platforms/stlink/Makefile.inc | 1 + src/platforms/stlink/platform.c | 28 ++------------- src/platforms/stlink/platform.h | 6 ++-- src/platforms/stm32/gdb_if.c | 4 +-- src/platforms/stm32/timing.c | 65 ++++++++++++++++++++++++++++++++++ src/platforms/stm32/timing.h | 27 ++++++++++++++ src/platforms/swlink/Makefile.inc | 1 + src/platforms/swlink/platform.c | 33 ++--------------- src/platforms/swlink/platform.h | 9 +++-- 16 files changed, 116 insertions(+), 129 deletions(-) create mode 100644 src/platforms/stm32/timing.c create mode 100644 src/platforms/stm32/timing.h (limited to 'src/platforms/native/platform.h') diff --git a/src/include/platform_support.h b/src/include/platform_support.h index 7d8443c..2bfbe65 100644 --- a/src/include/platform_support.h +++ b/src/include/platform_support.h @@ -32,6 +32,8 @@ void platform_init(void); const char *platform_target_voltage(void); int platform_hwversion(void); +void platform_timeout_set(uint32_t ms); +bool platform_timeout_is_expired(void); void platform_delay(uint32_t delay); void platform_srst_set_val(bool assert); bool platform_target_get_power(void); diff --git a/src/platforms/f4discovery/Makefile.inc b/src/platforms/f4discovery/Makefile.inc index 21b4078..d8f7754 100644 --- a/src/platforms/f4discovery/Makefile.inc +++ b/src/platforms/f4discovery/Makefile.inc @@ -20,6 +20,7 @@ SRC += cdcacm.c \ traceswo.c \ usbuart.c \ serialno.c \ + timing.c \ all: blackmagic.bin diff --git a/src/platforms/f4discovery/platform.c b/src/platforms/f4discovery/platform.c index 6e10ff4..e85ebd5 100644 --- a/src/platforms/f4discovery/platform.c +++ b/src/platforms/f4discovery/platform.c @@ -28,7 +28,6 @@ #include "morse.h" #include -#include #include #include #include @@ -36,9 +35,6 @@ #include #include -uint8_t running_status; -volatile uint32_t timeout_counter; - jmp_buf fatal_error_jmpbuf; void platform_init(void) @@ -77,35 +73,11 @@ void platform_init(void) GPIO_PUPD_NONE, LED_UART | LED_IDLE_RUN | LED_ERROR | LED_BOOTLOADER); - /* Setup heartbeat timer */ - systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); - systick_set_reload(168000000/(10*8)); /* Interrupt us at 10 Hz */ - SCB_SHPR(11) &= ~((15 << 4) & 0xff); - SCB_SHPR(11) |= ((14 << 4) & 0xff); - systick_interrupt_enable(); - systick_counter_enable(); - + platform_timing_init(); usbuart_init(); cdcacm_init(); } -void platform_delay(uint32_t delay) -{ - timeout_counter = delay; - while(timeout_counter); -} - -void sys_tick_handler(void) -{ - if(running_status) - gpio_toggle(LED_PORT, LED_IDLE_RUN); - - if(timeout_counter) - timeout_counter--; - - SET_ERROR_STATE(morse_update()); -} - const char *platform_target_voltage(void) { return "ABSENT!"; diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 61753af..3c5c582 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -27,6 +27,7 @@ #include "gdb_packet.h" #include "gpio.h" #include "morse.h" +#include "timing.h" #include @@ -140,9 +141,6 @@ #define DEBUG(...) -extern uint8_t running_status; -extern volatile uint32_t timeout_counter; - extern jmp_buf fatal_error_jmpbuf; #define gpio_set_val(port, pin, val) do { \ diff --git a/src/platforms/native/Makefile.inc b/src/platforms/native/Makefile.inc index 2270ff5..8b76a53 100644 --- a/src/platforms/native/Makefile.inc +++ b/src/platforms/native/Makefile.inc @@ -19,6 +19,7 @@ SRC += cdcacm.c \ traceswo.c \ usbuart.c \ serialno.c \ + timing.c \ all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 5c28747..ac54b4b 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -28,7 +28,6 @@ #include "morse.h" #include -#include #include #include #include @@ -36,9 +35,6 @@ #include #include -uint8_t running_status; -volatile uint32_t timeout_counter; - jmp_buf fatal_error_jmpbuf; static void adc_init(void); @@ -115,14 +111,6 @@ void platform_init(void) GPIO_CNF_INPUT_PULL_UPDOWN, PWR_BR_PIN); } - /* Setup heartbeat timer */ - systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); - systick_set_reload(900000); /* Interrupt us at 10 Hz */ - SCB_SHPR(11) &= ~((15 << 4) & 0xff); - SCB_SHPR(11) |= ((14 << 4) & 0xff); - systick_interrupt_enable(); - systick_counter_enable(); - if (platform_hwversion() > 0) { adc_init(); } else { @@ -133,6 +121,7 @@ void platform_init(void) /* Relocate interrupt vector table here */ SCB_VTOR = 0x2000; + platform_timing_init(); cdcacm_init(); usbuart_init(); setup_vbus_irq(); @@ -161,22 +150,6 @@ void platform_target_set_power(bool power) gpio_set_val(PWR_BR_PORT, PWR_BR_PIN, !power); } } -void platform_delay(uint32_t delay) -{ - timeout_counter = delay; - while(timeout_counter); -} - -void sys_tick_handler(void) -{ - if(running_status) - gpio_toggle(LED_PORT, LED_IDLE_RUN); - - if(timeout_counter) - timeout_counter--; - - SET_ERROR_STATE(morse_update()); -} static void adc_init(void) { diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index c0b4dba..ae9bcef 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -27,6 +27,7 @@ #include "gdb_packet.h" #include "gpio.h" #include "morse.h" +#include "timing.h" #include @@ -146,9 +147,6 @@ #define DEBUG(...) -extern uint8_t running_status; -extern volatile uint32_t timeout_counter; - extern jmp_buf fatal_error_jmpbuf; #define SET_RUN_STATE(state) {running_status = (state);} diff --git a/src/platforms/stlink/Makefile.inc b/src/platforms/stlink/Makefile.inc index 52ad33b..f2ebce5 100644 --- a/src/platforms/stlink/Makefile.inc +++ b/src/platforms/stlink/Makefile.inc @@ -18,6 +18,7 @@ SRC += cdcacm.c \ platform.c \ usbuart.c \ serialno.c \ + timing.c \ all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex dfu_upgrade.bin dfu_upgrade.hex diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index 446fb47..fb10faa 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -27,7 +27,6 @@ #include "usbuart.h" #include -#include #include #include #include @@ -104,25 +103,11 @@ void platform_init(void) gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run); - /* Setup heartbeat timer */ - systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); - systick_set_reload(900000); /* Interrupt us at 10 Hz */ - SCB_SHPR(11) &= ~((15 << 4) & 0xff); - SCB_SHPR(11) |= ((14 << 4) & 0xff); - systick_interrupt_enable(); - systick_counter_enable(); - - usbuart_init(); - SCB_VTOR = 0x2000; /* Relocate interrupt vector table here */ + platform_timing_init(); cdcacm_init(); -} - -void platform_delay(uint32_t delay) -{ - timeout_counter = delay; - while (timeout_counter); + usbuart_init(); } void platform_srst_set_val(bool assert) @@ -135,15 +120,6 @@ void platform_srst_set_val(bool assert) gpio_set(SRST_PORT, pin); } -void sys_tick_handler(void) -{ - if(running_status) - gpio_toggle(LED_PORT, led_idle_run); - - if(timeout_counter) - timeout_counter--; -} - const char *platform_target_voltage(void) { return "unknown"; diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index fcbe259..f026db3 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -26,6 +26,7 @@ #include "gdb_packet.h" #include "gpio.h" +#include "timing.h" #include #include @@ -129,14 +130,13 @@ #define DEBUG(...) -extern uint8_t running_status; -extern volatile uint32_t timeout_counter; - extern jmp_buf fatal_error_jmpbuf; extern uint16_t led_idle_run; +#define LED_IDLE_RUN led_idle_run #define SET_RUN_STATE(state) {running_status = (state);} #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, led_idle_run, state);} +#define SET_ERROR_STATE(x) #define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} #define PLATFORM_FATAL_ERROR(error) do { \ diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c index 286c66b..52922e7 100644 --- a/src/platforms/stm32/gdb_if.c +++ b/src/platforms/stm32/gdb_if.c @@ -113,7 +113,7 @@ unsigned char gdb_if_getchar(void) unsigned char gdb_if_getchar_to(int timeout) { - timeout_counter = timeout/100; + platform_timeout_set(timeout); if (!(out_ptr < count_out)) do { /* Detach if port closed */ @@ -121,7 +121,7 @@ unsigned char gdb_if_getchar_to(int timeout) return 0x04; gdb_if_update_buf(); - } while(timeout_counter && !(out_ptr < count_out)); + } while (!platform_timeout_is_expired() && !(out_ptr < count_out)); if(out_ptr < count_out) return gdb_if_getchar(); diff --git a/src/platforms/stm32/timing.c b/src/platforms/stm32/timing.c new file mode 100644 index 0000000..cac22ca --- /dev/null +++ b/src/platforms/stm32/timing.c @@ -0,0 +1,65 @@ +/* + * 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 . + */ +#include "general.h" + +#include +#include + +uint8_t running_status; + +static volatile uint32_t timeout_counter; + +void platform_timing_init(void) +{ + /* Setup heartbeat timer */ + systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); + systick_set_reload(900000); /* Interrupt us at 10 Hz */ + SCB_SHPR(11) &= ~((15 << 4) & 0xff); + SCB_SHPR(11) |= ((14 << 4) & 0xff); + systick_interrupt_enable(); + systick_counter_enable(); +} + +void platform_timeout_set(uint32_t ms) +{ + timeout_counter = ms / 100; +} + +bool platform_timeout_is_expired(void) +{ + return timeout_counter == 0; +} + +void platform_delay(uint32_t delay) +{ + platform_timeout_set(delay); + while (platform_timeout_is_expired()); +} + +void sys_tick_handler(void) +{ + if(running_status) + gpio_toggle(LED_PORT, LED_IDLE_RUN); + + if(timeout_counter) + timeout_counter--; + + SET_ERROR_STATE(morse_update()); +} + diff --git a/src/platforms/stm32/timing.h b/src/platforms/stm32/timing.h new file mode 100644 index 0000000..0178ff5 --- /dev/null +++ b/src/platforms/stm32/timing.h @@ -0,0 +1,27 @@ +/* + * 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 __TIMING_H +#define __TIMING_H + +extern uint8_t running_status; + +void platform_timing_init(void); + +#endif + diff --git a/src/platforms/swlink/Makefile.inc b/src/platforms/swlink/Makefile.inc index b68b1ab..f891cb0 100644 --- a/src/platforms/swlink/Makefile.inc +++ b/src/platforms/swlink/Makefile.inc @@ -18,6 +18,7 @@ SRC += cdcacm.c \ platform.c \ usbuart.c \ serialno.c \ + timing.c \ all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index 1b9a76e..cbdae0c 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -27,16 +27,12 @@ #include "usbuart.h" #include -#include #include #include #include #include #include -uint8_t running_status; -volatile uint32_t timeout_counter; - jmp_buf fatal_error_jmpbuf; void platform_init(void) @@ -72,7 +68,7 @@ void platform_init(void) GPIO_CNF_INPUT_PULL_UPDOWN, NRST_PIN); gpio_set_mode(LED_PORT, GPIO_MODE_OUTPUT_2_MHZ, - GPIO_CNF_OUTPUT_PUSHPULL, led_idle_run); + GPIO_CNF_OUTPUT_PUSHPULL, LED_IDLE_RUN); /* Remap TIM2 TIM2_REMAP[1] * TIM2_CH1_ETR -> PA15 (TDI, set as output above) @@ -83,34 +79,11 @@ void platform_init(void) data |= AFIO_MAPR_TIM2_REMAP_PARTIAL_REMAP1; AFIO_MAPR = data; - /* Setup heartbeat timer */ - systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8); - systick_set_reload(900000); /* Interrupt us at 10 Hz */ - SCB_SHPR(11) &= ~((15 << 4) & 0xff); - SCB_SHPR(11) |= ((14 << 4) & 0xff); - systick_interrupt_enable(); - systick_counter_enable(); - - usbuart_init(); - SCB_VTOR = 0x2000; // Relocate interrupt vector table here + platform_timing_init(); cdcacm_init(); -} - -void platform_delay(uint32_t delay) -{ - timeout_counter = delay; - while(timeout_counter); -} - -void sys_tick_handler(void) -{ - if(running_status) - gpio_toggle(LED_PORT, led_idle_run); - - if(timeout_counter) - timeout_counter--; + usbuart_init(); } const char *platform_target_voltage(void) diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 6ee4a9c..27cc299 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -26,6 +26,7 @@ #include "gdb_packet.h" #include "gpio.h" +#include "timing.h" #include @@ -69,6 +70,7 @@ #define SWCLK_PIN TCK_PIN #define LED_PORT GPIOA +#define LED_IDLE_RUN GPIO8 /* Use PC14 for a "dummy" uart led. So we can observere at least with scope*/ #define LED_PORT_UART GPIOC #define LED_UART GPIO14 @@ -123,14 +125,11 @@ #define DEBUG(...) -extern uint8_t running_status; -extern volatile uint32_t timeout_counter; - extern jmp_buf fatal_error_jmpbuf; -#define led_idle_run GPIO8 #define SET_RUN_STATE(state) {running_status = (state);} -#define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, led_idle_run, state);} +#define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);} +#define SET_ERROR_STATE(x) #define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} #define PLATFORM_FATAL_ERROR(error) { \ -- 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/platforms/native/platform.h') 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 68f54a35457da4c07ec84bd7e0c2823183e8811e Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 22 Mar 2015 14:06:56 -0700 Subject: Remove old platform specific error handling macros. --- src/platforms/f4discovery/platform.h | 15 --------------- src/platforms/launchpad-icdi/platform.c | 1 - src/platforms/launchpad-icdi/platform.h | 17 ----------------- src/platforms/libftdi/platform.h | 3 --- src/platforms/native/platform.c | 2 -- src/platforms/native/platform.h | 17 ----------------- src/platforms/stlink/platform.c | 2 -- src/platforms/stlink/platform.h | 15 --------------- src/platforms/swlink/platform.c | 2 -- src/platforms/swlink/platform.h | 15 --------------- 10 files changed, 89 deletions(-) (limited to 'src/platforms/native/platform.h') diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 68027ee..92ae046 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -24,11 +24,8 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include "gdb_packet.h" #include "gpio.h" -#include "morse.h" #include "timing.h" -#include "target.h" #include @@ -142,8 +139,6 @@ #define DEBUG(...) -extern jmp_buf fatal_error_jmpbuf; - #define gpio_set_val(port, pin, val) do { \ if(val) \ gpio_set((port), (pin)); \ @@ -155,16 +150,6 @@ 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);} -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) { \ - if(running_status) gdb_putpacketz("X1D"); \ - else gdb_putpacketz("EFF"); \ - running_status = 0; \ - target_list_free(); \ - morse("TARGET LOST.", 1); \ - longjmp(fatal_error_jmpbuf, (error)); \ -} - static inline int platform_hwversion(void) { return 0; diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index 1a3598a..ff67fa0 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -33,7 +33,6 @@ extern void trace_tick(void); -jmp_buf fatal_error_jmpbuf; uint8_t running_status; volatile uint32_t timeout_counter; diff --git a/src/platforms/launchpad-icdi/platform.h b/src/platforms/launchpad-icdi/platform.h index ddc2035..c13172f 100644 --- a/src/platforms/launchpad-icdi/platform.h +++ b/src/platforms/launchpad-icdi/platform.h @@ -17,12 +17,6 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include "gdb_packet.h" -#include "target.h" -#include "morse.h" - -#include - #include #include @@ -31,7 +25,6 @@ #define DFU_IDENT "Black Magic Firmware Upgrade (Launchpad)" #define DFU_IFACE_STRING "lolwut" -extern jmp_buf fatal_error_jmpbuf; extern uint8_t running_status; extern volatile uint32_t timeout_counter; @@ -108,16 +101,6 @@ extern usbd_driver lm4f_usb_driver; #define SET_IDLE_STATE(state) {} #define SET_ERROR_STATE(state) SET_IDLE_STATE(state) -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) { \ - if( running_status ) gdb_putpacketz("X1D"); \ - else gdb_putpacketz("EFF"); \ - running_status = 0; \ - target_list_free(); \ - morse("TARGET LOST.", 1); \ - longjmp(fatal_error_jmpbuf, (error)); \ -} - #define PLATFORM_HAS_TRACESWO inline static void gpio_set_val(uint32_t port, uint8_t pin, uint8_t val) { diff --git a/src/platforms/libftdi/platform.h b/src/platforms/libftdi/platform.h index 135b2e3..8611674 100644 --- a/src/platforms/libftdi/platform.h +++ b/src/platforms/libftdi/platform.h @@ -36,9 +36,6 @@ #define SET_IDLE_STATE(state) #define SET_ERROR_STATE(state) -#define PLATFORM_FATAL_ERROR(error) abort() -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() - extern struct ftdi_context *ftdic; void platform_buffer_flush(void); diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index ac54b4b..babb498 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -35,8 +35,6 @@ #include #include -jmp_buf fatal_error_jmpbuf; - static void adc_init(void); static void setup_vbus_irq(void); diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 3b1769b..6958585 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -24,13 +24,9 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include "gdb_packet.h" #include "gpio.h" -#include "morse.h" #include "timing.h" -#include - #define PLATFORM_HAS_TRACESWO #define PLATFORM_HAS_POWER_SWITCH #define BOARD_IDENT "Black Magic Probe" @@ -147,23 +143,10 @@ #define DEBUG(...) -extern jmp_buf fatal_error_jmpbuf; - #define SET_RUN_STATE(state) {running_status = (state);} #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"); \ - else gdb_putpacketz("EFF"); \ - running_status = 0; \ - target_list_free(); \ - morse("TARGET LOST.", 1); \ - longjmp(fatal_error_jmpbuf, (error)); \ -} while (0) - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index fb10faa..dd501a4 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -36,8 +36,6 @@ uint8_t running_status; volatile uint32_t timeout_counter; -jmp_buf fatal_error_jmpbuf; - uint16_t led_idle_run; /* Pins PC[14:13] are used to detect hardware revision. Read * 11 for STLink V1 e.g. on VL Discovery, tag as hwversion 0 diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index 549b6d6..aa02ac0 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -24,17 +24,13 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include "gdb_packet.h" #include "gpio.h" #include "timing.h" -#include "target.h" #include #include #include -#include - #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 ")" #define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -131,23 +127,12 @@ #define DEBUG(...) -extern jmp_buf fatal_error_jmpbuf; - extern uint16_t led_idle_run; #define LED_IDLE_RUN led_idle_run #define SET_RUN_STATE(state) {running_status = (state);} #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, led_idle_run, state);} #define SET_ERROR_STATE(x) -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) do { \ - if(running_status) gdb_putpacketz("X1D"); \ - else gdb_putpacketz("EFF"); \ - running_status = 0; \ - target_list_free(); \ - longjmp(fatal_error_jmpbuf, (error)); \ -} while (0) - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index cbdae0c..02cde19 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -33,8 +33,6 @@ #include #include -jmp_buf fatal_error_jmpbuf; - void platform_init(void) { uint32_t data; diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index e82124a..2c6fb76 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -24,12 +24,8 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include "gdb_packet.h" #include "gpio.h" #include "timing.h" -#include "target.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 ")" @@ -126,21 +122,10 @@ #define DEBUG(...) -extern jmp_buf fatal_error_jmpbuf; - #define SET_RUN_STATE(state) {running_status = (state);} #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);} #define SET_ERROR_STATE(x) -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) { \ - if(running_status) gdb_putpacketz("X1D"); \ - else gdb_putpacketz("EFF"); \ - running_status = 0; \ - target_list_free(); \ - longjmp(fatal_error_jmpbuf, (error)); \ -} - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf -- cgit v1.2.3