Skip to content

Commit 8fd67f7

Browse files
authored
Merge pull request #87 from no111u3/main
Fix time types in independent_watchdog and library build
2 parents 494ac00 + f24f53a commit 8fd67f7

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/independent_watchdog.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
//! Originally from stm32h7-hal, adapted for stm32g4xx-hal
1414
use crate::{
1515
stm32::{iwdg::pr::PR_A, IWDG},
16-
time::{MicroSecond, U32Ext},
16+
time::MicroSecond,
1717
};
18+
use fugit::ExtU32;
1819

1920
/// The implementation of the hardware IWDG
2021
pub struct IndependentWatchdog {
@@ -83,7 +84,7 @@ impl IndependentWatchdog {
8384
// Set the prescaler
8485
let (prescaler, _) = Self::MAX_MILLIS_FOR_PRESCALER
8586
.iter()
86-
.find(|(_, max_millis)| *max_millis >= max_window_time.0 / 1000)
87+
.find(|(_, max_millis)| *max_millis >= max_window_time.to_millis())
8788
.expect("IWDG max time is greater than is possible");
8889
while self.iwdg.sr.read().pvu().bit_is_set() {
8990
cortex_m::asm::nop();
@@ -99,9 +100,9 @@ impl IndependentWatchdog {
99100
.write(|w| w.win().bits(Self::MAX_COUNTER_VALUE as u16));
100101

101102
// Calculate the counter values
102-
let reload_value = (max_window_time.0 / 1000) * (Self::CLOCK_SPEED / 1000)
103+
let reload_value = max_window_time.to_millis() * (Self::CLOCK_SPEED / 1000)
103104
/ Self::get_prescaler_divider(prescaler);
104-
let window_value = (min_window_time.0 / 1000) * (Self::CLOCK_SPEED / 1000)
105+
let window_value = min_window_time.to_millis() * (Self::CLOCK_SPEED / 1000)
105106
/ Self::get_prescaler_divider(prescaler);
106107

107108
// Set the reload value
@@ -132,7 +133,7 @@ impl IndependentWatchdog {
132133

133134
/// Start the watchdog with the given max time and no minimal time
134135
pub fn start<T: Into<MicroSecond>>(&mut self, max_time: T) {
135-
self.start_windowed(0_u32.ms(), max_time.into());
136+
self.start_windowed(0_u32.millis(), max_time.into());
136137
}
137138

138139
fn get_prescaler_divider(prescaler: &PR_A) -> u32 {

src/spi.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::rcc::{Enable, GetBusFreq, Rcc, RccBus, Reset};
1818
use crate::stm32::SPI4;
1919
use crate::stm32::{RCC, SPI1, SPI2, SPI3};
2020
use crate::time::Hertz;
21+
use core::cell::UnsafeCell;
2122
use core::ptr;
2223
pub use hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
2324

@@ -210,8 +211,9 @@ macro_rules! spi {
210211
} else if sr.crcerr().bit_is_set() {
211212
nb::Error::Other(Error::Crc)
212213
} else if sr.txe().bit_is_set() {
214+
let dr = &self.spi.dr as *const _ as *const UnsafeCell<u8>;
213215
// NOTE(write_volatile) see note above
214-
unsafe { ptr::write_volatile(&self.spi.dr as *const _ as *mut u8, byte) }
216+
unsafe { ptr::write_volatile(UnsafeCell::raw_get(dr), byte) };
215217
return Ok(());
216218
} else {
217219
nb::Error::WouldBlock

src/time.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// This code has been taken from the stm32g0xx-hal project and modified slightly to support
22
/// STM32G4xx MCUs.
3-
43
pub use fugit::{
54
Duration, ExtU32, HertzU32 as Hertz, HoursDurationU32 as Hour,
65
MicrosDurationU32 as MicroSecond, MinutesDurationU32 as Minute, NanosDurationU32 as NanoSecond,

0 commit comments

Comments
 (0)