aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/launchpad-icdi
diff options
context:
space:
mode:
authorNicolas Schodet2015-05-11 11:44:13 +0200
committerNicolas Schodet2015-06-16 17:00:31 +0200
commitb877293fd8603270854876f8c7e6a6d46fb49c2c (patch)
tree580838207cb8a0b5d980a6b1d2cc5b3d5420fb90 /src/platforms/launchpad-icdi
parent21b3aba640e492b49140cb9c994f97a61ca51d29 (diff)
parent482070c91b0cc5a5f16c02a30e26e306685566bb (diff)
Merge remote-tracking branch 'github/master' into dev2
Conflicts: src/main.c
Diffstat (limited to 'src/platforms/launchpad-icdi')
-rw-r--r--src/platforms/launchpad-icdi/Makefile.inc21
-rw-r--r--src/platforms/launchpad-icdi/platform.c130
-rw-r--r--src/platforms/launchpad-icdi/platform.h118
3 files changed, 269 insertions, 0 deletions
diff --git a/src/platforms/launchpad-icdi/Makefile.inc b/src/platforms/launchpad-icdi/Makefile.inc
new file mode 100644
index 0000000..e46b727
--- /dev/null
+++ b/src/platforms/launchpad-icdi/Makefile.inc
@@ -0,0 +1,21 @@
+CROSS_COMPILE ?= arm-none-eabi-
+CC = $(CROSS_COMPILE)gcc
+OBJCOPY = $(CROSS_COMPILE)objcopy
+
+INCLUDES = -I../libopencm3/include
+
+CPU_FLAGS = -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+CFLAGS += $(INCLUDES) $(CPU_FLAGS) -DTARGET_IS_BLIZZARD_RB1 -DLM4F -DPART_TM4C123GH6PM
+
+LINKER_SCRIPT="platforms/tm4c/tm4c.ld"
+LDFLAGS = -nostartfiles -lc $(CPU_FLAGS) -nodefaultlibs -T$(LINKER_SCRIPT) -Wl,--gc-sections \
+ -L../libopencm3/lib -lopencm3_lm4f -lnosys -lm -lgcc
+
+VPATH += platforms/tm4c
+
+SRC += cdcacm.c \
+ usbuart.c \
+ traceswo.o
+
+all: blackmagic.bin
+
diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c
new file mode 100644
index 0000000..ff67fa0
--- /dev/null
+++ b/src/platforms/launchpad-icdi/platform.c
@@ -0,0 +1,130 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+#include "general.h"
+#include "gdb_if.h"
+#include "cdcacm.h"
+#include "usbuart.h"
+
+#include <libopencm3/lm4f/rcc.h>
+#include <libopencm3/lm4f/nvic.h>
+#include <libopencm3/lm4f/uart.h>
+#include <libopencm3/cm3/systick.h>
+#include <libopencm3/lm4f/usb.h>
+
+#define SYSTICKHZ 100
+#define SYSTICKMS (1000 / SYSTICKHZ)
+
+#define PLL_DIV_80MHZ 5
+#define PLL_DIV_25MHZ 16
+
+extern void trace_tick(void);
+
+uint8_t running_status;
+volatile uint32_t timeout_counter;
+
+void sys_tick_handler(void)
+{
+ if(timeout_counter)
+ timeout_counter--;
+ trace_tick();
+}
+
+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);
+
+ gpio_enable_ahb_aperture();
+
+ gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TMS_PIN);
+ gpio_mode_setup(TCK_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TCK_PIN);
+ gpio_mode_setup(TDI_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TDI_PIN);
+ gpio_mode_setup(TDO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, TDO_PIN);
+ gpio_mode_setup(SRST_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, SRST_PIN);
+ gpio_set_output_config(SRST_PORT, GPIO_OTYPE_OD, GPIO_DRIVE_2MA, SRST_PIN);
+ gpio_set(SRST_PORT, SRST_PIN);
+
+ systick_set_clocksource(STK_CSR_CLKSOURCE_AHB_DIV8);
+ systick_set_reload(rcc_get_system_clock_frequency() / (SYSTICKHZ * 8));
+
+ systick_interrupt_enable();
+ systick_counter_enable();
+
+ 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();
+}
+
+void platform_timeout_set(uint32_t ms)
+{
+ timeout_counter = ms / 10;
+}
+
+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());
+}
+
+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
new file mode 100644
index 0000000..52b963e
--- /dev/null
+++ b/src/platforms/launchpad-icdi/platform.h
@@ -0,0 +1,118 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+#ifndef __PLATFORM_H
+#define __PLATFORM_H
+
+#include <libopencm3/lm4f/gpio.h>
+#include <libopencm3/usb/usbd.h>
+
+#include "version.h"
+
+#define BOARD_IDENT "Black Magic Probe (Launchpad ICDI), (Firmware " FIRMWARE_VERSION ")"
+#define BOARD_IDENT_DFU "Black Magic (Upgrade) for Launchpad, (Firmware " FIRMWARE_VERSION ")"
+#define DFU_IDENT "Black Magic Firmware Upgrade (Launchpad)"
+#define DFU_IFACE_STRING "lolwut"
+
+extern uint8_t running_status;
+extern volatile uint32_t timeout_counter;
+
+#define TMS_PORT GPIOA_BASE
+#define TMS_PIN GPIO3
+
+#define TCK_PORT GPIOA_BASE
+#define TCK_PIN GPIO2
+
+#define TDI_PORT GPIOA_BASE
+#define TDI_PIN GPIO5
+
+#define TDO_PORT GPIOA_BASE
+#define TDO_PIN GPIO4
+
+#define SWO_PORT GPIOD_BASE
+#define SWO_PIN GPIO6
+
+#define SWDIO_PORT TMS_PORT
+#define SWDIO_PIN TMS_PIN
+
+#define SWCLK_PORT TCK_PORT
+#define SWCLK_PIN TCK_PIN
+
+#define SRST_PORT GPIOA_BASE
+#define SRST_PIN GPIO6
+
+#define TMS_SET_MODE() { \
+ gpio_mode_setup(TMS_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TMS_PIN); \
+ gpio_set_output_config(TMS_PORT, GPIO_OTYPE_PP, GPIO_DRIVE_2MA, 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); \
+ gpio_set_output_config(SWDIO_PORT, GPIO_OTYPE_PP, GPIO_DRIVE_2MA, SWDIO_PIN); \
+}
+
+extern usbd_driver lm4f_usb_driver;
+#define USB_DRIVER lm4f_usb_driver
+#define USB_IRQ NVIC_USB0_IRQ
+#define USB_ISR usb0_isr
+
+#define IRQ_PRI_USB (2 << 4)
+
+#define USBUART UART0
+#define USBUART_CLK RCC_UART0
+#define USBUART_IRQ NVIC_UART0_IRQ
+#define USBUART_ISR uart0_isr
+#define UART_PIN_SETUP() do { \
+ periph_clock_enable(RCC_GPIOA); \
+ __asm__("nop"); __asm__("nop"); __asm__("nop"); \
+ gpio_set_af(GPIOA_BASE, 0x1, GPIO0 | GPIO1); \
+ gpio_mode_setup(GPIOA_BASE, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO0); \
+ gpio_mode_setup(GPIOA_BASE, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO1); \
+ } while (0)
+
+#define TRACEUART UART2
+#define TRACEUART_CLK RCC_UART2
+#define TRACEUART_IRQ NVIC_UART2_IRQ
+#define TRACEUART_ISR uart2_isr
+
+/* Use newlib provided integer only stdio functions */
+#define sscanf siscanf
+#define sprintf siprintf
+#define vasprintf vasiprintf
+
+#define DEBUG(...)
+
+#define SET_RUN_STATE(state) {running_status = (state);}
+#define SET_IDLE_STATE(state) {}
+#define SET_ERROR_STATE(state) SET_IDLE_STATE(state)
+
+#define PLATFORM_HAS_TRACESWO
+
+inline static void gpio_set_val(uint32_t port, uint8_t pin, uint8_t val) {
+ gpio_write(port, pin, val == 0 ? 0 : 0xff);
+}
+
+inline static uint8_t gpio_get(uint32_t port, uint8_t pin) {
+ return !(gpio_read(port, pin) == 0);
+}
+
+#define disconnect_usb() do { usbd_disconnect(usbdev,1); nvic_disable_irq(USB_IRQ);} while(0)
+
+#endif