Add cargo embed support, including rtt printing & panic logs

master
Levi Pearson 2020-07-07 23:46:22 -06:00
parent 52da592ec1
commit 0291bf41d2
3 changed files with 70 additions and 1 deletions

View File

@ -19,6 +19,7 @@ panic-halt = "0.2.0"
#panic-persist = "0.2.1" #panic-persist = "0.2.1"
embedded-hal = "0.2.3" embedded-hal = "0.2.3"
nb = "0.1.2" nb = "0.1.2"
rtt-target = { version = "0.2.0", features = ["cortex-m"] }
[dependencies.stm32f1] [dependencies.stm32f1]
version = "0.10.0" version = "0.10.0"

50
Embed.toml Normal file
View File

@ -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

View File

@ -9,7 +9,9 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use panic_halt as _; //use panic_halt as _;
use core::panic::PanicInfo;
use rtt_target::{rprintln, rtt_init_print};
use nb::block; use nb::block;
@ -23,6 +25,8 @@ use embedded_hal::digital::v2::OutputPin;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
// Init buffers for debug printing
rtt_init_print!();
// Get access to the core peripherals from the cortex-m crate // Get access to the core peripherals from the cortex-m crate
let cp = cortex_m::Peripherals::take().unwrap(); let cp = cortex_m::Peripherals::take().unwrap();
// Get access to the device specific peripherals from the peripheral access crate // 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 // Configure the syst timer to trigger an update every second
let mut timer = Timer::syst(cp.SYST, &clocks).start_count_down(1.hz()); 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 // Wait for the timer to trigger an update and change the state of the LED
let mut i = 0;
loop { loop {
block!(timer.wait()).unwrap(); block!(timer.wait()).unwrap();
led.set_high().unwrap(); led.set_high().unwrap();
block!(timer.wait()).unwrap(); block!(timer.wait()).unwrap();
led.set_low().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.
}