Skip to main content
Contents Index
Search Book
Search Results:
No results.
Readability settings Prev Up Next
\(\newcommand{\N}{\mathbb N}
\newcommand{\Z}{\mathbb Z}
\newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Subsection 1.2.4 Part 4: Explore the Registers
Now we’ll find out what the setup lines in
blinky.c actually do, by changing them one at a time. Predict what will happen before you make each change, then verify on the board, and discuss your predictions with a neighbor.
If you comment out Step 2a, will the LED still blink, stay on, or stay off? Predict below.
#define GPIOAEN (1U << 0) // RCC->IOPENR bit 0: clock for GPIOA
#define LED_PIN (1U << 5) // GPIOA bit 5: the on-board LED
int main(void) {
RCC->IOPENR |= GPIOAEN; // Step 1: enable GPIOA clock
GPIOA->MODER |= (1U << 10); // Step 2a: set bit 10
GPIOA->MODER &= ~(1U << 11); // Step 2b: clear bit 11 → PA5 output
while (1) {
GPIOA->ODR |= LED_PIN; // Step 3: bit 5 = 1 → LED on
for (int i = 0; i < 100000; i++);
GPIOA->ODR &= ~LED_PIN; // Step 4: bit 5 = 0 → LED off
for (int i = 0; i < 100000; i++);
}
return 0;
}
If you comment out Step 1, will the LED still blink, stay on, or stay off? Predict below.
#define GPIOAEN (1U << 0) // RCC->IOPENR bit 0: clock for GPIOA
#define LED_PIN (1U << 5) // GPIOA bit 5: the on-board LED
int main(void) {
RCC->IOPENR |= GPIOAEN; // Step 1: enable GPIOA clock
GPIOA->MODER |= (1U << 10); // Step 2a: set bit 10
GPIOA->MODER &= ~(1U << 11); // Step 2b: clear bit 11 → PA5 output
while (1) {
GPIOA->ODR |= LED_PIN; // Step 3: bit 5 = 1 → LED on
for (int i = 0; i < 100000; i++);
GPIOA->ODR &= ~LED_PIN; // Step 4: bit 5 = 0 → LED off
for (int i = 0; i < 100000; i++);
}
return 0;
}
If you replace
|= with
= in Step 3, what happens in a single-LED Blinky? When would it matter? Predict below.
#define GPIOAEN (1U << 0) // RCC->IOPENR bit 0: clock for GPIOA
#define LED_PIN (1U << 5) // GPIOA bit 5: the on-board LED
int main(void) {
RCC->IOPENR |= GPIOAEN; // Step 1: enable GPIOA clock
GPIOA->MODER |= (1U << 10); // Step 2a: set bit 10
GPIOA->MODER &= ~(1U << 11); // Step 2b: clear bit 11 → PA5 output
while (1) {
GPIOA->ODR |= LED_PIN; // Step 3: bit 5 = 1 → LED on
for (int i = 0; i < 100000; i++);
GPIOA->ODR &= ~LED_PIN; // Step 4: bit 5 = 0 → LED off
for (int i = 0; i < 100000; i++);
}
return 0;
}
Activity 1.2.4 . Register Exploration.
(a)
Comment out
GPIOA->MODER |= (1U << 10); (leave the clock enable and the MODER clear line). Build, flash, and confirm your prediction.
(b)
Restore the MODER line. Comment out
RCC->IOPENR |= GPIOAEN;. Build, flash, and confirm your prediction.
(c)
Restore the RCC line. Replace
GPIOA->ODR |= LED_PIN; with
GPIOA->ODR = LED_PIN; (no
|=). Does this change behavior for a single-LED Blinky? When would it matter?