Subsection 9.3.4 ODR, BSRR, and the Pin’s Own Circuit
Figure 9.3.3 is the chip’s own diagram of a single I/O pin, and it puts this chapter’s two topics in one picture. On the right are the pull-up and pull-down resistors that we configured through PUPDR and that hold PB4 HIGH when the button is open. Along the top, the input path leaves for “on-chip peripherals, power control and EXTI”. That branch is how a pin’s level reaches the multiplexer in Figure 9.2.3. And on the left, feeding the output data register, is a block labeled bit set/reset registers: BSRR is not a shortcut layered on top of ODR in software, it is a second write port into the same output latches, built into the pin’s circuit.
/gpio_input_driver.png)
The rule of thumb: use
ODR when the code writing it is the only code writing that port, and use BSRR when it is not, which, once you have interrupts, is more often than it used to be. BSRR costs nothing extra; a set or a clear is one store either way, and the read that |= and &= ~ need is the part that goes away.
