Skip to content

Commit adb3c30

Browse files
committed
Add preliminary Maple Mini support
1 parent 8cf25aa commit adb3c30

File tree

6 files changed

+215
-30
lines changed

6 files changed

+215
-30
lines changed

Diff for: src/Makefile

+5-8
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,14 @@ DFU_UTIL = dfu-util
2626
BOOT_VID_PID := 1209:0001
2727

2828
SRCS := $(wildcard *.c)
29-
SRCS += $(wildcard $(TARGET_DIR)/*.c)
29+
SRCS += $(wildcard $(TARGET_COMMON_DIR)/*.c)
30+
SRCS += $(wildcard $(TARGET_SPEC_DIR)/*.c)
3031

3132
OBJS += $(SRCS:.c=.o)
3233
DEPS = $(SRCS:.c=.d)
3334

3435
.DEFAULT_GOAL := $(BINARY).bin
3536

36-
%.dfuse-flash: %.bin
37-
$(DFU_UTIL) -d $(BOOT_VID_PID) -a 0 -s 0x08000000:leave -D $(<)
38-
39-
dfuse-flash: $(BINARY).dfuse-flash
40-
4137
clean::
4238
@rm -f $(OBJS)
4339
@rm -f $(DEPS)
@@ -53,12 +49,13 @@ debug: $(BINARY).elf
5349
erase:
5450
$(OOCD) -f $(OOCD_INTERFACE) -f $(OOCD_BOARD) -c "init" -c "reset init" -c "flash erase_sector 0 0 last" -c "reset" -c "shutdown"
5551

56-
.PHONY += debug size dfuse-flash erase
52+
.PHONY += debug size erase
5753

5854
OBJS := $(sort $(OBJS))
5955

6056
# Add the base directory to the header search path
6157
CPPFLAGS += -I.
6258

6359
# Add target config directory to the header search path
64-
CPPFLAGS += -I$(TARGET_DIR)/
60+
CPPFLAGS += -I$(TARGET_COMMON_DIR)/
61+
CPPFLAGS += -I$(TARGET_SPEC_DIR)/

Diff for: src/stm32f103/config.h renamed to src/stm32f103/generic/config.h

+12
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,16 @@
2424
#define DFU_UPLOAD_AVAILABLE 0
2525
#define DFU_DOWNLOAD_AVAILABLE 1
2626

27+
#ifndef HAVE_LED
28+
#define HAVE_LED 0
29+
#endif
30+
31+
#ifndef HAVE_BUTTON
32+
#define HAVE_BUTTON 0
33+
#endif
34+
35+
#ifndef HAVE_USB_PULLUP_CONTROL
36+
#define HAVE_USB_PULLUP_CONTROL 0
37+
#endif
38+
2739
#endif

Diff for: src/stm32f103/maplemini/config.h

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 APP_BASE_ADDRESS 0x08002000
23+
#define FLASH_PAGE_SIZE 1024
24+
#define DFU_UPLOAD_AVAILABLE 0
25+
#define DFU_DOWNLOAD_AVAILABLE 1
26+
27+
#define HAVE_LED 1
28+
#define LED_GPIO_PORT GPIOB
29+
#define LED_GPIO_PIN GPIO1
30+
#define LED_OPEN_DRAIN 0
31+
32+
#define HAVE_BUTTON 1
33+
#define BUTTON_GPIO_PORT GPIOB
34+
#define BUTTON_GPIO_PIN GPIO8
35+
#define BUTTON_ACTIVE_HIGH 1
36+
37+
#define HAVE_USB_PULLUP_CONTROL 1
38+
#define USB_PULLUP_GPIO_PORT GPIOB
39+
#define USB_PULLUP_GPIO_PIN GPIO9
40+
#define USB_PULLUP_ACTIVE_HIGH 0
41+
#define USB_PULLUP_OPEN_DRAIN 1
42+
43+
#define USES_GPIOA 0
44+
#define USES_GPIOB 1
45+
#define USES_GPIOC 0
46+
47+
#endif

Diff for: src/stm32f103/stlink/config.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 APP_BASE_ADDRESS 0x08002000
23+
#define FLASH_PAGE_SIZE 1024
24+
#define DFU_UPLOAD_AVAILABLE 0
25+
#define DFU_DOWNLOAD_AVAILABLE 1
26+
27+
#define HAVE_LED 1
28+
#define LED_GPIO_PORT GPIOA
29+
#define LED_GPIO_PIN GPIO9
30+
#define LED_OPEN_DRAIN 0
31+
32+
#define HAVE_BUTTON 0
33+
34+
#define HAVE_USB_PULLUP_CONTROL 0
35+
36+
#define USES_GPIOA 1
37+
38+
#endif

Diff for: src/stm32f103/target.c renamed to src/stm32f103/target_stm32f103.c

+89-19
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1717
*/
1818

19-
/* STM32F103-specific target functions */
19+
/* Common STM32F103 target functions */
2020

2121
#include <libopencm3/stm32/rcc.h>
2222
#include <libopencm3/stm32/gpio.h>
@@ -28,7 +28,22 @@
2828
#include "target.h"
2929
#include "config.h"
3030
#include "backup.h"
31-
#define LED_OPEN_DRAIN 0
31+
32+
#ifndef USES_GPIOA
33+
#if (HAVE_USB_PULLUP_CONTROL == 0)
34+
#define USES_GPIOA 1
35+
#else
36+
#define USES_GPIOA 0
37+
#endif
38+
#endif
39+
40+
#ifndef USES_GPIOB
41+
#define USES_GPIOB 0
42+
#endif
43+
44+
#ifndef USES_GPIOC
45+
#define USES_GPIOC 0
46+
#endif
3247

3348
static const uint32_t CMD_BOOT = 0x544F4F42UL;
3449

@@ -38,31 +53,73 @@ void target_clock_setup(void) {
3853
}
3954

4055
void target_gpio_setup(void) {
41-
/*
42-
LED0 on PA9
43-
*/
44-
45-
/* Enable GPIOA clock */
46-
rcc_periph_clock_enable(RCC_GPIOA);
56+
/* Enable GPIO clocks */
57+
if (USES_GPIOA) {
58+
rcc_periph_clock_enable(RCC_GPIOA);
59+
}
60+
if (USES_GPIOB) {
61+
rcc_periph_clock_enable(RCC_GPIOB);
62+
}
63+
if (USES_GPIOC) {
64+
rcc_periph_clock_enable(RCC_GPIOC);
65+
}
4766

4867
/* Setup LEDs */
49-
const uint8_t mode = GPIO_MODE_OUTPUT_10_MHZ;
50-
const uint8_t conf = (LED_OPEN_DRAIN ? GPIO_CNF_OUTPUT_OPENDRAIN
51-
: GPIO_CNF_OUTPUT_PUSHPULL);
52-
gpio_set_mode(GPIOA, mode, conf, GPIO9);
68+
#if HAVE_LED
69+
{
70+
const uint8_t mode = GPIO_MODE_OUTPUT_10_MHZ;
71+
const uint8_t conf = (LED_OPEN_DRAIN ? GPIO_CNF_OUTPUT_OPENDRAIN
72+
: GPIO_CNF_OUTPUT_PUSHPULL);
73+
if (LED_OPEN_DRAIN) {
74+
gpio_set(LED_GPIO_PORT, LED_GPIO_PIN);
75+
} else {
76+
gpio_clear(LED_GPIO_PORT, LED_GPIO_PIN);
77+
}
78+
gpio_set_mode(LED_GPIO_PORT, mode, conf, LED_GPIO_PIN);
79+
}
80+
#endif
81+
82+
#if HAVE_USB_PULLUP_CONTROL
83+
{
84+
const uint8_t mode = GPIO_MODE_OUTPUT_10_MHZ;
85+
const uint8_t conf = (USB_PULLUP_OPEN_DRAIN ? GPIO_CNF_OUTPUT_OPENDRAIN
86+
: GPIO_CNF_OUTPUT_PUSHPULL);
87+
/* Configure USB pullup transistor, initially disabled */
88+
if (USB_PULLUP_ACTIVE_HIGH) {
89+
gpio_clear(USB_PULLUP_GPIO_PORT, USB_PULLUP_GPIO_PIN);
90+
} else {
91+
gpio_set(USB_PULLUP_GPIO_PORT, USB_PULLUP_GPIO_PIN);
92+
}
93+
gpio_set_mode(USB_PULLUP_GPIO_PORT, mode, conf, USB_PULLUP_GPIO_PIN);
94+
}
95+
#else
96+
{
97+
/* Drive the USB DP pin to override the pull-up */
98+
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_10_MHZ,
99+
GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
100+
}
101+
#endif
53102
}
54103

55104
const usbd_driver* target_usb_init(void) {
56105
rcc_periph_reset_pulse(RST_USB);
57106

58-
rcc_periph_clock_enable(RCC_GPIOA);
59-
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_10_MHZ,
60-
GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);
107+
#if HAVE_USB_PULLUP_CONTROL
108+
/* Enable USB pullup to connect */
109+
if (USB_PULLUP_ACTIVE_HIGH) {
110+
gpio_set(USB_PULLUP_GPIO_PORT, USB_PULLUP_GPIO_PIN);
111+
} else {
112+
gpio_clear(USB_PULLUP_GPIO_PORT, USB_PULLUP_GPIO_PIN);
113+
}
114+
#else
115+
/* Override hard-wired USB pullup to disconnect and reconnect */
61116
gpio_clear(GPIOA, GPIO12);
62117
int i;
63-
for (i = 0; i < 800000; i++)
118+
for (i = 0; i < 800000; i++) {
64119
__asm__("nop");
65-
120+
}
121+
#endif
122+
66123
return &st_usbfs_v1_usb_driver;
67124
}
68125

@@ -73,10 +130,23 @@ bool target_get_force_bootloader(void) {
73130
if (cmd == CMD_BOOT) {
74131
force = true;
75132
}
76-
133+
77134
/* Clear the RTC backup register */
78135
backup_write(BKP0, 0);
79-
136+
137+
#if HAVE_BUTTON
138+
/* Check if the user button is held down */
139+
if (BUTTON_ACTIVE_HIGH) {
140+
if (gpio_get(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN)) {
141+
force = true;
142+
}
143+
} else {
144+
if (!gpio_get(BUTTON_GPIO_PORT, BUTTON_GPIO_PIN)) {
145+
force = true;
146+
}
147+
}
148+
#endif
149+
80150
return force;
81151
}
82152

Diff for: src/targets.mk

+24-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,31 @@
1515
## CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1616

1717
ifeq ($(TARGET),STM32F103)
18-
TARGET_DIR := ./stm32f103
19-
LDSCRIPT ?= $(TARGET_DIR)/stm32f103x8.ld
20-
ARCH = STM32F1
18+
TARGET_COMMON_DIR := ./stm32f103
19+
TARGET_SPEC_DIR := ./stm32f103/generic
20+
LDSCRIPT := ./stm32f103/stm32f103x8.ld
21+
ARCH = STM32F1
2122
endif
23+
ifeq ($(TARGET),BLUEPILL)
24+
TARGET_COMMON_DIR := ./stm32f103
25+
TARGET_SPEC_DIR := ./stm32f103/generic
26+
LDSCRIPT := ./stm32f103/stm32f103x8.ld
27+
ARCH = STM32F1
28+
DEFS += -DHAVE_LED=1 -DLED_GPIO_PORT=GPIOC -DLED_GPIO_PIN=GPIO13 -DLED_OPEN_DRAIN=1 -DUSES_GPIOC=1
29+
endif
30+
ifeq ($(TARGET),MAPLEMINI)
31+
TARGET_COMMON_DIR := ./stm32f103
32+
TARGET_SPEC_DIR := ./stm32f103/maplemini
33+
LDSCRIPT := ./stm32f103/stm32f103x8.ld
34+
ARCH = STM32F1
35+
endif
36+
ifeq ($(TARGET),STLINK)
37+
TARGET_COMMON_DIR := ./stm32f103
38+
TARGET_SPEC_DIR := ./stm32f103/stlink
39+
LDSCRIPT := ./stm32f103/stm32f103x8.ld
40+
ARCH = STM32F1
41+
endif
42+
2243
ifndef ARCH
2344
$(error Unknown target $(TARGET))
2445
endif

0 commit comments

Comments
 (0)