Skip to content

Commit 6f59f1e

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

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

embassy-stm32/src/hsem.rs

Lines changed: 19 additions & 5 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,19 @@ 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+
feature = "_core-cm7",
44+
not(feature = "_core-cm4")
45+
))]
4146
const fn current() -> CoreId {
4247
CoreId::Core0
4348
}
4449

45-
#[cfg(feature = "_core-cm4")]
50+
#[cfg(any(
51+
all(not(stm32wl), feature = "_core-cm4"),
52+
all(stm32wl, feature = "_core-cm0p")
53+
))]
4654
const fn current() -> CoreId {
4755
CoreId::Core1
4856
}
@@ -86,7 +94,10 @@ impl<'d> HardwareSemaphore<'d> {
8694
reg.procid() == process_id,
8795
) {
8896
(true, true, true) => Ok(()),
89-
_ => Err(HsemLockFailed),
97+
v => {
98+
error!("{}: {}", v, CoreId::current() as u8);
99+
Err(HsemLockFailed)
100+
}
90101
}
91102
}
92103

@@ -97,9 +108,12 @@ impl<'d> HardwareSemaphore<'d> {
97108
pub fn one_step_lock(&mut self, sem_id: u8) -> Result<(), HsemLockFailed> {
98109
let reg = HSEM.rlr(sem_id as usize).read();
99110

100-
match (reg.lock(), reg.coreid() == CoreId::current() as u8, reg.procid()) {
111+
match (reg.lock(), reg.coreid() == CoreId::current() as u8, reg.procid()) {
101112
(_, true, 0) => Ok(()),
102-
_ => Err(HsemLockFailed),
113+
v => {
114+
error!("{}: Current: {} Actual: {}", v, CoreId::current() as u8, reg.coreid());
115+
Err(HsemLockFailed)
116+
}
103117
}
104118
}
105119

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)