RTRM: Reading The Reference Manual
The first thing we have to find out is which pin is connected to which LED. This information is inthe STM32F3DISCOVERY User Manual (You downloaded a copy, right?). In this particular section:
The manual says:
- , the North LED, is connected to the pin
PE9
.PE9
is the short form of: Pin 9 on Port E.
Up to this point, we know that we want to change the state of the pins PE9 and PE11 to turn theNorth/East LEDs on/off. These pins are part of Port E so we’ll have to deal with the GPIOE
peripheral.
Each peripheral has a register block associated to it. A register block is a collection ofregisters allocated in contiguous memory. The address at which the register block starts is known asits base address. We need to figure out what’s the base address of the GPIOE
peripheral. Thatinformation is in the following section of the microcontroller :
The table says that base address of the GPIOE
register block is 0x4800_1000
.
We are interested in the register that’s at an offset of 0x18
from the base address of the peripheral. According to the table, that would be the register BSRR
.
Now we need to jump to the documentation of that particular register. It’s a few pages above in:
Finally!
This is the register we were writing to. The documentation says some interesting things. First, thisregister is write only … so let’s try reading its value :-)
.
We’ll use GDB’s examine
command: x
.
The other thing that the documentation says is that the bits 0 to 15 can be used to set thecorresponding pin. That is bit 0 sets the pin 0. Here, set means outputting a high value onthe pin.
The documentation also says that bits 16 to 31 can be used to reset the corresponding pin. In thiscase, the bit 16 resets the pin number 0. As you may guess, reset means outputting a low valueon the pin.
Correlating that information with our program, all seems to be in agreement:
Writing
1 << 9
(BS9 = 1
) toBSRR
setsPE9
high. That turns the North LED on.Writing
1 << 25
(BR9 = 1
) toBSRR
setsPE9
low. That turns the North LED off.