From 0291bf41d28533c4731991dad25a05c712cede78 Mon Sep 17 00:00:00 2001 From: Levi Pearson Date: Tue, 7 Jul 2020 23:46:22 -0600 Subject: [PATCH] Add cargo embed support, including rtt printing & panic logs --- Cargo.toml | 1 + Embed.toml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 20 +++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 Embed.toml diff --git a/Cargo.toml b/Cargo.toml index a551fd4..a6d3511 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ panic-halt = "0.2.0" #panic-persist = "0.2.1" embedded-hal = "0.2.3" nb = "0.1.2" +rtt-target = { version = "0.2.0", features = ["cortex-m"] } [dependencies.stm32f1] version = "0.10.0" diff --git a/Embed.toml b/Embed.toml new file mode 100644 index 0000000..8a45ee4 --- /dev/null +++ b/Embed.toml @@ -0,0 +1,50 @@ +[default.probe] +# USB vendor ID +# usb_vid = "1337" +# USB product ID +# usb_pid = "1337" +# Serial number +# serial = "12345678" +# The protocol to be used for communicating with the target. +protocol = "Swd" +# The speed in kHz of the data link to the target. +# speed = 1337 + +[default.flashing] +# Whether or not the target should be flashed. +enabled = true +# Whether or not the target should be halted after flashing. +halt_afterwards = false +# Whether or not bytes erased but not rewritten with data from the ELF +# should be restored with their contents before erasing. +restore_unwritten_bytes = false +# The path where an SVG of the assembled flash layout should be written to. +# flash_layout_output_path = "out.svg" + +[default.general] +# The chip name of the chip to be debugged. +chip = "stm32f103C8" +# A list of chip descriptions to be loaded during runtime. +chip_descriptions = [] +# The default log level to be used. +log_level = "Warn" + +[default.rtt] +# Whether or not an RTTUI should be opened after flashing. +# This is exclusive and cannot be used with GDB at the moment. +enabled = true +# A list of channel associations to be displayed. If left empty, all channels are displayed. +channels = [ + # { up = 0, down = 0, name = "name" } +] +# The duration in ms for which the logger should retry to attach to RTT. +timeout = 3000 +# Whether timestamps in the RTTUI are enabled +show_timestamps = true + +[default.gdb] +# Whether or not a GDB server should be opened after flashing. +# This is exclusive and cannot be used with RTT at the moment. +enabled = false +# The connection string in host:port format wher the GDB server will open a socket. +# gdb_connection_string diff --git a/src/main.rs b/src/main.rs index 7b224e7..504351c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,9 @@ #![no_std] #![no_main] -use panic_halt as _; +//use panic_halt as _; +use core::panic::PanicInfo; +use rtt_target::{rprintln, rtt_init_print}; use nb::block; @@ -23,6 +25,8 @@ use embedded_hal::digital::v2::OutputPin; #[entry] fn main() -> ! { + // Init buffers for debug printing + rtt_init_print!(); // Get access to the core peripherals from the cortex-m crate let cp = cortex_m::Peripherals::take().unwrap(); // Get access to the device specific peripherals from the peripheral access crate @@ -46,11 +50,25 @@ fn main() -> ! { // Configure the syst timer to trigger an update every second let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz()); + rprintln!("Hello, Rust!"); // Wait for the timer to trigger an update and change the state of the LED + let mut i = 0; loop { block!(timer.wait()).unwrap(); led.set_high().unwrap(); block!(timer.wait()).unwrap(); led.set_low().unwrap(); + i += 1; + rprintln!("Hello again; I have blinked {} times.", i); + if i == 10 { + panic!("Yow, 10 times is enough!"); + } } } + +#[inline(never)] +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + rprintln!("{}", info); + loop {} // You might need a compiler fence in here. +}