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/main.rs:13:3
|
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;
#[entry]
and I've tried other permutations. Any hints would be great, otherwise I guess I'll be cleaning everything out and starting again...
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].
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:
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.
//#![deny(unsafe_code)]
#![no_main]
#![no_std]
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:
#[entry]
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/main.rs:14:3
|
14 | #[entry]
| ^^^^^
Just for completeness - here's the Cargo.toml:
[package]
name = "dv3"
version = "0.1.0"
authors = ["Jorge Aparicio <jorge@japaric.io>"]
description = "A template for building applications for ARM Cortex-M microcontrollers"
documentation = "https://rust-embedded.github.io/cortex-m-quickstart/cortex_m_quickstart"
keywords = ["arm", "cortex-m", "template"]
categories = ["embedded", "no-std"]
license = "MIT OR Apache-2.0"
[profile.release]
lto = true
codegen-units = 1
debug = true
[dependencies.cast]
version = "0.2.2"
default-features = false
[dependencies.cortex-m]
version = "0.5.6"
[dependencies.cortex-m-rt]
version = "0.5.3"
[dependencies.cortex-m-semihosting]
version = "0.3.1"
[dependencies.embedded-graphics]
version = "0.4.1" # Doesn't work in 0.5.1 due to some error that isn't in earlier versions
[dependencies.embedded-hal]
version = "0.2.0"
[dependencies.heapless]
version = "0.5.1"
[dependencies.l3gd20]
path = "../l3gd20"
[dependencies.lsm303dlhc]
version = "0.2.0"
[dependencies.numtoa]
version = "0.2.3"
[dependencies.panic-semihosting]
version = "0.5.2"
[dependencies.shared-bus]
version = "0.1.4"
features = ["cortexm"]
optional = false
[dependencies.ssd1306]
version = "0.2.6"
[dependencies.stm32f3]
version = "0.8.0"
features = ["stm32f303", "rt"]
[dependencies.micromath]
version = "0.5.0"
[dependencies.stm32f3xx-hal]
#version = "0.4.0"
version = "0.4.0"
features = ["stm32f303xc", "stm32-usbd"]#, "rt"]#, "stm32f303xc", "stm32-usbd", "rt"]
[dependencies.f3]
version = "0.6.1"
[dependencies]
madgwick = "0.1.1"
nb = "0.1.2"
aligned = "0.3.1"
usb-device = "0.2.4"
usbd-serial = "0.1"