A peripheral handle is an owning value that controls access to a memory-mapped register block. Moving it transfers control; borrowing it provides temporary access. Shared borrows allow read-only access, while mutable borrows grant short-lived exclusive access. Rust prevents overlapping shared and mutable access to the same resource. section 1.4.1
A PAC can provide strongly typed handles in a Peripherals struct. Calling Peripherals::take() obtains the singleton, avoiding multiple software owners of the same peripheral. Move a handle into the module responsible for configuring and driving the device, then pass short-lived borrows to helpers. section 1.4.1 section 5.3.3
Write a GPIO register
A strongly typed GPIO handle can access its register methods. This write sets pin 13 through the dedicated BSRR set/reset register: gpioc.bsrr().write(|w| w.br13().set_bit()); section 5.3.3
gpioc.crh().modify(|_, w| {
w.mode13().output2() // Set mode to output, 2MHz
.cnf13().push_pull() // Set configuration to push-pull
});
This PAC example borrows a GPIO handle and uses modify to update selected register fields. section 5.3.3
