Skip to content

Commit d785495

Browse files
committed
Add support for the BigTreeTech SKR MINI E3 V2.0 board and STM32F103RC
The BigTreeTech SKR MINI E3 V2.0 is a 3D printer motherboard based on the STM32F103RC with 256 KiB of flash. Out of the box it has a MOSFET controlling the USB pullup wired to the SWCLK pin, which makes attaching a debugger very difficult. The USBMOD target variant has pullup control disabled for people that feel adventurous enough to desolder some components from their board to fix this issue, there is a more in-depth explanation in the USBMOD config.h. Both targets have a high memory variant which has been tested and confirmed working with the Klipper firmware by specifying "no bootloader" in its memory offset configuration menu.
1 parent e26b474 commit d785495

6 files changed

Lines changed: 262 additions & 3 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

src/stm32f103/skrminie3v2/config.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
36+
/* There is a PCB-mounted status LED, but it's unreadable when the board is installed,
37+
* and additionally it's wired to SWDIO so toggling it manually is a bad idea */
38+
#ifndef HAVE_LED
39+
#define HAVE_LED 0
40+
#endif
41+
42+
/* Display encoder button (BTN-ENC) on PA15, no external pullup */
43+
#ifndef HAVE_BUTTON
44+
#define HAVE_BUTTON 1
45+
#endif
46+
#ifndef BUTTON_ACTIVE_HIGH
47+
#define BUTTON_ACTIVE_HIGH 0
48+
#endif
49+
#ifndef BUTTON_GPIO_PORT
50+
#define BUTTON_GPIO_PORT GPIOA
51+
#endif
52+
#ifndef BUTTON_GPIO_PIN
53+
#define BUTTON_GPIO_PIN GPIO15
54+
#endif
55+
#ifndef BUTTON_USES_PULL
56+
#define BUTTON_USES_PULL 1
57+
#endif
58+
#ifndef BUTTON_SAMPLE_DELAY_CYCLES
59+
#define BUTTON_SAMPLE_DELAY_CYCLES 1440000
60+
#endif
61+
62+
#ifndef HAVE_USB_PULLUP_CONTROL
63+
#define HAVE_USB_PULLUP_CONTROL 1
64+
#endif
65+
#ifndef USB_PULLUP_GPIO_PORT
66+
#define USB_PULLUP_GPIO_PORT GPIOA
67+
#endif
68+
#ifndef USB_PULLUP_GPIO_PIN
69+
#define USB_PULLUP_GPIO_PIN GPIO14
70+
#endif
71+
#ifndef USB_PULLUP_ACTIVE_HIGH
72+
#define USB_PULLUP_ACTIVE_HIGH 0
73+
#endif
74+
#ifndef USB_PULLUP_OPEN_DRAIN
75+
#define USB_PULLUP_OPEN_DRAIN 1
76+
#endif
77+
78+
#ifndef USES_GPIOA
79+
#define USES_GPIOA 1
80+
#endif
81+
82+
/* For stm32duino bootloader compatibility, the following options enable
83+
* bootloader flashing using KIAUH: https://github.com/th33xitus/kiauh */
84+
#ifndef REG_BOOT
85+
#define REG_BOOT BKP10
86+
#endif
87+
88+
#ifndef CMD_BOOT
89+
#define CMD_BOOT 1
90+
#endif
91+
92+
#ifndef USB_ALT
93+
#define USB_ALT 2
94+
#endif
95+
96+
#endif
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
45+
/* There is a PCB-mounted status LED, but it's unreadable when the board is installed, and additionally it's wired to
46+
* SWDIO so toggling it manually is a bad idea. To restore reliable SWD communication, desolder either the status LED
47+
* itself (D16) or the resistor for it (R90). */
48+
#ifndef HAVE_LED
49+
#define HAVE_LED 0
50+
#endif
51+
52+
/* Display encoder button (BTN-ENC) on PA15, no external pullup */
53+
#ifndef HAVE_BUTTON
54+
#define HAVE_BUTTON 1
55+
#endif
56+
#ifndef BUTTON_ACTIVE_HIGH
57+
#define BUTTON_ACTIVE_HIGH 0
58+
#endif
59+
#ifndef BUTTON_GPIO_PORT
60+
#define BUTTON_GPIO_PORT GPIOA
61+
#endif
62+
#ifndef BUTTON_GPIO_PIN
63+
#define BUTTON_GPIO_PIN GPIO15
64+
#endif
65+
#ifndef BUTTON_USES_PULL
66+
#define BUTTON_USES_PULL 1
67+
#endif
68+
#ifndef BUTTON_SAMPLE_DELAY_CYCLES
69+
#define BUTTON_SAMPLE_DELAY_CYCLES 1440000
70+
#endif
71+
72+
/* The USB pullup MOSFET (U7) with its pullup resistor (R43) is wired to SWCLK on this board which makes attaching a
73+
* debug probe nearly impossible. It is however possible to desolder these two components and bridge the source and
74+
* drain contact pads for the MOSFET to gain debugger support. The [datasheet] for the MCU suggests that the pullup
75+
* 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
76+
* reset without an external MOSFET controlling that resistor. This does indeed work without any configuration in
77+
* dapboot as well as both the Klipper and Marlin 3D printer firmwares. There were no problems during testing when
78+
* performing software resets or using the reset button, the USB reset works seamlessly even when transitioning from
79+
* dapboot to a freshly flashed firmware.
80+
* [datasheet]: https://www.st.com/resource/en/datasheet/stm32f103rc.pdf */
81+
#ifndef HAVE_USB_PULLUP_CONTROL
82+
#define HAVE_USB_PULLUP_CONTROL 0
83+
#endif
84+
85+
#ifndef USES_GPIOA
86+
#define USES_GPIOA 1
87+
#endif
88+
89+
/* For stm32duino bootloader compatibility, the following options enable
90+
* bootloader flashing using KIAUH: https://github.com/th33xitus/kiauh */
91+
#ifndef REG_BOOT
92+
#define REG_BOOT BKP10
93+
#endif
94+
95+
#ifndef CMD_BOOT
96+
#define CMD_BOOT 1
97+
#endif
98+
99+
#ifndef USB_ALT
100+
#define USB_ALT 2
101+
#endif
102+
103+
#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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,32 @@ ifeq ($(TARGET),BLUEPILLPLUSSTM32_HIGH_128)
120120
ARCH = STM32F1
121121
DEFS += -DBOOTLOADER_HIGH
122122
endif
123+
ifeq ($(TARGET),BTTSKRMINIE3V2)
124+
TARGET_COMMON_DIR := ./stm32f103
125+
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2
126+
LDSCRIPT := ./stm32f103/stm32f103x8.ld
127+
ARCH = STM32F1
128+
endif
129+
ifeq ($(TARGET),BTTSKRMINIE3V2_HIGH_256)
130+
TARGET_COMMON_DIR := ./stm32f103
131+
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2
132+
LDSCRIPT := ./stm32f103/stm32f103xc_high.ld
133+
ARCH = STM32F1
134+
DEFS += -DBOOTLOADER_HIGH
135+
endif
136+
ifeq ($(TARGET),BTTSKRMINIE3V2_USBMOD)
137+
TARGET_COMMON_DIR := ./stm32f103
138+
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2_usbmod
139+
LDSCRIPT := ./stm32f103/stm32f103x8.ld
140+
ARCH = STM32F1
141+
endif
142+
ifeq ($(TARGET),BTTSKRMINIE3V2_USBMOD_HIGH_256)
143+
TARGET_COMMON_DIR := ./stm32f103
144+
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2_usbmod
145+
LDSCRIPT := ./stm32f103/stm32f103xc_high.ld
146+
ARCH = STM32F1
147+
DEFS += -DBOOTLOADER_HIGH
148+
endif
123149
ifeq ($(TARGET),STM32L1_GENERIC)
124150
TARGET_COMMON_DIR := ./stm32l1
125151
TARGET_SPEC_DIR := ./stm32l1/generic

0 commit comments

Comments
 (0)