0

I'm brand new to Rust so forgive me if I don't know the lingo/tools yet. I'm trying to get an STM32F4 to blink an LED, and I think the code is right, but when I build it xargo doesn't generate a binary or any sort of error. My code is:

#![feature(proc_macro)] // <- IMPORTANT! Feature gate for procedural macros
#![no_std]

extern crate cortex_m;
extern crate cortex_m_rtfm as rtfm;
extern crate stm32f40x;

use cortex_m::peripheral::SystClkSource;
use rtfm::{app, Threshold};

app! {
    device: stm32f40x,
    resources: {},
    tasks: {
        SYS_TICK: {
            path: toggle,
            resources: [GPIOC],
        },
    },
}

fn init(p: init::Peripherals, _r: init::Resources) {
    // TODO: initialize the GPIO
    p.SYST.set_clock_source(SystClkSource::Core);
    p.SYST.set_reload(8_000_000); // 1s?
    p.SYST.enable_interrupt();
    p.SYST.enable_counter();
}

fn idle() -> ! {
    loop {
        rtfm::wfi();
    }
}

fn toggle(_t: &mut Threshold, r: SYS_TICK::Resources) {
    **r.GPIOC.odr.modify(|r, w| w.odr13().bit(!r.odr13().bit()));
}

The Cargo.toml file is

[package]
name = "sign_firmware"
version = "0.0.1"
authors = ["teryret"]
categories = ["embedded", "no-std"]
description = "With any luck this will cause an STM32F4 based board to drive a few thousand LEDs."
keywords = ["arm", "cortex-m"]
license = "MIT OR Apache-2.0"
repository = "TODO"
[dependencies]
cortex-m = "*"
cortex-m-rt = "*"
cortex-m-rtfm = "*"
stm32f40x = "*"

[profile]
[profile.release]
debug = true
lto = true

[target.arm-none-linux-gnueabihf]
ar = "arm-linux-gnueabihf-gcc-ar"
linker = "arm-linux-gnueabihf-gcc"

And when I run xargo build --release in the docker image I set up to contain all the dependencies and whatnot it says:

teryret@bee ~/d/rtfm> ./build 
   Compiling core v0.0.0 (file:///usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore)
    Finished release [optimized + debuginfo] target(s) in 12.82 secs
    Updating git repository `https://github.com/rust-lang-nursery/compiler-builtins`
   Compiling compiler_builtins v0.1.0 (https://github.com/rust-lang-nursery/compiler-builtins#f5532b22)
    Finished release [optimized + debuginfo] target(s) in 2.12 secs
warning: unused manifest key: target.arm-none-linux-gnueabihf.ar
warning: unused manifest key: target.arm-none-linux-gnueabihf.linker
 Downloading cortex-m-rtfm v0.2.1
 Downloading stm32f40x v0.5.0
 Downloading cortex-m-rt v0.3.6
 Downloading cortex-m v0.3.1
 Downloading rtfm-core v0.1.0
 Downloading static-ref v0.2.1
 Downloading cortex-m-rtfm-macros v0.2.0
 Downloading error-chain v0.10.0
 Downloading quote v0.3.15
 Downloading rtfm-syntax v0.1.0
 Downloading syn v0.11.11
 Downloading unicode-xid v0.0.4
 Downloading synom v0.11.3
 Downloading volatile-register v0.2.0
 Downloading bare-metal v0.1.1
 Downloading aligned v0.1.1
 Downloading vcell v0.1.0
 Downloading r0 v0.2.2
   Compiling r0 v0.2.2
   Compiling libc v0.2.33
   Compiling vcell v0.1.0
   Compiling quote v0.3.15
   Compiling cc v1.0.3
   Compiling sign_firmware v0.0.1 (file:///usr/src/myapp)
   Compiling cortex-m-rt v0.3.6
   Compiling cortex-m-rtfm v0.2.1
   Compiling cfg-if v0.1.2
   Compiling rustc-demangle v0.1.5
   Compiling bare-metal v0.1.1
   Compiling unicode-xid v0.0.4
   Compiling aligned v0.1.1
   Compiling cortex-m v0.3.1
   Compiling static-ref v0.2.1
   Compiling volatile-register v0.2.0
   Compiling synom v0.11.3
   Compiling rtfm-core v0.1.0
   Compiling syn v0.11.11
   Compiling stm32f40x v0.5.0
   Compiling backtrace-sys v0.1.16
   Compiling backtrace v0.3.4
   Compiling error-chain v0.10.0
   Compiling rtfm-syntax v0.1.0
   Compiling cortex-m-rtfm-macros v0.2.0
    Finished release [optimized + debuginfo] target(s) in 47.2 secs

While lots of stuff is generated in target/ none of it is a binary I can flash onto the board. Any idea why? I mean, it's got to be something simple, but I don't have the experience to know where to look.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
teryret
  • 240
  • 2
  • 11
  • There's nothing under `target/release` that has the name containing "myproject"? Something like `tree target/release | grep myproject`? – Shepmaster Nov 18 '17 at 15:48
  • Exactly (nothing there). Since I posted the question I discovered the -v flag and from that found that one of the files that came with the template I'm using was the thing that had actually been compiling. That file was simply "pub mod examples;". Do I need to add a pub mod somewhere? – teryret Nov 18 '17 at 15:51
  • 1
    What file have you placed your code in? I'd expect `src/main.rs`. – Shepmaster Nov 18 '17 at 15:58
  • X-| Sure enough, that was the problem. I'd been calling it src/hello.rs on account of it being called that in the guide I'm starting from (http://blog.japaric.io/quickstart/). Thanks for your help (I'd be glad to mark that as the answer if you make it one)! – teryret Nov 18 '17 at 16:00
  • not that it's **examples** /hello.rs, not **src** /hello.rs. – Shepmaster Nov 18 '17 at 16:13

1 Answers1

2

In the tutorial you were following, all of the examples are in an "examples" directory. You can build these using the --example argument, as shown in the tutorial:

xargo build --example hello

If this is your primary program, however, you will want to put your code in "src/main.rs", allowing just:

xargo build

If you have multiple executables, you can also specify that.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366