Skip to content

Commit 159ce19

Browse files
committed
scb: derive serde, Hash, PartialOrd for VectActive behind gates
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
1 parent 6b01313 commit 159ce19

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ volatile-register = "0.2.0"
2121
bitfield = "0.13.2"
2222
embedded-hal = "0.2.4"
2323

24+
[dependencies.serde_crate]
25+
package = "serde"
26+
version = "1"
27+
features = [ "derive" ]
28+
optional = true
29+
2430
[features]
2531
cm7 = []
2632
cm7-r0p1 = ["cm7"]
2733
inline-asm = []
2834
linker-plugin-lto = []
35+
serde = [ "serde_crate" ]
36+
std-map = []
2937

3038
[workspace]
3139
members = ["xtask", "cortex-m-semihosting", "panic-semihosting", "panic-itm"]

src/peripheral/scb.rs

Lines 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_crate::{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), serde(crate = "serde_crate"))]
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), serde(crate = "serde_crate"))]
267+
#[cfg_attr(feature = "std-map", derive(PartialOrd, Hash))]
262268
pub enum VectActive {
263269
/// Thread mode
264270
ThreadMode,

0 commit comments

Comments
 (0)