Attribute Macro cortex_m_rt::pre_init[][src]

#[pre_init]
Expand description

Attribute to mark which function will be called at the beginning of the reset handler.

IMPORTANT: This attribute can appear at most 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 function must have the signature of unsafe fn().

Safety

The function will be called before memory is initialized, as soon as possible after reset. Any access of memory, including any static variables, will result in undefined behavior.

Warning: Due to rvalue static promotion static variables may be accessed whenever taking a reference to a constant. This means that even trivial expressions such as &1 in the #[pre_init] function or any code called by it will cause immediate undefined behavior.

Users are advised to only use the #[pre_init] feature when absolutely necessary as these constraints make safe usage difficult.

Examples

#[pre_init]
unsafe fn before_main() {
    // do something here
}