Skip to content

Commit 49de9eb

Browse files
committed
STM32duino support added
1 parent aebf7b7 commit 49de9eb

16 files changed

+793
-41
lines changed

.gitignore

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#user files
2+
userconfig.h
3+
14
#working subdirs
25
obj/*
36
bin/*
@@ -15,4 +18,39 @@ openocd.cfg
1518
*.sublime-project
1619
*.sublime-workspace
1720

18-
.vscode
21+
# Prerequisites
22+
*.d
23+
24+
# Compiled Object files
25+
*.slo
26+
*.lo
27+
*.o
28+
*.obj
29+
30+
# Precompiled Headers
31+
*.gch
32+
*.pch
33+
34+
# Compiled Dynamic libraries
35+
*.so
36+
*.dylib
37+
*.dll
38+
39+
# Fortran module files
40+
*.mod
41+
*.smod
42+
43+
# Compiled Static libraries
44+
*.lai
45+
*.la
46+
*.a
47+
*.lib
48+
49+
# PlatformIO
50+
.pio
51+
52+
# Visual Studio Code
53+
.vscode/.browse.c_cpp.db*
54+
.vscode/c_cpp_properties.json
55+
.vscode/launch.json
56+
.vscode/ipch

.vscode/extensions.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"platformio.platformio-ide"
6+
],
7+
"unwantedRecommendations": [
8+
"ms-vscode.cpptools-extension-pack"
9+
]
10+
}

Makefile

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,25 +162,26 @@ swclean: | $(SWODIR)
162162

163163
clean: swclean fwclean
164164

165-
FWTARGETS = stm32l100x6a stm32l100x8a stm32l100xba stm32l100xc
166-
FWTARGETS += stm32l151x6a stm32l151x8a stm32l151xba stm32l151xc stm32l151xd stm32l151xe
167-
FWTARGETS += stm32l152x6a stm32l152x8a stm32l152xba stm32l152xc stm32l152xd stm32l152xe
168-
FWTARGETS += stm32l152xc stm32l162xc stm32l162xd stm32l162xe
169-
FWTARGETS += stm32l052x6 stm32l052x8 stm32l053x6 stm32l053x8
170-
FWTARGETS += stm32l062x8 stm32l063x8
171-
FWTARGETS += stm32l072v8 stm32l072xb stm32l072xc
172-
FWTARGETS += stm32l073v8 stm32l073xb stm32l073xc
173-
FWTARGETS += stm32l476xc stm32l476xe stm32l476xg
174-
FWTARGETS += stm32f103x4 stm32f103x6 stm32f103x8 stm32f103xb stm32f103xc
175-
FWTARGETS += stm32f303xb stm32f303xc stm32f303xd stm32f303xe
176-
FWTARGETS += stm32f401xe stm32f411xe stm32f429xe stm32f429xg stm32f429xi stm32f429xi_hs
177-
FWTARGETS += stm32f105xb stm32f107xb
178-
FWTARGETS += stm32l433xb stm32l433xc
179-
FWTARGETS += stm32f070x6 stm32f070xb stm32f072x8
180-
FWTARGETS += stm32g431x6 stm32g431x8 stm32g431xb
181-
FWTARGETS += stm32g474xb stm32g474xc stm32g474xe
182-
FWTARGETS += stm32f446xc stm32f446xc_hs stm32f446xe stm32f446xe_hs
183-
FWTARGETS += stm32f405xg stm32f405xg_hs
165+
#FWTARGETS = stm32l100x6a stm32l100x8a stm32l100xba stm32l100xc
166+
#FWTARGETS += stm32l151x6a stm32l151x8a stm32l151xba stm32l151xc stm32l151xd stm32l151xe
167+
#FWTARGETS += stm32l152x6a stm32l152x8a stm32l152xba stm32l152xc stm32l152xd stm32l152xe
168+
#FWTARGETS += stm32l152xc stm32l162xc stm32l162xd stm32l162xe
169+
#FWTARGETS += stm32l052x6 stm32l052x8 stm32l053x6 stm32l053x8
170+
#FWTARGETS += stm32l062x8 stm32l063x8
171+
#FWTARGETS += stm32l072v8 stm32l072xb stm32l072xc
172+
#FWTARGETS += stm32l073v8 stm32l073xb stm32l073xc
173+
#FWTARGETS += stm32l476xc stm32l476xe stm32l476xg
174+
#FWTARGETS += stm32f103x4 stm32f103x6 stm32f103x8 stm32f103xb stm32f103xc
175+
#FWTARGETS += stm32f303xb stm32f303xc stm32f303xd stm32f303xe
176+
#FWTARGETS += stm32f401xe stm32f411xe stm32f429xe stm32f429xg stm32f429xi stm32f429xi_hs
177+
#FWTARGETS += stm32f105xb stm32f107xb
178+
#FWTARGETS += stm32l433xb stm32l433xc
179+
#FWTARGETS += stm32f070x6 stm32f070xb stm32f072x8
180+
#FWTARGETS += stm32g431x6 stm32g431x8 stm32g431xb
181+
#FWTARGETS += stm32g474xb stm32g474xc stm32g474xe
182+
#FWTARGETS += stm32f446xc stm32f446xc_hs stm32f446xe stm32f446xe_hs
183+
#FWTARGETS += stm32f405xg stm32f405xg_hs
184+
FWTARGETS = stm32f401xe stm32f411xe stm32f401xe_0x2000 stm32f411xe_0x2000
184185

185186
$(FWTARGETS) : fwclean
186187

@@ -454,12 +455,24 @@ stm32f401xe :
454455
FWDEFS='STM32F4 STM32F401xE' \
455456
LDPARAMS='ROMLEN=512K RAMLEN=96K APPALIGN=0x4000'
456457

458+
stm32f401xe_0x2000 :
459+
$(MAKE) bootloader FWCPU='-mcpu=cortex-m4' \
460+
FWSTARTUP='mcu/stm32f4xx.S' \
461+
FWDEFS='STM32F4 STM32F401xE' \
462+
LDPARAMS='ROMLEN=512K RAMLEN=96K APPALIGN=0x2000'
463+
457464
stm32f411xe :
458465
$(MAKE) bootloader FWCPU='-mcpu=cortex-m4' \
459466
FWSTARTUP='mcu/stm32f4xx.S' \
460467
FWDEFS='STM32F4 STM32F411xE' \
461468
LDPARAMS='ROMLEN=512K RAMLEN=128K APPALIGN=0x4000'
462469

470+
stm32f411xe_0x2000 :
471+
$(MAKE) bootloader FWCPU='-mcpu=cortex-m4' \
472+
FWSTARTUP='mcu/stm32f4xx.S' \
473+
FWDEFS='STM32F4 STM32F411xE' \
474+
LDPARAMS='ROMLEN=512K RAMLEN=128K APPALIGN=0x2000'
475+
463476
stm32f429xe :
464477
$(MAKE) bootloader FWCPU='-mcpu=cortex-m4' \
465478
FWSTARTUP='mcu/stm32f4xx.S' \

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
First things first: Don't forget to read the original [README.md](README_org.md) of the parent project.
2+
3+
### Secure STM32duino-compatible USB DFU1.1 bootloader for STM32F401(xE) and STM32F411(xE) (Blackpill)
4+
This is a fork of [dmitrystu's](https://github.com/dmitrystu/) great [sboot_stm32](https://github.com/dmitrystu/sboot_stm32) bootloader, which is a beautiful piece of software, with a few modifications to make it act similarly like [rogerclarkmelbourne's](https://github.com/rogerclarkmelbourne/) [STM32duino-bootloader](https://github.com/rogerclarkmelbourne/STM32duino-bootloader), adapt the nifty little RTC magic number feature from [Serasidis'](https://github.com/Serasidis/) [STM32 HID-Bootloader](https://github.com/Serasidis/STM32_HID_Bootloader), and thus provide better compatiblity to the [STM32duino Arduino Core](https://github.com/stm32duino/Arduino_Core_STM32) - especially when developing with [PlatformIO](https://docs.platformio.org/en/latest/integration/ide/vscode.html) and VSCode.
5+
6+
#### So why all this?
7+
For downloading firmwares to your Blackpill via USB you can simply do the little finger dance and you're fine... kind of... unless you're some lazy dude like me, who doesn't want to do the extra [equilibristics](https://en.wiktionary.org/wiki/equilibristics) to fiddle around with the board all the time while coding. Having a pretty weak pull-down connected to BOOT1 with a far higher resistance than my thick clumsy fingers doesn't help neither.
8+
9+
Since the STM32F103 doesn't have a USB-capable bootloader in ROM, [Roger](https://github.com/rogerclarkmelbourne/) wrote the [STM32duino-bootloader](https://github.com/rogerclarkmelbourne/STM32duino-bootloader) for the Bluepill and [ST-Link Baite-Clones](https://www.google.com/search?q=STink+bait), which always starts up after resetting the board and then proceeds to the user application after a short timeout. This way the host can toggle the DTR "pin" of the USB-serial which is detected by the [STM32duino Arduino Core](https://github.com/stm32duino/Arduino_Core_STM32) and triggers a reset of the board like the [Maple](https://www.leaflabs.com/maple) boards first implemented this.
10+
11+
The beforementioned [HID Bootloader](https://github.com/Serasidis/STM32_HID_Bootloader), which is [only partly supported](https://docs.platformio.org/en/stable/boards/ststm32/blackpill_f411ce.html#uploading) by PlatformIO's [ST STM32-platform](https://docs.platformio.org/en/stable/platforms/ststm32.html), and [Roger's](https://github.com/rogerclarkmelbourne/) [STM32duino-bootloader](https://github.com/rogerclarkmelbourne/STM32duino-bootloader) additionally implement [checking a register of the RTC's backup domain](https://github.com/rogerclarkmelbourne/STM32duino-bootloader/blob/master/hardware.c#L241) to determine whether the bootloader should be [force-entered](https://github.com/Serasidis/STM32_HID_Bootloader/blob/master/bootloader/F4/Src/main.c#L136) or [skipped completely](https://github.com/rogerclarkmelbourne/STM32duino-bootloader/blob/master/main.c#L49) after the reset, which can be controlled by the user application and is also reflected in the [STM32duino Arduino Core](https://github.com/stm32duino/Arduino_Core_STM32). See its [bootloader.c](https://github.com/stm32duino/Arduino_Core_STM32/blob/main/libraries/SrcWrapper/src/stm32/bootloader.c) for more details.
12+
13+
To complete the whole and round it nicely [WeAct](https://github.com/WeActStudio/) especially made their [HID Bootloader](https://github.com/WeActStudio/WeAct_HID_Bootloader_F4x1) incompatible with [Serasidis'](https://github.com/Serasidis/) [STM32 HID-Bootloader](https://github.com/Serasidis/STM32_HID_Bootloader) from which it was forked and their Blackpills are usually shipped with. Yay! [I'm lovin' it!](https://www.youtube.com/watch?v=tfhlEP8LT4k)
14+
15+
#### Bringing it all together
16+
So what would be nice is a standard dfu-capable bootloader that can easily be entered automatically using your development IDE and is supported by the standard STM32-Arduino Framework.
17+
So here you go!
18+
19+
**This bootloader implements**
20+
+ The DFU protocol (sboot)
21+
+ Application offsets 0x2000 and 0x4000 in flash
22+
(it can actually be quite tiny depending on the selected features)
23+
+ Automatically entering the bootloader after power-on (STM32duino-bootloader)
24+
+ Entering the bootloader by double-clicking the reset-button (sboot)
25+
+ Entering the bootloader by holding down a user-button (all)
26+
+ Force-entering the bootloader when no firmware is detected (STM32duino-bootloader)
27+
+ Force-entering or force-skipping the bootloader by
28+
+ RTC magic number (HID/STM32duino Bootloader) or
29+
+ magic number in SRAM (sboot)
30+
+ Automatically exiting the bootloader and running the firmware after various configurable timeouts
31+
+ Encrypted firmware downloads (sboot)
32+
+ Verifying the checksum of the firmware (sboot)
33+
+ A nervously flashing LED while in bootloader
34+
+ Each of the features above can be enabled/disabled separately
35+
Not all combinations make sense! You choose! ([userconfig.h](https://github.com/rbm78bln/STM32duino-bootloader_stm32f411-blackpill/blob/master/userconfig-example.h))
36+
37+
**Supported MCU targets**
38+
39+
| mcu_target | MCU | remarks |
40+
|---------------|-------------|---------|
41+
| stm32f401xe | STM32F401xE | tested |
42+
| stm32f411xe | STM32F411xE | tested |
43+
44+
#### This bootloader does not (yet?) implement
45+
+ ST-DfuSe extensions
46+
+ STM32F103 MCU targets (Bluepills, [Baite-STLinks](https://www.google.com/search?q=STink+bait))
47+
+ Being badly incompatible to everything else ([WeAct HID-Bootloader](https://github.com/WeActStudio/WeAct_HID_Bootloader_F4x1))
48+
49+
#### Activating the bootloader
50+
+ Simply just power up your board
51+
+ Toggle the DTR "pin" of the USB-serial interface
52+
+ Write RTC_MAGIC_NUMBER_BOOTLOADER into register 4 of the RTC backup domain (RTC->BKP4R) and issue a (whatever) reset
53+
+ Write DFU_BOOTKEY at DFU_BOOTKEY_ADDR (RAM top by default) and make a software reset
54+
+ Assert DFU_BOOTSTRAP_PIN on DFU_BOOTSTRAP_PORT on startup
55+
+ Make a double reset during the DFU_DBLRESET_MS period
56+
+ Overwrite the first four bytes of your user firmware
57+
58+
![Ralf Miunske](https://miunske.eu/github/?sboot_stm32f411)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"folders": [
3+
{
4+
"name": "STM32F411duino-bootloader",
5+
"path": "."
6+
}
7+
],
8+
"settings": {
9+
"platformio-ide.autoPreloadEnvTasks": true,
10+
"platformio-ide.disablePIOHomeStartup": true,
11+
"files.associations": {
12+
"*.json": "jsonc"
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)