[][src]Attribute Macro cortex_m_rt_macros::entry

#[entry]

Attribute to declare the entry point of the program

IMPORTANT: This attribute must appear exactly once in the dependency graph. Also, if you are using Rust 1.30 the attribute must be used on a reachable item (i.e. there must be no private modules between the item and the root of the crate); if the item is in the root of the crate you'll be fine. This reachability restriction doesn't apply to Rust 1.31 and newer releases.

The specified function will be called by the reset handler after RAM has been initialized. In the case of the thumbv7em-none-eabihf target the FPU will also be enabled before the function is called.

The type of the specified function must be [unsafe] fn() -> ! (never ending function)

Properties

The entry point will be called by the reset handler. The program can't reference to the entry point, much less invoke it.

static mut variables declared within the entry point are safe to access. The compiler can't prove this is safe so the attribute will help by making a transformation to the source code: for this reason a variable like static mut FOO: u32 will become let FOO: &'static mut u32;. Note that &'static mut references have move semantics.

Examples

#[entry]
fn main() -> ! {
    loop {
        /* .. */
    }
}
#[entry]
fn main() -> ! {
    static mut FOO: u32 = 0;

    let foo: &'static mut u32 = FOO;
    assert_eq!(*foo, 0);
    *foo = 1;
    assert_eq!(*foo, 1);

    loop {
        /* .. */
    }
}