Merge #507
507: Stm32 data upate 4 r=Dirbaio a=Dirbaio Main imrpvement is RCC regs info comes from yamls now. Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
commit
e36e36dab6
@ -103,7 +103,7 @@ crate::pac::peripherals!(
|
|||||||
|
|
||||||
crate::pac::peripherals!(
|
crate::pac::peripherals!(
|
||||||
(can, CAN) => {
|
(can, CAN) => {
|
||||||
unsafe impl bxcan::FilterOwner for peripherals::$inst {
|
unsafe impl bxcan::FilterOwner for peripherals::CAN {
|
||||||
const NUM_FILTER_BANKS: u8 = 14;
|
const NUM_FILTER_BANKS: u8 = 14;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -144,4 +144,10 @@ crate::pac::peripheral_pins!(
|
|||||||
($inst:ident, can, CAN, $pin:ident, RX, $af:expr) => {
|
($inst:ident, can, CAN, $pin:ident, RX, $af:expr) => {
|
||||||
impl_pin!($inst, $pin, RxPin, $af);
|
impl_pin!($inst, $pin, RxPin, $af);
|
||||||
};
|
};
|
||||||
|
($inst:ident, can, CAN, $pin:ident, TX) => {
|
||||||
|
impl_pin!($inst, $pin, TxPin, 0);
|
||||||
|
};
|
||||||
|
($inst:ident, can, CAN, $pin:ident, RX) => {
|
||||||
|
impl_pin!($inst, $pin, RxPin, 0);
|
||||||
|
};
|
||||||
);
|
);
|
||||||
|
@ -49,16 +49,11 @@ pac::dma_channels! {
|
|||||||
|
|
||||||
/// safety: must be called only once
|
/// safety: must be called only once
|
||||||
pub(crate) unsafe fn init() {
|
pub(crate) unsafe fn init() {
|
||||||
pac::peripherals! {
|
crate::pac::peripheral_rcc! {
|
||||||
(dmamux, $peri:ident) => {
|
($name:ident, dmamux, DMAMUX, $clock:ident, ($reg:ident, $field:ident, $set_field:ident), $rst:tt) => {
|
||||||
{
|
crate::pac::RCC.$reg().modify(|reg| {
|
||||||
pac::peripheral_rcc! {
|
reg.$set_field(true);
|
||||||
($peri, $clock:ident, $en_reg:ident, $rst_reg:ident, $en_fn:ident, $rst_fn:ident) => {
|
});
|
||||||
use crate::rcc::sealed::RccPeripheral;
|
|
||||||
crate::peripherals::$peri::enable()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -601,14 +601,10 @@ crate::pac::pins!(
|
|||||||
);
|
);
|
||||||
|
|
||||||
pub(crate) unsafe fn init() {
|
pub(crate) unsafe fn init() {
|
||||||
crate::pac::gpio_rcc! {
|
crate::pac::peripheral_rcc! {
|
||||||
($en_reg:ident) => {
|
($name:ident, gpio, GPIO, $clock:ident, ($reg:ident, $field:ident, $set_field:ident), $rst:tt) => {
|
||||||
crate::pac::RCC.$en_reg().modify(|reg| {
|
crate::pac::RCC.$reg().modify(|reg| {
|
||||||
crate::pac::gpio_rcc! {
|
reg.$set_field(true);
|
||||||
($name:ident, $clock:ident, $en_reg, $rst_reg:ident, $en_fn:ident, $rst_fn:ident) => {
|
|
||||||
reg.$en_fn(true);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -120,35 +120,33 @@ pub(crate) mod sealed {
|
|||||||
pub trait RccPeripheral: sealed::RccPeripheral + 'static {}
|
pub trait RccPeripheral: sealed::RccPeripheral + 'static {}
|
||||||
|
|
||||||
crate::pac::peripheral_rcc!(
|
crate::pac::peripheral_rcc!(
|
||||||
($inst:ident, $clk:ident, $enable:ident, $reset:ident, $perien:ident, $perirst:ident) => {
|
($inst:ident, gpio, GPIO, $clk:ident, $en:tt, $rst:tt) => {};
|
||||||
|
($inst:ident, $module:ident, $block:ident, $clk:ident, ($en_reg:ident, $en_field:ident, $en_set_field:ident), ($rst_reg:ident, $rst_field:ident, $rst_set_field:ident)) => {
|
||||||
impl sealed::RccPeripheral for peripherals::$inst {
|
impl sealed::RccPeripheral for peripherals::$inst {
|
||||||
fn frequency() -> crate::time::Hertz {
|
fn frequency() -> crate::time::Hertz {
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_| {
|
||||||
unsafe {
|
unsafe { get_freqs().$clk }
|
||||||
let freqs = get_freqs();
|
|
||||||
freqs.$clk
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn enable() {
|
fn enable() {
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_| {
|
||||||
unsafe {
|
unsafe {
|
||||||
crate::pac::RCC.$enable().modify(|w| w.$perien(true));
|
crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(true));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn disable() {
|
fn disable() {
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_| {
|
||||||
unsafe {
|
unsafe {
|
||||||
crate::pac::RCC.$enable().modify(|w| w.$perien(false));
|
crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(false));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn reset() {
|
fn reset() {
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_| {
|
||||||
unsafe {
|
unsafe {
|
||||||
crate::pac::RCC.$reset().modify(|w| w.$perirst(true));
|
crate::pac::RCC.$rst_reg().modify(|w| w.$rst_set_field(true));
|
||||||
crate::pac::RCC.$reset().modify(|w| w.$perirst(false));
|
crate::pac::RCC.$rst_reg().modify(|w| w.$rst_set_field(false));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -156,27 +154,24 @@ crate::pac::peripheral_rcc!(
|
|||||||
|
|
||||||
impl RccPeripheral for peripherals::$inst {}
|
impl RccPeripheral for peripherals::$inst {}
|
||||||
};
|
};
|
||||||
($inst:ident, $clk:ident, $enable:ident, $perien:ident) => {
|
($inst:ident, $module:ident, $block:ident, $clk:ident, ($en_reg:ident, $en_field:ident, $en_set_field:ident), _) => {
|
||||||
impl sealed::RccPeripheral for peripherals::$inst {
|
impl sealed::RccPeripheral for peripherals::$inst {
|
||||||
fn frequency() -> crate::time::Hertz {
|
fn frequency() -> crate::time::Hertz {
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_| {
|
||||||
unsafe {
|
unsafe { get_freqs().$clk }
|
||||||
let freqs = get_freqs();
|
|
||||||
freqs.$clk
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn enable() {
|
fn enable() {
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_| {
|
||||||
unsafe {
|
unsafe {
|
||||||
crate::pac::RCC.$enable().modify(|w| w.$perien(true));
|
crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(true));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn disable() {
|
fn disable() {
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_| {
|
||||||
unsafe {
|
unsafe {
|
||||||
crate::pac::RCC.$enable().modify(|w| w.$perien(false));
|
crate::pac::RCC.$en_reg().modify(|w| w.$en_set_field(false));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-tim2"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-tim2"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
|
@ -10,7 +10,6 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-tim2"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-tim2"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
|
@ -9,9 +9,7 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-tim2"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "net", "stm32f767zi", "unstable-pac", "time-driver-tim2"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt", "tcp", "medium-ethernet", "pool-16"] }
|
embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt", "tcp", "medium-ethernet", "pool-16"] }
|
||||||
embassy-macros = { path = "../../embassy-macros" }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
|
@ -13,7 +13,6 @@ use embassy::executor::{Executor, Spawner};
|
|||||||
use embassy::io::AsyncWriteExt;
|
use embassy::io::AsyncWriteExt;
|
||||||
use embassy::time::{Duration, Timer};
|
use embassy::time::{Duration, Timer};
|
||||||
use embassy::util::Forever;
|
use embassy::util::Forever;
|
||||||
use embassy_macros::interrupt_take;
|
|
||||||
use embassy_net::{
|
use embassy_net::{
|
||||||
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
|
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
|
||||||
};
|
};
|
||||||
@ -101,7 +100,7 @@ fn main() -> ! {
|
|||||||
RNG_INST.replace(rng);
|
RNG_INST.replace(rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
let eth_int = interrupt_take!(ETH);
|
let eth_int = interrupt::take!(ETH);
|
||||||
let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
|
let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
|
||||||
let state = STATE.put(State::new());
|
let state = STATE.put(State::new());
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "time-driver-tim2", "stm32g071rb", "memory-x", "unstable-pac"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "time-driver-tim2", "stm32g071rb", "memory-x", "unstable-pac"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
|
@ -1,34 +1,4 @@
|
|||||||
//! This build script copies the `memory.x` file from the crate root into
|
|
||||||
//! a directory where the linker can always find it at build time.
|
|
||||||
//! For many projects this is optional, as the linker always searches the
|
|
||||||
//! project root directory -- wherever `Cargo.toml` is. However, if you
|
|
||||||
//! are using a workspace or have a more complicated build setup, this
|
|
||||||
//! build script becomes required. Additionally, by requesting that
|
|
||||||
//! Cargo re-run the build script whenever `memory.x` is changed,
|
|
||||||
//! updating `memory.x` ensures a rebuild of the application with the
|
|
||||||
//! new memory settings.
|
|
||||||
|
|
||||||
use std::env;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Put `memory.x` in our output directory and ensure it's
|
|
||||||
// on the linker search path.
|
|
||||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
||||||
File::create(out.join("memory.x"))
|
|
||||||
.unwrap()
|
|
||||||
.write_all(include_bytes!("memory.x"))
|
|
||||||
.unwrap();
|
|
||||||
println!("cargo:rustc-link-search={}", out.display());
|
|
||||||
|
|
||||||
// By default, Cargo will re-run a build script whenever
|
|
||||||
// any file in the project changes. By specifying `memory.x`
|
|
||||||
// here, we ensure the build script is only re-run when
|
|
||||||
// `memory.x` is changed.
|
|
||||||
println!("cargo:rerun-if-changed=memory.x");
|
|
||||||
|
|
||||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
MEMORY
|
|
||||||
{
|
|
||||||
/* NOTE 1 K = 1 KiBi = 1024 bytes */
|
|
||||||
/* These values correspond to the STM32G071C8 */
|
|
||||||
FLASH : ORIGIN = 0x08000000, LENGTH = 64K
|
|
||||||
RAM : ORIGIN = 0x20000000, LENGTH = 36K
|
|
||||||
}
|
|
@ -11,9 +11,7 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32h743zi", "net", "time-driver-tim2"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32h743zi", "net", "time-driver-tim2"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt", "tcp", "medium-ethernet", "pool-16"] }
|
embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt", "tcp", "medium-ethernet", "pool-16"] }
|
||||||
embassy-macros = { path = "../../embassy-macros" }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
|
@ -13,7 +13,6 @@ use embassy::executor::{Executor, Spawner};
|
|||||||
use embassy::io::AsyncWriteExt;
|
use embassy::io::AsyncWriteExt;
|
||||||
use embassy::time::{Duration, Timer};
|
use embassy::time::{Duration, Timer};
|
||||||
use embassy::util::Forever;
|
use embassy::util::Forever;
|
||||||
use embassy_macros::interrupt_take;
|
|
||||||
use embassy_net::{
|
use embassy_net::{
|
||||||
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
|
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
|
||||||
};
|
};
|
||||||
@ -100,7 +99,7 @@ fn main() -> ! {
|
|||||||
RNG_INST.replace(rng);
|
RNG_INST.replace(rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
let eth_int = interrupt_take!(ETH);
|
let eth_int = interrupt::take!(ETH);
|
||||||
let mac_addr = [0x10; 6];
|
let mac_addr = [0x10; 6];
|
||||||
let state = STATE.put(State::new());
|
let state = STATE.put(State::new());
|
||||||
let eth = unsafe {
|
let eth = unsafe {
|
||||||
|
@ -9,8 +9,6 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-tim3"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-tim3"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
embassy-macros = { path = "../../embassy-macros" }
|
|
||||||
|
|
||||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time"] }
|
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time"] }
|
||||||
lorawan-device = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "4bff2e0021103adfbccedcbf49dbcd0474adc4b2", default-features = false, features = ["async"] }
|
lorawan-device = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "4bff2e0021103adfbccedcbf49dbcd0474adc4b2", default-features = false, features = ["async"] }
|
||||||
|
@ -9,8 +9,6 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l151cb-a", "time-driver-tim2", "memory-x"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l151cb-a", "time-driver-tim2", "memory-x"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
embassy-macros = { path = "../../embassy-macros" }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
|
@ -11,7 +11,6 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt" ] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt" ] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "unstable-pac", "stm32l4s5vi", "time-driver-tim2"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "unstable-pac", "stm32l4s5vi", "time-driver-tim2"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
|
@ -9,7 +9,6 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "unstable-pac", "stm32u585ai", "memory-x" ] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "unstable-pac", "stm32u585ai", "memory-x" ] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
|
@ -9,7 +9,6 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32wb55cc", "time-driver-tim2"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32wb55cc", "time-driver-tim2"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.3"
|
defmt-rtt = "0.3"
|
||||||
|
@ -9,7 +9,6 @@ resolver = "2"
|
|||||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32wl55jc-cm4", "time-driver-tim2", "memory-x", "subghz", "unstable-pac"] }
|
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32wl55jc-cm4", "time-driver-tim2", "memory-x", "subghz", "unstable-pac"] }
|
||||||
embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
|
|
||||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time"] }
|
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time"] }
|
||||||
|
|
||||||
lorawan-device = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "4bff2e0021103adfbccedcbf49dbcd0474adc4b2", default-features = false, features = ["async"] }
|
lorawan-device = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "4bff2e0021103adfbccedcbf49dbcd0474adc4b2", default-features = false, features = ["async"] }
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit e60ce40e6f9d29e9a8b45ea7b9118e0d55b30928
|
Subproject commit ec3fb03dc0325e62ed55ac2dd949b412f3f864e6
|
@ -42,11 +42,9 @@ pub struct Package {
|
|||||||
pub struct Peripheral {
|
pub struct Peripheral {
|
||||||
pub address: u64,
|
pub address: u64,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub kind: Option<String>,
|
|
||||||
#[serde(default)]
|
|
||||||
pub block: Option<String>,
|
pub block: Option<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub clock: Option<String>,
|
pub rcc: Option<PeripheralRcc>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub pins: Vec<Pin>,
|
pub pins: Vec<Pin>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@ -55,6 +53,26 @@ pub struct Peripheral {
|
|||||||
pub interrupts: BTreeMap<String, String>,
|
pub interrupts: BTreeMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct PeripheralRcc {
|
||||||
|
pub clock: String,
|
||||||
|
pub registers: PeripheralRccRegisters,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct PeripheralRccRegisters {
|
||||||
|
#[serde(default)]
|
||||||
|
pub enable: Option<PeripheralRccRegister>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub reset: Option<PeripheralRccRegister>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
|
pub struct PeripheralRccRegister {
|
||||||
|
pub register: String,
|
||||||
|
pub field: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
|
||||||
pub struct Pin {
|
pub struct Pin {
|
||||||
pub pin: String,
|
pub pin: String,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use chiptool::generate::CommonModule;
|
use chiptool::generate::CommonModule;
|
||||||
use chiptool::ir::IR;
|
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||||
@ -17,24 +16,6 @@ use chiptool::{generate, ir, transform};
|
|||||||
mod data;
|
mod data;
|
||||||
use data::*;
|
use data::*;
|
||||||
|
|
||||||
fn find_reg<'c>(rcc: &'c ir::IR, reg_regex: &str, field_name: &str) -> Option<(&'c str, &'c str)> {
|
|
||||||
let reg_regex = Regex::new(reg_regex).unwrap();
|
|
||||||
|
|
||||||
for (name, fieldset) in &rcc.fieldsets {
|
|
||||||
// Workaround for some families that prefix register aliases with C1_, which does
|
|
||||||
// not help matching for clock name.
|
|
||||||
if !name.starts_with("C1") && !name.starts_with("C2") && reg_regex.is_match(name) {
|
|
||||||
for field in &fieldset.fields {
|
|
||||||
if field_name == field.name {
|
|
||||||
return Some((name.as_str(), field.name.as_str()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn make_peripheral_counts(out: &mut String, data: &BTreeMap<String, u8>) {
|
fn make_peripheral_counts(out: &mut String, data: &BTreeMap<String, u8>) {
|
||||||
write!(
|
write!(
|
||||||
out,
|
out,
|
||||||
@ -130,21 +111,6 @@ pub fn gen_chip(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load RCC register for chip
|
|
||||||
let (_, rcc) = core
|
|
||||||
.peripherals
|
|
||||||
.iter()
|
|
||||||
.find(|(name, _)| name == &"RCC")
|
|
||||||
.expect("RCC peripheral missing");
|
|
||||||
|
|
||||||
let rcc_block = rcc.block.as_ref().expect("RCC peripheral has no block");
|
|
||||||
let bi = BlockInfo::parse(&rcc_block);
|
|
||||||
let rcc_reg_path = options
|
|
||||||
.data_dir
|
|
||||||
.join("registers")
|
|
||||||
.join(&format!("{}_{}.yaml", bi.module, bi.version));
|
|
||||||
let rcc: IR = serde_yaml::from_reader(File::open(rcc_reg_path).unwrap()).unwrap();
|
|
||||||
|
|
||||||
let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new();
|
let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new();
|
||||||
let mut pin_table: Vec<Vec<String>> = Vec::new();
|
let mut pin_table: Vec<Vec<String>> = Vec::new();
|
||||||
let mut interrupt_table: Vec<Vec<String>> = Vec::new();
|
let mut interrupt_table: Vec<Vec<String>> = Vec::new();
|
||||||
@ -156,8 +122,6 @@ pub fn gen_chip(
|
|||||||
let mut peripheral_counts: BTreeMap<String, u8> = BTreeMap::new();
|
let mut peripheral_counts: BTreeMap<String, u8> = BTreeMap::new();
|
||||||
let mut dma_channel_counts: BTreeMap<String, u8> = BTreeMap::new();
|
let mut dma_channel_counts: BTreeMap<String, u8> = BTreeMap::new();
|
||||||
let mut dbgmcu_table: Vec<Vec<String>> = Vec::new();
|
let mut dbgmcu_table: Vec<Vec<String>> = Vec::new();
|
||||||
let mut gpio_rcc_table: Vec<Vec<String>> = Vec::new();
|
|
||||||
let mut gpio_regs: HashSet<String> = HashSet::new();
|
|
||||||
|
|
||||||
let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address as u32;
|
let gpio_base = core.peripherals.get(&"GPIOA".to_string()).unwrap().address as u32;
|
||||||
let gpio_stride = 0x400;
|
let gpio_stride = 0x400;
|
||||||
@ -290,88 +254,38 @@ pub fn gen_chip(
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround for clock registers being split on some chip families. Assume fields are
|
if let Some(rcc) = &p.rcc {
|
||||||
// named after peripheral and look for first field matching and use that register.
|
let mut clock = rcc.clock.to_ascii_lowercase();
|
||||||
let mut en = find_reg(&rcc, "^.+ENR\\d*$", &format!("{}EN", name));
|
if name.starts_with("TIM") {
|
||||||
let mut rst = find_reg(&rcc, "^.+RSTR\\d*$", &format!("{}RST", name));
|
clock = format!("{}_tim", clock)
|
||||||
|
}
|
||||||
|
|
||||||
if en.is_none() && name.ends_with("1") {
|
let mut row = Vec::new();
|
||||||
en = find_reg(
|
row.push(name.clone());
|
||||||
&rcc,
|
row.push(bi.module.clone());
|
||||||
"^.+ENR\\d*$",
|
row.push(bi.block.clone());
|
||||||
&format!("{}EN", &name[..name.len() - 1]),
|
row.push(clock);
|
||||||
);
|
|
||||||
rst = find_reg(
|
|
||||||
&rcc,
|
|
||||||
"^.+RSTR\\d*$",
|
|
||||||
&format!("{}RST", &name[..name.len() - 1]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
match (en, rst) {
|
for reg in [&rcc.registers.enable, &rcc.registers.reset] {
|
||||||
(Some((enable_reg, enable_field)), reset_reg_field) => {
|
if let Some(reg) = reg {
|
||||||
let clock = match &p.clock {
|
row.push(format!(
|
||||||
Some(clock) => clock.as_str(),
|
"({}, {}, set_{})",
|
||||||
None => {
|
reg.register.to_ascii_lowercase(),
|
||||||
// No clock was specified, derive the clock name from the enable register name.
|
reg.field.to_ascii_lowercase(),
|
||||||
// N.B. STM32G0 has only one APB bus but split ENR registers
|
reg.field.to_ascii_lowercase()
|
||||||
// (e.g. APBENR1).
|
));
|
||||||
Regex::new("([A-Z]+\\d*)ENR\\d*")
|
|
||||||
.unwrap()
|
|
||||||
.captures(enable_reg)
|
|
||||||
.unwrap()
|
|
||||||
.get(1)
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let clock = if name.starts_with("TIM") {
|
|
||||||
format!("{}_tim", clock.to_ascii_lowercase())
|
|
||||||
} else {
|
} else {
|
||||||
clock.to_ascii_lowercase()
|
row.push("_".to_string())
|
||||||
};
|
|
||||||
|
|
||||||
let mut row = Vec::with_capacity(6);
|
|
||||||
row.push(name.clone());
|
|
||||||
row.push(clock);
|
|
||||||
row.push(enable_reg.to_ascii_lowercase());
|
|
||||||
|
|
||||||
if let Some((reset_reg, reset_field)) = reset_reg_field {
|
|
||||||
row.push(reset_reg.to_ascii_lowercase());
|
|
||||||
row.push(format!("set_{}", enable_field.to_ascii_lowercase()));
|
|
||||||
row.push(format!("set_{}", reset_field.to_ascii_lowercase()));
|
|
||||||
} else {
|
|
||||||
row.push(format!("set_{}", enable_field.to_ascii_lowercase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if !name.starts_with("GPIO") {
|
|
||||||
peripheral_rcc_table.push(row);
|
|
||||||
} else {
|
|
||||||
gpio_rcc_table.push(row);
|
|
||||||
gpio_regs.insert(enable_reg.to_ascii_lowercase());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, Some(_)) => {
|
|
||||||
println!("Unable to find enable register for {}", name)
|
peripheral_rcc_table.push(row);
|
||||||
}
|
|
||||||
(None, None) => {
|
|
||||||
println!("Unable to find enable and reset register for {}", name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dev.peripherals.push(ir_peri);
|
dev.peripherals.push(ir_peri);
|
||||||
}
|
}
|
||||||
|
|
||||||
for reg in gpio_regs {
|
|
||||||
gpio_rcc_table.push(vec![reg]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We should always find GPIO RCC regs. If not, it means something
|
|
||||||
// is broken and GPIO won't work because it's not enabled.
|
|
||||||
assert!(!gpio_rcc_table.is_empty());
|
|
||||||
|
|
||||||
for (id, channel_info) in &core.dma_channels {
|
for (id, channel_info) in &core.dma_channels {
|
||||||
let mut row = Vec::new();
|
let mut row = Vec::new();
|
||||||
let dma_peri = core.peripherals.get(&channel_info.dma).unwrap();
|
let dma_peri = core.peripherals.get(&channel_info.dma).unwrap();
|
||||||
@ -502,7 +416,6 @@ pub fn gen_chip(
|
|||||||
&peripheral_dma_channels_table,
|
&peripheral_dma_channels_table,
|
||||||
);
|
);
|
||||||
make_table(&mut data, "peripheral_rcc", &peripheral_rcc_table);
|
make_table(&mut data, "peripheral_rcc", &peripheral_rcc_table);
|
||||||
make_table(&mut data, "gpio_rcc", &gpio_rcc_table);
|
|
||||||
make_table(&mut data, "dma_channels", &dma_channels_table);
|
make_table(&mut data, "dma_channels", &dma_channels_table);
|
||||||
make_table(&mut data, "dbgmcu", &dbgmcu_table);
|
make_table(&mut data, "dbgmcu", &dbgmcu_table);
|
||||||
make_peripheral_counts(&mut data, &peripheral_counts);
|
make_peripheral_counts(&mut data, &peripheral_counts);
|
||||||
@ -547,6 +460,8 @@ pub fn gen(options: Options) {
|
|||||||
let mut chip_core_names: Vec<String> = Vec::new();
|
let mut chip_core_names: Vec<String> = Vec::new();
|
||||||
|
|
||||||
for chip_name in &options.chips {
|
for chip_name in &options.chips {
|
||||||
|
println!("Generating {}...", chip_name);
|
||||||
|
|
||||||
let chip = load_chip(&options, chip_name);
|
let chip = load_chip(&options, chip_name);
|
||||||
for (core_index, core) in chip.cores.iter().enumerate() {
|
for (core_index, core) in chip.cores.iter().enumerate() {
|
||||||
let chip_core_name = match chip.cores.len() {
|
let chip_core_name = match chip.cores.len() {
|
||||||
|
@ -8,7 +8,7 @@ fn main() {
|
|||||||
|
|
||||||
let args: Vec<String> = args().collect();
|
let args: Vec<String> = args().collect();
|
||||||
|
|
||||||
let chips = match &args[..] {
|
let mut chips = match &args[..] {
|
||||||
[_, chip] => {
|
[_, chip] => {
|
||||||
vec![chip.clone()]
|
vec![chip.clone()]
|
||||||
}
|
}
|
||||||
@ -24,6 +24,8 @@ fn main() {
|
|||||||
_ => panic!("usage: stm32-metapac-gen [chip?]"),
|
_ => panic!("usage: stm32-metapac-gen [chip?]"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
chips.sort();
|
||||||
|
|
||||||
gen(Options {
|
gen(Options {
|
||||||
out_dir,
|
out_dir,
|
||||||
data_dir,
|
data_dir,
|
||||||
|
Loading…
Reference in New Issue
Block a user