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();
  4. (gdb) continue
  5. Continuing.
  6. Program received signal SIGTRAP, Trace/breakpoint trap.
  7. 0x08000f3c in __bkpt ()
  8. (gdb) finish
  9. Run till exit from #0 0x08000f3c in __bkpt ()
  10. main () at src/08-leds-again/src/main.rs:25
  11. 25 aux8::bkpt();
  12. (gdb) p/x *gpioe
  13. $1 = stm32f30x::gpioc::RegisterBlock {
  14. moder: stm32f30x::gpioc::MODER {
  15. register: vcell::VolatileCell<u32> {
  16. value: core::cell::UnsafeCell<u32> {
  17. value: 0x0
  18. }
  19. }
  20. },
  21. otyper: stm32f30x::gpioc::OTYPER {
  22. register: vcell::VolatileCell<u32> {
  23. value: core::cell::UnsafeCell<u32> {
  24. value: 0x0
  25. }
  26. }
  27. },
  28. ospeedr: stm32f30x::gpioc::OSPEEDR {
  29. register: vcell::VolatileCell<u32> {
  30. value: core::cell::UnsafeCell<u32> {
  31. value: 0x0
  32. }
  33. }
  34. },
  35. pupdr: stm32f30x::gpioc::PUPDR {
  36. register: vcell::VolatileCell<u32> {
  37. value: core::cell::UnsafeCell<u32> {
  38. value: 0x0
  39. }
  40. }
  41. },
  42. idr: stm32f30x::gpioc::IDR {
  43. register: vcell::VolatileCell<u32> {
  44. value: core::cell::UnsafeCell<u32> {
  45. value: 0x0
  46. }
  47. }
  48. },
  49. odr: stm32f30x::gpioc::ODR {
  50. register: vcell::VolatileCell<u32> {
  51. value: core::cell::UnsafeCell<u32> {
  52. value: 0x0
  53. }
  54. }
  55. },
  56. bsrr: stm32f30x::gpioc::BSRR {
  57. register: vcell::VolatileCell<u32> {
  58. value: core::cell::UnsafeCell<u32> {
  59. value: 0x0
  60. }
  61. }
  62. },
  63. lckr: stm32f30x::gpioc::LCKR {
  64. register: vcell::VolatileCell<u32> {
  65. value: core::cell::UnsafeCell<u32> {
  66. value: 0x0
  67. }
  68. }
  69. },
  70. afrl: stm32f30x::gpioc::AFRL {
  71. register: vcell::VolatileCell<u32> {
  72. value: core::cell::UnsafeCell<u32> {
  73. value: 0x0
  74. }
  75. }
  76. },
  77. afrh: stm32f30x::gpioc::AFRH {
  78. register: vcell::VolatileCell<u32> {
  79. value: core::cell::UnsafeCell<u32> {
  80. value: 0x0
  81. }
  82. }
  83. },
  84. brr: stm32f30x::gpioc::BRR {
  85. register: vcell::VolatileCell<u32> {
  86. value: core::cell::UnsafeCell<u32> {
  87. value: 0x0
  88. }
  89. }
  90. }
  91. }