【发布时间】: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