Why does cargo build hang indefinitely when doing the embedded discovery tutorial

Viewed 584

I am currently trying to go through the 11th chapter of the Rust Embedded Discovery Book. The repository for this chapter can be found here.

The compiler hangs on the following code:

#![deny(unsafe_code)]
#![no_main]
#![no_std]

#[allow(unused_imports)]
use aux11::{entry, iprint, iprintln};

#[entry]
fn main() -> ! {
    let (usart1, _mono_timer, _itm) = aux11::init();

    for char in b"The quick brown fox jumps over the lazy dog.".iter() {
        // Send a single character
        usart1.tdr.write(|w| w.tdr().bits(u16::from(*char)));
    }

    loop {}
}

with the other change on this directory is bumping the version of cortex-m to 0.5.8.

EDIT: The command I run is cargo build --verbose, so whats being run is the compiler itself and not the program. This is the full command and its output:

C:/Users/User/.cargo/bin/cargo.exe build --color=always --message-format=json-diagnostic-rendered-ansi --target thumbv7em-none-eabihf --verbose
       Fresh semver-parser v0.7.0
       Fresh nb v1.0.0
       Fresh unicode-xid v0.2.1
       Fresh vcell v0.1.3
       Fresh void v1.0.2
       Fresh aligned v0.2.0
       Fresh r0 v0.2.2
       Fresh bitfield v0.13.2
       Fresh byteorder v1.4.2
       Fresh semver v0.9.0
       Fresh rustc_version v0.2.3
       Fresh nb v0.1.3
       Fresh volatile-register v0.2.0
       Fresh hash32 v0.1.1
       Fresh proc-macro2 v1.0.24
       Fresh embedded-hal v0.2.4
       Fresh typenum v1.12.0
       Fresh quote v1.0.8
       Fresh generic-array v0.11.1
       Fresh bare-metal v0.2.5
       Fresh syn v1.0.58
       Fresh cast v0.2.3
       Fresh l3gd20 v0.2.0
       Fresh heapless v0.3.7
       Fresh cortex-m-rt-macros v0.1.8
       Fresh cortex-m v0.5.8
       Fresh cortex-m v0.7.2
       Fresh lsm303dlhc v0.2.0
       Fresh cortex-m-rt v0.6.13
       Fresh panic-itm v0.4.2
       Fresh stm32f30x v0.7.1
       Fresh stm32f30x-hal v0.2.0
       Fresh f3 v0.6.1
       Fresh aux11 v0.1.0 (C:\repos\discovery\src\11-usart\auxiliary)
   Compiling usart v0.1.0 (C:\repos\discovery\src\11-usart)
     Running `C:\Users\User\.cargo\bin\rustc.exe --crate-name usart --edition=2018 src\11-usart\src\main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=b319e2d1d8d11eef -C extra-filename=-b319e2d1d8d11eef --out-dir C:\repos\discovery\target\thumbv7em-none-eabihf\debug\deps --target thumbv7em-none-eabihf -C incremental=C:\repos\discovery\target\thumbv7em-none-eabihf\debug\incremental -L dependency=C:\repos\discovery\target\thumbv7em-none-eabihf\debug\deps -L dependency=C:\repos\discovery\target\debug\deps --extern aux11=C:\repos\discovery\target\thumbv7em-none-eabihf\debug\deps\libaux11-2d2dac5f4230a287.rlib --extern heapless=C:\repos\discovery\target\thumbv7em-none-eabihf\debug\deps\libheapless-61d8b3c4b16d4842.rlib -C link-arg=-Tlink.x -L C:\repos\discovery\target\thumbv7em-none-eabihf\debug\build\cortex-m-7f60ed6e068039ff\out -L C:\repos\discovery\target\thumbv7em-none-eabihf\debug\build\cortex-m-rt-17f16ed1a0c77cc5\out -L C:\repos\discovery\target\thumbv7em-none-eabihf\debug\build\f3-1a08fdc1cbf64e81\out -L C:\repos\discovery\target\thumbv7em-none-eabihf\debug\build\stm32f30x-50ac612f864f84d1\out -L C:\repos\discovery\target\thumbv7em-none-eabihf\debug\build\cortex-m-2bd89fb5390eaa29\out`

It has run for over 10 hours now, so just the long compile time of Rust shouldn't be a factor.

These are my toolchain's versions:

  • rustc 1.51.0 (2fd73fabe 2021-03-23)
  • rustup 1.23.1 (3df2264a9 2020-11-30)
  • cargo 1.51.0 (43b129a20 2021-03-16)

EDIT: Here is my auxiliary/Cargo.toml, which changed from source only the cortex-m version (due to other errors I get on 0.5.6):

[package]
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"
name = "aux11"
version = "0.1.0"

[dependencies]
cortex-m = "=0.5.8" # 0.5.11 introduces a breaking change.  Use 0.5.6, since we know it works for this example
cortex-m-rt = "0.6.3"
panic-itm = "0.4.0"

[dependencies.f3]
features = ["rt"]
version = "0.6.1"

[features]
adapter = []

Here are Cargo.toml and auxiliary/src/lib.rs, which are unchanged from source:

Cargo.toml:

[package]
authors = ["Jorge Aparicio <jorge@japaric.io>"]
edition = "2018"
name = "usart"
version = "0.1.0"

[dependencies.aux11]
path = "auxiliary"
# enable this if you are going to use an external serial adapter
# features = ["adapter"]

[dependencies.heapless]
default-features = false
version = "0.3.7"

auxiliary/src/lib.rs:

//! Initialization code

#![no_std]

#[allow(unused_extern_crates)] // NOTE(allow) bug rust-lang/rust53964
extern crate panic_itm; // panic handler

pub use cortex_m::{asm::bkpt, iprint, iprintln, peripheral::ITM};
pub use cortex_m_rt::entry;
pub use f3::hal::{prelude, serial::Serial, stm32f30x::usart1, time::MonoTimer};

use f3::hal::{
    prelude::*,
    stm32f30x::{self, USART1},
};

pub fn init() -> (&'static mut usart1::RegisterBlock, MonoTimer, ITM) {
    let cp = cortex_m::Peripherals::take().unwrap();
    let dp = stm32f30x::Peripherals::take().unwrap();

    let mut flash = dp.FLASH.constrain();
    let mut rcc = dp.RCC.constrain();

    let clocks = rcc.cfgr.freeze(&mut flash.acr);

    let (tx, rx) = match () {
        #[cfg(feature = "adapter")]
        () => {
            let mut gpioa = dp.GPIOA.split(&mut rcc.ahb);

            let tx = gpioa.pa9.into_af7(&mut gpioa.moder, &mut gpioa.afrh);
            let rx = gpioa.pa10.into_af7(&mut gpioa.moder, &mut gpioa.afrh);

            (tx, rx)
        }
        #[cfg(not(feature = "adapter"))]
        () => {
            let mut gpioc = dp.GPIOC.split(&mut rcc.ahb);

            let tx = gpioc.pc4.into_af7(&mut gpioc.moder, &mut gpioc.afrl);
            let rx = gpioc.pc5.into_af7(&mut gpioc.moder, &mut gpioc.afrl);

            (tx, rx)
        }
    };

    Serial::usart1(dp.USART1, (tx, rx), 115_200.bps(), clocks, &mut rcc.apb2);
    // If you are having trouble sending/receiving data to/from the
    // HC-05 bluetooth module, try this configuration instead:
    // Serial::usart1(dp.USART1, (tx, rx), 9600.bps(), clocks, &mut rcc.apb2);

    unsafe {
        (
            &mut *(USART1::ptr() as *mut _),
            MonoTimer::new(cp.DWT, clocks),
            cp.ITM,
        )
    }
}

I found no clues in the output, so any suggestions are very welcome!

0 Answers
Related