Skip to content

Add stm32 bootloader support - #1001

Open
mariolopjr wants to merge 1 commit into
rmk-rs:mainfrom
mariolopjr:mariolopjr/add-smt32-bootloader-reboot-support
Open

Add stm32 bootloader support#1001
mariolopjr wants to merge 1 commit into
rmk-rs:mainfrom
mariolopjr:mariolopjr/add-smt32-bootloader-reboot-support

Conversation

@mariolopjr

@mariolopjr mariolopjr commented Jul 24, 2026

Copy link
Copy Markdown

I have two Mode Design keyboards which use the stm32 chip, specifically the STM32F401RC chip.

This is PR1 of two.

I ported the way QMK does a software restart on these boards (before keys are processed) to enter DFU, and then jumping to the actual keyboard firmware after flashing.

Works well on my two boards and been flashing/restarting/using it the past week. Let me know if there's anything you would want changed!

@mariolopjr mariolopjr changed the title Add smt32 bootloader support Add stm32 bootloader support Jul 24, 2026
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

Size Report

Example main PR Diff .text .data .bss
use_config/nrf52832_ble 398.7 KiB 398.7 KiB +0.00% 0 0 0
use_config/nrf52840_ble 448.3 KiB 448.3 KiB +0.00% ⬇️ -4 0 0
use_config/nrf52840_ble_split (central) 501.4 KiB 501.4 KiB +0.00% ⬆️ +4 0 0
use_config/nrf52840_ble_split (peripheral) 320.5 KiB 320.5 KiB +0.00% ⬇️ -4 0 0
use_config/pi_pico_w_ble 672.4 KiB 672.4 KiB +0.00% ⬇️ -8 0 0
use_config/rp2040 150.4 KiB 150.4 KiB +0.00% ⬇️ -4 0 0
use_config/rp2040_split (central) 164.3 KiB 164.3 KiB +0.00% 0 0 0
use_config/rp2040_split (peripheral) 27.8 KiB 27.8 KiB +0.00% 0 0 0
use_config/stm32f1 63.6 KiB 63.8 KiB +0.35% ⬆️ +220 0 +12
use_config/stm32h7 101.9 KiB 102.1 KiB +0.22% ⬆️ +224 0 +12
use_rust/nrf52832_ble 387.0 KiB 387.0 KiB +0.00% ⬇️ -4 0 0
use_rust/nrf52840_ble 441.9 KiB 441.9 KiB +0.00% ⬆️ +4 0 0
use_rust/nrf52840_ble_split (central) 508.0 KiB 508.0 KiB +0.00% 0 0 0
use_rust/nrf52840_ble_split (peripheral) 318.4 KiB 318.4 KiB +0.00% 0 0 0
use_rust/pi_pico_w_ble 672.8 KiB 672.7 KiB +0.00% ⬇️ -8 0 0
use_rust/rp2040 150.2 KiB 150.2 KiB +0.00% ⬇️ -4 0 0
use_rust/rp2040_split (central) 162.7 KiB 162.7 KiB +0.00% ⬇️ -4 0 0
use_rust/rp2040_split (peripheral) 28.2 KiB 28.2 KiB +0.00% 0 0 0
use_rust/stm32f1 63.5 KiB 63.5 KiB +0.00% ⬆️ +4 0 0
use_rust/stm32h7 121.8 KiB 121.8 KiB +0.00% ⬇️ -4 0 0
use_config/nrf52832_ble — 398.7 KiB → 398.7 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 364568	   8620	  35056	 408244	  63ab4	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 364568	   8620	  35056	 408244	  63ab4	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +79  [ = ]       0    .debug_str
  +0.5%     +40  [ = ]       0    .debug_abbrev
  +0.0%      +3  [ = ]       0    .strtab
  -2.1%      -1  [ = ]       0    [Unmapped]
  -0.0%     -10  [ = ]       0    .debug_loc
  -0.0%     -67  [ = ]       0    .debug_line
  -0.0%    -564  [ = ]       0    .debug_info
  -0.0%    -520  [ = ]       0    TOTAL
use_config/nrf52840_ble — 448.3 KiB → 448.3 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 397300	   8628	  53168	 459096	  70158	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 397304	   8628	  53168	 459100	  7015c	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +970  [ = ]       0    .debug_str
  +0.0%    +475  [ = ]       0    .debug_info
  +0.1%    +281  [ = ]       0    .debug_line
  +0.5%     +40  [ = ]       0    .debug_abbrev
  +0.0%     +25  [ = ]       0    .strtab
  +7.1%      +5  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  +0.0% +1.75Ki  -0.0%      -4    TOTAL
use_config/nrf52840_ble_split (central) — 501.4 KiB → 501.4 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 454768	   8684	  49976	 513428	  7d594	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 454764	   8684	  49976	 513424	  7d590	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +255  [ = ]       0    .debug_info
  +0.0%    +232  [ = ]       0    .debug_str
  +0.5%     +40  [ = ]       0    .debug_abbrev
  +0.0%     +31  [ = ]       0    .debug_line
  +0.0%      +4  +0.0%      +4    .text
  +0.0%      +1  [ = ]       0    .strtab
  +1.8%      +1  [ = ]       0    [Unmapped]
  +0.0%    +564  +0.0%      +4    TOTAL
use_config/nrf52840_ble_split (peripheral) — 320.5 KiB → 320.5 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 292264	   8500	  27464	 328228	  50224	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 292268	   8500	  27464	 328232	  50228	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +7.08Ki  [ = ]       0    .debug_str
  +0.3%    +734  [ = ]       0    .strtab
  +0.0%    +461  [ = ]       0    .debug_info
  +0.1%    +123  [ = ]       0    .debug_line
  +4.1%      +2  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  +0.1% +8.37Ki  -0.0%      -4    TOTAL
use_config/pi_pico_w_ble — 672.4 KiB → 672.4 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 634268	      0	  54304	 688572	  a81bc	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 634276	      0	  54304	 688580	  a81c4	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +400  [ = ]       0    .debug_info
  +0.0%    +214  [ = ]       0    .debug_str
  +0.0%    +122  [ = ]       0    .debug_line
  +0.6%     +60  [ = ]       0    .debug_abbrev
   +29%     +12  [ = ]       0    [Unmapped]
  +0.0%     +10  [ = ]       0    .debug_loc
  +0.0%      +6  [ = ]       0    .strtab
  -0.0%      -8  -0.0%      -8    .text
  +0.0%    +816  -0.0%      -8    TOTAL
use_config/rp2040 — 150.4 KiB → 150.4 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 138376	      0	  15644	 154020	  259a4	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 138380	      0	  15644	 154024	  259a8	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +410  [ = ]       0    .debug_str
  +0.0%    +338  [ = ]       0    .debug_info
  +0.1%    +151  [ = ]       0    .debug_line
  +0.3%     +21  [ = ]       0    .debug_abbrev
  +0.0%     +10  [ = ]       0    .debug_loc
  -0.0%      -4  [ = ]       0    .strtab
  -0.0%      -4  -0.0%      -4    .text
 -47.9%     -34  [ = ]       0    [Unmapped]
  +0.0%    +888  -0.0%      -4    TOTAL
use_config/rp2040_split (central) — 164.3 KiB → 164.3 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 151688	      0	  16508	 168196	  29104	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 151688	      0	  16508	 168196	  29104	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +264  [ = ]       0    .debug_info
  +0.0%    +215  [ = ]       0    .debug_str
  +0.3%     +21  [ = ]       0    .debug_abbrev
  +0.0%     +10  [ = ]       0    .debug_loc
   +11%      +4  [ = ]       0    [Unmapped]
  -0.0%      -3  [ = ]       0    .strtab
  -0.1%     -99  [ = ]       0    .debug_line
  +0.0%    +412  [ = ]       0    TOTAL
use_config/rp2040_split (peripheral) — 27.8 KiB → 27.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25616	     60	   2796	  28472	   6f38	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25616	     60	   2796	  28472	   6f38	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +321  [ = ]       0    .debug_str
  +0.1%    +302  [ = ]       0    .debug_info
  +0.7%     +40  [ = ]       0    .debug_abbrev
  +0.0%     +24  [ = ]       0    .debug_line
  +0.0%      +3  [ = ]       0    .strtab
  +5.4%      +2  [ = ]       0    [Unmapped]
  +0.0%    +692  [ = ]       0    TOTAL
use_config/stm32f1 — 63.6 KiB → 63.8 KiB (+0.35% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57804	     28	   7500	  65332	   ff34	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  57584	     28	   7488	  65100	   fe4c	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.3% +1.73Ki  [ = ]       0    .debug_info
  +0.1% +1.29Ki  [ = ]       0    .debug_str
  +0.3%    +421  [ = ]       0    .debug_loc
  +0.9%    +398  [ = ]       0    .strtab
  +0.4%    +379  [ = ]       0    .debug_line
  +1.4%    +288  [ = ]       0    .symtab
  +0.4%    +220  +0.4%    +220    .text
  +1.1%    +144  [ = ]       0    .debug_frame
  +1.1%     +63  [ = ]       0    .debug_abbrev
  +0.8%     +48  [ = ]       0    .debug_aranges
  [ = ]       0  [NEW]      +8    .uninit
  [ = ]       0  +0.1%      +4    .bss
  -0.1%     -24  [ = ]       0    .debug_ranges
 -37.3%     -25  [ = ]       0    [Unmapped]
  +0.3% +4.89Ki  +0.4%    +232    TOTAL
use_config/stm32h7 — 101.9 KiB → 102.1 KiB (+0.22% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  94528	    264	   9748	 104540	  1985c	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  94304	    264	   9736	 104304	  19770	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +1.76Ki  [ = ]       0    .debug_info
  +0.0%    +435  [ = ]       0    .debug_str
  +0.2%    +431  [ = ]       0    .debug_loc
  +0.3%    +362  [ = ]       0    .debug_line
  +1.0%    +288  [ = ]       0    .symtab
  +0.3%    +232  [ = ]       0    .strtab
  +0.3%    +224  +0.3%    +224    .text
  +0.9%    +144  [ = ]       0    .debug_frame
  +0.1%     +48  [ = ]       0    .debug_aranges
  +0.4%     +25  [ = ]       0    .debug_abbrev
  [ = ]       0  [NEW]      +8    .uninit
  [ = ]       0  +0.0%      +4    .bss
  -9.5%      -4  [ = ]       0    [Unmapped]
  -0.1%     -40  [ = ]       0    .debug_ranges
  +0.1% +3.86Ki  +0.2%    +236    TOTAL
use_rust/nrf52832_ble — 387.0 KiB → 387.0 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 352588	   8620	  35112	 396320	  60c20	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 352592	   8620	  35112	 396324	  60c24	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +230  [ = ]       0    .debug_info
  +0.0%    +223  [ = ]       0    .debug_str
  +0.0%     +32  [ = ]       0    .debug_line
  +0.3%     +21  [ = ]       0    .debug_abbrev
  +0.0%     +10  [ = ]       0    .debug_loc
  +3.9%      +2  [ = ]       0    [Unmapped]
  -0.0%      -2  [ = ]       0    .strtab
  -0.0%      -4  -0.0%      -4    .text
  +0.0%    +512  -0.0%      -4    TOTAL
use_rust/nrf52840_ble — 441.9 KiB → 441.9 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 396696	   8628	  47224	 452548	  6e7c4	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 396692	   8628	  47224	 452544	  6e7c0	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +191  [ = ]       0    .debug_info
  +0.0%    +109  [ = ]       0    .debug_str
  +0.5%     +40  [ = ]       0    .debug_abbrev
  +0.0%      +4  +0.0%      +4    .text
  -2.9%      -2  [ = ]       0    [Unmapped]
  -0.0%     -10  [ = ]       0    .debug_loc
  -0.0%     -31  [ = ]       0    .strtab
  -0.1%    -301  [ = ]       0    .debug_line
  [ = ]       0  +0.0%      +4    TOTAL
use_rust/nrf52840_ble_split (central) — 508.0 KiB → 508.0 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 457568	   8684	  53976	 520228	  7f024	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 457568	   8684	  53976	 520228	  7f024	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +255  [ = ]       0    .debug_info
  +0.0%    +232  [ = ]       0    .debug_str
  +0.5%     +40  [ = ]       0    .debug_abbrev
  +0.0%     +31  [ = ]       0    .debug_line
  +0.0%      +1  [ = ]       0    .strtab
  -1.4%      -1  [ = ]       0    [Unmapped]
  -0.0%     -10  [ = ]       0    .debug_loc
  +0.0%    +548  [ = ]       0    TOTAL
use_rust/nrf52840_ble_split (peripheral) — 318.4 KiB → 318.4 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 290264	   8500	  27232	 325996	  4f96c	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 290264	   8500	  27232	 325996	  4f96c	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +259  [ = ]       0    .debug_str
  +0.0%    +227  [ = ]       0    .debug_info
  +0.0%     +24  [ = ]       0    .debug_line
  +0.0%     +18  [ = ]       0    .strtab
  -2.8%      -2  [ = ]       0    [Unmapped]
  -0.0%     -10  [ = ]       0    .debug_loc
  +0.0%    +516  [ = ]       0    TOTAL
use_rust/pi_pico_w_ble — 672.8 KiB → 672.7 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 634392	      0	  54496	 688888	  a82f8	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 634400	      0	  54496	 688896	  a8300	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +395  [ = ]       0    .debug_info
  +0.0%    +258  [ = ]       0    .debug_str
  +0.0%    +130  [ = ]       0    .debug_line
  +0.6%     +60  [ = ]       0    .debug_abbrev
  +0.0%     +28  [ = ]       0    .strtab
  +0.0%     +10  [ = ]       0    .debug_loc
   +14%      +7  [ = ]       0    [Unmapped]
  -0.0%      -8  -0.0%      -8    .text
  +0.0%    +880  -0.0%      -8    TOTAL
use_rust/rp2040 — 150.2 KiB → 150.2 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 138196	      0	  15564	 153760	  258a0	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 138200	      0	  15564	 153764	  258a4	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +410  [ = ]       0    .debug_str
  +0.0%    +338  [ = ]       0    .debug_info
  +0.1%    +150  [ = ]       0    .debug_line
  +0.3%     +21  [ = ]       0    .debug_abbrev
  +5.4%      +3  [ = ]       0    [Unmapped]
  -0.0%      -4  [ = ]       0    .strtab
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -10  [ = ]       0    .debug_loc
  +0.0%    +904  -0.0%      -4    TOTAL
use_rust/rp2040_split (central) — 162.7 KiB → 162.7 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 150300	      0	  16340	 166640	  28af0	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 150304	      0	  16340	 166644	  28af4	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +356  [ = ]       0    .debug_str
  +0.0%    +289  [ = ]       0    .debug_info
  +0.3%     +21  [ = ]       0    .debug_abbrev
  +0.0%      +6  [ = ]       0    .strtab
  +0.0%      +1  [ = ]       0    .debug_line
  -2.0%      -1  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  +0.0%    +668  -0.0%      -4    TOTAL
use_rust/rp2040_split (peripheral) — 28.2 KiB → 28.2 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25716	     60	   3060	  28836	   70a4	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25716	     60	   3060	  28836	   70a4	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +316  [ = ]       0    .debug_str
  +0.1%    +244  [ = ]       0    .debug_info
  +0.0%     +20  [ = ]       0    .debug_line
  +0.0%      +3  [ = ]       0    .strtab
  -4.8%      -3  [ = ]       0    [Unmapped]
  +0.0%    +580  [ = ]       0    TOTAL
use_rust/stm32f1 — 63.5 KiB → 63.5 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57536	     28	   7504	  65068	   fe2c	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  57532	     28	   7504	  65064	   fe28	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +277  [ = ]       0    .debug_info
  +0.0%    +241  [ = ]       0    .debug_str
  +0.4%     +21  [ = ]       0    .debug_abbrev
  +0.0%     +20  [ = ]       0    .debug_line
  +0.0%      +4  +0.0%      +4    .text
  -3.6%      -2  [ = ]       0    [Unmapped]
  -0.0%      -9  [ = ]       0    .strtab
  +0.0%    +552  +0.0%      +4    TOTAL
use_rust/stm32h7 — 121.8 KiB → 121.8 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 108516	    320	  15852	 124688	  1e710	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 108520	    320	  15852	 124692	  1e714	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +314  [ = ]       0    .debug_info
  +0.1%    +150  [ = ]       0    .debug_line
  +0.3%     +21  [ = ]       0    .debug_abbrev
   +21%      +8  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  -0.2%    -178  [ = ]       0    .strtab
  -0.1% -1.71Ki  [ = ]       0    .debug_str
  -0.0% -1.40Ki  -0.0%      -4    TOTAL

@mariolopjr
mariolopjr marked this pull request as ready for review July 24, 2026 17:49
@HaoboGu

HaoboGu commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Can you separate this PR into 2:

  1. The clock setting
  2. The stm32 bootloader

to make it easier to review, thanks!

@mariolopjr
mariolopjr force-pushed the mariolopjr/add-smt32-bootloader-reboot-support branch from b99a92f to 6b988af Compare July 31, 2026 00:32
@mariolopjr

Copy link
Copy Markdown
Author

Sorry about that @HaoboGu! I removed the other commit and will chain a PR with it, thanks again!

@HaoboGu

HaoboGu commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

I just reviewed the code, I found it refers some QMK code. Due to the license conflict(QMK is GPL license), I cannot merge it. I'm really sorry for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants