Skip to content

Commit 240bf96

Browse files
committed
Update for new pac
1 parent c45373c commit 240bf96

File tree

10 files changed

+365
-476
lines changed

10 files changed

+365
-476
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ embedded-hal = { version = "0.2.6", features = ["unproven"] }
3232
embedded-dma = "0.2.0"
3333
cortex-m = { version = "^0.7.7", features = ["critical-section-single-core"] }
3434
defmt = { version = ">=0.2.0,<0.4", optional = true }
35-
stm32h7 = { version = "0.16.0", package = "stm32h7-staging", features = ["critical-section"], default-features = false }
35+
stm32h7 = { path = "../stm32-rs/stm32h7", features = ["critical-section"], default-features = false }
36+
#stm32h7 = { git = "https://github.com/stm32-rs/stm32-rs-nightlies", features = ["critical-section"], default-features = false }
37+
#stm32h7 = { version = "0.17.0", package = "stm32h7-staging", features = ["critical-section"], default-features = false }
3638
void = { version = "1.0.2", default-features = false }
3739
cast = { version = "0.3.0", default-features = false }
3840
nb = "1.0.0"

src/adc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,10 @@ macro_rules! adc_hal {
734734
/// Enable ADC
735735
pub fn enable(mut self) -> Adc<$ADC, Enabled> {
736736
// Refer to RM0433 Rev 7 - Chapter 25.4.9
737-
self.rb.isr().modify(|_, w| w.adrdy().set_bit());
738-
self.rb.cr().modify(|_, w| w.aden().set_bit());
737+
self.rb.isr().modify(|_, w| w.adrdy().clear());
738+
self.rb.cr().modify(|_, w| w.aden().enabled());
739739
while self.rb.isr().read().adrdy().bit_is_clear() {}
740-
self.rb.isr().modify(|_, w| w.adrdy().set_bit());
740+
self.rb.isr().modify(|_, w| w.adrdy().clear());
741741

742742
self.configure();
743743

src/dma/bdma.rs

Lines changed: 61 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -587,161 +587,78 @@ where
587587
}
588588
}
589589

590-
// Macro that creates a struct representing a stream on either BDMA controller
590+
// A struct representing a stream on either BDMA controller
591591
//
592592
// The implementation does the heavy lifting of mapping to the right fields on
593593
// the stream
594-
macro_rules! bdma_stream {
595-
($(($name:ident, $number:expr,
596-
$ifcr:ident, $tcif:ident, $htif:ident, $teif:ident, $gif:ident,
597-
$isr:ident, $tcisr:ident, $htisr:ident, $teisr:ident, $gisr:ident)
598-
),+$(,)*) => {
599-
$(
600-
impl<I: Instance> InstanceStream for StreamX<I, $number> {
601-
#[inline(always)]
602-
fn stream_clear_interrupts(&mut self) {
603-
//NOTE(unsafe) Atomic write with no side-effects and we only access the bits
604-
// that belongs to the StreamX
605-
let dma = unsafe { &*I::ptr() };
606-
dma.$ifcr().write(|w| w
607-
.$tcif().set_bit() //Clear transfer complete interrupt flag
608-
.$htif().set_bit() //Clear half transfer interrupt flag
609-
.$teif().set_bit() //Clear transfer error interrupt flag
610-
.$gif().set_bit() //Clear global interrupt flag
611-
);
612-
let _ = dma.$isr().read();
613-
let _ = dma.$isr().read(); // Delay 2 peripheral clocks
614-
}
594+
impl<I: Instance, const S: u8> InstanceStream for StreamX<I, S> {
595+
#[inline(always)]
596+
fn stream_clear_interrupts(&mut self) {
597+
//NOTE(unsafe) Atomic write with no side-effects and we only access the bits
598+
// that belongs to the StreamX
599+
let dma = unsafe { &*I::ptr() };
600+
dma.ifcr().write(|w| w
601+
.ctcif(S).set_bit() //Clear transfer complete interrupt flag
602+
.chtif(S).set_bit() //Clear half transfer interrupt flag
603+
.cteif(S).set_bit() //Clear transfer error interrupt flag
604+
.cgif(S).set_bit() //Clear global interrupt flag
605+
);
606+
let _ = dma.isr().read();
607+
let _ = dma.isr().read(); // Delay 2 peripheral clocks
608+
}
615609

616-
#[inline(always)]
617-
fn stream_clear_transfer_complete_flag(&mut self) {
618-
//NOTE(unsafe) Atomic write with no side-effects and we only access the bits
619-
// that belongs to the StreamX
620-
let dma = unsafe { &*I::ptr() };
621-
dma.$ifcr().write(|w| w.$tcif().set_bit());
622-
}
610+
#[inline(always)]
611+
fn stream_clear_transfer_complete_flag(&mut self) {
612+
//NOTE(unsafe) Atomic write with no side-effects and we only access the bits
613+
// that belongs to the StreamX
614+
let dma = unsafe { &*I::ptr() };
615+
dma.ifcr().write(|w| w.ctcif(S).set_bit());
616+
}
623617

624-
#[inline(always)]
625-
fn stream_clear_transfer_complete_interrupt(&mut self) {
626-
self.stream_clear_transfer_complete_flag();
627-
//NOTE(unsafe) Atomic read with no side-effects.
628-
let dma = unsafe { &*I::ptr() };
629-
let _ = dma.$isr().read();
630-
let _ = dma.$isr().read(); // Delay 2 peripheral clocks
631-
}
618+
#[inline(always)]
619+
fn stream_clear_transfer_complete_interrupt(&mut self) {
620+
self.stream_clear_transfer_complete_flag();
621+
//NOTE(unsafe) Atomic read with no side-effects.
622+
let dma = unsafe { &*I::ptr() };
623+
let _ = dma.isr().read();
624+
let _ = dma.isr().read(); // Delay 2 peripheral clocks
625+
}
632626

633-
#[inline(always)]
634-
fn stream_clear_transfer_error_interrupt(&mut self) {
635-
//NOTE(unsafe) Atomic write with no side-effects and we only access the bits
636-
// that belongs to the StreamX
637-
let dma = unsafe { &*I::ptr() };
638-
dma.$ifcr().write(|w| w.$teif().set_bit());
639-
let _ = dma.$isr().read();
640-
let _ = dma.$isr().read(); // Delay 2 peripheral clocks
641-
}
627+
#[inline(always)]
628+
fn stream_clear_transfer_error_interrupt(&mut self) {
629+
//NOTE(unsafe) Atomic write with no side-effects and we only access the bits
630+
// that belongs to the StreamX
631+
let dma = unsafe { &*I::ptr() };
632+
dma.ifcr().write(|w| w.cteif(S).set_bit());
633+
let _ = dma.isr().read();
634+
let _ = dma.isr().read(); // Delay 2 peripheral clocks
635+
}
642636

643-
#[inline(always)]
644-
fn stream_get_transfer_complete_flag() -> bool {
645-
//NOTE(unsafe) Atomic read with no side effects
646-
let dma = unsafe { &*I::ptr() };
647-
dma.$isr().read().$tcisr().bit_is_set()
648-
}
637+
#[inline(always)]
638+
fn stream_get_transfer_complete_flag() -> bool {
639+
//NOTE(unsafe) Atomic read with no side effects
640+
let dma = unsafe { &*I::ptr() };
641+
dma.isr().read().tcif(S).bit_is_set()
642+
}
649643

650-
#[inline(always)]
651-
fn stream_get_half_transfer_flag() -> bool {
652-
//NOTE(unsafe) Atomic read with no side effects
653-
let dma = unsafe { &*I::ptr() };
654-
dma.$isr().read().$htisr().bit_is_set()
655-
}
644+
#[inline(always)]
645+
fn stream_get_half_transfer_flag() -> bool {
646+
//NOTE(unsafe) Atomic read with no side effects
647+
let dma = unsafe { &*I::ptr() };
648+
dma.isr().read().htif(S).bit_is_set()
649+
}
656650

657-
#[inline(always)]
658-
fn stream_clear_half_transfer_interrupt(&mut self) {
659-
//NOTE(unsafe) Atomic write with no side-effects and we only access the bits
660-
// that belongs to the StreamX
661-
let dma = unsafe { &*I::ptr() };
662-
dma.$ifcr().write(|w| w.$htif().set_bit());
663-
let _ = dma.$isr().read();
664-
let _ = dma.$isr().read(); // Delay 2 peripheral clocks
665-
}
666-
}
667-
)+
668-
};
651+
#[inline(always)]
652+
fn stream_clear_half_transfer_interrupt(&mut self) {
653+
//NOTE(unsafe) Atomic write with no side-effects and we only access the bits
654+
// that belongs to the StreamX
655+
let dma = unsafe { &*I::ptr() };
656+
dma.ifcr().write(|w| w.chtif(S).set_bit());
657+
let _ = dma.isr().read();
658+
let _ = dma.isr().read(); // Delay 2 peripheral clocks
659+
}
669660
}
670661

671-
#[cfg(not(feature = "rm0468"))]
672-
bdma_stream!(
673-
// Note: the field names start from one, unlike the RM where they start from
674-
// zero. May need updating if it gets fixed upstream.
675-
(
676-
Stream0, 0, ifcr, ctcif1, chtif1, cteif1, cgif1, isr, tcif1, htif1,
677-
teif1, gif1
678-
),
679-
(
680-
Stream1, 1, ifcr, ctcif2, chtif2, cteif2, cgif2, isr, tcif2, htif2,
681-
teif2, gif2
682-
),
683-
(
684-
Stream2, 2, ifcr, ctcif3, chtif3, cteif3, cgif3, isr, tcif3, htif3,
685-
teif3, gif3
686-
),
687-
(
688-
Stream3, 3, ifcr, ctcif4, chtif4, cteif4, cgif4, isr, tcif4, htif4,
689-
teif4, gif4
690-
),
691-
(
692-
Stream4, 4, ifcr, ctcif5, chtif5, cteif5, cgif5, isr, tcif5, htif5,
693-
teif5, gif5
694-
),
695-
(
696-
Stream5, 5, ifcr, ctcif6, chtif6, cteif6, cgif6, isr, tcif6, htif6,
697-
teif6, gif6
698-
),
699-
(
700-
Stream6, 6, ifcr, ctcif7, chtif7, cteif7, cgif7, isr, tcif7, htif7,
701-
teif7, gif7
702-
),
703-
(
704-
Stream7, 7, ifcr, ctcif8, chtif8, cteif8, cgif8, isr, tcif8, htif8,
705-
teif8, gif8
706-
),
707-
);
708-
#[cfg(feature = "rm0468")]
709-
bdma_stream!(
710-
// For this sub-familiy, the field names do match the RM.
711-
(
712-
Stream0, 0, ifcr, ctcif0, chtif0, cteif0, cgif0, isr, tcif0, htif0,
713-
teif0, gif0
714-
),
715-
(
716-
Stream1, 1, ifcr, ctcif1, chtif1, cteif1, cgif1, isr, tcif1, htif1,
717-
teif1, gif1
718-
),
719-
(
720-
Stream2, 2, ifcr, ctcif2, chtif2, cteif2, cgif2, isr, tcif2, htif2,
721-
teif2, gif2
722-
),
723-
(
724-
Stream3, 3, ifcr, ctcif3, chtif3, cteif3, cgif3, isr, tcif3, htif3,
725-
teif3, gif3
726-
),
727-
(
728-
Stream4, 4, ifcr, ctcif4, chtif4, cteif4, cgif4, isr, tcif4, htif4,
729-
teif4, gif4
730-
),
731-
(
732-
Stream5, 5, ifcr, ctcif5, chtif5, cteif5, cgif5, isr, tcif5, htif5,
733-
teif5, gif5
734-
),
735-
(
736-
Stream6, 6, ifcr, ctcif6, chtif6, cteif6, cgif6, isr, tcif6, htif6,
737-
teif6, gif6
738-
),
739-
(
740-
Stream7, 7, ifcr, ctcif7, chtif7, cteif7, cgif7, isr, tcif7, htif7,
741-
teif7, gif7
742-
),
743-
);
744-
745662
/// Type alias for the DMA Request Multiplexer
746663
///
747664
pub type DMAReq = pac::dmamux2::ccr::DMAREQ_ID;

src/flash/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ const UNLOCK_KEY2: u32 = 0xCDEF_89AB;
277277

278278
#[allow(unused_unsafe)]
279279
fn unlock(bank: &BANK) {
280-
bank.keyr().write(|w| unsafe { w.keyr().bits(UNLOCK_KEY1) });
281-
bank.keyr().write(|w| unsafe { w.keyr().bits(UNLOCK_KEY2) });
280+
bank.keyr().write(|w| unsafe { w.key1r().bits(UNLOCK_KEY1) });
281+
bank.keyr().write(|w| unsafe { w.key1r().bits(UNLOCK_KEY2) });
282282
assert!(!bank.cr().read().lock().bit())
283283
}
284284

src/i2c.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ macro_rules! busy_wait {
130130
if isr.$flag().$variant() {
131131
break;
132132
} else if isr.berr().is_error() {
133-
$i2c.icr().write(|w| w.berrcf().set_bit());
133+
$i2c.icr().write(|w| w.berrcf().clear());
134134
return Err(Error::Bus);
135135
} else if isr.arlo().is_lost() {
136-
$i2c.icr().write(|w| w.arlocf().set_bit());
136+
$i2c.icr().write(|w| w.arlocf().clear());
137137
return Err(Error::Arbitration);
138138
} else if isr.nackf().bit_is_set() {
139139
$i2c.icr()
140-
.write(|w| w.stopcf().set_bit().nackcf().set_bit());
140+
.write(|w| w.stopcf().clear().nackcf().clear());
141141
flush_txdr!($i2c);
142142
return Err(Error::NotAcknowledge);
143143
} else {
@@ -375,12 +375,12 @@ macro_rules! i2c {
375375
pub fn clear_irq(&mut self, event: Event) {
376376
self.i2c.icr().write(|w| {
377377
match event {
378-
Event::Stop => w.stopcf().set_bit(),
378+
Event::Stop => w.stopcf().clear(),
379379
Event::Errors => w
380-
.berrcf().set_bit()
381-
.arlocf().set_bit()
382-
.ovrcf().set_bit(),
383-
Event::NotAcknowledge => w.nackcf().set_bit(),
380+
.berrcf().clear()
381+
.arlocf().clear()
382+
.ovrcf().clear(),
383+
Event::NotAcknowledge => w.nackcf().clear(),
384384
_ => w
385385
}
386386
});

src/rcc/rec.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ pub trait ResetEnable {
8787
/// Reset this peripheral
8888
#[allow(clippy::return_self_not_must_use)]
8989
fn reset(self) -> Self;
90+
91+
/// # Safety
92+
/// Caller has to ensure there are no other instances of this type
93+
unsafe fn new() -> Self;
9094
}
9195

9296
/// The clock gating state of a peripheral in low-power mode
@@ -341,6 +345,11 @@ macro_rules! peripheral_reset_and_enable_control_generator {
341345
});
342346
self
343347
}
348+
/// # Safety
349+
/// Caller has to ensure there are no other instances of this type
350+
unsafe fn new() -> Self {
351+
Self { _marker: PhantomData }
352+
}
344353
}
345354
$( #[ $pmeta ] )*
346355
impl $p {

0 commit comments

Comments
 (0)