Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/stm32-hal.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cortex-m = "0.7.3"
# Peripheral Access Crates
stm32f3 = { version = "0.15.1", optional = true }
stm32f4 = { version = "0.15.1", optional = true }
stm32l4 = { version = "0.15.1", optional = true }
stm32l4 = { path = "../stm32-rs/stm32l4", optional = true }
stm32l5 = { version = "0.15.1", optional = true }
stm32g0 = { version = "0.15.1", optional = true }
stm32g4 = { version = "0.15.1", optional = true }
Expand Down Expand Up @@ -107,6 +107,8 @@ l4x5 = ["stm32l4/stm32l4x5", "l4"]
l4x6 = ["stm32l4/stm32l4x6", "l4"]
# todo: Handle l4+ (P, R, S, Q)

l4p5 = ["stm32l4/stm32l4p5", "l4p"]

# [L5](https://docs.rs/crate/stm32l5/latest/source/Cargo.toml)
l552 = ["stm32l5/stm32l552", "l5"]
l562 = ["stm32l5/stm32l562", "l5"]
Expand Down Expand Up @@ -165,6 +167,7 @@ embedded_hal = ["embedded-hal", "nb"]
f3 = []
f4 = []
l4 = []
l4p = []
l5 = []
g0 = []
g4 = []
Expand Down
4 changes: 2 additions & 2 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,15 +870,15 @@ macro_rules! hal {

// L44 RM, Table 41. "DMA1 requests for each channel
// todo: DMA2 support.
#[cfg(any(feature = "f3", feature = "l4"))]
#[cfg(any(feature = "f3", all(feature = "l4", not(feature = "l4plus"))))]
let dma_channel = match self.device {
AdcDevice::One => DmaInput::Adc1.dma1_channel(),
AdcDevice::Two => DmaInput::Adc2.dma1_channel(),
_ => panic!("DMA on ADC beyond 2 is not supported. If it is for your MCU, please submit an issue \
or PR on Github.")
};

#[cfg(feature = "l4")]
#[cfg(all(feature = "l4", not(feature = "l4plus")))]
match self.device {
AdcDevice::One => dma.channel_select(DmaInput::Adc1),
AdcDevice::Two => dma.channel_select(DmaInput::Adc2),
Expand Down
23 changes: 14 additions & 9 deletions src/clocks/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
util::rcc_en_reset,
};

#[cfg(any(feature = "l4", feature = "l5", feature = "wb", feature = "g4"))]
#[cfg(any(feature = "l4", feature = "l4p", feature = "l5", feature = "wb", feature = "g4"))]
use crate::pac::CRS;

use cfg_if::cfg_if;
Expand All @@ -31,7 +31,7 @@ pub enum Clk48Src {
Msi = 0b11,
}

#[cfg(any(feature = "l4", feature = "l5", feature = "wb", feature = "g4"))]
#[cfg(any(feature = "l4", feature = "l4p", feature = "l5", feature = "wb", feature = "g4"))]
#[derive(Clone, Copy)]
#[repr(u8)]
/// Select the SYNC signal source. Sets the CRS_CFGR register, SYNCSRC field.
Expand Down Expand Up @@ -80,7 +80,7 @@ impl PllSrc {
}
}

#[cfg(any(feature = "l4", feature = "l5", feature = "wb", feature = "wl"))]
#[cfg(any(feature = "l4", feature = "l4p", feature = "l5", feature = "wb", feature = "wl"))]
#[derive(Clone, Copy, PartialEq)]
#[repr(u8)]
/// Select the system clock used when exiting Stop mode. Sets RCC_CFGR register, STOPWUCK field.
Expand Down Expand Up @@ -266,6 +266,8 @@ impl Default for PllCfg {
divn: 64,
#[cfg(feature = "wl")]
divn: 24,
#[cfg(feature = "l4p")]
divn: 16,
#[cfg(not(feature = "wb"))]
divr: Pllr::Div2,
#[cfg(feature = "wb")]
Expand Down Expand Up @@ -568,7 +570,7 @@ pub struct Clocks {
#[cfg(not(any(feature = "g0", feature = "wl")))]
/// Enable the HSI48. For L4, this is only applicable for some devices.
pub hsi48_on: bool,
#[cfg(any(feature = "l4", feature = "l5", feature = "wb", feature = "wl"))]
#[cfg(any(feature = "l4", feature = "l4p", feature = "l5", feature = "wb", feature = "wl"))]
/// Select the input source to use after waking up from `stop` mode. Eg HSI or MSI.
pub stop_wuck: StopWuck,
#[cfg(feature = "wb")]
Expand All @@ -577,7 +579,7 @@ pub struct Clocks {
#[cfg(not(any(feature = "g0", feature = "g4", feature = "wl")))]
/// SAI1 kernel clock source selection
pub sai1_src: SaiSrc,
#[cfg(feature = "g4")]
#[cfg(any(feature = "g4", feature = "l4p"))]
/// Range 1 boost mode: Used to increase regulator voltage to 1.28v, for when system
/// clock frequency is up to 170Mhz. Defaults to true.
pub boost_mode: bool,
Expand Down Expand Up @@ -619,7 +621,7 @@ impl Clocks {
}

cfg_if! {
if #[cfg(feature = "g4")] {
if #[cfg(any(feature = "g4", feature = "l4p"))] {
if self.boost_mode {
// The sequence to switch from Range1 normal mode to Range1 boost mode is:
// 1. The system clock must be divided by 2 using the AHB prescaler before switching to a
Expand Down Expand Up @@ -1066,7 +1068,7 @@ impl Clocks {
while rcc.cr.read().hserdy().bit_is_clear() {}
}
PllSrc::Hsi => {
#[cfg(any(feature = "l4", feature = "l5"))]
#[cfg(any(feature = "l4", feature = "l4p", feature = "l5"))]
// Generally reverts to MSI (see note below)
if let StopWuck::Msi = self.stop_wuck {
rcc.cr.modify(|_, w| w.hsion().set_bit());
Expand Down Expand Up @@ -1387,6 +1389,9 @@ impl Clocks {
#[cfg(feature = "l4")]
let max_clock = 80_000_000;

#[cfg(feature = "l4p")]
let max_clock = 120_000_000;

#[cfg(feature = "l5")]
let max_clock = 110_000_000;

Expand Down Expand Up @@ -1497,13 +1502,13 @@ impl Default for Clocks {
security_system: false,
#[cfg(not(any(feature = "g0", feature = "wl")))]
hsi48_on: false,
#[cfg(any(feature = "l4", feature = "l5", feature = "wb", feature = "wl"))]
#[cfg(any(feature = "l4", feature = "l4p", feature = "l5", feature = "wb", feature = "wl"))]
stop_wuck: StopWuck::Msi,
#[cfg(feature = "wb")]
rf_wakeup_src: RfWakeupSrc::Lse,
#[cfg(not(any(feature = "g0", feature = "g4", feature = "wl")))]
sai1_src: SaiSrc::Pllp,
#[cfg(feature = "g4")]
#[cfg(any(feature = "g4", feature = "l4p"))]
boost_mode: true,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/clocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cfg_if::cfg_if! {
if #[cfg(any(feature = "f3", feature = "f4"))] {
mod f;
pub use f::*;
} else if #[cfg(any(feature = "l4", feature = "l5", feature = "g0", feature = "g4", feature = "wb", feature = "wl"))] {
} else if #[cfg(any(feature = "l4", feature = "l4p", feature = "l5", feature = "g0", feature = "g4", feature = "wb", feature = "wl"))] {
mod baseline;
pub use baseline::*;
} else if #[cfg(feature = "u5")] {
Expand Down
4 changes: 2 additions & 2 deletions src/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl CrcExt for CRC {
if #[cfg(feature = "f3")] {
rcc.ahbenr.modify(|_, w| w.crcen().set_bit());
// F3 doesn't appear to have a crcrst field in `ahbrstr`, per RM.
} else if #[cfg(any(feature = "l4", feature = "wb"))] {
} else if #[cfg(any(feature = "l4", feature = "l4p", feature = "wb"))] {
rcc.ahb1enr.modify(|_, w| w.crcen().set_bit());
rcc.ahb1rstr.modify(|_, w| w.crcrst().set_bit());
rcc.ahb1rstr.modify(|_, w| w.crcrst().clear_bit());
Expand Down Expand Up @@ -157,7 +157,7 @@ impl Crc {
///
/// The IDR is not involved with CRC calculation.
pub fn set_idr(&mut self, value: u8) {
self.reg.idr.write(|w| w.idr().bits(value));
self.reg.idr.write(|w| unsafe { w.idr().bits(value) });
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ where
{
let (ptr, len) = (buf.as_ptr(), buf.len());

#[cfg(any(feature = "f3", feature = "l4"))]
#[cfg(any(feature = "f3", all(feature = "l4", not(feature = "l4plus"))))]
let dma_channel = match dac_channel {
DacChannel::C1 => DmaInput::Dac1Ch1.dma1_channel(),
DacChannel::C2 => DmaInput::Dac1Ch2.dma1_channel(),
};

#[cfg(feature = "l4")]
#[cfg(all(feature = "l4", not(feature = "l4plus")))]
match dac_channel {
DacChannel::C1 => dma.channel_select(DmaInput::Dac1Ch1),
DacChannel::C2 => dma.channel_select(DmaInput::Dac1Ch2),
Expand Down
Loading