#raspberry-pi #uart #bare-metal #ruspiro #debugging

无标准库 ruspiro-uart

为Raspberry Pi 3的UART0(PL011)和UART1(miniUART)外设提供简单便捷的访问API

6个版本 (重大更改)

0.4.0 2021年9月7日
0.3.1 2020年9月13日
0.3.0 2019年12月14日
0.2.0 2019年8月31日
0.0.3 2019年7月30日

#2054嵌入式开发


用于 ruspiro-sdk

MIT/Apache

34KB
445

UART RusPiRo软件包

此软件包提供对Raspberry Pi的Uart0(Pl011)和Uart1(miniUART)外设的访问。这在裸机开发期间非常有用,可以使用连接到Raspberry Pi miniUART的终端控制台来获取在设备上执行程序时打印的调试信息。特别是当程序处于没有其他输出选项且闪烁LED不足够的状态时。

CI Latest Version Documentation License

用法

要使用此软件包,只需将以下依赖项添加到您的 Cargo.toml 文件中

[dependencies]
ruspiro-uart = "0.4.0"

完成后,UART抽象的访问将在您的Rust文件中可用,如下所示

use ruspiro_uart::Uart1;

fn demo() {
    let mut uart = Uart1::new();
    if uart.initialize(250_000_000, 115_200).is_ok() {
        uart.send_string("This is some string");
    }
}

在此示例中,一旦Uart1超出作用域,它将不再可用。这使得在实际示例中使用它有些不便。因此,建议将UART用作通用的控制台输出通道。为此,请参阅ruspiro-console软件包。但如果你想要在没有控制台抽象的情况下使用uart,建议将其包装到单例中以保证安全的跨核心访问和一次性初始化。在示例中,我们将固定的核心时钟速率传递给初始化函数。然而,实际的核心时钟速率可以通过调用Raspberry Pi的邮箱属性标签接口获取(有关详细信息,请参阅ruspiro-mailbox)。此邮箱软件包未链接到Uart软件包,以确保尽可能少地依赖以使用此软件包。

use ruspiro_singleton::Singleton;
use ruspiro_uart::Uart1;

static UART: Singleton<Uart1> = Singleton::new(Uart1::new());

fn demo() {
    let _ = UART.with_mut(|uart| uart.initialize(250_000_000, 115_200)).expect("unable to init uart1");

    print_something("Hello Uart...");
}

fn print_something(s: &str) {
    UART.with_ref(|uart| uart.send_string(s));
}

许可

根据Apache License,版本2.0,(LICENSE-APACHEhttps://apache.ac.cn/licenses/LICENSE-2.0) 或 MIT (LICENSE-MIThttp://opensource.org/licenses/MIT))许可。

依赖关系

~2MB
~40K SLoC