Skip to content

Commit 67bdf68

Browse files
bors[bot]burrbull
andauthored
Merge #366
366: update dependencies r=therealprof a=burrbull Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
2 parents 25702c0 + e809bca commit 67bdf68

File tree

9 files changed

+198
-195
lines changed

9 files changed

+198
-195
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Breaking changes
1111

12+
- Bump `stm32f1` to `0.14.0`, `cortex-m-rtic` to `0.6.0-rc2` and others
1213
- Bump `stm32-usbd` dependency (`0.6.0`)
1314
- Use bit-banding for Peripheral enable/reset.
1415
Don't require APBs in initializers.

Cargo.toml

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,15 @@ features = ["stm32f103", "rt"]
1616
default-target = "x86_64-unknown-linux-gnu"
1717

1818
[dependencies]
19-
cortex-m = "0.6.0"
20-
nb = "0.1.2"
21-
cortex-m-rt = "0.6.8"
22-
stm32f1 = "0.11.0"
19+
cortex-m = "0.7"
20+
cortex-m-rt = "0.7"
21+
nb = "1"
22+
stm32f1 = "0.14.0"
2323
embedded-dma = "0.1.2"
2424
bxcan = ">=0.4, <0.6"
25-
26-
[dependencies.void]
27-
default-features = false
28-
version = "1.0.2"
29-
30-
[dependencies.cast]
31-
default-features = false
32-
version = "0.2.2"
33-
34-
[dependencies.embedded-hal]
35-
version = "0.2.3"
36-
features = ["unproven"]
25+
cast = { default-features = false, version = "0.3.0" }
26+
void = { default-features = false, version = "1.0.2" }
27+
embedded-hal = { features = ["unproven"], version = "0.2.6" }
3728

3829
[dependencies.stm32-usbd]
3930
version = "0.6.0"
@@ -43,34 +34,19 @@ optional = true
4334
panic-halt = "0.2.0"
4435
panic-semihosting = "0.5.2"
4536
panic-itm = "0.4.1"
46-
cortex-m-rtic = "0.5"
37+
cortex-m-rtic = "0.6.0-rc.2"
4738
cortex-m-semihosting = "0.3.3"
48-
heapless = "0.5.6"
39+
heapless = "0.7.7"
4940
m = "0.1.1"
5041
mfrc522 = "0.2.0"
51-
serde_derive = "1.0.90"
52-
usb-device = "0.2.3"
53-
usbd-serial = "0.1.0"
54-
55-
[dev-dependencies.byteorder]
56-
default-features = false
57-
version = "1.3.1"
58-
59-
[dev-dependencies.cobs]
60-
default-features = false
61-
version = "0.1.4"
62-
63-
[dev-dependencies.crc16]
64-
default-features = false
65-
version = "0.4.0"
66-
67-
[dev-dependencies.either]
68-
default-features = false
69-
version = "1.5.2"
70-
71-
[dev-dependencies.serde]
72-
default-features = false
73-
version = "1.0.90"
42+
usb-device = "0.2.8"
43+
usbd-serial = "0.1.1"
44+
byteorder = { default-features = false, version = "1.4.3" }
45+
cobs = { default-features = false, version = "0.1.4" }
46+
crc16 = { default-features = false, version = "0.4.0" }
47+
either = { default-features = false, version = "1.6.1" }
48+
serde = { default-features = false, version = "1.0.130"}
49+
serde_derive = "1.0.130"
7450

7551
[features]
7652
device-selected = []

examples/can-rtic.rs

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,14 @@
1111
#![no_main]
1212
#![no_std]
1313

14+
use panic_halt as _;
15+
16+
use bxcan::Frame;
1417
use core::cmp::Ordering;
1518

16-
use bxcan::{filter::Mask32, ExtendedId, Frame, Interrupts, Rx, StandardId, Tx};
17-
use heapless::{
18-
binary_heap::{BinaryHeap, Max},
19-
consts::*,
20-
};
21-
use nb::block;
22-
use panic_halt as _;
23-
use rtic::app;
24-
use stm32f1xx_hal::{
25-
can::Can,
26-
pac::{Interrupt, CAN1},
27-
prelude::*,
28-
};
19+
use heapless::binary_heap::{BinaryHeap, Max};
20+
21+
use stm32f1xx_hal::pac::Interrupt;
2922

3023
#[derive(Debug)]
3124
pub struct PriorityFrame(Frame);
@@ -52,22 +45,31 @@ impl PartialEq for PriorityFrame {
5245

5346
impl Eq for PriorityFrame {}
5447

55-
fn enqueue_frame(queue: &mut BinaryHeap<PriorityFrame, U16, Max>, frame: Frame) {
48+
fn enqueue_frame(queue: &mut BinaryHeap<PriorityFrame, Max, 16>, frame: Frame) {
5649
queue.push(PriorityFrame(frame)).unwrap();
5750
rtic::pend(Interrupt::USB_HP_CAN_TX);
5851
}
5952

60-
#[app(device = stm32f1xx_hal::pac, peripherals = true)]
61-
const APP: () = {
62-
struct Resources {
53+
#[rtic::app(device = stm32f1xx_hal::pac)]
54+
mod app {
55+
use super::{enqueue_frame, PriorityFrame};
56+
use bxcan::{filter::Mask32, ExtendedId, Frame, Interrupts, Rx, StandardId, Tx};
57+
use heapless::binary_heap::{BinaryHeap, Max};
58+
use stm32f1xx_hal::{can::Can, pac::CAN1, prelude::*};
59+
60+
#[local]
61+
struct Local {
6362
can_tx: Tx<Can<CAN1>>,
64-
can_tx_queue: BinaryHeap<PriorityFrame, U16, Max>,
65-
tx_count: usize,
6663
can_rx: Rx<Can<CAN1>>,
6764
}
65+
#[shared]
66+
struct Shared {
67+
can_tx_queue: BinaryHeap<PriorityFrame, Max, 16>,
68+
tx_count: usize,
69+
}
6870

6971
#[init]
70-
fn init(cx: init::Context) -> init::LateResources {
72+
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
7173
let mut flash = cx.device.FLASH.constrain();
7274
let rcc = cx.device.RCC.constrain();
7375

@@ -105,23 +107,25 @@ const APP: () = {
105107
can.enable_interrupts(
106108
Interrupts::TRANSMIT_MAILBOX_EMPTY | Interrupts::FIFO0_MESSAGE_PENDING,
107109
);
108-
block!(can.enable()).unwrap();
110+
nb::block!(can.enable()).unwrap();
109111

110112
let (can_tx, can_rx) = can.split();
111113

112114
let can_tx_queue = BinaryHeap::new();
113115

114-
init::LateResources {
115-
can_tx,
116-
can_tx_queue,
117-
tx_count: 0,
118-
can_rx,
119-
}
116+
(
117+
Shared {
118+
can_tx_queue,
119+
tx_count: 0,
120+
},
121+
Local { can_tx, can_rx },
122+
init::Monotonics(),
123+
)
120124
}
121125

122-
#[idle(resources = [can_tx_queue, tx_count])]
126+
#[idle(shared = [can_tx_queue, tx_count])]
123127
fn idle(mut cx: idle::Context) -> ! {
124-
let mut tx_queue = cx.resources.can_tx_queue;
128+
let mut tx_queue = cx.shared.can_tx_queue;
125129

126130
// Enqueue some messages. Higher ID means lower priority.
127131
tx_queue.lock(|mut tx_queue| {
@@ -155,7 +159,7 @@ const APP: () = {
155159

156160
// Add some higher priority messages when 3 messages have been sent.
157161
loop {
158-
let tx_count = cx.resources.tx_count.lock(|tx_count| *tx_count);
162+
let tx_count = cx.shared.tx_count.lock(|tx_count| *tx_count);
159163

160164
if tx_count >= 3 {
161165
tx_queue.lock(|mut tx_queue| {
@@ -196,45 +200,50 @@ const APP: () = {
196200
}
197201

198202
// This ISR is triggered by each finished frame transmission.
199-
#[task(binds = USB_HP_CAN_TX, resources = [can_tx, can_tx_queue, tx_count])]
203+
#[task(binds = USB_HP_CAN_TX, local = [can_tx], shared = [can_tx_queue, tx_count])]
200204
fn can_tx(cx: can_tx::Context) {
201-
let tx = cx.resources.can_tx;
202-
let tx_queue = cx.resources.can_tx_queue;
205+
let tx = cx.local.can_tx;
206+
let mut tx_queue = cx.shared.can_tx_queue;
207+
let mut tx_count = cx.shared.tx_count;
203208

204209
tx.clear_interrupt_flags();
205210

206211
// There is now a free mailbox. Try to transmit pending frames until either
207212
// the queue is empty or transmission would block the execution of this ISR.
208-
while let Some(frame) = tx_queue.peek() {
209-
match tx.transmit(&frame.0) {
210-
Ok(None) => {
211-
// Frame was successfully placed into a transmit buffer.
212-
tx_queue.pop();
213-
*cx.resources.tx_count += 1;
213+
(&mut tx_queue, &mut tx_count).lock(|tx_queue, tx_count| {
214+
while let Some(frame) = tx_queue.peek() {
215+
match tx.transmit(&frame.0) {
216+
Ok(None) => {
217+
// Frame was successfully placed into a transmit buffer.
218+
tx_queue.pop();
219+
*tx_count += 1;
220+
}
221+
Ok(Some(pending_frame)) => {
222+
// A lower priority frame was replaced with our high priority frame.
223+
// Put the low priority frame back in the transmit queue.
224+
tx_queue.pop();
225+
enqueue_frame(tx_queue, pending_frame);
226+
}
227+
Err(nb::Error::WouldBlock) => break,
228+
Err(_) => unreachable!(),
214229
}
215-
Ok(Some(pending_frame)) => {
216-
// A lower priority frame was replaced with our high priority frame.
217-
// Put the low priority frame back in the transmit queue.
218-
tx_queue.pop();
219-
enqueue_frame(tx_queue, pending_frame);
220-
}
221-
Err(nb::Error::WouldBlock) => break,
222-
Err(_) => unreachable!(),
223230
}
224-
}
231+
});
225232
}
226233

227-
#[task(binds = USB_LP_CAN_RX0, resources = [can_rx, can_tx_queue])]
228-
fn can_rx0(cx: can_rx0::Context) {
234+
#[task(binds = USB_LP_CAN_RX0, local = [can_rx], shared = [can_tx_queue])]
235+
fn can_rx0(mut cx: can_rx0::Context) {
229236
// Echo back received packages with correct priority ordering.
230237
loop {
231-
match cx.resources.can_rx.receive() {
238+
match cx.local.can_rx.receive() {
232239
Ok(frame) => {
233-
enqueue_frame(cx.resources.can_tx_queue, frame);
240+
cx.shared.can_tx_queue.lock(|can_tx_queue| {
241+
enqueue_frame(can_tx_queue, frame);
242+
});
234243
}
235244
Err(nb::Error::WouldBlock) => break,
236245
Err(nb::Error::Other(_)) => {} // Ignore overrun errors.
237246
}
238247
}
239248
}
240-
};
249+
}

examples/exti_rtic.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
#![no_std]
44
#![no_main]
55

6-
extern crate rtic;
7-
86
use panic_halt as _;
9-
use rtic::app;
10-
use stm32f1xx_hal::{
11-
gpio::{gpioa::PA0, gpioc::PC13, Edge, ExtiPin, Input, Output, PullDown, PushPull},
12-
prelude::*,
13-
};
14-
15-
#[app(device = stm32f1xx_hal::pac, peripherals = true)]
16-
const APP: () = {
17-
struct Resources {
7+
8+
#[rtic::app(device = stm32f1xx_hal::pac)]
9+
mod app {
10+
use stm32f1xx_hal::{
11+
gpio::{gpioa::PA0, gpioc::PC13, Edge, ExtiPin, Input, Output, PullDown, PushPull},
12+
prelude::*,
13+
};
14+
15+
#[shared]
16+
struct Shared {}
17+
18+
#[local]
19+
struct Local {
1820
button: PA0<Input<PullDown>>,
1921
led: PC13<Output<PushPull>>,
2022
}
2123

2224
#[init]
23-
fn init(mut ctx: init::Context) -> init::LateResources {
25+
fn init(mut ctx: init::Context) -> (Shared, Local, init::Monotonics) {
2426
let mut afio = ctx.device.AFIO.constrain();
2527

2628
let mut gpioc = ctx.device.GPIOC.split();
@@ -32,12 +34,12 @@ const APP: () = {
3234
button.enable_interrupt(&mut ctx.device.EXTI);
3335
button.trigger_on_edge(&mut ctx.device.EXTI, Edge::Rising);
3436

35-
init::LateResources { button, led }
37+
(Shared {}, Local { button, led }, init::Monotonics())
3638
}
3739

38-
#[task(binds = EXTI0, resources = [button, led])]
40+
#[task(binds = EXTI0, local = [button, led])]
3941
fn button_click(ctx: button_click::Context) {
40-
ctx.resources.button.clear_interrupt_pending_bit();
41-
ctx.resources.led.toggle();
42+
ctx.local.button.clear_interrupt_pending_bit();
43+
ctx.local.led.toggle();
4244
}
43-
};
45+
}

examples/panics.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Prints "Hello, world" on the OpenOCD console
22
3-
#![deny(unsafe_code)]
43
#![no_main]
54
#![no_std]
65

@@ -18,11 +17,11 @@ fn main() -> ! {
1817
}
1918

2019
#[exception]
21-
fn HardFault(ef: &ExceptionFrame) -> ! {
20+
unsafe fn HardFault(ef: &ExceptionFrame) -> ! {
2221
panic!("{:#?}", ef);
2322
}
2423

2524
#[exception]
26-
fn DefaultHandler(irqn: i16) {
25+
unsafe fn DefaultHandler(irqn: i16) {
2726
panic!("Unhandled exception (IRQn = {})", irqn);
2827
}

0 commit comments

Comments
 (0)