grmmgrmm
grmmgrmm

Reputation: 1408

Using SPI on TM4C123 to drive display

I use embedded rust on a tiva-c-launchpad (tm4c123) to which I connected a SSD1309 OLED display which I'm trying to drive using SPI.

The crates I use are the tm4c123x_hal and the ssd1309. I based my attempt on this example.

I ran into an issue which I don't understand because I'm lacking experience in embedded 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
    );

    ...

The issue I'm running into is this:

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`.

I'm having trouble understanding how to tackle that. So, I understand that MisoPin needs to be implemented on PA3 but my gut feeling tells me that I'm simply using it wrong. So what am I doing wrong or what could be the next thing to look into?

BTW: I'm rather new to embedded rust. Thus, chances are high that this is an asbolute noob problem :)

Upvotes: 0

Views: 378

Answers (1)

grmmgrmm
grmmgrmm

Reputation: 1408

Ok, I think I found the answer re-reading the documentation here: https://docs.rs/tm4c123x-hal/latest/tm4c123x_hal/spi/trait.MisoPin.html

What is important to note is that in this HAL the MisoPin is only implemented for 4 pins, one of which is PA4.

Changed to use that and the error is gone.

Incredible how phrasing questions sometimes helps to find the answer...

EDIT: I put a fully working example based on my findings here and hope it helps others to get up to speed faster: https://github.com/HerrMuellerluedenscheid/tm4c-oled-example

Upvotes: 1

Related Questions