Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation code does not work properly #3793

Open
huifer opened this issue Jan 22, 2025 · 0 comments
Open

Documentation code does not work properly #3793

huifer opened this issue Jan 22, 2025 · 0 comments

Comments

@huifer
Copy link

huifer commented Jan 22, 2025

link : https://embassy.dev/book/#_pac_version
Code source : https://github.com/embassy-rs/embassy/blob/main/docs/examples/layer-by-layer/blinky-pac/src/main.rs

#![no_std]
#![no_main]

use pac::gpio::vals;
use {defmt_rtt as _, panic_probe as _, stm32_metapac as pac};

#[cortex_m_rt::entry]
fn main() -> ! {
    // Enable GPIO clock
    let rcc = pac::RCC;
    rcc.ahb2enr().modify(|w| {
        w.set_gpioben(true);
        w.set_gpiocen(true);
    });

    rcc.ahb2rstr().modify(|w| {
        w.set_gpiobrst(true);
        w.set_gpiocrst(true);
        w.set_gpiobrst(false);
        w.set_gpiocrst(false);
    });

    // Setup button
    let gpioc = pac::GPIOC;
    const BUTTON_PIN: usize = 13;
    gpioc.pupdr().modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULL_UP));
    gpioc.otyper().modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSH_PULL));
    gpioc.moder().modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT));

    // Setup LED
    let gpiob = pac::GPIOB;
    const LED_PIN: usize = 14;
    gpiob.pupdr().modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING));
    gpiob.otyper().modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSH_PULL));
    gpiob.moder().modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT));

    // Main loop
    loop {
        if gpioc.idr().read().idr(BUTTON_PIN) == vals::Idr::LOW {
            gpiob.bsrr().write(|w| w.set_bs(LED_PIN, true));
        } else {
            gpiob.bsrr().write(|w| w.set_br(LED_PIN, true));
        }
    }
}

In the above code, use pac:gpio::vals; Is there any other way to pour Vals properly.

cargo.toml :

# This file was automatically generated.

[package]
edition = "2021"
name = "app"
version = "0.1.0"

[dependencies]
embassy-stm32 = { version = "0.2.0", features =  ["defmt",
    "stm32l431rc", "time-driver-any", "memory-x", "unstable-pac", "exti", "chrono","low-power"]  }
embassy-executor = { version = "0.7.0", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt"] }
embassy-time = { version = "0.4.0", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
ufmt = "0.1"
embassy-futures = {version = "0.1.1",features = ["defmt"]}
defmt = "0.3.5"
defmt-rtt = "0.4.0"
cortex-m = {version = "0.7.7", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7.3"
panic-probe = "0.3.1"

embedded-io-async = "0.6.1"
embedded-io = "0.6.1"
embedded-alloc = {version = "=0.6.0", features = ["llff"]}
heapless="0.8.0"
nb = "1.0.0"
static_cell = "2"
stm32-metapac = {version = "16.0.0",features = ["pac","stm32l431rc"]}
embassy-sync = "0.6.2"
[[bin]]
name = "app"
test = false
bench = false

[profile.dev]


[profile.release]
debug = true
[features]
default = ["defmt-default"]
defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant