-1

I'm trying to write a multi-threaded bare-metal application for the STM32F4Discovery using the Real-Time For the Masses (RTFM) crate. I've frankensteined together a minimal application from an example for the STM32F3Discovery board and this example:

#![no_std]

extern crate cortex_m;
extern crate cortex_m_rtfm as rtfm;
extern crate cortex_m_semihosting;
extern crate panic_semihosting;
extern crate stm32f4;

use stm32f4::stm32f407;

use rtfm::app;

app! {
    device: stm32f407,
}

fn init(_p: init::Peripherals) {
}

fn idle() -> ! {
    loop {
        rtfm::wfi();
    }
}

Compilation fails with

error: requires `start` lang_item

I'm new to Rust (in fact I was hoping to learn the language with this project) and have no idea where the error might be located. Is it just that the app! macro is broken or am I missing something?

arkap
  • 27
  • 8
  • 1
    I'm thoroughly unfamiliar with what you're trying to do, but in the linked example the first line of code starts with `#![feature(proc_macro)] // <- IMPORTANT! Feature gate for procedural macros`, but you're missing it. Could that be it? – orlp Sep 20 '18 at 17:00
  • A good tutorial is https://os.phil-opp.com/freestanding-rust-binary/ – hellow Sep 20 '18 at 17:05
  • @orlp No that's just some remnant from before procedural macros became stable. I suppose all these examples being a bit dated is part of the problem. – arkap Sep 20 '18 at 17:38
  • @hellow thank you. I'm pretty sure now that the `app!` macro is broken - at least for current nightly toolchains - as it should provide the program's entry point. – arkap Sep 21 '18 at 08:09
  • With this question you are basically on the wrong track, IMHO you need `#[no_main]`, and this error won't occur. You need a vector table with a reset vector, which points to a reset handler function. This function needs to set up global variables (`bss` and `data` sections) and then call `main`. The examples you copied together hide part of this behind some macro magic, and part of it is in the `cortex-m*` crates. – starblue Sep 21 '18 at 09:17
  • I ran into different problems combining `#[no_main]` with RTFM (see https://stackoverflow.com/a/52427009/3749401). And the way I understand it RTFM and `app!` should take care of initialization. I suppose I'll have to wait for an update to RTFM if I want to use the macro. – arkap Sep 21 '18 at 12:56

1 Answers1

1

I've found a workaround in RTFM's issues on GitHub that allows to compile the code above:

  1. import cortex-m-rt and its entry macro

    #[macro_use(entry)]
    extern crate cortex_m_rt as rt;
    
  2. add #![no_main] to the head of the source

  3. wrap the main function using the entry macro:

    #[entry]
    fn entry_wrap() -> ! {
        main();
        loop {}
    }
    

I haven't tested this yet but it compiles without problems.

arkap
  • 27
  • 8
  • I tell you that long ago: https://stackoverflow.com/questions/52425667/undefined-reference-to-main-when-using-real-time-for-the-masses/52427009#comment91798519_52425667 & https://stackoverflow.com/questions/52425667/undefined-reference-to-main-when-using-real-time-for-the-masses/52427009#comment91800626_52425667 – Stargateur Oct 10 '18 at 13:23
  • You failed to get your point across. I'm a beginner at Rust and your passive-aggressive question didn't help me at atll. – arkap Oct 10 '18 at 13:27
  • Well, sorry about that, didn't want to be agressif just make you think. – Stargateur Oct 10 '18 at 13:29
  • Alright, no hard feelings. I suppose a short explanation or a link to a resource explaining the interplay of `entry`, `#[no_main]` and how to use all that to solve my problem would have been more helpful. – arkap Oct 10 '18 at 13:32