LEDs, again

In the last section, I gave you initialized (configured) peripherals (I initialized them inaux7::init). That’s why just writing to BSRR was enough to control the LEDs. But, peripheralsare not initialized right after the microcontroller boots.

In this section, you’ll have more fun with registers. I won’t do any initialization and you’ll haveto initialize configure GPIOE pins as digital outputs pins so that you’ll be able to drive LEDsagain.

This is the starter code.

1. {{#include src/main.rs}}

If you run the starter code, you’ll see that nothing happens this time. Furthermore, if you printthe GPIOE register block, you’ll see that every register reads as zero even after thegpioe.odr.write statement was executed!

1. $ cargo run
2. Breakpoint 1, main () at src/08-leds-again/src/main.rs:9
3. 9           let (gpioe, rcc) = aux8::init();

5. (gdb) continue
6. Continuing.

8. Program received signal SIGTRAP, Trace/breakpoint trap.
9. 0x08000f3c in __bkpt ()

11. (gdb) finish
12. Run till exit from #0  0x08000f3c in __bkpt ()
13. main () at src/08-leds-again/src/main.rs:25
14. 25          aux8::bkpt();

16. (gdb) p/x *gpioe
17. $1 = stm32f30x::gpioc::RegisterBlock {
18. moder: stm32f30x::gpioc::MODER {
19. register: vcell::VolatileCell<u32> {
20. value: core::cell::UnsafeCell<u32> {
21. value: 0x0
22. }
23. }
24. },
25. otyper: stm32f30x::gpioc::OTYPER {
26. register: vcell::VolatileCell<u32> {
27. value: core::cell::UnsafeCell<u32> {
28. value: 0x0
29. }
30. }
31. },
32. ospeedr: stm32f30x::gpioc::OSPEEDR {
33. register: vcell::VolatileCell<u32> {
34. value: core::cell::UnsafeCell<u32> {
35. value: 0x0
36. }
37. }
38. },
39. pupdr: stm32f30x::gpioc::PUPDR {
40. register: vcell::VolatileCell<u32> {
41. value: core::cell::UnsafeCell<u32> {
42. value: 0x0
43. }
44. }
45. },
46. idr: stm32f30x::gpioc::IDR {
47. register: vcell::VolatileCell<u32> {
48. value: core::cell::UnsafeCell<u32> {
49. value: 0x0
50. }
51. }
52. },
53. odr: stm32f30x::gpioc::ODR {
54. register: vcell::VolatileCell<u32> {
55. value: core::cell::UnsafeCell<u32> {
56. value: 0x0
57. }
58. }
59. },
60. bsrr: stm32f30x::gpioc::BSRR {
61. register: vcell::VolatileCell<u32> {
62. value: core::cell::UnsafeCell<u32> {
63. value: 0x0
64. }
65. }
66. },
67. lckr: stm32f30x::gpioc::LCKR {
68. register: vcell::VolatileCell<u32> {
69. value: core::cell::UnsafeCell<u32> {
70. value: 0x0
71. }
72. }
73. },
74. afrl: stm32f30x::gpioc::AFRL {
75. register: vcell::VolatileCell<u32> {
76. value: core::cell::UnsafeCell<u32> {
77. value: 0x0
78. }
79. }
80. },
81. afrh: stm32f30x::gpioc::AFRH {
82. register: vcell::VolatileCell<u32> {
83. value: core::cell::UnsafeCell<u32> {
84. value: 0x0
85. }
86. }
87. },
88. brr: stm32f30x::gpioc::BRR {
89. register: vcell::VolatileCell<u32> {
90. value: core::cell::UnsafeCell<u32> {
91. value: 0x0
92. }
93. }
94. }
95. }