liveBook · Manning

Peripheral handle

As explained in Embedded Software with Rust

A peripheral handle is an owning value that grants exclusive software control over a peripheral's memory-mapped registers.

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

How Embedded Software with Rust covers it

How deep it goes
Explains ownership, borrowing, PAC singleton access, and register operations, stopping short of detailed register-block internals.
Examples
Uses STM32F103 GPIO handles to set pins and configure register fields, with a USART interrupt example.
What you can do after
Operate/configure peripherals through owned PAC handles and pass temporary borrows to helper code.
How it connects
Connects peripheral handles to ownership, borrowing, memory-mapped I/O, and peripheral access crates.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.