more docs
Some checks failed
Rust/va416xx-rs/pipeline/pr-main There was a failure building this commit
Some checks failed
Rust/va416xx-rs/pipeline/pr-main There was a failure building this commit
This commit is contained in:
parent
5d8b74bf13
commit
d25108f85d
@ -1,6 +1,5 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
use cortex_m::asm;
|
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_time::Timer;
|
use embassy_time::Timer;
|
||||||
use embedded_hal::digital::StatefulOutputPin;
|
use embedded_hal::digital::StatefulOutputPin;
|
||||||
|
@ -11,6 +11,7 @@ use panic_rtt_target as _;
|
|||||||
use rtt_target::{rprintln, rtt_init_print};
|
use rtt_target::{rprintln, rtt_init_print};
|
||||||
use simple_examples::peb1;
|
use simple_examples::peb1;
|
||||||
use va416xx_hal::dma::{Dma, DmaCfg, DmaChannel, DmaCtrlBlock};
|
use va416xx_hal::dma::{Dma, DmaCfg, DmaChannel, DmaCtrlBlock};
|
||||||
|
use va416xx_hal::irq_router::enable_and_init_irq_router;
|
||||||
use va416xx_hal::pwm::CountdownTimer;
|
use va416xx_hal::pwm::CountdownTimer;
|
||||||
use va416xx_hal::{
|
use va416xx_hal::{
|
||||||
pac::{self, interrupt},
|
pac::{self, interrupt},
|
||||||
@ -45,6 +46,7 @@ fn main() -> ! {
|
|||||||
.xtal_n_clk_with_src_freq(peb1::EXTCLK_FREQ)
|
.xtal_n_clk_with_src_freq(peb1::EXTCLK_FREQ)
|
||||||
.freeze(&mut dp.sysconfig)
|
.freeze(&mut dp.sysconfig)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
enable_and_init_irq_router(&mut dp.sysconfig, &dp.irq_router);
|
||||||
// Safety: The DMA control block has an alignment rule of 128 and we constructed it directly
|
// Safety: The DMA control block has an alignment rule of 128 and we constructed it directly
|
||||||
// statically.
|
// statically.
|
||||||
let dma = Dma::new(&mut dp.sysconfig, dp.dma, DmaCfg::default(), unsafe {
|
let dma = Dma::new(&mut dp.sysconfig, dp.dma, DmaCfg::default(), unsafe {
|
||||||
|
@ -10,7 +10,12 @@ use panic_rtt_target as _;
|
|||||||
use rtt_target::{rprintln, rtt_init_print};
|
use rtt_target::{rprintln, rtt_init_print};
|
||||||
use simple_examples::peb1;
|
use simple_examples::peb1;
|
||||||
use va416xx_hal::{
|
use va416xx_hal::{
|
||||||
pac::{self, interrupt},
|
clock::{
|
||||||
|
assert_periph_reset, deassert_periph_reset, disable_peripheral_clock,
|
||||||
|
enable_peripheral_clock, PeripheralSelect,
|
||||||
|
},
|
||||||
|
irq_router::enable_and_init_irq_router,
|
||||||
|
pac::{self, adc::rxfifoirqtrg::W, interrupt},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
timer::{default_ms_irq_handler, set_up_ms_tick, CountdownTimer, MS_COUNTER},
|
timer::{default_ms_irq_handler, set_up_ms_tick, CountdownTimer, MS_COUNTER},
|
||||||
};
|
};
|
||||||
@ -36,24 +41,21 @@ fn main() -> ! {
|
|||||||
.xtal_n_clk_with_src_freq(peb1::EXTCLK_FREQ)
|
.xtal_n_clk_with_src_freq(peb1::EXTCLK_FREQ)
|
||||||
.freeze(&mut dp.sysconfig)
|
.freeze(&mut dp.sysconfig)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
enable_and_init_irq_router(&mut dp.sysconfig, &dp.irq_router);
|
||||||
let _ = set_up_ms_tick(&mut dp.sysconfig, dp.tim0, &clocks);
|
let _ = set_up_ms_tick(&mut dp.sysconfig, dp.tim0, &clocks);
|
||||||
let mut second_timer = CountdownTimer::new(&mut dp.sysconfig, dp.tim1, &clocks);
|
let mut second_timer = CountdownTimer::new(&mut dp.sysconfig, dp.tim1, &clocks);
|
||||||
second_timer.start(1.Hz());
|
|
||||||
second_timer.listen();
|
second_timer.listen();
|
||||||
// let delay_provider = dp.sy
|
second_timer.start(1.Hz());
|
||||||
loop {
|
loop {
|
||||||
let current_ms = critical_section::with(|cs| MS_COUNTER.borrow(cs).get());
|
let current_ms = critical_section::with(|cs| MS_COUNTER.borrow(cs).get());
|
||||||
if current_ms - last_ms >= 1000 {
|
if current_ms >= last_ms + 1000 {
|
||||||
last_ms = current_ms;
|
// To prevent drift.
|
||||||
|
last_ms += 1000;
|
||||||
rprintln!("MS counter: {}", current_ms);
|
rprintln!("MS counter: {}", current_ms);
|
||||||
let second = critical_section::with(|cs| SEC_COUNTER.borrow(cs).get());
|
let second = critical_section::with(|cs| SEC_COUNTER.borrow(cs).get());
|
||||||
rprintln!("Second counter: {}", second);
|
rprintln!("Second counter: {}", second);
|
||||||
}
|
}
|
||||||
for _ in 0..30000 {
|
asm::delay(1000);
|
||||||
asm::nop();
|
|
||||||
}
|
|
||||||
|
|
||||||
//delay_provider.delay_ms(1000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use cortex_m::interrupt::Mutex;
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
|
use critical_section::Mutex;
|
||||||
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 simple_examples::peb1;
|
use simple_examples::peb1;
|
||||||
|
use va416xx_hal::irq_router::enable_and_init_irq_router;
|
||||||
use va416xx_hal::pac::{self, interrupt};
|
use va416xx_hal::pac::{self, interrupt};
|
||||||
use va416xx_hal::prelude::*;
|
use va416xx_hal::prelude::*;
|
||||||
use va416xx_hal::wdt::Wdt;
|
use va416xx_hal::wdt::Wdt;
|
||||||
@ -40,6 +41,7 @@ fn main() -> ! {
|
|||||||
.xtal_n_clk_with_src_freq(peb1::EXTCLK_FREQ)
|
.xtal_n_clk_with_src_freq(peb1::EXTCLK_FREQ)
|
||||||
.freeze(&mut dp.sysconfig)
|
.freeze(&mut dp.sysconfig)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
enable_and_init_irq_router(&mut dp.sysconfig, &dp.irq_router);
|
||||||
let mut delay_sysclk = cortex_m::delay::Delay::new(cp.SYST, clocks.apb0().raw());
|
let mut delay_sysclk = cortex_m::delay::Delay::new(cp.SYST, clocks.apb0().raw());
|
||||||
|
|
||||||
let mut last_interrupt_counter = 0;
|
let mut last_interrupt_counter = 0;
|
||||||
@ -49,7 +51,7 @@ fn main() -> ! {
|
|||||||
if TEST_MODE != TestMode::AllowReset {
|
if TEST_MODE != TestMode::AllowReset {
|
||||||
wdt_ctrl.feed();
|
wdt_ctrl.feed();
|
||||||
}
|
}
|
||||||
let interrupt_counter = cortex_m::interrupt::free(|cs| WDT_INTRPT_COUNT.borrow(cs).get());
|
let interrupt_counter = critical_section::with(|cs| WDT_INTRPT_COUNT.borrow(cs).get());
|
||||||
if interrupt_counter > last_interrupt_counter {
|
if interrupt_counter > last_interrupt_counter {
|
||||||
rprintln!("interrupt counter has increased to {}", interrupt_counter);
|
rprintln!("interrupt counter has increased to {}", interrupt_counter);
|
||||||
last_interrupt_counter = interrupt_counter;
|
last_interrupt_counter = interrupt_counter;
|
||||||
@ -65,7 +67,7 @@ fn main() -> ! {
|
|||||||
#[interrupt]
|
#[interrupt]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn WATCHDOG() {
|
fn WATCHDOG() {
|
||||||
cortex_m::interrupt::free(|cs| {
|
critical_section::with(|cs| {
|
||||||
WDT_INTRPT_COUNT
|
WDT_INTRPT_COUNT
|
||||||
.borrow(cs)
|
.borrow(cs)
|
||||||
.set(WDT_INTRPT_COUNT.borrow(cs).get() + 1);
|
.set(WDT_INTRPT_COUNT.borrow(cs).get() + 1);
|
||||||
|
@ -108,6 +108,7 @@ mod app {
|
|||||||
use spacepackets::ecss::{
|
use spacepackets::ecss::{
|
||||||
tc::PusTcReader, tm::PusTmCreator, EcssEnumU8, PusPacket, WritablePusPacket,
|
tc::PusTcReader, tm::PusTmCreator, EcssEnumU8, PusPacket, WritablePusPacket,
|
||||||
};
|
};
|
||||||
|
use va416xx_hal::irq_router::enable_and_init_irq_router;
|
||||||
use va416xx_hal::{
|
use va416xx_hal::{
|
||||||
clock::ClkgenExt,
|
clock::ClkgenExt,
|
||||||
edac,
|
edac,
|
||||||
@ -163,6 +164,7 @@ mod app {
|
|||||||
.xtal_n_clk_with_src_freq(Hertz::from_raw(EXTCLK_FREQ))
|
.xtal_n_clk_with_src_freq(Hertz::from_raw(EXTCLK_FREQ))
|
||||||
.freeze(&mut cx.device.sysconfig)
|
.freeze(&mut cx.device.sysconfig)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
enable_and_init_irq_router(&mut cx.device.sysconfig, &cx.device.irq_router);
|
||||||
setup_edac(&mut cx.device.sysconfig);
|
setup_edac(&mut cx.device.sysconfig);
|
||||||
|
|
||||||
let gpiob = PinsG::new(&mut cx.device.sysconfig, cx.device.portg);
|
let gpiob = PinsG::new(&mut cx.device.sysconfig, cx.device.portg);
|
||||||
|
18
va416xx-hal/src/irq_router.rs
Normal file
18
va416xx-hal/src/irq_router.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
use crate::{
|
||||||
|
clock::{PeripheralSelect, SyscfgExt},
|
||||||
|
pac,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn enable_and_init_irq_router(sysconfig: &mut pac::Sysconfig, irq_router: &pac::IrqRouter) {
|
||||||
|
sysconfig.enable_peripheral_clock(PeripheralSelect::IrqRouter);
|
||||||
|
sysconfig.assert_periph_reset_for_two_cycles(PeripheralSelect::IrqRouter);
|
||||||
|
unsafe {
|
||||||
|
irq_router.dmasel0().write_with_zero(|w| w);
|
||||||
|
irq_router.dmasel1().write_with_zero(|w| w);
|
||||||
|
irq_router.dmasel2().write_with_zero(|w| w);
|
||||||
|
irq_router.dmasel3().write_with_zero(|w| w);
|
||||||
|
irq_router.adcsel().write_with_zero(|w| w);
|
||||||
|
irq_router.dacsel0().write_with_zero(|w| w);
|
||||||
|
irq_router.dacsel1().write_with_zero(|w| w);
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,26 @@
|
|||||||
|
//! This is the **H**ardware **A**bstraction **L**ayer (HAL) for the VA416xx MCU family.
|
||||||
|
//!
|
||||||
|
//! It is an additional hardware abstraction on top of the [peripheral access API](https://egit.irs.uni-stuttgart.de/rust/va416xx-rs/src/branch/main/va416xx).
|
||||||
|
|
||||||
|
//! It is the result of reading the datasheet for the device and encoding a type-safe layer over the
|
||||||
|
//! raw PAC. This crate also implements traits specified by the
|
||||||
|
//! [embedded-hal](https://github.com/rust-embedded/embedded-hal) project, making it compatible with
|
||||||
|
//! various drivers in the embedded rust ecosystem.
|
||||||
|
|
||||||
|
//! You have to enable one of the following device features to use this crate depending on
|
||||||
|
//! which chip you are using:
|
||||||
|
|
||||||
|
//! - `va41630`
|
||||||
|
//! - `va41629`
|
||||||
|
//! - `va41628`
|
||||||
|
//! - `va41620`
|
||||||
|
//!
|
||||||
|
//! When using this HAL and writing applications for the VA416xx family in general, it is strongly
|
||||||
|
//! recommended that you set up the clock properly, because the default internal HBO clock
|
||||||
|
//! is not very accurate. You can use the [crate::clock] module for this. If you are working
|
||||||
|
//! with interrupts, it is strongly recommended to set up the IRQ router with the
|
||||||
|
//! [crate::irq_router] module at the very least because that peripheral has confusing and/or
|
||||||
|
//! faulty register reset values which might leads to weird bugs and glitches.
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -22,6 +45,7 @@ pub mod dma;
|
|||||||
pub mod edac;
|
pub mod edac;
|
||||||
pub mod gpio;
|
pub mod gpio;
|
||||||
pub mod i2c;
|
pub mod i2c;
|
||||||
|
pub mod irq_router;
|
||||||
pub mod nvm;
|
pub mod nvm;
|
||||||
pub mod pwm;
|
pub mod pwm;
|
||||||
pub mod spi;
|
pub mod spi;
|
||||||
|
@ -590,7 +590,7 @@ impl<Tim: ValidTim> CountdownTimer<Tim> {
|
|||||||
self.rst_val = (self.clock.raw() / self.curr_freq.raw()) - 1;
|
self.rst_val = (self.clock.raw() / self.curr_freq.raw()) - 1;
|
||||||
self.set_reload(self.rst_val);
|
self.set_reload(self.rst_val);
|
||||||
// Decrementing counter, to set the reset value.
|
// Decrementing counter, to set the reset value.
|
||||||
self.set_count(0);
|
self.set_count(self.rst_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
Loading…
Reference in New Issue
Block a user