aboutsummaryrefslogtreecommitdiff
path: root/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src
diff options
context:
space:
mode:
Diffstat (limited to 'docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src')
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs
new file mode 100644
index 000000000..239eac188
--- /dev/null
+++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs
@@ -0,0 +1,69 @@
1#![no_std]
2#![no_main]
3
4use defmt_rtt as _;
5use panic_probe as _;
6
7use stm32_metapac as pac;
8
9use pac::gpio::vals;
10
11#[cortex_m_rt::entry]
12fn main() -> ! {
13 // Enable GPIO clock
14 let rcc = pac::RCC;
15 unsafe {
16 rcc.ahb2enr().modify(|w| {
17 w.set_gpioben(true);
18 w.set_gpiocen(true);
19 });
20
21 rcc.ahb2rstr().modify(|w| {
22 w.set_gpiobrst(true);
23 w.set_gpiocrst(true);
24 w.set_gpiobrst(false);
25 w.set_gpiocrst(false);
26 });
27 }
28
29 // Setup button
30 let gpioc = pac::GPIOC;
31 const BUTTON_PIN: usize = 13;
32 unsafe {
33 gpioc
34 .pupdr()
35 .modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP));
36 gpioc
37 .otyper()
38 .modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL));
39 gpioc
40 .moder()
41 .modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT));
42 }
43
44 // Setup LED
45 let gpiob = pac::GPIOB;
46 const LED_PIN: usize = 14;
47 unsafe {
48 gpiob
49 .pupdr()
50 .modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING));
51 gpiob
52 .otyper()
53 .modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL));
54 gpiob
55 .moder()
56 .modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT));
57 }
58
59 // Main loop
60 loop {
61 unsafe {
62 if gpioc.idr().read().idr(BUTTON_PIN) == vals::Idr::LOW {
63 gpiob.bsrr().write(|w| w.set_bs(LED_PIN, true));
64 } else {
65 gpiob.bsrr().write(|w| w.set_br(LED_PIN, true));
66 }
67 }
68 }
69}