Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
113 changes: 113 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,119 @@ The scancodes are the same.

It's not controlled by the EC, use https://keyboard.frame.work.

## Keyboard controller (Laptop 12 2nd Gen input deck)

The 2nd Gen input deck of the Laptop 12 has an STM32 microcontroller for
keyboard and touchpad, connected to the EC. All of these need root.

### Check firmware version and state

```
> sudo framework_tool --stm32-kbd-info
STM32 Keyboard Controller
Firmware: 1.2.0
Commit: 5d02bc4a139c3be3
Chip ID: 0x0489 (STM32U073/U083)
Flash / RAM: 64 KB / 40 KB
Unique ID: 52002E000350335250323520
Do-not-update: no
Fn Lock: off
Fn/Ctrl swap: off
Caps Lock: off
```

Older firmware shows less, for example no chip ID and no Fn Lock state.
If the controller has no firmware at all, it says so:

```
> sudo framework_tool --stm32-kbd-info
STM32 Keyboard Controller
No firmware, the controller is in its ROM bootloader
Flash it with --flash-stm32-kbd
```

### Fn Lock

Only works if `--stm32-kbd-info` shows the Fn Lock state (e.g. on 1.2.0, not
on 1.0.0). Otherwise reflashing turns it off.

```
> sudo framework_tool --stm32-kbd-fn-lock on
Fn Lock turned on
> sudo framework_tool --stm32-kbd-fn-lock off
Fn Lock turned off
```

### Update firmware

Takes an Intel HEX file. Keyboard and touchpad don't work while flashing,
it reads everything back to verify and checks the version afterwards.
Flashing also resets the settings stored on the keyboard, like Fn Lock.

```
# Check the file without flashing
> framework_tool --flash-stm32-kbd dahlia_tp_module_v12_20260914.hex --dry-run
Image: 44212 bytes at 0x08000000-0x0800ACB3
Image version: 1.2.0
Dry run, not flashing

> sudo framework_tool --flash-stm32-kbd dahlia_tp_module_v12_20260914.hex
Image: 44212 bytes at 0x08000000-0x0800ACB3
Image version: 1.2.0
Keyboard and touchpad don't work until flashing is done
Entering bootloader...
Erasing...
Writing: 100%
Verifying: 100%
Exiting bootloader...
Controller: 0x0489 (STM32U073/U083), bootloader v1.2
Flash complete, now running 1.2.0
```

If flashing gets interrupted, just run it again. The bootloader is in ROM,
so it works even when the controller has no firmware.

Update protection asks automatic updaters to leave the keyboard alone, for
example when it runs custom firmware. It's only a hint, `--flash-stm32-kbd`
ignores it. Flashing again without the option removes it.

```
# Flash and set update protection. Skip reading the firmware back to verify.
> sudo framework_tool --flash-stm32-kbd dahlia_tp_module_v12_20260914.hex --stm32-kbd-update-protect --stm32-kbd-no-verify
Image: 44212 bytes at 0x08000000-0x0800ACB3
Image version: 1.2.0
Keyboard and touchpad don't work until flashing is done
Entering bootloader...
Erasing...
Writing: 100%
Exiting bootloader...
Controller: 0x0489 (STM32U073/U083), bootloader v1.2
Flash complete, now running 1.2.0
Update protection set, automatic updaters should skip this keyboard

> sudo framework_tool --stm32-kbd-info
[...]
Do-not-update: yes
[...]
```

### Other commands

The keyboard and touchpad drop out for about a second during these.

```
# Read the chip ID from the bootloader (for firmware that doesn't report it)
> sudo framework_tool --stm32-kbd-identify
Entering the bootloader - keyboard and touchpad drop out for about a second
Controller: 0x0489 (STM32U073/U083), bootloader v1.2

# Restart the controller
> sudo framework_tool --stm32-kbd-reset

# Erase the firmware. Keyboard and touchpad stop working until flashed again!
> sudo framework_tool --stm32-kbd-erase --force
```

## Advanced commands

Mostly for debugging firmware.
Expand Down
44 changes: 43 additions & 1 deletion framework_lib/src/commandline/clap_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::chromium_ec::commands::SetGpuSerialMagic;
use crate::chromium_ec::CrosEcDriverType;
use crate::commandline::{
Cli, ClickForceArg, ConsoleArg, FpBrightnessArg, HardwareDeviceType, InputDeckModeArg,
LogLevel, RebootEcArg, TabletModeArg,
LogLevel, OnOffArg, RebootEcArg, TabletModeArg,
};

/// Swiss army knife for Framework laptops
Expand Down Expand Up @@ -185,6 +185,38 @@ struct ClapCli {
#[arg(long)]
flash_rw_ec: Option<std::path::PathBuf>,

/// Show firmware version and state of the STM32 keyboard controller (Laptop 12 2nd gen input deck)
#[arg(long)]
stm32_kbd_info: bool,

/// Flash the STM32 keyboard controller with firmware from an Intel HEX file
#[arg(long, value_name = "HEX_FILE")]
flash_stm32_kbd: Option<std::path::PathBuf>,

/// Read the STM32 keyboard controller's chip ID from its bootloader (keyboard drops out briefly)
#[arg(long)]
stm32_kbd_identify: bool,

/// Restart the STM32 keyboard controller (keyboard drops out briefly)
#[arg(long)]
stm32_kbd_reset: bool,

/// Erase the STM32 keyboard controller, leaving keyboard and touchpad dead until flashed (needs --force)
#[arg(long)]
stm32_kbd_erase: bool,

/// Turn Fn Lock on or off on the STM32 keyboard controller
#[arg(long)]
stm32_kbd_fn_lock: Option<OnOffArg>,

/// Don't read the firmware back after flashing (use with --flash-stm32-kbd)
#[arg(long, requires("flash_stm32_kbd"))]
stm32_kbd_no_verify: bool,

/// Ask automatic updaters to leave the keyboard alone (use with --flash-stm32-kbd)
#[arg(long, requires("flash_stm32_kbd"))]
stm32_kbd_update_protect: bool,

/// Show status of intrusion switch
#[arg(long)]
intrusion: bool,
Expand Down Expand Up @@ -689,6 +721,16 @@ pub fn parse(args: &[String]) -> Cli {
flash_rw_ec: args
.flash_rw_ec
.map(|x| x.into_os_string().into_string().unwrap()),
stm32_kbd_info: args.stm32_kbd_info,
flash_stm32_kbd: args
.flash_stm32_kbd
.map(|x| x.into_os_string().into_string().unwrap()),
stm32_kbd_identify: args.stm32_kbd_identify,
stm32_kbd_reset: args.stm32_kbd_reset,
stm32_kbd_erase: args.stm32_kbd_erase,
stm32_kbd_fn_lock: args.stm32_kbd_fn_lock,
stm32_kbd_no_verify: args.stm32_kbd_no_verify,
stm32_kbd_update_protect: args.stm32_kbd_update_protect,
intrusion: args.intrusion,
inputdeck: args.inputdeck,
inputdeck_mode: args.inputdeck_mode,
Expand Down
Loading
Loading