Skip to content

Commit

Permalink
[rust] set clock speed to 1008 MHz on sun20iw1 platform
Browse files Browse the repository at this point in the history
Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
  • Loading branch information
luojia65 committed Sep 28, 2024
1 parent 96062f8 commit 3c3ff34
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion board/100ask-d1-h-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
#![no_main]

use panic_halt as _;
use syterkit::{clock_dump, entry, println, show_banner, Clocks, Peripherals};
use syterkit::{clock_dump, clock_init, entry, println, show_banner, Clocks, Peripherals};

#[entry]
fn main(p: Peripherals, _c: Clocks) {
// Display the bootloader banner.
show_banner();

// Initialize system clocks. // TODO: built-in in `entry` macro
clock_init(&p.ccu);

// Initialize the DRAM.
let dram_size = syterkit::mctl::init(&p.ccu);
println!("DRAM size: {}M 🐏", dram_size);
Expand Down
2 changes: 1 addition & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use allwinner_hal::ccu::Clocks;
pub use syterkit_macros::entry;

#[cfg(feature = "sun20iw1")]
pub use soc::sun20iw1::{clock_dump, Peripherals};
pub use soc::sun20iw1::{clock_dump, clock_init, Peripherals};

/// Print SyterKit banner.
pub fn show_banner() {
Expand Down
21 changes: 21 additions & 0 deletions rust/src/soc/sun20iw1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ impl<'a> Peripherals<'a> {
}
}

/// Initialize clock configurations.
pub fn clock_init(ccu: &CCU) {
// TODO rewrite accordding to function `set_pll_cpux_axi` in src/drivers/sun20iw1/sys-clk.c
unsafe {
ccu.cpu_axi_config
.modify(|val| val.set_clock_source(CpuClockSource::PllPeri1x))
};
unsafe {
ccu.pll_cpu_control.modify(|val| val.set_pll_n(42 - 1));
ccu.pll_cpu_control.modify(|val| val.disable_lock());
ccu.pll_cpu_control.modify(|val| val.enable_lock())
};
while !ccu.pll_cpu_control.read().is_locked() {
core::hint::spin_loop();
}
unsafe {
ccu.cpu_axi_config
.modify(|val| val.set_clock_source(CpuClockSource::PllCpu));
};
}

/// Dump information about the system clocks.
pub fn clock_dump(ccu: &CCU) {
let cpu_clock_source = ccu.cpu_axi_config.read().clock_source();
Expand Down

0 comments on commit 3c3ff34

Please sign in to comment.