RMK has included many optimizations by default to reduce binary size. But there are still some tricks to reduce the binary size further. If you get a linker error like:
or some errors occur when writing configs to flash, that means your microcontroller's internal flash is not big enough.
For the minimal example, please check out the examples/use_rust/stm32f1 and examples/use_config/stm32f1 examples.
There are several approaches to solve the problem:
DEFMT_LOG levelLogging is quite useful when debugging the firmware, but it requires a lot of flash. You can change the default logging level to error at .cargo/config.toml, to print only error messages and save flash:
According to embassy's doc, you can set the following in your .cargo/config.toml
And then compile your project with nightly Rust:
keyboard.toml usersRMK provides several options that you can use to reduce the binary size:
If you don't need storage, you can disable the storage feature to save some flash. To disable storage feature you need to disable default features of rmk crate, and then enable other features you need.
You can also fully remove defmt by removing defmt feature from rmk crate and similar feature gates from all other dependencies.
If you don't need vial support, you can also disable the vial feature by disabling default features of rmk crate.
If you're using keyboard.toml, you'll also need to disable storage, defmt, and vial in the toml config:
panic-haltBy default, RMK uses panic-probe to print error messages if panic occurs. But panic-probe actually takes lots of flash because the panic call can not be optimized. The solution is to use panic-halt instead of panic-probe:
Then in main.rs, use panic-halt instead:
defmt-rttYou can also remove the entire defmt-rtt logger to save flash.
In this case, you have to implement an empty defmt logger.
You can disable storage and vial feature in Cargo.toml:
And then remove anything no longer needed in main.rs.