Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use probe-rs as probe-run is deprecated #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "probe-run --chip STM32F446RETx" # Use with probe-run (see https://github.com/knurling-rs/probe-run)
runner = "probe-rs run --chip STM32F446RETx" # Use with probe-rs (see https://github.com/probe-rs/probe-rs)
# runner = "arm-none-eabi-gdb -q -x openocd.gdb" # Use with GDB / OpenOCD. Note: you may need to use gdb-multiarch instead depending on your platform

rustflags = [
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ categories = ["embedded", "hardware-support", "no-std"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cortex-m = "0.7.5"
cortex-m = { version = "0.7.5", features = ["critical-section-single-core"] }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this feature needed for? I initially had a build error that I think is due to this feature being added in a later version of cortex-m.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before adding that I got errors that _critical_section_1_0_release and _critical_section_1_0_acquire were undefined.

wink@3900x 24-01-25T17:29:44.278Z:~/prgs/rust/forks/nucleo-f446re (Use-probe-rs)
$ cargo run --example blinky
   Compiling cortex-m v0.7.7
   Compiling critical-section v1.1.2
   Compiling rtt-target v0.4.0
   Compiling stm32f4 v0.14.0
   Compiling panic-probe v0.3.1
   Compiling nucleo-f446re v0.1.0 (/home/wink/prgs/rust/forks/nucleo-f446re)
   Compiling stm32f4xx-hal v0.13.2
error: linking with `rust-lld` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/wink/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:

...

-f446re/target/thumbv7em-none-eabi/debug/examples/blinky-246071663e38f089" "--gc-sections" "--nmagic" "-Tlink.x"
  = note: rust-lld: error: undefined symbol: _critical_section_1_0_acquire
          >>> referenced by lib.rs:183 (/home/wink/.cargo/registry/src/index.crates.io-6f17d22bba15001f/critical-section-1.1.2/src/lib.rs:183)
          >>>               rtt_target-50579e5237c22b68.rtt_target.d2ed4632eeeaf5a9-cgu.0.rcgu.o:(critical_section::with::h4960bdd999319092) in archive /home/wink/prgs/rust/forks/nucleo-f446re/target/thumbv7em-none-eabi/debug/deps/librtt_target-50579e5237c22b68.rlib
          
          rust-lld: error: undefined symbol: _critical_section_1_0_release
          >>> referenced by lib.rs:200 (/home/wink/.cargo/registry/src/index.crates.io-6f17d22bba15001f/critical-section-1.1.2/src/lib.rs:200)
          >>>               rtt_target-50579e5237c22b68.rtt_target.d2ed4632eeeaf5a9-cgu.0.rcgu.o:(core::ptr::drop_in_place$LT$critical_section..with..Guard$GT$::h5caa149425e17113) in archive /home/wink/prgs/rust/forks/nucleo-f446re/target/thumbv7em-none-eabi/debug/deps/librtt_target-50579e5237c22b68.rlib
          

error: could not compile `nucleo-f446re` (example "blinky") due to previous error
wink@3900x 24-01-25T17:30:37.535Z:~/prgs/rust/forks/nucleo-f446re (Use-probe-rs)

I did a search for undefined _critical_section_1_0_release and found this so I added critical-section-single-core. Actually, I didn't find that ferrous post originally, but it pedantically explains why so used that one here :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I see what's going on now. I had an older lockfile initially, which only use 0.7.5, which does fail to build with the feature (because it was added in 0.7.6). But, newer versions of the dependencies use 0.7.7 which does have the feature, and requires it in this situation (as your link to the Ferrous Systems blog explains). At least it makes sense now.

embedded-hal = "0.2.7"
switch-hal = "0.4.0"
stm32f4xx-hal = { version = "0.13.2", features = ["stm32f446"]}
unwrap-infallible = "0.1.5"
rtt-target = "0.5.0"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed for cargo embed for the example you added? If so, I think it's best to place it in the dev-dependencies as someone using the crate as a library has no need to add this as a dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm going to remove the new examples so this will be removed.


[dev-dependencies]
cortex-m-rt = "0.7.1"
Expand Down
7 changes: 7 additions & 0 deletions Embed.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[default.general]
chip = "STM32F446RETx"

# By default use denable rtt if we use `cargo embed`
[default.rtt]
enabled = true

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ There are two main ways to make use of this BSP:
Many examples are provided to illustrate both ways of using the BSP, which can be found in the `examples` directory. Use a USB cable to connect the Nucleo board's debugger to the host computer, and then run an example with cargo:
> `cargo run --example blinky`

Here, `cargo run` implicitly makes use of [probe-run](https://github.com/knurling-rs/probe-run) to flash, execute, and handle panic and backtrace info. If you prefer GDB and OpenOCD, you can change the behavior of `cargo run` by editing `.cargo/config.toml` (basic scripts for GDB and OpenOCD are provided).
Here, `cargo run` implicitly makes use of [probe-rs](https://github.com/probe-rs/probe-rs) to flash, execute, and handle panic and backtrace info. If you prefer GDB and OpenOCD, you can change the behavior of `cargo run` by editing `.cargo/config.toml` (basic scripts for GDB and OpenOCD are provided).

# Reference material

Expand Down
14 changes: 14 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Examples

If you've installed `probe-rs` with `cargo install probe-rs --features cli`
just use `cargo run --example <filename>` to build and run any of the
examples.

For `channels-3d-1u` you can use also use
`cargo embed --example channels-3d-1u` which provides a nicer interface,
a terminal with 3 tabs and you can switch between the tabe using
F1, F2 and F3.

In all cases Ctrl-C terminates the program.

**TODO:** Document serial_*, inparticular how to setup the hardware!
91 changes: 91 additions & 0 deletions examples/channels-3u-1d.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#![deny(unsafe_code)]
#![no_std]
#![no_main]

use cortex_m_rt::entry;
use embedded_hal::blocking::delay::DelayMs;
use nucleo_f446re::{led::LedDigital, Nucleo};
use panic_probe as _;


use core::fmt::Write;
use rtt_target::{rtt_init, ChannelMode::BlockIfFull};

#[entry]
fn main() -> ! {
let mut nucleo = Nucleo::<LedDigital>::init().unwrap();

let channels = rtt_init! {
up: {
0: {
size: 512,
mode: BlockIfFull,
name: "Up zero"
}
1: {
size: 128,
name: "Up one"
}
2: {
size: 128,
name: "Up two"
}
}
down: {
0: {
size: 512,
mode: BlockIfFull,
name: "Down zero"
}
}
};

let mut output2 = channels.up.1;
writeln!(
output2,
"Hi! I will turn anything you type on channel 0 into upper case."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this example but couldn't get it to work like I thought. On channel 0 I am able to get an uppercase'd echo and periodic logs on channel 2, but channel 1 (which has this message) doesn't do anything. I probably need to read up more on RTT to get what is going on here.

It does feel similar to the comment I left on the other example, that I'm not sure this adds much to this nucleo crate (rather an example of RTT usage). But, it is a more involved example so I'm more inclined to include it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing for now

)
.ok();

let mut output = channels.up.0;
let mut log = channels.up.2;
let mut input = channels.down.0;
let mut buf = [0u8; 512];
let mut count: u8 = 0;

loop {
writeln!(log, "Top of loop, invoking input.read").ok();
let bytes = loop {
let bytes_read = input.read(&mut buf[..]);

if bytes_read > 0 {
break bytes_read;
}

writeln!(log, "No bytes read, sleeping").ok();
nucleo.delay.delay_ms(1000_u32);
};

writeln!(log, "read {} bytes", bytes).ok();
if bytes > 0 {
for c in buf.iter_mut() {
c.make_ascii_uppercase();
}

let mut p = 0;
while p < bytes {
p += output.write(&buf[p..bytes]);
}
}

writeln!(log, "Messsge no. {}/{}", count, bytes).ok();
nucleo.user_led.toggle();

count += 1;

nucleo.delay.delay_ms(10_u32);
//for _ in 0..1_000_000 {
// cortex_m::asm::nop();
//}
}
}
23 changes: 23 additions & 0 deletions examples/rprintln.rs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't see much value in this example being included in this repository. It seems more like a demonstration of rtt features as otherwise the behavior is identical to the blinky example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that was important feature you can when using probe-rs so I added it. But to simplify this change I'm removing them.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![deny(unsafe_code)]
#![no_std]
#![no_main]

use cortex_m_rt::entry;
use embedded_hal::blocking::delay::DelayMs;
use nucleo_f446re::{led::LedDigital, Nucleo};
use panic_probe as _;
use rtt_target;

#[entry]
fn main() -> ! {
let mut nucleo = Nucleo::<LedDigital>::init().unwrap();
// Can also use the LED default generic argument with <Nucleo>::init().unwrap();

rtt_target::rtt_init_print!();
loop {
rtt_target::rprintln!("rprintln!(Hello, world!)");
rtt_target::debug_rprintln!("debug_rprintln!(Hello, world!)");
nucleo.user_led.toggle();
nucleo.delay.delay_ms(500_u32);
}
}
Loading