Skip to content

Commit e18c34b

Browse files
aq1018claude
andcommitted
unlock BOOT_LOCK for h4 SYS region
H4 has no BTPG/BTER equivalents from V3 — BOOT_LOCK in STATR gates SYS access instead. unlock_boot() writes KEY1/KEY2 to BOOT_MODEKEYR to clear it; standard PER/FTPG then operates on 0x1FFF0000 directly. probe-rs still won't attach the sys algo until ch32-data flips SYS_1 write:false → true. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0c9a288 commit e18c34b

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

algos/h4/src/bin/sys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ algorithm!(Algo, {
2323

2424
impl FlashAlgorithm for Algo {
2525
fn new(_addr: u32, _clock: u32, _function: Function) -> Result<Self, ErrorCode> {
26-
unlock_main();
26+
unlock_boot();
2727
Ok(Self)
2828
}
2929

@@ -44,6 +44,6 @@ impl FlashAlgorithm for Algo {
4444

4545
impl Drop for Algo {
4646
fn drop(&mut self) {
47-
lock_main();
47+
lock_boot();
4848
}
4949
}

algos/h4/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ pub fn unlock_options() {
5353
FLASH.obkeyr().write(|w| w.set_obtkey(KEY2));
5454
}
5555

56+
/// BOOT_LOCK gates SYS access; standard PER/FTPG flow then targets 0x1FFF0000
57+
/// directly (H4 has no BTPG/BTER equivalents).
58+
pub fn unlock_boot() {
59+
unlock_main();
60+
FLASH.boot_modekeyr().write(|w| w.set_bootkeyr(KEY1));
61+
FLASH.boot_modekeyr().write(|w| w.set_bootkeyr(KEY2));
62+
}
63+
64+
pub fn lock_boot() {
65+
FLASH.statr().modify(|w| w.set_boot_lock(true));
66+
lock_main();
67+
}
68+
5669
pub fn page_erase(addr: u32) {
5770
wait_busy();
5871
FLASH.ctlr().modify(|w| w.set_per(true));

0 commit comments

Comments
 (0)