some more defmt updates

This commit is contained in:
Robin Müller 2025-04-16 17:14:35 +02:00
parent acb652e940
commit 5f88f094ca
Signed by: muellerr
GPG Key ID: A649FB78196E3849
20 changed files with 310 additions and 310 deletions

View File

@ -8,8 +8,9 @@ cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7" cortex-m-rt = "0.7"
embedded-hal = "1" embedded-hal = "1"
embedded-io = "0.6" embedded-io = "0.6"
rtt-target = "0.6" defmt-rtt = "0.4"
panic-rtt-target = "0.2" defmt = "1"
panic-probe = { version = "1", features = ["defmt"] }
# Even though we do not use this directly, we need to activate this feature explicitely # Even though we do not use this directly, we need to activate this feature explicitely
# so that RTIC compiles because thumv6 does not have CAS operations natively. # so that RTIC compiles because thumv6 does not have CAS operations natively.

View File

@ -4,9 +4,11 @@
#[rtic::app(device = pac)] #[rtic::app(device = pac)]
mod app { mod app {
use panic_rtt_target as _;
use rtic_example::SYSCLK_FREQ; use rtic_example::SYSCLK_FREQ;
use rtt_target::{rprintln, rtt_init_default, set_print_channel}; // Import panic provider.
use panic_probe as _;
// Import global logger.
use defmt_rtt as _;
use va108xx_hal::{ use va108xx_hal::{
clock::{set_clk_div_register, FilterClkSel}, clock::{set_clk_div_register, FilterClkSel},
gpio::{FilterType, InterruptEdge}, gpio::{FilterType, InterruptEdge},
@ -19,19 +21,12 @@ mod app {
rtic_monotonics::systick_monotonic!(Mono, 1_000); rtic_monotonics::systick_monotonic!(Mono, 1_000);
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, defmt::Format)]
pub enum PressMode { pub enum PressMode {
Toggle, Toggle,
Keep, Keep,
} }
#[derive(Debug, PartialEq)]
pub enum CfgMode {
Prompt,
Fixed,
}
const CFG_MODE: CfgMode = CfgMode::Fixed;
// You can change the press mode here // You can change the press mode here
const DEFAULT_MODE: PressMode = PressMode::Toggle; const DEFAULT_MODE: PressMode = PressMode::Toggle;
@ -47,18 +42,11 @@ mod app {
#[init] #[init]
fn init(cx: init::Context) -> (Shared, Local) { fn init(cx: init::Context) -> (Shared, Local) {
let channels = rtt_init_default!(); defmt::println!("-- Vorago Button IRQ Example --");
set_print_channel(channels.up.0);
rprintln!("-- Vorago Button IRQ Example --");
Mono::start(cx.core.SYST, SYSCLK_FREQ.raw()); Mono::start(cx.core.SYST, SYSCLK_FREQ.raw());
let mode = match CFG_MODE { let mode = DEFAULT_MODE;
// Ask mode from user via RTT defmt::info!("Using {:?} mode", mode);
CfgMode::Prompt => prompt_mode(channels.down.0),
// Use mode hardcoded in `DEFAULT_MODE`
CfgMode::Fixed => DEFAULT_MODE,
};
rprintln!("Using {:?} mode", mode);
let mut dp = cx.device; let mut dp = cx.device;
let pinsa = PinsA::new(dp.porta); let pinsa = PinsA::new(dp.porta);
@ -107,21 +95,4 @@ mod app {
leds[0].on(); leds[0].on();
} }
} }
fn prompt_mode(mut down_channel: rtt_target::DownChannel) -> PressMode {
rprintln!("Using prompt mode");
rprintln!("Please enter the mode [0: Toggle, 1: Keep]");
let mut read_buf: [u8; 16] = [0; 16];
let mut read;
loop {
read = down_channel.read(&mut read_buf);
for &byte in &read_buf[..read] {
match byte as char {
'0' => return PressMode::Toggle,
'1' => return PressMode::Keep,
_ => continue, // Ignore other characters
}
}
}
}
} }

View File

@ -4,8 +4,10 @@
#[rtic::app(device = pac)] #[rtic::app(device = pac)]
mod app { mod app {
use panic_rtt_target as _; // Import panic provider.
use rtt_target::{rprintln, rtt_init_default}; use panic_probe as _;
// Import global logger.
use defmt_rtt as _;
use va108xx_hal::pac; use va108xx_hal::pac;
#[local] #[local]
@ -16,8 +18,7 @@ mod app {
#[init] #[init]
fn init(_ctx: init::Context) -> (Shared, Local) { fn init(_ctx: init::Context) -> (Shared, Local) {
rtt_init_default!(); defmt::println!("-- Vorago RTIC template --");
rprintln!("-- Vorago RTIC template --");
(Shared {}, Local {}) (Shared {}, Local {})
} }

View File

@ -1,4 +1,4 @@
//! More complex UART application //! More complex UART application on UART PA8 (TX) and PA9 (RX).
//! //!
//! Uses the IRQ capabilities of the VA10820 peripheral and the RTIC framework to poll the UART in //! Uses the IRQ capabilities of the VA10820 peripheral and the RTIC framework to poll the UART in
//! a non-blocking way. All received data will be sent back to the sender. //! a non-blocking way. All received data will be sent back to the sender.
@ -14,13 +14,19 @@ const RX_RING_BUF_SIZE: usize = 1024;
mod app { mod app {
use super::*; use super::*;
use embedded_io::Write; use embedded_io::Write;
use panic_rtt_target as _;
use ringbuf::traits::{Consumer, Observer, Producer}; use ringbuf::traits::{Consumer, Observer, Producer};
use rtic_example::SYSCLK_FREQ; use rtic_example::SYSCLK_FREQ;
// Import panic provider.
use panic_probe as _;
// Import global logger.
use defmt_rtt as _;
use rtic_monotonics::Monotonic; use rtic_monotonics::Monotonic;
use rtt_target::{rprintln, rtt_init_print};
use va108xx_hal::{ use va108xx_hal::{
pac, pins::PinsA, prelude::*, uart::{self, RxWithInterrupt, Tx}, InterruptConfig pac,
pins::PinsA,
prelude::*,
uart::{self, RxWithInterrupt, Tx},
InterruptConfig,
}; };
#[local] #[local]
@ -38,8 +44,7 @@ mod app {
#[init] #[init]
fn init(cx: init::Context) -> (Shared, Local) { fn init(cx: init::Context) -> (Shared, Local) {
rtt_init_print!(); defmt::println!("-- VA108xx UART Echo with IRQ example application--");
rprintln!("-- VA108xx UART Echo with IRQ example application--");
Mono::start(cx.core.SYST, SYSCLK_FREQ.raw()); Mono::start(cx.core.SYST, SYSCLK_FREQ.raw());
@ -54,7 +59,8 @@ mod app {
(tx, rx), (tx, rx),
115200.Hz().into(), 115200.Hz().into(),
InterruptConfig::new(pac::Interrupt::OC3, true, true), InterruptConfig::new(pac::Interrupt::OC3, true, true),
).unwrap(); )
.unwrap();
let (tx, rx) = irq_uart.split(); let (tx, rx) = irq_uart.split();
let mut rx = rx.into_rx_with_irq(); let mut rx = rx.into_rx_with_irq();
@ -99,7 +105,7 @@ mod app {
} }
if ringbuf_full { if ringbuf_full {
// Could also drop oldest data, but that would require the consumer to be shared. // Could also drop oldest data, but that would require the consumer to be shared.
rprintln!("buffer full, data was dropped"); defmt::println!("buffer full, data was dropped");
} }
} }

View File

@ -5,14 +5,17 @@
#[rtic::app(device = pac, dispatchers = [OC31, OC30, OC29])] #[rtic::app(device = pac, dispatchers = [OC31, OC30, OC29])]
mod app { mod app {
use cortex_m::asm; use cortex_m::asm;
use panic_rtt_target as _;
use rtic_example::SYSCLK_FREQ; use rtic_example::SYSCLK_FREQ;
use rtic_monotonics::systick::prelude::*; use rtic_monotonics::systick::prelude::*;
use rtic_monotonics::Monotonic; use rtic_monotonics::Monotonic;
use rtt_target::{rprintln, rtt_init_print}; // Import panic provider.
use panic_probe as _;
// Import global logger.
use defmt_rtt as _;
use va108xx_hal::{ use va108xx_hal::{
gpio::{Output, PinState}, gpio::{Output, PinState},
pac, pins::PinsA, pac,
pins::PinsA,
}; };
#[local] #[local]
@ -29,8 +32,7 @@ mod app {
#[init] #[init]
fn init(cx: init::Context) -> (Shared, Local) { fn init(cx: init::Context) -> (Shared, Local) {
rtt_init_print!(); defmt::println!("-- Vorago VA108xx RTIC template --");
rprintln!("-- Vorago VA108xx RTIC template --");
Mono::start(cx.core.SYST, SYSCLK_FREQ.raw()); Mono::start(cx.core.SYST, SYSCLK_FREQ.raw());
@ -56,7 +58,7 @@ mod app {
)] )]
async fn blinky(cx: blinky::Context) { async fn blinky(cx: blinky::Context) {
loop { loop {
rprintln!("toggling LEDs"); defmt::println!("toggling LEDs");
cx.local.led0.toggle(); cx.local.led0.toggle();
cx.local.led1.toggle(); cx.local.led1.toggle();
cx.local.led2.toggle(); cx.local.led2.toggle();

View File

@ -7,13 +7,15 @@ edition = "2021"
cortex-m = {version = "0.7", features = ["critical-section-single-core"]} cortex-m = {version = "0.7", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7" cortex-m-rt = "0.7"
panic-halt = "1" panic-halt = "1"
panic-rtt-target = "0.2"
critical-section = "1" critical-section = "1"
rtt-target = "0.6" defmt-rtt = "0.4"
defmt = "1"
panic-probe = { version = "1", features = ["defmt"] }
embedded-hal = "1" embedded-hal = "1"
embedded-hal-nb = "1" embedded-hal-nb = "1"
embedded-io = "0.6" embedded-io = "0.6"
cortex-m-semihosting = "0.5.0" cortex-m-semihosting = "0.5.0"
portable-atomic = { version = "1", features = ["unsafe-assume-single-core"] }
[dependencies.va108xx-hal] [dependencies.va108xx-hal]
version = "0.11" version = "0.11"

View File

@ -10,8 +10,10 @@ use core::cell::RefCell;
use cortex_m::interrupt::Mutex; use cortex_m::interrupt::Mutex;
use cortex_m_rt::entry; use cortex_m_rt::entry;
use embedded_hal::delay::DelayNs; use embedded_hal::delay::DelayNs;
use panic_rtt_target as _; // Import panic provider.
use rtt_target::{rprintln, rtt_init_print}; use panic_probe as _;
// Import logger.
use defmt_rtt as _;
use va108xx_hal::{ use va108xx_hal::{
pac::{self, interrupt}, pac::{self, interrupt},
prelude::*, prelude::*,
@ -23,15 +25,14 @@ static CSD_TGT_2: Mutex<RefCell<Option<CountdownTimer>>> = Mutex::new(RefCell::n
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
rtt_init_print!(); defmt::println!("-- VA108xx Cascade example application--");
rprintln!("-- VA108xx Cascade example application--");
let dp = pac::Peripherals::take().unwrap(); let dp = pac::Peripherals::take().unwrap();
let mut delay = CountdownTimer::new(50.MHz(), dp.tim0); let mut delay = CountdownTimer::new(50.MHz(), dp.tim0);
// Will be started periodically to trigger a cascade // Will be started periodically to trigger a cascade
let mut cascade_triggerer = CountdownTimer::new(50.MHz(), dp.tim3).auto_disable(true); let mut cascade_triggerer = CountdownTimer::new(50.MHz(), dp.tim3).auto_disable(true);
cascade_triggerer.enable_interupt(InterruptConfig::new(pac::Interrupt::OC1, true, false)); cascade_triggerer.enable_interrupt(InterruptConfig::new(pac::Interrupt::OC1, true, false));
cascade_triggerer.enable(); cascade_triggerer.enable();
// First target for cascade // First target for cascade
@ -49,7 +50,7 @@ fn main() -> ! {
// Normally it should already be sufficient to activate IRQ in the CTRL // Normally it should already be sufficient to activate IRQ in the CTRL
// register but a full interrupt is use here to display print output when // register but a full interrupt is use here to display print output when
// the timer expires // the timer expires
cascade_target_1.enable_interupt(InterruptConfig::new(pac::Interrupt::OC2, true, false)); cascade_target_1.enable_interrupt(InterruptConfig::new(pac::Interrupt::OC2, true, false));
// The counter will only activate when the cascade signal is coming in so // The counter will only activate when the cascade signal is coming in so
// it is okay to call start here to set the reset value // it is okay to call start here to set the reset value
cascade_target_1.start(1.Hz()); cascade_target_1.start(1.Hz());
@ -69,7 +70,7 @@ fn main() -> ! {
// Normally it should already be sufficient to activate IRQ in the CTRL // Normally it should already be sufficient to activate IRQ in the CTRL
// register but a full interrupt is use here to display print output when // register but a full interrupt is use here to display print output when
// the timer expires // the timer expires
cascade_target_2.enable_interupt(InterruptConfig::new(pac::Interrupt::OC3, true, false)); cascade_target_2.enable_interrupt(InterruptConfig::new(pac::Interrupt::OC3, true, false));
// The counter will only activate when the cascade signal is coming in so // The counter will only activate when the cascade signal is coming in so
// it is okay to call start here to set the reset value // it is okay to call start here to set the reset value
cascade_target_2.start(1.Hz()); cascade_target_2.start(1.Hz());
@ -87,7 +88,7 @@ fn main() -> ! {
CSD_TGT_2.borrow(cs).replace(Some(cascade_target_2)); CSD_TGT_2.borrow(cs).replace(Some(cascade_target_2));
}); });
loop { loop {
rprintln!("-- Triggering cascade in 0.5 seconds --"); defmt::info!("-- Triggering cascade in 0.5 seconds --");
cascade_triggerer.start(2.Hz()); cascade_triggerer.start(2.Hz());
delay.delay_ms(5000); delay.delay_ms(5000);
} }
@ -96,20 +97,20 @@ fn main() -> ! {
#[interrupt] #[interrupt]
fn OC1() { fn OC1() {
static mut IDX: u32 = 0; static mut IDX: u32 = 0;
rprintln!("{}: Cascade triggered timed out", &IDX); defmt::info!("{}: Cascade triggered timed out", &IDX);
*IDX += 1; *IDX += 1;
} }
#[interrupt] #[interrupt]
fn OC2() { fn OC2() {
static mut IDX: u32 = 0; static mut IDX: u32 = 0;
rprintln!("{}: First cascade target timed out", &IDX); defmt::info!("{}: First cascade target timed out", &IDX);
*IDX += 1; *IDX += 1;
} }
#[interrupt] #[interrupt]
fn OC3() { fn OC3() {
static mut IDX: u32 = 0; static mut IDX: u32 = 0;
rprintln!("{}: Second cascade target timed out", &IDX); defmt::info!("{}: Second cascade target timed out", &IDX);
*IDX += 1; *IDX += 1;
} }

View File

@ -1,11 +1,15 @@
//! Simple PWM example //! Simple PWM example
//!
//! Outputs a PWM waveform on pin PA3.
#![no_main] #![no_main]
#![no_std] #![no_std]
use cortex_m_rt::entry; use cortex_m_rt::entry;
use embedded_hal::{delay::DelayNs, pwm::SetDutyCycle}; use embedded_hal::{delay::DelayNs, pwm::SetDutyCycle};
use panic_rtt_target as _; // Import panic provider.
use rtt_target::{rprintln, rtt_init_print}; use panic_probe as _;
// Import logger.
use defmt_rtt as _;
use va108xx_hal::{ use va108xx_hal::{
pac, pac,
pins::PinsA, pins::PinsA,
@ -16,8 +20,7 @@ use va108xx_hal::{
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
rtt_init_print!(); defmt::println!("-- VA108xx PWM example application--");
rprintln!("-- VA108xx PWM example application--");
let dp = pac::Peripherals::take().unwrap(); let dp = pac::Peripherals::take().unwrap();
let pinsa = PinsA::new(dp.porta); let pinsa = PinsA::new(dp.porta);
let mut pwm = pwm::PwmPin::new(50.MHz(), (pinsa.pa3, dp.tim3), 10.Hz()).unwrap(); let mut pwm = pwm::PwmPin::new(50.MHz(), (pinsa.pa3, dp.tim3), 10.Hz()).unwrap();
@ -36,7 +39,7 @@ fn main() -> ! {
current_duty_cycle += 0.02; current_duty_cycle += 0.02;
counter += 1; counter += 1;
if counter % 10 == 0 { if counter % 10 == 0 {
rprintln!("current duty cycle: {}", current_duty_cycle); defmt::info!("current duty cycle: {}", current_duty_cycle);
} }
pwm.set_duty_cycle(get_duty_from_percent(current_duty_cycle)) pwm.set_duty_cycle(get_duty_from_percent(current_duty_cycle))
@ -57,8 +60,8 @@ fn main() -> ! {
upper_limit -= 0.01; upper_limit -= 0.01;
pwmb.set_pwmb_lower_limit(get_duty_from_percent(lower_limit)); pwmb.set_pwmb_lower_limit(get_duty_from_percent(lower_limit));
pwmb.set_pwmb_upper_limit(get_duty_from_percent(upper_limit)); pwmb.set_pwmb_upper_limit(get_duty_from_percent(upper_limit));
rprintln!("Lower limit: {}", pwmb.pwmb_lower_limit()); defmt::info!("Lower limit: {}", pwmb.pwmb_lower_limit());
rprintln!("Upper limit: {}", pwmb.pwmb_upper_limit()); defmt::info!("Upper limit: {}", pwmb.pwmb_upper_limit());
} }
pwm = PwmPin::<PwmA>::from(pwmb); pwm = PwmPin::<PwmA>::from(pwmb);
} }

View File

@ -1,20 +0,0 @@
//! Code to test RTT logger functionality
#![no_main]
#![no_std]
use cortex_m_rt::entry;
use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use va108xx_hal as _;
#[entry]
fn main() -> ! {
rtt_init_print!();
rprintln!("-- VA108XX RTT example --");
let mut counter = 0;
loop {
rprintln!("{}: Hello, world!", counter);
counter += 1;
cortex_m::asm::delay(25_000_000);
}
}

View File

@ -1,23 +1,21 @@
//! SPI example application //! SPI example application
#![no_main] #![no_main]
#![no_std] #![no_std]
use core::cell::RefCell;
use cortex_m_rt::entry; use cortex_m_rt::entry;
use embedded_hal::{ use embedded_hal::{
delay::DelayNs, delay::DelayNs,
spi::{Mode, SpiBus, MODE_0}, spi::{Mode, SpiBus, MODE_0},
}; };
use panic_rtt_target as _; // Import panic provider.
use rtt_target::{rprintln, rtt_init_print}; use panic_probe as _;
// Import logger.
use defmt_rtt as _;
use va108xx_hal::{ use va108xx_hal::{
pac::{self, interrupt}, pac,
pins::{PinsA, PinsB}, pins::{PinsA, PinsB},
prelude::*, prelude::*,
spi::{self, configure_pin_as_hw_cs_pin, Spi, SpiClkConfig, TransferConfig}, spi::{self, configure_pin_as_hw_cs_pin, Spi, SpiClkConfig, TransferConfig},
timer::CountdownTimer, timer::CountdownTimer,
InterruptConfig,
}; };
#[derive(PartialEq, Debug)] #[derive(PartialEq, Debug)]
@ -43,16 +41,12 @@ const FILL_WORD: u8 = 0x0f;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
rtt_init_print!(); defmt::println!("-- VA108xx SPI example application--");
rprintln!("-- VA108xx SPI example application--"); let dp = pac::Peripherals::take().unwrap();
let mut dp = pac::Peripherals::take().unwrap();
let mut delay = CountdownTimer::new(50.MHz(), dp.tim0); let mut delay = CountdownTimer::new(50.MHz(), dp.tim0);
let spi_clk_cfg = SpiClkConfig::from_clk(50.MHz(), SPI_SPEED_KHZ.kHz()) let spi_clk_cfg = SpiClkConfig::from_clk(50.MHz(), SPI_SPEED_KHZ.kHz())
.expect("creating SPI clock config failed"); .expect("creating SPI clock config failed");
//let spia_ref: RefCell<Option<SpiBase<pac::Spia, u8>>> = RefCell::new(None);
//let spib_ref: RefCell<Option<SpiBase<pac::Spib, u8>>> = RefCell::new(None);
let spi = None;
let pinsa = PinsA::new(dp.porta); let pinsa = PinsA::new(dp.porta);
let pinsb = PinsB::new(dp.portb); let pinsb = PinsB::new(dp.portb);
@ -62,7 +56,7 @@ fn main() -> ! {
} }
// Set up the SPI peripheral // Set up the SPI peripheral
let spi = match SPI_BUS_SEL { let mut spi = match SPI_BUS_SEL {
SpiBusSelect::SpiAPortA => { SpiBusSelect::SpiAPortA => {
let (sck, mosi, miso) = (pinsa.pa31, pinsa.pa30, pinsa.pa29); let (sck, mosi, miso) = (pinsa.pa31, pinsa.pa30, pinsa.pa29);
let mut spia = Spi::new(50.MHz(), dp.spia, (sck, miso, mosi), spi_cfg).unwrap(); let mut spia = Spi::new(50.MHz(), dp.spia, (sck, miso, mosi), spi_cfg).unwrap();
@ -122,7 +116,7 @@ fn main() -> ! {
let tx_buf: [u8; 3] = [0x01, 0x02, 0x03]; let tx_buf: [u8; 3] = [0x01, 0x02, 0x03];
spi.transfer(&mut reply_buf[0..3], &tx_buf).unwrap(); spi.transfer(&mut reply_buf[0..3], &tx_buf).unwrap();
assert_eq!(tx_buf, reply_buf[0..3]); assert_eq!(tx_buf, reply_buf[0..3]);
rprintln!( defmt::info!(
"Received reply: {}, {}, {}", "Received reply: {}, {}, {}",
reply_buf[0], reply_buf[0],
reply_buf[1], reply_buf[1],
@ -132,7 +126,7 @@ fn main() -> ! {
let mut tx_rx_buf: [u8; 3] = [0x03, 0x02, 0x01]; let mut tx_rx_buf: [u8; 3] = [0x03, 0x02, 0x01];
spi.transfer_in_place(&mut tx_rx_buf).unwrap(); spi.transfer_in_place(&mut tx_rx_buf).unwrap();
rprintln!( defmt::info!(
"Received reply: {}, {}, {}", "Received reply: {}, {}, {}",
tx_rx_buf[0], tx_rx_buf[0],
tx_rx_buf[1], tx_rx_buf[1],

View File

@ -2,17 +2,19 @@
#![no_main] #![no_main]
#![no_std] #![no_std]
use core::cell::Cell;
use cortex_m_rt::entry; use cortex_m_rt::entry;
use critical_section::Mutex; use embedded_hal::delay::DelayNs;
use panic_rtt_target as _; // Import panic provider.
use rtt_target::{rprintln, rtt_init_print}; use panic_probe as _;
// Import logger.
use defmt_rtt as _;
use portable_atomic::AtomicU32;
use va108xx_hal::{ use va108xx_hal::{
clock::{get_sys_clock, set_sys_clock}, clock::{get_sys_clock, set_sys_clock},
pac::{self, interrupt}, pac::{self, interrupt},
prelude::*, prelude::*,
time::Hertz, time::Hertz,
timer::{default_ms_irq_handler, CountdownTimer, Event, InterruptConfig, MS_COUNTER}, timer::{CountdownTimer, InterruptConfig},
}; };
#[allow(dead_code)] #[allow(dead_code)]
@ -21,14 +23,15 @@ enum LibType {
Hal, Hal,
} }
static SEC_COUNTER: Mutex<Cell<u32>> = Mutex::new(Cell::new(0)); static MS_COUNTER: AtomicU32 = AtomicU32::new(0);
static SEC_COUNTER: AtomicU32 = AtomicU32::new(0);
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
rtt_init_print!(); let dp = pac::Peripherals::take().unwrap();
let mut dp = pac::Peripherals::take().unwrap(); let mut delay = CountdownTimer::new(50.MHz(), dp.tim2);
let mut last_ms = 0; let mut last_ms = 0;
rprintln!("-- Vorago system ticks using timers --"); defmt::info!("-- Vorago system ticks using timers --");
set_sys_clock(50.MHz()); set_sys_clock(50.MHz());
let lib_type = LibType::Hal; let lib_type = LibType::Hal;
match lib_type { match lib_type {
@ -65,23 +68,23 @@ fn main() -> ! {
} }
LibType::Hal => { LibType::Hal => {
let mut ms_timer = CountdownTimer::new(get_sys_clock().unwrap(), dp.tim0); let mut ms_timer = CountdownTimer::new(get_sys_clock().unwrap(), dp.tim0);
ms_timer.enable_interupt(InterruptConfig::new(interrupt::OC0, true, true)); ms_timer.enable_interrupt(InterruptConfig::new(interrupt::OC0, true, true));
ms_timer.start(1.kHz()); ms_timer.start(1.kHz());
let mut second_timer = CountdownTimer::new(get_sys_clock().unwrap(), dp.tim1); let mut second_timer = CountdownTimer::new(get_sys_clock().unwrap(), dp.tim1);
second_timer.enable_interupt(InterruptConfig::new(interrupt::OC1, true, true)); second_timer.enable_interrupt(InterruptConfig::new(interrupt::OC1, true, true));
second_timer.start(1.Hz()); second_timer.start(1.Hz());
} }
} }
loop { loop {
let current_ms = critical_section::with(|cs| MS_COUNTER.borrow(cs).get()); let current_ms = MS_COUNTER.load(portable_atomic::Ordering::Relaxed);
if current_ms - last_ms >= 1000 { if current_ms - last_ms >= 1000 {
// To prevent drift. // To prevent drift.
last_ms += 1000; last_ms += 1000;
rprintln!("MS counter: {}", current_ms); defmt::info!("MS counter: {}", current_ms);
let second = critical_section::with(|cs| SEC_COUNTER.borrow(cs).get()); let second = SEC_COUNTER.load(portable_atomic::Ordering::Relaxed);
rprintln!("Second counter: {}", second); defmt::info!("Second counter: {}", second);
} }
cortex_m::asm::delay(10000); delay.delay_ms(50);
} }
} }
@ -95,15 +98,11 @@ fn unmask_irqs() {
#[interrupt] #[interrupt]
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn OC0() { fn OC0() {
default_ms_irq_handler() MS_COUNTER.fetch_add(1, portable_atomic::Ordering::Relaxed);
} }
#[interrupt] #[interrupt]
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn OC1() { fn OC1() {
critical_section::with(|cs| { SEC_COUNTER.fetch_add(1, portable_atomic::Ordering::Relaxed);
let mut sec = SEC_COUNTER.borrow(cs).get();
sec += 1;
SEC_COUNTER.borrow(cs).set(sec);
});
} }

View File

@ -13,14 +13,15 @@
use cortex_m_rt::entry; use cortex_m_rt::entry;
use embedded_hal_nb::{nb, serial::Read}; use embedded_hal_nb::{nb, serial::Read};
use embedded_io::Write as _; use embedded_io::Write as _;
use panic_rtt_target as _; // Import panic provider.
use rtt_target::{rprintln, rtt_init_print}; use panic_probe as _;
// Import logger.
use defmt_rtt as _;
use va108xx_hal::{pac, pins::PinsA, prelude::*, uart}; use va108xx_hal::{pac, pins::PinsA, prelude::*, uart};
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
rtt_init_print!(); defmt::println!("-- VA108xx UART example application--");
rprintln!("-- VA108xx UART example application--");
let dp = pac::Peripherals::take().unwrap(); let dp = pac::Peripherals::take().unwrap();

View File

@ -3,7 +3,7 @@
#![no_std] #![no_std]
use cortex_m_rt::entry; use cortex_m_rt::entry;
use panic_rtt_target as _; use panic_probe as _;
use va108xx_hal as _; use va108xx_hal as _;
#[entry] #[entry]

View File

@ -58,10 +58,10 @@ macro_rules! hw_cs_multi_pin {
$cs_id:path $cs_id:path
) => { ) => {
#[doc = concat!( #[doc = concat!(
"Newtype wrapper to use [Pin] [`", stringify!($pin_ty), "Newtype wrapper to use [Pin] [`", stringify!($pin_ty),
"`] as a HW CS pin for [`", stringify!($spi_id), "`] as a HW CS pin for [`", stringify!($spi_id),
"`] with [`", stringify!($cs_id), "`]." "`] with [`", stringify!($cs_id), "`]."
)] )]
pub struct $name(Pin<$pin_id>); pub struct $name(Pin<$pin_id>);
impl $name { impl $name {

View File

@ -20,7 +20,8 @@ use fugit::RateExtU32;
use vorago_shared_periphs::{ use vorago_shared_periphs::{
gpio::{Pin, PinIdProvider}, gpio::{Pin, PinIdProvider},
ioconfig::regs::FunSel, ioconfig::regs::FunSel,
Port, sysconfig::enable_peripheral_clock,
PeripheralSelect, Port,
}; };
/// Get the peripheral block of a TIM peripheral given the index. /// Get the peripheral block of a TIM peripheral given the index.
@ -317,8 +318,7 @@ pub unsafe trait TimRegInterface {
/// ///
/// Only the bit related to the corresponding TIM peripheral is modified /// Only the bit related to the corresponding TIM peripheral is modified
#[inline] #[inline]
#[allow(dead_code)] fn assert_tim_reset(&self) {
fn clear_tim_reset_bit(&self) {
unsafe { unsafe {
va108xx::Peripherals::steal() va108xx::Peripherals::steal()
.sysconfig .sysconfig
@ -328,8 +328,7 @@ pub unsafe trait TimRegInterface {
} }
#[inline] #[inline]
#[allow(dead_code)] fn deassert_tim_reset(&self) {
fn set_tim_reset_bit(&self) {
unsafe { unsafe {
va108xx::Peripherals::steal() va108xx::Peripherals::steal()
.sysconfig .sysconfig
@ -337,6 +336,12 @@ pub unsafe trait TimRegInterface {
.modify(|r, w| w.bits(r.bits() | self.mask_32())); .modify(|r, w| w.bits(r.bits() | self.mask_32()));
} }
} }
fn assert_tim_reset_for_cycles(&self, cycles: u32) {
self.assert_tim_reset();
cortex_m::asm::delay(cycles);
self.deassert_tim_reset();
}
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
@ -369,27 +374,35 @@ unsafe impl TimRegInterface for CountdownTimer {
} }
impl CountdownTimer { impl CountdownTimer {
/// Configures a TIM peripheral as a periodic count down timer /// Create a countdown timer structure for a given TIM peripheral.
pub fn new<Tim: TimMarker>(sys_clk: Hertz, _tim: Tim) -> Self { ///
/// This does not enable the timer. You can use the [Self::load], [Self::start],
/// [Self::enable_interrupt] and [Self::enable] API to set up and configure the countdown
/// timer.
pub fn new<Tim: TimMarker + TimRegInterface>(sys_clk: Hertz, tim: Tim) -> Self {
enable_tim_clk(Tim::ID.raw_id()); enable_tim_clk(Tim::ID.raw_id());
let cd_timer = CountdownTimer { tim.assert_tim_reset_for_cycles(2);
CountdownTimer {
tim: Tim::ID, tim: Tim::ID,
sys_clk, sys_clk,
rst_val: 0, rst_val: 0,
curr_freq: 0.Hz(), curr_freq: 0.Hz(),
last_cnt: 0, last_cnt: 0,
}; }
cd_timer
.tim
.reg_block()
.ctrl()
.modify(|_, w| w.enable().set_bit());
cd_timer
} }
pub fn enable_interupt(&mut self, irq_cfg: InterruptConfig) { #[inline(always)]
pub fn enable(&mut self) {
self.tim
.reg_block()
.enable()
.write(|w| unsafe { w.bits(1) });
}
pub fn enable_interrupt(&mut self, irq_cfg: InterruptConfig) {
if irq_cfg.route { if irq_cfg.route {
let irqsel = unsafe { pac::Irqsel::steal() }; let irqsel = unsafe { pac::Irqsel::steal() };
enable_peripheral_clock(PeripheralSelect::Irqsel);
irqsel irqsel
.tim0(self.raw_id() as usize) .tim0(self.raw_id() as usize)
.write(|w| unsafe { w.bits(irq_cfg.id as u32) }); .write(|w| unsafe { w.bits(irq_cfg.id as u32) });
@ -403,35 +416,23 @@ impl CountdownTimer {
.modify(|_, w| w.irq_enb().set_bit()); .modify(|_, w| w.irq_enb().set_bit());
} }
#[inline(always)] /// Calls [Self::load] to configure the specified frequency and then calls [Self::enable].
pub fn enable(&mut self) { pub fn start(&mut self, frequency: impl Into<Hertz>) {
self.tim self.load(frequency);
.reg_block() self.enable();
.enable()
.write(|w| unsafe { w.bits(1) });
} }
/// This function only clears the interrupt enable bit. /// Return `Ok` if the timer has wrapped. Peripheral will automatically clear the
/// /// flag and restart the time if configured correctly
/// It does not mask the interrupt in the NVIC or un-route the IRQ. pub fn wait(&mut self) -> nb::Result<(), void::Void> {
#[inline(always)] let cnt = self.tim.reg_block().cnt_value().read().bits();
pub fn disable_interrupt(&mut self) { if (cnt > self.last_cnt) || cnt == 0 {
self.tim self.last_cnt = self.rst_val;
.reg_block() Ok(())
.ctrl() } else {
.modify(|_, w| w.irq_enb().clear_bit()); self.last_cnt = cnt;
} Err(nb::Error::WouldBlock)
}
/// Disables the TIM and the dedicated TIM clock.
pub fn stop(self) {
self.tim
.reg_block()
.ctrl()
.write(|w| w.enable().clear_bit());
let syscfg = unsafe { va108xx::Sysconfig::steal() };
syscfg
.tim_clk_enable()
.modify(|r, w| unsafe { w.bits(r.bits() & !(1 << self.raw_id())) });
} }
/// Load the count down timer with a timeout but do not start it. /// Load the count down timer with a timeout but do not start it.
@ -556,45 +557,34 @@ impl CountdownTimer {
pub fn curr_freq(&self) -> Hertz { pub fn curr_freq(&self) -> Hertz {
self.curr_freq self.curr_freq
} }
}
/// CountDown implementation for TIMx /// This function only clears the interrupt enable bit.
impl CountdownTimer { ///
#[inline] /// It does not mask the interrupt in the NVIC or un-route the IRQ.
pub fn start<T>(&mut self, timeout: T) #[inline(always)]
where pub fn disable_interrupt(&mut self) {
T: Into<Hertz>, self.tim
{ .reg_block()
self.load(timeout); .ctrl()
self.enable(); .modify(|_, w| w.irq_enb().clear_bit());
} }
/// Return `Ok` if the timer has wrapped. Peripheral will automatically clear the /// Disables the TIM and the dedicated TIM clock.
/// flag and restart the time if configured correctly pub fn stop_with_clock_disable(self) {
pub fn wait(&mut self) -> nb::Result<(), void::Void> {
let cnt = self.tim.reg_block().cnt_value().read().bits();
if (cnt > self.last_cnt) || cnt == 0 {
self.last_cnt = self.rst_val;
Ok(())
} else {
self.last_cnt = cnt;
Err(nb::Error::WouldBlock)
}
}
/// Returns [false] if the timer was not active, and true otherwise.
pub fn cancel(&mut self) -> bool {
if !self.tim.reg_block().ctrl().read().enable().bit_is_set() {
return false;
}
self.tim self.tim
.reg_block() .reg_block()
.ctrl() .ctrl()
.write(|w| w.enable().clear_bit()); .write(|w| w.enable().clear_bit());
true let syscfg = unsafe { va108xx::Sysconfig::steal() };
syscfg
.tim_clk_enable()
.modify(|r, w| unsafe { w.bits(r.bits() & !(1 << self.raw_id())) });
} }
} }
/// CountDown implementation for TIMx
impl CountdownTimer {}
//================================================================================================== //==================================================================================================
// Delay implementations // Delay implementations
//================================================================================================== //==================================================================================================

View File

@ -13,8 +13,8 @@ fn main() -> ! {
rprintln!("-- Vorago Temperature Sensor and I2C Example --"); rprintln!("-- Vorago Temperature Sensor and I2C Example --");
let dp = pac::Peripherals::take().unwrap(); let dp = pac::Peripherals::take().unwrap();
let mut delay = CountdownTimer::new(50.MHz(), dp.tim0); let mut delay = CountdownTimer::new(50.MHz(), dp.tim0);
let mut temp_sensor = Adt75TempSensor::new(50.MHz(), dp.i2ca) let mut temp_sensor =
.expect("Creating temperature sensor struct failed"); Adt75TempSensor::new(50.MHz(), dp.i2ca).expect("Creating temperature sensor struct failed");
loop { loop {
let temp = temp_sensor let temp = temp_sensor
.read_temperature() .read_temperature()

View File

@ -33,11 +33,7 @@ fn main() -> ! {
let dp = pac::Peripherals::take().unwrap(); let dp = pac::Peripherals::take().unwrap();
let pinsa = PinsA::new(dp.porta); let pinsa = PinsA::new(dp.porta);
let mut delay = CountdownTimer::new(50.MHz(), dp.tim0); let mut delay = CountdownTimer::new(50.MHz(), dp.tim0);
let (sck, mosi, miso) = ( let (sck, mosi, miso) = (pinsa.pa20, pinsa.pa19, pinsa.pa18);
pinsa.pa20,
pinsa.pa19,
pinsa.pa18,
);
let cs_pin = pinsa.pa16; let cs_pin = pinsa.pa16;
let hw_cs_id = configure_pin_as_hw_cs_pin(cs_pin); let hw_cs_id = configure_pin_as_hw_cs_pin(cs_pin);
@ -50,12 +46,7 @@ fn main() -> ! {
) )
.mode(MODE_3) .mode(MODE_3)
.slave_output_disable(true); .slave_output_disable(true);
let mut spi = Spi::new( let mut spi = Spi::new(50.MHz(), dp.spib, (sck, miso, mosi), spi_cfg).unwrap();
50.MHz(),
dp.spib,
(sck, miso, mosi),
spi_cfg,
).unwrap();
spi.cfg_hw_cs(hw_cs_id); spi.cfg_hw_cs(hw_cs_id);
let mut tx_rx_buf: [u8; 3] = [0; 3]; let mut tx_rx_buf: [u8; 3] = [0; 3];

View File

@ -14,20 +14,19 @@ use max116xx_10bit::VoltageRefMode;
use max116xx_10bit::{AveragingConversions, AveragingResults}; use max116xx_10bit::{AveragingConversions, AveragingResults};
use panic_rtt_target as _; use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use va108xx_hal::gpio::Port; use va108xx_hal::gpio::{Input, Output, PinState, Port};
use va108xx_hal::spi::{OptionalHwCs, SpiClkConfig}; use va108xx_hal::pins::PinsA;
use va108xx_hal::spi::{configure_pin_as_hw_cs_pin, SpiClkConfig};
use va108xx_hal::timer::CountdownTimer; use va108xx_hal::timer::CountdownTimer;
use va108xx_hal::{ use va108xx_hal::{
gpio::PinsA, pac,
pac::{self, interrupt},
prelude::*, prelude::*,
spi::{Spi, SpiBase, SpiConfig}, spi::{HwChipSelectId, Spi, SpiConfig},
timer::{default_ms_irq_handler, set_up_ms_tick, DelayMs, InterruptConfig},
}; };
use va108xx_hal::{port_function_select, FunSel}; use va108xx_hal::{port_function_select, FunSel};
use vorago_reb1::max11619::{ use vorago_reb1::max11619::{
max11619_externally_clocked_no_wakeup, max11619_externally_clocked_with_wakeup, max11619_externally_clocked_no_wakeup, max11619_externally_clocked_with_wakeup,
max11619_internally_clocked, EocPin, AN2_CHANNEL, POTENTIOMETER_CHANNEL, max11619_internally_clocked, AN2_CHANNEL, POTENTIOMETER_CHANNEL,
}; };
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Copy, Clone)]
@ -57,34 +56,34 @@ const MUX_MODE: MuxMode = MuxMode::None;
// This is probably more or less a re-implementation of https://docs.rs/embedded-hal-bus/latest/embedded_hal_bus/spi/struct.ExclusiveDevice.html. // This is probably more or less a re-implementation of https://docs.rs/embedded-hal-bus/latest/embedded_hal_bus/spi/struct.ExclusiveDevice.html.
// Users should look at the embedded-hal-bus crate for sharing the bus. // Users should look at the embedded-hal-bus crate for sharing the bus.
pub struct SpiWithHwCs<Delay, HwCs> { pub struct SpiWithHwCs<Delay> {
inner: SpiBase<pac::Spib, u8>, inner: Spi<u8>,
delay_provider: Delay, delay_provider: Delay,
hw_cs: HwCs, hw_cs_id: HwChipSelectId,
} }
impl<Delay: DelayNs, HwCs: OptionalHwCs<pac::Spib>> SpiWithHwCs<Delay, HwCs> { impl<Delay: DelayNs> SpiWithHwCs<Delay> {
pub fn new(spi: SpiBase<pac::Spib, u8>, hw_cs: HwCs, delay_provider: Delay) -> Self { pub fn new(spi: Spi<u8>, hw_cs_id: HwChipSelectId, delay_provider: Delay) -> Self {
Self { Self {
inner: spi, inner: spi,
hw_cs, hw_cs_id,
delay_provider, delay_provider,
} }
} }
} }
impl<Delay, HwCs> embedded_hal::spi::ErrorType for SpiWithHwCs<Delay, HwCs> { impl<Delay> embedded_hal::spi::ErrorType for SpiWithHwCs<Delay> {
type Error = Infallible; type Error = Infallible;
} }
impl<Delay: DelayNs, HwCs: OptionalHwCs<pac::Spib>> SpiDevice for SpiWithHwCs<Delay, HwCs> { impl<Delay: DelayNs> SpiDevice for SpiWithHwCs<Delay> {
fn transaction( fn transaction(
&mut self, &mut self,
operations: &mut [spi::Operation<'_, u8>], operations: &mut [spi::Operation<'_, u8>],
) -> Result<(), Self::Error> { ) -> Result<(), Self::Error> {
// Only the HW CS is configured here. This is not really necessary, but showcases // Only the HW CS is configured here. This is not really necessary, but showcases
// that we could scale this multiple SPI devices. // that we could scale this multiple SPI devices.
self.inner.cfg_hw_cs_with_pin(&self.hw_cs); self.inner.cfg_hw_cs(self.hw_cs_id);
for operation in operations { for operation in operations {
match operation { match operation {
spi::Operation::Read(buf) => self.inner.read(buf).ok().unwrap(), spi::Operation::Read(buf) => self.inner.read(buf).ok().unwrap(),
@ -111,28 +110,17 @@ fn main() -> ! {
rprintln!("-- Vorago ADC Example --"); rprintln!("-- Vorago ADC Example --");
let mut dp = pac::Peripherals::take().unwrap(); let mut dp = pac::Peripherals::take().unwrap();
let tim0 = set_up_ms_tick( let mut delay = CountdownTimer::new(SYS_CLK, dp.tim0);
InterruptConfig::new(pac::Interrupt::OC0, true, true),
&mut dp.sysconfig,
Some(&mut dp.irqsel),
SYS_CLK,
dp.tim0,
);
let delay = DelayMs::new(tim0).unwrap();
unsafe { unsafe {
cortex_m::peripheral::NVIC::unmask(pac::Interrupt::OC0); cortex_m::peripheral::NVIC::unmask(pac::Interrupt::OC0);
} }
let pinsa = PinsA::new(&mut dp.sysconfig, dp.porta); let pinsa = PinsA::new(dp.porta);
let spi_cfg = SpiConfig::default() let spi_cfg = SpiConfig::default()
.clk_cfg(SpiClkConfig::from_clk(SYS_CLK, 3.MHz()).unwrap()) .clk_cfg(SpiClkConfig::from_clk(SYS_CLK, 3.MHz()).unwrap())
.mode(MODE_0) .mode(MODE_0)
.blockmode(true); .blockmode(true);
let (sck, mosi, miso) = ( let (sck, mosi, miso) = (pinsa.pa20, pinsa.pa19, pinsa.pa18);
pinsa.pa20.into_funsel_2(),
pinsa.pa19.into_funsel_2(),
pinsa.pa18.into_funsel_2(),
);
if MUX_MODE == MuxMode::PortB19to17 { if MUX_MODE == MuxMode::PortB19to17 {
port_function_select(&mut dp.ioconfig, Port::B, 19, FunSel::Sel1).ok(); port_function_select(&mut dp.ioconfig, Port::B, 19, FunSel::Sel1).ok();
@ -141,39 +129,30 @@ fn main() -> ! {
port_function_select(&mut dp.ioconfig, Port::B, 16, FunSel::Sel1).ok(); port_function_select(&mut dp.ioconfig, Port::B, 16, FunSel::Sel1).ok();
} }
// Set the accelerometer chip select low in case the board slot is populated // Set the accelerometer chip select low in case the board slot is populated
let mut accel_cs = pinsa.pa16.into_push_pull_output(); Output::new(pinsa.pa16, PinState::Low);
accel_cs.set_high();
let spi = Spi::new( let hw_cs_id = configure_pin_as_hw_cs_pin(pinsa.pa17);
&mut dp.sysconfig, let spi = Spi::new(50.MHz(), dp.spib, (sck, miso, mosi), spi_cfg).unwrap();
50.MHz(),
dp.spib, let delay_spi = CountdownTimer::new(SYS_CLK, dp.tim1);
(sck, miso, mosi), let spi_with_hwcs = SpiWithHwCs::new(spi, hw_cs_id, delay_spi);
spi_cfg,
)
.downgrade();
let delay_provider = CountdownTimer::new(&mut dp.sysconfig, 50.MHz(), dp.tim1);
let spi_with_hwcs = SpiWithHwCs::new(spi, pinsa.pa17.into_funsel_2(), delay_provider);
match EXAMPLE_MODE { match EXAMPLE_MODE {
ExampleMode::NotUsingEoc => spi_example_externally_clocked(spi_with_hwcs, delay), ExampleMode::NotUsingEoc => spi_example_externally_clocked(spi_with_hwcs, &mut delay),
ExampleMode::UsingEoc => { ExampleMode::UsingEoc => {
spi_example_internally_clocked(spi_with_hwcs, delay, pinsa.pa14.into_floating_input()); spi_example_internally_clocked(
spi_with_hwcs,
&mut delay,
Input::new_floating(pinsa.pa14),
);
} }
ExampleMode::NotUsingEocWithDelay => { ExampleMode::NotUsingEocWithDelay => {
let delay_us = CountdownTimer::new(&mut dp.sysconfig, 50.MHz(), dp.tim2); spi_example_externally_clocked_with_delay(spi_with_hwcs, &mut delay);
spi_example_externally_clocked_with_delay(spi_with_hwcs, delay, delay_us);
} }
} }
} }
#[interrupt]
#[allow(non_snake_case)]
fn OC0() {
default_ms_irq_handler();
}
/// Use the SPI clock as the conversion clock /// Use the SPI clock as the conversion clock
fn spi_example_externally_clocked(spi: impl SpiDevice, mut delay: DelayMs) -> ! { fn spi_example_externally_clocked(spi: impl SpiDevice, delay: &mut impl DelayNs) -> ! {
let mut adc = max11619_externally_clocked_no_wakeup(spi) let mut adc = max11619_externally_clocked_no_wakeup(spi)
.expect("Creating externally clocked MAX11619 device failed"); .expect("Creating externally clocked MAX11619 device failed");
if READ_MODE == ReadMode::AverageN { if READ_MODE == ReadMode::AverageN {
@ -228,11 +207,7 @@ fn spi_example_externally_clocked(spi: impl SpiDevice, mut delay: DelayMs) -> !
} }
} }
fn spi_example_externally_clocked_with_delay( fn spi_example_externally_clocked_with_delay(spi: impl SpiDevice, delay: &mut impl DelayNs) -> ! {
spi: impl SpiDevice,
mut delay: DelayMs,
mut delay_us: impl DelayNs,
) -> ! {
let mut adc = let mut adc =
max11619_externally_clocked_with_wakeup(spi).expect("Creating MAX116xx device failed"); max11619_externally_clocked_with_wakeup(spi).expect("Creating MAX116xx device failed");
let mut cmd_buf: [u8; 32] = [0; 32]; let mut cmd_buf: [u8; 32] = [0; 32];
@ -244,7 +219,7 @@ fn spi_example_externally_clocked_with_delay(
ReadMode::Single => { ReadMode::Single => {
rprintln!("Reading single potentiometer channel"); rprintln!("Reading single potentiometer channel");
let pot_val = adc let pot_val = adc
.read_single_channel(&mut cmd_buf, POTENTIOMETER_CHANNEL, &mut delay_us) .read_single_channel(&mut cmd_buf, POTENTIOMETER_CHANNEL, delay)
.expect("Creating externally clocked MAX11619 ADC failed"); .expect("Creating externally clocked MAX11619 ADC failed");
rprintln!("Single channel read:"); rprintln!("Single channel read:");
rprintln!("\tPotentiometer value: {}", pot_val); rprintln!("\tPotentiometer value: {}", pot_val);
@ -255,7 +230,7 @@ fn spi_example_externally_clocked_with_delay(
&mut cmd_buf, &mut cmd_buf,
&mut res_buf.iter_mut(), &mut res_buf.iter_mut(),
POTENTIOMETER_CHANNEL, POTENTIOMETER_CHANNEL,
&mut delay_us, delay,
) )
.expect("Multi-Channel read failed"); .expect("Multi-Channel read failed");
print_res_buf(&res_buf); print_res_buf(&res_buf);
@ -266,7 +241,7 @@ fn spi_example_externally_clocked_with_delay(
&mut cmd_buf, &mut cmd_buf,
&mut res_buf.iter_mut(), &mut res_buf.iter_mut(),
AN2_CHANNEL, AN2_CHANNEL,
&mut delay_us, delay,
) )
.expect("Multi-Channel read failed"); .expect("Multi-Channel read failed");
rprintln!("Multi channel read from 2 to 3:"); rprintln!("Multi channel read from 2 to 3:");
@ -283,7 +258,11 @@ fn spi_example_externally_clocked_with_delay(
} }
/// This function uses the EOC pin to determine whether the conversion finished /// This function uses the EOC pin to determine whether the conversion finished
fn spi_example_internally_clocked(spi: impl SpiDevice, mut delay: DelayMs, eoc_pin: EocPin) -> ! { fn spi_example_internally_clocked(
spi: impl SpiDevice,
delay: &mut impl DelayNs,
eoc_pin: Input,
) -> ! {
let mut adc = max11619_internally_clocked( let mut adc = max11619_internally_clocked(
spi, spi,
eoc_pin, eoc_pin,

View File

@ -15,12 +15,12 @@ fn main() -> ! {
rtt_init_print!(); rtt_init_print!();
rprintln!("-- VA108XX REB1 NVM example --"); rprintln!("-- VA108XX REB1 NVM example --");
let mut dp = pac::Peripherals::take().unwrap(); let dp = pac::Peripherals::take().unwrap();
let mut timer = CountdownTimer::new(&mut dp.sysconfig, CLOCK_FREQ, dp.tim0); let mut timer = CountdownTimer::new(CLOCK_FREQ, dp.tim0);
let mut nvm = M95M01::new(&mut dp.sysconfig, CLOCK_FREQ, dp.spic); let mut nvm = M95M01::new(CLOCK_FREQ, dp.spic);
let status_reg = nvm.read_status_reg().expect("reading status reg failed"); let status_reg = nvm.read_status_reg().expect("reading status reg failed");
if status_reg.zero_segment() == 0b111 { if status_reg.zero_segment().value() == 0b111 {
panic!("status register unexpected values"); panic!("status register unexpected values");
} }

View File

@ -15,6 +15,10 @@
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"preLaunchTask": "rust: cargo build led blinky", "preLaunchTask": "rust: cargo build led blinky",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/blinky-leds", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/blinky-leds",
"interface": "jtag", "interface": "jtag",
"runToEntryPoint": "main", "runToEntryPoint": "main",
@ -39,6 +43,10 @@
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"preLaunchTask": "rust: cargo build hal tests", "preLaunchTask": "rust: cargo build hal tests",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/board-tests", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/board-tests",
"interface": "jtag", "interface": "jtag",
"runToEntryPoint": "main", "runToEntryPoint": "main",
@ -63,6 +71,10 @@
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"preLaunchTask": "rust: cargo build rtt", "preLaunchTask": "rust: cargo build rtt",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/rtt-log", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/rtt-log",
"interface": "jtag", "interface": "jtag",
"runToEntryPoint": "main", "runToEntryPoint": "main",
@ -87,6 +99,10 @@
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"preLaunchTask": "rust: cargo build button blinky", "preLaunchTask": "rust: cargo build button blinky",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/blinky-button-irq", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/blinky-button-irq",
"interface": "jtag", "interface": "jtag",
"runToEntryPoint": "main", "runToEntryPoint": "main",
@ -113,6 +129,10 @@
"preLaunchTask": "rust: cargo build systick", "preLaunchTask": "rust: cargo build systick",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/timer-ticks", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/timer-ticks",
"interface": "jtag", "interface": "jtag",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"runToEntryPoint": "main", "runToEntryPoint": "main",
"rttConfig": { "rttConfig": {
"enabled": true, "enabled": true,
@ -133,7 +153,11 @@
"servertype": "jlink", "servertype": "jlink",
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx-base.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "rust: cargo build uart", "preLaunchTask": "rust: cargo build uart",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/uart", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/uart",
"interface": "jtag", "interface": "jtag",
@ -158,6 +182,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "rust: cargo build spi", "preLaunchTask": "rust: cargo build spi",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/spi", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/spi",
"interface": "jtag", "interface": "jtag",
@ -182,6 +210,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx-base.svd.patched", "svdFile": "./va108xx/svd/va108xx-base.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "rust: cargo build temp sensor", "preLaunchTask": "rust: cargo build temp sensor",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/adt75-temp-sensor", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/adt75-temp-sensor",
"interface": "jtag", "interface": "jtag",
@ -206,6 +238,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx-base.svd.patched", "svdFile": "./va108xx/svd/va108xx-base.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "rust: cargo build button blinky rtic", "preLaunchTask": "rust: cargo build button blinky rtic",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/blinky-button-rtic", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/blinky-button-rtic",
"interface": "jtag", "interface": "jtag",
@ -230,6 +266,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx-base.svd.patched", "svdFile": "./va108xx/svd/va108xx-base.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "uart-echo-rtic-example", "preLaunchTask": "uart-echo-rtic-example",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/uart-echo-rtic", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/uart-echo-rtic",
"interface": "jtag", "interface": "jtag",
@ -254,6 +294,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "rust: cargo build pwm", "preLaunchTask": "rust: cargo build pwm",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/pwm", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/pwm",
"interface": "jtag", "interface": "jtag",
@ -278,6 +322,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "rust: cargo build cascade", "preLaunchTask": "rust: cargo build cascade",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/cascade", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/cascade",
"interface": "jtag", "interface": "jtag",
@ -302,6 +350,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "rust: cargo build accelerometer", "preLaunchTask": "rust: cargo build accelerometer",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/adxl343-accelerometer", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/adxl343-accelerometer",
"interface": "jtag", "interface": "jtag",
@ -318,19 +370,6 @@
] ]
} }
}, },
{
"type": "cortex-debug",
"request": "launch",
"name": "Blinky HAL",
"servertype": "jlink",
"cwd": "${workspaceRoot}",
"device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched",
"preLaunchTask": "blinky-hal",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/blinky",
"interface": "jtag",
"runToEntryPoint": "main",
},
{ {
"type": "cortex-debug", "type": "cortex-debug",
"request": "launch", "request": "launch",
@ -339,6 +378,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "rust: cargo build adc", "preLaunchTask": "rust: cargo build adc",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/max11619-adc", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/max11619-adc",
"interface": "jtag", "interface": "jtag",
@ -363,6 +406,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "uart-echo-rtic-example", "preLaunchTask": "uart-echo-rtic-example",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/uart-echo-rtic", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/uart-echo-rtic",
"interface": "jtag", "interface": "jtag",
@ -387,6 +434,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "reb1-nvm", "preLaunchTask": "reb1-nvm",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/nvm", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/examples/nvm",
"interface": "jtag", "interface": "jtag",
@ -411,6 +462,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "rtic-example", "preLaunchTask": "rtic-example",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/rtic-example", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/rtic-example",
"interface": "jtag", "interface": "jtag",
@ -435,6 +490,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "embassy-example", "preLaunchTask": "embassy-example",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/embassy-example", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/embassy-example",
"interface": "jtag", "interface": "jtag",
@ -459,6 +518,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "bootloader", "preLaunchTask": "bootloader",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/release/bootloader", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/release/bootloader",
"interface": "jtag", "interface": "jtag",
@ -483,6 +546,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "flashloader", "preLaunchTask": "flashloader",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/release/flashloader", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/release/flashloader",
"interface": "jtag", "interface": "jtag",
@ -507,6 +574,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "async-gpio", "preLaunchTask": "async-gpio",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/async-gpio", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/async-gpio",
"interface": "jtag", "interface": "jtag",
@ -531,6 +602,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "async-uart-tx", "preLaunchTask": "async-uart-tx",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/async-uart-tx", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/async-uart-tx",
"interface": "jtag", "interface": "jtag",
@ -555,6 +630,10 @@
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"device": "Cortex-M0", "device": "Cortex-M0",
"svdFile": "./va108xx/svd/va108xx.svd.patched", "svdFile": "./va108xx/svd/va108xx.svd.patched",
"serverArgs": [
"-jtagconf",
"-1,-1"
],
"preLaunchTask": "async-uart-rx", "preLaunchTask": "async-uart-rx",
"executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/async-uart-rx", "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/async-uart-rx",
"interface": "jtag", "interface": "jtag",
@ -572,4 +651,4 @@
} }
}, },
] ]
} }