A read-modify-write operation reads a register, changes selected fields, then writes the updated value back. In a Peripheral Access Crate (PAC), `modify` provides this pattern: unmentioned fields keep their current values. Because the sequence reads before writing, another context such as an interrupt can update the register in between. section 5.3.3 section 5.3.1
gpioc.crh().modify(|_, w| {
w.mode13().output2() // Set mode to output, 2MHz
.cnf13().push_pull() // Set configuration to push-pull
});
This PAC call updates GPIO pin 13's mode and configuration fields in CRH while preserving the other fields. section 5.3.3
For GPIO output changes, STM32's BSRR register offers an alternative: writing set/reset bits changes pins without reading the current port state, avoiding the read-modify-write race. section 5.3.1 section 5.3.3




