probe-rs / rtt-target

Target side implementation of the RTT (Real-Time Transfer) I/O protocol
MIT License
123 stars 30 forks source link

Unable to build when using rtt target #38

Closed TheFern2 closed 1 year ago

TheFern2 commented 1 year ago

I am relatively new to rust and embedded world. I can compile and run my project on my nucleo4266 but when I add rtt target I get a rust-lld linking error. Any idea what I'm doing wrong?

[dependencies]
embedded-hal = "0.2"
nb = "1"
cortex-m = "0.7.7"
cortex-m-rt = "0.7.0"
# Panic behaviour, see https://crates.io/keywords/panic-impl for alternatives
panic-halt = "0.2"
rtt-target = "0.4.0"
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }

[dependencies.stm32f4xx-hal]
version = "0.15.0"
features = ["stm32f446", "rt"]
#![deny(unsafe_code)]
#![allow(clippy::empty_loop)]
#![no_main]
#![no_std]

// Halt on panic
// use panic_halt as _; // panic handler
use panic_rtt_target as _;

// use panic_rtt_target as _;
// use rtt_target::{rprintln, rtt_init_print};
use cortex_m_rt::entry;
use stm32f4xx_hal as hal;
use crate::hal::{pac, prelude::*};

use rtt_target::{rprintln, rtt_init_print};

#[entry]
fn main() -> ! {
    rtt_init_print!();
    if let (Some(dp), Some(cp)) = (
        pac::Peripherals::take(),
        cortex_m::peripheral::Peripherals::take(),
    ) {
        // Set up the LED. On the Nucleo-446RE it's connected to pin PA5.
        let gpioa = dp.GPIOA.split();
        let mut led = gpioa.pa5.into_push_pull_output();

        // Set up the system clock. We want to run at 48MHz for this one.
        let rcc = dp.RCC.constrain();
        let clocks = rcc.cfgr.sysclk(48.MHz()).freeze();

        // Create a delay abstraction based on SysTick
        let mut delay = cp.SYST.delay(&clocks);

        loop {
            // On for 1s, off for 1s.
            led.toggle();
            delay.delay_ms(5000_u32);
            rprintln!("Yay I am ticking!!")
        }
    }

    loop {}
}
Compiling blinky-rs v0.1.0 (/home/fernandob/Downloads/test_nucleo-master)
error: could not compile `blinky-rs` due to 2 previous errors
error: linking with `rust-lld` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH=[snip]
= note: rust-lld: warning: section type mismatch for .got
          >>> <internal>:(.got): SHT_PROGBITS
          >>> output section .got: SHT_NOBITS

          rust-lld: warning: section type mismatch for .got.plt
          >>> <internal>:(.got.plt): SHT_PROGBITS
          >>> output section .got: SHT_NOBITS

          rust-lld: warning: section type mismatch for .got
          >>> <internal>:(.got): SHT_PROGBITS
          >>> output section .got: SHT_NOBITS

          rust-lld: error: undefined symbol: _critical_section_1_0_release
          >>> referenced by lib.rs:197 (/home/fernandob/.cargo/registry/src/github.com-1ecc6299db9ec823/critical-section-1.1.1/src/lib.rs:197)
          >>>               rtt_target-594f1569cb403d20.rtt_target.2e912cf7-cgu.11.rcgu.o:(core::ptr::drop_in_place$LT$critical_section..with..Guard$GT$::hd4b7bc756b82a1b6) in archive /home/fernandob/Downloads/test_nucleo-master/target/thumbv7em-none-eabihf/debug/deps/librtt_target-594f1569cb403d20.rlib

          rust-lld: error: undefined symbol: _critical_section_1_0_acquire
          >>> referenced by lib.rs:180 (/home/fernandob/.cargo/registry/src/github.com-1ecc6299db9ec823/critical-section-1.1.1/src/lib.rs:180)
          >>>               rtt_target-594f1569cb403d20.rtt_target.2e912cf7-cgu.14.rcgu.o:(critical_section::with::h2d4c3e0afc82c83d) in archive /home/fernandob/Downloads/test_nucleo-master/target/thumbv7em-none-eabihf/debug/deps/librtt_target-594f1569cb403d20.rlib
          >>> referenced by lib.rs:180 (/home/fernandob/.cargo/registry/src/github.com-1ecc6299db9ec823/critical-section-1.1.1/src/lib.rs:180)
          >>>               rtt_target-594f1569cb403d20.rtt_target.2e912cf7-cgu.14.rcgu.o:(critical_section::with::hd7b00b367f11c22c) in archive /home/fernandob/Downloads/test_nucleo-master/target/thumbv7em-none-eabihf/debug/deps/librtt_target-594f1569cb403d20.rlib

error: aborting due to previous error

       Error Failed to run cargo build: exit code = Some(101).
TheFern2 commented 1 year ago

Okay by some miracle, I was just downgrading all the dependencies, to see if I would get lucky. And when I downgraded rtt-target from 4.0.0 to 0.3.1 it gave me a clearer error, that I was missing adding cortex-m as a feature.

[dependencies]
embedded-hal = "0.2.7"
nb = "1.1.0"
cortex-m = "0.7.6"
cortex-m-rt = "0.7.3"
# Panic behaviour, see https://crates.io/keywords/panic-impl for alternatives
panic-halt = "0.2"
rtt-target = { version = "0.3.1", features = ["cortex-m"] }  # <--- I was missing this
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }

[dependencies.stm32f4xx-hal]
version = "0.15.0"
features = ["stm32f446", "rt"]