Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ To build other targets, you can override the
|`STLINK` | STLink/v2 hardware clones | https://wiki.paparazziuav.org/wiki/STLink#Clones |
|`OLIMEXSTM32H103` | Olimex STM32-H103 | https://www.olimex.com/Products/ARM/ST/STM32-H103/ |
|`BLUEPILLPLUSSTM32` | Bluepill with USB C | https://github.com/WeActTC/BluePill-Plus/ |
|`BTTSKRMINIE3V2` | BigTreeTech SKR MINI E3 V2.0 (3D printer motherboard) | https://github.com/bigtreetech/BIGTREETECH-SKR-mini-E3 |
|`BTTSKRMINIE3V2_USBMOD` | BTT SKR MINI E3 V2.0 with USB pullup removed | https://github.com/bigtreetech/BIGTREETECH-SKR-mini-E3 |

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

| Target Variant | Description |
| -------------- | ----------------------------------------------------- |
|` ` | Standard bootloader, using first 8kB of flash |
|`_HIGH` | High memory bootloader for 64kB chips (experimental) |
|`_HIGH_128` | High memory bootloader for 128kB chips (experimental) |
|`_HIGH_256` | High memory bootloader for 256kB chips (experimental) |

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:

Expand Down
30 changes: 29 additions & 1 deletion release.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ all: dapboot-bluepill.bin \
dapboot-stlink.bin \
dapboot-olimexstm32h103.bin \
dapboot-bluepillplusstm32.bin \
dapboot-bttskrminie3v2.bin \
dapboot-bttskrminie3v2-usbmod.bin \
dapboot-bluepill-high.bin \
dapboot-maplemini-high.bin \
dapboot-stlink-high.bin \
Expand All @@ -43,7 +45,9 @@ all: dapboot-bluepill.bin \
dapboot-maplemini-high-128.bin \
dapboot-stlink-high-128.bin \
dapboot-olimexstm32h103-high-128.bin \
dapboot-bluepillplusstm32-high-128.bin
dapboot-bluepillplusstm32-high-128.bin \
dapboot-bttskrminie3v2-high-256.bin \
dapboot-bttskrminie3v2-usbmod-high-256.bin

clean:
$(Q)$(RM) $(BUILD_DIR)/*.bin
Expand Down Expand Up @@ -84,6 +88,18 @@ dapboot-bluepillplusstm32.bin: | $(BUILD_DIR)
$(Q)$(MAKE) TARGET=BLUEPILLPLUSSTM32 -C src/
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)

dapboot-bttskrminie3v2.bin: | $(BUILD_DIR)
@printf " BUILD $(@)\n"
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2 -C src/ clean
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2 -C src/
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)

dapboot-bttskrminie3v2-usbmod.bin: | $(BUILD_DIR)
@printf " BUILD $(@)\n"
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_USBMOD -C src/ clean
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_USBMOD -C src/
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)

dapboot-bluepill-high.bin: | $(BUILD_DIR)
@printf " BUILD $(@)\n"
$(Q)$(MAKE) TARGET=BLUEPILL_HIGH -C src/ clean
Expand Down Expand Up @@ -143,3 +159,15 @@ dapboot-bluepillplusstm32-high-128.bin: | $(BUILD_DIR)
$(Q)$(MAKE) TARGET=BLUEPILLPLUSSTM32_HIGH_128 -C src/ clean
$(Q)$(MAKE) TARGET=BLUEPILLPLUSSTM32_HIGH_128 -C src/
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)

dapboot-bttskrminie3v2-high-256.bin: | $(BUILD_DIR)
@printf " BUILD $(@)\n"
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_HIGH_256 -C src/ clean
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_HIGH_256 -C src/
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)

dapboot-bttskrminie3v2-usbmod-high-256.bin: | $(BUILD_DIR)
@printf " BUILD $(@)\n"
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_USBMOD_HIGH_256 -C src/ clean
$(Q)$(MAKE) TARGET=BTTSKRMINIE3V2_USBMOD_HIGH_256 -C src/
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)
99 changes: 99 additions & 0 deletions src/stm32f103/skrminie3v2/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2021, Dennis Marttinen
*
* Permission to use, copy, modify, and/or distribute this software
* for any purpose with or without fee is hereby granted, provided
* that the above copyright notice and this permission notice
* appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef CONFIG_H_INCLUDED
#define CONFIG_H_INCLUDED

#ifndef APP_BASE_ADDRESS
#define APP_BASE_ADDRESS (0x08000000 + BOOTLOADER_OFFSET)
#endif
#ifndef FLASH_PAGE_SIZE
/* The BTT SKR MINI E3 V2.0 uses an STM32F103RC with 256 KiB of flash and 2 KiB pages */
#define FLASH_PAGE_SIZE 2048
#endif
#ifndef DFU_UPLOAD_AVAILABLE
#define DFU_UPLOAD_AVAILABLE 1
#endif
#ifndef DFU_DOWNLOAD_AVAILABLE
#define DFU_DOWNLOAD_AVAILABLE 1
#endif
#ifndef DFU_WILL_DETACH
#define DFU_WILL_DETACH 0
#endif

/* There is a PCB-mounted status LED, but it's unreadable when the board is installed,
* and additionally it's wired to SWDIO so toggling it manually is a bad idea */
#ifndef HAVE_LED
#define HAVE_LED 0
#endif

/* Display encoder button (BTN-ENC) on PA15, no external pullup */
#ifndef HAVE_BUTTON
#define HAVE_BUTTON 1
#endif
#ifndef BUTTON_ACTIVE_HIGH
#define BUTTON_ACTIVE_HIGH 0
#endif
#ifndef BUTTON_GPIO_PORT
#define BUTTON_GPIO_PORT GPIOA
#endif
#ifndef BUTTON_GPIO_PIN
#define BUTTON_GPIO_PIN GPIO15
#endif
#ifndef BUTTON_USES_PULL
#define BUTTON_USES_PULL 1
#endif
#ifndef BUTTON_SAMPLE_DELAY_CYCLES
#define BUTTON_SAMPLE_DELAY_CYCLES 1440000
#endif

#ifndef HAVE_USB_PULLUP_CONTROL
#define HAVE_USB_PULLUP_CONTROL 1
#endif
#ifndef USB_PULLUP_GPIO_PORT
#define USB_PULLUP_GPIO_PORT GPIOA
#endif
#ifndef USB_PULLUP_GPIO_PIN
#define USB_PULLUP_GPIO_PIN GPIO14
#endif
#ifndef USB_PULLUP_ACTIVE_HIGH
#define USB_PULLUP_ACTIVE_HIGH 0
#endif
#ifndef USB_PULLUP_OPEN_DRAIN
#define USB_PULLUP_OPEN_DRAIN 1
#endif

#ifndef USES_GPIOA
#define USES_GPIOA 1
#endif

/* For stm32duino bootloader compatibility, the following options enable
* bootloader flashing using KIAUH: https://github.com/th33xitus/kiauh */
#ifndef REG_BOOT
#define REG_BOOT BKP10
#endif

#ifndef CMD_BOOT
#define CMD_BOOT 1
#endif

#ifndef USB_DFU_ALTN
#define USB_DFU_ALTN 2
#endif

#endif
106 changes: 106 additions & 0 deletions src/stm32f103/skrminie3v2_usbmod/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2021, Dennis Marttinen
*
* Permission to use, copy, modify, and/or distribute this software
* for any purpose with or without fee is hereby granted, provided
* that the above copyright notice and this permission notice
* appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

/*
* ATTENTION! Using the USBMOD target requires hardware modifications to your BTT SKR MINI E3 V2.0. These modifications
* aim to restore the broken SWD debugging support of this board by removing "unnecessary" components attached to the
* SWDIO and SWDCLK pins. Read the comments carefully, and proceed at your own risk! Flashing this firmware on an
* unmodified SKR MINI will not harm it, but USB will not work in the bootloader. Here's the schematic for the board for
* looking up the component identifiers mentioned in the comments:
* 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
*/

#ifndef CONFIG_H_INCLUDED
#define CONFIG_H_INCLUDED

#ifndef APP_BASE_ADDRESS
#define APP_BASE_ADDRESS (0x08000000 + BOOTLOADER_OFFSET)
#endif
#ifndef FLASH_PAGE_SIZE
/* The BTT SKR MINI E3 V2.0 uses an STM32F103RC with 256 KiB of flash and 2 KiB pages */
#define FLASH_PAGE_SIZE 2048
#endif
#ifndef DFU_UPLOAD_AVAILABLE
#define DFU_UPLOAD_AVAILABLE 1
#endif
#ifndef DFU_DOWNLOAD_AVAILABLE
#define DFU_DOWNLOAD_AVAILABLE 1
#endif
#ifndef DFU_WILL_DETACH
#define DFU_WILL_DETACH 0
#endif

/* There is a PCB-mounted status LED, but it's unreadable when the board is installed, and additionally it's wired to
* SWDIO so toggling it manually is a bad idea. To restore reliable SWD communication, desolder either the status LED
* itself (D16) or the resistor for it (R90). */
#ifndef HAVE_LED
#define HAVE_LED 0
#endif

/* Display encoder button (BTN-ENC) on PA15, no external pullup */
#ifndef HAVE_BUTTON
#define HAVE_BUTTON 1
#endif
#ifndef BUTTON_ACTIVE_HIGH
#define BUTTON_ACTIVE_HIGH 0
#endif
#ifndef BUTTON_GPIO_PORT
#define BUTTON_GPIO_PORT GPIOA
#endif
#ifndef BUTTON_GPIO_PIN
#define BUTTON_GPIO_PIN GPIO15
#endif
#ifndef BUTTON_USES_PULL
#define BUTTON_USES_PULL 1
#endif
#ifndef BUTTON_SAMPLE_DELAY_CYCLES
#define BUTTON_SAMPLE_DELAY_CYCLES 1440000
#endif

/* The USB pullup MOSFET (U7) with its pullup resistor (R43) is wired to SWCLK on this board which makes attaching a
* debug probe nearly impossible. It is however possible to desolder these two components and bridge the source and
* drain contact pads for the MOSFET to gain debugger support. The [datasheet] for the MCU suggests that the pullup
* 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
* reset without an external MOSFET controlling that resistor. This does indeed work without any configuration in
* dapboot as well as both the Klipper and Marlin 3D printer firmwares. There were no problems during testing when
* performing software resets or using the reset button, the USB reset works seamlessly even when transitioning from
* dapboot to a freshly flashed firmware.
* [datasheet]: https://www.st.com/resource/en/datasheet/stm32f103rc.pdf */
#ifndef HAVE_USB_PULLUP_CONTROL
#define HAVE_USB_PULLUP_CONTROL 0
#endif

#ifndef USES_GPIOA
#define USES_GPIOA 1
#endif

/* For stm32duino bootloader compatibility, the following options enable
* bootloader flashing using KIAUH: https://github.com/th33xitus/kiauh */
#ifndef REG_BOOT
#define REG_BOOT BKP10
#endif

#ifndef CMD_BOOT
#define CMD_BOOT 1
#endif

#ifndef USB_DFU_ALTN
#define USB_DFU_ALTN 2
#endif

#endif
4 changes: 2 additions & 2 deletions src/stm32f103/stm32f103x8.ld
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

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

/* Define memory regions. */
MEMORY
Expand Down
31 changes: 31 additions & 0 deletions src/stm32f103/stm32f103xc_high.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of the libopencm3 project.
*
* Copyright (C) 2015 Karl Palsson <karlp@tweak.net.au>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

/* Linker script for STM32F103xC, 256k flash, 48k RAM. */

/* Define memory regions. */
MEMORY
{
vectors (rx) : ORIGIN = 0x08000000, LENGTH = 0x150
rom (rx) : ORIGIN = 0x0803e600, LENGTH = 0x1A00
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 48K
}

/* Include the common ld script. */
INCLUDE stm32f103/stm32f1.ld
27 changes: 27 additions & 0 deletions src/targets.mk
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ ifeq ($(TARGET),BLUEPILLPLUSSTM32_HIGH)
TARGET_SPEC_DIR := ./stm32f103/bluepillplus
LDSCRIPT := ./stm32f103/stm32f103x8_high.ld
ARCH = STM32F1
DEFS += -DBOOTLOADER_HIGH
endif
ifeq ($(TARGET),BLUEPILLPLUSSTM32_HIGH_128)
TARGET_COMMON_DIR := ./stm32f103
Expand All @@ -125,6 +126,32 @@ ifeq ($(TARGET),BLUEPILLPLUSGD32)
LDSCRIPT := ./stm32f103/stm32f103x8.ld
ARCH = STM32F1
endif
ifeq ($(TARGET),BTTSKRMINIE3V2)
TARGET_COMMON_DIR := ./stm32f103
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2
LDSCRIPT := ./stm32f103/stm32f103x8.ld
ARCH = STM32F1
endif
ifeq ($(TARGET),BTTSKRMINIE3V2_HIGH_256)
TARGET_COMMON_DIR := ./stm32f103
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2
LDSCRIPT := ./stm32f103/stm32f103xc_high.ld
ARCH = STM32F1
DEFS += -DBOOTLOADER_HIGH
endif
ifeq ($(TARGET),BTTSKRMINIE3V2_USBMOD)
TARGET_COMMON_DIR := ./stm32f103
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2_usbmod
LDSCRIPT := ./stm32f103/stm32f103x8.ld
ARCH = STM32F1
endif
ifeq ($(TARGET),BTTSKRMINIE3V2_USBMOD_HIGH_256)
TARGET_COMMON_DIR := ./stm32f103
TARGET_SPEC_DIR := ./stm32f103/skrminie3v2_usbmod
LDSCRIPT := ./stm32f103/stm32f103xc_high.ld
ARCH = STM32F1
DEFS += -DBOOTLOADER_HIGH
endif
ifeq ($(TARGET),STM32L1_GENERIC)
TARGET_COMMON_DIR := ./stm32l1
TARGET_SPEC_DIR := ./stm32l1/generic
Expand Down