Skip to main content

Subsection 7.1.5 Part 3b: Watching a Register Change

Your debug session from Subsection 7.1.4 is halted at the first line of main(), and while it is halted, the debugger can show you every peripheral register on the chip, live. In the pane on the right, select the SFRs tab (Special Function Registers). It lists the processor’s internals under Cortex_M0PLUS and every peripheral you have used, under STM32C031: ADC, GPIOA, RCC, USART2, and the rest, each expandable down to individual registers and bit fields (Figure 7.1.7). These are the same registers, with the same names, as in the reference manual, RM0490. What the SFRs view adds is the value each one holds on your own chip at this moment.
Figure 7.1.7. The SFRs tab: the processor’s internals under Cortex_M0PLUS, and every peripheral from the reference manual under STM32C031. The x16/x10/x2 buttons switch the value display’s radix between base-16 (hexadecimal), base-10 (decimal) and base-2 (binary).
The first statement of main() (highlighted in blue, loaded, not yet executed) is one you can recite from Day 1:
RCC->IOPENR |= GPIOAEN;     // Step 1: enable GPIOA clock

Activity 7.1.6. Predict, Then Step.

(a)

In the SFRs tab, expand RCC, then RCC_IOPENR. Note the current value of the register, and take a look at its bit 0 (the field named GPIOAEN).

(b)

The blue-highlighted line is about to run. Predict what RCC_IOPENR will read after it executes, the whole register, not just the bit.

(c)

Execute exactly that one line: click Step Over in the toolbar. Check RCC_IOPENR against your prediction.
Figure 7.1.8. RCC_IOPENR before and after single-stepping the first line of main(). Left: at launch the register reads 0x0, and GPIOA’s clock is off. Right: after one Step Over it reads 0x1, and the GPIOAEN field holds 1. The yellow highlight means “this value changed since the debugger last looked.” Right after launch the debugger is reading every register for the first time, so many rows glow yellow. Ignore that first flush. After a step the highlight becomes useful: only RCC_IOPENR is yellow, the one register the step changed.
You wrote RCC->IOPENR |= GPIOAEN; in week one and trusted that it did something. You have now watched it happen on your own board: one line of code changing one bit in one register. Every register write in every program this term can be checked the same way.