Skip to content

Commit df06cd4

Browse files
committed
pexperimental change + test fix
1 parent 3162172 commit df06cd4

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

embassy-stm32/src/hsem.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct HsemLockFailed;
1111
///
1212
/// On some chips, the Reference Manual calls this value MASTERID instead of COREID.
1313
#[repr(u8)]
14+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1415
pub enum CoreId {
1516
#[cfg(any(stm32h7a3, stm32h7b3, stm32h7b0))]
1617
/// Cortex-M7, core 1. MASTERID = 1
@@ -37,12 +38,15 @@ pub enum CoreId {
3738
}
3839

3940
impl CoreId {
40-
#[cfg(any(feature = "_core-cm7", not(feature = "_core-cm4")))]
41+
#[cfg(any(
42+
all(stm32wl, feature = "_core-cm4"),
43+
all(not(stm32wl), any(feature = "_core-cm7", not(feature = "_core-cm4"))),
44+
))]
4145
const fn current() -> CoreId {
4246
CoreId::Core0
4347
}
4448

45-
#[cfg(feature = "_core-cm4")]
49+
#[cfg(any(all(not(stm32wl), feature = "_core-cm4"), all(stm32wl, feature = "_core-cm0p")))]
4650
const fn current() -> CoreId {
4751
CoreId::Core1
4852
}
@@ -86,7 +90,10 @@ impl<'d> HardwareSemaphore<'d> {
8690
reg.procid() == process_id,
8791
) {
8892
(true, true, true) => Ok(()),
89-
_ => Err(HsemLockFailed),
93+
v => {
94+
error!("{}: {}", v, CoreId::current() as u8);
95+
Err(HsemLockFailed)
96+
}
9097
}
9198
}
9299

@@ -99,7 +106,10 @@ impl<'d> HardwareSemaphore<'d> {
99106

100107
match (reg.lock(), reg.coreid() == CoreId::current() as u8, reg.procid()) {
101108
(_, true, 0) => Ok(()),
102-
_ => Err(HsemLockFailed),
109+
v => {
110+
error!("{}: Current: {} Actual: {}", v, CoreId::current() as u8, reg.coreid());
111+
Err(HsemLockFailed)
112+
}
103113
}
104114
}
105115

tests/stm32/src/bin/hsem.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ async fn main(_spawner: Spawner) {
1414
let p: embassy_stm32::Peripherals = init();
1515

1616
let mut hsem = HardwareSemaphore::new(p.HSEM);
17-
hsem.one_step_lock(1).unwrap();
17+
18+
if hsem.is_semaphore_locked(5) {
19+
defmt::panic!("Semaphore 5 already locked!")
20+
}
21+
22+
hsem.one_step_lock(5).unwrap();
1823
hsem.two_step_lock(1, 0).unwrap();
1924

2025
info!("Test OK");

0 commit comments

Comments
 (0)