Skip to content

Commit 1bab001

Browse files
neu-rahclaude
andcommitted
rust_stm32_bridge: correct + trim the clock comments
main.rs said "72MHz PLL" where it's really the 64MHz HSI/2 x16 clamp; replace the 25-line reverted-HSE incident log with the 5 still-true lines. README "what this doesn't prove": device #2 is a real peripheral stack now, not a trivial component -- reword accordingly. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 53b9c00 commit 1bab001

2 files changed

Lines changed: 16 additions & 34 deletions

File tree

‎examples/rust_stm32_bridge/README.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,10 @@ elsewhere.
171171

172172
## What this doesn't prove, and why that's honest
173173

174-
This tests the mechanism on a trivial component, not `focCompose`'s real
175-
SPI sensor/PWM driver composition — swapping in a real slice of that
176-
work is a natural next step, but deliberately sequenced after the
177-
mechanism itself was proven on something small (the same "trivial but
178-
real" discipline `cuda_device_chain` used before this). And per the FFI
174+
Device #1 is a trivial counter; device #2 is a real I2C peripheral stack
175+
but still only called at startup. Neither exercises `focCompose`'s real
176+
SPI-sensor / PWM-driver composition or a control loop — a natural next
177+
step, deliberately sequenced after the mechanism itself. And per the FFI
179178
finding above: don't expect this pattern to preserve zero-overhead across
180179
a *hot, high-frequency* Rust↔C++ boundary (e.g. calling into a composed
181180
FOC control loop every PWM cycle) without measuring the real call

‎examples/rust_stm32_bridge/src/main.rs‎

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020
//! preserved as separate source here).
2121
//!
2222
//! Device #2: `cpp/lcd_shim.cpp` bridges the same way to a real 16x2
23-
//! character LCD over I2C1 (PB6/PB7) via a PCF8574 backpack -- zero new
24-
//! OneIO/OneBus driver code needed (both were already platform-agnostic),
25-
//! one real gap found+fixed in OneChip (a missing single-byte
26-
//! `TwiMaster::send(addr,byte)` overload `oneBus::I2cGpio` needs). Also
27-
//! switches the clock to real 72MHz PLL, not just raw 8MHz HSI --
28-
//! `hd44780.h`'s portable delay loop is calibrated assuming ~72MHz, and
29-
//! running it at only 8MHz would make every LCD init delay ~9x too
30-
//! short. See README.md for the full story.
23+
//! character LCD over I2C1 (PB6/PB7) via a PCF8574 backpack, using the
24+
//! unmodified oneIO::display::I2cLcd -> Hd44780 -> oneBus::I2cGpio ->
25+
//! hw::stm32::Stm32I2cCore stack -- composition over a real peripheral,
26+
//! not a toy counter. Needs a PLL clock (hd44780.h's delay loop assumes
27+
//! ~72MHz; the 8MHz HSI reset default would under-delay LCD init ~9x).
28+
//! See README.md.
3129
#![no_std]
3230
#![no_main]
3331

@@ -61,27 +59,12 @@ fn main() -> ! {
6159
let mut gpioc = dp.GPIOC.split(&mut dp.RCC);
6260

6361
let mut flash = dp.FLASH.constrain();
64-
// HSI-derived PLL, NOT HSE -- real, sequenced findings, both caught
65-
// by register readback rather than assumed:
66-
// (1) rcc::Config::hsi().sysclk(72.MHz()) does not error on an
67-
// unreachable target -- HSI/2=4MHz's max PLL multiplier is x16
68-
// (hardware limit), so it silently clamps to 64MHz instead of
69-
// the requested 72MHz (confirmed: PLLSRC=0, PLLMUL=x16).
70-
// (2) Tried rcc::Config::hse(8.MHz()).sysclk(72.MHz()) to reach the
71-
// literal 72MHz via the Blue Pill's onboard crystal -- REVERTED:
72-
// the driver's real HSE-ready wait is an unconditional busy-loop
73-
// (`while hserdy is clear {}`) with no timeout, executed BEFORE
74-
// any PLL/LED/LCD code. If this specific board's HSE crystal
75-
// isn't populated or isn't starting, that hangs forever and
76-
// NOTHING after it (including the LCD output below) ever runs.
77-
// A second register readback after that attempt was consistent
78-
// with exactly this (state frozen before the PLL step), not
79-
// confirmed as a working 72MHz clock.
80-
// 64MHz (not 72MHz) is safe for hd44780.h's delay calibration: a
81-
// slower-than-assumed clock makes the busy-loop delays LONGER than
82-
// the nominal microsecond value, not shorter -- HD44780 tolerates
83-
// longer-than-minimum delays fine, only under-delaying breaks it
84-
// (the real problem the original 8MHz-only config had).
62+
// sysclk(72.MHz()) on HSI silently clamps to 64 MHz -- HSI/2 = 4 MHz
63+
// caps the PLL at x16 (PLLSRC=0, PLLMUL=x16, register-confirmed). The
64+
// HSE path for a literal 72 MHz is avoided: the HAL's HSE-ready wait
65+
// is an un-timeout'd busy-loop, so a dead crystal hangs the firmware.
66+
// 64 MHz is fine for hd44780.h -- a slower clock only over-delays.
67+
// lcd_shim.cpp pins the I2C core to the matching 32 MHz APB1.
8568
let _rcc = dp.RCC.freeze(rcc::Config::hsi().sysclk(72.MHz()), &mut flash.acr);
8669

8770
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);

0 commit comments

Comments
 (0)