Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
9eca23a
Update erase target to handle unlocking flash
devanlai Aug 27, 2017
e6147fa
Using WINUSB_MS_VENDOR_CODE in extra string
karelbilek Dec 3, 2017
ebc9b4b
Migrate from CircleCI 1.0 to 2.0
devanlai Feb 28, 2018
9b16a36
Fixes issue #13. Added a delay(Approximately 20ms) before reading the…
0x3333 Aug 9, 2019
7216508
Added a variable to control the button sample delay.
0x3333 Aug 9, 2019
a1975ed
Fix issue #15.
0x3333 Aug 9, 2019
b1f4a08
Added a README entry explaining the button usage.
0x3333 Aug 9, 2019
e3a77a8
Fix C89 compatibility.
0x3333 Aug 9, 2019
aee636b
Merge pull request #14 from 0x3333/master
devanlai Aug 9, 2019
d78d0f7
Fix a miserable typo.
0x3333 Aug 9, 2019
05941c8
Merge pull request #18 from 0x3333/issue14
devanlai Aug 9, 2019
0071344
Merge pull request #16 from 0x3333/issue15
devanlai Aug 9, 2019
8bb813a
Fixes issue #17. Added guard on all defines in config.h, allowing the…
0x3333 Aug 9, 2019
fed09dd
Created a target for BluePill, allowing it to be overridden.
0x3333 Aug 9, 2019
ff22575
Merge pull request #19 from 0x3333/issue17
devanlai Aug 9, 2019
9bb26fa
Merge pull request #7 from karel-3d/patch-1
devanlai Aug 19, 2019
a9e1f57
Don't compile all of libopencm3, only required target
Feb 26, 2020
a5bbe4c
Merge pull request #20 from KoviRobi/dont-build-all-of-libopencm3
devanlai Feb 26, 2020
9415383
Allow configuring button pull-ups in each target.
dmsc Apr 17, 2020
7595c15
bluepill: Use the BOOT1 input in to enter the bootloader.
dmsc Apr 17, 2020
7b62074
Use link-time-optimization in the build.
dmsc Apr 17, 2020
f7d5035
Merge pull request #21 from dmsc/use-boot1-as-button
devanlai Apr 19, 2020
3c5a855
Merge pull request #22 from dmsc/use-lto
devanlai Apr 19, 2020
e0bde59
Link with newlib-nano, this is 348 bytes smaller.
dmsc May 2, 2020
0dfd64e
Implement experimental high-memory bootloader
dmsc May 2, 2020
1e4c130
Merge pull request #24 from dmsc/optional-hiboot
devanlai May 4, 2020
083f3af
Pass through custom toolchain PREFIX for locm3
devanlai May 4, 2020
5879c2e
Fill bin file gaps with all ones instead of zeros
devanlai May 4, 2020
d6dd446
Differentiate product name for high-memory version of the bootloader
devanlai May 4, 2020
c015c39
Bump version to 1.11
devanlai May 4, 2020
e047ca0
Update CI toolchain from 2017q2 (GCC 6.2.1) to 2019q4 (9.2.1)
devanlai May 4, 2020
b019c6e
Update README board links
devanlai May 4, 2020
0fbb8a0
dfu: allow overriding wTransferSize
karlp Oct 13, 2020
24d7045
dfu: allow targets to customize poll interval
karlp Oct 13, 2020
217cf4f
add stm32l1 target
karlp Oct 13, 2020
a89c83f
Merge pull request #27 from karlp/l1
devanlai Oct 13, 2020
c8c3a2f
dfu: support "detach"
karlp Oct 13, 2020
c87c047
l1: avoid warnings on "abuse" of .data subsections
karlp Oct 13, 2020
2b3bf0b
Update to rebased latest version of locm3
devanlai Oct 17, 2020
a4873e1
Merge pull request #28 from karlp/dfu-detach
devanlai Oct 17, 2020
1b91699
dfu: defer detach reset to after USB response
devanlai Oct 17, 2020
013a47d
Merge pull request #29 from karlp/l1-sections
devanlai Oct 17, 2020
eb14188
Add support for Olimex STM32-H103
jeanthom Apr 5, 2021
099d8e8
Implement button for Olimex STM32-H103
jeanthom Apr 6, 2021
8787895
Fix LED pin for Olimex STM32-H103
jeanthom Apr 6, 2021
2189eca
Use open drain for USB pull-up control in Olimex STM32-H103
jeanthom Apr 6, 2021
2040e7a
Merge pull request #32 from jeanthom/master
devanlai Apr 6, 2021
1a92de6
Allow configuration of VID/PID without hacking up the source code
obra Jul 13, 2021
b768145
Merge pull request #33 from keyboardio/configurable-vid-pid
devanlai Jul 13, 2021
9e2fd01
Document how to customize the DFU endpoint URL
obra Jul 13, 2021
6d868b4
Merge pull request #34 from keyboardio/document-lp-url
devanlai Jul 13, 2021
bff90e4
Add Bluepill Plus support
iovxw Aug 14, 2021
c883e96
Merge pull request #36 from iovxw/bluepill-plus
devanlai Aug 14, 2021
30aebb7
A tiny refactoring of the toolchain fetch helper that makes it also w…
obra Sep 3, 2021
f66d7d5
Slightly jumped the gun on the previous commit. There were other
obra Sep 4, 2021
9b544e5
Allow more flexibility when configuring from config.h
obra Sep 4, 2021
af09454
Extract Vendor, Product, and Interface strings so they can be overrid…
obra Sep 4, 2021
b96c8b9
Merge pull request #37 from keyboardio/jesse/mac-toolchain
devanlai Sep 4, 2021
0173069
Merge pull request #38 from keyboardio/jesse/override-vid-pid-url
devanlai Sep 4, 2021
087b7c7
Merge pull request #39 from keyboardio/jesse/extract-descriptor-strings
devanlai Sep 4, 2021
4f61d96
Add a new target for the GigaDevice variant of the BluePill Plus.
obra Sep 4, 2021
7f8279d
Fix detach request callback being treated as manifest request callback
twelho Sep 6, 2021
aea139a
Fix RTC backup register indexing, add target-specific register and bo…
twelho Sep 6, 2021
5aa7684
Enable specifying the alternate setting for the DFU interface per-target
twelho Sep 6, 2021
e26b474
Fix: set BOOTLOADER_HIGH for target BLUEPILLPLUSSTM32_HIGH
twelho Sep 6, 2021
d785495
Add support for the BigTreeTech SKR MINI E3 V2.0 board and STM32F103RC
twelho Sep 6, 2021
e49cd53
Add BTT SKR MINI E3 V2.0 targets to release.Makefile
twelho Sep 6, 2021
ffd5464
Merge pull request #40 from keyboardio/jesse/bluepillplus-gd32
devanlai Sep 7, 2021
5ad3db6
Move descriptors back to usb_conf.c, set iInterface to 4, rename macr…
twelho Sep 10, 2021
30e54d0
Use only one backup register for CMD_BOOT for stm32f103 based targets
twelho Sep 10, 2021
bc98fc4
Add DFU_WILL_DETACH option for automatic detach/reset and enable it b…
twelho Sep 10, 2021
4af4c1a
Update config.h for BTTSKRMINIE3V2{,_USBMOD} to accommodate changes f…
twelho Sep 10, 2021
f650c80
Merge remote-tracking branch 'upstream/master' into bttskrminie3v2
twelho Sep 10, 2021
da0ec9d
Adjust DFU_WILL_DETACH behavior
devanlai Sep 11, 2021
9bf8c4d
Detect USB requests and reset or enter error state
devanlai Sep 11, 2021
191a092
Refine manifest request event criteria
devanlai Sep 11, 2021
d1428ca
Merge pull request #42 from twelho/fix-rtc-bkp-register-indexing
devanlai Sep 11, 2021
29fdafe
Merge pull request #43 from twelho/dfu-custom-alt-setting
devanlai Sep 11, 2021
178d909
Implement proper manifestation according to the spec
twelho Sep 11, 2021
cf8eb38
Merge pull request #41 from twelho/fix-manifest-reset
devanlai Sep 11, 2021
b3d8255
Merge pull request #44 from twelho/bttskrminie3v2
devanlai Sep 11, 2021
7e25c1e
Replace target_manifest_app with target_pre_detach
devanlai Sep 11, 2021
1013c98
Update README with bootloader changes
devanlai Sep 11, 2021
3f5f387
Update RTC backup register notes
devanlai Sep 11, 2021
0ca7707
Add a new 'target_post_setup' hook that targets can use for their own
obra Mar 7, 2022
94762bd
Merge pull request #47 from keyboardio/f/target-post-setup-hook
devanlai Mar 7, 2022
fd1acb5
Remove BTTSKRMINIE3V2_USBMOD, use BTTSKRMINIE3V2 instead
twelho Jul 8, 2023
af4d680
Fix build for high memory targets
twelho Jul 8, 2023
1cd9417
Disable SWD if PA13/PA14 are used for another purpose
twelho Jul 8, 2023
78ea3e6
Replace CircleCI with GitHub Actions
devanlai Jul 15, 2023
9af0f05
Merge pull request #51 from twelho/fix-highmem
devanlai Jul 15, 2023
44585f5
Merge pull request #52 from twelho/fix-usbpullup
devanlai Jul 15, 2023
2fe6322
Merge pull request #50 from twelho/skrminie3v2-fixes
devanlai Jul 15, 2023
8f9011b
locm3: rebase to recent master
devanlai Feb 21, 2025
8a1f099
github: update to upload-artifact v4
devanlai Feb 22, 2025
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
38 changes: 38 additions & 0 deletions .github/workflows/build-firmware.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build Firmware
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3
with:
submodules: recursive

- name: Cache Toolchain
id: cache-toolchain
uses: actions/cache@v3
env:
cache-name: cache-toolchain
with:
path: ~/toolchains/
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('util/install-toolchain.sh') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-

- if: ${{ steps.cache-toolchain.outputs.cache-hit != 'true' }}
name: Download toolchain
run: ./util/install-toolchain.sh

- name: Build Firmware
run: make -f release.Makefile -k all
env:
PREFIX: ~/toolchains/gcc-arm-embedded/bin/arm-none-eabi-

- name: Archive Firmware
uses: actions/upload-artifact@v4
with:
name: firmware-bin
path: build/*.bin
71 changes: 64 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,35 @@ The default target is a generic STM32F103 dev board with an LED on PC13, commonl
To build other targets, you can override the
`TARGET` variable when invoking `make`.

cd src/
make clean
make TARGET=STLINK

### Targets

| Target Name | Description | Link |
| ----------- | ----------- |----- |
|`BLUEPILL` | Cheap dev board | http://wiki.stm32duino.com/index.php?title=Blue_Pill |
|`MAPLEMINI` | LeafLabs Maple Mini board and clone derivatives | http://wiki.stm32duino.com/index.php?title=Maple_Mini |
|`BLUEPILL` | Cheap dev board | https://stm32duinoforum.com/forum/wiki_subdomain/index_title_Blue_Pill.html |
|`MAPLEMINI` | LeafLabs Maple Mini board and clone derivatives | https://stm32duinoforum.com/forum/wiki_subdomain/index_title_Maple_Mini.html |
|`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 |

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 8 KiB of flash |
|`_HIGH` | High memory bootloader for 64 KiB chips (experimental) |
|`_HIGH_128` | High memory bootloader for 128 KiB chips (experimental) |
|`_HIGH_256` | High memory bootloader for 256 KiB 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 7 KiB 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 128 KiB flash, use:

make clean
make TARGET=BLUEPILL_HIGH_128


## Flash instructions
The `make flash` target will use openocd to upload the bootloader to an attached board. By default, the Makefile assumes you're using a [CMSIS-DAP](http://www.arm.com/products/processors/cortex-m/cortex-microcontroller-software-interface-standard.php) based probe, but you can override this by overriding `OOCD_INTERFACE` variable. For example:
Expand All @@ -33,24 +52,62 @@ Here is an example `local.mk` that changes the default target to the STLink/v2 a
TARGET ?= STLINK
OOCD_INTERFACE ?= interface/stlink-v2.cfg

You can also use the env variable `DEFS` to override default configuration for a target, like:

# Disable LED on BluePill
DEFS="-DHAVE_LED=0" make TARGET=BLUEPILL

# Allow access to all Flash on MapleMini and change the app base address
DEFS="-DFLASH_SIZE_OVERRIDE=0x20000 -DAPP_BASE_ADDRESS=0x08004000" make TARGET=MAPLEMINI LDSCRIPT="/some/folder/stm32f103x8-16kb-boot.ld"

## Using the bootloader
### Building for the bootloader
The bootloader occupies the lower 8KiB of flash, so your application must offset its flash contents by 8KiB. This can be done by modifying your linker script or flags as appropriate.
The standard bootloader occupies the lower 8KiB of flash, so your application must offset its flash contents by 8KiB. This can be done by modifying your linker script or flags as appropriate.

The high memory bootloaders do not use the lower part of the flash, so you only need to make sure your application leaves 7 KiB of flash free.

See the [highboot branch](https://github.com/devanlai/dapboot/tree/highboot) for an experimental variation that doesn't require the application to be offset.

### Switching to the bootloader
The bootloader can be built to look for arbitrary patterns, but the default for the STM32F103 target looks for a magic value stored in the RTC backup registers. Writing the magic value and then resetting will run the bootloader instead of the main application.
The bootloader can be built to look for arbitrary patterns, but the default looks for a magic value stored in the RTC backup registers. Writing the magic value and then resetting will run the bootloader instead of the main application.

In version v1.11 and earlier, the bootloader for STM32F103 targets looks for `0x544F` in RTC backup register 2 and `0x4F42` in RTC backup register 1 (together they spell "BOOT" in ASCII). From v1.20 on, the bootloader will only use RTC backup register 1 and check for `0x4F42` on targets with 16-bit backup registers and `0x544F4F42` on targets with 32-bit backup registers.

The backup register and bootloader command word can be customized with the `REG_BOOT` and `CMD_BOOT` defines respectively.

You can also use a button to stay in bootloader while booting. It's configured using `HAVE_BUTTON` define. If your button has a debounce capacitor, you can use `BUTTON_SAMPLE_DELAY_CYCLES` define to specify how many cycles to wait before sampling the I/O pin, by default it is approximately 20ms in a 72Mhz MCU.

The bootloader currently looks for `0x544F` in RTC backup register 1 and `0x4F42` in RTC backup register 0 (together they spell "BOOT" in ASCII).
On the bluepill boards, the default is using the BOOT1 input (available on jumper in the board) to enter the bootloader.

### WebUSB
This bootloader implements the draft [WebUSB](https://wicg.github.io/webusb/) specification, which allows web pages to access the bootloader (after presenting the user with a device picker dialog).

For a demo implementing dfu-util features in the browser, see https://devanlai.github.io/webdfu/dfu-util/

To customize the WebUSB landing page, you can use the `LANDING_PAGE_URL` define. To set it from the command line, you can use the `DEFS` environment variable:

DEFS='-DLANDING_PAGE_URL=\"example.com/dfu-util/\"' make

Note that the URL scheme shoul not be part of the `LANDING_PAGE_URL` string. As of this writing, it is hardcoded to HTTPS.

### Manifestation behavior
There are two different manifestation behaviors that can be selected using the `DFU_WILL_DETACH` define. By default, `DFU_WILL_DETACH` is set to 1 for backwards compatibility with existing behavior.

When `DFU_WILL_DETACH` is enabled, the bootloader autonomously reboot into the new firmware after it has been successfully downloaded and passes the basic validation check. This can be helpful on platforms such as Windows where it is not possible to generate a USB bus reset to signal that the bootloader should switch to the application.

When `DFU_WILL_DETACH` is disabled, the bootloader will return to the idle state after validating the firmware. The DFU host application can then perform other operations or reboot the target into the new firmware by issuing a DFU detach request or generating a USB bus reset. (This can be done with `dfu-util` by passing the `-R` flag).

## USB VID/PID
The USB VID/PID pair ([1209/DB42](http://pid.codes/1209/DB42/)) is allocated through the [pid.codes](http://pid.codes/) open-source USB PID program.
The default USB VID/PID pair ([1209/DB42](http://pid.codes/1209/DB42/)) is allocated through the [pid.codes](http://pid.codes/) open-source USB PID program.

To use a custom VID/PID pair, you need to set the macros `USB_VID` and `USB_PID`. One way to do this is by setting the `DEFS` environment variable when compiling:

DEFS="-DUSB_VID=0x1209 -DUSB_PID=0xCAFE" make


## USB Vendor, Product, and Interface strings

To customize the USB vendor, product, and interface strings that DAPBoot reports to the USB host, you may set the macros `USB_VENDOR_STRING`, `USB_PRODUCT_STRING`, and `USB_INTERFACE_STRING`, respectively. You can do this by setting the `DEFS` environment variable or including these macros in your board's `config.h`


## Licensing
All contents of the dapboot project are licensed under terms that are compatible with the terms of the GNU Lesser General Public License version 3.
Expand Down
12 changes: 0 additions & 12 deletions circle.yml

This file was deleted.

2 changes: 1 addition & 1 deletion libopencm3
Submodule libopencm3 updated 1182 files
100 changes: 99 additions & 1 deletion release.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ BUILD_DIR ?= ./build

all: dapboot-bluepill.bin \
dapboot-maplemini.bin \
dapboot-stlink.bin
dapboot-stlink.bin \
dapboot-olimexstm32h103.bin \
dapboot-bluepillplusstm32.bin \
dapboot-bttskrminie3v2.bin \
dapboot-bluepill-high.bin \
dapboot-maplemini-high.bin \
dapboot-stlink-high.bin \
dapboot-olimexstm32h103-high.bin \
dapboot-bluepillplusstm32-high.bin \
dapboot-bluepill-high-128.bin \
dapboot-maplemini-high-128.bin \
dapboot-stlink-high-128.bin \
dapboot-olimexstm32h103-high-128.bin \
dapboot-bluepillplusstm32-high-128.bin \
dapboot-bttskrminie3v2-high-256.bin

clean:
$(Q)$(RM) $(BUILD_DIR)/*.bin
Expand Down Expand Up @@ -59,3 +73,87 @@ dapboot-maplemini.bin: | $(BUILD_DIR)
$(Q)$(MAKE) TARGET=MAPLEMINI -C src/ clean
$(Q)$(MAKE) TARGET=MAPLEMINI -C src/
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)

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

dapboot-bluepillplusstm32.bin: | $(BUILD_DIR)
@printf " BUILD $(@)\n"
$(Q)$(MAKE) TARGET=BLUEPILLPLUSSTM32 -C src/ clean
$(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-bluepill-high.bin: | $(BUILD_DIR)
@printf " BUILD $(@)\n"
$(Q)$(MAKE) TARGET=BLUEPILL_HIGH -C src/ clean
$(Q)$(MAKE) TARGET=BLUEPILL_HIGH -C src/
$(Q)cp src/dapboot.bin $(BUILD_DIR)/$(@)

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

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

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

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

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

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

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

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

dapboot-bluepillplusstm32-high-128.bin: | $(BUILD_DIR)
@printf " BUILD $(@)\n"
$(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)/$(@)
7 changes: 5 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ clean::
include rules.mk

size: $(OBJS) $(BINARY).elf
@$(PREFIX)-size $(OBJS) $(BINARY).elf
@$(PREFIX)size $(OBJS) $(BINARY).elf

debug: $(BINARY).elf
-$(GDB) --tui --eval "target remote | $(OOCD) -f $(OOCD_INTERFACE) -f $(OOCD_BOARD) -f debug.cfg" $(BINARY).elf

erase:
$(OOCD) -f $(OOCD_INTERFACE) -f $(OOCD_BOARD) -c "init" -c "reset init" -c "flash erase_sector 0 0 last" -c "reset" -c "shutdown"
$(OOCD) -f $(OOCD_INTERFACE) -f $(OOCD_BOARD) \
-c "init" -c "reset init" \
-c "stm32f1x unlock 0; reset halt" \
-c "flash erase_sector 0 0 last" -c "reset" -c "shutdown"

.PHONY += debug size erase

Expand Down
22 changes: 10 additions & 12 deletions src/dapboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,36 @@

#include "dapboot.h"
#include "target.h"
#include "config.h"
#include "usb_conf.h"
#include "dfu.h"
#include "webusb.h"
#include "winusb.h"
#include "config.h"

static inline void __set_MSP(uint32_t topOfMainStack) {
asm("msr msp, %0" : : "r" (topOfMainStack));
}

bool validate_application(void) {
if ((*(volatile uint32_t *)APP_BASE_ADDRESS & 0x2FFE0000) == 0x20000000) {
return true;
}
return false;
return ((uint32_t)(APP_INITIAL_STACK) & 0x2FFE0000) == 0x20000000;
}

static void jump_to_application(void) __attribute__ ((noreturn));

static void jump_to_application(void) {
vector_table_t* app_vector_table = (vector_table_t*)APP_BASE_ADDRESS;


/* Use the application's vector table */
target_relocate_vector_table();
if (APP_RELOCATE_VECTORS)
target_relocate_vector_table();

/* Do any necessary early setup for the application */
target_pre_main();

/* Initialize the application's stack pointer */
__set_MSP((uint32_t)(app_vector_table->initial_sp_value));
__set_MSP((uint32_t)(APP_INITIAL_STACK));

/* Jump to the application entry point */
app_vector_table->reset();
APP_ENTRY_POINT();

while (1);
}
Expand All @@ -75,10 +72,11 @@ int main(void) {
}

usbd_device* usbd_dev = usb_setup();
dfu_setup(usbd_dev, &target_manifest_app, NULL, NULL);
dfu_setup(usbd_dev, validate_application, NULL, NULL);
webusb_setup(usbd_dev);
winusb_setup(usbd_dev);

target_post_setup();

while (1) {
usbd_poll(usbd_dev);
}
Expand Down
18 changes: 18 additions & 0 deletions src/dapboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,22 @@

extern bool validate_application(void);

#ifdef BOOTLOADER_HIGH
/* Definitions for high memory bootloader */
#define APP_INITIAL_STACK vector_table.reserved_x001c[0]
#define APP_ENTRY_POINT vector_table.reserved_x001c[1]
#define APP_RELOCATE_VECTORS 0
#define DFU_PATCH_VECTORS 1
#define BOOTLOADER_OFFSET 0

#else
/* Definitions for low memory (standard) bootloader */
#define APP_INITIAL_STACK ((vector_table_t*)APP_BASE_ADDRESS)->initial_sp_value
#define APP_ENTRY_POINT ((vector_table_t*)APP_BASE_ADDRESS)->reset
#define APP_RELOCATE_VECTORS 1
#define DFU_PATCH_VECTORS 0
#define BOOTLOADER_OFFSET 0x00002000

#endif

#endif
Loading