26个版本
0.10.0 | 2023年11月30日 |
---|---|
0.9.2 | 2023年2月20日 |
0.9.1 | 2022年9月7日 |
0.9.0 | 2022年3月6日 |
0.2.3 | 2019年7月7日 |
#3 in #hardware-abstraction
每月753次下载
用于 9 个crate(8个直接使用)
455KB
9K SLoC
stm32f3xx-hal
stm32f3xx-hal
包含了对STMicro STM32F3系列微控制器外设访问API的多设备硬件抽象。通过功能门选择MCU,通常由板级支持crate指定。支持的芯片变体示例
- stm32f301
- stm32f318
- stm32f302
- stm32f303
- stm32f373
- stm32f378
- stm32f334
- stm32f328
- stm32f358
- stm32f398
这个crate背后的想法是,为了编写适用于同一系列中所有芯片的HAL,可以忽略那些MCU上各种外设之间微小的差异。
非常欢迎对这个crate进行合作,以及合并请求!
这个crate依赖于Adam Greig出色的stm32f3
crate以提供适当的寄存器定义,并实现了embedded-hal
traits的部分集合。
几乎所有的实现都是从Jorge Aparicio的stm32f30x-hal
crate中无耻地改编而来的。
入门
添加stm32f3xx-hal和其他依赖项
Cargo.toml
[dependencies]
# Only set the critical section feature, if you are using a bare-metal platform
# without any RTOS
# See https://github.com/rust-embedded/critical-section for further details.
cortex-m = { version = "0.7.4", features = ["critical-section-single-core"]}
cortex-m-rt = { version = "0.7.3", features = ["device"] }
# Panic behavior, see https://crates.io/keywords/panic-impl for alternatives
panic-halt = "0.2.0"
# Replace stm32f303xc with your target chip, see next section for more info
stm32f3xx-hal = { version = "0.10.0", features = ["ld", "rt", "stm32f303xc"] }
我们还需要通过创建 .cargo/config
来告诉Rust目标架构和如何链接我们的可执行文件。
.cargo/config
[target.thumbv7em-none-eabihf]
rustflags = [
"-C", "link-arg=-Tlink.x",
]
[build]
target = "thumbv7em-none-eabihf"
选择正确的芯片
这个crate要求你指定目标芯片作为功能。
示例:STM32F3Discovery板根据用户手册拥有STM32F303VCT6芯片。因此,你需要在你的 Cargo.toml
中指定 stm32f303xc
(注意VC → xc)。
可以通过cargo功能选择所有可能的芯片变体。你可以在这里,文档中找到列表。
注意
- 这些特性是互斥的。只能选择一个特性或芯片变体。
- 您必须恰好选择一个特性才能构建此容器。
背景
对于某些stm32f3xx芯片,存在功能、外设使用和“底层”实现不同的子变体。为了在不允许代码仅在其他子变体上运行的情况下,充分利用某些子变体上的所有外设,它们是必须指定的一些独立特性。
基本用法
#![no_std]
#![no_main]
use cortex_m::asm;
use cortex_m_rt::entry;
use panic_halt as _;
use stm32f3xx_hal::{self as hal, pac, prelude::*};
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let mut rcc = dp.RCC.constrain();
let mut gpioe = dp.GPIOE.split(&mut rcc.ahb);
let mut led = gpioe
.pe13
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
loop {
led.toggle().unwrap();
asm::delay(8_000_000);
}
}
有关更多示例程序,请参阅示例文件夹。
变更日志
最小支持的Rust版本(MSRV)
此容器保证在稳定Rust 1.60.0及更高版本上编译。它可能可以用较旧的版本编译,但这可能在任何新的补丁版本中改变。
贡献
许可
根据您的选择,许可协议为以下之一
- Apache许可证第2版 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
。
除非您明确说明,否则根据Apache-2.0许可证定义,您有意提交的任何贡献,包括您的工作,将根据上述内容双重许可,不附加任何额外条款或条件。
依赖项
约25MB
约705K SLoC