Skip to content

Commit 2a6ae4d

Browse files
committed
Add DAP42DC target for Derek's debugger hardware
1 parent 0d63f66 commit 2a6ae4d

5 files changed

Lines changed: 332 additions & 1 deletion

File tree

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export V
2424

2525
BUILD_DIR ?= ./build
2626

27-
all: DAP42.bin KITCHEN42.bin \
27+
all: DAP42.bin DAP42DC.bin KITCHEN42.bin \
2828
DAP103.bin DAP103-DFU.bin \
2929
DAP103-NUCLEO-STBOOT.bin \
3030
BRAINv3.3.bin \
@@ -44,6 +44,12 @@ DAP42.bin: | $(BUILD_DIR)
4444
$(Q)$(MAKE) TARGET=STM32F042 -C src/
4545
$(Q)cp src/DAP42.bin $(BUILD_DIR)/$(@)
4646

47+
DAP42DC.bin: | $(BUILD_DIR)
48+
@printf " BUILD $(@)\n"
49+
$(Q)$(MAKE) TARGET=DAP42DC -C src/ clean
50+
$(Q)$(MAKE) TARGET=DAP42DC -C src/
51+
$(Q)cp src/DAP42.bin $(BUILD_DIR)/$(@)
52+
4753
KITCHEN42.bin: | $(BUILD_DIR)
4854
@printf " BUILD $(@)\n"
4955
$(Q)$(MAKE) TARGET=KITCHEN42 -C src/ clean
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Copyright (c) 2015, Devan Lai
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software
5+
* for any purpose with or without fee is hereby granted, provided
6+
* that the above copyright notice and this permission notice
7+
* appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10+
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11+
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12+
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13+
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15+
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
/*
20+
Portions of this file are derived from:
21+
22+
Dapper Mime - an open-source CMSIS-DAP implementation
23+
HAL for STM32F0xx2
24+
this file is used by the mbed CMSIS-DAP routines
25+
26+
Copyright (C) 2014 Peter Lawrence
27+
28+
Permission is hereby granted, free of charge, to any person obtaining a
29+
copy of this software and associated documentation files (the "Software"),
30+
to deal in the Software without restriction, including without limitation
31+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
32+
and/or sell copies of the Software, and to permit persons to whom the
33+
Software is furnished to do so, subject to the following conditions:
34+
35+
The above copyright notice and this permission notice shall be included in
36+
all copies or substantial portions of the Software.
37+
38+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
41+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
43+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
44+
DEALINGS IN THE SOFTWARE.
45+
*/
46+
47+
#ifndef __DAP_CONFIG_H__
48+
#define __DAP_CONFIG_H__
49+
50+
//**************************************************************************************************
51+
/**
52+
\defgroup DAP_Config_Debug_gr CMSIS-DAP Debug Unit Information
53+
\ingroup DAP_ConfigIO_gr
54+
@{
55+
Provides definitions about:
56+
- Definition of Cortex-M processor parameters used in CMSIS-DAP Debug Unit.
57+
- Debug Unit communication packet size.
58+
- Debug Access Port communication mode (JTAG or SWD).
59+
- Optional information about a connected Target Device (for Evaluation Boards).
60+
*/
61+
62+
#include "config.h"
63+
64+
// Board configuration options
65+
66+
/// Processor Clock of the Cortex-M MCU used in the Debug Unit.
67+
/// This value is used to calculate the SWD/JTAG clock speed.
68+
#define CPU_CLOCK 48000000 ///< Specifies the CPU Clock in Hz
69+
70+
/// Number of processor cycles for I/O Port write operations.
71+
/// This value is used to calculate the SWD/JTAG clock speed that is generated with I/O
72+
/// Port write operations in the Debug Unit by a Cortex-M MCU. Most Cortex-M processors
73+
/// requrie 2 processor cycles for a I/O Port Write operation. If the Debug Unit uses
74+
/// a Cortex-M0+ processor with high-speed peripheral I/O only 1 processor cycle might be
75+
/// required.
76+
#define IO_PORT_WRITE_CYCLES 2 ///< I/O Cycles: 2=default, 1=Cortex-M0+ fast I/0
77+
78+
/// Indicate that Serial Wire Debug (SWD) communication mode is available at the Debug Access Port.
79+
/// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
80+
#define DAP_SWD 1 ///< SWD Mode: 1 = available, 0 = not available
81+
82+
/// Indicate that JTAG communication mode is available at the Debug Port.
83+
/// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
84+
#if defined(CONF_JTAG)
85+
#define DAP_JTAG 1 ///< JTAG Mode: 1 = available
86+
#else
87+
#define DAP_JTAG 0 ///< JTAG Mode: 0 = not available
88+
#endif
89+
90+
/// Configure maximum number of JTAG devices on the scan chain connected to the Debug Access Port.
91+
/// This setting impacts the RAM requirements of the Debug Unit. Valid range is 1 .. 255.
92+
#define DAP_JTAG_DEV_CNT 8 ///< Maximum number of JTAG devices on scan chain
93+
94+
/// Default communication mode on the Debug Access Port.
95+
/// Used for the command \ref DAP_Connect when Port Default mode is selected.
96+
#define DAP_DEFAULT_PORT 1 ///< Default JTAG/SWJ Port Mode: 1 = SWD, 2 = JTAG.
97+
98+
/// Default communication speed on the Debug Access Port for SWD and JTAG mode.
99+
/// Used to initialize the default SWD/JTAG clock frequency.
100+
/// The command \ref DAP_SWJ_Clock can be used to overwrite this default setting.
101+
#define DAP_DEFAULT_SWJ_CLOCK 10000000 ///< Default SWD/JTAG clock frequency in Hz.
102+
103+
/// Maximum Package Size for Command and Response data.
104+
/// This configuration settings is used to optimized the communication performance with the
105+
/// debugger and depends on the USB peripheral. Change setting to 1024 for High-Speed USB.
106+
#define DAP_PACKET_SIZE 64 ///< USB: 64 = Full-Speed, 1024 = High-Speed.
107+
108+
/// Maximum Package Buffers for Command and Response data.
109+
/// This configuration settings is used to optimized the communication performance with the
110+
/// debugger and depends on the USB peripheral. For devices with limited RAM or USB buffer the
111+
/// setting can be reduced (valid range is 1 .. 255). Change setting to 4 for High-Speed USB.
112+
#define DAP_PACKET_COUNT 12 ///< Buffers: 64 = Full-Speed, 4 = High-Speed.
113+
114+
#define DAP_PACKET_QUEUE_SIZE (DAP_PACKET_COUNT+8)
115+
116+
/// Debug Unit is connected to fixed Target Device.
117+
/// The Debug Unit may be part of an evaluation board and always connected to a fixed
118+
/// known device. In this case a Device Vendor and Device Name string is stored which
119+
/// may be used by the debugger or IDE to configure device parameters.
120+
#define TARGET_DEVICE_FIXED 0 ///< Target Device: 1 = known, 0 = unknown;
121+
122+
#if TARGET_DEVICE_FIXED
123+
#define TARGET_DEVICE_VENDOR "" ///< String indicating the Silicon Vendor
124+
#define TARGET_DEVICE_NAME "" ///< String indicating the Target Device
125+
#endif
126+
127+
///@}
128+
129+
#define SWCLK_GPIO_PORT GPIOA
130+
#define SWCLK_GPIO_PIN GPIO1
131+
#define SWDIO_GPIO_PORT GPIOA
132+
#define SWDIO_GPIO_PIN GPIO0
133+
#define nRESET_GPIO_PORT GPIOA
134+
#define nRESET_GPIO_PIN GPIO4
135+
136+
#define LED_CON_GPIO_PORT GPIOA
137+
#define LED_CON_GPIO_PIN GPIO5
138+
#define LED_RUN_GPIO_PORT GPIOA
139+
#define LED_RUN_GPIO_PIN GPIO6
140+
#define LED_ACT_GPIO_PORT GPIOA
141+
#define LED_ACT_GPIO_PIN GPIO7
142+
143+
#define SWDIO_GPIO_PIN_NUM 0
144+
145+
#endif

src/stm32f042/dap42dc/config.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2016, Devan Lai
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software
5+
* for any purpose with or without fee is hereby granted, provided
6+
* that the above copyright notice and this permission notice
7+
* appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10+
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11+
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12+
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13+
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15+
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
#ifndef CONFIG_H_INCLUDED
20+
#define CONFIG_H_INCLUDED
21+
22+
#define PRODUCT_NAME "DAP42dc"
23+
#define REMAP_USB 1
24+
25+
#define CAN_RX_AVAILABLE 1
26+
#define CAN_TX_AVAILABLE 0
27+
#define CAN_NVIC_LINE NVIC_CEC_CAN_IRQ
28+
29+
#define VCDC_AVAILABLE 0
30+
#define VCDC_TX_BUFFER_SIZE 256
31+
#define VCDC_RX_BUFFER_SIZE 256
32+
33+
#define CDC_AVAILABLE 1
34+
#define DEFAULT_BAUDRATE 115200
35+
36+
#define CONSOLE_USART USART2
37+
#define CONSOLE_TX_BUFFER_SIZE 128
38+
#define CONSOLE_RX_BUFFER_SIZE 1024
39+
40+
#define CONSOLE_USART_GPIO_PORT GPIOA
41+
#define CONSOLE_USART_GPIO_PINS (GPIO2|GPIO3)
42+
#define CONSOLE_USART_GPIO_AF GPIO_AF1
43+
#define CONSOLE_USART_MODE USART_MODE_TX_RX
44+
#define CONSOLE_USART_CLOCK RCC_USART2
45+
46+
#define CONSOLE_USART_IRQ_NAME usart2_isr
47+
#define CONSOLE_USART_NVIC_LINE NVIC_USART2_IRQ
48+
#define CONSOLE_RX_DMA_CONTROLLER DMA1
49+
#define CONSOLE_RX_DMA_CLOCK RCC_DMA
50+
#define CONSOLE_RX_DMA_CHANNEL DMA_CHANNEL5
51+
52+
#define DFU_AVAILABLE 1
53+
#define nBOOT0_GPIO_CLOCK RCC_GPIOB
54+
#define nBOOT0_GPIO_PORT GPIOB
55+
#define nBOOT0_GPIO_PIN GPIO8
56+
57+
/* Word size for usart_recv and usart_send */
58+
typedef uint8_t usart_word_t;
59+
60+
#define LED_OPEN_DRAIN 1
61+
62+
#endif

src/stm32f042/dap42dc/target.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2016, Devan Lai
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software
5+
* for any purpose with or without fee is hereby granted, provided
6+
* that the above copyright notice and this permission notice
7+
* appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10+
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11+
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12+
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13+
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15+
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
#include <libopencm3/stm32/rcc.h>
20+
#include <libopencm3/stm32/crs.h>
21+
#include <libopencm3/stm32/gpio.h>
22+
23+
#include "target.h"
24+
#include "config.h"
25+
26+
/* Reconfigure processor settings */
27+
void cpu_setup(void) {
28+
29+
}
30+
31+
/* Set STM32 to 48 MHz. */
32+
void clock_setup(void) {
33+
rcc_clock_setup_in_hsi48_out_48mhz();
34+
35+
// Trim from USB sync frame
36+
crs_autotrim_usb_enable();
37+
rcc_set_usbclk_source(RCC_HSI48);
38+
}
39+
40+
static void button_setup(void) {
41+
/* Enable GPIOB clock. */
42+
rcc_periph_clock_enable(RCC_GPIOB);
43+
44+
/* Set PB8 to an input */
45+
gpio_mode_setup(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO8);
46+
}
47+
48+
void gpio_setup(void) {
49+
/*
50+
LED0 (R), 1 (G), 2 (B) on PA5, PA6, PA7, open drain
51+
TX, RX (MCU-side) on PA2, PA3
52+
TGT_RST on PA4
53+
TGT_SWDIO, TGT_SWCLK on PA0, PA1
54+
*/
55+
56+
/* Enable GPIOA and GPIOB clocks. */
57+
rcc_periph_clock_enable(RCC_GPIOA);
58+
59+
/* Setup LEDs as open-drain outputs */
60+
gpio_set_output_options(GPIOA, GPIO_OTYPE_OD, GPIO_OSPEED_LOW,
61+
GPIO5 | GPIO6 | GPIO7);
62+
63+
gpio_mode_setup(GPIOA, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
64+
GPIO5 | GPIO6 | GPIO7);
65+
button_setup();
66+
}
67+
68+
void target_console_init(void) {
69+
/* Enable UART clock */
70+
rcc_periph_clock_enable(CONSOLE_USART_CLOCK);
71+
72+
/* Setup GPIO pins for UART2 */
73+
gpio_mode_setup(CONSOLE_USART_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, CONSOLE_USART_GPIO_PINS);
74+
gpio_set_af(CONSOLE_USART_GPIO_PORT, CONSOLE_USART_GPIO_AF, CONSOLE_USART_GPIO_PINS);
75+
}
76+
77+
void led_bit(uint8_t position, bool state) {
78+
uint32_t gpio = 0xFFFFFFFFU;
79+
if (position == 0) {
80+
gpio = GPIO5;
81+
} else if (position == 1) {
82+
gpio = GPIO6;
83+
} else if (position == 2) {
84+
gpio = GPIO7;
85+
}
86+
87+
if (gpio != 0xFFFFFFFFU) {
88+
if (state) {
89+
gpio_clear(GPIOA, gpio);
90+
} else {
91+
gpio_set(GPIOA, gpio);
92+
}
93+
}
94+
}
95+
96+
void led_num(uint8_t value) {
97+
if (value & 0x4) {
98+
gpio_clear(GPIOA, GPIO5);
99+
} else {
100+
gpio_set(GPIOA, GPIO5);
101+
}
102+
if (value & 0x2) {
103+
gpio_clear(GPIOA, GPIO6);
104+
} else {
105+
gpio_set(GPIOA, GPIO6);
106+
}
107+
if (value & 0x1) {
108+
gpio_clear(GPIOA, GPIO7);
109+
} else {
110+
gpio_set(GPIOA, GPIO7);
111+
}
112+
}

src/targets.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ ifeq ($(TARGET),DAP42K6U)
4444
LDSCRIPT ?= ./stm32f042/stm32f042x6.ld
4545
ARCH = STM32F0
4646
endif
47+
ifeq ($(TARGET),DAP42DC)
48+
TARGET_COMMON_DIR := ./stm32f042
49+
TARGET_SPEC_DIR := ./stm32f042/dap42dc
50+
LDSCRIPT ?= ./stm32f042/stm32f042x6.ld
51+
ARCH = STM32F0
52+
endif
4753
ifeq ($(TARGET),STM32F103)
4854
TARGET_COMMON_DIR := ./stm32f103
4955
TARGET_SPEC_DIR := ./stm32f103/stlinkv2-dongle

0 commit comments

Comments
 (0)