use semihosting with a feature-flag

This commit is contained in:
Astro 2019-03-14 19:58:41 +01:00
parent 7ce7ff2a6d
commit c1b0e54550
3 changed files with 40 additions and 13 deletions

View File

@ -19,11 +19,12 @@ features = []
default-target = "thumbv7em-none-eabihf" default-target = "thumbv7em-none-eabihf"
[dependencies] [dependencies]
panic-abort = "0.3.1" panic-abort = { version = "0.3.1" }
panic-semihosting = { version = "0.5.1", optional = true }
log = "0.4"
cortex-m = "0.5" cortex-m = "0.5"
cortex-m-rt = { version = "0.6", features = ["device"] } cortex-m-rt = { version = "0.6", features = ["device"] }
cortex-m-semihosting = "0.3" cortex-m-log = { version = "0.4", features = ["log-integration"] }
stm32f4 = { version = "0.6", features = ["rt", "stm32f429"] } stm32f4 = { version = "0.6", features = ["rt", "stm32f429"] }
embedded-hal = "0.2" embedded-hal = "0.2"
stm32f4xx-hal = { git = "https://github.com/stm32-rs/stm32f4xx-hal.git", features = ["rt", "stm32f429"] } stm32f4xx-hal = { git = "https://github.com/stm32-rs/stm32f4xx-hal.git", features = ["rt", "stm32f429"] }
@ -31,6 +32,8 @@ stm32f4xx-hal = { git = "https://github.com/stm32-rs/stm32f4xx-hal.git", feature
stm32-eth = { version = "0.1.0", features = ["smoltcp-phy", "nucleo-f429zi"] } stm32-eth = { version = "0.1.0", features = ["smoltcp-phy", "nucleo-f429zi"] }
smoltcp = { version = "0.5.0", default-features = false, features = ["proto-ipv4", "proto-ipv6", "socket-icmp", "socket-udp", "socket-tcp", "log", "verbose"] } smoltcp = { version = "0.5.0", default-features = false, features = ["proto-ipv4", "proto-ipv6", "socket-icmp", "socket-udp", "socket-tcp", "log", "verbose"] }
[features]
semihosting = ["panic-semihosting", "cortex-m-log/semihosting"]
[profile.release] [profile.release]
codegen-units = 1 codegen-units = 1

View File

@ -24,7 +24,7 @@ stdenv.mkDerivation {
# Let openocd output scroll by # Let openocd output scroll by
sleep 1 sleep 1
echo "Run 'cargo build --release'" echo "Run 'cargo build --release --features=semihosting'"
echo "Then 'gdb target/thumbv7em-none-eabihf/release/adc2tcp'" echo "Then 'gdb target/thumbv7em-none-eabihf/release/adc2tcp'"
''; '';
} }

View File

@ -4,8 +4,15 @@
#![feature(never_type)] #![feature(never_type)]
#[allow(unused_extern_crates)] #[allow(unused_extern_crates)]
#[cfg(not(feature = "semihosting"))]
extern crate panic_abort; extern crate panic_abort;
#[cfg(feature = "semihosting")]
extern crate panic_semihosting;
#[macro_use]
extern crate log;
use core::fmt::Write;
use cortex_m::asm::wfi; use cortex_m::asm::wfi;
use cortex_m_rt::entry; use cortex_m_rt::entry;
use embedded_hal::watchdog::{WatchdogEnable, Watchdog}; use embedded_hal::watchdog::{WatchdogEnable, Watchdog};
@ -18,9 +25,6 @@ use stm32f4xx_hal::{
}; };
use smoltcp::time::Instant; use smoltcp::time::Instant;
use core::fmt::Write;
use cortex_m_semihosting::hio;
mod adc_input; mod adc_input;
mod net; mod net;
mod server; mod server;
@ -29,10 +33,30 @@ mod timer;
const OUTPUT_INTERVAL: u32 = 1000; const OUTPUT_INTERVAL: u32 = 1000;
#[cfg(not(feature = "semihosting"))]
fn init_log() {}
#[cfg(feature = "semihosting")]
fn init_log() {
use log::LevelFilter;
use cortex_m_log::log::{Logger, init};
use cortex_m_log::printer::semihosting::{InterruptOk, hio::HStdout};
static mut LOGGER: Option<Logger<InterruptOk<HStdout>>> = None;
let logger = Logger {
inner: InterruptOk::<_>::stdout().expect("semihosting stdout"),
level: LevelFilter::Info,
};
let logger = unsafe {
LOGGER.get_or_insert(logger)
};
init(logger).expect("set logger");
}
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let mut stdout = hio::hstdout().unwrap(); init_log();
writeln!(stdout, "adc2tcp").unwrap(); info!("adc2tcp");
let mut cp = CorePeripherals::take().unwrap(); let mut cp = CorePeripherals::take().unwrap();
cp.SCB.enable_icache(); cp.SCB.enable_icache();
@ -57,19 +81,19 @@ fn main() -> ! {
let gpioc = dp.GPIOC.split(); let gpioc = dp.GPIOC.split();
let gpiog = dp.GPIOG.split(); let gpiog = dp.GPIOG.split();
writeln!(stdout, "ADC init").unwrap(); info!("ADC init");
adc_input::setup(&mut cp.NVIC, dp.ADC1, gpioa.pa3); adc_input::setup(&mut cp.NVIC, dp.ADC1, gpioa.pa3);
writeln!(stdout, "Eth setup").unwrap(); info!("Eth setup");
stm32_eth::setup_pins( stm32_eth::setup_pins(
gpioa.pa1, gpioa.pa2, gpioa.pa7, gpiob.pb13, gpioc.pc1, gpioa.pa1, gpioa.pa2, gpioa.pa7, gpiob.pb13, gpioc.pc1,
gpioc.pc4, gpioc.pc5, gpiog.pg11, gpiog.pg13 gpioc.pc4, gpioc.pc5, gpiog.pg11, gpiog.pg13
); );
writeln!(stdout, "Timer setup").unwrap(); info!("Timer setup");
timer::setup(cp.SYST, clocks); timer::setup(cp.SYST, clocks);
writeln!(stdout, "Net startup").unwrap(); info!("Net startup");
net::run(&mut cp.NVIC, dp.ETHERNET_MAC, dp.ETHERNET_DMA, |net| { net::run(&mut cp.NVIC, dp.ETHERNET_MAC, dp.ETHERNET_DMA, |net| {
let mut server = Server::new(net); let mut server = Server::new(net);