diff --git a/rumcake/Cargo.toml b/rumcake/Cargo.toml index 5857d7e..f030c6c 100644 --- a/rumcake/Cargo.toml +++ b/rumcake/Cargo.toml @@ -33,20 +33,20 @@ flavours = [ cortex-m = { version = "0.7.6", optional = true } defmt = "0.3" embedded-hal = "0.2.7" -embedded-hal-async = "1.0.0-rc.2" +embedded-hal-async = "1.0.0" embedded-storage = "0.3.0" embedded-storage-async = "0.4.0" embedded-io-async = "0.6.0" embedded-graphics = { version = "0.8.1", features = ["defmt"] } embedded-layout = "0.3.2" embedded-text = "0.6.2" -embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "7703f47", features = ["defmt"] } -embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "7703f47" } -embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "7703f47", features = ["defmt", "integrated-timers", "executor-thread", "nightly"] } -embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "7703f47", features = ["defmt", "defmt-timestamp-uptime"] } -embassy-usb = { git = "https://github.com/embassy-rs/embassy", rev = "7703f47", features = ["defmt"] } -embassy-stm32 = { git = "https://github.com/embassy-rs/embassy", rev = "7703f47", features = ["defmt", "unstable-pac"], optional = true } -embassy-nrf = { git = "https://github.com/embassy-rs/embassy", rev = "7703f47", features = ["defmt", "nfc-pins-as-gpio", "time-driver-rtc1"], optional = true } +embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "b8be126", features = ["defmt"] } +embassy-futures = { git = "https://github.com/embassy-rs/embassy", rev = "b8be126" } +embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "b8be126", features = ["defmt", "integrated-timers", "executor-thread"] } +embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "b8be126", features = ["defmt", "defmt-timestamp-uptime"] } +embassy-usb = { git = "https://github.com/embassy-rs/embassy", rev = "b8be126", features = ["defmt"] } +embassy-stm32 = { git = "https://github.com/embassy-rs/embassy", rev = "b8be126", features = ["defmt", "unstable-pac"], optional = true } +embassy-nrf = { git = "https://github.com/embassy-rs/embassy", rev = "b8be126", features = ["defmt", "nfc-pins-as-gpio", "time-driver-rtc1"], optional = true } nrf-softdevice = { git = "https://github.com/embassy-rs/nrf-softdevice", rev = "487f98e", optional = true } tickv = { git = "https://github.com/tock/tock", rev = "18cf287" } keyberon = { path = "../keyberon" } diff --git a/rumcake/src/drivers/ws2812_bitbang.rs b/rumcake/src/drivers/ws2812_bitbang.rs index e6bf49f..7c3b6d9 100644 --- a/rumcake/src/drivers/ws2812_bitbang.rs +++ b/rumcake/src/drivers/ws2812_bitbang.rs @@ -43,12 +43,8 @@ pub mod driver { } } - #[cfg(not(feature = "stm32f072cb"))] const NOP_FUDGE: f64 = 0.6; - #[cfg(feature = "stm32f072cb")] - const NOP_FUDGE: f64 = 0.4; - const TICK_CONV_FACTOR: f64 = (SYSCLK as u64 / gcd(SYSCLK as u64, 1_000_000_000)) as f64 / (1_000_000_000 / gcd(SYSCLK as u64, 1_000_000_000)) as f64; diff --git a/rumcake/src/hw/mcu/stm32.rs b/rumcake/src/hw/mcu/stm32.rs index ce59d52..e616df8 100644 --- a/rumcake/src/hw/mcu/stm32.rs +++ b/rumcake/src/hw/mcu/stm32.rs @@ -4,16 +4,11 @@ //! of other versions of the `mcu` module. This is the case so that parts of `rumcake` can remain //! hardware-agnostic. -use core::fmt::Debug; use embassy_stm32::bind_interrupts; -use embassy_stm32::dma::NoDma; -use embassy_stm32::flash::{Bank1Region, Blocking, Flash as HALFlash}; -use embassy_stm32::i2c::I2c; +use embassy_stm32::flash::{Blocking, Flash as HALFlash}; use embassy_stm32::peripherals::{FLASH, PA11, PA12, USB}; -use embassy_stm32::time::Hertz; +use embassy_stm32::rcc::{APBPrescaler, Hse, Pll, PllMul, PllPreDiv, PllSource, Sysclk, HSI_FREQ}; use embassy_stm32::usb::Driver; -use embedded_hal::blocking::i2c::Write; -use embedded_hal_async::i2c::I2c as AsyncI2c; use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; use embedded_storage_async::nor_flash::{ NorFlash as AsyncNorFlash, ReadNorFlash as AsyncReadNorFlash, @@ -43,6 +38,14 @@ pub fn jump_to_bootloader() { }; } +const fn gcd(a: u32, b: u32) -> u32 { + if b == 0 { + a + } else { + gcd(b, a % b) + } +} + /// Initialize the MCU's internal clocks. pub fn initialize_rcc() { let mut conf = embassy_stm32::Config::default(); @@ -50,15 +53,31 @@ pub fn initialize_rcc() { #[cfg(feature = "stm32f072cb")] { - rcc_conf.sys_ck = Some(embassy_stm32::time::Hertz(SYSCLK)); + rcc_conf.pll = Some(Pll { + src: PllSource::HSI, + prediv: PllPreDiv::DIV2, + mul: PllMul::from(((2 * 2 * SYSCLK + HSI_FREQ.0) / HSI_FREQ.0 / 2) as u8 - 2), + }); + rcc_conf.sys = Sysclk::PLL1_P; } #[cfg(feature = "stm32f303cb")] { - rcc_conf.sysclk = Some(embassy_stm32::time::Hertz(SYSCLK)); - rcc_conf.hse = Some(embassy_stm32::time::Hertz(8_000_000)); - rcc_conf.pclk1 = Some(embassy_stm32::time::Hertz(24_000_000)); - rcc_conf.pclk2 = Some(embassy_stm32::time::Hertz(24_000_000)); + let hse = embassy_stm32::time::mhz(8); + let div = gcd(SYSCLK, hse.0); + + rcc_conf.hse = Some(Hse { + freq: hse, + mode: embassy_stm32::rcc::HseMode::Oscillator, + }); + rcc_conf.pll = Some(Pll { + src: PllSource::HSE, + prediv: PllPreDiv::from((hse.0 / div) as u8 - 1), + mul: PllMul::from((SYSCLK / div) as u8 - 2), + }); + rcc_conf.apb1_pre = APBPrescaler::DIV2; + rcc_conf.apb2_pre = APBPrescaler::DIV2; + rcc_conf.sys = Sysclk::PLL1_P; } conf.rcc = rcc_conf;