Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a78c497

Browse filesBrowse files
bors[bot]tmplt
andauthored
Merge #363
363: scb: derive serde, Hash, PartialOrd for VectActive behind gates r=thalesfragoso a=tmplt Exposes two new feature gates for VectActive serde::{Serialize, Deserialize} (via "serde") and Hash, PartialOrd (via "std-map") for use on host-side ITM tracing programs. While the struct itself is not received directly over ITM, its use greatly simplifies the implementation by allowing VectActive as keys in map collections and file/socket {,de}serialization to forward the structure elsewhere. These features are not enabled by default. Before this patch, serde functionality could be realized via [0], but this does not propagate down a dependency chain (i.e. if realized for crate B, which crate A depends on, serde functionality is not exposed in crate A unless VectActive is wrapped in a type from crate B). I am not aware of any method to realize PartialOrd, Hash derivation for a downstream crate. [0] https://serde.rs/remote-derive.html Co-authored-by: Viktor Sonesten <v@tmplt.dev>
2 parents 6b01313 + 74e9bbe commit a78c497
Copy full SHA for a78c497

File tree

6 files changed

+44
-4
lines changed
Filter options

6 files changed

+44
-4
lines changed

‎Cargo.toml

Copy file name to clipboardExpand all lines: Cargo.toml
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ volatile-register = "0.2.0"
2121
bitfield = "0.13.2"
2222
embedded-hal = "0.2.4"
2323

24+
[dependencies.serde]
25+
version = "1"
26+
features = [ "derive" ]
27+
optional = true
28+
2429
[features]
2530
cm7 = []
2631
cm7-r0p1 = ["cm7"]
2732
inline-asm = []
2833
linker-plugin-lto = []
34+
std-map = []
2935

3036
[workspace]
3137
members = ["xtask", "cortex-m-semihosting", "panic-semihosting", "panic-itm"]

‎src/peripheral/scb.rs

Copy file name to clipboardExpand all lines: src/peripheral/scb.rs
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use super::CBP;
1111
#[cfg(not(armv6m))]
1212
use super::CPUID;
1313
use super::SCB;
14+
#[cfg(feature = "serde")]
15+
use serde::{Deserialize, Serialize};
1416

1517
/// Register block
1618
#[repr(C)]
@@ -194,6 +196,8 @@ impl SCB {
194196

195197
/// Processor core exceptions (internal interrupts)
196198
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
199+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
200+
#[cfg_attr(feature = "std-map", derive(PartialOrd, Hash))]
197201
pub enum Exception {
198202
/// Non maskable interrupt
199203
NonMaskableInt,
@@ -259,6 +263,8 @@ impl Exception {
259263

260264
/// Active exception number
261265
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
266+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
267+
#[cfg_attr(feature = "std-map", derive(PartialOrd, Hash))]
262268
pub enum VectActive {
263269
/// Thread mode
264270
ThreadMode,

‎xtask/Cargo.toml

Copy file name to clipboardExpand all lines: xtask/Cargo.toml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ harness = false
1111

1212
[dependencies]
1313
ar = "0.8.0"
14+
cortex-m = { path = "../", features = ["serde", "std-map"] }
15+
serde_json = "1"

‎xtask/src/lib.rs

Copy file name to clipboardExpand all lines: xtask/src/lib.rs
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,24 @@ pub fn check_blobs() {
208208

209209
println!("Blobs identical.");
210210
}
211+
212+
// Check that serde and PartialOrd works with VectActive
213+
pub fn check_host_side() {
214+
use cortex_m::peripheral::scb::VectActive;
215+
216+
// check serde
217+
{
218+
let v = VectActive::from(22).unwrap();
219+
let json = serde_json::to_string(&v).expect("Failed to serialize VectActive");
220+
let deser_v: VectActive =
221+
serde_json::from_str(&json).expect("Failed to deserialize VectActive");
222+
assert_eq!(deser_v, v);
223+
}
224+
225+
// check PartialOrd
226+
{
227+
let a = VectActive::from(19).unwrap();
228+
let b = VectActive::from(20).unwrap();
229+
assert_eq!(a < b, true);
230+
}
231+
}

‎xtask/src/main.rs

Copy file name to clipboardExpand all lines: xtask/src/main.rs
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
use std::{env, process};
2-
use xtask::{assemble_blobs, check_blobs};
2+
use xtask::{assemble_blobs, check_blobs, check_host_side};
33

44
fn main() {
55
let subcommand = env::args().skip(1).next();
66
match subcommand.as_ref().map(|s| &**s) {
77
Some("assemble") => assemble_blobs(),
88
Some("check-blobs") => check_blobs(),
9+
Some("check-host-side") => check_host_side(),
910
_ => {
1011
eprintln!("usage: cargo xtask <subcommand>");
1112
eprintln!();
1213
eprintln!("subcommands:");
13-
eprintln!(" assemble Reassemble the pre-built artifacts");
14-
eprintln!(" check-blobs Check that the pre-built artifacts are up-to-date and reproducible");
14+
eprintln!(" assemble Reassemble the pre-built artifacts");
15+
eprintln!(" check-blobs Check that the pre-built artifacts are up-to-date and reproducible");
16+
eprintln!(" check-host-side Build the crate in a non-Cortex-M host application and check host side usage of certain types");
1517
process::exit(1);
1618
}
1719
}

‎xtask/tests/ci.rs

Copy file name to clipboardExpand all lines: xtask/tests/ci.rs
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::process::Command;
22
use std::{env, str};
3-
use xtask::{check_blobs, install_targets};
3+
use xtask::{check_blobs, check_host_side, install_targets};
44

55
/// List of all compilation targets we support.
66
///
@@ -105,4 +105,7 @@ fn main() {
105105
let is_nightly = str::from_utf8(&output.stdout).unwrap().contains("nightly");
106106

107107
check_crates_build(is_nightly);
108+
109+
// Check host-side applications of the crate.
110+
check_host_side();
108111
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.