【问题标题】:What right hand side of the statement is doing?语句的右侧在做什么?
【发布时间】:2021-09-04 19:24:09
【问题描述】:

LED 闪烁后。我从章节注册开始,在第一页本身我遇到了一些问题。我阅读了其中的大部分内容,发现地址是 const 并使用我们使用原始指针 GPIOE_BSRR 作为 *mut u32 的固定值,它正在复制地址(引用)变量并允许我们进行更改。 其次,我们使用 * 解引用,并根据原始指针引用规则将语句放入 unsafe 块中。..

我希望到这里我现在就明白了,下一个问题是我们在右侧使用 shift 运算符所做的事情。我们使用 9 11 设置和 16, 25 重置 但为什么每班 1 个?

  #![no_main]
#![no_std]

#[allow(unused_imports)]
use aux7::{entry, iprint, iprintln};

#[entry]
fn main() -> ! {
aux7::init();

{
// A magic address!
const GPIOE_BSRR: u32 = 0x48001018;

    // Turn on the "North" LED (red)
    //we use the dereference operator * on a raw pointer that requires an unsafe block.
    //change data through the mutable pointer
    (GPIOE_BSRR as *mut u32) = 1 << 9;

    // Turn on the "East" LED (green)
    *(GPIOE_BSRR as *mut u32) = 1 << 11;

    // Turn off the "North" LED
    (GPIOE_BSRR as *mut u32) = 1 << (9 + 16);

    // Turn off the "East" LED
    (GPIOE_BSRR as *mut u32) = 1 << (11 + 16);
}
loop {}
}

【问题讨论】:

    标签: rust stm32 stm32f4discovery


    【解决方案1】:

    向 GPIO BSRR 写入 1 会设置或重置 GPIO ODR 中的位。写 0 什么都不做。请参阅RM0090 第 8.4.7 节。

    【讨论】:

    • 哦,是的,我错过了它正在写入 1 和 0 的 ODR 寄存器。我还有一个问题。编写、设置、重置就这么简单吗?这种转变实际上是如何与地址一起工作的? 1
    【解决方案2】:

    1 用于设置和重置位,这就是我们使用 1 来打开和关闭 LED 的原因。 1 表示我们在这里进行左移操作。 例如:我们有 32 位 (0000....0) 对。 0 表示每个位的电压低,现在要打开位于引脚 9 的 LD3(红色 LED),我们使用 1 为其提供高电压(因为 1 用于设置和重置两者),类似于关闭 LED我们正在执行 1 因为引脚 9 的复位位是 25(9+16),并且再次使用 1 来复位引脚。

    有关更多信息,您可以阅读发现板的参考手册。 https://www.st.com/resource/en/reference_manual/dm00043574-stm32f303xb-c-d-e-stm32f303x6-8-stm32f328x8-stm32f358xc-stm32f398xe-advanced-arm-based-mcus-stmicroelectronics.pdf#page=240&zoom=100,89,117

    谢谢

    【讨论】:

    • 感谢您的解释。现在更清楚了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 2010-11-18
    • 1970-01-01
    • 2012-02-04
    • 2011-08-27
    • 2014-12-22
    • 1970-01-01
    相关资源
    最近更新 更多