Skip to content

Commit d3f1368

Browse files
committed
fix examples
1 parent 8df358d commit d3f1368

File tree

8 files changed

+60
-44
lines changed

8 files changed

+60
-44
lines changed

examples/adc_ext_trig_double_dma_serial.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ unsafe fn DMA_CHANNEL1() {
6363
// Address is in byte, value in 2Bytes, this is why second dma buffer ist added with BUFFER_SIZE
6464
// and not BUFFER_SIZE/2
6565

66-
let dma = &(*stm32g0::stm32g031::DMA::ptr());
66+
let dma = &(*hal::stm32::DMA::ptr());
6767
let htif1 = dma.isr.read().htif1().bit();
6868
let tcif1 = dma.isr.read().tcif1().bit();
6969
// set the global clear bit of DMA channel1
@@ -107,7 +107,7 @@ fn main() -> ! {
107107

108108
let mut dma = dp.DMA.split(&mut rcc, dp.DMAMUX);
109109

110-
let adc_ptr = unsafe { &(*stm32g0::stm32g031::ADC::ptr()) };
110+
let adc_ptr = unsafe { &(*hal::stm32::ADC::ptr()) };
111111
let adc_data_register_addr = &adc_ptr.dr as *const _ as u32;
112112

113113
let adc_buffer1_addr: u32 = adc_buffer1.as_ptr() as u32;
@@ -125,8 +125,7 @@ fn main() -> ! {
125125
// https://sourceware.org/gdb/current/onlinedocs/gdb/Memory.html
126126

127127
// dma ch1 reads from ADC register into memory
128-
dma.ch1
129-
.select_peripheral(stm32g0xx_hal::dmamux::DmaMuxIndex::ADC);
128+
dma.ch1.select_peripheral(hal::dmamux::DmaMuxIndex::ADC);
130129
// The dma continuesly fills the buffer, when its full, it starts over again
131130
dma.ch1.set_circular_mode(true);
132131

@@ -180,7 +179,7 @@ fn main() -> ! {
180179
// this is only available on timer TIM2, TIM3, TIM4 and TIM1
181180
unsafe {
182181
// get pointer of timer 2
183-
let tim = &(*stm32g0::stm32g031::TIM2::ptr());
182+
let tim = &(*hal::stm32::TIM2::ptr());
184183
//
185184
tim.cr2.modify(|_, w| w.mms().bits(3 as u8));
186185
}

examples/ir_remote.rs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use infrared::protocols::nec::NecCommand;
2020
use infrared::{protocols::Nec, Sender};
2121
use rtic::app;
2222

23-
const IR_SAMPLERATE: Hertz = Hertz(20_000);
23+
const IR_SAMPLERATE: Hertz = Hertz::kHz(20);
2424
const STROBE_COMMAND: NecCommand = NecCommand {
2525
addr: 0,
2626
cmd: 15,
@@ -31,15 +31,22 @@ type IrPin = PwmPin<stm32::TIM17, timer::Channel1>;
3131
type IrTimer = Timer<stm32::TIM16>;
3232

3333
#[app(device = hal::stm32, peripherals = true)]
34-
const APP: () = {
35-
struct Resources {
36-
timer: IrTimer,
34+
mod app {
35+
use super::*;
36+
37+
#[shared]
38+
struct Shared {
3739
transmitter: Sender<Nec, IrPin>,
40+
}
41+
42+
#[local]
43+
struct Local {
44+
timer: IrTimer,
3845
exti: stm32::EXTI,
3946
}
4047

4148
#[init]
42-
fn init(mut ctx: init::Context) -> init::LateResources {
49+
fn init(mut ctx: init::Context) -> (Shared, Local, init::Monotonics) {
4350
let mut rcc = ctx.device.RCC.freeze(rcc::Config::pll());
4451

4552
let gpiob = ctx.device.GPIOB.split(&mut rcc);
@@ -48,33 +55,35 @@ const APP: () = {
4855
gpioc.pc13.listen(SignalEdge::Falling, &mut ctx.device.EXTI);
4956

5057
let mut timer = ctx.device.TIM16.timer(&mut rcc);
51-
timer.start(IR_SAMPLERATE);
58+
timer.start(IR_SAMPLERATE.into_duration());
5259
timer.listen();
5360

5461
let carrier_timer = ctx.device.TIM17.pwm(38.kHz(), &mut rcc);
5562
let mut ir_pin = carrier_timer.bind_pin(gpiob.pb9);
5663
ir_pin.set_duty(ir_pin.get_max_duty() / 2);
57-
let transmitter = Sender::new(IR_SAMPLERATE.0, ir_pin);
64+
let transmitter = Sender::new(IR_SAMPLERATE.raw(), ir_pin);
5865

59-
init::LateResources {
60-
timer,
61-
transmitter,
62-
exti: ctx.device.EXTI,
63-
}
66+
(
67+
Shared { transmitter },
68+
Local {
69+
timer,
70+
exti: ctx.device.EXTI,
71+
},
72+
init::Monotonics(),
73+
)
6474
}
6575

66-
#[task(binds = TIM16, resources = [timer, transmitter])]
67-
fn timer_tick(ctx: timer_tick::Context) {
68-
ctx.resources.transmitter.tick();
69-
ctx.resources.timer.clear_irq();
76+
#[task(binds = TIM16, local = [timer], shared = [transmitter])]
77+
fn timer_tick(mut ctx: timer_tick::Context) {
78+
ctx.shared.transmitter.lock(|tx| tx.tick());
79+
ctx.local.timer.clear_irq();
7080
}
7181

72-
#[task(binds = EXTI4_15, resources = [exti, transmitter])]
73-
fn button_click(ctx: button_click::Context) {
74-
ctx.resources
82+
#[task(binds = EXTI4_15, local = [exti], shared = [transmitter])]
83+
fn button_click(mut ctx: button_click::Context) {
84+
ctx.shared
7585
.transmitter
76-
.load(&STROBE_COMMAND)
77-
.expect("failed to send IR command");
78-
ctx.resources.exti.unpend(Event::GPIO13);
86+
.lock(|tx| tx.load(&STROBE_COMMAND).expect("failed to send IR command"));
87+
ctx.local.exti.unpend(Event::GPIO13);
7988
}
80-
};
89+
}

examples/opm.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,21 @@ use hal::timer::opm::Opm;
1818
use rtic::app;
1919

2020
#[app(device = hal::stm32, peripherals = true)]
21-
const APP: () = {
22-
struct Resources {
21+
mod app {
22+
use super::*;
23+
24+
#[shared]
25+
struct Shared {}
26+
27+
#[local]
28+
struct Local {
2329
exti: stm32::EXTI,
2430
led: PA5<Output<PushPull>>,
2531
opm: Opm<stm32::TIM3>,
2632
}
2733

2834
#[init]
29-
fn init(ctx: init::Context) -> init::LateResources {
35+
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
3036
let mut rcc = ctx.device.RCC.freeze(rcc::Config::pll());
3137
let mut exti = ctx.device.EXTI;
3238

@@ -55,13 +61,13 @@ const APP: () = {
5561
opm_ch3.enable();
5662
opm_ch4.enable();
5763

58-
init::LateResources { opm, exti, led }
64+
(Shared {}, Local { opm, exti, led }, init::Monotonics())
5965
}
6066

61-
#[task(binds = EXTI4_15, resources = [exti, led, opm])]
67+
#[task(binds = EXTI4_15, local = [exti, led, opm])]
6268
fn button_click(ctx: button_click::Context) {
63-
ctx.resources.led.toggle().unwrap();
64-
ctx.resources.opm.generate();
65-
ctx.resources.exti.unpend(Event::GPIO13);
69+
ctx.local.led.toggle().unwrap();
70+
ctx.local.opm.generate();
71+
ctx.local.exti.unpend(Event::GPIO13);
6672
}
67-
};
73+
}

examples/rtic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ mod app {
4040
let gpioc = ctx.device.GPIOC.split(&mut rcc);
4141

4242
let mut timer = ctx.device.TIM17.timer(&mut rcc);
43-
timer.start(3.Hz());
43+
timer.start(Hertz::Hz(3).into_duration());
4444
timer.listen();
4545

4646
let mut exti = ctx.device.EXTI;

examples/stopwatch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ fn main() -> ! {
3434
let elapsed_us = stopwatch.trace(|| {
3535
delay.delay(100.micros());
3636
});
37-
hprintln!("Delay: 100 us -> {} us", elapsed_us.0).unwrap();
37+
hprintln!("Delay: 100 us -> {}", elapsed_us).unwrap();
3838

3939
timer.start(100.micros());
4040
let elapsed_us = stopwatch.trace(|| {
4141
block!(timer.wait()).unwrap();
4242
});
43-
hprintln!("Timer: 100 us -> {} us", elapsed_us.0).unwrap();
43+
hprintln!("Timer: 100 us -> {}", elapsed_us).unwrap();
4444

4545
let elapsed_us = stopwatch.trace(calc_something);
46-
hprintln!("Calc @ 16 MHz: {} us", elapsed_us.0).unwrap();
46+
hprintln!("Calc @ 16 MHz: {}", elapsed_us).unwrap();
4747

4848
let rcc = rcc.freeze(Config::new(SysClockSrc::PLL));
4949
stopwatch.set_clock(rcc.clocks.apb_tim_clk);
5050

5151
let elapsed_us = stopwatch.trace(calc_something);
52-
hprintln!("Calc @ 64 MHz: {} us", elapsed_us.0).unwrap();
52+
hprintln!("Calc @ 64 MHz: {}", elapsed_us).unwrap();
5353

5454
loop {}
5555
}

examples/uart-dma.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ fn main() -> ! {
1919
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
2020
let mut rcc = dp.RCC.constrain();
2121
let gpioa = dp.GPIOA.split(&mut rcc);
22-
let gpiob = dp.GPIOB.split(&mut rcc);
2322

2423
let mut led = gpioa.pa5.into_push_pull_output();
2524

src/analog/comparator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ macro_rules! impl_comparator {
258258
positive_input.setup(&self);
259259
negative_input.setup(&self);
260260
// Delay for scaler voltage bridge initialization for certain negative inputs
261-
let voltage_scaler_delay = clocks.sys_clk.0 / (1_000_000 / 200); // 200us
261+
let voltage_scaler_delay = clocks.sys_clk.raw() / (1_000_000 / 200); // 200us
262262
cortex_m::asm::delay(voltage_scaler_delay);
263263
self.csr().modify(|_, w| unsafe {
264264
w.hyst()

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub extern crate stm32g0;
1616

1717
pub use nb::block;
1818

19+
#[cfg(feature = "device-selected")]
20+
pub use stm32 as pac;
21+
1922
#[cfg(feature = "stm32g030")]
2023
pub use stm32g0::stm32g030 as stm32;
2124

0 commit comments

Comments
 (0)