Skip to content

Commit

Permalink
update embassy
Browse files Browse the repository at this point in the history
  • Loading branch information
Univa committed Mar 12, 2024
1 parent 54cae71 commit e5480bf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
16 changes: 8 additions & 8 deletions rumcake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 0 additions & 4 deletions rumcake/src/drivers/ws2812_bitbang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
43 changes: 31 additions & 12 deletions rumcake/src/hw/mcu/stm32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -43,22 +38,46 @@ 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();
let mut rcc_conf = embassy_stm32::rcc::Config::default();

#[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;
Expand Down

0 comments on commit e5480bf

Please sign in to comment.