使用 TM4C123 上的 SPI 驱动显示
Using SPI on TM4C123 to drive display
我在 tiva-c-launchpad (tm4c123
) 上使用嵌入式 Rust,我连接了一个 SSD1309
OLED 显示器,我试图使用 SPI
驱动它。
我用的板条箱是tm4c123x_hal and the ssd1309。
我的尝试基于 this example.
我 运行 遇到一个我不明白的问题,因为我缺乏嵌入式 Rust 的经验。
#![no_std]
#![no_main]
use core::fmt::Write;
use cortex_m_rt::entry;
use panic_halt as _;
use ssd1309::Builder; // you can put a breakpoint on `rust_begin_unwind` to catch panics
use tm4c123x_hal::{self as hal, prelude::*};
use display_interface_spi::SPIInterfaceNoCS;
#[entry]
fn main() -> ! {
let p = hal::Peripherals::take().unwrap();
let mut sc = p.SYSCTL.constrain();
let mut porta = p.GPIO_PORTA.split(&sc.power_control);
sc.clock_setup.oscillator = hal::sysctl::Oscillator::Main(
hal::sysctl::CrystalFrequency::_16mhz,
hal::sysctl::SystemClock::UsePll(hal::sysctl::PllOutputFrequency::_80_00mhz),
);
let clocks = sc.clock_setup.freeze();
let dc = porta.pa4.into_push_pull_output(); /* GPIO data/command select pin */
let scl = porta.pa2.into_af_open_drain(&mut porta.control); // PA2 grau SCL (clock line)
let miso = porta.pa3.into_floating_input(); // also tried let miso = porta.pa3.into_af_open_drain(&mut porta.control);
let mosi = porta.pa5.into_af_open_drain(&mut porta.control); // PA5 lila (data line) MOSI?
let mode = hal::spi::MODE_0;
let freq = 400000_u32.hz();
let pins = (scl, miso, mosi);
let spi = hal::spi::Spi::spi0(
p.SSI0,
pins,
mode, freq, &clocks, &sc.power_control
);
...
我 运行 关注的问题是:
error[E0277]: the trait bound `PA3<Input<Floating>>: MisoPin<tm4c123x_hal::tm4c123x::SSI0>` is not satisfied
--> examples/tiva-c-launchpad/src/main.rs:35:43
|
35 | let spi = hal::spi::Spi::spi0(p.SSI0, pins, mode, freq, &clocks, &sc.power_control);
| ------------------- ^^^^ the trait `MisoPin<tm4c123x_hal::tm4c123x::SSI0>` is not implemented for `PA3<Input<Floating>>`
| |
| required by a bound introduced by this call
|
note: required by a bound in `Spi::<tm4c123x_hal::tm4c123x::SSI0, (SCK, MISO, MOSI)>::spi0`
--> /Users/mariuskriegerowski/src/rust/embedded-rust-example/tm4c-hal/tm4c123x-hal/src/spi.rs:221:1
|
221 | / hal! {
222 | | SSI0: (Ssi0, spi0),
223 | | SSI1: (Ssi1, spi1),
224 | | SSI2: (Ssi2, spi2),
225 | | SSI3: (Ssi3, spi3),
226 | | }
| |_^ required by this bound in `Spi::<tm4c123x_hal::tm4c123x::SSI0, (SCK, MISO, MOSI)>::spi0`
= note: this error originates in the macro `hal` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
我无法理解如何解决这个问题。所以,我知道 MisoPin
需要在 PA3
上实现,但我的直觉告诉我我只是用错了。那么我做错了什么或者接下来要研究的是什么?
顺便说一句:我对嵌入式 Rust 比较陌生。因此,这是一个菜鸟问题的可能性很高:)
好的,我想我在此处找到了答案 re-reading 文档:https://docs.rs/tm4c123x-hal/latest/tm4c123x_hal/spi/trait.MisoPin.html
需要注意的是,在此 HAL 中,MisoPin
仅针对 4 个引脚实现,其中之一是 PA4
。
改为使用那个,错误消失了。
难以置信 措辞 问题有时如何帮助找到答案...
编辑:我根据我的发现在这里提供了一个完整的示例,希望它能帮助其他人更快地上手:https://github.com/HerrMuellerluedenscheid/tm4c-oled-example
我在 tiva-c-launchpad (tm4c123
) 上使用嵌入式 Rust,我连接了一个 SSD1309
OLED 显示器,我试图使用 SPI
驱动它。
我用的板条箱是tm4c123x_hal and the ssd1309。 我的尝试基于 this example.
我 运行 遇到一个我不明白的问题,因为我缺乏嵌入式 Rust 的经验。
#![no_std]
#![no_main]
use core::fmt::Write;
use cortex_m_rt::entry;
use panic_halt as _;
use ssd1309::Builder; // you can put a breakpoint on `rust_begin_unwind` to catch panics
use tm4c123x_hal::{self as hal, prelude::*};
use display_interface_spi::SPIInterfaceNoCS;
#[entry]
fn main() -> ! {
let p = hal::Peripherals::take().unwrap();
let mut sc = p.SYSCTL.constrain();
let mut porta = p.GPIO_PORTA.split(&sc.power_control);
sc.clock_setup.oscillator = hal::sysctl::Oscillator::Main(
hal::sysctl::CrystalFrequency::_16mhz,
hal::sysctl::SystemClock::UsePll(hal::sysctl::PllOutputFrequency::_80_00mhz),
);
let clocks = sc.clock_setup.freeze();
let dc = porta.pa4.into_push_pull_output(); /* GPIO data/command select pin */
let scl = porta.pa2.into_af_open_drain(&mut porta.control); // PA2 grau SCL (clock line)
let miso = porta.pa3.into_floating_input(); // also tried let miso = porta.pa3.into_af_open_drain(&mut porta.control);
let mosi = porta.pa5.into_af_open_drain(&mut porta.control); // PA5 lila (data line) MOSI?
let mode = hal::spi::MODE_0;
let freq = 400000_u32.hz();
let pins = (scl, miso, mosi);
let spi = hal::spi::Spi::spi0(
p.SSI0,
pins,
mode, freq, &clocks, &sc.power_control
);
...
我 运行 关注的问题是:
error[E0277]: the trait bound `PA3<Input<Floating>>: MisoPin<tm4c123x_hal::tm4c123x::SSI0>` is not satisfied
--> examples/tiva-c-launchpad/src/main.rs:35:43
|
35 | let spi = hal::spi::Spi::spi0(p.SSI0, pins, mode, freq, &clocks, &sc.power_control);
| ------------------- ^^^^ the trait `MisoPin<tm4c123x_hal::tm4c123x::SSI0>` is not implemented for `PA3<Input<Floating>>`
| |
| required by a bound introduced by this call
|
note: required by a bound in `Spi::<tm4c123x_hal::tm4c123x::SSI0, (SCK, MISO, MOSI)>::spi0`
--> /Users/mariuskriegerowski/src/rust/embedded-rust-example/tm4c-hal/tm4c123x-hal/src/spi.rs:221:1
|
221 | / hal! {
222 | | SSI0: (Ssi0, spi0),
223 | | SSI1: (Ssi1, spi1),
224 | | SSI2: (Ssi2, spi2),
225 | | SSI3: (Ssi3, spi3),
226 | | }
| |_^ required by this bound in `Spi::<tm4c123x_hal::tm4c123x::SSI0, (SCK, MISO, MOSI)>::spi0`
= note: this error originates in the macro `hal` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
我无法理解如何解决这个问题。所以,我知道 MisoPin
需要在 PA3
上实现,但我的直觉告诉我我只是用错了。那么我做错了什么或者接下来要研究的是什么?
顺便说一句:我对嵌入式 Rust 比较陌生。因此,这是一个菜鸟问题的可能性很高:)
好的,我想我在此处找到了答案 re-reading 文档:https://docs.rs/tm4c123x-hal/latest/tm4c123x_hal/spi/trait.MisoPin.html
需要注意的是,在此 HAL 中,MisoPin
仅针对 4 个引脚实现,其中之一是 PA4
。
改为使用那个,错误消失了。
难以置信 措辞 问题有时如何帮助找到答案...
编辑:我根据我的发现在这里提供了一个完整的示例,希望它能帮助其他人更快地上手:https://github.com/HerrMuellerluedenscheid/tm4c-oled-example