Skip to main content

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.
Figure 9.3.3. One GPIO pin, from RM0490 Figure 15. The output data register can be written directly or through the bit set/reset registers (left); the input path is sampled into the input data register and also leaves for the EXTI (top left); and the pull-up and pull-down resistors, selected in PUPDR, are on the pin side (right). The Schmitt trigger in the input driver is what turns a slowly changing voltage (such as a debounced button’s) into a clean logic level.
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.