Skip to content

Commit b3d8255

Browse files
authored
Merge pull request #44 from twelho/bttskrminie3v2
Add support for the BigTreeTech SKR MINI E3 V2.0 board and STM32F103RC
2 parents cf8eb38 + f650c80 commit b3d8255

7 files changed

Lines changed: 298 additions & 4 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ To build other targets, you can override the
2121
|`STLINK` | STLink/v2 hardware clones | https://wiki.paparazziuav.org/wiki/STLink#Clones |
2222
|`OLIMEXSTM32H103` | Olimex STM32-H103 | https://www.olimex.com/Products/ARM/ST/STM32-H103/ |
2323
|`BLUEPILLPLUSSTM32` | Bluepill with USB C | https://github.com/WeActTC/BluePill-Plus/ |
24+
|`BTTSKRMINIE3V2` | BigTreeTech SKR MINI E3 V2.0 (3D printer motherboard) | https://github.com/bigtreetech/BIGTREETECH-SKR-mini-E3 |
25+
|`BTTSKRMINIE3V2_USBMOD` | BTT SKR MINI E3 V2.0 with USB pullup removed | https://github.com/bigtreetech/BIGTREETECH-SKR-mini-E3 |
2426

25-
For each of the above targets, there are three variants that can be added to the target name:
27+
For the above targets there are some potential variants that can be added to the target name based on what the target supports:
2628

2729
| Target Variant | Description |
2830
| -------------- | ----------------------------------------------------- |
2931
|` ` | Standard bootloader, using first 8kB of flash |
3032
|`_HIGH` | High memory bootloader for 64kB chips (experimental) |
3133
|`_HIGH_128` | High memory bootloader for 128kB chips (experimental) |
34+
|`_HIGH_256` | High memory bootloader for 256kB chips (experimental) |
3235

3336
The high memory bootloader is a variation that doesn't require the application to be at an offset, the bootloader resides in the top 6.5kB of ROM and hides its reset and stack vectors inside unused entries of the application vector table. As an example, to compile for a Bluepill board with 128kB flash, use:
3437

release.Makefile

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ all: dapboot-bluepill.bin \
3434
dapboot-stlink.bin \
3535
dapboot-olimexstm32h103.bin \
3636
dapboot-bluepillplusstm32.bin \
37+
dapboot-bttskrminie3v2.bin \
38+
dapboot-bttskrminie3v2-usbmod.bin \
3739
dapboot-bluepill-high.bin \
3840
dapboot-maplemini-high.bin \
3941
dapboot-stlink-high.bin \
@@ -43,7 +45,9 @@ all: dapboot-bluepill.bin \
4345
dapboot-maplemini-high-128.bin \
4446
dapboot-stlink-high-128.bin \
4547
dapboot-olimexstm32h103-high-128.bin \
46-
dapboot-bluepillplusstm32-high-128.bin
48+
dapboot-bluepillplusstm32-high-128.bin \
49+
dapboot-bttskrminie3v2-high-256.bin \
50+
dapboot-bttskrminie3v2-usbmod-high-256.bin
4751

4852
clean:
4953
$(Q)$(RM) $(BUILD_DIR)/*.bin
@@ -84,6 +88,18 @@ dapboot-bluepillplusstm32.bin: | $(BUILD_DIR)
8488
$(Q)$(MAKE) TARGET=BLUEPILLPLUSSTM32 -C src/
8589
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)
8690

91+
dapboot-bttskrminie3v2.bin: | $(BUILD_DIR)
92+
@printf " BUILD $(@)\n"
93+
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2 -C src/ clean
94+
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2 -C src/
95+
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)
96+
97+
dapboot-bttskrminie3v2-usbmod.bin: | $(BUILD_DIR)
98+
@printf " BUILD $(@)\n"
99+
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_USBMOD -C src/ clean
100+
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_USBMOD -C src/
101+
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)
102+
87103
dapboot-bluepill-high.bin: | $(BUILD_DIR)
88104
@printf " BUILD $(@)\n"
89105
$(Q)$(MAKE) TARGET=BLUEPILL_HIGH -C src/ clean
@@ -143,3 +159,15 @@ dapboot-bluepillplusstm32-high-128.bin: | $(BUILD_DIR)
143159
$(Q)$(MAKE) TARGET=BLUEPILLPLUSSTM32_HIGH_128 -C src/ clean
144160
$(Q)$(MAKE) TARGET=BLUEPILLPLUSSTM32_HIGH_128 -C src/
145161
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)
162+
163+
dapboot-bttskrminie3v2-high-256.bin: | $(BUILD_DIR)
164+
@printf " BUILD $(@)\n"
165+
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_HIGH_256 -C src/ clean
166+
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_HIGH_256 -C src/
167+
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)
168+
169+
dapboot-bttskrminie3v2-usbmod-high-256.bin: | $(BUILD_DIR)
170+
@printf " BUILD $(@)\n"
171+
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_USBMOD_HIGH_256 -C src/ clean
172+
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_USBMOD_HIGH_256 -C src/
173+
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)

src/stm32f103/skrminie3v2/config.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2021, Dennis Marttinen
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+
#ifndef APP_BASE_ADDRESS
23+
#define APP_BASE_ADDRESS (0x08000000 + BOOTLOADER_OFFSET)
24+
#endif
25+
#ifndef FLASH_PAGE_SIZE
26+
/* The BTT SKR MINI E3 V2.0 uses an STM32F103RC with 256 KiB of flash and 2 KiB pages */
27+
#define FLASH_PAGE_SIZE 2048
28+
#endif
29+
#ifndef DFU_UPLOAD_AVAILABLE
30+
#define DFU_UPLOAD_AVAILABLE 1
31+
#endif
32+
#ifndef DFU_DOWNLOAD_AVAILABLE
33+
#define DFU_DOWNLOAD_AVAILABLE 1
34+
#endif
35+
#ifndef DFU_WILL_DETACH
36+
#define DFU_WILL_DETACH 0
37+
#endif
38+
39+
/* There is a PCB-mounted status LED, but it's unreadable when the board is installed,
40+
* and additionally it's wired to SWDIO so toggling it manually is a bad idea */
41+
#ifndef HAVE_LED
42+
#define HAVE_LED 0
43+
#endif
44+
45+
/* Display encoder button (BTN-ENC) on PA15, no external pullup */
46+
#ifndef HAVE_BUTTON
47+
#define HAVE_BUTTON 1
48+
#endif
49+
#ifndef BUTTON_ACTIVE_HIGH
50+
#define BUTTON_ACTIVE_HIGH 0
51+
#endif
52+
#ifndef BUTTON_GPIO_PORT
53+
#define BUTTON_GPIO_PORT GPIOA
54+
#endif
55+
#ifndef BUTTON_GPIO_PIN
56+
#define BUTTON_GPIO_PIN GPIO15
57+
#endif
58+
#ifndef BUTTON_USES_PULL
59+
#define BUTTON_USES_PULL 1
60+
#endif
61+
#ifndef BUTTON_SAMPLE_DELAY_CYCLES
62+
#define BUTTON_SAMPLE_DELAY_CYCLES 1440000
63+
#endif
64+
65+
#ifndef HAVE_USB_PULLUP_CONTROL
66+
#define HAVE_USB_PULLUP_CONTROL 1
67+
#endif
68+
#ifndef USB_PULLUP_GPIO_PORT
69+
#define USB_PULLUP_GPIO_PORT GPIOA
70+
#endif
71+
#ifndef USB_PULLUP_GPIO_PIN
72+
#define USB_PULLUP_GPIO_PIN GPIO14
73+
#endif
74+
#ifndef USB_PULLUP_ACTIVE_HIGH
75+
#define USB_PULLUP_ACTIVE_HIGH 0
76+
#endif
77+
#ifndef USB_PULLUP_OPEN_DRAIN
78+
#define USB_PULLUP_OPEN_DRAIN 1
79+
#endif
80+
81+
#ifndef USES_GPIOA
82+
#define USES_GPIOA 1
83+
#endif
84+
85+
/* For stm32duino bootloader compatibility, the following options enable
86+
* bootloader flashing using KIAUH: https://github.com/th33xitus/kiauh */
87+
#ifndef REG_BOOT
88+
#define REG_BOOT BKP10
89+
#endif
90+
91+
#ifndef CMD_BOOT
92+
#define CMD_BOOT 1
93+
#endif
94+
95+
#ifndef USB_DFU_ALTN
96+
#define USB_DFU_ALTN 2
97+
#endif
98+
99+
#endif
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2021, Dennis Marttinen
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+
* ATTENTION! Using the USBMOD target requires hardware modifications to your BTT SKR MINI E3 V2.0. These modifications
21+
* aim to restore the broken SWD debugging support of this board by removing "unnecessary" components attached to the
22+
* SWDIO and SWDCLK pins. Read the comments carefully, and proceed at your own risk! Flashing this firmware on an
23+
* unmodified SKR MINI will not harm it, but USB will not work in the bootloader. Here's the schematic for the board for
24+
* looking up the component identifiers mentioned in the comments:
25+
* https://github.com/bigtreetech/BIGTREETECH-SKR-mini-E3/blob/master/hardware/BTT%20SKR%20MINI%20E3%20V2.0/Hardware/BTT%20SKR%20MINI%20E3%20V2.0SCHpdf.PDF
26+
*/
27+
28+
#ifndef CONFIG_H_INCLUDED
29+
#define CONFIG_H_INCLUDED
30+
31+
#ifndef APP_BASE_ADDRESS
32+
#define APP_BASE_ADDRESS (0x08000000 + BOOTLOADER_OFFSET)
33+
#endif
34+
#ifndef FLASH_PAGE_SIZE
35+
/* The BTT SKR MINI E3 V2.0 uses an STM32F103RC with 256 KiB of flash and 2 KiB pages */
36+
#define FLASH_PAGE_SIZE 2048
37+
#endif
38+
#ifndef DFU_UPLOAD_AVAILABLE
39+
#define DFU_UPLOAD_AVAILABLE 1
40+
#endif
41+
#ifndef DFU_DOWNLOAD_AVAILABLE
42+
#define DFU_DOWNLOAD_AVAILABLE 1
43+
#endif
44+
#ifndef DFU_WILL_DETACH
45+
#define DFU_WILL_DETACH 0
46+
#endif
47+
48+
/* There is a PCB-mounted status LED, but it's unreadable when the board is installed, and additionally it's wired to
49+
* SWDIO so toggling it manually is a bad idea. To restore reliable SWD communication, desolder either the status LED
50+
* itself (D16) or the resistor for it (R90). */
51+
#ifndef HAVE_LED
52+
#define HAVE_LED 0
53+
#endif
54+
55+
/* Display encoder button (BTN-ENC) on PA15, no external pullup */
56+
#ifndef HAVE_BUTTON
57+
#define HAVE_BUTTON 1
58+
#endif
59+
#ifndef BUTTON_ACTIVE_HIGH
60+
#define BUTTON_ACTIVE_HIGH 0
61+
#endif
62+
#ifndef BUTTON_GPIO_PORT
63+
#define BUTTON_GPIO_PORT GPIOA
64+
#endif
65+
#ifndef BUTTON_GPIO_PIN
66+
#define BUTTON_GPIO_PIN GPIO15
67+
#endif
68+
#ifndef BUTTON_USES_PULL
69+
#define BUTTON_USES_PULL 1
70+
#endif
71+
#ifndef BUTTON_SAMPLE_DELAY_CYCLES
72+
#define BUTTON_SAMPLE_DELAY_CYCLES 1440000
73+
#endif
74+
75+
/* The USB pullup MOSFET (U7) with its pullup resistor (R43) is wired to SWCLK on this board which makes attaching a
76+
* debug probe nearly impossible. It is however possible to desolder these two components and bridge the source and
77+
* drain contact pads for the MOSFET to gain debugger support. The [datasheet] for the MCU suggests that the pullup
78+
* resistor for the USB D+ pin (R44) is enough on its own, as the MCU itself can pull the pin down to initiate a USB
79+
* reset without an external MOSFET controlling that resistor. This does indeed work without any configuration in
80+
* dapboot as well as both the Klipper and Marlin 3D printer firmwares. There were no problems during testing when
81+
* performing software resets or using the reset button, the USB reset works seamlessly even when transitioning from
82+
* dapboot to a freshly flashed firmware.
83+
* [datasheet]: https://www.st.com/resource/en/datasheet/stm32f103rc.pdf */
84+
#ifndef HAVE_USB_PULLUP_CONTROL
85+
#define HAVE_USB_PULLUP_CONTROL 0
86+
#endif
87+
88+
#ifndef USES_GPIOA
89+
#define USES_GPIOA 1
90+
#endif
91+
92+
/* For stm32duino bootloader compatibility, the following options enable
93+
* bootloader flashing using KIAUH: https://github.com/th33xitus/kiauh */
94+
#ifndef REG_BOOT
95+
#define REG_BOOT BKP10
96+
#endif
97+
98+
#ifndef CMD_BOOT
99+
#define CMD_BOOT 1
100+
#endif
101+
102+
#ifndef USB_DFU_ALTN
103+
#define USB_DFU_ALTN 2
104+
#endif
105+
106+
#endif

src/stm32f103/stm32f103x8.ld

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919

2020
/* Linker script for STM32F103x8, 64k flash, 20k RAM.
21-
* This script also works for the STM32F103xB, as the bootloader uses only the
22-
* first 8kB of flash. */
21+
* This script also works for the STM32F103xB and the STM32F103xC,
22+
* as the bootloader only uses the first 8kB of flash. */
2323

2424
/* Define memory regions. */
2525
MEMORY

src/stm32f103/stm32f103xc_high.ld

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2015 Karl Palsson <karlp@tweak.net.au>
5+
*
6+
* This library is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
/* Linker script for STM32F103xC, 256k flash, 48k RAM. */
21+
22+
/* Define memory regions. */
23+
MEMORY
24+
{
25+
vectors (rx) : ORIGIN = 0x08000000, LENGTH = 0x150
26+
rom (rx) : ORIGIN = 0x0803e600, LENGTH = 0x1A00
27+
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 48K
28+
}
29+
30+
/* Include the common ld script. */
31+
INCLUDE stm32f103/stm32f1.ld

src/targets.mk

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ ifeq ($(TARGET),BLUEPILLPLUSSTM32_HIGH)
111111
TARGET_SPEC_DIR := ./stm32f103/bluepillplus
112112
LDSCRIPT := ./stm32f103/stm32f103x8_high.ld
113113
ARCH = STM32F1
114+
DEFS += -DBOOTLOADER_HIGH
114115
endif
115116
ifeq ($(TARGET),BLUEPILLPLUSSTM32_HIGH_128)
116117
TARGET_COMMON_DIR := ./stm32f103
@@ -125,6 +126,32 @@ ifeq ($(TARGET),BLUEPILLPLUSGD32)
125126
LDSCRIPT := ./stm32f103/stm32f103x8.ld
126127
ARCH = STM32F1
127128
endif
129+
ifeq ($(TARGET),BTTSKRMINIE3V2)
130+
TARGET_COMMON_DIR := ./stm32f103
131+
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2
132+
LDSCRIPT := ./stm32f103/stm32f103x8.ld
133+
ARCH = STM32F1
134+
endif
135+
ifeq ($(TARGET),BTTSKRMINIE3V2_HIGH_256)
136+
TARGET_COMMON_DIR := ./stm32f103
137+
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2
138+
LDSCRIPT := ./stm32f103/stm32f103xc_high.ld
139+
ARCH = STM32F1
140+
DEFS += -DBOOTLOADER_HIGH
141+
endif
142+
ifeq ($(TARGET),BTTSKRMINIE3V2_USBMOD)
143+
TARGET_COMMON_DIR := ./stm32f103
144+
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2_usbmod
145+
LDSCRIPT := ./stm32f103/stm32f103x8.ld
146+
ARCH = STM32F1
147+
endif
148+
ifeq ($(TARGET),BTTSKRMINIE3V2_USBMOD_HIGH_256)
149+
TARGET_COMMON_DIR := ./stm32f103
150+
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2_usbmod
151+
LDSCRIPT := ./stm32f103/stm32f103xc_high.ld
152+
ARCH = STM32F1
153+
DEFS += -DBOOTLOADER_HIGH
154+
endif
128155
ifeq ($(TARGET),STM32L1_GENERIC)
129156
TARGET_COMMON_DIR := ./stm32l1
130157
TARGET_SPEC_DIR := ./stm32l1/generic

0 commit comments

Comments
 (0)