Add support for generating PAC for dual cores
* Chips that have multiple cores will be exposed as chipname_corename, i.e. stm32wl55jc_cm4 * Chips that have single cores will use the chip family as feature name and pick the first and only core from the list * Add support for stm32wl55 chip family
This commit is contained in:
@ -239,23 +239,40 @@ stm32h743xg = [ "stm32-metapac/stm32h743xg",]
|
||||
stm32h743xi = [ "stm32-metapac/stm32h743xi",]
|
||||
stm32h743zg = [ "stm32-metapac/stm32h743zg",]
|
||||
stm32h743zi = [ "stm32-metapac/stm32h743zi",]
|
||||
stm32h745bg = [ "stm32-metapac/stm32h745bg",]
|
||||
stm32h745bi = [ "stm32-metapac/stm32h745bi",]
|
||||
stm32h745ig = [ "stm32-metapac/stm32h745ig",]
|
||||
stm32h745ii = [ "stm32-metapac/stm32h745ii",]
|
||||
stm32h745xg = [ "stm32-metapac/stm32h745xg",]
|
||||
stm32h745xi = [ "stm32-metapac/stm32h745xi",]
|
||||
stm32h745zg = [ "stm32-metapac/stm32h745zg",]
|
||||
stm32h745zi = [ "stm32-metapac/stm32h745zi",]
|
||||
stm32h747ag = [ "stm32-metapac/stm32h747ag",]
|
||||
stm32h747ai = [ "stm32-metapac/stm32h747ai",]
|
||||
stm32h747bg = [ "stm32-metapac/stm32h747bg",]
|
||||
stm32h747bi = [ "stm32-metapac/stm32h747bi",]
|
||||
stm32h747ig = [ "stm32-metapac/stm32h747ig",]
|
||||
stm32h747ii = [ "stm32-metapac/stm32h747ii",]
|
||||
stm32h747xg = [ "stm32-metapac/stm32h747xg",]
|
||||
stm32h747xi = [ "stm32-metapac/stm32h747xi",]
|
||||
stm32h747zi = [ "stm32-metapac/stm32h747zi",]
|
||||
stm32h745bg_cm7 = [ "stm32-metapac/stm32h745bg_cm7",]
|
||||
stm32h745bg_cm4 = [ "stm32-metapac/stm32h745bg_cm4",]
|
||||
stm32h745bi_cm7 = [ "stm32-metapac/stm32h745bi_cm7",]
|
||||
stm32h745bi_cm4 = [ "stm32-metapac/stm32h745bi_cm4",]
|
||||
stm32h745ig_cm7 = [ "stm32-metapac/stm32h745ig_cm7",]
|
||||
stm32h745ig_cm4 = [ "stm32-metapac/stm32h745ig_cm4",]
|
||||
stm32h745ii_cm7 = [ "stm32-metapac/stm32h745ii_cm7",]
|
||||
stm32h745ii_cm4 = [ "stm32-metapac/stm32h745ii_cm4",]
|
||||
stm32h745xg_cm7 = [ "stm32-metapac/stm32h745xg_cm7",]
|
||||
stm32h745xg_cm4 = [ "stm32-metapac/stm32h745xg_cm4",]
|
||||
stm32h745xi_cm7 = [ "stm32-metapac/stm32h745xi_cm7",]
|
||||
stm32h745xi_cm4 = [ "stm32-metapac/stm32h745xi_cm4",]
|
||||
stm32h745zg_cm7 = [ "stm32-metapac/stm32h745zg_cm7",]
|
||||
stm32h745zg_cm4 = [ "stm32-metapac/stm32h745zg_cm4",]
|
||||
stm32h745zi_cm7 = [ "stm32-metapac/stm32h745zi_cm7",]
|
||||
stm32h745zi_cm4 = [ "stm32-metapac/stm32h745zi_cm4",]
|
||||
stm32h747ag_cm7 = [ "stm32-metapac/stm32h747ag_cm7",]
|
||||
stm32h747ag_cm4 = [ "stm32-metapac/stm32h747ag_cm4",]
|
||||
stm32h747ai_cm7 = [ "stm32-metapac/stm32h747ai_cm7",]
|
||||
stm32h747ai_cm4 = [ "stm32-metapac/stm32h747ai_cm4",]
|
||||
stm32h747bg_cm7 = [ "stm32-metapac/stm32h747bg_cm7",]
|
||||
stm32h747bg_cm4 = [ "stm32-metapac/stm32h747bg_cm4",]
|
||||
stm32h747bi_cm7 = [ "stm32-metapac/stm32h747bi_cm7",]
|
||||
stm32h747bi_cm4 = [ "stm32-metapac/stm32h747bi_cm4",]
|
||||
stm32h747ig_cm7 = [ "stm32-metapac/stm32h747ig_cm7",]
|
||||
stm32h747ig_cm4 = [ "stm32-metapac/stm32h747ig_cm4",]
|
||||
stm32h747ii_cm7 = [ "stm32-metapac/stm32h747ii_cm7",]
|
||||
stm32h747ii_cm4 = [ "stm32-metapac/stm32h747ii_cm4",]
|
||||
stm32h747xg_cm7 = [ "stm32-metapac/stm32h747xg_cm7",]
|
||||
stm32h747xg_cm4 = [ "stm32-metapac/stm32h747xg_cm4",]
|
||||
stm32h747xi_cm7 = [ "stm32-metapac/stm32h747xi_cm7",]
|
||||
stm32h747xi_cm4 = [ "stm32-metapac/stm32h747xi_cm4",]
|
||||
stm32h747zi_cm7 = [ "stm32-metapac/stm32h747zi_cm7",]
|
||||
stm32h747zi_cm4 = [ "stm32-metapac/stm32h747zi_cm4",]
|
||||
stm32h750ib = [ "stm32-metapac/stm32h750ib",]
|
||||
stm32h750vb = [ "stm32-metapac/stm32h750vb",]
|
||||
stm32h750xb = [ "stm32-metapac/stm32h750xb",]
|
||||
@ -266,15 +283,24 @@ stm32h753ii = [ "stm32-metapac/stm32h753ii",]
|
||||
stm32h753vi = [ "stm32-metapac/stm32h753vi",]
|
||||
stm32h753xi = [ "stm32-metapac/stm32h753xi",]
|
||||
stm32h753zi = [ "stm32-metapac/stm32h753zi",]
|
||||
stm32h755bi = [ "stm32-metapac/stm32h755bi",]
|
||||
stm32h755ii = [ "stm32-metapac/stm32h755ii",]
|
||||
stm32h755xi = [ "stm32-metapac/stm32h755xi",]
|
||||
stm32h755zi = [ "stm32-metapac/stm32h755zi",]
|
||||
stm32h757ai = [ "stm32-metapac/stm32h757ai",]
|
||||
stm32h757bi = [ "stm32-metapac/stm32h757bi",]
|
||||
stm32h757ii = [ "stm32-metapac/stm32h757ii",]
|
||||
stm32h757xi = [ "stm32-metapac/stm32h757xi",]
|
||||
stm32h757zi = [ "stm32-metapac/stm32h757zi",]
|
||||
stm32h755bi_cm7 = [ "stm32-metapac/stm32h755bi_cm7",]
|
||||
stm32h755bi_cm4 = [ "stm32-metapac/stm32h755bi_cm4",]
|
||||
stm32h755ii_cm7 = [ "stm32-metapac/stm32h755ii_cm7",]
|
||||
stm32h755ii_cm4 = [ "stm32-metapac/stm32h755ii_cm4",]
|
||||
stm32h755xi_cm7 = [ "stm32-metapac/stm32h755xi_cm7",]
|
||||
stm32h755xi_cm4 = [ "stm32-metapac/stm32h755xi_cm4",]
|
||||
stm32h755zi_cm7 = [ "stm32-metapac/stm32h755zi_cm7",]
|
||||
stm32h755zi_cm4 = [ "stm32-metapac/stm32h755zi_cm4",]
|
||||
stm32h757ai_cm7 = [ "stm32-metapac/stm32h757ai_cm7",]
|
||||
stm32h757ai_cm4 = [ "stm32-metapac/stm32h757ai_cm4",]
|
||||
stm32h757bi_cm7 = [ "stm32-metapac/stm32h757bi_cm7",]
|
||||
stm32h757bi_cm4 = [ "stm32-metapac/stm32h757bi_cm4",]
|
||||
stm32h757ii_cm7 = [ "stm32-metapac/stm32h757ii_cm7",]
|
||||
stm32h757ii_cm4 = [ "stm32-metapac/stm32h757ii_cm4",]
|
||||
stm32h757xi_cm7 = [ "stm32-metapac/stm32h757xi_cm7",]
|
||||
stm32h757xi_cm4 = [ "stm32-metapac/stm32h757xi_cm4",]
|
||||
stm32h757zi_cm7 = [ "stm32-metapac/stm32h757zi_cm7",]
|
||||
stm32h757zi_cm4 = [ "stm32-metapac/stm32h757zi_cm4",]
|
||||
stm32h7a3ag = [ "stm32-metapac/stm32h7a3ag",]
|
||||
stm32h7a3ai = [ "stm32-metapac/stm32h7a3ai",]
|
||||
stm32h7a3ig = [ "stm32-metapac/stm32h7a3ig",]
|
||||
@ -554,4 +580,10 @@ stm32wb55vc = [ "stm32-metapac/stm32wb55vc",]
|
||||
stm32wb55ve = [ "stm32-metapac/stm32wb55ve",]
|
||||
stm32wb55vg = [ "stm32-metapac/stm32wb55vg",]
|
||||
stm32wb55vy = [ "stm32-metapac/stm32wb55vy",]
|
||||
stm32wl55cc_cm4 = [ "stm32-metapac/stm32wl55cc_cm4",]
|
||||
stm32wl55cc_cm0p = [ "stm32-metapac/stm32wl55cc_cm0p",]
|
||||
stm32wl55jc_cm4 = [ "stm32-metapac/stm32wl55jc_cm4",]
|
||||
stm32wl55jc_cm0p = [ "stm32-metapac/stm32wl55jc_cm0p",]
|
||||
stm32wl55uc_cm4 = [ "stm32-metapac/stm32wl55uc_cm4",]
|
||||
stm32wl55uc_cm0p = [ "stm32-metapac/stm32wl55uc_cm0p",]
|
||||
# END GENERATED FEATURES
|
||||
|
@ -19,10 +19,17 @@ data_path = '../stm32-data/data'
|
||||
try:
|
||||
_, chip_name, output_file = sys.argv
|
||||
except:
|
||||
raise Exception("Usage: gen.py STM32F429ZI path/to/generated.rs")
|
||||
raise Exception("Usage: gen.py STM32F429ZI_CM0 path/to/generated.rs")
|
||||
|
||||
c = chip_name.split('_', 1)
|
||||
|
||||
chip_name = c[0].upper()
|
||||
core_name = None
|
||||
|
||||
if len(c) > 1:
|
||||
core_name = c[1].lower()
|
||||
|
||||
# ======= load chip
|
||||
chip_name = chip_name.upper()
|
||||
with open(f'{data_path}/chips/{chip_name}.yaml', 'r') as f:
|
||||
chip = yaml.load(f, Loader=SafeLoader)
|
||||
|
||||
@ -41,7 +48,13 @@ with open(output_file, 'w') as f:
|
||||
singletons.extend((f'EXTI{x}' for x in range(16)))
|
||||
num_dmas = 0
|
||||
|
||||
for (name, peri) in chip['peripherals'].items():
|
||||
core = chip['cores'][0]
|
||||
if core_name != None:
|
||||
for c in chip['cores']:
|
||||
if core_name == c['name']:
|
||||
core = c
|
||||
|
||||
for (name, peri) in core['peripherals'].items():
|
||||
if 'block' not in peri:
|
||||
continue
|
||||
|
||||
|
@ -1,7 +1,13 @@
|
||||
import os
|
||||
import toml
|
||||
import yaml
|
||||
from glob import glob
|
||||
|
||||
try:
|
||||
from yaml import CSafeLoader as SafeLoader
|
||||
except ImportError:
|
||||
from yaml import SafeLoader
|
||||
|
||||
abspath = os.path.abspath(__file__)
|
||||
dname = os.path.dirname(abspath)
|
||||
os.chdir(dname)
|
||||
@ -12,6 +18,7 @@ supported_families = [
|
||||
'STM32L4',
|
||||
'STM32H7',
|
||||
'STM32WB55',
|
||||
'STM32WL55',
|
||||
]
|
||||
|
||||
# ======= load chip list
|
||||
@ -21,7 +28,15 @@ for f in sorted(glob('../stm32-data/data/chips/*.yaml')):
|
||||
name = os.path.splitext(os.path.basename(f))[0]
|
||||
if any((family in name for family in supported_families)):
|
||||
name = name.lower()
|
||||
features[name] = ['stm32-metapac/' + name]
|
||||
# ======= load chip
|
||||
with open(f, 'r') as f:
|
||||
chip = yaml.load(f, Loader=SafeLoader)
|
||||
|
||||
if len(chip['cores']) > 1:
|
||||
for core in chip['cores']:
|
||||
features[name + "_" + core['name']] = ['stm32-metapac/' + name + '_' + core['name']]
|
||||
else:
|
||||
features[name] = ['stm32-metapac/' + name]
|
||||
|
||||
# ========= Update Cargo features
|
||||
|
||||
|
@ -16,13 +16,13 @@ pub struct Clocks {
|
||||
#[cfg(any(rcc_l0))]
|
||||
pub ahb: Hertz,
|
||||
|
||||
#[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55))]
|
||||
#[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55, rcc_wl55))]
|
||||
pub ahb1: Hertz,
|
||||
|
||||
#[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55))]
|
||||
#[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55, rcc_wl55))]
|
||||
pub ahb2: Hertz,
|
||||
|
||||
#[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55))]
|
||||
#[cfg(any(rcc_l4, rcc_f4, rcc_h7, rcc_wb55, rcc_wl55))]
|
||||
pub ahb3: Hertz,
|
||||
|
||||
#[cfg(any(rcc_h7))]
|
||||
@ -62,6 +62,9 @@ cfg_if::cfg_if! {
|
||||
} else if #[cfg(rcc_wb55)] {
|
||||
mod wb55;
|
||||
pub use wb55::*;
|
||||
} else if #[cfg(rcc_wl55)] {
|
||||
mod wl55;
|
||||
pub use wl55::*;
|
||||
}
|
||||
}
|
||||
|
||||
|
213
embassy-stm32/src/rcc/wl55/mod.rs
Normal file
213
embassy-stm32/src/rcc/wl55/mod.rs
Normal file
@ -0,0 +1,213 @@
|
||||
pub use super::types::*;
|
||||
use crate::pac;
|
||||
use crate::peripherals::{self, RCC};
|
||||
use crate::rcc::{get_freqs, set_freqs, Clocks};
|
||||
use crate::time::Hertz;
|
||||
use crate::time::U32Ext;
|
||||
use core::marker::PhantomData;
|
||||
use embassy::util::Unborrow;
|
||||
use embassy_extras::unborrow;
|
||||
|
||||
/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC,
|
||||
/// and with the addition of the init function to configure a system clock.
|
||||
|
||||
/// Only the basic setup using the HSE and HSI clocks are supported as of now.
|
||||
|
||||
/// HSI speed
|
||||
pub const HSI_FREQ: u32 = 16_000_000;
|
||||
|
||||
/// System clock mux source
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum ClockSrc {
|
||||
HSE(Hertz),
|
||||
HSI16,
|
||||
}
|
||||
|
||||
impl Into<u8> for APBPrescaler {
|
||||
fn into(self) -> u8 {
|
||||
match self {
|
||||
APBPrescaler::NotDivided => 1,
|
||||
APBPrescaler::Div2 => 0x04,
|
||||
APBPrescaler::Div4 => 0x05,
|
||||
APBPrescaler::Div8 => 0x06,
|
||||
APBPrescaler::Div16 => 0x07,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<u8> for AHBPrescaler {
|
||||
fn into(self) -> u8 {
|
||||
match self {
|
||||
AHBPrescaler::NotDivided => 1,
|
||||
AHBPrescaler::Div2 => 0x08,
|
||||
AHBPrescaler::Div4 => 0x09,
|
||||
AHBPrescaler::Div8 => 0x0a,
|
||||
AHBPrescaler::Div16 => 0x0b,
|
||||
AHBPrescaler::Div64 => 0x0c,
|
||||
AHBPrescaler::Div128 => 0x0d,
|
||||
AHBPrescaler::Div256 => 0x0e,
|
||||
AHBPrescaler::Div512 => 0x0f,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Clocks configutation
|
||||
pub struct Config {
|
||||
mux: ClockSrc,
|
||||
ahb_pre: AHBPrescaler,
|
||||
apb1_pre: APBPrescaler,
|
||||
apb2_pre: APBPrescaler,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
#[inline]
|
||||
fn default() -> Config {
|
||||
Config {
|
||||
mux: ClockSrc::HSI16,
|
||||
ahb_pre: AHBPrescaler::NotDivided,
|
||||
apb1_pre: APBPrescaler::NotDivided,
|
||||
apb2_pre: APBPrescaler::NotDivided,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
#[inline]
|
||||
pub fn clock_src(mut self, mux: ClockSrc) -> Self {
|
||||
self.mux = mux;
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
|
||||
self.ahb_pre = pre;
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self {
|
||||
self.apb1_pre = pre;
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self {
|
||||
self.apb2_pre = pre;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// RCC peripheral
|
||||
pub struct Rcc<'d> {
|
||||
_rb: peripherals::RCC,
|
||||
phantom: PhantomData<&'d mut peripherals::RCC>,
|
||||
}
|
||||
|
||||
impl<'d> Rcc<'d> {
|
||||
pub fn new(rcc: impl Unborrow<Target = peripherals::RCC> + 'd) -> Self {
|
||||
unborrow!(rcc);
|
||||
Self {
|
||||
_rb: rcc,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
// Safety: RCC init must have been called
|
||||
pub fn clocks(&self) -> &'static Clocks {
|
||||
unsafe { get_freqs() }
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension trait that freezes the `RCC` peripheral with provided clocks configuration
|
||||
pub trait RccExt {
|
||||
fn freeze(self, config: Config) -> Clocks;
|
||||
}
|
||||
|
||||
impl RccExt for RCC {
|
||||
#[inline]
|
||||
fn freeze(self, cfgr: Config) -> Clocks {
|
||||
let rcc = pac::RCC;
|
||||
let (sys_clk, sw) = match cfgr.mux {
|
||||
ClockSrc::HSI16 => {
|
||||
// Enable HSI16
|
||||
unsafe {
|
||||
rcc.cr().write(|w| w.set_hsion(true));
|
||||
while !rcc.cr().read().hsirdy() {}
|
||||
}
|
||||
|
||||
(HSI_FREQ, 0x01)
|
||||
}
|
||||
ClockSrc::HSE(freq) => {
|
||||
// Enable HSE
|
||||
unsafe {
|
||||
rcc.cr().write(|w| w.set_hseon(true));
|
||||
while !rcc.cr().read().hserdy() {}
|
||||
}
|
||||
|
||||
(freq.0, 0x02)
|
||||
}
|
||||
};
|
||||
|
||||
unsafe {
|
||||
rcc.cfgr().modify(|w| {
|
||||
w.set_sw(sw.into());
|
||||
w.set_hpre(cfgr.ahb_pre.into());
|
||||
w.set_ppre1(cfgr.apb1_pre.into());
|
||||
w.set_ppre2(cfgr.apb2_pre.into());
|
||||
});
|
||||
}
|
||||
|
||||
let ahb_freq: u32 = match cfgr.ahb_pre {
|
||||
AHBPrescaler::NotDivided => sys_clk,
|
||||
pre => {
|
||||
let pre: u8 = pre.into();
|
||||
let pre = 1 << (pre as u32 - 7);
|
||||
sys_clk / pre
|
||||
}
|
||||
};
|
||||
|
||||
let (apb1_freq, apb1_tim_freq) = match cfgr.apb1_pre {
|
||||
APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
|
||||
pre => {
|
||||
let pre: u8 = pre.into();
|
||||
let pre: u8 = 1 << (pre - 3);
|
||||
let freq = ahb_freq / pre as u32;
|
||||
(freq, freq * 2)
|
||||
}
|
||||
};
|
||||
|
||||
let (apb2_freq, apb2_tim_freq) = match cfgr.apb2_pre {
|
||||
APBPrescaler::NotDivided => (ahb_freq, ahb_freq),
|
||||
pre => {
|
||||
let pre: u8 = pre.into();
|
||||
let pre: u8 = 1 << (pre - 3);
|
||||
let freq = ahb_freq / (1 << (pre as u8 - 3));
|
||||
(freq, freq * 2)
|
||||
}
|
||||
};
|
||||
|
||||
Clocks {
|
||||
sys: sys_clk.hz(),
|
||||
ahb1: ahb_freq.hz(),
|
||||
ahb2: ahb_freq.hz(),
|
||||
ahb3: ahb_freq.hz(),
|
||||
apb1: apb1_freq.hz(),
|
||||
apb2: apb2_freq.hz(),
|
||||
apb1_tim: apb1_tim_freq.hz(),
|
||||
apb2_tim: apb2_tim_freq.hz(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn init(config: Config) {
|
||||
let r = <peripherals::RCC as embassy::util::Steal>::steal();
|
||||
let rcc = pac::RCC;
|
||||
rcc.ahb2enr().write(|w| {
|
||||
w.set_gpioaen(true);
|
||||
w.set_gpioben(true);
|
||||
w.set_gpiocen(true);
|
||||
w.set_gpiohen(true);
|
||||
});
|
||||
let clocks = r.freeze(config);
|
||||
set_freqs(clocks);
|
||||
}
|
Reference in New Issue
Block a user