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:

#![deny(unsafe_code)]
#![no_main]
#![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();
    }
}

I can get it to compile but linking with rust-lld fails with

= note: rust-lld: error: undefined symbol: main

I am confused because when I run cargo expand I do get a main function:

fn main() {
    #![allow(path_statements)]
    let init: fn(init::Peripherals) = init;
    rtfm::atomic(unsafe { &mut rtfm::Threshold::new(0) },
                 |_t|
                     unsafe {
                         let _late_resources =
                             init(init::Peripherals{core:
                                                        ::stm32f407::CorePeripherals::steal(),
                                                    device:
                                                        ::stm32f407::Peripherals::steal(),});
                     });
    let idle: fn() -> ! = idle;
    idle();
}

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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
arkap
  • 27
  • 8
  • But you put `#![no_main]` in your code – Stargateur Sep 20 '18 at 13:46
  • I just copied that from the example. If I remove the `#![no_main]` the compiler complains that the `start` `lang_item` is missing. – arkap Sep 20 '18 at 14:21
  • What exemple, one link you provided don't use no_main and the other use `use aux5::entry; #[entry]` – Stargateur Sep 20 '18 at 14:35
  • [This](https://github.com/rust-embedded/discovery/blob/master/src/05-led-roulette/src/main.rs) main has it. Anyway, like I said, if I remove it, I get the missing `start` `lang_item` error and the way I understood it, `app!` should expand to a working main. I'm sorry if this is all obvious stuff. To me all this macro magic is pretty confusing right now. – arkap Sep 20 '18 at 15:27
  • But like I said, this main use a macro [`entry`](https://rust-embedded.github.io/cortex-m-rt/0.6.1/cortex_m_rt_macros/fn.entry.html) you think is here for nothing ? – Stargateur Sep 20 '18 at 15:31
  • I thought `app!` would take care of it. After all the [example](http://blog.japaric.io/rtfm-v2/#hello-world) I referenced doesn't seem to need it either. – arkap Sep 20 '18 at 15:37
  • But this one don't use no_main... you can't mix example take only few line and expect thing work – Stargateur Sep 20 '18 at 15:38
  • I know. But since I don't get what isn't working, I asked the question here. So I guess you're telling me that my problem really is that missing `start` `lang_item`. – arkap Sep 20 '18 at 15:43
  • I never said that, i already answered your question, I don't know how to use your crate, I only know the general answer. – Stargateur Sep 20 '18 at 15:50
  • Alright, thanks. I'll probably delete this question then and ask about the `lang_item`. – arkap Sep 20 '18 at 15:55
  • You should not delete question, just create a new one but I don't think you should, just [edit] your actual question to improve it. – Stargateur Sep 20 '18 at 16:03

1 Answers1

0

As you ask the compiler to not insert main, there is no main symbol in your program.

Rust uses symbol mangling so your main function doesn't have a symbol named main.

The answer depends on your contextm but generally this should do it:

#[no_mangle] // ensure that this symbol is called `main` in the output
pub extern fn main(argc: i32, argv: *const *const u8) -> i32 {

}

All additional information can be found here

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Stargateur
  • 24,473
  • 8
  • 65
  • 91