Skip to content

Commit 7e69d97

Browse files
committed
link correction
1 parent 66d51fc commit 7e69d97

File tree

13 files changed

+149
-45
lines changed

13 files changed

+149
-45
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ example.
9898

9999
Assuming a working debug connection to your VA108xx board, you can debug using VS Code with
100100
the [`Cortex-Debug` plugin](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug).
101+
Please make sure that [`objdump-multiarch` and `nm-multiarch`](https://forums.raspberrypi.com/viewtopic.php?t=333146)
102+
are installed as well.
101103

102104
Some sample configuration files for VS code were provided and can be used by running
103105
`cp -rT vscode .vscode` like specified above. After that, you can use `Run and Debug`
@@ -112,4 +114,5 @@ configuration variables in your `settings.json`:
112114
- `"cortex-debug.gdbPath.osx"`
113115

114116
The provided VS Code configurations also provide an integrated RTT logger, which you can access
115-
via the terminal at `RTT Ch:0 console`.
117+
via the terminal at `RTT Ch:0 console`. In order for the RTT block address detection to
118+
work properly, `objdump-multiarch` and `nm-multiarch` need to be installed.

examples/embassy/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@ async fn main(_spawner: Spawner) {
1818
let mut dp = pac::Peripherals::take().unwrap();
1919

2020
// Safety: Only called once here.
21-
unsafe { embassy_example::init(&mut dp.sysconfig, SYSCLK_FREQ, dp.tim23, dp.tim22) };
21+
unsafe {
22+
embassy_example::init(
23+
&mut dp.sysconfig,
24+
&dp.irqsel,
25+
SYSCLK_FREQ,
26+
dp.tim23,
27+
dp.tim22,
28+
)
29+
};
2230

2331
let porta = PinsA::new(&mut dp.sysconfig, Some(dp.ioconfig), dp.porta);
2432
let mut led0 = porta.pa10.into_readable_push_pull_output();

examples/embassy/src/time_driver.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! This is a sample time driver implementation for the VA416xx family of devices, supporting
1+
//! This is a sample time driver implementation for the VA108xx family of devices, supporting
22
//! one alarm and requiring/reserving 2 TIM peripherals. You could adapt this implementation to
33
//! support more alarms.
44
//!
@@ -12,30 +12,36 @@ use portable_atomic::{AtomicU32, AtomicU8, Ordering};
1212
use embassy_time_driver::{time_driver_impl, AlarmHandle, Driver, TICK_HZ};
1313
use once_cell::sync::OnceCell;
1414
use va108xx_hal::{
15+
clock::enable_peripheral_clock,
1516
enable_interrupt,
1617
pac::{self, interrupt},
1718
prelude::*,
1819
timer::{enable_tim_clk, ValidTim},
20+
PeripheralSelect,
1921
};
2022

2123
pub type TimekeeperClk = pac::Tim23;
2224
pub type AlarmClk0 = pac::Tim22;
2325
pub type AlarmClk1 = pac::Tim21;
2426
pub type AlarmClk2 = pac::Tim20;
2527

28+
const TIMEKEEPER_IRQ: pac::Interrupt = pac::Interrupt::OC31;
29+
const ALARM_IRQ: pac::Interrupt = pac::Interrupt::OC30;
30+
2631
/// Initialization method for embassy
2732
///
2833
/// # Safety
2934
/// This has to be called once at initialization time to initiate the time driver for
3035
/// embassy.
3136
pub unsafe fn init(
3237
syscfg: &mut pac::Sysconfig,
38+
irqsel: &pac::Irqsel,
3339
sysclk: impl Into<Hertz>,
3440
timekeeper: TimekeeperClk,
3541
alarm_tim: AlarmClk0,
3642
) {
3743
//enable_and_init_irq_router(syscfg, irq_router);
38-
DRIVER.init(syscfg, sysclk, timekeeper, alarm_tim)
44+
DRIVER.init(syscfg, irqsel, sysclk, timekeeper, alarm_tim)
3945
}
4046

4147
time_driver_impl!(
@@ -114,10 +120,12 @@ impl TimerDriverEmbassy {
114120
fn init(
115121
&self,
116122
syscfg: &mut pac::Sysconfig,
123+
irqsel: &pac::Irqsel,
117124
sysclk: impl Into<Hertz>,
118125
timekeeper: TimekeeperClk,
119126
alarm_tim: AlarmClk0,
120127
) {
128+
enable_peripheral_clock(syscfg, PeripheralSelect::Irqsel);
121129
enable_tim_clk(syscfg, TimekeeperClk::TIM_ID);
122130
let sysclk = sysclk.into();
123131
// Initiate scale value here. This is required to convert timer ticks back to a timestamp.
@@ -130,8 +138,11 @@ impl TimerDriverEmbassy {
130138
.cnt_value()
131139
.write(|w| unsafe { w.bits(u32::MAX) });
132140
// Switch on. Timekeeping should always be done.
141+
irqsel
142+
.tim0(TimekeeperClk::TIM_ID as usize)
143+
.write(|w| unsafe { w.bits(TIMEKEEPER_IRQ as u32) });
133144
unsafe {
134-
enable_interrupt(pac::Interrupt::OC31);
145+
enable_interrupt(TIMEKEEPER_IRQ);
135146
}
136147
timekeeper.ctrl().modify(|_, w| w.irq_enb().set_bit());
137148
timekeeper.enable().write(|w| unsafe { w.bits(1) });
@@ -145,8 +156,11 @@ impl TimerDriverEmbassy {
145156
});
146157
// Enable general interrupts. The IRQ enable of the peripheral remains cleared.
147158
unsafe {
148-
enable_interrupt(pac::Interrupt::OC30);
159+
enable_interrupt(ALARM_IRQ);
149160
}
161+
irqsel
162+
.tim0(AlarmClk0::TIM_ID as usize)
163+
.write(|w| unsafe { w.bits(ALARM_IRQ as u32) });
150164
}
151165

152166
// Should be called inside the IRQ of the timekeeper timer.

examples/rtic/src/bin/uart.rs renamed to examples/rtic/src/bin/uart-rtic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
mod app {
1515
use embedded_io::Write;
1616
use panic_rtt_target as _;
17+
use rtic_example::SYSCLK_FREQ;
1718
use rtic_sync::make_channel;
1819
use rtt_target::{rprintln, rtt_init_print};
1920
use va108xx_hal::{
@@ -47,9 +48,10 @@ mod app {
4748
#[init]
4849
fn init(cx: init::Context) -> (Shared, Local) {
4950
rtt_init_print!();
50-
//set_print_channel(channels.up.0);
5151
rprintln!("-- VA108xx UART IRQ example application--");
5252

53+
Mono::start(cx.core.SYST, SYSCLK_FREQ.raw());
54+
5355
let mut dp = cx.device;
5456
let gpiob = PinsB::new(&mut dp.sysconfig, Some(dp.ioconfig), dp.portb);
5557
let tx = gpiob.pb21.into_funsel_1();
@@ -66,7 +68,6 @@ mod app {
6668

6769
let (rx_info_tx, rx_info_rx) = make_channel!(RxInfo, 3);
6870
let rx_buf: [u8; 64] = [0; 64];
69-
//reply_handler::spawn().expect("spawning reply handler failed");
7071
(
7172
Shared { irq_uart, rx_buf },
7273
Local {

examples/rtic/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![no_std]
2+
use va108xx_hal::time::Hertz;
3+
4+
pub const SYSCLK_FREQ: Hertz = Hertz::from_raw(50_000_000);

examples/rtic/src/main.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ mod app {
77
use cortex_m::asm;
88
use embedded_hal::digital::StatefulOutputPin;
99
use panic_rtt_target as _;
10+
use rtic_example::SYSCLK_FREQ;
1011
use rtic_monotonics::systick::prelude::*;
1112
use rtic_monotonics::Monotonic;
12-
use rtt_target::{rprintln, rtt_init_default};
13+
use rtt_target::{rprintln, rtt_init_print};
1314
use va108xx_hal::{
1415
gpio::{OutputReadablePushPull, Pin, PinsA, PA10, PA6, PA7},
1516
pac,
@@ -25,15 +26,20 @@ mod app {
2526
#[shared]
2627
struct Shared {}
2728

28-
rtic_monotonics::systick_monotonic!(Mono, 10_000);
29+
rtic_monotonics::systick_monotonic!(Mono);
2930

3031
#[init]
31-
fn init(_ctx: init::Context) -> (Shared, Local) {
32-
rtt_init_default!();
32+
fn init(mut cx: init::Context) -> (Shared, Local) {
33+
rtt_init_print!();
3334
rprintln!("-- Vorago VA108xx RTIC template --");
34-
let mut dp = pac::Peripherals::take().unwrap();
3535

36-
let porta = PinsA::new(&mut dp.sysconfig, Some(dp.ioconfig), dp.porta);
36+
Mono::start(cx.core.SYST, SYSCLK_FREQ.raw());
37+
38+
let porta = PinsA::new(
39+
&mut cx.device.sysconfig,
40+
Some(cx.device.ioconfig),
41+
cx.device.porta,
42+
);
3743
let led0 = porta.pa10.into_readable_push_pull_output();
3844
let led1 = porta.pa7.into_readable_push_pull_output();
3945
let led2 = porta.pa6.into_readable_push_pull_output();
@@ -55,10 +61,11 @@ mod app {
5561
)]
5662
async fn blinky(cx: blinky::Context) {
5763
loop {
64+
rprintln!("toggling LEDs");
5865
cx.local.led0.toggle().ok();
5966
cx.local.led1.toggle().ok();
6067
cx.local.led2.toggle().ok();
61-
Mono::delay(200.millis()).await;
68+
Mono::delay(1000.millis()).await;
6269
}
6370
}
6471
}

examples/simple/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cortex-m = {version = "0.7", features = ["critical-section-single-core"]}
88
cortex-m-rt = "0.7"
99
panic-halt = "0.2"
1010
panic-rtt-target = "0.1"
11+
critical-section = "1"
1112
rtt-target = "0.5"
1213
embedded-hal = "1"
1314
embedded-hal-nb = "1"

examples/simple/examples/timer-ticks.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#![no_std]
44

55
use core::cell::Cell;
6-
use cortex_m::interrupt::Mutex;
76
use cortex_m_rt::entry;
7+
use critical_section::Mutex;
88
use panic_rtt_target as _;
99
use rtt_target::{rprintln, rtt_init_print};
1010
use va108xx_hal::{
@@ -83,11 +83,12 @@ fn main() -> ! {
8383
}
8484
}
8585
loop {
86-
let current_ms = cortex_m::interrupt::free(|cs| MS_COUNTER.borrow(cs).get());
86+
let current_ms = critical_section::with(|cs| MS_COUNTER.borrow(cs).get());
8787
if current_ms - last_ms >= 1000 {
88-
last_ms = current_ms;
88+
// To prevent drift.
89+
last_ms += 1000;
8990
rprintln!("MS counter: {}", current_ms);
90-
let second = cortex_m::interrupt::free(|cs| SEC_COUNTER.borrow(cs).get());
91+
let second = critical_section::with(|cs| SEC_COUNTER.borrow(cs).get());
9192
rprintln!("Second counter: {}", second);
9293
}
9394
cortex_m::asm::delay(10000);
@@ -110,7 +111,7 @@ fn OC0() {
110111
#[interrupt]
111112
#[allow(non_snake_case)]
112113
fn OC1() {
113-
cortex_m::interrupt::free(|cs| {
114+
critical_section::with(|cs| {
114115
let mut sec = SEC_COUNTER.borrow(cs).get();
115116
sec += 1;
116117
SEC_COUNTER.borrow(cs).set(sec);

va108xx-hal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ embedded-hal-nb = "1"
1919
embedded-io = "0.6"
2020
fugit = "0.3"
2121
typenum = "1"
22+
critical-section = "1"
2223
delegate = "0.12"
2324

2425
[dependencies.va108xx]

va108xx-hal/src/timer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{
2020
typelevel::Sealed,
2121
};
2222
use core::cell::Cell;
23-
use cortex_m::interrupt::Mutex;
23+
use critical_section::Mutex;
2424
use fugit::RateExtU32;
2525

2626
const IRQ_DST_NONE: u32 = 0xffffffff;
@@ -729,7 +729,7 @@ pub fn set_up_ms_delay_provider<TIM: ValidTim>(
729729
/// This function can be called in a specified interrupt handler to increment
730730
/// the MS counter
731731
pub fn default_ms_irq_handler() {
732-
cortex_m::interrupt::free(|cs| {
732+
critical_section::with(|cs| {
733733
let mut ms = MS_COUNTER.borrow(cs).get();
734734
ms += 1;
735735
MS_COUNTER.borrow(cs).set(ms);
@@ -738,7 +738,7 @@ pub fn default_ms_irq_handler() {
738738

739739
/// Get the current MS tick count
740740
pub fn get_ms_ticks() -> u32 {
741-
cortex_m::interrupt::free(|cs| MS_COUNTER.borrow(cs).get())
741+
critical_section::with(|cs| MS_COUNTER.borrow(cs).get())
742742
}
743743

744744
//==================================================================================================

0 commit comments

Comments
 (0)