Cannot find attribute macro 'entry' in this scope

Hi all

I've had some rust embedded code for the stm32f3discovery board working for a while, but in the last day or two, I've run into a problem where I'm seeing the above error:

error: cannot find attribute macro entry in this scope
--> src/
13 | #[entry]
| ^^^^^

I have tried everything I can think of, but even starting again is consistently leading me into the same error. I think I must have broken something, but I can't figure out what. I have:

extern crate cortex_m_rt;
use cortex_m_rt::entry;


and I've tried other permutations. Any hints would be great, otherwise I guess I'll be cleaning everything out and starting again...

Can you maybe a more detailed version of your code including your Cargo.toml?

It sounds like you haven't imported the #[entry] attribute.

You can either add #[macro_use] above extern crate cortex_m_rt to import the #[entry] attribute into the global scope for your entire crate, or you could refer to it using the fully qualified name, #[cortex_m_rt::entry].

But shouldn't it be imported bu use cortex_m_rt::entry; statement?


Sorry, I didn't see the use statement, if you're already pulling in cortex_m_rt::entry it should be fine to write #[entry].

There may be something else going on that we can't see. Is this code in a publicly accessible place? If we can look at the original file it may be easier to see what's going on.

Also, would you be able to surround the code samples in your original post with triple backticks to make it easier to see what is code and what is prose? (see the Multi-line Blocks of Code section from here for more info on formatting)

It looks like you are not depending on cortex-m-rt = "0.6.*" (prior to it entry was a declarative / macro_rules! macro rather than a (procedural) attribute macro attribute, hence the use ...entry; line working and yet there not being an attribute macro in scope).

To ensure you do, make sure your Cargo.toml contains something like:

cortex-m-rt = "0.6.12"
1 Like

Hi all

This has been answered, see Yandros above, but I'm including the code that broke and the Cargo.toml, just for completeness.

Thanks for the help and suggestions. I've essentially moved all the code in the file into a new project and got it working bit-by-bit, but I'd still like to understand what I did wrong. The minimum set of source-code from the file that won't compile follows. It is ugly, but that's what is not compiling.


extern crate stm32f3;
extern crate panic_semihosting;
extern crate cortex_m_rt;
extern crate cortex_m_semihosting;

use cortex_m_semihosting::hprintln;
use cortex_m_rt::entry;

// I reduced the source code to just this block:
fn main() -> ! {
    hprintln!("Hello, world!").unwrap();

    // exit QEMU
    // NOTE do not run this on hardware; it can corrupt OpenOCD state
    // debug::exit(debug::EXIT_SUCCESS);

    loop {}

Here's the error:

error: cannot find attribute macro `entry` in this scope
  --> src/
14 | #[entry]
   |   ^^^^^

Just for completeness - here's the Cargo.toml:

name = "dv3"
version = "0.1.0"
authors = ["Jorge Aparicio <>"]
description = "A template for building applications for ARM Cortex-M microcontrollers"
documentation = ""
keywords = ["arm", "cortex-m", "template"]
categories = ["embedded", "no-std"]
license = "MIT OR Apache-2.0"

lto = true
codegen-units = 1
debug = true

version = "0.2.2"
default-features = false

version = "0.5.6"

version = "0.5.3"

version = "0.3.1"

version = "0.4.1"    # Doesn't work in 0.5.1 due to some error that isn't in earlier versions

version = "0.2.0"

version = "0.5.1"

path = "../l3gd20"

version = "0.2.0"

version = "0.2.3"

version = "0.5.2"

version = "0.1.4"
features = ["cortexm"]
optional = false

version = "0.2.6"

version = "0.8.0"
features = ["stm32f303", "rt"]

version = "0.5.0"

#version = "0.4.0"
version = "0.4.0"
features = ["stm32f303xc", "stm32-usbd"]#, "rt"]#, "stm32f303xc", "stm32-usbd", "rt"]

version = "0.6.1"

madgwick = "0.1.1"
nb = "0.1.2"
aligned = "0.3.1"
usb-device = "0.2.4"
usbd-serial = "0.1"

Thanks! This fixed the problem. I'm still not sure how I got it to suddenly stop working, but that's an issue for another day...

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.