Skip to content

Add an option in chip_config.frequenecy to configure CPU clock of ESP32.#871

Open
farooqkz wants to merge 5 commits into
HaoboGu:mainfrom
farooqkz:main
Open

Add an option in chip_config.frequenecy to configure CPU clock of ESP32.#871
farooqkz wants to merge 5 commits into
HaoboGu:mainfrom
farooqkz:main

Conversation

@farooqkz

@farooqkz farooqkz commented Jun 1, 2026

Copy link
Copy Markdown

Currently it can be only 160 and 80 (values in MHz) as in par with esp-hal. As a note, when configuration of XTAL clock in
esp-hal has been stabilized, we could also have that to further lower CPU clock to save battery.

The patch is ready for review. However, I think it could be a good idea if rmk prints a warning to the console if the chip is not ESP32 yet frequency is present.

Cheers!

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

Size Report

Example main PR Diff .text .data .bss
use_config/nrf52832_ble 372.1 KiB 372.1 KiB +0.00% ⬆️ +4 0 0
use_config/nrf52840_ble 421.7 KiB 421.7 KiB +0.00% ⬆️ +8 0 0
use_config/nrf52840_ble_split (central) 497.2 KiB 497.2 KiB +0.00% ⬇️ -8 0 0
use_config/nrf52840_ble_split (peripheral) 322.3 KiB 322.2 KiB +0.00% ⬇️ -8 0 0
use_config/pi_pico_w_ble 659.3 KiB 659.3 KiB +0.00% ⬇️ -4 0 0
use_config/rp2040 147.2 KiB 147.2 KiB +0.00% ⬆️ +4 0 0
use_config/rp2040_split (central) 160.5 KiB 160.4 KiB +0.00% ⬇️ -8 0 0
use_config/rp2040_split (peripheral) 27.4 KiB 27.4 KiB +0.00% 0 0 0
use_config/stm32f1 62.6 KiB 62.6 KiB +0.00% 0 0 0
use_config/stm32h7 99.8 KiB 99.8 KiB +0.00% 0 0 0
use_rust/nrf52832_ble 359.6 KiB 359.6 KiB +0.00% ⬆️ +12 0 0
use_rust/nrf52840_ble 417.8 KiB 417.8 KiB +0.00% ⬆️ +8 0 0
use_rust/nrf52840_ble_split (central) 506.6 KiB 506.6 KiB +0.00% ⬇️ -4 0 0
use_rust/nrf52840_ble_split (peripheral) 319.0 KiB 319.0 KiB +0.00% ⬇️ -4 0 0
use_rust/pi_pico_w_ble 659.9 KiB 659.9 KiB +0.00% 0 0 0
use_rust/rp2040 147.2 KiB 147.2 KiB +0.00% 0 0 0
use_rust/rp2040_split (central) 159.6 KiB 159.6 KiB +0.00% ⬇️ -4 0 0
use_rust/rp2040_split (peripheral) 27.8 KiB 27.8 KiB +0.00% 0 0 0
use_rust/stm32f1 62.6 KiB 62.6 KiB -0.01% ⬇️ -8 0 0
use_rust/stm32h7 121.2 KiB 121.2 KiB +0.00% ⬆️ +8 0 0
use_config/nrf52832_ble — 372.1 KiB → 372.1 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 341428	   5256	  34376	 381060	  5d084	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 341424	   5256	  34376	 381056	  5d080	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +32  [ = ]       0    .debug_ranges
  +0.0%     +32  [ = ]       0    .symtab
  +0.0%     +25  [ = ]       0    .strtab
  +0.0%     +20  [ = ]       0    .debug_frame
  +0.0%      +8  [ = ]       0    .debug_aranges
  +0.0%      +4  +0.0%      +4    .text
  -5.3%      -3  [ = ]       0    [Unmapped]
  -0.5%     -40  [ = ]       0    .debug_abbrev
  -0.1%    -216  [ = ]       0    .debug_line
  -0.0%    -677  [ = ]       0    .debug_str
  -0.2% -1.02Ki  [ = ]       0    .debug_loc
  -0.1% -1.74Ki  [ = ]       0    .debug_info
  -0.1% -3.56Ki  +0.0%      +4    TOTAL
use_config/nrf52840_ble — 421.7 KiB → 421.7 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 375412	   5264	  51176	 431852	  696ec	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 375404	   5264	  51176	 431844	  696e4	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0% +1.13Ki  [ = ]       0    .debug_str
  +0.0%     +64  [ = ]       0    .symtab
  +0.0%     +50  [ = ]       0    .strtab
  +0.1%     +36  [ = ]       0    .debug_frame
  +0.0%     +32  [ = ]       0    .debug_ranges
  +0.0%     +16  [ = ]       0    .debug_aranges
  +0.0%      +8  +0.0%      +8    .text
 -14.5%      -8  [ = ]       0    [Unmapped]
  -0.9%     -76  [ = ]       0    .debug_abbrev
  -0.1%    -210  [ = ]       0    .debug_line
  -0.1% -1.02Ki  [ = ]       0    .debug_loc
  -0.1% -2.86Ki  [ = ]       0    .debug_info
  -0.0% -2.84Ki  +0.0%      +8    TOTAL
use_config/nrf52840_ble_split (central) — 497.2 KiB → 497.2 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 455564	   6588	  46992	 509144	  7c4d8	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 455572	   6588	  46992	 509152	  7c4e0	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +13%      +8  [ = ]       0    [Unmapped]
  -0.0%      -8  -0.0%      -8    .text
  -0.2%     -17  [ = ]       0    .debug_abbrev
  -0.0%    -109  [ = ]       0    .debug_line
  -0.0%    -190  [ = ]       0    .debug_info
  -0.0%    -860  [ = ]       0    .debug_str
  -0.0% -1.15Ki  -0.0%      -8    TOTAL
use_config/nrf52840_ble_split (peripheral) — 322.3 KiB → 322.2 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 296548	   5920	  27512	 329980	  508fc	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 296556	   5920	  27512	 329988	  50904	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +49  [ = ]       0    .debug_info
   +20%      +7  [ = ]       0    [Unmapped]
  -0.0%      -8  -0.0%      -8    .text
  -0.0%     -99  [ = ]       0    .debug_line
  -0.0%    -777  [ = ]       0    .debug_str
  -0.0%    -828  -0.0%      -8    TOTAL
use_config/pi_pico_w_ble — 659.3 KiB → 659.3 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 619524	      0	  55572	 675096	  a4d18	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 619528	      0	  55572	 675100	  a4d1c	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +39  [ = ]       0    .debug_info
  +0.2%     +20  [ = ]       0    .debug_abbrev
  +9.5%      +4  [ = ]       0    [Unmapped]
  -0.0%      -1  [ = ]       0    .debug_line
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -42  [ = ]       0    .debug_loc
  -0.0%    -344  [ = ]       0    .debug_str
  -0.0%    -328  -0.0%      -4    TOTAL
use_config/rp2040 — 147.2 KiB → 147.2 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 135336	      0	  15372	 150708	  24cb4	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 135332	      0	  15372	 150704	  24cb0	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +738  [ = ]       0    .debug_str
  +0.0%    +316  [ = ]       0    .debug_info
  +0.0%     +42  [ = ]       0    .debug_loc
  +0.0%     +10  [ = ]       0    .debug_line
  +0.0%      +4  +0.0%      +4    .text
  -4.8%      -2  [ = ]       0    [Unmapped]
  +0.0% +1.08Ki  +0.0%      +4    TOTAL
use_config/rp2040_split (central) — 160.5 KiB → 160.4 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 148116	      0	  16184	 164300	  281cc	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 148124	      0	  16184	 164308	  281d4	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +61  [ = ]       0    .debug_info
   +14%      +8  [ = ]       0    [Unmapped]
  -0.0%      -8  -0.0%      -8    .text
  -0.0%     -10  [ = ]       0    .debug_loc
  -0.0%     -64  [ = ]       0    .debug_line
  -0.0%    -643  [ = ]       0    .debug_str
  -0.0%    -656  -0.0%      -8    TOTAL
use_config/rp2040_split (peripheral) — 27.4 KiB → 27.4 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25252	     60	   2764	  28076	   6dac	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25252	     60	   2764	  28076	   6dac	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +4.3%      +2  [ = ]       0    [Unmapped]
  -0.0%      -1  [ = ]       0    .debug_str
  -0.0%      -1  [ = ]       0    .strtab
  [ = ]       0  [ = ]       0    TOTAL
use_config/stm32f1 — 62.6 KiB → 62.6 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  56596	     28	   7504	  64128	   fa80	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  56596	     28	   7504	  64128	   fa80	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +17  [ = ]       0    .debug_line
  +0.0%     +13  [ = ]       0    .debug_info
  -1.6%      -1  [ = ]       0    [Unmapped]
  -0.0%    -297  [ = ]       0    .debug_str
  -0.0%    -268  [ = ]       0    TOTAL
use_config/stm32h7 — 99.8 KiB → 99.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  92140	    268	   9736	 102144	  18f00	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  92140	    268	   9736	 102144	  18f00	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +3.6%      +2  [ = ]       0    [Unmapped]
  -0.0%    -123  [ = ]       0    .debug_info
  -0.1%    -150  [ = ]       0    .debug_line
  -0.0%    -637  [ = ]       0    .debug_str
  -0.0%    -908  [ = ]       0    TOTAL
use_rust/nrf52832_ble — 359.6 KiB → 359.6 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 329560	   5264	  33368	 368192	  59e40	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 329548	   5264	  33368	 368180	  59e34	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +32  [ = ]       0    .symtab
  +0.0%     +25  [ = ]       0    .strtab
  +0.0%     +20  [ = ]       0    .debug_frame
  +0.0%     +16  [ = ]       0    .debug_ranges
  +0.0%     +12  +0.0%     +12    .text
  +0.0%      +8  [ = ]       0    .debug_aranges
 -23.5%     -12  [ = ]       0    [Unmapped]
  -0.7%     -57  [ = ]       0    .debug_abbrev
  -0.0%    -126  [ = ]       0    .debug_str
  -0.1%    -341  [ = ]       0    .debug_line
  -0.2% -1.06Ki  [ = ]       0    .debug_loc
  -0.1% -2.44Ki  [ = ]       0    .debug_info
  -0.1% -3.91Ki  +0.0%     +12    TOTAL
use_rust/nrf52840_ble — 417.8 KiB → 417.8 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 375896	   5264	  46656	 427816	  68728	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 375888	   5264	  46656	 427808	  68720	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +715  [ = ]       0    .debug_info
  +0.0%    +421  [ = ]       0    .debug_str
  +0.5%     +38  [ = ]       0    .debug_abbrev
  +0.0%      +8  +0.0%      +8    .text
  -0.0%      -1  [ = ]       0    .strtab
 -10.6%      -5  [ = ]       0    [Unmapped]
  -0.0%     -72  [ = ]       0    .debug_line
  +0.0% +1.08Ki  +0.0%      +8    TOTAL
use_rust/nrf52840_ble_split (central) — 506.6 KiB → 506.6 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 459444	   6588	  52728	 518760	  7ea68	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 459448	   6588	  52728	 518764	  7ea6c	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +57  [ = ]       0    .debug_line
  +0.1%      +6  [ = ]       0    .debug_abbrev
  +8.5%      +5  [ = ]       0    [Unmapped]
  +0.0%      +1  [ = ]       0    .strtab
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -22  [ = ]       0    .debug_loc
  -0.0%    -718  [ = ]       0    .debug_info
  -0.0% -1.33Ki  [ = ]       0    .debug_str
  -0.0% -1.99Ki  -0.0%      -4    TOTAL
use_rust/nrf52840_ble_split (peripheral) — 319.0 KiB → 319.0 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 294992	   5360	  26272	 326624	  4fbe0	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 294996	   5360	  26272	 326628	  4fbe4	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.52Ki  [ = ]       0    .debug_str
  +0.0%    +425  [ = ]       0    .debug_info
  +0.0%     +42  [ = ]       0    .debug_loc
  +6.5%      +3  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -98  [ = ]       0    .debug_line
  +0.0% +1.88Ki  -0.0%      -4    TOTAL
use_rust/pi_pico_w_ble — 659.9 KiB → 659.9 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 619972	      0	  55716	 675688	  a4f68	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 619972	      0	  55716	 675688	  a4f68	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +574  [ = ]       0    .debug_str
  -4.2%      -2  [ = ]       0    [Unmapped]
  -0.0%     -15  [ = ]       0    .debug_line
  -0.0%     -42  [ = ]       0    .debug_loc
  -0.0%    -475  [ = ]       0    .debug_info
  +0.0%     +40  [ = ]       0    TOTAL
use_rust/rp2040 — 147.2 KiB → 147.2 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 135520	      0	  15252	 150772	  24cf4	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 135520	      0	  15252	 150772	  24cf4	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +330  [ = ]       0    .debug_info
  +0.0%    +223  [ = ]       0    .debug_str
  +0.0%     +38  [ = ]       0    .debug_line
  +0.0%     +22  [ = ]       0    .debug_loc
  -2.0%      -1  [ = ]       0    [Unmapped]
  +0.0%    +612  [ = ]       0    TOTAL
use_rust/rp2040_split (central) — 159.6 KiB → 159.6 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 147484	      0	  15964	 163448	  27e78	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 147488	      0	  15964	 163452	  27e7c	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +10  [ = ]       0    .debug_loc
  +6.4%      +3  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -36  [ = ]       0    .debug_line
  -0.0%     -47  [ = ]       0    .debug_str
  -0.0%    -274  [ = ]       0    .debug_info
  -0.0%    -348  -0.0%      -4    TOTAL
use_rust/rp2040_split (peripheral) — 27.8 KiB → 27.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25372	     60	   3028	  28460	   6f2c	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25372	     60	   3028	  28460	   6f2c	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  -0.0%      -1  [ = ]       0    .strtab
  -1.8%      -1  [ = ]       0    [Unmapped]
  -0.0%      -2  [ = ]       0    .debug_str
  -0.0%      -4  [ = ]       0    TOTAL
use_rust/stm32f1 — 62.6 KiB → 62.6 KiB (-0.01% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  56636	     28	   7480	  64144	   fa90	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  56644	     28	   7480	  64152	   fa98	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +58  [ = ]       0    .debug_str
  +0.0%     +14  [ = ]       0    .debug_line
  +5.9%      +3  [ = ]       0    [Unmapped]
  -0.0%      -8  -0.0%      -8    .text
  -0.0%     -31  [ = ]       0    .debug_info
  +0.0%     +36  -0.0%      -8    TOTAL
use_rust/stm32h7 — 121.2 KiB → 121.2 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 108260	    324	  15524	 124108	  1e4cc	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 108252	    324	  15524	 124100	  1e4c4	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2%    +286  [ = ]       0    .debug_line
  +0.0%     +81  [ = ]       0    .debug_str
  +0.0%      +8  +0.0%      +8    .text
  -0.0%      -6  [ = ]       0    .debug_info
  -0.0%     -10  [ = ]       0    .debug_loc
 -22.9%     -11  [ = ]       0    [Unmapped]
  +0.0%    +348  +0.0%      +8    TOTAL

@HaoboGu

HaoboGu commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR! Did you try to override the initialization code in the proc-macro using #[Override(chip_config)], like https://github.com/HaoboGu/rmk/blob/main/examples/use_config/stm32h7/src/main.rs

I think setting values like frequency to esp32 only is more like a "patch", it's not a common solution for all chips

@farooqkz

farooqkz commented Jun 3, 2026

Copy link
Copy Markdown
Author

Thanks for the PR! Did you try to override the initialization code in the proc-macro using #[Override(chip_config)], like https://github.com/HaoboGu/rmk/blob/main/examples/use_config/stm32h7/src/main.rs

I think setting values like frequency to esp32 only is more like a "patch", it's not a common solution for all chips

Many chips work with different frequencies. So I guess the frequency should be configurable for those which support it. However for ESP32, only 80 and 160 will be valid. I think it makes sense to change the value type to f32 and get this PR merged. Then open issues for others like STM32 for subsequent PRs if anyone is interested.

farooqkz added 4 commits June 3, 2026 18:16
Currently it can be only 160 and 80 (values in MHz) as in par with
esp-hal. As a note, when configuration of XTAL clock in esp-hal has been
stabilized, we could also have that to further lower CPU clock to save
battery.
@farooqkz

farooqkz commented Jun 3, 2026

Copy link
Copy Markdown
Author

History cleaned. frequency is now f64

@farooqkz

farooqkz commented Jun 3, 2026

Copy link
Copy Markdown
Author

Checking HAL of stm32f1, I'm unsure if f64 fits.

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