Skip to content

Commit

Permalink
Add optional feature: log-itm
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinevg committed Mar 24, 2021
1 parent 7605c82 commit 0e44003
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 103 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# These are backup files generated by rustfmt
**/*.rs.bk

# Cargo.lock should be ignored for libraries
Cargo.lock

# misc
Makefile
TODO
Expand Down
123 changes: 33 additions & 90 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "daisy_bsp"
version = "0.2.0"
version = "0.3.0"
authors = ["Antoine van Gelder <antoine@flowdsp.io>"]
edition = "2018"
license = "AGPL-3.0-or-later"
Expand Down Expand Up @@ -59,6 +59,8 @@ optional = true

[dev-dependencies]
panic-semihosting = { version = "0.5.6" }
panic-itm = { version = "~0.4.1" }
panic-halt = "0.2.0"
cortex-m-semihosting = { version = "0.3.5" }


Expand All @@ -72,6 +74,7 @@ petal = []
patch = []
field = []
audio_hal = []
log-itm = []
uses_num = [ "num", "num-derive", "num-traits" ]


Expand Down Expand Up @@ -130,3 +133,7 @@ required-features = ["seed"]
[[example]]
name = "adc_bsp"
required-features = ["seed"]

[[example]]
name = "itm"
required-features = ["seed", "log-itm"]
55 changes: 55 additions & 0 deletions examples/itm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#![no_main]
#![no_std]

use panic_semihosting as _;
use cortex_m_rt::entry;

use daisy_bsp as daisy;
use daisy::hal::prelude::*;
use daisy::led::Led;
use daisy::log_itm;


#[entry]
fn main() -> ! {
// - board setup ----------------------------------------------------------

let board = daisy::Board::take().unwrap();
let dp = daisy::pac::Peripherals::take().unwrap();

let ccdr = board.freeze_clocks(dp.PWR.constrain(),
dp.RCC.constrain(),
&dp.SYSCFG);

log_itm!("Hello daisy::itm !");

let pins = board.split_gpios(dp.GPIOA.split(ccdr.peripheral.GPIOA),
dp.GPIOB.split(ccdr.peripheral.GPIOB),
dp.GPIOC.split(ccdr.peripheral.GPIOC),
dp.GPIOD.split(ccdr.peripheral.GPIOD),
dp.GPIOE.split(ccdr.peripheral.GPIOE),
dp.GPIOF.split(ccdr.peripheral.GPIOF),
dp.GPIOG.split(ccdr.peripheral.GPIOG),
dp.GPIOH.split(ccdr.peripheral.GPIOH),
dp.GPIOI.split(ccdr.peripheral.GPIOI),
dp.GPIOJ.split(ccdr.peripheral.GPIOJ),
dp.GPIOK.split(ccdr.peripheral.GPIOK));

let mut led_user = daisy::led::LedUser::new(pins.LED_USER);


// - main loop ------------------------------------------------------------

let one_second = ccdr.clocks.sys_ck().0;
let mut counter = 0;

loop {
log_itm!("ping: {}", counter);
counter += 1;

led_user.on();
cortex_m::asm::delay(one_second);
led_user.off();
cortex_m::asm::delay(one_second);
}
}
38 changes: 32 additions & 6 deletions src/clocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,36 @@ impl SeedCrystal for rcc::Rcc {
/// ```
pub fn configure(pwr: pwr::Pwr, rcc: rcc::Rcc, syscfg: &pac::SYSCFG) -> rcc::Ccdr {
let pwrcfg = pwr.vos0(syscfg).freeze();
rcc.use_seed_crystal() // high speed external crystal @ 16 MHz
.pll1_strategy(rcc::PllConfigStrategy::Iterative) // pll1 drives system clock
.sys_ck(480.mhz()) // system clock @ 480 MHz
.pll3_p_ck(PLL3_P) // audio clock @ 12.288 MHz
.per_ck(4.mhz()) // peripheral clock @ 4 MHz
.freeze(pwrcfg, syscfg)

#[cfg(not(feature = "log-itm"))]
let ccdr = rcc.use_seed_crystal() // high speed external crystal @ 16 MHz
.pll1_strategy(rcc::PllConfigStrategy::Iterative) // pll1 drives system clock
.sys_ck(480.mhz()) // system clock @ 480 MHz
.pll3_p_ck(PLL3_P) // audio clock @ 12.288 MHz
.per_ck(4.mhz()) // peripheral clock @ 4 MHz
.freeze(pwrcfg, syscfg);

#[cfg(any(feature = "log-itm"))]
let ccdr = rcc.use_seed_crystal() // high speed external crystal @ 16 MHz
.pll1_strategy(rcc::PllConfigStrategy::Iterative) // pll1 drives system clock
.sys_ck(480.mhz()) // system clock @ 480 MHz
.pll1_r_ck(480.mhz()) // for TRACECK
.pll3_p_ck(PLL3_P) // audio clock @ 12.288 MHz
.per_ck(4.mhz()) // peripheral clock @ 4 MHz
.freeze(pwrcfg, syscfg);

// enable itm support
#[cfg(any(feature = "log-itm"))]
unsafe {
let swo_frequency = 2_000_000;
let mut cp = cortex_m::Peripherals::steal();
let dp = pac::Peripherals::steal();
crate::itm::enable_itm(&mut cp.DCB,
&dp.DBGMCU,
&mut cp.ITM,
ccdr.clocks.c_ck().0,
swo_frequency);
}

ccdr
}
Loading

0 comments on commit 0e44003

Please sign in to comment.