1#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
5#[repr(u8)]
6#[cfg_attr(feature = "defmt", derive(defmt::Format))]
7pub enum CoreId {
8 #[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757))]
9 Core0 = 0x3,
11
12 #[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757))]
13 Core1 = 0x1,
15
16 #[cfg(not(any(stm32h745, stm32h747, stm32h755, stm32h757)))]
17 Core0 = 0x4,
19
20 #[cfg(any(stm32wb, stm32wl))]
21 Core1 = 0x8,
23}
24
25impl CoreId {
26 pub fn current() -> Self {
29 let cpuid = unsafe { cortex_m::peripheral::CPUID::PTR.read_volatile().base.read() };
30 match (cpuid & 0x000000F0) >> 4 {
31 #[cfg(any(stm32wb, stm32wl))]
32 0x0 => CoreId::Core1,
33
34 #[cfg(not(any(stm32h745, stm32h747, stm32h755, stm32h757)))]
35 0x4 => CoreId::Core0,
36
37 #[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757))]
38 0x4 => CoreId::Core1,
39
40 #[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757))]
41 0x7 => CoreId::Core0,
42 _ => panic!("Unknown Cortex-M core"),
43 }
44 }
45
46 #[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757, stm32wb, stm32wl))]
47 pub const fn other(&self) -> Self {
49 match &self {
50 Self::Core0 => Self::Core1,
51 Self::Core1 => Self::Core0,
52 }
53 }
54
55 pub const fn to_index(&self) -> usize {
57 match &self {
58 CoreId::Core0 => 0,
59 #[cfg(any(stm32h745, stm32h747, stm32h755, stm32h757, stm32wb, stm32wl))]
60 CoreId::Core1 => 1,
61 }
62 }
63}